Added a .revert() to the locally_change_current_dir object.

This commit is contained in:
Davis King 2015-07-02 08:20:27 -04:00
parent 484448113c
commit b52e50a30b
2 changed files with 23 additions and 2 deletions

View File

@ -90,6 +90,15 @@ namespace dlib
);
/*!
ensures
- 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())
!*/
};

View File

@ -18,13 +18,14 @@ namespace dlib
const std::string& new_dir
)
{
reverted = false;
_old_dir = get_current_dir();
set_current_dir(new_dir);
}
~locally_change_current_dir()
{
set_current_dir(_old_dir);
revert();
}
const std::string& old_dir (
@ -33,7 +34,18 @@ namespace dlib
return _old_dir;
}
void revert (
)
{
if (!reverted)
{
set_current_dir(_old_dir);
reverted = true;
}
}
private:
bool reverted;
std::string _old_dir;
};