Commit b52e50a3 authored by Davis King's avatar Davis King

Added a .revert() to the locally_change_current_dir object.

parent 48444811
...@@ -90,7 +90,16 @@ namespace dlib ...@@ -90,7 +90,16 @@ namespace dlib
); );
/*! /*!
ensures ensures
- calls set_current_dir(old_dir()) - if (revert() hasn't already been called) then
- calls set_current_dir(old_dir())
!*/
void revert (
);
/*!
ensures
- if (revert() hasn't already been called) then
- calls set_current_dir(old_dir())
!*/ !*/
}; };
......
...@@ -18,13 +18,14 @@ namespace dlib ...@@ -18,13 +18,14 @@ namespace dlib
const std::string& new_dir const std::string& new_dir
) )
{ {
reverted = false;
_old_dir = get_current_dir(); _old_dir = get_current_dir();
set_current_dir(new_dir); set_current_dir(new_dir);
} }
~locally_change_current_dir() ~locally_change_current_dir()
{ {
set_current_dir(_old_dir); revert();
} }
const std::string& old_dir ( const std::string& old_dir (
...@@ -33,7 +34,18 @@ namespace dlib ...@@ -33,7 +34,18 @@ namespace dlib
return _old_dir; return _old_dir;
} }
void revert (
)
{
if (!reverted)
{
set_current_dir(_old_dir);
reverted = true;
}
}
private: private:
bool reverted;
std::string _old_dir; std::string _old_dir;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment