Changeset 10270 for trunk/FACT++/src/Converter.h
- Timestamp:
- 03/30/11 15:41:11 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Converter.h
r10219 r10270 9 9 class Converter 10 10 { 11 public: 12 typedef std::pair<const std::type_info *, int> Type; 13 typedef std::pair<int, int> Offset; 14 typedef std::pair<Type, Offset> Format; 15 typedef std::vector<Format> FormatList; 16 17 struct O { }; 18 struct W { }; 19 20 static std::string Clean(std::string s); 21 11 22 private: 12 bool rc; /// Flag for the success of the conversion 13 std::ostream &wout; /// ostream to which output is redirected 14 std::vector<char> data; /// data storage 15 std::vector<boost::any> vec; /// storage for typed data 23 std::ostream &wout; /// ostream to which output is redirected 24 25 const std::string fFormat; /// Original format string 26 const FormatList fList; /// Compiled format description 27 28 template <class T> 29 T Get(std::stringstream &line) const; 30 31 bool GetBool(std::stringstream &line) const; 32 std::string GetString(std::stringstream &line) const; 33 std::string GetStringEol(std::stringstream &line) const; 16 34 17 35 template<class T> 18 void EvalImp(int i, std::stringstream &line, std::vector<char> &v, const T &val);36 void GetBinImp(std::vector<char> &v, const T &val) const; 19 37 template<class T> 20 void Eval(int i, std::stringstream &line, std::vector<char> &v); 21 void EvalBool(int i, std::stringstream &line, std::vector<char> &v); 22 void EvalString(int i, std::stringstream &line, std::vector<char> &v); 38 void GetBinImp(std::vector<boost::any> &v, const T &val) const; 39 40 void GetBinString(std::vector<char> &v, const std::string &val) const; 41 void GetBinString(std::vector<boost::any> &v, const std::string &val) const; 23 42 24 43 template<class T> 25 std::string Get(const char *&data); 44 std::string GetString(const char *&data) const; 45 46 template<class T> 47 static Type GetType(); 48 template<class T> 49 static Type GetVoid(); 50 51 template <class T> 52 std::vector<T> Get(const std::string &str) const; 53 template <class T> 54 T Get(const void *d, int size) const; 55 56 57 58 template<class T> 59 void Add(std::string &str, const char* &ptr) const; 60 void AddString(std::string &str, const std::string &ptr) const; 61 template<class T> 62 void Add(std::vector<boost::any> &vec, const char* &ptr) const; 63 void AddString(std::vector<boost::any> &vec, const std::string &ptr) const; 64 26 65 27 66 public: 28 Converter(std::ostream &out, const std::string &fmt, const std::string &str);29 Converter( std::ostream &out, const std::string &fmt, const void *d, int size);67 Converter(std::ostream &out, const std::string &fmt, bool strict=true); 68 Converter(const std::string &fmt, bool strict=true); 30 69 31 /// Returns whether the conversion was successfull32 bool GetRc() const { return rc; }70 /// @returns whether the interpreted format was valid but empty ("") 71 bool empty() const { return fList.size()==1 && fList.back().first.second==0; } 33 72 34 /// const Pointer to the data memory 35 const char *Ptr() const { return &*data.begin(); } 36 /// non-const Pointer to the data memory (for convinience using Dim) 37 char *Ptr() { return &*data.begin(); } 73 /// @returns whether the compilation was successfull 74 bool valid() const { return !fList.empty() && fList.back().first.second==0; } 38 75 39 /// Return the size of the data memory40 int Size() const { return data.size(); }76 /// @returns true if the compilation failed 77 bool operator!() const { return !valid(); } 41 78 42 /// Return the data memory converted into a string (not necessarily \0-terminated) 43 const std::string Str() const { return std::string(&*data.begin(), data.size()); } 79 const FormatList &GetList() const { return fList; } 44 80 81 static FormatList Compile(std::ostream &out, const std::string &fmt, bool strict=false); 82 static FormatList Compile(const std::string &fmt, bool strict=false); 45 83 84 std::string GetString(const void *d, int size) const; 85 std::vector<char> GetVector(const void *d, int size) const; 86 std::vector<boost::any> GetAny(const void *d, int size) const; 87 88 std::vector<boost::any> GetAny(const std::string &str) const; 89 std::vector<char> GetVector(const std::string &str) const; 90 91 static std::string GetHex(const void *d, int size); 92 93 /* 46 94 // Returns the number of entries in Converter:vec 47 95 int N() const { return vec.size(); } … … 58 106 template <class T> 59 107 T At(int i) const { return boost::any_cast<T>(vec[i]); } 60 108 */ 61 109 62 110 static std::vector<std::string> Regex(const std::string &expr, const std::string &line);
Note:
See TracChangeset
for help on using the changeset viewer.