10 #include <boost/any.hpp> 19 typedef std::pair<const std::type_info *, int>
Type;
21 typedef std::pair<Type, Offset>
Format;
27 static std::string
Clean(std::string s);
36 T
Get(std::stringstream &line)
const;
38 bool GetBool(std::stringstream &line)
const;
39 std::string
GetString(std::stringstream &line)
const;
43 void GetBinImp(std::vector<char> &v,
const T &val)
const;
45 void GetBinImp(std::vector<boost::any> &v,
const T &val)
const;
47 void GetBinString(std::vector<char> &v,
const std::string &val)
const;
48 void GetBinString(std::vector<boost::any> &v,
const std::string &val)
const;
53 std::string
GetString(
const char* &ptr)
const;
61 std::vector<T>
Get(
const std::string &
str)
const;
63 T
Get(
const void *d,
size_t size)
const;
68 void Add(std::string &
str,
const char* &ptr)
const;
69 void AddString(std::string &
str,
const char* &ptr)
const;
71 void Add(std::vector<boost::any> &vec,
const char* &ptr)
const;
72 void AddString(std::vector<boost::any> &vec,
const char* &ptr)
const;
76 Converter(std::ostream &out,
const std::string &fmt,
bool strict=
true);
77 Converter(
const std::string &fmt,
bool strict=
true);
80 bool empty()
const {
return fList.size()==1 && fList.back().first.second==0; }
83 bool valid()
const {
return !fList.empty() && fList.back().first.second==0; }
89 size_t GetSize()
const {
return fList.size()==0 ? 0 : fList.back().second.second; }
91 static FormatList
Compile(std::ostream &out,
const std::string &fmt,
bool strict=
false);
92 static FormatList
Compile(
const std::string &fmt,
bool strict=
false);
95 std::vector<char>
GetVector(
const void *d,
size_t size)
const;
96 std::vector<boost::any>
GetAny(
const void *d,
size_t size)
const;
98 std::vector<boost::any>
GetAny(
const std::string &
str)
const;
99 std::vector<char>
GetVector(
const std::string &str)
const;
101 std::vector<std::string>
ToStrings(
const void *src)
const;
102 void ToFits(
void* dest,
const void* src,
size_t size)
const;
104 std::vector<char>
ToFits(
const void* src,
size_t size)
const;
107 static std::string
ToFormat(
const std::vector<std::string> &
fits);
110 static std::string
GetHex(
const void *dat,
size_t size,
size_t col=0,
bool prefix=
true)
112 if (size%
sizeof(T)!=0)
113 throw std::runtime_error(
"GetHex: Total not dividable by typesize.");
115 const T *ptr =
reinterpret_cast<const T*
>(dat);
117 std::ostringstream text;
120 const size_t w = nearbyint(ceil(log2(size+1)))/4+1;
122 for (
size_t i=0;
i<size/
sizeof(T);
i++)
124 if (prefix && col!=0 &&
i%col==0)
125 text << std::setfill(
'0') << std::setw(w) <<
i <<
"| ";
127 text << std::setfill(
'0') << std::setw(2*
sizeof(T));
128 text << (
unsigned int)ptr[i] <<
':';
130 if (col!=0 && i%col==col-1)
138 template<
typename T,
typename S>
139 static std::string
GetHex(
const S &s,
size_t col=0,
bool prefix=
true)
141 return GetHex<T>(&s,
sizeof(S), col, prefix);
144 void Print(std::ostream &out)
const;
147 static std::vector<std::string>
Regex(
const std::string &expr,
const std::string &line);
static std::string GetHex(const S &s, size_t col=0, bool prefix=true)
std::vector< Format > FormatList
T Get(std::stringstream &line) const
Compiled format description.
void Add(std::string &str, const char *&ptr) const
std::vector< boost::any > GetAny(const void *d, size_t size) const
const FormatList & GetList() const
std::string GetString(std::stringstream &line) const
static std::string Clean(std::string s)
void GetBinImp(std::vector< char > &v, const T &val) const
static FormatList Compile(std::ostream &out, const std::string &fmt, bool strict=false)
static std::vector< std::string > Regex(const std::string &expr, const std::string &line)
void GetBinString(std::vector< char > &v, const std::string &val) const
bool GetBool(std::stringstream &line) const
std::pair< const std::type_info *, int > Type
static std::string GetHex(const void *dat, size_t size, size_t col=0, bool prefix=true)
std::pair< Type, Offset > Format
static std::string ToFormat(const std::vector< std::string > &fits)
std::pair< int, int > Offset
std::string GetStringEol(std::stringstream &line) const
Converter(std::ostream &out, const std::string &fmt, bool strict=true)
const FormatList fList
Original format string.
A compiler for the DIM data format string.
void AddString(std::string &str, const char *&ptr) const
std::vector< std::string > ToStrings(const void *src) const
const std::string fFormat
ostream to which output is redirected
std::vector< std::string > GetFitsFormat() const
std::vector< char > GetVector(const void *d, size_t size) const
void ToFits(void *dest, const void *src, size_t size) const