File: misc_api_shared.h

package info (click to toggle)
concurrentqueue 1.0.4%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,656 kB
  • sloc: cpp: 37,309; makefile: 99; ansic: 67; python: 46; sh: 11
file content (57 lines) | stat: -rw-r--r-- 1,224 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (C) 2014  Davis E. King (davis@dlib.net)
// License: Boost Software License   See LICENSE.txt for the full license.
#ifndef DLIB_MISC_API_ShARED_Hh_
#define DLIB_MISC_API_ShARED_Hh_

#include <string>
#include "../noncopyable.h"

namespace dlib
{

// ----------------------------------------------------------------------------------------

    class locally_change_current_dir : noncopyable
    {
    public:
        explicit locally_change_current_dir (
            const std::string& new_dir
        )
        {
            reverted = false;
            _old_dir = get_current_dir();
            set_current_dir(new_dir);
        }

        ~locally_change_current_dir()
        {
            revert();
        }

        const std::string& old_dir (
        ) const 
        {
            return _old_dir;
        }

        void revert (
        )
        {
            if (!reverted)
            {
                set_current_dir(_old_dir);
                reverted = true;
            }
        }

    private:
        bool reverted;
        std::string _old_dir;
    };

// ----------------------------------------------------------------------------------------

}

#endif // DLIB_MISC_API_ShARED_Hh_