Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
672b4b27
Commit
672b4b27
authored
Apr 26, 2014
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added locally_change_current_dir
parent
4934b002
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
+82
-0
misc_api.h
dlib/misc_api.h
+2
-0
misc_api_kernel_abstract.h
dlib/misc_api/misc_api_kernel_abstract.h
+35
-0
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