67 std::vector<std::string>
data;
99 os <<
"Param: " << v.
name <<
"= "
102 <<
" UCD=" << v.
ucd <<
"\n"
114 os <<
"Field: " << v.
name <<
"length="
115 << v.
data.size() <<
" [" << v.
unit <<
"]\n"
117 <<
" UCD=" << v.
ucd <<
"\n"
119 if (v.
data.size() > 0){
121 for (
size_t idx=0; idx < 5; ++idx) {os << v.
data[idx] <<
", ";}
123 for (
size_t idx=v.
data.size() - 5; idx < v.
data.size() - 1; ++idx) {os << v.
data[idx] <<
", ";}
124 os << v.
data[v.
data.size() - 1] <<
"]\n";
133 template <
typename T>
137 os <<
"Field: " << v.
name <<
"length="
138 << v.
data.size() <<
" [" << v.
unit <<
"]\n"
140 <<
" UCD=" << v.
ucd <<
"\n"
142 if (v.
data.size() > 0){
144 for (
size_t idx=0; idx < 5; ++idx) {os << v.
data[idx] <<
", ";}
146 for (
size_t idx=v.
data.size() - 5; idx < v.
data.size() - 1; ++idx) {os << v.
data[idx] <<
", ";}
147 os << v.
data[v.
data.size() - 1] <<
"]\n";
169 VOTable(
const std::string & input_filename);
174 template <
typename T>
VOField<T> get(std::string field_name);
180 void parse(
const std::string & input_filename);
198 this->parse(input_filename);
199 this->setup_params();
200 this->setup_fields();
209 std::string json_str =
xml2json(content.c_str());
210 this->document.Parse(json_str.c_str());
211 this->setup_params();
212 this->setup_fields();
220 void VOTable::parse(
const std::string & input_filename){
221 std::ostringstream oss;
222 std::ifstream infile;
223 infile.open(input_filename);
225 oss << infile.rdbuf();
227 std::string json_str =
xml2json(oss.str().data());
228 this->document.Parse(json_str.c_str());
237 void VOTable::setup_params(){
239 if (!this->document[
"VOTABLE"][
"RESOURCE"][
"TABLE"].HasMember(
"PARAM")){
240 std::cerr <<
"No PARAM elements found in VOTABLE\n";
244 const rapidjson::Value& where = this->document[
"VOTABLE"][
"RESOURCE"][
"TABLE"][
"PARAM"];
245 for (
const auto& v : where.GetArray()){
247 auto name = v[
"@name"].GetString();
249 p.datatype = v[
"@datatype"].GetString();
250 p.value = v[
"@value"].GetString();
251 if (v.HasMember(
"@ucd")) {p.ucd = v[
"@ucd"].GetString();}
252 if (v.HasMember(
"@ytype")) {p.utype = v[
"@utype"].GetString();}
253 if (v.HasMember(
"@unit")) {p.unit = v[
"@unit"].GetString();}
254 if (v.HasMember(
"@DESCRIPTION")) {p.description = v[
"@DESCRIPTION"].GetString(); }
269 void VOTable::setup_fields(){
272 const rapidjson::Value& where = this->document[
"VOTABLE"][
"RESOURCE"][
"TABLE"][
"FIELD"];
273 for (
const auto& v : where.GetArray()){
275 auto name = v[
"@name"].GetString();
277 p.datatype = v[
"@datatype"].GetString();
278 if (v.HasMember(
"@ucd")) {p.ucd = v[
"@ucd"].GetString();}
279 if (v.HasMember(
"@ytype")) {p.utype = v[
"@utype"].GetString();}
280 if (v.HasMember(
"@unit")) {p.unit = v[
"@unit"].GetString();}
281 if (v.HasMember(
"@DESCRIPTION")) {p.description = v[
"@DESCRIPTION"].GetString(); }
282 this->
fields.push_back(p);
286 const rapidjson::Value& data = this->document[
"VOTABLE"][
"RESOURCE"][
"TABLE"][
"DATA"][
"TABLEDATA"][
"TR"];
287 size_t n_entries = data.GetArray().Size();
288 size_t n_fields = this->
fields.size();
289 for (
auto & field: this->
fields){
290 field.data.resize(n_entries);
292 this->n_data = n_entries;
295 const auto& tr_array = data.GetArray();
296 for (
size_t k_entry=0; k_entry < n_entries; ++k_entry){
297 const auto& td = tr_array[k_entry][
"TD"].GetArray();
298 for(
size_t k_field=0; k_field < n_fields; ++k_field){
299 this->fields[k_field].data[k_entry] = td[k_field].GetString();
319 return this->fields.size();
329 template <
typename T>
332 for (
size_t idx=0; idx < this->fields.size(); ++idx){
333 if (field_name.compare(this->fields[idx].name) == 0){
338 if (match == (
size_t(-1))){
339 throw std::runtime_error(
"Field: " + field_name +
" not found.");
341 return this->get<T>(match);
351 template <
typename T>
353 size_t n = this->
size();
355 newfield.
data.resize(n);
356 const auto & field = this->fields[field_index];
360 newfield.
data.begin(), [](std::string val) { return parseString<T>(val);});
361 newfield.
name = field.name;
363 newfield.
ucd = field.ucd;
364 newfield.
utype = field.utype;
365 newfield.
unit = field.unit;
377 for (
const auto & p: vot.
params){
378 os <<
" - " << p.second;
381 for (
const auto & f: vot.
fields){