diff options
author | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2005-05-28 12:04:33 +0000 |
---|---|---|
committer | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2005-05-28 12:04:33 +0000 |
commit | 5555ec71ef4be69a2f4425554d030829a33baac2 (patch) | |
tree | 9f3052433dbd2d8e478974e8ccdf682150ca284e /src/file.cc | |
parent | d41baa0734e66bfe72ffe848ac5fa2fa69ce68f5 (diff) |
Make announcing to the portal work
git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@17 83718e91-0e4f-0410-abf4-91180603181f
Diffstat (limited to 'src/file.cc')
-rw-r--r-- | src/file.cc | 99 |
1 files changed, 97 insertions, 2 deletions
diff --git a/src/file.cc b/src/file.cc index 8982434..2bff9b8 100644 --- a/src/file.cc +++ b/src/file.cc @@ -1,5 +1,7 @@ // $Header$ +#include <iomanip> +#include <ios> #include <sstream> #include "cctk_Parameters.h" @@ -13,14 +15,23 @@ using namespace std; file:: -file (char const * const id) +file (char const * const id, + enum state const st) + : storage (st) { DECLARE_CCTK_PARAMETERS; ostringstream filenamebuf; filenamebuf << out_dir << "/" << storage_filename; string const filenamestring = filenamebuf.str(); - fil.open (filenamestring.c_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); + } } @@ -28,13 +39,97 @@ file (char const * const id) file:: ~ file () { + if (get_state() == final) + { + store ("simulation", "done"); + } fil.close(); } void file:: +store (char const * const key, + int const value) +{ + assert (key); + + ostringstream keybuf; + keybuf << 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, + double const value) +{ + assert (key); + + ostringstream keybuf; + keybuf << key; + ostringstream valuebuf; + valuebuf << setprecision(15) << value; + + ostringstream buf; + buf << clean (keybuf.str()) << "=" << clean (valuebuf.str()) << endl; + + write (buf.str()); +} + + + +void file:: +store (char const * const key, + char const * const value) +{ + assert (key); + + ostringstream keybuf; + keybuf << 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) { fil << msg; } + + + +string file:: +clean (string const & txt) + const +{ + ostringstream buf; + + for (string::const_iterator p = txt.begin(); p != txt.end(); ++ p) + { + switch (* p) + { + case '=': buf << "\\="; break; + case '"': buf << "\\\""; break; + case '\\': buf << "\\\\"; break; + default: buf << * p; + } + } + + return buf.str(); +} |