00001 // Copyright CERN 2012 - Developed in collaboration with GSI 00002 00012 #ifndef _FESA_STREAM_H_ 00013 #define _FESA_STREAM_H_ 00014 00015 #include <fstream> 00016 #include <sstream> 00017 #include <string> 00018 #include <map> 00019 00020 namespace fesa 00021 { 00022 00023 class FesaStream: public std::ostringstream 00024 { 00025 public: 00026 00027 FesaStream(const std::string streamName); 00028 00029 //instantiate or just retrieve a config stream object (one FesaStream per independent Fesa project). 00030 static FesaStream* getConfigStream(const std::string streamName); 00031 00032 static FesaStream* getStateStream(const std::string streamName); 00033 00034 std::string getFileName() const 00035 { 00036 return fileName_; 00037 } 00038 00039 //Create and generate configFile from current ostream buffer 00040 bool update(); 00041 //Read file and return contain in a string format 00042 bool read(std::string& streamName); 00043 00044 //Header/Footer of the file 00045 static std::string configHeader_, configFooter_; 00046 static std::string stateHeader_, stateFooter_; 00047 00048 private: 00049 00050 static FesaStream* getFileStream(const std::string streamName); 00051 00052 std::string* fileHeader_; 00053 std::string* fileFooter_; 00054 std::string fileName_; //Config file name 00055 std::fstream fileStream_; //Config file stream 00056 00057 // Map to register FesaStream objects 00058 static std::map<std::string, FesaStream*> fileFactoryMap_; 00059 }; 00060 00061 } // fesa 00062 00063 #endif // _FESA_STREAM_H_