MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
global.h
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment,
4 ** also known as GENESIS 3 base code.
5 ** copyright (C) 2003-2004 Upinder S. Bhalla. and NCBS
6 ** It is made available under the terms of the
7 ** GNU Lesser Public License version 2.1
8 ** See the file COPYING.LIB for the full notice.
9 **********************************************************************/
10 
11 
12 #ifndef __MOOSE_GLOBAL_INC_
13 #define __MOOSE_GLOBAL_INC_
14 
15 #include <ctime>
16 #include <map>
17 #include <sstream>
18 
19 #include "../randnum/RNG.h" /* Use inbuilt rng */
20 #include "../utility/print_function.hpp"
21 
22 using namespace std;
23 
27 extern stringstream errorSS;
28 
32 extern unsigned int totalTests;
33 
34 
40 #define TEST_BEGIN cout << endl << "Test(" << totalTests << "): " << SIMPLE_CURRENT_FUNCTION;
41 #define TEST_END totalTests++; \
42  cout << std::right << setw(20) << "test of " << SIMPLE_CURRENT_FUNCTION << " finished.";
43 
44 #define MISSING_BRACKET_AT_END -1
45 #define EMPTY_PATH -2
46 #define SPACES_AT_THE_BEGINING -3
47 #define SPACES_AT_THE_END -4
48 #define SPACES_IN_BETWEEN -5
49 #define BAD_CHARACTER_IN_PATH -6
50 
51 
52 /*-----------------------------------------------------------------------------
53  * Global functions in namespace moose
54  *-----------------------------------------------------------------------------*/
55 namespace moose
56 {
57 
58  extern moose::RNG<double> rng;
59 
66  extern unsigned long __rng_seed__;
67 
75  string fixPath(string path);
76 
85  int checkPath( const string& path );
86 
98  string joinPath(string pathA, string pathB);
99 
105  void mtseed( unsigned int seed );
106 
112  double mtrand( void );
113 
121  string createMOOSEPath( const string& path );
122 
131  string toString( double x );
132 
136  bool createParentDirs( const string& path );
137 
147  string toFilename( const string& path );
148 
156  string getExtension( const string& path, bool without_dot = true );
157 
166  string pathToName( const string& path );
167 
177  string moosePathToUserPath( string path );
178 
179  /* --------------------------------------------------------------------------*/
185  /* ----------------------------------------------------------------------------*/
186  int getGlobalSeed( );
187 
188  /* --------------------------------------------------------------------------*/
195  /* ----------------------------------------------------------------------------*/
196  void setGlobalSeed( int seed );
197 }
198 
199 #endif /* ----- #ifndef __MOOSE_GLOBAL_INC_ ----- */
void mtseed(unsigned int x)
Set the global seed or all rngs.
Definition: global.cpp:89
string fixPath(string path)
Fix a path. For testing purpose.
Definition: global.cpp:74
string toString(double x)
Convert a given value to string.
Definition: global.cpp:199
string pathToName(const string &path)
Return the name when path is given. Its behaviour is exactly the same as of basename command on unix ...
Definition: global.cpp:183
bool createParentDirs(const string &path)
Create directories recursively needed to open the given file p.
Definition: global.cpp:122
moose::RNG< double > rng
Definition: global.cpp:47
string getExtension(const string &path, bool without_dot)
Get the extension of a given filepath.
Definition: global.cpp:170
stringstream errorSS
Global stringstream for message printing.
Definition: global.cpp:32
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...
Definition: global.cpp:189
void setGlobalSeed(int seed)
Definition: global.cpp:211
string joinPath(string pathA, string pathB)
Append pathB to pathA and return the result.
Definition: global.cpp:66
unsigned long __rng_seed__
A global seed for all RNGs in moose. When moose.seed( x ) is called, this variable is set...
Definition: global.cpp:45
int getGlobalSeed()
Definition: global.cpp:206
string toFilename(const string &path)
Replace all directory sepearator with _. This creates a filepath which can be created in current dire...
Definition: global.cpp:161
string createMOOSEPath(const string &path)
Create a POSIX compatible path from a given string. Remove/replace bad characters.
Definition: global.cpp:105
int checkPath(const string &path)
Checks if given path is correct. If not, return false and error-code as well.
Definition: global.cpp:50
double mtrand(void)
Generate a random double between 0 and 1.
Definition: global.cpp:97
unsigned int totalTests
Keep tracks of how many tests have been executed in moose.
Definition: global.cpp:30
static char path[]
Definition: mfield.cpp:403