Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef ATOOLS_Org_Data_Reader_H
0002 #define ATOOLS_Org_Data_Reader_H
0003 
0004 #include "ATOOLS/Org/Read_Write_Base.H"
0005 
0006 namespace ATOOLS {
0007 
0008   class Data_Reader: public Read_Write_Base {
0009   protected:
0010     
0011     std::string m_string;
0012 
0013     bool m_allowunits;
0014 
0015     template <class Read_Type > Read_Type 
0016     Convert(std::string cur) const;
0017 
0018     template <class Read_Type > Read_Type 
0019     ReadValue(const std::string &parameter,const size_t &file);
0020     template <class Read_Type > std::vector<Read_Type> 
0021     ReadVector(const std::string &parameter,const size_t &file);
0022     template <class Read_Type > std::vector< std::vector<Read_Type> > 
0023     ReadMatrix(const std::string &parameter,const size_t &file);   
0024 
0025   public:
0026 
0027     // constructors
0028     Data_Reader();
0029     Data_Reader(const std::string &wordsep,const std::string &linesep,
0030         const std::string &comment,const std::string &ignore="");
0031 
0032     // destructor
0033     ~Data_Reader();
0034 
0035     // member functions
0036     template <class Read_Type >
0037     bool ReadFromFile(Read_Type& value,std::string parameter=nullstring);
0038     template <class Read_Type >
0039     bool ReadFromString(Read_Type& value,std::string parameter=nullstring);
0040 
0041     template <class Read_Type >
0042     bool VectorFromFile(std::vector<Read_Type>& values,
0043             std::string parameter=nullstring);
0044     template <class Read_Type >
0045     bool VectorFromString(std::vector<Read_Type>& values,
0046               std::string parameter=nullstring);
0047 
0048     template <class Read_Type >
0049     bool MatrixFromFile(std::vector<std::vector<Read_Type> >& values,
0050             std::string parameter=nullstring);
0051     template <class Read_Type >
0052     bool MatrixFromString(std::vector<std::vector<Read_Type> >& values,
0053               std::string parameter=nullstring);
0054 
0055     std::string GetStringNormalisingNoneLikeValues(const std::string &parameter,
0056                                                    const std::string &def);
0057     bool StringVectorFromFileNormalisingNoneLikeValues(std::vector<std::string>& vals,
0058                                                        std::string parameter=nullstring);
0059     bool StringVectorFromStringNormalisingNoneLikeValues(std::vector<std::string>& vals,
0060                                                          std::string parameter=nullstring);
0061 
0062     void SetString(const std::string string, bool multiline=false);
0063 
0064     void RescanFileContent(const std::string content, bool multiline=false);
0065 
0066     // inline functions
0067     inline const std::string String() const
0068     { return m_string; }
0069 
0070     template <class Read_Type> inline Read_Type
0071     GetValue(const std::string &parameter,const Read_Type &def)
0072     { 
0073       Read_Type val; 
0074       if (!ReadFromFile(val,parameter)) return def; 
0075       return val; 
0076     }
0077 
0078     template <class Read_Type> inline Read_Type
0079     StringValue(const std::string &parameter,const Read_Type &def)
0080     { 
0081       Read_Type val; 
0082       if (!ReadFromString(val,parameter)) return def; 
0083       return val; 
0084     }
0085 
0086     inline void SetAllowUnits(const bool units) { m_allowunits=units; }
0087 
0088     inline bool AllowUnits() const { return m_allowunits; }
0089 
0090     static inline void NormaliseNoneLikeValue(std::string & value) {
0091       if (value == "None" || value == "Off" || value == "0") {
0092         value = "None";
0093       }
0094     }
0095 
0096   }; // end of class Data_Reader
0097 
0098 } // end of namespace ATOOLS
0099 
0100 #endif