1#include "RawDataCnv/SniperJSON.h"
6const std::string SniperJSON::SPACES(
" \n\t\r" );
7const std::string SniperJSON::DELIMITS(
", \n]}\t\r" );
15 cursor = jstr.find_first_not_of( SniperJSON::SPACES, cursor );
16 if ( cursor != std::string::npos ) {
throw Exception( jstr, cursor ); }
24 if ( m_type == 2 || m_type == 0 )
26 m_jvec.push_back( var );
34 if ( m_type == 1 || m_type == 0 )
36 std::string _key =
'"' +
key +
'"';
37 m_jmap.insert( std::make_pair( _key, val ) );
52 if ( m_type == 1 ) {
return m_jmap.size(); }
53 else if ( m_type == 2 ) {
return m_jvec.size(); }
59 return m_jmap.at(
'"' +
key +
'"' );
63 return m_jmap.at(
'"' +
key +
'"' );
67 std::ostringstream oss;
70 return loads( oss.str() );
75void SniperJSON::init(
const std::string& jstr, StrCursor& cursor ) {
76 switch ( getValidChar( jstr, cursor ) )
79 readObjectMap( jstr, cursor );
83 readArrayVec( jstr, cursor );
87 readStringStr( jstr, cursor );
91 readScalarStr( jstr, cursor );
96char SniperJSON::getValidChar(
const std::string& jstr, StrCursor& cursor ) {
97 cursor = jstr.find_first_not_of( SPACES, cursor );
98 if ( cursor != std::string::npos ) {
return jstr.at( cursor ); }
99 throw Exception( jstr, cursor );
102void SniperJSON::readObjectMap(
const std::string& jstr, StrCursor& cursor ) {
105 if ( getValidChar( jstr, ++cursor ) !=
'}' )
109 readStringStr( jstr, ++cursor );
110 const std::string&
key = m_jvar;
111 if (
key.size() == 2 || getValidChar( jstr, cursor ) !=
':' )
116 m_jmap.insert( std::make_pair(
key,
SniperJSON( jstr, ++cursor ) ) );
117 }
while ( getValidChar( jstr, cursor ) ==
',' );
122 if ( status && getValidChar( jstr, cursor ) ==
'}' )
128 throw Exception( jstr, cursor );
131void SniperJSON::readArrayVec(
const std::string& jstr, StrCursor& cursor ) {
132 if ( getValidChar( jstr, ++cursor ) !=
']' )
136 m_jvec.push_back(
SniperJSON( jstr, ++cursor ) );
137 }
while ( getValidChar( jstr, cursor ) ==
',' );
140 if ( getValidChar( jstr, cursor ) ==
']' )
146 throw Exception( jstr, cursor );
149void SniperJSON::readStringStr(
const std::string& jstr, StrCursor& cursor ) {
150 if ( getValidChar( jstr, cursor ) ==
'"' )
152 StrCursor pstart = cursor;
153 cursor = jstr.find(
'"', pstart + 1 );
154 if ( cursor != std::string::npos )
157 m_jvar = jstr.substr( pstart, cursor - pstart );
162 throw Exception( jstr, cursor );
165void SniperJSON::readScalarStr(
const std::string& jstr, StrCursor& cursor ) {
166 StrCursor pstart = cursor;
167 cursor = jstr.find_first_of( DELIMITS, pstart + 1 );
168 if ( cursor != std::string::npos || pstart == 0 )
170 m_jvar = jstr.substr( pstart, cursor - pstart );
174 throw Exception( jstr, cursor );
177SniperJSON::Exception::Exception(
const std::string& msg ) : m_msg(
"json error: " ) {
181SniperJSON::Exception::Exception(
const std::string& jstr,
int cursor )
182 : m_msg(
"invalid json:\n" ) {
183 m_msg += jstr.substr( 0, cursor + 1 );
184 m_msg +=
" <<< parsing error";
187SniperJSON::Exception::~Exception() throw() {}
189const char* SniperJSON::Exception::what()
const throw() {
return m_msg.c_str(); }
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
bool insert(const std::string &key, const SniperJSON &val)
static SniperJSON loads(const std::string &jstr)
bool push_back(const SniperJSON &var)
static SniperJSON load(std::istream &is)
SniperJSON & operator[](int index)