Skip to content

Commit

Permalink
Added a .revert() to the locally_change_current_dir object.
Browse files Browse the repository at this point in the history
  • Loading branch information
davisking committed Jul 2, 2015
1 parent 4844481 commit b52e50a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 10 additions & 1 deletion dlib/misc_api/misc_api_kernel_abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ namespace dlib
);
/*!
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())
!*/
};

Expand Down
14 changes: 13 additions & 1 deletion dlib/misc_api/misc_api_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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;
};

Expand Down

0 comments on commit b52e50a

Please sign in to comment.