57 static const char SINGLE_QUOTE;
58 static const char DOUBLE_QUOTE;
60 typedef std::map<char, const char *> conv_map_t;
63 const conv_map_t conversion;
68 static const objType NONE=0;
69 static const objType KEY=1;
70 static const objType VALUE=2;
71 static const objType PAIR=KEY|VALUE;
72 static const objType LIST=4;
73 static const objType SET=8;
74 static const objType MAP=16;
75 static const objType MAP_KEY=MAP|KEY;
76 static const objType MAP_VALUE=MAP|VALUE;
77 static const objType MAP_PAIR=MAP|PAIR;
78 static const objType TUPLE=64;
79 static const objType STRING=128;
87 void writePrefix(std::ostream & ostr, objType type)
const {};
90 void writeSeparator(std::ostream & ostr, objType type)
const {
96 void writeSuffix(std::ostream & ostr, objType type)
const {};
100 void toStream(std::ostream & ostr,
const T & x, objType hint=NONE)
const ;
105 void toStream(std::ostream & ostr,
const std::list<T> & x)
const {
106 this->iterableToStream(ostr, x, LIST);
110 void toStream(std::ostream & ostr,
const std::set<T> & x)
const {
111 this->iterableToStream(ostr, x, SET);
114 template <
class K,
class V>
115 void toStream(std::ostream & ostr,
const std::map<K,V> & x)
const {
116 this->iterableToStream(ostr, x, MAP);
119 template <
class K,
class V>
120 void toStream(std::ostream & ostr,
const std::pair<K,V> & x)
const {
121 this->pairToStream(ostr, x);
125 template <
class K,
class V>
127 this->pairToStream(ostr, x, MAP_PAIR);
138 void iterableToStream(std::ostream & ostr,
const T & x, objType iterableType = NONE)
const {
139 writePrefix(ostr, iterableType);
140 objType separatorType = NONE;
141 for (
const auto & entry: x){
142 this->writeSeparator(ostr, separatorType);
145 separatorType = iterableType;
147 writeSuffix(ostr, iterableType);
150 template <
class K,
class V>
151 void pairToStream(std::ostream & ostr,
const std::pair<K,V> & x, objType containerType= NONE)
const {
153 this->writePrefix(ostr, PAIR|containerType);
155 this->writePrefix(ostr, KEY|containerType);
157 this->writeSuffix(ostr, KEY|containerType);
159 this->writeSeparator(ostr, PAIR|containerType);
161 this->writePrefix(ostr, VALUE|containerType);
163 this->writeSuffix(ostr, VALUE|containerType);
165 this->writeSuffix(ostr, PAIR|containerType);
170 void toStream(std::ostream & ostr,
char c)
const {
171 this->charToStream(ostr, c);
175 void toStream(std::ostream & ostr,
const char *x)
const {
176 this->stringToStream(ostr, x);
180 void toStream(std::ostream & ostr,
const std::string &x)
const {
181 this->stringToStream(ostr, x);
185 void toStream(std::ostream & ostr,
bool x)
const {
186 this->boolToStream(ostr, x);
190 void toStream(std::ostream & ostr,
const nullptr_t & t)
const {
191 this->nullToStream(ostr);
197 void toStr(std::string & str,
const T & x)
const {
198 std::stringstream sstr;
206 void floatToStream(std::ostream & ostr,
double x)
const {
211 void intToStream(std::ostream & ostr,
int x)
const {
216 void boolToStream(std::ostream & ostr,
bool x)
const {
219 ostr << std::boolalpha;
224 void nullToStream(std::ostream & ostr)
const {
229 void charToStream(std::ostream & ostr,
char c)
const {
234 void stringToStream(std::ostream & ostr,
const char *x)
const {
239 void stringToStream(std::ostream & ostr,
const std::string & x)
const final {
240 stringToStream(ostr, x.c_str());
296 typedef std::map<objType,SimpleFormatter> char_map_t;
310 void writePrefix(std::ostream & ostr, objType type)
const override {
311 writePrefix(ostr, getFormatter(type));
315 void writePrefix(std::ostream & ostr,
const SimpleFormatter & fmt)
const {
322 void writeSeparator(std::ostream & ostr, objType type)
const override {
323 writeSeparator(ostr, getFormatter(type));
327 void writeSeparator(std::ostream & ostr,
const SimpleFormatter & fmt)
const {
329 ostr << fmt.separator;
334 void writeSuffix(std::ostream & ostr, objType type)
const override {
335 writeSuffix(ostr, getFormatter(type));
339 void writeSuffix(std::ostream & ostr,
const SimpleFormatter & fmt)
const {
347 void stringToStream(std::ostream & ostr,
const char * x)
const override {
348 charsToStream(ostr, x);
360 charsToStream(ostr, c);
367 char_map_t fmtChars = {
376 const SimpleFormatter & getFormatter(objType t)
const;
380 void charsToStream(std::ostream & ostr,
const S &s)
const;
383 void handleChars(std::ostream & ostr,
char c)
const;
386 void handleChars(std::ostream & ostr,
const char *c)
const;