6const std::string SniperJSON::SPACES(
" \n\t\r");
7const std::string SniperJSON::DELIMITS(
", \n]}\t\r");
20 cursor = jstr.find_first_not_of(SniperJSON::SPACES, cursor);
21 if (cursor != std::string::npos)
23 throw Exception(jstr, cursor);
35 if (m_type == 2 || m_type == 0)
37 m_jvec.push_back(var);
46 if (m_type == 1 || m_type == 0)
48 std::string _key =
'"' +
key +
'"';
49 m_jmap.insert(std::make_pair(_key, val));
80 return m_jmap.at(
'"' +
key +
'"');
85 return m_jmap.at(
'"' +
key +
'"');
90 std::ostringstream oss;
93 return loads(oss.str());
101void SniperJSON::init(
const std::string &jstr, StrCursor &cursor)
103 switch (getValidChar(jstr, cursor))
106 readObjectMap(jstr, cursor);
110 readArrayVec(jstr, cursor);
114 readStringStr(jstr, cursor);
118 readScalarStr(jstr, cursor);
123char SniperJSON::getValidChar(
const std::string &jstr, StrCursor &cursor)
125 cursor = jstr.find_first_not_of(SPACES, cursor);
126 if (cursor != std::string::npos)
128 return jstr.at(cursor);
130 throw Exception(jstr, cursor);
133void SniperJSON::readObjectMap(
const std::string &jstr, StrCursor &cursor)
137 if (getValidChar(jstr, ++cursor) !=
'}')
142 readStringStr(jstr, ++cursor);
143 const std::string &
key = m_jvar;
144 if (
key.size() == 2 || getValidChar(jstr, cursor) !=
':')
149 m_jmap.insert(std::make_pair(
key,
SniperJSON(jstr, ++cursor)));
150 }
while (getValidChar(jstr, cursor) ==
',');
155 if (status && getValidChar(jstr, cursor) ==
'}')
161 throw Exception(jstr, cursor);
164void SniperJSON::readArrayVec(
const std::string &jstr, StrCursor &cursor)
166 if (getValidChar(jstr, ++cursor) !=
']')
172 }
while (getValidChar(jstr, cursor) ==
',');
175 if (getValidChar(jstr, cursor) ==
']')
181 throw Exception(jstr, cursor);
184void SniperJSON::readStringStr(
const std::string &jstr, StrCursor &cursor)
186 if (getValidChar(jstr, cursor) ==
'"')
188 StrCursor pstart = cursor;
189 cursor = jstr.find(
'"', pstart + 1);
190 if (cursor != std::string::npos)
193 m_jvar = jstr.substr(pstart, cursor - pstart);
198 throw Exception(jstr, cursor);
201void SniperJSON::readScalarStr(
const std::string &jstr, StrCursor &cursor)
203 StrCursor pstart = cursor;
204 cursor = jstr.find_first_of(DELIMITS, pstart + 1);
205 if (cursor != std::string::npos || pstart == 0)
207 m_jvar = jstr.substr(pstart, cursor - pstart);
211 throw Exception(jstr, cursor);
214SniperJSON::Exception::Exception(
const std::string &msg)
215 : m_msg(
"json error: ")
220SniperJSON::Exception::Exception(
const std::string &jstr,
int cursor)
221 : m_msg(
"invalid json:\n")
223 m_msg += jstr.substr(0, cursor + 1);
224 m_msg +=
" <<< parsing error";
227SniperJSON::Exception::~Exception() throw()
231const char *SniperJSON::Exception::what()
const throw()
233 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)