Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
672b4b27
Commit
672b4b27
authored
Apr 26, 2014
by
Davis King
Browse files
Added locally_change_current_dir
parent
4934b002
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
+82
-0
dlib/misc_api.h
dlib/misc_api.h
+2
-0
dlib/misc_api/misc_api_kernel_abstract.h
dlib/misc_api/misc_api_kernel_abstract.h
+35
-0
dlib/misc_api/misc_api_shared.h
dlib/misc_api/misc_api_shared.h
+45
-0
No files found.
dlib/misc_api.h
View file @
672b4b27
...
...
@@ -14,5 +14,7 @@
#include "misc_api/posix.h"
#endif
#include "misc_api/misc_api_shared.h"
#endif // DLIB_MISC_APi_
dlib/misc_api/misc_api_kernel_abstract.h
View file @
672b4b27
...
...
@@ -59,6 +59,41 @@ namespace dlib
to change the current working directory.
!*/
// ----------------------------------------------------------------------------------------
class
locally_change_current_dir
:
noncopyable
{
/*!
WHAT THIS OBJECT REPRESENTS
This object is a RAII tool for safely switching the current directory
to a new directory and then automatically switching back to the original
directory upon this object's destruction.
!*/
public:
explicit
locally_change_current_dir
(
const
std
::
string
&
new_dir
);
/*!
ensures
- calls set_current_dir(new_dir)
- #old_dir() == The value of get_current_dir() prior to switching to new_dir.
!*/
const
std
::
string
&
old_dir
(
)
const
;
/*!
ensures
- returns the directory we switch back to once this object is destructed.
!*/
~
locally_change_current_dir
(
);
/*!
ensures
- calls set_current_dir(old_dir())
!*/
};
// ----------------------------------------------------------------------------------------
class
dir_create_error
:
public
error
{
...
...
dlib/misc_api/misc_api_shared.h
0 → 100644
View file @
672b4b27
// 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_H__
#define DLIB_MISC_API_ShARED_H__
#include <string>
#include "../noncopyable.h"
namespace
dlib
{
// ----------------------------------------------------------------------------------------
class
locally_change_current_dir
:
noncopyable
{
public:
explicit
locally_change_current_dir
(
const
std
::
string
&
new_dir
)
{
_old_dir
=
get_current_dir
();
set_current_dir
(
new_dir
);
}
~
locally_change_current_dir
()
{
set_current_dir
(
_old_dir
);
}
const
std
::
string
&
old_dir
(
)
const
{
return
_old_dir
;
}
private:
std
::
string
_old_dir
;
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_MISC_API_ShARED_H__
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment