1#ifndef JSON_SPIRIT_READER_TEMPLATE 
    2#define JSON_SPIRIT_READER_TEMPLATE 
    9#if defined(_MSC_VER) && (_MSC_VER >= 1020) 
   18#include <boost/bind.hpp> 
   19#include <boost/function.hpp> 
   20#include <boost/version.hpp> 
   22#if BOOST_VERSION >= 103800 
   23    #include <boost/spirit/include/classic_core.hpp> 
   24    #include <boost/spirit/include/classic_confix.hpp> 
   25    #include <boost/spirit/include/classic_escape_char.hpp> 
   26    #include <boost/spirit/include/classic_multi_pass.hpp> 
   27    #include <boost/spirit/include/classic_position_iterator.hpp> 
   28    #define spirit_namespace boost::spirit::classic 
   30    #include <boost/spirit/core.hpp> 
   31    #include <boost/spirit/utility/confix.hpp> 
   32    #include <boost/spirit/utility/escape_char.hpp> 
   33    #include <boost/spirit/iterator/multi_pass.hpp> 
   34    #include <boost/spirit/iterator/position_iterator.hpp> 
   35    #define spirit_namespace boost::spirit 
   40    const spirit_namespace::int_parser < boost::int64_t >  
int64_p  = spirit_namespace::int_parser < boost::int64_t  >();
 
   41    const spirit_namespace::uint_parser< boost::uint64_t > 
uint64_p = spirit_namespace::uint_parser< boost::uint64_t >();
 
   43    template< 
class Iter_type >
 
   44    bool is_eq( Iter_type first, Iter_type last, 
const char* c_str )
 
   46        for( Iter_type i = first; i != last; ++i, ++c_str )
 
   48            if( *c_str == 0 ) 
return false;
 
   50            if( *i != *c_str ) 
return false;
 
   56    template< 
class Char_type >
 
   59        if( ( c >= 
'0' ) && ( c <= 
'9' ) ) 
return c - 
'0';
 
   60        if( ( c >= 
'a' ) && ( c <= 
'f' ) ) 
return c - 
'a' + 10;
 
   61        if( ( c >= 
'A' ) && ( c <= 
'F' ) ) 
return c - 
'A' + 10;
 
   65    template< 
class Char_type, 
class Iter_type >
 
   68        const Char_type c1( *( ++begin ) );
 
   69        const Char_type c2( *( ++begin ) );
 
   74    template< 
class Char_type, 
class Iter_type >
 
   77        const Char_type c1( *( ++begin ) );
 
   78        const Char_type c2( *( ++begin ) );
 
   79        const Char_type c3( *( ++begin ) );
 
   80        const Char_type c4( *( ++begin ) );
 
   88    template< 
class String_type >
 
   90                                        typename String_type::const_iterator& begin, 
 
   91                                        typename String_type::const_iterator end )
 
   93        typedef typename String_type::value_type Char_type;
 
   95        const Char_type c2( *begin );
 
   99            case 't':  s += 
'\t'; 
break;
 
  100            case 'b':  s += 
'\b'; 
break;
 
  101            case 'f':  s += 
'\f'; 
break;
 
  102            case 'n':  s += 
'\n'; 
break;
 
  103            case 'r':  s += 
'\r'; 
break;
 
  104            case '\\': s += 
'\\'; 
break;
 
  105            case '/':  s += 
'/';  
break;
 
  106            case '"':  s += 
'"';  
break;
 
  109                if( end - begin >= 3 )  
 
  111                    s += hex_str_to_char< Char_type >( begin );  
 
  117                if( end - begin >= 5 )  
 
  119                    s += unicode_str_to_char< Char_type >( begin );  
 
  126    template< 
class String_type >
 
  128                                   typename String_type::const_iterator end )
 
  130        typedef typename String_type::const_iterator Iter_type;
 
  132        if( end - begin < 2 ) 
return String_type( begin, end );
 
  136        result.reserve( end - begin );
 
  138        const Iter_type end_minus_1( end - 1 );
 
  140        Iter_type substr_start = begin;
 
  143        for( ; i < end_minus_1; ++i )
 
  147                result.append( substr_start, i );
 
  153                substr_start = i + 1;
 
  157        result.append( substr_start, end );
 
  162    template< 
class String_type >
 
  163    String_type 
get_str_( 
typename String_type::const_iterator begin, 
 
  164                       typename String_type::const_iterator end )
 
  166        assert( end - begin >= 2 );
 
  168        typedef typename String_type::const_iterator Iter_type;
 
  170        Iter_type str_without_quotes( ++begin );
 
  171        Iter_type end_without_quotes( --end );
 
  173        return substitute_esc_chars< String_type >( str_without_quotes, end_without_quotes );
 
  176    inline std::string 
get_str( std::string::const_iterator begin, std::string::const_iterator end )
 
  178        return get_str_< std::string >( begin, end );
 
  181    inline std::wstring 
get_str( std::wstring::const_iterator begin, std::wstring::const_iterator end )
 
  183        return get_str_< std::wstring >( begin, end );
 
  186    template< 
class String_type, 
class Iter_type >
 
  187    String_type 
get_str( Iter_type begin, Iter_type end )
 
  189        const String_type tmp( begin, end );  
 
  191        return get_str( tmp.begin(), tmp.end() );
 
  199    template< 
class Value_type, 
class Iter_type >
 
  220            begin_compound< Object_type >();
 
  234            begin_compound< Array_type >();
 
  248            name_ = get_str< String_type >( begin, end );
 
  251        void new_str( Iter_type begin, Iter_type end )
 
  258            assert( 
is_eq( begin, end, 
"true" ) );
 
  265            assert( 
is_eq( begin, end, 
"false" ) );
 
  272            assert( 
is_eq( begin, end, 
"null" ) );
 
  306        template< 
class Array_or_obj >
 
  317                Array_or_obj new_array_or_obj;   
 
  359    template< 
typename Iter_type >
 
  360    void throw_error( spirit_namespace::position_iterator< Iter_type > i, 
const std::string& reason )
 
  362        throw Error_position( i.get_position().line, i.get_position().column, reason );
 
  365    template< 
typename Iter_type >
 
  373    template< 
class Value_type, 
class Iter_type >
 
  374    class Json_grammer : 
public spirit_namespace::grammar< Json_grammer< Value_type, Iter_type > >
 
  415        template< 
typename ScannerT >
 
  424                typedef typename Value_type::String_type::value_type Char_type;
 
  429                typedef boost::function< void( Char_type )            > Char_action;
 
  430                typedef boost::function< void( Iter_type, Iter_type ) > Str_action;
 
  431                typedef boost::function< void( 
double )               > Real_action;
 
  459                    | str_p( 
"true" ) [ new_true  ] 
 
  460                    | str_p( 
"false" )[ new_false ] 
 
  461                    | str_p( 
"null" ) [ new_null  ]
 
  465                    = ch_p(
'{')[ begin_obj ]
 
  481                    = ch_p(
'[')[ begin_array ]
 
  503                    = strict_real_p[ new_real   ] 
 
  511            const spirit_namespace::rule< ScannerT >& 
start()
 const { 
return json_; }
 
  521    template< 
class Iter_type, 
class Value_type >
 
  524        typedef spirit_namespace::position_iterator< Iter_type > Posn_iter_t;
 
  526        const Posn_iter_t posn_begin( begin, end );
 
  527        const Posn_iter_t posn_end( end, end );
 
  532    template< 
class Istream_type >
 
  537        typedef spirit_namespace::multi_pass< istream_iter > 
Mp_iter;
 
  541            is.unsetf( std::ios::skipws );
 
  559    template< 
class Iter_type, 
class Value_type >
 
  564        const spirit_namespace::parse_info< Iter_type > info = 
 
  565                            spirit_namespace::parse( begin, end, 
 
  567                                                    spirit_namespace::space_p | 
 
  568                                                    spirit_namespace::comment_p(
"//") | 
 
  569                                                    spirit_namespace::comment_p(
"/*", 
"*/") );
 
  588    template< 
class Iter_type, 
class Value_type >
 
  607    template< 
class String_type, 
class Value_type >
 
  610        typename String_type::const_iterator begin = s.begin();
 
  619    template< 
class String_type, 
class Value_type >
 
  629    template< 
class Istream_type, 
class Value_type >
 
  641    template< 
class Istream_type, 
class Value_type >
 
Definition: json_spirit_reader_template.h:417
definition(const Json_grammer &self)
Definition: json_spirit_reader_template.h:420
spirit_namespace::rule< ScannerT > array_
Definition: json_spirit_reader_template.h:509
spirit_namespace::rule< ScannerT > string_
Definition: json_spirit_reader_template.h:509
spirit_namespace::rule< ScannerT > json_
Definition: json_spirit_reader_template.h:509
spirit_namespace::rule< ScannerT > elements_
Definition: json_spirit_reader_template.h:509
spirit_namespace::rule< ScannerT > object_
Definition: json_spirit_reader_template.h:509
spirit_namespace::rule< ScannerT > members_
Definition: json_spirit_reader_template.h:509
const spirit_namespace::rule< ScannerT > & start() const
Definition: json_spirit_reader_template.h:511
spirit_namespace::rule< ScannerT > number_
Definition: json_spirit_reader_template.h:509
spirit_namespace::rule< ScannerT > pair_
Definition: json_spirit_reader_template.h:509
spirit_namespace::rule< ScannerT > value_
Definition: json_spirit_reader_template.h:509
Definition: json_spirit_reader_template.h:375
static void throw_not_value(Iter_type begin, Iter_type end)
Definition: json_spirit_reader_template.h:385
Json_grammer(Semantic_actions_t &semantic_actions)
Definition: json_spirit_reader_template.h:380
static void throw_not_string(Iter_type begin, Iter_type end)
Definition: json_spirit_reader_template.h:410
Semantic_actions_t & actions_
Definition: json_spirit_reader_template.h:518
Json_grammer & operator=(const Json_grammer &)
static void throw_not_pair(Iter_type begin, Iter_type end)
Definition: json_spirit_reader_template.h:400
static void throw_not_colon(Iter_type begin, Iter_type end)
Definition: json_spirit_reader_template.h:405
static void throw_not_array(Iter_type begin, Iter_type end)
Definition: json_spirit_reader_template.h:390
Semantic_actions< Value_type, Iter_type > Semantic_actions_t
Definition: json_spirit_reader_template.h:378
static void throw_not_object(Iter_type begin, Iter_type end)
Definition: json_spirit_reader_template.h:395
Definition: json_spirit_reader_template.h:201
void begin_obj(Char_type c)
Definition: json_spirit_reader_template.h:216
void new_name(Iter_type begin, Iter_type end)
Definition: json_spirit_reader_template.h:244
void new_false(Iter_type begin, Iter_type end)
Definition: json_spirit_reader_template.h:263
String_type::value_type Char_type
Definition: json_spirit_reader_template.h:208
Config_type::Object_type Object_type
Definition: json_spirit_reader_template.h:206
std::vector< Value_type * > stack_
Definition: json_spirit_reader_template.h:354
void end_array(Char_type c)
Definition: json_spirit_reader_template.h:237
Value_type * current_p_
Definition: json_spirit_reader_template.h:352
Config_type::String_type String_type
Definition: json_spirit_reader_template.h:205
void begin_compound()
Definition: json_spirit_reader_template.h:307
void new_uint64(boost::uint64_t ui)
Definition: json_spirit_reader_template.h:282
void new_int(boost::int64_t i)
Definition: json_spirit_reader_template.h:277
Value_type * add_to_current(const Value_type &value)
Definition: json_spirit_reader_template.h:333
void new_true(Iter_type begin, Iter_type end)
Definition: json_spirit_reader_template.h:256
Value_type & value_
Definition: json_spirit_reader_template.h:351
void end_compound()
Definition: json_spirit_reader_template.h:323
String_type name_
Definition: json_spirit_reader_template.h:356
void new_real(double d)
Definition: json_spirit_reader_template.h:287
Semantic_actions(Value_type &value)
Definition: json_spirit_reader_template.h:210
void end_obj(Char_type c)
Definition: json_spirit_reader_template.h:223
void new_str(Iter_type begin, Iter_type end)
Definition: json_spirit_reader_template.h:251
Value_type * add_first(const Value_type &value)
Definition: json_spirit_reader_template.h:297
Value_type::Config_type Config_type
Definition: json_spirit_reader_template.h:204
void begin_array(Char_type c)
Definition: json_spirit_reader_template.h:230
Config_type::Array_type Array_type
Definition: json_spirit_reader_template.h:207
void new_null(Iter_type begin, Iter_type end)
Definition: json_spirit_reader_template.h:270
Semantic_actions & operator=(const Semantic_actions &)
#define spirit_namespace
Definition: json_spirit_reader_template.h:35
const Status _2
Definition: status.h:444
const Status _1
Definition: status.h:443
Definition: json_spirit_error_position.h:16
void append_esc_char_and_incr_iter(String_type &s, typename String_type::const_iterator &begin, typename String_type::const_iterator end)
Definition: json_spirit_reader_template.h:89
const spirit_namespace::uint_parser< boost::uint64_t > uint64_p
Definition: json_spirit_reader_template.h:41
String_type get_str_(typename String_type::const_iterator begin, typename String_type::const_iterator end)
Definition: json_spirit_reader_template.h:163
Char_type unicode_str_to_char(Iter_type &begin)
Definition: json_spirit_reader_template.h:75
void add_posn_iter_and_read_range_or_throw(Iter_type begin, Iter_type end, Value_type &value)
Definition: json_spirit_reader_template.h:522
String_type substitute_esc_chars(typename String_type::const_iterator begin, typename String_type::const_iterator end)
Definition: json_spirit_reader_template.h:127
Iter_type read_range_or_throw(Iter_type begin, Iter_type end, Value_type &value)
Definition: json_spirit_reader_template.h:560
bool is_eq(Iter_type first, Iter_type last, const char *c_str)
Definition: json_spirit_reader_template.h:44
void throw_error(spirit_namespace::position_iterator< Iter_type > i, const std::string &reason)
Definition: json_spirit_reader_template.h:360
Char_type hex_str_to_char(Iter_type &begin)
Definition: json_spirit_reader_template.h:66
void read_string_or_throw(const String_type &s, Value_type &value)
Definition: json_spirit_reader_template.h:620
bool read_range(Iter_type &begin, Iter_type end, Value_type &value)
Definition: json_spirit_reader_template.h:589
Char_type hex_to_num(const Char_type c)
Definition: json_spirit_reader_template.h:57
bool read_stream(Istream_type &is, Value_type &value)
Definition: json_spirit_reader_template.h:630
void read_stream_or_throw(Istream_type &is, Value_type &value)
Definition: json_spirit_reader_template.h:642
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
Definition: json_spirit_reader_template.h:176
bool read_string(const String_type &s, Value_type &value)
Definition: json_spirit_reader_template.h:608
const spirit_namespace::int_parser< boost::int64_t > int64_p
Definition: json_spirit_reader_template.h:40
Value_type
Definition: json_spirit_value.h:33
@ obj_type
Definition: json_spirit_value.h:33
@ array_type
Definition: json_spirit_value.h:33
Definition: json_spirit_error_position.h:22
Definition: json_spirit_reader_template.h:534
Mp_iter begin_
Definition: json_spirit_reader_template.h:547
std::istream_iterator< Char_type, Char_type > istream_iter
Definition: json_spirit_reader_template.h:536
spirit_namespace::multi_pass< istream_iter > Mp_iter
Definition: json_spirit_reader_template.h:537
Multi_pass_iters(Istream_type &is)
Definition: json_spirit_reader_template.h:539
Istream_type::char_type Char_type
Definition: json_spirit_reader_template.h:535
Mp_iter end_
Definition: json_spirit_reader_template.h:548
long long int64_t
Definition: wposix_types.h:48
unsigned long long uint64_t
Definition: wposix_types.h:57