8 #include "CoolKernel/RecordSpecification.h"
9 #include "CoolKernel/Record.h"
10 #include "CoralBase/AttributeList.h"
11 #include "CoralBase/Attribute.h"
13 #include "boost/regex.hpp"
26 const std::map<std::string, cool::StorageType::TypeId> typeCorrespondance={
28 {
"Bool", StorageType::Bool},
29 {
"UChar",StorageType::UChar},
30 {
"Int16", StorageType::Int16},
31 {
"UInt16", StorageType::UInt16},
32 {
"Int32", StorageType::Int32},
33 {
"UInt32", StorageType::UInt32},
34 {
"UInt63",StorageType::UInt63},
35 {
"Int64", StorageType::Int64},
36 {
"Float", StorageType::Float},
37 {
"Double", StorageType::Double},
38 {
"String255", StorageType::String255},
39 {
"String4k", StorageType::String4k},
40 {
"String64k", StorageType::String64k},
41 {
"String16M", StorageType::String16M},
42 {
"String128M", StorageType::String128M},
43 {
"Blob64k", StorageType::Blob64k},
44 {
"Blob16M", StorageType::Blob16M},
45 {
"Blob128M", StorageType::Blob128M}
61 if (not
s.good() or
s.eof()){
62 const std::string
msg(
"Json2Cool constructor; Input is invalid and could not be opened.");
63 throw std::runtime_error(
msg);
69 std::cout<<
"ERROR AT LINE "<<__LINE__<<
" of "<<__FILE__<<std::endl;
70 std::cout<<
e.what()<<std::endl;
86 const std::string& ks=
k.key();
87 const long long key=std::stoll(ks);
88 std::vector<coral::AttributeList> tempVector;
89 for (json::const_iterator
i=
f.begin();
i!=
f.end();++
i){
90 const json& arrayElem=
i.value();
92 const auto & attList=
r.attributeList();
93 tempVector.push_back(attList);
101 const std::string& ks=
i.key();
102 const long long key=std::stoll(ks);
104 const auto & attList=
r.attributeList();
113 cool::RecordSpecification *
115 if (stringSpecification.empty())
return nullptr;
116 auto *
spec =
new cool::RecordSpecification();
118 std::string inputObj=stringSpecification;
121 for (
unsigned int i = 0;
i < nl.size();
i++)
124 auto it = nl[
i].items().begin();
125 std::string
n((*it).key());
126 std::string
t((*it).value());
127 spec->extend(
n, typeCorrespondance.find(
t)->second);
133 std::string
input(stringSpecification);
135 std::string
regex=R
"delim(([^\s,:]*):\s?([^\s,]*),?)delim";
141 std::string
n(
what[1]);
142 std::string
t(
what[2]);
144 spec->extend(
n, typeCorrespondance.find(
t)->second);
154 cool::Record
a(*pSpec);
155 unsigned int s=
a.size();
157 json::const_iterator
it = j.begin();
158 for (
unsigned int i(0);
i!=
s;++
i){
163 const auto thisVal =
it.value();
170 if (thisVal.is_null()){
176 if(strVal.size()>2&& strVal[0]==
'"'&& strVal[strVal.size()-1]==
'"')
177 strVal=strVal.substr(1,strVal.size()-2);
179 if((strVal.compare(
"NULL")==0||strVal.compare(
"null")==0)&&
180 (typespec==StorageType::Bool || typespec==StorageType::Int16 || typespec==StorageType::UInt16
181 || typespec==StorageType::Int32 || typespec==StorageType::UInt32
182 || typespec==StorageType::Int64 || typespec==StorageType::UInt63
183 || typespec==StorageType::Float || typespec==StorageType::Double)){
188 case StorageType::Bool:
190 const bool newVal=(strVal ==
"true");
191 att.setValue<
bool>(newVal);
194 case StorageType::UChar:
196 const unsigned char newVal=std::stoul(strVal);
197 att.setValue<
unsigned char>(newVal);
200 case StorageType::Int16:
202 const short newVal=std::stol(strVal);
203 att.setValue<
short>(newVal);
206 case StorageType::UInt16:
208 const unsigned short newVal=std::stoul(strVal);
209 att.setValue<
unsigned short>(newVal);
212 case StorageType::Int32:
214 const int newVal=std::stoi(strVal);
215 att.setValue<
int>(newVal);
218 case StorageType::UInt32:
220 const unsigned int newVal=std::stoull(strVal);
221 att.setValue<
unsigned int>(newVal);
224 case StorageType::UInt63:
226 const unsigned long long newVal=std::stoull(strVal);
227 att.setValue<
unsigned long long>(newVal);
230 case StorageType::Int64:
232 const long long newVal=std::stoll(strVal);
233 att.setValue<
long long>(newVal);
236 case StorageType::Float:
238 const float newVal=std::stof(strVal);
239 att.setValue<
float>(newVal);
242 case StorageType::Double:
244 const double newVal=std::stod(strVal);
245 att.setValue<
double>(newVal);
248 case StorageType::String255:
249 case StorageType::String4k:
250 case StorageType::String64k:
251 case StorageType::String16M:
252 case StorageType::String128M:
254 att.setValue<std::string>(thisVal.get<std::string>());
257 case StorageType::Blob128M:
258 case StorageType::Blob16M:
259 case StorageType::Blob64k:
268 for (
auto& [
key,
val] : typeCorrespondance) {
277 std::string errorMessage(
"UNTREATED TYPE! " +
typeName);
278 std::cerr << errorMessage << std::endl;
279 throw std::runtime_error(errorMessage);
285 std::cerr <<
e.what() << std::endl;
286 throw std::runtime_error(
e.what());