1999-10-13 17:32:46 +00:00
|
|
|
|
// -*- C++ -*-
|
2002-05-30 02:24:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file path.h
|
2002-09-25 10:03:41 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-05-30 02:24:33 +00:00
|
|
|
|
*
|
2002-09-25 10:03:41 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-05-30 02:24:33 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1999-10-13 17:32:46 +00:00
|
|
|
|
#ifndef PATH_H
|
|
|
|
|
#define PATH_H
|
|
|
|
|
|
2000-10-02 00:55:02 +00:00
|
|
|
|
#include <boost/utility.hpp>
|
1999-10-13 17:32:46 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace support {
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* Path - utility closs for stackable working directories
|
|
|
|
|
*
|
|
|
|
|
* You can use a local variable of this type to temporarily
|
|
|
|
|
* change to a directory as the cwd, for example :
|
|
|
|
|
*
|
|
|
|
|
* if (blah) {
|
|
|
|
|
* Path p("/tmp/blah");
|
2002-12-01 22:59:25 +00:00
|
|
|
|
* ...
|
2002-05-30 02:24:33 +00:00
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* At the end of p's scope the cwd is reset to its previous value.
|
|
|
|
|
*/
|
2001-04-17 14:22:53 +00:00
|
|
|
|
class Path : boost::noncopyable {
|
1999-10-13 17:32:46 +00:00
|
|
|
|
public:
|
2002-05-30 02:24:33 +00:00
|
|
|
|
/// change to the given directory
|
2003-10-06 15:43:21 +00:00
|
|
|
|
explicit Path(std::string const & path);
|
2002-09-25 10:03:41 +00:00
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
|
/// set cwd to the previous value if needed
|
2003-09-04 01:44:16 +00:00
|
|
|
|
~Path();
|
2002-09-25 10:03:41 +00:00
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
|
/// set cwd to the previous value if needed
|
2000-04-04 00:19:15 +00:00
|
|
|
|
int pop();
|
1999-10-13 17:32:46 +00:00
|
|
|
|
private:
|
2002-05-30 02:24:33 +00:00
|
|
|
|
/// whether we are in the new cwd or not
|
1999-10-13 17:32:46 +00:00
|
|
|
|
bool popped_;
|
2002-05-30 02:24:33 +00:00
|
|
|
|
/// the previous cwd
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string pushedDir_;
|
1999-10-13 17:32:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// To avoid the wrong usage:
|
|
|
|
|
// Path("/tmp"); // wrong
|
|
|
|
|
// Path p("/tmp"); // right
|
|
|
|
|
// we add this macro:
|
2000-08-07 20:58:24 +00:00
|
|
|
|
///
|
2003-09-04 01:44:16 +00:00
|
|
|
|
#ifndef PATH_C
|
2000-01-13 16:28:54 +00:00
|
|
|
|
#define Path(x) unnamed_Path;
|
2003-09-04 01:44:16 +00:00
|
|
|
|
#endif
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
|
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
} // namespace support
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
|
#endif // PATH_H
|