99#include " Exceptions.h"
1010#include < chrono>
1111#include < string>
12- #include " rapidjson/document.h "
12+ #include < tao/json.hpp > // ToJsonDocument() returns a tao::json::value (was rapidjson)
1313
1414class DataProvder ;
1515
@@ -74,32 +74,41 @@ namespace rcdb {
7474
7575 if (GetValueType () != ValueTypes::Json &&
7676 GetValueType () != ValueTypes::String &&
77- GetValueType () != ValueTypes::Blob) {
78- throw rcdb::ValueFormatError (" Value type of the condition is not String, Json or Blob" );
77+ GetValueType () != ValueTypes::Blob &&
78+ GetValueType () != ValueTypes::Time) {
79+ throw rcdb::ValueFormatError (" Value type of the condition is not String, Json, Blob or Time" );
7980 }
8081
82+ // For Time values this is the raw stored datetime string
83+ // ("YYYY-MM-DD HH:MM:SS"); use ToTime() for a parsed time_point.
8184 return _text_value;
8285 }
8386
8487
85- // / @deprecated use json ToJson() instead
86- rapidjson::Document ToJsonDocument ()
88+ /* * Returns the condition value parsed as a JSON document.
89+ *
90+ * Only valid when the condition's value type is Json (e.g. the CODA 'rtvs'
91+ * dictionary). This is a drop-in for the historical rapidjson implementation:
92+ * the same text is parsed into the same JSON structure/values -- only the
93+ * returned type changed from rapidjson::Document to tao::json::value, so the
94+ * header no longer depends on rapidjson. Callers keep `auto json = ...;` but
95+ * use tao's accessors (e.g. json.at("%(config)").get_string()) instead of
96+ * rapidjson's (json["%(config)"].GetString()).
97+ *
98+ * Throws rcdb::ValueFormatError if the value type is not Json, or the text is
99+ * not parseable JSON -- the same error contract as the old implementation.
100+ */
101+ tao::json::value ToJsonDocument ()
87102 {
88- using namespace rapidjson ;
89-
90103 if (GetValueType () != ValueTypes::Json) {
91104 throw rcdb::ValueFormatError (" Value type of the condition is not Json" );
92105 }
93106
94- Document document; // Default template parameter uses UTF8 and MemoryPoolAllocator.
95-
96-
97- // "normal" parsing, decode strings to new buffers. Can use other input stream via ParseStream().
98- if (document.Parse (_text_value.c_str ()).HasParseError ()) {
107+ try {
108+ return tao::json::from_string (_text_value);
109+ } catch (const std::exception &) {
99110 throw rcdb::ValueFormatError (" Error while parsing JSon" );
100111 }
101-
102- return document;
103112 }
104113
105114
@@ -123,36 +132,36 @@ namespace rcdb {
123132 rcdb::ValueTypes GetValueType () { return _type.GetValueType (); }
124133
125134
126- void SetId (unsigned long _id ) {
127- Condition:: _id = _id ;
135+ void SetId (unsigned long id ) {
136+ _id = id ;
128137 }
129138
130139 unsigned long GetId () {
131140 return _id;
132141 }
133142
134- void SetRunNumber (unsigned long _runNumber ) {
135- Condition:: _runNumber = _runNumber ;
143+ void SetRunNumber (unsigned long runNumber ) {
144+ _runNumber = runNumber ;
136145 }
137146
138- void SetTextValue (const std::string &_text_value ) {
139- Condition:: _text_value = _text_value ;
147+ void SetTextValue (const std::string &text_value ) {
148+ _text_value = text_value ;
140149 }
141150
142- void SetIntValue (int _int_value ) {
143- Condition:: _int_value = _int_value ;
151+ void SetIntValue (int int_value ) {
152+ _int_value = int_value ;
144153 }
145154
146- void SetFloatValue (double _float_value ) {
147- Condition:: _float_value = _float_value ;
155+ void SetFloatValue (double float_value ) {
156+ _float_value = float_value ;
148157 }
149158
150- void SetBoolValue (bool _bool_value ) {
151- Condition:: _bool_value = _bool_value ;
159+ void SetBoolValue (bool bool_value ) {
160+ _bool_value = bool_value ;
152161 }
153162
154- void SetTime (std::chrono::time_point<std::chrono::system_clock> _time ) {
155- Condition:: _time = _time ;
163+ void SetTime (std::chrono::time_point<std::chrono::system_clock> time ) {
164+ _time = time ;
156165 }
157166
158167 private:
0 commit comments