API  4.5.1
For C++ developers
OpenSim::IO::CwdChanger Class Referencefinal

A class that: More...

Public Member Functions

 CwdChanger (const CwdChanger &)=delete
 
 CwdChanger (CwdChanger &&tmp)
 
CwdChangeroperator= (const CwdChanger &)=delete
 
CwdChangeroperator= (CwdChanger &&)
 
void restore ()
 Prematurely change the current working directory back to its original location. More...
 
void stay () noexcept
 Release CwdChanger's control over the current working directory, such that the CwdChanger instance does not attempt to change back to its original directory on destruction. More...
 
 ~CwdChanger () noexcept
 Destructs a CwdChanger instance. More...
 

Static Public Member Functions

static CwdChanger noop ()
 Returns a CwdChanger that does nothing. More...
 
static CwdChanger changeTo (const std::string &newDir)
 Returns a CwdChanger that changes to newDir. More...
 
static CwdChanger changeToParentOf (const std::string &path)
 Returns a CwdChanger that changes to the parent of path. More...
 

Detailed Description

A class that:

  • On construction: switches the calling process's current working directory to the supplied directory
  • On destruction: switches the calling process's working directory back to its original directory.

Constructor & Destructor Documentation

◆ CwdChanger() [1/2]

OpenSim::IO::CwdChanger::CwdChanger ( const CwdChanger )
delete

◆ CwdChanger() [2/2]

OpenSim::IO::CwdChanger::CwdChanger ( CwdChanger &&  tmp)

◆ ~CwdChanger()

OpenSim::IO::CwdChanger::~CwdChanger ( )
noexcept

Destructs a CwdChanger instance.

The destructor switches the calling process's current working directory back to whatever it was before constructing the instance, unless:

  • The instance was constructed with noop(): in this case, it does nothing
  • The instance is an rvalue temporary: does nothing

Member Function Documentation

◆ changeTo()

static CwdChanger OpenSim::IO::CwdChanger::changeTo ( const std::string &  newDir)
static

Returns a CwdChanger that changes to newDir.

◆ changeToParentOf()

static CwdChanger OpenSim::IO::CwdChanger::changeToParentOf ( const std::string &  path)
static

Returns a CwdChanger that changes to the parent of path.

This is useful when changing into a file's parent dir:

CwdChanger::changeToParentOf(xmlFile);

◆ noop()

static CwdChanger OpenSim::IO::CwdChanger::noop ( )
static

Returns a CwdChanger that does nothing.

This is useful for conditional directory changing:

CwdChanger c = shouldSwitch ? CwdChanger::changeTo(p) : CwdChanger::noop();

◆ operator=() [1/2]

CwdChanger& OpenSim::IO::CwdChanger::operator= ( const CwdChanger )
delete

◆ operator=() [2/2]

CwdChanger& OpenSim::IO::CwdChanger::operator= ( CwdChanger &&  )

◆ restore()

void OpenSim::IO::CwdChanger::restore ( )

Prematurely change the current working directory back to its original location.

This is functionally equivalent to prematurely destructing the CwdChanger. After calling CwdChanger::restore(), the now-restored CwdChanger will become a noop instance that, when it destructs, will not attempt to change back to the original directory.

◆ stay()

void OpenSim::IO::CwdChanger::stay ( )
noexcept

Release CwdChanger's control over the current working directory, such that the CwdChanger instance does not attempt to change back to its original directory on destruction.


The documentation for this class was generated from the following file: