diff --git a/lib/tdm_datamodel.hpp b/lib/tdm_datamodel.hpp index 8f26d05..d200372 100644 --- a/lib/tdm_datamodel.hpp +++ b/lib/tdm_datamodel.hpp @@ -152,7 +152,8 @@ struct tdm_channelgroup { std::string name_; std::string description_; std::string root_; - std::vector channels_; // referenced by id + std::vector channels_; // referenced by id + std::vector submatrices_; const std::string get_info(int width = 20) { diff --git a/lib/tdm_reaper.cpp b/lib/tdm_reaper.cpp index 09f5042..d8d2dce 100644 --- a/lib/tdm_reaper.cpp +++ b/lib/tdm_reaper.cpp @@ -65,7 +65,7 @@ void tdm_reaper::process_tdm(bool showlog) // process elements of XML this->process_include(showlog); this->process_root(showlog); - + this->process_channelgroups(showlog); } void tdm_reaper::process_include(bool showlog) @@ -147,18 +147,50 @@ void tdm_reaper::process_root(bool showlog) tdmroot_.author_ = tdmdataroot.child_value("author"); tdmroot_.timestamp_ = tdmdataroot.child_value("datetime"); - // collect group identifiers by means of regex pattern "usi[0-9]+" - std::string chnlgrps = tdmdataroot.child_value("channelgroups"); - std::regex regid("(usi[0-9]+)"); - std::smatch usi_match; - std::sregex_iterator pos(chnlgrps.begin(), chnlgrps.end(), regid); - std::sregex_iterator end; - for ( ; pos != end; ++pos) tdmroot_.channelgroups_.push_back(pos->str()); - // std::cout<str(0)<<"\n"; + // collect channelgroup identifiers associated to root + tdmroot_.channelgroups_ = this->extract_ids(tdmdataroot.child_value("channelgroups")); if ( showlog ) std::cout< + pugi::xml_node tdmdata = xml_doc_.child("usi:tdm").child("usi:data"); + + // find all its elements + for ( pugi::xml_node group = tdmdata.child("tdm_channelgroup"); group; + group = group.next_sibling("tdm_channelgroup") ) + { + // declare new group + tdm_channelgroup tdmchannelgroup; + + // extract properties + tdmchannelgroup.id_ = group.attribute("id").value(); + tdmchannelgroup.name_ = group.child_value("name"); + tdmchannelgroup.description_ = group.child_value("description"); + std::vector gr = this->extract_ids(group.child_value("root")); + if ( gr.size() == 1 ) + { + tdmchannelgroup.root_ = gr.at(0); + } + else + { + throw std::runtime_error("tdm_channelgroup without root id"); + } + tdmchannelgroup.channels_ = this->extract_ids(group.child_value("channels")); + tdmchannelgroup.submatrices_ = this->extract_ids(group.child_value("submatrices")); + + // add channelgroup to map + tdmchannelgroups_.insert( std::pair( + tdmchannelgroup.id_,tdmchannelgroup) ); + + if ( showlog ) std::cout< tdmchannelgroups_; + // // number/names/ids of channels, channelgroups and channels's assignment to groups // int num_channels_, num_groups_; // std::vector channel_id_, inc_id_, units_, channel_name_; @@ -80,6 +83,24 @@ class tdm_reaper // // binary data container // std::vector tdxbuf_; + // extract list of identifiers from e.g. "#xpointer(id("usi12") id("usi13"))" + std::vector extract_ids(std::string idstring) + { + // collect group identifiers by means of regex pattern "usi[0-9]+" + std::regex regid("(usi[0-9]+)"); + + // declare match instance and regex iterator (to find ALL matches) + std::smatch usi_match; + std::sregex_iterator pos(idstring.begin(), idstring.end(), regid); + std::sregex_iterator end; + + // iterate through all matches + std::vector listofids; + for ( ; pos != end; ++pos) listofids.push_back(pos->str()); + + return listofids; + } + public: // encoding @@ -102,8 +123,8 @@ public: void process_root(bool showlog); // process/list all channels and groups + void process_channelgroups(bool showlog); void process_channels(bool showlog); - void process_groups(bool showlog); // void parse_structure(); //