Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:09:52

0001 #ifndef ATOOLS_Org_My_File_H
0002 #define ATOOLS_Org_My_File_H
0003 
0004 #include "ATOOLS/Org/MyStrStream.H"
0005 
0006 #include <fstream>
0007 #include <vector>
0008 #include <string>
0009 #include <map>
0010 #include <memory>
0011 
0012 namespace ATOOLS {
0013 
0014   const std::string nullstring("");
0015 
0016   struct fom {
0017     
0018     enum code {
0019       temporary =  1,
0020       permanent =  2,
0021       unknown   = 99
0022     };
0023 
0024   };// end of struct fom
0025     
0026   inline fom::code operator|(const fom::code c1,const fom::code c2)
0027   { return (fom::code)((int)c1|(int)c2); }
0028 
0029   std::ostream &operator<<(std::ostream &ostr,const fom::code &code);
0030 
0031   template <class FileType>
0032   class My_File {
0033   public:
0034 
0035     typedef FileType File_Type;
0036 
0037   protected:
0038 
0039     std::string m_path, m_file;
0040 
0041     std::shared_ptr<File_Type>   p_file;
0042     std::shared_ptr<MyStrStream> p_stream;
0043     
0044     fom::code m_mode;
0045 
0046   public:
0047 
0048     // constructor
0049     My_File(const std::string &path="",const std::string &file="");
0050     // destructor
0051     ~My_File();
0052 
0053     // member functions
0054     bool Open();
0055     bool Close();
0056 
0057     //inline functions
0058     void SetPath(const std::string &path);
0059     void SetFile(const std::string &file);
0060 
0061     void SetMode(const fom::code &mode);
0062 
0063     const std::string &Path() const;
0064     const std::string &File() const;
0065 
0066     const fom::code &Mode() const;
0067 
0068     File_Type *operator()() const;
0069     File_Type *operator->() const;
0070     File_Type &operator*() const;
0071 
0072     // static member functions
0073     static bool OpenDB(std::string file);
0074     static bool CloseDB(std::string file,int mode=1);
0075 
0076     static bool FileInDB(const std::string &name);
0077     static bool CopyInDB(std::string oldfile, std::string newfile);
0078 
0079     std::string FileContent() const
0080     { return p_stream!=NULL?p_stream->str():""; }
0081 
0082   };// end of class My_File
0083 
0084   template<class FileType>
0085   std::ostream &operator<<(std::ostream &ostr,
0086                const My_File<FileType> &file);
0087 
0088 }// end of namespace ATOOLS
0089 
0090 #define My_In_File ATOOLS::My_File<std::ifstream>
0091 #define My_Out_File ATOOLS::My_File<std::ofstream>
0092 
0093 #endif