MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
global.cpp File Reference
#include "global.h"
#include <numeric>
#include <sys/stat.h>
#include <sys/types.h>
+ Include dependency graph for global.cpp:

Go to the source code of this file.

Namespaces

 moose
 

Functions

int checkPath (const string &path)
 Checks if given path is correct. If not, return false and error-code as well. More...
 
int moose::checkPath (const string &path)
 Checks if given path is correct. If not, return false and error-code as well. More...
 
string moose::createMOOSEPath (const string &path)
 Create a POSIX compatible path from a given string. Remove/replace bad characters. More...
 
bool moose::createParentDirs (const string &path)
 Create directories recursively needed to open the given file p. More...
 
string dumpStats (int)
 
string fixPath (string path)
 Fix a path. For testing purpose. More...
 
string moose::fixPath (string path)
 Fix a path. For testing purpose. More...
 
string moose::getExtension (const string &path, bool without_dot=true)
 Get the extension of a given filepath. More...
 
int moose::getGlobalSeed ()
 
string joinPath (string pathA, string pathB)
 Append pathB to pathA and return the result. More...
 
string moose::joinPath (string pathA, string pathB)
 Append pathB to pathA and return the result. More...
 
string moose::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 one needs to create more than 1 element. More...
 
double moose::mtrand (void)
 Generate a random double between 0 and 1. More...
 
void moose::mtseed (unsigned int x)
 Set the global seed or all rngs. More...
 
string moose::pathToName (const string &path)
 Return the name when path is given. Its behaviour is exactly the same as of basename command on unix system. More...
 
void moose::setGlobalSeed (int seed)
 
string moose::toFilename (const string &path)
 Replace all directory sepearator with _. This creates a filepath which can be created in current directory without any need to create parent directory. More...
 
string moose::toString (double x)
 Convert a given value to string. More...
 

Variables

unsigned long moose::__rng_seed__ = 0
 A global seed for all RNGs in moose. When moose.seed( x ) is called, this variable is set. Other's RNGs (except muparser) uses this seed to initialize them. By default it is initialized by random_device (see global.cpp). More...
 
stringstream errorSS
 Global stringstream for message printing. More...
 
bool isRNGInitialized = false
 
moose::RNG< double > moose::rng
 
clock_t simClock = clock()
 
unsigned int totalTests = 0
 Keep tracks of how many tests have been executed in moose. More...
 

Function Documentation

int checkPath ( const string &  path)

Checks if given path is correct. If not, return false and error-code as well.

Parameters
pathPath name.
Returns
0 if path is all-right. Negative number if path is not OK.

Definition at line 50 of file global.cpp.

References BAD_CHARACTER_IN_PATH, EMPTY_PATH, and MISSING_BRACKET_AT_END.

Referenced by moose::fixPath().

51  {
52  if( path.size() < 1)
53  return EMPTY_PATH;
54 
55  if( path.find_first_of( " \\!") != std::string::npos )
56  return BAD_CHARACTER_IN_PATH;
57 
58  if ( path[path.size() - 1 ] != ']')
59  {
61  }
62  return 0;
63  }
#define MISSING_BRACKET_AT_END
Definition: global.h:44
#define BAD_CHARACTER_IN_PATH
Definition: global.h:49
#define EMPTY_PATH
Definition: global.h:45
static char path[]
Definition: mfield.cpp:403

+ Here is the caller graph for this function:

string dumpStats ( int  )
string fixPath ( string  path)

Fix a path. For testing purpose.

Parameters
pathPath as string.
Returns
A fixed path.

Definition at line 74 of file global.cpp.

References moose::checkPath(), MISSING_BRACKET_AT_END, and path.

Referenced by HSolveUtils::gates(), and moose::joinPath().

75  {
76  int pathOk = moose::checkPath( path );
77  if( pathOk == 0)
78  return path;
79  else if( pathOk == MISSING_BRACKET_AT_END)
80  return path + "[0]";
81  return path;
82  }
#define MISSING_BRACKET_AT_END
Definition: global.h:44
int checkPath(const string &path)
Checks if given path is correct. If not, return false and error-code as well.
Definition: global.cpp:50
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

string joinPath ( string  pathA,
string  pathB 
)

Append pathB to pathA and return the result.

If pathA does not have [indexs] at the end, append "[0]" to pathA and then add pathB to it. This version does not care if the result has '[0]' at its end.

Parameters
pathAFirst path.
pathBSecond path.
Returns
A string representing moose-path.

Definition at line 66 of file global.cpp.

References moose::fixPath().

67  {
68  pathA = moose::fixPath( pathA );
69  string newPath = pathA + "/" + pathB;
70  return moose::fixPath( newPath );
71  }
string fixPath(string path)
Fix a path. For testing purpose.
Definition: global.cpp:74

+ Here is the call graph for this function:

Variable Documentation

stringstream errorSS

Global stringstream for message printing.

Definition at line 32 of file global.cpp.

Referenced by HSolveUtils::gates().

bool isRNGInitialized = false

Definition at line 34 of file global.cpp.

Referenced by moose::mtseed().

clock_t simClock = clock()

Definition at line 36 of file global.cpp.

unsigned int totalTests = 0

Keep tracks of how many tests have been executed in moose.

Definition at line 30 of file global.cpp.