#ifndef FACT_Converter #define FACT_Converter #include #include #include class Converter { private: bool rc; /// Flag for the success of the conversion std::ostream &wout; /// ostream to which output is redirected std::vector data; /// data storage std::vector vec; /// storage for typed data template void EvalImp(int i, std::stringstream &line, std::vector &v, const T &val); template void Eval(int i, std::stringstream &line, std::vector &v); void EvalBool(int i, std::stringstream &line, std::vector &v); void EvalString(int i, std::stringstream &line, std::vector &v); template std::string Get(const char *&data); public: Converter(std::ostream &out, const std::string &fmt, const std::string &str); Converter(std::ostream &out, const std::string &fmt, const void *d, int size); /// Returns whether the conversion was successfull bool GetRc() const { return rc; } /// const Pointer to the data memory const char *Ptr() const { return &*data.begin(); } /// non-const Pointer to the data memory (for convinience using Dim) char *Ptr() { return &*data.begin(); } /// Return the size of the data memory int Size() const { return data.size(); } /// Return the data memory converted into a string (not necessarily \0-terminated) const std::string Str() const { return std::string(&*data.begin(), data.size()); } // Returns the number of entries in Converter:vec int N() const { return vec.size(); } /// Checks if an entry with the given class type is available at index i in Converter::vec template bool Has(unsigned int i) const { return i T Get(int i) const { return !Has(i) ? T() : boost::any_cast(vec[i]); } /// return the entry with the given class type at index i from Converter::vec (throws exceptions) template T At(int i) const { return boost::any_cast(vec[i]); } static std::vector Regex(const std::string &expr, const std::string &line); }; #endif