use templates in the sax interface instead of virtuals
This commit is contained in:
		
							parent
							
								
									f6febbe359
								
							
						
					
					
						commit
						442886d040
					
				
					 10 changed files with 207 additions and 209 deletions
				
			
		|  | @ -34,68 +34,68 @@ using nlohmann::json; | |||
| 
 | ||||
| #include <fstream> | ||||
| 
 | ||||
| class SaxCountdown : public nlohmann::json::json_sax_t | ||||
| class SaxCountdown | ||||
| { | ||||
|   public: | ||||
|     explicit SaxCountdown(const int count) : events_left(count) | ||||
|     {} | ||||
| 
 | ||||
|     bool null() override | ||||
|     bool null() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool boolean(bool) override | ||||
|     bool boolean(bool) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_integer(json::number_integer_t) override | ||||
|     bool number_integer(json::number_integer_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_unsigned(json::number_unsigned_t) override | ||||
|     bool number_unsigned(json::number_unsigned_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_float(json::number_float_t, const std::string&) override | ||||
|     bool number_float(json::number_float_t, const std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool string(std::string&) override | ||||
|     bool string(std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool start_object(std::size_t) override | ||||
|     bool start_object(std::size_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool key(std::string&) override | ||||
|     bool key(std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool end_object() override | ||||
|     bool end_object() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool start_array(std::size_t) override | ||||
|     bool start_array(std::size_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool end_array() override | ||||
|     bool end_array() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool parse_error(std::size_t, const std::string&, const json::exception&) override | ||||
|     bool parse_error(std::size_t, const std::string&, const json::exception&) | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
|  |  | |||
|  | @ -35,48 +35,48 @@ using nlohmann::json; | |||
| 
 | ||||
| #include <valarray> | ||||
| 
 | ||||
| class SaxEventLogger : public nlohmann::json::json_sax_t | ||||
| class SaxEventLogger | ||||
| { | ||||
|   public: | ||||
|     bool null() override | ||||
|     bool null() | ||||
|     { | ||||
|         events.push_back("null()"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool boolean(bool val) override | ||||
|     bool boolean(bool val) | ||||
|     { | ||||
|         events.push_back(val ? "boolean(true)" : "boolean(false)"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool number_integer(json::number_integer_t val) override | ||||
|     bool number_integer(json::number_integer_t val) | ||||
|     { | ||||
|         events.push_back("number_integer(" + std::to_string(val) + ")"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool number_unsigned(json::number_unsigned_t val) override | ||||
|     bool number_unsigned(json::number_unsigned_t val) | ||||
|     { | ||||
|         events.push_back("number_unsigned(" + std::to_string(val) + ")"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool number_float(json::number_float_t, const std::string& s) override | ||||
|     bool number_float(json::number_float_t, const std::string& s) | ||||
|     { | ||||
|         events.push_back("number_float(" + s + ")"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool string(std::string& val) override | ||||
|     bool string(std::string& val) | ||||
|     { | ||||
|         events.push_back("string(" + val + ")"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool start_object(std::size_t elements) override | ||||
|     bool start_object(std::size_t elements = -1) | ||||
|     { | ||||
|         if (elements == no_limit) | ||||
|         if (elements == std::size_t(-1)) | ||||
|         { | ||||
|             events.push_back("start_object()"); | ||||
|         } | ||||
|  | @ -87,21 +87,21 @@ class SaxEventLogger : public nlohmann::json::json_sax_t | |||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool key(std::string& val) override | ||||
|     bool key(std::string& val) | ||||
|     { | ||||
|         events.push_back("key(" + val + ")"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool end_object() override | ||||
|     bool end_object() | ||||
|     { | ||||
|         events.push_back("end_object()"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool start_array(std::size_t elements) override | ||||
|     bool start_array(std::size_t elements = -1) | ||||
|     { | ||||
|         if (elements == no_limit) | ||||
|         if (elements == std::size_t(-1)) | ||||
|         { | ||||
|             events.push_back("start_array()"); | ||||
|         } | ||||
|  | @ -112,13 +112,13 @@ class SaxEventLogger : public nlohmann::json::json_sax_t | |||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool end_array() override | ||||
|     bool end_array() | ||||
|     { | ||||
|         events.push_back("end_array()"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool parse_error(std::size_t position, const std::string&, const json::exception&) override | ||||
|     bool parse_error(std::size_t position, const std::string&, const json::exception&) | ||||
|     { | ||||
|         errored = true; | ||||
|         events.push_back("parse_error(" + std::to_string(position) + ")"); | ||||
|  | @ -129,68 +129,68 @@ class SaxEventLogger : public nlohmann::json::json_sax_t | |||
|     bool errored = false; | ||||
| }; | ||||
| 
 | ||||
| class SaxCountdown : public nlohmann::json::json_sax_t | ||||
| class SaxCountdown | ||||
| { | ||||
|   public: | ||||
|     explicit SaxCountdown(const int count) : events_left(count) | ||||
|     {} | ||||
| 
 | ||||
|     bool null() override | ||||
|     bool null() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool boolean(bool) override | ||||
|     bool boolean(bool) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_integer(json::number_integer_t) override | ||||
|     bool number_integer(json::number_integer_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_unsigned(json::number_unsigned_t) override | ||||
|     bool number_unsigned(json::number_unsigned_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_float(json::number_float_t, const std::string&) override | ||||
|     bool number_float(json::number_float_t, const std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool string(std::string&) override | ||||
|     bool string(std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool start_object(std::size_t) override | ||||
|     bool start_object(std::size_t = -1) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool key(std::string&) override | ||||
|     bool key(std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool end_object() override | ||||
|     bool end_object() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool start_array(std::size_t) override | ||||
|     bool start_array(std::size_t = -1) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool end_array() override | ||||
|     bool end_array() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool parse_error(std::size_t, const std::string&, const json::exception&) override | ||||
|     bool parse_error(std::size_t, const std::string&, const json::exception&) | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
|  |  | |||
|  | @ -35,45 +35,45 @@ using nlohmann::json; | |||
| #include <iostream> | ||||
| #include <valarray> | ||||
| 
 | ||||
| struct SaxEventLogger : public nlohmann::json::json_sax_t | ||||
| struct SaxEventLogger | ||||
| { | ||||
|     bool null() override | ||||
|     bool null() | ||||
|     { | ||||
|         events.push_back("null()"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool boolean(bool val) override | ||||
|     bool boolean(bool val) | ||||
|     { | ||||
|         events.push_back(val ? "boolean(true)" : "boolean(false)"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool number_integer(json::number_integer_t val) override | ||||
|     bool number_integer(json::number_integer_t val) | ||||
|     { | ||||
|         events.push_back("number_integer(" + std::to_string(val) + ")"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool number_unsigned(json::number_unsigned_t val) override | ||||
|     bool number_unsigned(json::number_unsigned_t val) | ||||
|     { | ||||
|         events.push_back("number_unsigned(" + std::to_string(val) + ")"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool number_float(json::number_float_t, const std::string& s) override | ||||
|     bool number_float(json::number_float_t, const std::string& s) | ||||
|     { | ||||
|         events.push_back("number_float(" + s + ")"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool string(std::string& val) override | ||||
|     bool string(std::string& val) | ||||
|     { | ||||
|         events.push_back("string(" + val + ")"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool start_object(std::size_t elements) override | ||||
|     bool start_object(std::size_t elements) | ||||
|     { | ||||
|         if (elements == std::size_t(-1)) | ||||
|         { | ||||
|  | @ -86,19 +86,19 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t | |||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool key(std::string& val) override | ||||
|     bool key(std::string& val) | ||||
|     { | ||||
|         events.push_back("key(" + val + ")"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool end_object()override | ||||
|     bool end_object() | ||||
|     { | ||||
|         events.push_back("end_object()"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool start_array(std::size_t elements) override | ||||
|     bool start_array(std::size_t elements) | ||||
|     { | ||||
|         if (elements == std::size_t(-1)) | ||||
|         { | ||||
|  | @ -111,13 +111,13 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t | |||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool end_array() override | ||||
|     bool end_array() | ||||
|     { | ||||
|         events.push_back("end_array()"); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool parse_error(std::size_t position, const std::string&, const json::exception&) override | ||||
|     bool parse_error(std::size_t position, const std::string&, const json::exception&) | ||||
|     { | ||||
|         events.push_back("parse_error(" + std::to_string(position) + ")"); | ||||
|         return false; | ||||
|  | @ -128,9 +128,9 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t | |||
| 
 | ||||
| struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger | ||||
| { | ||||
|     bool start_object(std::size_t elements) override | ||||
|     bool start_object(std::size_t elements) | ||||
|     { | ||||
|         if (elements == no_limit) | ||||
|         if (elements == -1) | ||||
|         { | ||||
|             events.push_back("start_object()"); | ||||
|         } | ||||
|  | @ -144,7 +144,7 @@ struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger | |||
| 
 | ||||
| struct SaxEventLoggerExitAfterKey : public SaxEventLogger | ||||
| { | ||||
|     bool key(std::string& val) override | ||||
|     bool key(std::string& val) | ||||
|     { | ||||
|         events.push_back("key(" + val + ")"); | ||||
|         return false; | ||||
|  | @ -153,9 +153,9 @@ struct SaxEventLoggerExitAfterKey : public SaxEventLogger | |||
| 
 | ||||
| struct SaxEventLoggerExitAfterStartArray : public SaxEventLogger | ||||
| { | ||||
|     bool start_array(std::size_t elements) override | ||||
|     bool start_array(std::size_t elements) | ||||
|     { | ||||
|         if (elements == no_limit) | ||||
|         if (elements == -1) | ||||
|         { | ||||
|             events.push_back("start_array()"); | ||||
|         } | ||||
|  |  | |||
|  | @ -34,68 +34,68 @@ using nlohmann::json; | |||
| 
 | ||||
| #include <fstream> | ||||
| 
 | ||||
| class SaxCountdown : public nlohmann::json::json_sax_t | ||||
| class SaxCountdown | ||||
| { | ||||
|   public: | ||||
|     explicit SaxCountdown(const int count) : events_left(count) | ||||
|     {} | ||||
| 
 | ||||
|     bool null() override | ||||
|     bool null() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool boolean(bool) override | ||||
|     bool boolean(bool) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_integer(json::number_integer_t) override | ||||
|     bool number_integer(json::number_integer_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_unsigned(json::number_unsigned_t) override | ||||
|     bool number_unsigned(json::number_unsigned_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_float(json::number_float_t, const std::string&) override | ||||
|     bool number_float(json::number_float_t, const std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool string(std::string&) override | ||||
|     bool string(std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool start_object(std::size_t) override | ||||
|     bool start_object(std::size_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool key(std::string&) override | ||||
|     bool key(std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool end_object() override | ||||
|     bool end_object() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool start_array(std::size_t) override | ||||
|     bool start_array(std::size_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool end_array() override | ||||
|     bool end_array() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool parse_error(std::size_t, const std::string&, const json::exception&) override | ||||
|     bool parse_error(std::size_t, const std::string&, const json::exception&) | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
|  |  | |||
|  | @ -34,68 +34,68 @@ using nlohmann::json; | |||
| 
 | ||||
| #include <fstream> | ||||
| 
 | ||||
| class SaxCountdown : public nlohmann::json::json_sax_t | ||||
| class SaxCountdown | ||||
| { | ||||
|   public: | ||||
|     explicit SaxCountdown(const int count) : events_left(count) | ||||
|     {} | ||||
| 
 | ||||
|     bool null() override | ||||
|     bool null() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool boolean(bool) override | ||||
|     bool boolean(bool) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_integer(json::number_integer_t) override | ||||
|     bool number_integer(json::number_integer_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_unsigned(json::number_unsigned_t) override | ||||
|     bool number_unsigned(json::number_unsigned_t) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool number_float(json::number_float_t, const std::string&) override | ||||
|     bool number_float(json::number_float_t, const std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool string(std::string&) override | ||||
|     bool string(std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool start_object(std::size_t) override | ||||
|     bool start_object(std::size_t = -1) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool key(std::string&) override | ||||
|     bool key(std::string&) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool end_object() override | ||||
|     bool end_object() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool start_array(std::size_t) override | ||||
|     bool start_array(std::size_t = -1) | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool end_array() override | ||||
|     bool end_array() | ||||
|     { | ||||
|         return events_left-- > 0; | ||||
|     } | ||||
| 
 | ||||
|     bool parse_error(std::size_t, const std::string&, const json::exception&) override | ||||
|     bool parse_error(std::size_t, const std::string&, const json::exception&) | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue