diff options
Diffstat (limited to 'src/file.cc')
-rw-r--r-- | src/file.cc | 128 |
1 files changed, 76 insertions, 52 deletions
diff --git a/src/file.cc b/src/file.cc index 9300403..cc93ca9 100644 --- a/src/file.cc +++ b/src/file.cc @@ -8,87 +8,104 @@ #include "file.hh" +using namespace std; + namespace Formaline { - - using namespace std; - - - + file:: file (char const * const id, - enum state const st) - : storage (st) + enum state const st, + char const * const p, + file * const par) + : storage (st), path (p), parent (par) { DECLARE_CCTK_PARAMETERS; - + + if (parent) return; + ostringstream filenamebuf; filenamebuf << out_dir << "/" << storage_filename; string const filenamestring = filenamebuf.str(); - + ios::openmode const mode = get_state() == initial ? ios::trunc : ios::app; fil.open (filenamestring.c_str(), mode); - + if (get_state() == initial) { store ("jobid", id); } } - - - + + + file:: ~ file () { - if (get_state() == final) + if (parent) return; + + if (get_state()) { store ("simulation", "done"); } fil.close(); } - - - + + + + file * file:: + open_group (char const * const name) + { + assert (name); + string name1 (name); + if (not name1.empty() and name1[name1.length()-1] != '/') { + name1 = name1 + "/"; + } + return new file (0, get_state (), name1.c_str(), this); + } + + + void file:: store (char const * const key, bool const value) { assert (key); - + ostringstream keybuf; - keybuf << key; + keybuf << path << key; ostringstream valuebuf; valuebuf << (value ? "yes" : "no"); - + ostringstream buf; buf << clean (keybuf.str()) << "=" << clean (valuebuf.str()) << endl; - + write (buf.str()); } - - - + + + void file:: store (char const * const key, CCTK_INT const value) { assert (key); - + ostringstream keybuf; - keybuf << key; + keybuf << path << key; ostringstream valuebuf; valuebuf << value; - + ostringstream buf; buf << clean (keybuf.str()) << "=" << clean (valuebuf.str()) << endl; - + write (buf.str()); } - - - + + + void file:: store (char const * const key, CCTK_REAL const value) @@ -98,7 +115,7 @@ namespace Formaline int const prec = numeric_limits<CCTK_REAL>::digits10; ostringstream keybuf; - keybuf << key; + keybuf << path << key; ostringstream valuebuf; valuebuf << setprecision(prec) << value; @@ -107,43 +124,50 @@ namespace Formaline write (buf.str()); } - - - + + + void file:: store (char const * const key, char const * const value) { assert (key); - + ostringstream keybuf; - keybuf << key; + keybuf << path << key; ostringstream valuebuf; valuebuf << value; - + ostringstream buf; buf << clean (keybuf.str()) << "=" << "\"" << clean (valuebuf.str()) << "\"" << endl; - + write (buf.str()); } - - - + + + void file:: - write (std::string const & msg) + write (string const & msg) { - fil << msg; + if (parent) + { + parent->write (msg); + } + else + { + fil << msg; + } } - - - + + + string file:: clean (string const & txt) const { ostringstream buf; - + for (string::const_iterator p = txt.begin(); p != txt.end(); ++ p) { switch (* p) @@ -154,10 +178,10 @@ namespace Formaline default: buf << * p; } } - + return buf.str(); } - - - + + + } // namespace Formaline |