58 static const char SINGLE_QUOTE;
59 static const char DOUBLE_QUOTE;
61 typedef std::map<char, const char *> conv_map_t;
64 const conv_map_t conversion;
69 static const objType NONE=0;
70 static const objType KEY=1;
71 static const objType VALUE=2;
72 static const objType PAIR=KEY|VALUE;
73 static const objType LIST=4;
74 static const objType SET=8;
75 static const objType MAP=16;
76 static const objType MAP_KEY=MAP|KEY;
77 static const objType MAP_VALUE=MAP|VALUE;
78 static const objType MAP_PAIR=MAP|PAIR;
79 static const objType TUPLE=64;
80 static const objType STRING=128;
88 void writePrefix(std::ostream & ostr, objType type)
const {};
91 void writeSeparator(std::ostream & ostr, objType type)
const {
97 void writeSuffix(std::ostream & ostr, objType type)
const {};
101 void toStream(std::ostream & ostr,
const T & x, objType hint=NONE)
const ;
106 void toStream(std::ostream & ostr,
const std::list<T> & x)
const {
107 this->iterableToStream(ostr, x, LIST);
111 void toStream(std::ostream & ostr,
const std::set<T> & x)
const {
112 this->iterableToStream(ostr, x, SET);
115 template <
class K,
class V>
116 void toStream(std::ostream & ostr,
const std::map<K,V> & x)
const {
117 this->iterableToStream(ostr, x, MAP);
120 template <
class K,
class V>
121 void toStream(std::ostream & ostr,
const std::pair<K,V> & x)
const {
122 this->pairToStream(ostr, x);
126 template <
class K,
class V>
128 this->pairToStream(ostr, x, MAP_PAIR);
139 void iterableToStream(std::ostream & ostr,
const T & x, objType iterableType = NONE)
const {
140 writePrefix(ostr, iterableType);
141 objType separatorType = NONE;
142 for (
const auto & entry: x){
143 this->writeSeparator(ostr, separatorType);
146 separatorType = iterableType;
148 writeSuffix(ostr, iterableType);
151 template <
class K,
class V>
152 void pairToStream(std::ostream & ostr,
const std::pair<K,V> & x, objType containerType= NONE)
const {
154 this->writePrefix(ostr, PAIR|containerType);
156 this->writePrefix(ostr, KEY|containerType);
158 this->writeSuffix(ostr, KEY|containerType);
160 this->writeSeparator(ostr, PAIR|containerType);
162 this->writePrefix(ostr, VALUE|containerType);
164 this->writeSuffix(ostr, VALUE|containerType);
166 this->writeSuffix(ostr, PAIR|containerType);
171 void toStream(std::ostream & ostr,
char c)
const {
172 this->charToStream(ostr, c);
176 void toStream(std::ostream & ostr,
const char *x)
const {
177 this->stringToStream(ostr, x);
181 void toStream(std::ostream & ostr,
const std::string &x)
const {
182 this->stringToStream(ostr, x);
186 void toStream(std::ostream & ostr,
bool x)
const {
187 this->boolToStream(ostr, x);
191 void toStream(std::ostream & ostr,
const nullptr_t & t)
const {
192 this->nullToStream(ostr);
198 void toStr(std::string & str,
const T & x)
const {
199 std::stringstream sstr;
207 void floatToStream(std::ostream & ostr,
double x)
const {
212 void intToStream(std::ostream & ostr,
int x)
const {
217 void boolToStream(std::ostream & ostr,
bool x)
const {
218 ostr << std::ios_base::boolalpha;
223 void nullToStream(std::ostream & ostr)
const {
228 void charToStream(std::ostream & ostr,
char c)
const {
233 void stringToStream(std::ostream & ostr,
const char *x)
const {
238 void stringToStream(std::ostream & ostr,
const std::string & x)
const final {
239 stringToStream(ostr, x.c_str());
295 typedef std::map<objType,SimpleFormatter> char_map_t;
309 void writePrefix(std::ostream & ostr, objType type)
const override {
310 writePrefix(ostr, getFormatter(type));
314 void writePrefix(std::ostream & ostr,
const SimpleFormatter & fmt)
const {
321 void writeSeparator(std::ostream & ostr, objType type)
const override {
322 writeSeparator(ostr, getFormatter(type));
326 void writeSeparator(std::ostream & ostr,
const SimpleFormatter & fmt)
const {
328 ostr << fmt.separator;
333 void writeSuffix(std::ostream & ostr, objType type)
const override {
334 writeSuffix(ostr, getFormatter(type));
338 void writeSuffix(std::ostream & ostr,
const SimpleFormatter & fmt)
const {
346 void stringToStream(std::ostream & ostr,
const char * x)
const override {
347 charsToStream(ostr, x);
359 charsToStream(ostr, c);
366 char_map_t fmtChars = {
375 const SimpleFormatter & getFormatter(objType t)
const;
379 void charsToStream(std::ostream & ostr,
const S &s)
const;
382 void handleChars(std::ostream & ostr,
char c)
const;
385 void handleChars(std::ostream & ostr,
const char *c)
const;