Pointwise Plugin SDK
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members

Manipulates the current working directory. More...

#include <PwpCwd.h>

+ Inheritance diagram for PwpCwd:

Public Member Functions

bool pop ()
 Restores the current working directory. More...
 
bool push (const char *dir)
 Sets the current working directory. More...
 
 PwpCwd (const char *dir=0)
 Constructor. More...
 
 ~PwpCwd ()
 Destructor. More...
 

Static Public Member Functions

static bool popDir ()
 Restores the current working directory. More...
 
static bool pushDir (const char *dir)
 Sets the current working directory. More...
 

Private Attributes

int depth_
 The stack depth. More...
 

Detailed Description

Manipulates the current working directory.

The PwpCwd class pushes and pops the current working directory onto the shared directory stack using the global functions pwpCwdPush() and pwpCwdPop().

To prevent push/pop mismatches, two PwpCwd objects should never exist in the same scope.

Sample Usage:
#include "PwpCwd.h"
// For code clarity, return values are not checked below.
static void func()
{
PwpCwd loc1("/a/completely/different/folder");
// do something here
loc1.push("/yet/another/folder");
// do something else here
loc1.pop(); // back to "/a/completely/different/folder"
// do something else here
loc1.pop(); // cwd is back what it was when func() was called
loc1.pop(); // does nothing and returns false
// loc1's destructor will do nothing since we called pop() too
// many times above.
}
static void startHere()
{
PwpCwd loc("/some/path/to/a/folder");
// do something here
func();
// do something else here
// loc's destructor will restore the cwd to
// what it was when startHere() was called.
}
See Also
pwpCwdPush(), pwpCwdPop()

Definition at line 56 of file PwpCwd.h.

Constructor & Destructor Documentation

PwpCwd::PwpCwd ( const char *  dir = 0)

Constructor.

Constructs instance and pushes dir.

Parameters
dirThe directory to make current
Note
If you want to check the status, do not pass the directory to the constructor. Instead you should use the push() method:
const char *dir = "/some/folder";
PwpCwd loc; // default ctor
if (loc.push(dir)) {
// do something
}

Definition at line 14 of file PwpCwd.cxx.

References push().

PwpCwd::~PwpCwd ( )

Destructor.

Definition at line 20 of file PwpCwd.cxx.

References pop().

Member Function Documentation

bool PwpCwd::pop ( )

Restores the current working directory.

Each PwpCwd object maintains a local directory stack internally and can only pop() directories it has pushed.

Returns
true on success.

Definition at line 37 of file PwpCwd.cxx.

References depth_, and popDir().

Referenced by ~PwpCwd().

bool PwpCwd::popDir ( )
static

Restores the current working directory.

This method pops directly from the global directory stack using pwpCwdPop(). It should only be called after a corresponding call to pushDir().

Returns
true on success.
See Also
pwpCwdPush(), pwpCwdPop()

Definition at line 54 of file PwpCwd.cxx.

References pwpCwdPop().

Referenced by pop().

bool PwpCwd::push ( const char *  dir)

Sets the current working directory.

Each PwpCwd object maintains a local directory stack internally. It can only pop() directories it has pushed.

Parameters
dirThe directory to make current
Returns
true on success.

Definition at line 27 of file PwpCwd.cxx.

References depth_, and pushDir().

Referenced by FileDestPwpCwd::FileDestPwpCwd(), and PwpCwd().

bool PwpCwd::pushDir ( const char *  dir)
static

Sets the current working directory.

This method pushes directly onto the global directory stack using pwpCwdPush(). It is the caller's responsibility to make a corresponding call to popDir().

Parameters
dirThe directory to make current
Returns
true on success.
See Also
pwpCwdPush(), pwpCwdPop()

Definition at line 48 of file PwpCwd.cxx.

References pwpCwdPush().

Referenced by push().

Member Data Documentation

int PwpCwd::depth_
private

The stack depth.

Definition at line 117 of file PwpCwd.h.

Referenced by pop(), and push().


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