22 #include <sys/types.h>
39 extern string joinPath(
string pathA,
string pathB);
55 if( path.find_first_of(
" \\!") != std::string::npos )
58 if ( path[path.size() - 1 ] !=
']')
69 string newPath = pathA +
"/" + pathB;
109 std::string::size_type n = 0;
110 string zeroIndex(
"[0]");
111 while( (n = s.find( zeroIndex, n )) != std::string::npos )
112 s.erase( n, zeroIndex.size() );
128 size_t pos = p.find_last_of(
'/' );
129 if( pos != std::string::npos )
130 p = p.substr( 0, pos );
137 string command(
"mkdir -p ");
139 int ret = system( command.c_str() );
141 if( stat( p.c_str(), &
info ) != 0 )
146 else if( info.st_mode & S_IFDIR )
164 std::replace(p.begin(), p.end(),
'/',
'_' );
165 std::replace(p.begin(), p.end(),
'\\',
'_' );
172 size_t dotPos = path.find_last_of(
'.' );
173 if( dotPos == std::string::npos )
177 return path.substr( dotPos + 1 );
179 return path.substr( dotPos );
185 return path.substr( path.find_last_of(
'/' ) );
202 sprintf(buffer,
"%.17g", x );
203 return string( buffer );
void mtseed(unsigned int x)
Set the global seed or all rngs.
string fixPath(string path)
Fix a path. For testing purpose.
string toString(double x)
Convert a given value to string.
string pathToName(const string &path)
Return the name when path is given. Its behaviour is exactly the same as of basename command on unix ...
unsigned int totalTests
Keep tracks of how many tests have been executed in moose.
string joinPath(string pathA, string pathB)
Append pathB to pathA and return the result.
bool createParentDirs(const string &path)
Create directories recursively needed to open the given file p.
void setSeed(const unsigned long seed)
If seed if 0 then set seed to a random number else set seed to the given number.
#define MISSING_BRACKET_AT_END
#define BAD_CHARACTER_IN_PATH
string getExtension(const string &path, bool without_dot)
Get the extension of a given filepath.
int checkPath(const string &path)
Checks if given path is correct. If not, return false and error-code as well.
string moosePathToUserPath(string path)
When user gives a path /a/b/c, moose creates a path /a[0]/b[0]/c[0]. This is helpful in cases where o...
void setGlobalSeed(int seed)
string joinPath(string pathA, string pathB)
Append pathB to pathA and return the result.
unsigned long __rng_seed__
A global seed for all RNGs in moose. When moose.seed( x ) is called, this variable is set...
string fixPath(string path)
Fix a path. For testing purpose.
stringstream errorSS
Global stringstream for message printing.
string toFilename(const string &path)
Replace all directory sepearator with _. This creates a filepath which can be created in current dire...
string createMOOSEPath(const string &path)
Create a POSIX compatible path from a given string. Remove/replace bad characters.
#define LOG(t, a)
This macro only expands when not compiling for release.
int checkPath(const string &path)
Checks if given path is correct. If not, return false and error-code as well.
double mtrand(void)
Generate a random double between 0 and 1.
T uniform(const T a, const T b)
Generate a uniformly distributed random number between a and b.