diff --git a/.github/workflows/run-all.yml b/.github/workflows/run-all.yml index 0ec0e63a..7c6aeef0 100644 --- a/.github/workflows/run-all.yml +++ b/.github/workflows/run-all.yml @@ -27,6 +27,7 @@ jobs: libboost-test-dev \ make \ ninja-build \ + nlohmann-json3-dev \ qtbase5-dev \ ruby \ ruby-dev \ diff --git a/3rdparty/json_spirit/CMakeLists.txt b/3rdparty/json_spirit/CMakeLists.txt deleted file mode 100644 index c1406a5d..00000000 --- a/3rdparty/json_spirit/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -find_package(Boost 1.34 REQUIRED) - -add_library(json_spirit.header INTERFACE) -target_sources(json_spirit.header INTERFACE - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit.h - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_error_position.h - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_reader_template.h - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_stream_reader.h - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_utils.h - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_value.h - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_writer_options.h - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_writer_template.h -) -target_include_directories(json_spirit.header SYSTEM - INTERFACE - ${Boost_INCLUDE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/.. -) - -add_library(json_spirit STATIC EXCLUDE_FROM_ALL - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_reader.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_reader.h - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_value.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_writer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_writer.h - ${CMAKE_CURRENT_SOURCE_DIR}/json_spirit_writer_options.h -) -target_link_libraries(json_spirit PUBLIC json_spirit.header) diff --git a/3rdparty/json_spirit/json_spirit.h b/3rdparty/json_spirit/json_spirit.h deleted file mode 100644 index 5e50fc1f..00000000 --- a/3rdparty/json_spirit/json_spirit.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef JSON_SPIRIT -#define JSON_SPIRIT - -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include "json_spirit_value.h" -#include "json_spirit_reader.h" -#include "json_spirit_writer.h" -#include "json_spirit_utils.h" - -#endif diff --git a/3rdparty/json_spirit/json_spirit.vcproj b/3rdparty/json_spirit/json_spirit.vcproj deleted file mode 100644 index 0cbe0efa..00000000 --- a/3rdparty/json_spirit/json_spirit.vcproj +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/3rdparty/json_spirit/json_spirit_error_position.h b/3rdparty/json_spirit/json_spirit_error_position.h deleted file mode 100644 index 23e7075d..00000000 --- a/3rdparty/json_spirit/json_spirit_error_position.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef JSON_SPIRIT_ERROR_POSITION -#define JSON_SPIRIT_ERROR_POSITION - -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include - -namespace json_spirit -{ - // An Error_position exception is thrown by the "read_or_throw" functions below on finding an error. - // Note the "read_or_throw" functions are around 3 times slower than the standard functions "read" - // functions that return a bool. - // - struct Error_position - { - Error_position(); - Error_position( unsigned int line, unsigned int column, const std::string& reason ); - bool operator==( const Error_position& lhs ) const; - unsigned int line_; - unsigned int column_; - std::string reason_; - }; - - inline Error_position::Error_position() - : line_( 0 ) - , column_( 0 ) - { - } - - inline Error_position::Error_position( unsigned int line, unsigned int column, const std::string& reason ) - : line_( line ) - , column_( column ) - , reason_( reason ) - { - } - - inline bool Error_position::operator==( const Error_position& lhs ) const - { - if( this == &lhs ) return true; - - return ( reason_ == lhs.reason_ ) && - ( line_ == lhs.line_ ) && - ( column_ == lhs.column_ ); - } -} - -#endif diff --git a/3rdparty/json_spirit/json_spirit_reader.cpp b/3rdparty/json_spirit/json_spirit_reader.cpp deleted file mode 100644 index 1bcbf35b..00000000 --- a/3rdparty/json_spirit/json_spirit_reader.cpp +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#include "json_spirit_reader.h" -#include "json_spirit_reader_template.h" - -using namespace json_spirit; - -#ifdef JSON_SPIRIT_VALUE_ENABLED - bool json_spirit::read( const std::string& s, Value& value ) - { - return read_string( s, value ); - } - - void json_spirit::read_or_throw( const std::string& s, Value& value ) - { - read_string_or_throw( s, value ); - } - - bool json_spirit::read( std::istream& is, Value& value ) - { - return read_stream( is, value ); - } - - void json_spirit::read_or_throw( std::istream& is, Value& value ) - { - read_stream_or_throw( is, value ); - } - - bool json_spirit::read( std::string::const_iterator& begin, std::string::const_iterator end, Value& value ) - { - return read_range( begin, end, value ); - } - - void json_spirit::read_or_throw( std::string::const_iterator& begin, std::string::const_iterator end, Value& value ) - { - begin = read_range_or_throw( begin, end, value ); - } -#endif - -#if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - bool json_spirit::read( const std::wstring& s, wValue& value ) - { - return read_string( s, value ); - } - - void json_spirit::read_or_throw( const std::wstring& s, wValue& value ) - { - read_string_or_throw( s, value ); - } - - bool json_spirit::read( std::wistream& is, wValue& value ) - { - return read_stream( is, value ); - } - - void json_spirit::read_or_throw( std::wistream& is, wValue& value ) - { - read_stream_or_throw( is, value ); - } - - bool json_spirit::read( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wValue& value ) - { - return read_range( begin, end, value ); - } - - void json_spirit::read_or_throw( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wValue& value ) - { - begin = read_range_or_throw( begin, end, value ); - } -#endif - -#ifdef JSON_SPIRIT_MVALUE_ENABLED - bool json_spirit::read( const std::string& s, mValue& value ) - { - return read_string( s, value ); - } - - void json_spirit::read_or_throw( const std::string& s, mValue& value ) - { - read_string_or_throw( s, value ); - } - - bool json_spirit::read( std::istream& is, mValue& value ) - { - return read_stream( is, value ); - } - - void json_spirit::read_or_throw( std::istream& is, mValue& value ) - { - read_stream_or_throw( is, value ); - } - - bool json_spirit::read( std::string::const_iterator& begin, std::string::const_iterator end, mValue& value ) - { - return read_range( begin, end, value ); - } - - void json_spirit::read_or_throw( std::string::const_iterator& begin, std::string::const_iterator end, mValue& value ) - { - begin = read_range_or_throw( begin, end, value ); - } -#endif - -#if defined( JSON_SPIRIT_WMVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - bool json_spirit::read( const std::wstring& s, wmValue& value ) - { - return read_string( s, value ); - } - - void json_spirit::read_or_throw( const std::wstring& s, wmValue& value ) - { - read_string_or_throw( s, value ); - } - - bool json_spirit::read( std::wistream& is, wmValue& value ) - { - return read_stream( is, value ); - } - - void json_spirit::read_or_throw( std::wistream& is, wmValue& value ) - { - read_stream_or_throw( is, value ); - } - - bool json_spirit::read( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wmValue& value ) - { - return read_range( begin, end, value ); - } - - void json_spirit::read_or_throw( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wmValue& value ) - { - begin = read_range_or_throw( begin, end, value ); - } -#endif diff --git a/3rdparty/json_spirit/json_spirit_reader.h b/3rdparty/json_spirit/json_spirit_reader.h deleted file mode 100644 index 4dea8684..00000000 --- a/3rdparty/json_spirit/json_spirit_reader.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef JSON_SPIRIT_READER -#define JSON_SPIRIT_READER - -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include "json_spirit_value.h" -#include "json_spirit_error_position.h" -#include - -namespace json_spirit -{ - // functions to reads a JSON values - -#ifdef JSON_SPIRIT_VALUE_ENABLED - bool read( const std::string& s, Value& value ); - bool read( std::istream& is, Value& value ); - bool read( std::string::const_iterator& begin, std::string::const_iterator end, Value& value ); - - void read_or_throw( const std::string& s, Value& value ); - void read_or_throw( std::istream& is, Value& value ); - void read_or_throw( std::string::const_iterator& begin, std::string::const_iterator end, Value& value ); -#endif - -#if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - bool read( const std::wstring& s, wValue& value ); - bool read( std::wistream& is, wValue& value ); - bool read( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wValue& value ); - - void read_or_throw( const std::wstring& s, wValue& value ); - void read_or_throw( std::wistream& is, wValue& value ); - void read_or_throw( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wValue& value ); -#endif - -#ifdef JSON_SPIRIT_MVALUE_ENABLED - bool read( const std::string& s, mValue& value ); - bool read( std::istream& is, mValue& value ); - bool read( std::string::const_iterator& begin, std::string::const_iterator end, mValue& value ); - - void read_or_throw( const std::string& s, mValue& value ); - void read_or_throw( std::istream& is, mValue& value ); - void read_or_throw( std::string::const_iterator& begin, std::string::const_iterator end, mValue& value ); -#endif - -#if defined( JSON_SPIRIT_WMVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - bool read( const std::wstring& s, wmValue& value ); - bool read( std::wistream& is, wmValue& value ); - bool read( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wmValue& value ); - - void read_or_throw( const std::wstring& s, wmValue& value ); - void read_or_throw( std::wistream& is, wmValue& value ); - void read_or_throw( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wmValue& value ); -#endif -} - -#endif diff --git a/3rdparty/json_spirit/json_spirit_reader_template.h b/3rdparty/json_spirit/json_spirit_reader_template.h deleted file mode 100644 index c015c4ce..00000000 --- a/3rdparty/json_spirit/json_spirit_reader_template.h +++ /dev/null @@ -1,650 +0,0 @@ -#ifndef JSON_SPIRIT_READER_TEMPLATE -#define JSON_SPIRIT_READER_TEMPLATE - -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include "json_spirit_value.h" -#include "json_spirit_error_position.h" - -//#define BOOST_SPIRIT_THREADSAFE // uncomment for multithreaded use, requires linking to boost.thread - -#include -#include -#include - -#if BOOST_VERSION >= 103800 - #include - #include - #include - #include - #include - #define spirit_namespace boost::spirit::classic -#else - #include - #include - #include - #include - #include - #define spirit_namespace boost::spirit -#endif - -namespace json_spirit -{ - const spirit_namespace::int_parser < boost::int64_t > int64_p = spirit_namespace::int_parser < boost::int64_t >(); - const spirit_namespace::uint_parser< boost::uint64_t > uint64_p = spirit_namespace::uint_parser< boost::uint64_t >(); - - template< class Iter_type > - bool is_eq( Iter_type first, Iter_type last, const char* c_str ) - { - for( Iter_type i = first; i != last; ++i, ++c_str ) - { - if( *c_str == 0 ) return false; - - if( *i != *c_str ) return false; - } - - return true; - } - - template< class Char_type > - Char_type hex_to_num( const Char_type c ) - { - if( ( c >= '0' ) && ( c <= '9' ) ) return c - '0'; - if( ( c >= 'a' ) && ( c <= 'f' ) ) return c - 'a' + 10; - if( ( c >= 'A' ) && ( c <= 'F' ) ) return c - 'A' + 10; - return 0; - } - - template< class Char_type, class Iter_type > - Char_type hex_str_to_char( Iter_type& begin ) - { - const Char_type c1( *( ++begin ) ); - const Char_type c2( *( ++begin ) ); - - return ( hex_to_num( c1 ) << 4 ) + hex_to_num( c2 ); - } - - template< class Char_type, class Iter_type > - Char_type unicode_str_to_char( Iter_type& begin ) - { - const Char_type c1( *( ++begin ) ); - const Char_type c2( *( ++begin ) ); - const Char_type c3( *( ++begin ) ); - const Char_type c4( *( ++begin ) ); - - return ( hex_to_num( c1 ) << 12 ) + - ( hex_to_num( c2 ) << 8 ) + - ( hex_to_num( c3 ) << 4 ) + - hex_to_num( c4 ); - } - - template< class String_type > - void append_esc_char_and_incr_iter( String_type& s, - typename String_type::const_iterator& begin, - typename String_type::const_iterator end ) - { - typedef typename String_type::value_type Char_type; - - const Char_type c2( *begin ); - - switch( c2 ) - { - case 't': s += '\t'; break; - case 'b': s += '\b'; break; - case 'f': s += '\f'; break; - case 'n': s += '\n'; break; - case 'r': s += '\r'; break; - case '\\': s += '\\'; break; - case '/': s += '/'; break; - case '"': s += '"'; break; - case 'x': - { - if( end - begin >= 3 ) // expecting "xHH..." - { - s += hex_str_to_char< Char_type >( begin ); - } - break; - } - case 'u': - { - if( end - begin >= 5 ) // expecting "uHHHH..." - { - s += unicode_str_to_char< Char_type >( begin ); - } - break; - } - } - } - - template< class String_type > - String_type substitute_esc_chars( typename String_type::const_iterator begin, - typename String_type::const_iterator end ) - { - typedef typename String_type::const_iterator Iter_type; - - if( end - begin < 2 ) return String_type( begin, end ); - - String_type result; - - result.reserve( end - begin ); - - const Iter_type end_minus_1( end - 1 ); - - Iter_type substr_start = begin; - Iter_type i = begin; - - for( ; i < end_minus_1; ++i ) - { - if( *i == '\\' ) - { - result.append( substr_start, i ); - - ++i; // skip the '\' - - append_esc_char_and_incr_iter( result, i, end ); - - substr_start = i + 1; - } - } - - result.append( substr_start, end ); - - return result; - } - - template< class String_type > - String_type get_str_( typename String_type::const_iterator begin, - typename String_type::const_iterator end ) - { - assert( end - begin >= 2 ); - - typedef typename String_type::const_iterator Iter_type; - - Iter_type str_without_quotes( ++begin ); - Iter_type end_without_quotes( --end ); - - return substitute_esc_chars< String_type >( str_without_quotes, end_without_quotes ); - } - - inline std::string get_str( std::string::const_iterator begin, std::string::const_iterator end ) - { - return get_str_< std::string >( begin, end ); - } - - inline std::wstring get_str( std::wstring::const_iterator begin, std::wstring::const_iterator end ) - { - return get_str_< std::wstring >( begin, end ); - } - - template< class String_type, class Iter_type > - String_type get_str( Iter_type begin, Iter_type end ) - { - const String_type tmp( begin, end ); // convert multipass iterators to string iterators - - return get_str( tmp.begin(), tmp.end() ); - } - - // this class's methods get called by the spirit parse resulting - // in the creation of a JSON object or array - // - // NB Iter_type could be a std::string iterator, wstring iterator, a position iterator or a multipass iterator - // - template< class Value_type, class Iter_type > - class Semantic_actions - { - public: - - typedef typename Value_type::Config_type Config_type; - typedef typename Config_type::String_type String_type; - typedef typename Config_type::Object_type Object_type; - typedef typename Config_type::Array_type Array_type; - typedef typename String_type::value_type Char_type; - - Semantic_actions( Value_type& value ) - : value_( value ) - , current_p_( 0 ) - { - } - - void begin_obj( Char_type c ) - { - assert( c == '{' ); - - begin_compound< Object_type >(); - } - - void end_obj( Char_type c ) - { - assert( c == '}' ); - - end_compound(); - } - - void begin_array( Char_type c ) - { - assert( c == '[' ); - - begin_compound< Array_type >(); - } - - void end_array( Char_type c ) - { - assert( c == ']' ); - - end_compound(); - } - - void new_name( Iter_type begin, Iter_type end ) - { - assert( current_p_->type() == obj_type ); - - name_ = get_str< String_type >( begin, end ); - } - - void new_str( Iter_type begin, Iter_type end ) - { - add_to_current( get_str< String_type >( begin, end ) ); - } - - void new_true( Iter_type begin, Iter_type end ) - { - assert( is_eq( begin, end, "true" ) ); - - add_to_current( true ); - } - - void new_false( Iter_type begin, Iter_type end ) - { - assert( is_eq( begin, end, "false" ) ); - - add_to_current( false ); - } - - void new_null( Iter_type begin, Iter_type end ) - { - assert( is_eq( begin, end, "null" ) ); - - add_to_current( Value_type() ); - } - - void new_int( boost::int64_t i ) - { - add_to_current( i ); - } - - void new_uint64( boost::uint64_t ui ) - { - add_to_current( ui ); - } - - void new_real( double d ) - { - add_to_current( d ); - } - - private: - - Semantic_actions& operator=( const Semantic_actions& ); - // to prevent "assignment operator could not be generated" warning - - Value_type* add_first( const Value_type& value ) - { - assert( current_p_ == 0 ); - - value_ = value; - current_p_ = &value_; - return current_p_; - } - - template< class Array_or_obj > - void begin_compound() - { - if( current_p_ == 0 ) - { - add_first( Array_or_obj() ); - } - else - { - stack_.push_back( current_p_ ); - - Array_or_obj new_array_or_obj; // avoid copy by building new array or object in place - - current_p_ = add_to_current( new_array_or_obj ); - } - } - - void end_compound() - { - if( current_p_ != &value_ ) - { - current_p_ = stack_.back(); - - stack_.pop_back(); - } - } - - Value_type* add_to_current( const Value_type& value ) - { - if( current_p_ == 0 ) - { - return add_first( value ); - } - else if( current_p_->type() == array_type ) - { - current_p_->get_array().push_back( value ); - - return ¤t_p_->get_array().back(); - } - - assert( current_p_->type() == obj_type ); - - return &Config_type::add( current_p_->get_obj(), name_, value ); - } - - Value_type& value_; // this is the object or array that is being created - Value_type* current_p_; // the child object or array that is currently being constructed - - std::vector< Value_type* > stack_; // previous child objects and arrays - - String_type name_; // of current name/value pair - }; - - template< typename Iter_type > - void throw_error( spirit_namespace::position_iterator< Iter_type > i, const std::string& reason ) - { - throw Error_position( i.get_position().line, i.get_position().column, reason ); - } - - template< typename Iter_type > - void throw_error( Iter_type i, const std::string& reason ) - { - throw reason; - } - - // the spirit grammer - // - template< class Value_type, class Iter_type > - class Json_grammer : public spirit_namespace::grammar< Json_grammer< Value_type, Iter_type > > - { - public: - - typedef Semantic_actions< Value_type, Iter_type > Semantic_actions_t; - - Json_grammer( Semantic_actions_t& semantic_actions ) - : actions_( semantic_actions ) - { - } - - static void throw_not_value( Iter_type begin, Iter_type end ) - { - throw_error( begin, "not a value" ); - } - - static void throw_not_array( Iter_type begin, Iter_type end ) - { - throw_error( begin, "not an array" ); - } - - static void throw_not_object( Iter_type begin, Iter_type end ) - { - throw_error( begin, "not an object" ); - } - - static void throw_not_pair( Iter_type begin, Iter_type end ) - { - throw_error( begin, "not a pair" ); - } - - static void throw_not_colon( Iter_type begin, Iter_type end ) - { - throw_error( begin, "no colon in pair" ); - } - - static void throw_not_string( Iter_type begin, Iter_type end ) - { - throw_error( begin, "not a string" ); - } - - template< typename ScannerT > - class definition - { - public: - - definition( const Json_grammer& self ) - { - using namespace spirit_namespace; - - typedef typename Value_type::String_type::value_type Char_type; - - // first we convert the semantic action class methods to functors with the - // parameter signature expected by spirit - - typedef boost::function< void( Char_type ) > Char_action; - typedef boost::function< void( Iter_type, Iter_type ) > Str_action; - typedef boost::function< void( double ) > Real_action; - typedef boost::function< void( boost::int64_t ) > Int_action; - typedef boost::function< void( boost::uint64_t ) > Uint64_action; - - Char_action begin_obj ( boost::bind( &Semantic_actions_t::begin_obj, &self.actions_, _1 ) ); - Char_action end_obj ( boost::bind( &Semantic_actions_t::end_obj, &self.actions_, _1 ) ); - Char_action begin_array( boost::bind( &Semantic_actions_t::begin_array, &self.actions_, _1 ) ); - Char_action end_array ( boost::bind( &Semantic_actions_t::end_array, &self.actions_, _1 ) ); - Str_action new_name ( boost::bind( &Semantic_actions_t::new_name, &self.actions_, _1, _2 ) ); - Str_action new_str ( boost::bind( &Semantic_actions_t::new_str, &self.actions_, _1, _2 ) ); - Str_action new_true ( boost::bind( &Semantic_actions_t::new_true, &self.actions_, _1, _2 ) ); - Str_action new_false ( boost::bind( &Semantic_actions_t::new_false, &self.actions_, _1, _2 ) ); - Str_action new_null ( boost::bind( &Semantic_actions_t::new_null, &self.actions_, _1, _2 ) ); - Real_action new_real ( boost::bind( &Semantic_actions_t::new_real, &self.actions_, _1 ) ); - Int_action new_int ( boost::bind( &Semantic_actions_t::new_int, &self.actions_, _1 ) ); - Uint64_action new_uint64 ( boost::bind( &Semantic_actions_t::new_uint64, &self.actions_, _1 ) ); - - // actual grammer - - json_ - = value_ | eps_p[ &throw_not_value ] - ; - - value_ - = string_[ new_str ] - | number_ - | object_ - | array_ - | str_p( "true" ) [ new_true ] - | str_p( "false" )[ new_false ] - | str_p( "null" ) [ new_null ] - ; - - object_ - = ch_p('{')[ begin_obj ] - >> !members_ - >> ( ch_p('}')[ end_obj ] | eps_p[ &throw_not_object ] ) - ; - - members_ - = pair_ >> *( ',' >> pair_ ) - ; - - pair_ - = string_[ new_name ] - >> ( ':' | eps_p[ &throw_not_colon ] ) - >> ( value_ | eps_p[ &throw_not_value ] ) - ; - - array_ - = ch_p('[')[ begin_array ] - >> !elements_ - >> ( ch_p(']')[ end_array ] | eps_p[ &throw_not_array ] ) - ; - - elements_ - = value_ >> *( ',' >> value_ ) - ; - - string_ - = lexeme_d // this causes white space and what would appear to be comments inside a string to be retained - [ - confix_p - ( - '"', - *lex_escape_ch_p, - '"' - ) - ] - ; - - number_ - = strict_real_p[ new_real ] - | int64_p [ new_int ] - | uint64_p [ new_uint64 ] - ; - } - - spirit_namespace::rule< ScannerT > json_, object_, members_, pair_, array_, elements_, value_, string_, number_; - - const spirit_namespace::rule< ScannerT >& start() const { return json_; } - }; - - private: - - Json_grammer& operator=( const Json_grammer& ); // to prevent "assignment operator could not be generated" warning - - Semantic_actions_t& actions_; - }; - - template< class Iter_type, class Value_type > - void add_posn_iter_and_read_range_or_throw( Iter_type begin, Iter_type end, Value_type& value ) - { - typedef spirit_namespace::position_iterator< Iter_type > Posn_iter_t; - - const Posn_iter_t posn_begin( begin, end ); - const Posn_iter_t posn_end( end, end ); - - read_range_or_throw( posn_begin, posn_end, value ); - } - - template< class Istream_type > - struct Multi_pass_iters - { - typedef typename Istream_type::char_type Char_type; - typedef std::istream_iterator< Char_type, Char_type > istream_iter; - typedef spirit_namespace::multi_pass< istream_iter > Mp_iter; - - Multi_pass_iters( Istream_type& is ) - { - is.unsetf( std::ios::skipws ); - - begin_ = spirit_namespace::make_multi_pass( istream_iter( is ) ); - end_ = spirit_namespace::make_multi_pass( istream_iter() ); - } - - Mp_iter begin_; - Mp_iter end_; - }; - - // reads a JSON Value from a pair of input iterators throwing an exception on invalid input, e.g. - // - // string::const_iterator start = str.begin(); - // const string::const_iterator next = read_range_or_throw( str.begin(), str.end(), value ); - // - // The iterator 'next' will point to the character past the - // last one read. - // - template< class Iter_type, class Value_type > - Iter_type read_range_or_throw( Iter_type begin, Iter_type end, Value_type& value ) - { - Semantic_actions< Value_type, Iter_type > semantic_actions( value ); - - const spirit_namespace::parse_info< Iter_type > info = - spirit_namespace::parse( begin, end, - Json_grammer< Value_type, Iter_type >( semantic_actions ), - spirit_namespace::space_p | - spirit_namespace::comment_p("//") | - spirit_namespace::comment_p("/*", "*/") ); - - if( !info.hit ) - { - assert( false ); // in theory exception should already have been thrown - throw_error( info.stop, "error" ); - } - - return info.stop; - } - - // reads a JSON Value from a pair of input iterators, e.g. - // - // string::const_iterator start = str.begin(); - // const bool success = read_string( start, str.end(), value ); - // - // The iterator 'start' will point to the character past the - // last one read. - // - template< class Iter_type, class Value_type > - bool read_range( Iter_type& begin, Iter_type end, Value_type& value ) - { - try - { - begin = read_range_or_throw( begin, end, value ); - - return true; - } - catch( ... ) - { - return false; - } - } - - // reads a JSON Value from a string, e.g. - // - // const bool success = read_string( str, value ); - // - template< class String_type, class Value_type > - bool read_string( const String_type& s, Value_type& value ) - { - typename String_type::const_iterator begin = s.begin(); - - return read_range( begin, s.end(), value ); - } - - // reads a JSON Value from a string throwing an exception on invalid input, e.g. - // - // read_string_or_throw( is, value ); - // - template< class String_type, class Value_type > - void read_string_or_throw( const String_type& s, Value_type& value ) - { - add_posn_iter_and_read_range_or_throw( s.begin(), s.end(), value ); - } - - // reads a JSON Value from a stream, e.g. - // - // const bool success = read_stream( is, value ); - // - template< class Istream_type, class Value_type > - bool read_stream( Istream_type& is, Value_type& value ) - { - Multi_pass_iters< Istream_type > mp_iters( is ); - - return read_range( mp_iters.begin_, mp_iters.end_, value ); - } - - // reads a JSON Value from a stream throwing an exception on invalid input, e.g. - // - // read_stream_or_throw( is, value ); - // - template< class Istream_type, class Value_type > - void read_stream_or_throw( Istream_type& is, Value_type& value ) - { - const Multi_pass_iters< Istream_type > mp_iters( is ); - - add_posn_iter_and_read_range_or_throw( mp_iters.begin_, mp_iters.end_, value ); - } -} - -#endif diff --git a/3rdparty/json_spirit/json_spirit_stream_reader.h b/3rdparty/json_spirit/json_spirit_stream_reader.h deleted file mode 100644 index 4c3c38d4..00000000 --- a/3rdparty/json_spirit/json_spirit_stream_reader.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef JSON_SPIRIT_READ_STREAM -#define JSON_SPIRIT_READ_STREAM - -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include "json_spirit_reader_template.h" - -namespace json_spirit -{ - // these classes allows you to read multiple top level contiguous values from a stream, - // the normal stream read functions have a bug that prevent multiple top level values - // from being read unless they are separated by spaces - - template< class Istream_type, class Value_type > - class Stream_reader - { - public: - - Stream_reader( Istream_type& is ) - : iters_( is ) - { - } - - bool read_next( Value_type& value ) - { - return read_range( iters_.begin_, iters_.end_, value ); - } - - private: - - typedef Multi_pass_iters< Istream_type > Mp_iters; - - Mp_iters iters_; - }; - - template< class Istream_type, class Value_type > - class Stream_reader_thrower - { - public: - - Stream_reader_thrower( Istream_type& is ) - : iters_( is ) - , posn_begin_( iters_.begin_, iters_.end_ ) - , posn_end_( iters_.end_, iters_.end_ ) - { - } - - void read_next( Value_type& value ) - { - posn_begin_ = read_range_or_throw( posn_begin_, posn_end_, value ); - } - - private: - - typedef Multi_pass_iters< Istream_type > Mp_iters; - typedef spirit_namespace::position_iterator< typename Mp_iters::Mp_iter > Posn_iter_t; - - Mp_iters iters_; - Posn_iter_t posn_begin_, posn_end_; - }; -} - -#endif diff --git a/3rdparty/json_spirit/json_spirit_utils.h b/3rdparty/json_spirit/json_spirit_utils.h deleted file mode 100644 index a2e72990..00000000 --- a/3rdparty/json_spirit/json_spirit_utils.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef JSON_SPIRIT_UTILS -#define JSON_SPIRIT_UTILS - -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include "json_spirit_value.h" -#include - -namespace json_spirit -{ - template< class Obj_t, class Map_t > - void obj_to_map( const Obj_t& obj, Map_t& mp_obj ) - { - mp_obj.clear(); - - for( typename Obj_t::const_iterator i = obj.begin(); i != obj.end(); ++i ) - { - mp_obj[ i->name_ ] = i->value_; - } - } - - template< class Obj_t, class Map_t > - void map_to_obj( const Map_t& mp_obj, Obj_t& obj ) - { - obj.clear(); - - for( typename Map_t::const_iterator i = mp_obj.begin(); i != mp_obj.end(); ++i ) - { - obj.push_back( typename Obj_t::value_type( i->first, i->second ) ); - } - } - -#ifdef JSON_SPIRIT_VALUE_ENABLED - typedef std::map< std::string, Value > Mapped_obj; -#endif - -#if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - typedef std::map< std::wstring, wValue > wMapped_obj; -#endif - - template< class Object_type, class String_type > - const typename Object_type::value_type::Value_type& find_value( const Object_type& obj, const String_type& name ) - { - for( typename Object_type::const_iterator i = obj.begin(); i != obj.end(); ++i ) - { - if( i->name_ == name ) - { - return i->value_; - } - } - - return Object_type::value_type::Value_type::null; - } -} - -#endif diff --git a/3rdparty/json_spirit/json_spirit_value.cpp b/3rdparty/json_spirit/json_spirit_value.cpp deleted file mode 100644 index 5f0260d8..00000000 --- a/3rdparty/json_spirit/json_spirit_value.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#include "json_spirit_value.h" diff --git a/3rdparty/json_spirit/json_spirit_value.h b/3rdparty/json_spirit/json_spirit_value.h deleted file mode 100644 index 2f36cf44..00000000 --- a/3rdparty/json_spirit/json_spirit_value.h +++ /dev/null @@ -1,605 +0,0 @@ -#ifndef JSON_SPIRIT_VALUE -#define JSON_SPIRIT_VALUE - -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// comment out the value types you don't need to reduce build times and intermediate file sizes -#define JSON_SPIRIT_VALUE_ENABLED -#define JSON_SPIRIT_WVALUE_ENABLED -#define JSON_SPIRIT_MVALUE_ENABLED -#define JSON_SPIRIT_WMVALUE_ENABLED - -namespace json_spirit -{ - enum Value_type{ obj_type, array_type, str_type, bool_type, int_type, real_type, null_type }; - - static std::string value_type_to_string( Value_type vtype ); - - struct Null{}; - - template< class Config > // Config determines whether the value uses std::string or std::wstring and - // whether JSON Objects are represented as vectors or maps - class Value_impl - { - public: - - typedef Config Config_type; - typedef typename Config::String_type String_type; - typedef typename Config::Object_type Object; - typedef typename Config::Array_type Array; - typedef typename String_type::const_pointer Const_str_ptr; // eg const char* - - Value_impl(); // creates null value - Value_impl( Const_str_ptr value ); - Value_impl( const String_type& value ); - Value_impl( const Object& value ); - Value_impl( const Array& value ); - Value_impl( bool value ); - Value_impl( int value ); - Value_impl( boost::int64_t value ); - Value_impl( boost::uint64_t value ); - Value_impl( double value ); - - template< class Iter > - Value_impl( Iter first, Iter last ); // constructor from containers, e.g. std::vector or std::list - - template< BOOST_VARIANT_ENUM_PARAMS( typename T ) > - Value_impl( const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& variant ); // constructor for compatible variant types - - Value_impl( const Value_impl& other ); - - bool operator==( const Value_impl& lhs ) const; - - Value_impl& operator=( const Value_impl& lhs ); - - Value_type type() const; - - bool is_uint64() const; - bool is_null() const; - - const String_type& get_str() const; - const Object& get_obj() const; - const Array& get_array() const; - bool get_bool() const; - int get_int() const; - boost::int64_t get_int64() const; - boost::uint64_t get_uint64() const; - double get_real() const; - - Object& get_obj(); - Array& get_array(); - - template< typename T > T get_value() const; // example usage: int i = value.get_value< int >(); - // or double d = value.get_value< double >(); - - static const Value_impl null; - - private: - - void check_type( const Value_type vtype ) const; - - typedef boost::variant< boost::recursive_wrapper< Object >, boost::recursive_wrapper< Array >, - String_type, bool, boost::int64_t, double, Null, boost::uint64_t > Variant; - - Variant v_; - - class Variant_converter_visitor : public boost::static_visitor< Variant > - { - public: - - template< typename T, typename A, template< typename, typename > class Cont > - Variant operator()( const Cont< T, A >& cont ) const - { - return Array( cont.begin(), cont.end() ); - } - - Variant operator()( int i ) const - { - return static_cast< boost::int64_t >( i ); - } - - template - Variant operator()( const T& t ) const - { - return t; - } - }; - }; - - // vector objects - - template< class Config > - struct Pair_impl - { - typedef typename Config::String_type String_type; - typedef typename Config::Value_type Value_type; - - Pair_impl() - { - } - - Pair_impl( const String_type& name, const Value_type& value ); - - bool operator==( const Pair_impl& lhs ) const; - - String_type name_; - Value_type value_; - }; - -#if defined( JSON_SPIRIT_VALUE_ENABLED ) || defined( JSON_SPIRIT_WVALUE_ENABLED ) - template< class String > - struct Config_vector - { - typedef String String_type; - typedef Value_impl< Config_vector > Value_type; - typedef Pair_impl < Config_vector > Pair_type; - typedef std::vector< Value_type > Array_type; - typedef std::vector< Pair_type > Object_type; - - static Value_type& add( Object_type& obj, const String_type& name, const Value_type& value ) - { - obj.push_back( Pair_type( name , value ) ); - - return obj.back().value_; - } - - static const String_type& get_name( const Pair_type& pair ) - { - return pair.name_; - } - - static const Value_type& get_value( const Pair_type& pair ) - { - return pair.value_; - } - }; -#endif - - // typedefs for ASCII - -#ifdef JSON_SPIRIT_VALUE_ENABLED - typedef Config_vector< std::string > Config; - - typedef Config::Value_type Value; - typedef Config::Pair_type Pair; - typedef Config::Object_type Object; - typedef Config::Array_type Array; -#endif - - // typedefs for Unicode - -#if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - typedef Config_vector< std::wstring > wConfig; - - typedef wConfig::Value_type wValue; - typedef wConfig::Pair_type wPair; - typedef wConfig::Object_type wObject; - typedef wConfig::Array_type wArray; -#endif - - // map objects - -#if defined( JSON_SPIRIT_MVALUE_ENABLED ) || defined( JSON_SPIRIT_WMVALUE_ENABLED ) - template< class String > - struct Config_map - { - typedef String String_type; - typedef Value_impl< Config_map > Value_type; - typedef std::vector< Value_type > Array_type; - typedef std::map< String_type, Value_type > Object_type; - typedef std::pair< const String_type, Value_type > Pair_type; - - static Value_type& add( Object_type& obj, const String_type& name, const Value_type& value ) - { - return obj[ name ] = value; - } - - static const String_type& get_name( const Pair_type& pair ) - { - return pair.first; - } - - static const Value_type& get_value( const Pair_type& pair ) - { - return pair.second; - } - }; -#endif - - // typedefs for ASCII - -#ifdef JSON_SPIRIT_MVALUE_ENABLED - typedef Config_map< std::string > mConfig; - - typedef mConfig::Value_type mValue; - typedef mConfig::Object_type mObject; - typedef mConfig::Array_type mArray; -#endif - - // typedefs for Unicode - -#if defined( JSON_SPIRIT_WMVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - typedef Config_map< std::wstring > wmConfig; - - typedef wmConfig::Value_type wmValue; - typedef wmConfig::Object_type wmObject; - typedef wmConfig::Array_type wmArray; -#endif - - /////////////////////////////////////////////////////////////////////////////////////////////// - // - // implementation - - inline bool operator==( const Null&, const Null& ) - { - return true; - } - - template< class Config > - const Value_impl< Config > Value_impl< Config >::null; - - template< class Config > - Value_impl< Config >::Value_impl() - : v_( Null() ) - { - } - - template< class Config > - Value_impl< Config >::Value_impl( const Const_str_ptr value ) - : v_( String_type( value ) ) - { - } - - template< class Config > - Value_impl< Config >::Value_impl( const String_type& value ) - : v_( value ) - { - } - - template< class Config > - Value_impl< Config >::Value_impl( const Object& value ) - : v_( value ) - { - } - - template< class Config > - Value_impl< Config >::Value_impl( const Array& value ) - : v_( value ) - { - } - - template< class Config > - Value_impl< Config >::Value_impl( bool value ) - : v_( value ) - { - } - - template< class Config > - Value_impl< Config >::Value_impl( int value ) - : v_( static_cast< boost::int64_t >( value ) ) - { - } - - template< class Config > - Value_impl< Config >::Value_impl( boost::int64_t value ) - : v_( value ) - { - } - - template< class Config > - Value_impl< Config >::Value_impl( boost::uint64_t value ) - : v_( value ) - { - } - - template< class Config > - Value_impl< Config >::Value_impl( double value ) - : v_( value ) - { - } - - template< class Config > - Value_impl< Config >::Value_impl( const Value_impl< Config >& other ) - : v_( other.v_ ) - { - } - - template< class Config > - template< class Iter > - Value_impl< Config >::Value_impl( Iter first, Iter last ) - : v_( Array( first, last ) ) - { - } - - template< class Config > - template< BOOST_VARIANT_ENUM_PARAMS( typename T ) > - Value_impl< Config >::Value_impl( const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& variant ) - : v_( boost::apply_visitor( Variant_converter_visitor(), variant) ) - { - } - - template< class Config > - Value_impl< Config >& Value_impl< Config >::operator=( const Value_impl& lhs ) - { - Value_impl tmp( lhs ); - - std::swap( v_, tmp.v_ ); - - return *this; - } - - template< class Config > - bool Value_impl< Config >::operator==( const Value_impl& lhs ) const - { - if( this == &lhs ) return true; - - if( type() != lhs.type() ) return false; - - return v_ == lhs.v_; - } - - template< class Config > - Value_type Value_impl< Config >::type() const - { - if( is_uint64() ) - { - return int_type; - } - - return static_cast< Value_type >( v_.which() ); - } - - template< class Config > - bool Value_impl< Config >::is_uint64() const - { - return v_.which() == null_type + 1; - } - - template< class Config > - bool Value_impl< Config >::is_null() const - { - return type() == null_type; - } - - template< class Config > - void Value_impl< Config >::check_type( const Value_type vtype ) const - { - if( type() != vtype ) - { - std::ostringstream os; - - os << "get_value< " << value_type_to_string( vtype ) << " > called on " << value_type_to_string( type() ) << " Value"; - - throw std::runtime_error( os.str() ); - } - } - - template< class Config > - const typename Config::String_type& Value_impl< Config >::get_str() const - { - check_type( str_type ); - - return *boost::get< String_type >( &v_ ); - } - - template< class Config > - const typename Value_impl< Config >::Object& Value_impl< Config >::get_obj() const - { - check_type( obj_type ); - - return *boost::get< Object >( &v_ ); - } - - template< class Config > - const typename Value_impl< Config >::Array& Value_impl< Config >::get_array() const - { - check_type( array_type ); - - return *boost::get< Array >( &v_ ); - } - - template< class Config > - bool Value_impl< Config >::get_bool() const - { - check_type( bool_type ); - - return boost::get< bool >( v_ ); - } - - template< class Config > - int Value_impl< Config >::get_int() const - { - check_type( int_type ); - - return static_cast< int >( get_int64() ); - } - - template< class Config > - boost::int64_t Value_impl< Config >::get_int64() const - { - check_type( int_type ); - - if( is_uint64() ) - { - return static_cast< boost::int64_t >( get_uint64() ); - } - - return boost::get< boost::int64_t >( v_ ); - } - - template< class Config > - boost::uint64_t Value_impl< Config >::get_uint64() const - { - check_type( int_type ); - - if( !is_uint64() ) - { - return static_cast< boost::uint64_t >( get_int64() ); - } - - return boost::get< boost::uint64_t >( v_ ); - } - - template< class Config > - double Value_impl< Config >::get_real() const - { - if( type() == int_type ) - { - return is_uint64() ? static_cast< double >( get_uint64() ) - : static_cast< double >( get_int64() ); - } - - check_type( real_type ); - - return boost::get< double >( v_ ); - } - - template< class Config > - typename Value_impl< Config >::Object& Value_impl< Config >::get_obj() - { - check_type( obj_type ); - - return *boost::get< Object >( &v_ ); - } - - template< class Config > - typename Value_impl< Config >::Array& Value_impl< Config >::get_array() - { - check_type( array_type ); - - return *boost::get< Array >( &v_ ); - } - - template< class Config > - Pair_impl< Config >::Pair_impl( const String_type& name, const Value_type& value ) - : name_( name ) - , value_( value ) - { - } - - template< class Config > - bool Pair_impl< Config >::operator==( const Pair_impl< Config >& lhs ) const - { - if( this == &lhs ) return true; - - return ( name_ == lhs.name_ ) && ( value_ == lhs.value_ ); - } - - // converts a C string, ie. 8 bit char array, to a string object - // - template < class String_type > - String_type to_str( const char* c_str ) - { - String_type result; - - for( const char* p = c_str; *p != 0; ++p ) - { - result += *p; - } - - return result; - } - - // - - namespace internal_ - { - template< typename T > - struct Type_to_type - { - }; - - template< class Value > - int get_value( const Value& value, Type_to_type< int > ) - { - return value.get_int(); - } - - template< class Value > - boost::int64_t get_value( const Value& value, Type_to_type< boost::int64_t > ) - { - return value.get_int64(); - } - - template< class Value > - boost::uint64_t get_value( const Value& value, Type_to_type< boost::uint64_t > ) - { - return value.get_uint64(); - } - - template< class Value > - double get_value( const Value& value, Type_to_type< double > ) - { - return value.get_real(); - } - - template< class Value > - typename Value::String_type get_value( const Value& value, Type_to_type< typename Value::String_type > ) - { - return value.get_str(); - } - - template< class Value > - typename Value::Array get_value( const Value& value, Type_to_type< typename Value::Array > ) - { - return value.get_array(); - } - - template< class Value > - typename Value::Object get_value( const Value& value, Type_to_type< typename Value::Object > ) - { - return value.get_obj(); - } - - template< class Value > - bool get_value( const Value& value, Type_to_type< bool > ) - { - return value.get_bool(); - } - } - - template< class Config > - template< typename T > - T Value_impl< Config >::get_value() const - { - return internal_::get_value( *this, internal_::Type_to_type< T >() ); - } - - static std::string value_type_to_string( const Value_type vtype ) - { - switch( vtype ) - { - case obj_type: return "Object"; - case array_type: return "Array"; - case str_type: return "string"; - case bool_type: return "boolean"; - case int_type: return "integer"; - case real_type: return "real"; - case null_type: return "null"; - } - - assert( false ); - - return "unknown type"; - } -} - -#endif diff --git a/3rdparty/json_spirit/json_spirit_writer.cpp b/3rdparty/json_spirit/json_spirit_writer.cpp deleted file mode 100644 index 24833ffc..00000000 --- a/3rdparty/json_spirit/json_spirit_writer.cpp +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#include "json_spirit_writer.h" -#include "json_spirit_writer_template.h" - -using namespace json_spirit; - -#ifdef JSON_SPIRIT_VALUE_ENABLED - void json_spirit::write( const Value& value, std::ostream& os, int options, unsigned int precision_of_doubles ) - { - write_stream( value, os, options, precision_of_doubles ); - } - std::string json_spirit::write( const Value& value, int options, unsigned int precision_of_doubles ) - { - return write_string( value, options, precision_of_doubles ); - } - - void json_spirit::write_formatted( const Value& value, std::ostream& os, unsigned int precision_of_doubles ) - { - write_stream( value, os, pretty_print, precision_of_doubles ); - } - - std::string json_spirit::write_formatted( const Value& value, unsigned int precision_of_doubles ) - { - return write_string( value, pretty_print, precision_of_doubles ); - } -#endif - -#ifdef JSON_SPIRIT_MVALUE_ENABLED - void json_spirit::write( const mValue& value, std::ostream& os, int options, unsigned int precision_of_doubles ) - { - write_stream( value, os, options, precision_of_doubles ); - } - - std::string json_spirit::write( const mValue& value, int options, unsigned int precision_of_doubles ) - { - return write_string( value, options, precision_of_doubles ); - } - - void json_spirit::write_formatted( const mValue& value, std::ostream& os, unsigned int precision_of_doubles ) - { - write_stream( value, os, pretty_print, precision_of_doubles ); - } - - std::string json_spirit::write_formatted( const mValue& value, unsigned int precision_of_doubles ) - { - return write_string( value, pretty_print, precision_of_doubles ); - } -#endif - -#if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - void json_spirit::write( const wValue& value, std::wostream& os, int options, unsigned int precision_of_doubles ) - { - write_stream( value, os, options, precision_of_doubles ); - } - - std::wstring json_spirit::write( const wValue& value, int options, unsigned int precision_of_doubles ) - { - return write_string( value, options, precision_of_doubles ); - } - - void json_spirit::write_formatted( const wValue& value, std::wostream& os, unsigned int precision_of_doubles ) - { - write_stream( value, os, pretty_print, precision_of_doubles ); - } - - std::wstring json_spirit::write_formatted( const wValue& value, unsigned int precision_of_doubles ) - { - return write_string( value, pretty_print, precision_of_doubles ); - } -#endif - -#if defined( JSON_SPIRIT_WMVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - void json_spirit::write_formatted( const wmValue& value, std::wostream& os, unsigned int precision_of_doubles ) - { - write_stream( value, os, pretty_print, precision_of_doubles ); - } - - std::wstring json_spirit::write_formatted( const wmValue& value, unsigned int precision_of_doubles ) - { - return write_string( value, pretty_print, precision_of_doubles ); - } - - void json_spirit::write( const wmValue& value, std::wostream& os, int options, unsigned int precision_of_doubles ) - { - write_stream( value, os, options, precision_of_doubles ); - } - - std::wstring json_spirit::write( const wmValue& value, int options, unsigned int precision_of_doubles ) - { - return write_string( value, options, precision_of_doubles ); - } -#endif diff --git a/3rdparty/json_spirit/json_spirit_writer.h b/3rdparty/json_spirit/json_spirit_writer.h deleted file mode 100644 index 0b7a2374..00000000 --- a/3rdparty/json_spirit/json_spirit_writer.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef JSON_SPIRIT_WRITER -#define JSON_SPIRIT_WRITER - -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include "json_spirit_value.h" -#include "json_spirit_writer_options.h" -#include - -namespace json_spirit -{ - // these functions to convert JSON Values to text - // note the precision used outputing doubles defaults to 17, - // unless the remove_trailing_zeros option is given in which case the default is 16 - -#ifdef JSON_SPIRIT_VALUE_ENABLED - void write( const Value& value, std::ostream& os, int options = none, unsigned int precision_of_doubles = 0 ); - std::string write( const Value& value, int options = none, unsigned int precision_of_doubles = 0 ); -#endif - -#ifdef JSON_SPIRIT_MVALUE_ENABLED - void write( const mValue& value, std::ostream& os, int options = none, unsigned int precision_of_doubles = 0 ); - std::string write( const mValue& value, int options = none, unsigned int precision_of_doubles = 0 ); -#endif - -#if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - void write( const wValue& value, std::wostream& os, int options = none, unsigned int precision_of_doubles = 0 ); - std::wstring write( const wValue& value, int options = none, unsigned int precision_of_doubles = 0 ); -#endif - -#if defined( JSON_SPIRIT_WMVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - void write( const wmValue& value, std::wostream& os, int options = none, unsigned int precision_of_doubles = 0 ); - std::wstring write( const wmValue& value, int options = none, unsigned int precision_of_doubles = 0 ); -#endif - - // these "formatted" versions of the "write" functions are the equivalent of the above functions - // with option "pretty_print" - -#ifdef JSON_SPIRIT_VALUE_ENABLED - void write_formatted( const Value& value, std::ostream& os, unsigned int precision_of_doubles = 0 ); - std::string write_formatted( const Value& value, unsigned int precision_of_doubles = 0 ); -#endif -#ifdef JSON_SPIRIT_MVALUE_ENABLED - void write_formatted( const mValue& value, std::ostream& os, unsigned int precision_of_doubles = 0 ); - std::string write_formatted( const mValue& value, unsigned int precision_of_doubles = 0 ); -#endif - -#if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - void write_formatted( const wValue& value, std::wostream& os, unsigned int precision_of_doubles = 0 ); - std::wstring write_formatted( const wValue& value, unsigned int precision_of_doubles = 0 ); -#endif -#if defined( JSON_SPIRIT_WMVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) - void write_formatted( const wmValue& value, std::wostream& os, unsigned int precision_of_doubles = 0 ); - std::wstring write_formatted( const wmValue& value, unsigned int precision_of_doubles = 0 ); -#endif -} - -#endif diff --git a/3rdparty/json_spirit/json_spirit_writer_options.h b/3rdparty/json_spirit/json_spirit_writer_options.h deleted file mode 100644 index f147a5a9..00000000 --- a/3rdparty/json_spirit/json_spirit_writer_options.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef JSON_SPIRIT_WRITER_OPTIONS -#define JSON_SPIRIT_WRITER_OPTIONS - -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -namespace json_spirit -{ - enum Output_options{ none = 0, // default options - - pretty_print = 0x01, // Add whitespace to format the output nicely. - - raw_utf8 = 0x02, // This prevents non-printable characters from being escapted using "\uNNNN" notation. - // Note, this is an extension to the JSON standard. It disables the escaping of - // non-printable characters allowing UTF-8 sequences held in 8 bit char strings - // to pass through unaltered. - - remove_trailing_zeros = 0x04, - // no longer used kept for backwards compatibility - single_line_arrays = 0x08, - // pretty printing except that arrays printed on single lines unless they contain - // composite elements, i.e. objects or arrays - always_escape_nonascii = 0x10, - // all unicode wide characters are escaped, i.e. outputed as "\uXXXX", even if they are - // printable under the current locale, ascii printable chars are not escaped - }; -} - -#endif diff --git a/3rdparty/json_spirit/json_spirit_writer_template.h b/3rdparty/json_spirit/json_spirit_writer_template.h deleted file mode 100644 index 35be8838..00000000 --- a/3rdparty/json_spirit/json_spirit_writer_template.h +++ /dev/null @@ -1,328 +0,0 @@ -#ifndef JSON_SPIRIT_WRITER_TEMPLATE -#define JSON_SPIRIT_WRITER_TEMPLATE - -// Copyright John W. Wilkinson 2007 - 2014 -// Distributed under the MIT License, see accompanying file LICENSE.txt - -// json spirit version 4.08 - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include "json_spirit_value.h" -#include "json_spirit_writer_options.h" - -#include -#include -#include -#include -#include - -namespace json_spirit -{ - inline char to_hex_char( unsigned int c ) - { - assert( c <= 0xF ); - - const char ch = static_cast< char >( c ); - - if( ch < 10 ) return '0' + ch; - - return 'A' - 10 + ch; - } - - template< class String_type > - String_type non_printable_to_string( unsigned int c ) - { - typedef typename String_type::value_type Char_type; - - String_type result( 6, '\\' ); - - result[1] = 'u'; - - result[ 5 ] = to_hex_char( c & 0x000F ); c >>= 4; - result[ 4 ] = to_hex_char( c & 0x000F ); c >>= 4; - result[ 3 ] = to_hex_char( c & 0x000F ); c >>= 4; - result[ 2 ] = to_hex_char( c & 0x000F ); - - return result; - } - - template< typename Char_type, class String_type > - bool add_esc_char( Char_type c, String_type& s ) - { - switch( c ) - { - case '"': s += to_str< String_type >( "\\\"" ); return true; - case '\\': s += to_str< String_type >( "\\\\" ); return true; - case '\b': s += to_str< String_type >( "\\b" ); return true; - case '\f': s += to_str< String_type >( "\\f" ); return true; - case '\n': s += to_str< String_type >( "\\n" ); return true; - case '\r': s += to_str< String_type >( "\\r" ); return true; - case '\t': s += to_str< String_type >( "\\t" ); return true; - } - - return false; - } - - template< class String_type > - String_type add_esc_chars( const String_type& s, bool raw_utf8, bool esc_nonascii ) - { - typedef typename String_type::const_iterator Iter_type; - typedef typename String_type::value_type Char_type; - - String_type result; - - const Iter_type end( s.end() ); - - for( Iter_type i = s.begin(); i != end; ++i ) - { - const Char_type c( *i ); - - if( add_esc_char( c, result ) ) continue; - - if( raw_utf8 ) - { - result += c; - } - else - { - const wint_t unsigned_c( ( c >= 0 ) ? c : 256 + c ); - - if( !esc_nonascii && iswprint( unsigned_c ) ) - { - result += c; - } - else - { - result += non_printable_to_string< String_type >( unsigned_c ); - } - } - } - - return result; - } - - // this class generates the JSON text, - // it keeps track of the indentation level etc. - // - template< class Value_type, class Ostream_type > - class Generator - { - typedef typename Value_type::Config_type Config_type; - typedef typename Config_type::String_type String_type; - typedef typename Config_type::Object_type Object_type; - typedef typename Config_type::Array_type Array_type; - typedef typename String_type::value_type Char_type; - typedef typename Object_type::value_type Obj_member_type; - - public: - - Generator( const Value_type& value, Ostream_type& os, int options, unsigned int precision_of_doubles ) - : os_( os ) - , indentation_level_( 0 ) - , pretty_( ( options & pretty_print ) != 0 || ( options & single_line_arrays ) != 0 ) - , raw_utf8_( ( options & raw_utf8 ) != 0 ) - , esc_nonascii_( ( options & always_escape_nonascii ) != 0 ) - , single_line_arrays_( ( options & single_line_arrays ) != 0 ) - , ios_saver_( os ) - { - if( precision_of_doubles > 0 ) - { - precision_of_doubles_ = precision_of_doubles; - } - else - { - precision_of_doubles_ = ( options & remove_trailing_zeros ) != 0 ? 16 : 17; - } - - output( value ); - } - - private: - - void output( const Value_type& value ) - { - switch( value.type() ) - { - case obj_type: output( value.get_obj() ); break; - case array_type: output( value.get_array() ); break; - case str_type: output( value.get_str() ); break; - case bool_type: output( value.get_bool() ); break; - case real_type: output( value.get_real() ); break; - case int_type: output_int( value ); break; - case null_type: os_ << "null"; break; - default: assert( false ); - } - } - - void output( const Object_type& obj ) - { - output_array_or_obj( obj, '{', '}' ); - } - - void output( const Obj_member_type& member ) - { - output( Config_type::get_name( member ) ); space(); - os_ << ':'; space(); - output( Config_type::get_value( member ) ); - } - - void output_int( const Value_type& value ) - { - if( value.is_uint64() ) - { - os_ << value.get_uint64(); - } - else - { - os_ << value.get_int64(); - } - } - - void output( const String_type& s ) - { - os_ << '"' << add_esc_chars( s, raw_utf8_, esc_nonascii_ ) << '"'; - } - - void output( bool b ) - { - os_ << to_str< String_type >( b ? "true" : "false" ); - } - - void output( double d ) - { - os_ << std::setprecision( precision_of_doubles_ ) << d; - } - - static bool contains_composite_elements( const Array_type& arr ) - { - for( typename Array_type::const_iterator i = arr.begin(); i != arr.end(); ++i ) - { - const Value_type& val = *i; - - if( val.type() == obj_type || - val.type() == array_type ) - { - return true; - } - } - - return false; - } - - template< class Iter > - void output_composite_item( Iter i, Iter last ) - { - output( *i ); - - if( ++i != last ) - { - os_ << ','; - } - } - - void output( const Array_type& arr ) - { - if( single_line_arrays_ && !contains_composite_elements( arr ) ) - { - os_ << '['; space(); - - for( typename Array_type::const_iterator i = arr.begin(); i != arr.end(); ++i ) - { - output_composite_item( i, arr.end() ); - - space(); - } - - os_ << ']'; - } - else - { - output_array_or_obj( arr, '[', ']' ); - } - } - - template< class T > - void output_array_or_obj( const T& t, Char_type start_char, Char_type end_char ) - { - os_ << start_char; new_line(); - - ++indentation_level_; - - for( typename T::const_iterator i = t.begin(); i != t.end(); ++i ) - { - indent(); - - output_composite_item( i, t.end() ); - - new_line(); - } - - --indentation_level_; - - indent(); os_ << end_char; - } - - void indent() - { - if( !pretty_ ) return; - - for( int i = 0; i < indentation_level_; ++i ) - { - os_ << " "; - } - } - - void space() - { - if( pretty_ ) os_ << ' '; - } - - void new_line() - { - if( pretty_ ) os_ << '\n'; - } - - Generator& operator=( const Generator& ); // to prevent "assignment operator could not be generated" warning - - Ostream_type& os_; - int indentation_level_; - bool pretty_; - bool raw_utf8_; - bool esc_nonascii_; - bool single_line_arrays_; - int precision_of_doubles_; - boost::io::basic_ios_all_saver< Char_type > ios_saver_; // so that ostream state is reset after control is returned to the caller - }; - - // writes JSON Value to a stream, e.g. - // - // write_stream( value, os, pretty_print ); - // - template< class Value_type, class Ostream_type > - void write_stream( const Value_type& value, Ostream_type& os, int options = none, unsigned int precision_of_doubles = 0 ) - { - os << std::dec; - Generator< Value_type, Ostream_type >( value, os, options, precision_of_doubles ); - } - - // writes JSON Value to a stream, e.g. - // - // const string json_str = write( value, pretty_print ); - // - template< class Value_type > - typename Value_type::String_type write_string( const Value_type& value, int options = none, unsigned int precision_of_doubles = 0 ) - { - typedef typename Value_type::String_type::value_type Char_type; - - std::basic_ostringstream< Char_type > os; - - write_stream( value, os, options, precision_of_doubles ); - - return os.str(); - } -} - -#endif diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c34f1cc..b39f9a46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,7 +297,6 @@ endif() # set(CUKE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) -add_subdirectory(3rdparty/json_spirit) add_subdirectory(src) # diff --git a/README.md b/README.md index 4426eb7b..41a443e6 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,9 @@ It relies on a few libraries: Optional for the GTest driver. By default downloaded and built by CMake. * [GMock](http://code.google.com/p/googlemock/) 1.6 or later. Optional for the internal test suite. By default downloaded and built by CMake. +* [nlohmann-json](https://github.com/nlohmann/json) 3.10.5 or later * [Qt 4 or 5](http://qt-project.org/). Optional for the CalcQt example and QtTest driver (only Qt 5). -This header-only library is included in the source code: - -* [JSON Spirit](http://www.codeproject.com/KB/recipes/JSON_Spirit.aspx) - It might work with earlier versions of the libraries, but it was not tested with them. diff --git a/include/cucumber-cpp/internal/connectors/wire/WireProtocol.hpp b/include/cucumber-cpp/internal/connectors/wire/WireProtocol.hpp index 1941ac83..ea50bc60 100644 --- a/include/cucumber-cpp/internal/connectors/wire/WireProtocol.hpp +++ b/include/cucumber-cpp/internal/connectors/wire/WireProtocol.hpp @@ -149,11 +149,11 @@ class CUCUMBER_CPP_EXPORT WireMessageCodec { }; /** - * WireMessageCodec implementation with JsonSpirit. + * WireMessageCodec implementation with Json. */ -class CUCUMBER_CPP_EXPORT JsonSpiritWireMessageCodec : public WireMessageCodec { +class CUCUMBER_CPP_EXPORT JsonWireMessageCodec : public WireMessageCodec { public: - JsonSpiritWireMessageCodec() = default; + JsonWireMessageCodec() = default; std::shared_ptr decode(const std::string& request) const override; const std::string encode(const WireResponse& response) const override; }; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 084427ac..fa01bee8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,7 @@ include(GenerateExportHeader) +find_package(nlohmann_json 3.10.5 REQUIRED) + set(CUKE_SOURCES drivers/GenericDriver.cpp ContextManager.cpp @@ -75,11 +77,6 @@ foreach(TARGET $ $/include> ) - # Declaring json_spirit.header to be a direct dependency with target_link_libraries breaks installation - target_include_directories(${TARGET} SYSTEM - PRIVATE - $ - ) target_link_libraries(${TARGET} PUBLIC Boost::boost diff --git a/src/connectors/wire/WireProtocol.cpp b/src/connectors/wire/WireProtocol.cpp index d70591ae..9d74aa14 100644 --- a/src/connectors/wire/WireProtocol.cpp +++ b/src/connectors/wire/WireProtocol.cpp @@ -1,15 +1,13 @@ #include #include -#include -#include -#include +#include #include #include #include -using namespace json_spirit; +using json = nlohmann::json; namespace cucumber { namespace internal { @@ -80,44 +78,42 @@ void SnippetTextResponse::accept(WireResponseVisitor& visitor) const { */ namespace { -typedef std::shared_ptr (*CommandDecoder)(const mValue& jsonArgs); +typedef std::shared_ptr (*CommandDecoder)(const json& jsonArgs); -CukeEngine::tags_type getScenarioTags(const mValue& jsonArgs) { +CukeEngine::tags_type getScenarioTags(const json& jsonArgs) { CukeEngine::tags_type tags; if (!jsonArgs.is_null()) { - const mArray& jsonTags = jsonArgs.get_obj().find("tags")->second.get_array(); - for (mArray::const_iterator i = jsonTags.begin(); i != jsonTags.end(); ++i) { - tags.push_back(i->get_str()); + const auto& jsonTags = jsonArgs.at("tags"); + for (const auto& tag : jsonTags) { + tags.push_back(tag.get()); } } return tags; } -std::shared_ptr BeginScenarioDecoder(const mValue& jsonArgs) { +std::shared_ptr BeginScenarioDecoder(const json& jsonArgs) { return std::make_shared(getScenarioTags(jsonArgs)); } -std::shared_ptr EndScenarioDecoder(const mValue& jsonArgs) { +std::shared_ptr EndScenarioDecoder(const json& jsonArgs) { return std::make_shared(getScenarioTags(jsonArgs)); } -std::shared_ptr StepMatchesDecoder(const mValue& jsonArgs) { - mObject stepMatchesArgs(jsonArgs.get_obj()); - const std::string& nameToMatch(stepMatchesArgs["name_to_match"].get_str()); +std::shared_ptr StepMatchesDecoder(const json& jsonArgs) { + const std::string& nameToMatch = jsonArgs.at("name_to_match"); return std::make_shared(nameToMatch); } -void fillTableArg(const mArray& jsonTableArg, CukeEngine::invoke_table_type& tableArg) { - typedef mArray::size_type size_type; - size_type rows = jsonTableArg.size(); +void fillTableArg(const json& jsonTableArg, CukeEngine::invoke_table_type& tableArg) { + const std::size_t rows = jsonTableArg.size(); if (rows > 0) { - size_type columns = jsonTableArg[0].get_array().size(); + const std::size_t columns = jsonTableArg[0].get>().size(); tableArg.resize(rows); - for (size_type i = 0; i < rows; ++i) { - const mArray& jsonRow(jsonTableArg[i].get_array()); + for (std::size_t i = 0; i < rows; ++i) { + const auto& jsonRow(jsonTableArg[i].get>()); if (jsonRow.size() == columns) { - for (size_type j = 0; j < columns; ++j) { - tableArg[i].push_back(jsonRow[j].get_str()); + for (std::size_t j = 0; j < columns; ++j) { + tableArg[i].push_back(jsonRow[j]); } } else { // TODO: Invalid row @@ -129,35 +125,35 @@ void fillTableArg(const mArray& jsonTableArg, CukeEngine::invoke_table_type& tab } void fillInvokeArgs( - const mObject& invokeParams, + const json& invokeParams, CukeEngine::invoke_args_type& args, CukeEngine::invoke_table_type& tableArg ) { - const mArray& jsonArgs(invokeParams.find("args")->second.get_array()); - for (mArray::const_iterator i = jsonArgs.begin(); i != jsonArgs.end(); ++i) { - if (i->type() == str_type) { - args.push_back(i->get_str()); - } else if (i->type() == array_type) { - fillTableArg(i->get_array(), tableArg); + const auto& jsonArgs = invokeParams.at("args"); + for (const auto& arg : jsonArgs) { + if (arg.is_string()) { + args.push_back(arg.get()); + } else if (arg.is_array()) { + fillTableArg(arg, tableArg); } } } -std::shared_ptr InvokeDecoder(const mValue& jsonArgs) { - mObject invokeParams(jsonArgs.get_obj()); +std::shared_ptr InvokeDecoder(const json& jsonArgs) { + const auto& invokeParams = jsonArgs.get(); CukeEngine::invoke_args_type args; CukeEngine::invoke_table_type tableArg; - const std::string& id(invokeParams["id"].get_str()); + const std::string& id = invokeParams.at("id"); fillInvokeArgs(invokeParams, args, tableArg); return std::make_shared(id, args, tableArg); } -std::shared_ptr SnippetTextDecoder(const mValue& jsonArgs) { - mObject snippetTextArgs(jsonArgs.get_obj()); - const std::string& stepKeyword(snippetTextArgs["step_keyword"].get_str()); - const std::string& stepName(snippetTextArgs["step_name"].get_str()); - const std::string& multilineArgClass(snippetTextArgs["multiline_arg_class"].get_str()); +std::shared_ptr SnippetTextDecoder(const json& jsonArgs) { + const auto& snippetTextArgs = jsonArgs.get(); + const std::string& stepKeyword = snippetTextArgs.at("step_keyword"); + const std::string& stepName = snippetTextArgs.at("step_name"); + const std::string& multilineArgClass = snippetTextArgs.at("multiline_arg_class"); return std::make_shared(stepKeyword, stepName, multilineArgClass); } } @@ -170,20 +166,16 @@ static const std::map commandDecodersMap = { {"snippet_text", SnippetTextDecoder}, }; -std::shared_ptr JsonSpiritWireMessageCodec::decode(const std::string& request) const { - std::istringstream is(request); - mValue json; +std::shared_ptr JsonWireMessageCodec::decode(const std::string& request) const { try { - read_stream(is, json); - mArray& jsonRequest = json.get_array(); - mValue& jsonCommand = jsonRequest[0]; + json jsonRequest = json::parse(request); + const auto& jsonCommand = jsonRequest.at(0); - const std::map::const_iterator commandDecoder - = commandDecodersMap.find(jsonCommand.get_str()); + const auto& commandDecoder = commandDecodersMap.find(jsonCommand.get()); if (commandDecoder != commandDecodersMap.end() && commandDecoder->second) { - mValue jsonArgs; + json jsonArgs; if (jsonRequest.size() > 1) { - jsonArgs = jsonRequest[1]; + jsonArgs = jsonRequest.at(1); } return commandDecoder->second(jsonArgs); } @@ -197,19 +189,19 @@ namespace { class WireResponseEncoder : public WireResponseVisitor { private: - mArray jsonOutput; + json jsonOutput = json::array(); - void success(const mValue* detail = 0) { + void success(const json* detail = nullptr) { output("success", detail); } - void fail(const mValue* detail = 0) { + void fail(const json* detail = nullptr) { output("fail", detail); } - void output(const char* responseType, const mValue* detail = 0) { + void output(const std::string& responseType, const json* detail = nullptr) { jsonOutput.push_back(responseType); - if (detail == 0 || detail->is_null()) { + if (detail == nullptr || detail->is_null()) { return; } jsonOutput.push_back(*detail); @@ -219,8 +211,7 @@ class WireResponseEncoder : public WireResponseVisitor { std::string encode(const WireResponse& response) { jsonOutput.clear(); response.accept(*this); - const mValue v(jsonOutput); - return write_string(v, ::raw_utf8); + return jsonOutput.dump(); } void visit(const SuccessResponse& /*response*/) override { @@ -228,7 +219,7 @@ class WireResponseEncoder : public WireResponseVisitor { } void visit(const FailureResponse& response) override { - mObject detailObject; + json detailObject; if (!response.getMessage().empty()) { detailObject["message"] = response.getMessage(); } @@ -238,24 +229,24 @@ class WireResponseEncoder : public WireResponseVisitor { if (detailObject.empty()) { fail(); } else { - const mValue detail(detailObject); + const json detail(detailObject); fail(&detail); } } void visit(const PendingResponse& response) override { - mValue jsonReponse(response.getMessage()); + json jsonReponse(response.getMessage()); output("pending", &jsonReponse); } void visit(const StepMatchesResponse& response) override { - mArray jsonMatches; + json jsonMatches = json::array(); for (const StepMatch& m : response.getMatchingSteps()) { - mObject jsonM; + json jsonM; jsonM["id"] = m.id; - mArray jsonArgs; + json jsonArgs = json::array(); for (const StepMatchArg& ma : m.args) { - mObject jsonMa; + json jsonMa; jsonMa["val"] = ma.value; jsonMa["pos"] = static_cast(ma.position); jsonArgs.push_back(jsonMa); @@ -263,26 +254,25 @@ class WireResponseEncoder : public WireResponseVisitor { jsonM["args"] = jsonArgs; if (!m.source.empty()) { jsonM["source"] = m.source; - ; } if (!m.regexp.empty()) { jsonM["regexp"] = m.regexp; } jsonMatches.push_back(jsonM); } - mValue jsonReponse(jsonMatches); + json jsonReponse(jsonMatches); output("success", &jsonReponse); } void visit(const SnippetTextResponse& response) override { - mValue jsonReponse(response.getStepSnippet()); + json jsonReponse(response.getStepSnippet()); success(&jsonReponse); } }; } -const std::string JsonSpiritWireMessageCodec::encode(const WireResponse& response) const { +const std::string JsonWireMessageCodec::encode(const WireResponse& response) const { try { WireResponseEncoder encoder; return encoder.encode(response); diff --git a/src/main.cpp b/src/main.cpp index c66fc60c..18656715 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,7 +13,7 @@ void acceptWireProtocol( ) { using namespace ::cucumber::internal; CukeEngineImpl cukeEngine; - JsonSpiritWireMessageCodec wireCodec; + JsonWireMessageCodec wireCodec; WireProtocolHandler protocolHandler(wireCodec, cukeEngine); std::unique_ptr server; #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) diff --git a/tests/integration/WireProtocolTest.cpp b/tests/integration/WireProtocolTest.cpp index b9d1b3ea..d11fb041 100644 --- a/tests/integration/WireProtocolTest.cpp +++ b/tests/integration/WireProtocolTest.cpp @@ -45,7 +45,7 @@ class WireMessageCodecTest : public Test { } protected: - const JsonSpiritWireMessageCodec codec; + const JsonWireMessageCodec codec; }; /* @@ -68,8 +68,11 @@ TEST_F(WireMessageCodecTest, handlesStepMatchesMessage) { .Times(1) .WillRepeatedly(Return(std::vector(0))); - decode("[\"step_matches\"," - "{\"name_to_match\":\"name to match\"}]") + decode(R"json([ + "step_matches", { + "name_to_match": "name to match" + } + ])json") .run(engine); } @@ -77,19 +80,21 @@ TEST_F(WireMessageCodecTest, handlesBeginScenarioMessageWithoutArgument) { MockCukeEngine engine; EXPECT_CALL(engine, beginScenario(ElementsAre())).Times(1); - decode("[\"begin_scenario\"]").run(engine); + decode(R"json([ + "begin_scenario" + ])json") + .run(engine); } TEST_F(WireMessageCodecTest, handlesBeginScenarioMessageWithTagsArgument) { MockCukeEngine engine; EXPECT_CALL(engine, beginScenario(ElementsAre("bar", "baz", "foo"))).Times(1); - decode("[\"begin_scenario\"," - "{\"tags\":[" - "\"bar\"," - "\"baz\"," - "\"foo\"" - "]}]") + decode(R"json([ + "begin_scenario", { + "tags": ["bar", "baz", "foo"] + } + ])json") .run(engine); } @@ -97,27 +102,36 @@ TEST_F(WireMessageCodecTest, handlesBeginScenarioMessageWithNullArgument) { MockCukeEngine engine; EXPECT_CALL(engine, beginScenario(ElementsAre())).Times(1); - decode("[\"begin_scenario\",null]").run(engine); + decode(R"json([ + "begin_scenario", + null + ])json") + .run(engine); } TEST_F(WireMessageCodecTest, handlesInvokeMessageWithNoArgs) { MockCukeEngine engine; EXPECT_CALL(engine, invokeStep("42", ElementsAre(), ElementsAre())).Times(1); - decode("[\"invoke\",{\"id\":\"42\",\"args\":[]}]").run(engine); + decode(R"json([ + "invoke", { + "id": "42", + "args": [] + } + ])json") + .run(engine); } TEST_F(WireMessageCodecTest, handlesInvokeMessageWithoutTableArgs) { MockCukeEngine engine; EXPECT_CALL(engine, invokeStep("42", ElementsAre("p1", "p2", "p3"), ElementsAre())).Times(1); - decode("[\"invoke\",{" - "\"id\":\"42\"," - "\"args\":[" - "\"p1\"," - "\"p2\"," - "\"p3\"" - "}]") + decode(R"json([ + "invoke", { + "id": "42", + "args": ["p1", "p2", "p3"] + } + ])json") .run(engine); } @@ -138,17 +152,20 @@ TEST_F(WireMessageCodecTest, handlesInvokeMessageWithTableArgs) { ) .Times(1); - decode("[\"invoke\",{" - "\"id\":\"42\"," - "\"args\":[" - "\"p1\"," - "[" - "[\"col1\",\"col2\"]," - "[\"r1c1\",\"r1c2\"]," - "[\"r2c1\",\"r2c2\"]," - "[\"r3c1\",\"r3c2\"]" - "]" - "}]") + decode(R"json([ + "invoke", { + "id": "42", + "args": [ + "p1", + [ + ["col1", "col2"], + ["r1c1", "r1c2"], + ["r2c1", "r2c2"], + ["r3c1", "r3c2"] + ] + ] + } + ])json") .run(engine); } @@ -156,33 +173,49 @@ TEST_F(WireMessageCodecTest, handlesInvokeMessageWithNullArg) { MockCukeEngine engine; EXPECT_CALL(engine, invokeStep("42", ElementsAre(), ElementsAre())).Times(1); - decode("[\"invoke\",{\"id\":\"42\",\"args\":[null]}]").run(engine); + decode(R"json([ + "invoke", { + "id": "42", + "args": [null] + } + ])json") + .run(engine); } TEST_F(WireMessageCodecTest, handlesEndScenarioMessageWithoutArgument) { MockCukeEngine engine; EXPECT_CALL(engine, endScenario(ElementsAre())).Times(1); - decode("[\"end_scenario\"]").run(engine); + decode(R"json([ + "end_scenario" + ])json") + .run(engine); } TEST_F(WireMessageCodecTest, handlesEndScenarioMessageWithNullArgument) { MockCukeEngine engine; EXPECT_CALL(engine, endScenario(ElementsAre())).Times(1); - decode("[\"end_scenario\",null]").run(engine); + decode(R"json([ + "end_scenario", + null + ])json") + .run(engine); } TEST_F(WireMessageCodecTest, handlesEndScenarioMessageWithTagsArgument) { MockCukeEngine engine; EXPECT_CALL(engine, endScenario(ElementsAre("cu", "cum", "ber"))).Times(1); - decode("[\"end_scenario\"," - "{\"tags\":[" - "\"cu\"," - "\"cum\"," - "\"ber\"" - "]}]") + decode(R"json([ + "end_scenario", { + "tags": [ + "cu", + "cum", + "ber" + ] + } + ])json") .run(engine); } @@ -190,10 +223,13 @@ TEST_F(WireMessageCodecTest, handlesSnippetTextMessage) { MockCukeEngine engine; EXPECT_CALL(engine, snippetText("Keyword", "step description", "Some::Class")).Times(1); - decode("[\"snippet_text\"," - "{\"step_keyword\":\"Keyword\"," - "\"multiline_arg_class\":\"Some::Class\"," - "\"step_name\":\"step description\"}]") + decode(R"json([ + "snippet_text", { + "step_keyword": "Keyword", + "multiline_arg_class": "Some::Class", + "step_name": "step description" + } + ])json") .run(engine); } @@ -248,21 +284,22 @@ TEST_F(WireMessageCodecTest, handlesStepMatchesResponse) { matches.push_back(sm2); StepMatchesResponse response(matches); - EXPECT_THAT( - codec.encode(response), - StrEq("[\"success\",[{" - "\"args\":[]," - "\"id\":\"1234\"," - "\"regexp\":\"Some (.*) regexp\"," - "\"source\":\"MyClass.cpp:56\"" - "},{" - "\"args\":[{" - "\"pos\":5," - "\"val\":\"odd\"" - "}]," - "\"id\":\"9876\"" - "}]]") + // clang-format off + EXPECT_THAT(codec.encode(response), StrEq( + "[\"success\",[{" + "\"args\":[]," + "\"id\":\"1234\"," + "\"regexp\":\"Some (.*) regexp\"," + "\"source\":\"MyClass.cpp:56\"" + "},{" + "\"args\":[{" + "\"pos\":5," + "\"val\":\"odd\"" + "}]," + "\"id\":\"9876\"" + "}]]") ); + // clang-format on } TEST_F(WireMessageCodecTest, handlesSnippetTextResponse) { @@ -288,17 +325,17 @@ TEST_F(WireMessageCodecTest, encodesResponseUsingRawUtf8) { // clang-format off EXPECT_THAT(codec.encode(response), StrEq( - "[\"success\",[{" - "\"args\":[{" - "\"pos\":5," - "\"val\":\"カラオケ機\"" - "},{" - "\"pos\":18," - "\"val\":\"ASCII\"" - "}]," - "\"id\":\"1234\"," - "\"regexp\":\"Some (.+) regexp (.+)\"" - "}]]")); + "[\"success\",[{" + "\"args\":[{" + "\"pos\":5," + "\"val\":\"カラオケ機\"" + "},{" + "\"pos\":18," + "\"val\":\"ASCII\"" + "}]," + "\"id\":\"1234\"," + "\"regexp\":\"Some (.+) regexp (.+)\"" + "}]]")); // clang-format on }