diff --git a/lib/imc_channel.hpp b/lib/imc_channel.hpp index 6a7f34d..7379178 100644 --- a/lib/imc_channel.hpp +++ b/lib/imc_channel.hpp @@ -4,6 +4,7 @@ #define IMCCHANNEL #include +#include "imc_datatype.hpp" //---------------------------------------------------------------------------// @@ -59,25 +60,113 @@ namespace imc < + std::string joinvec(std::vector
myvec, unsigned long int limit = 10) { + std::stringstream ss; + ss<<"["; + if ( myvec.size() <= limit ) + { + for ( dt el: myvec ) ss< 1 ) sumstr.pop_back(); + sumstr += std::string("]"); + return sumstr; + } + + // channel + struct channel + { + // associated environment of blocks and map of blocks + channel_env chnenv_; + const std::map* blocks_; + // collect meta-data of channels according to env, // just everything valueable in here std::string uuid_; std::string name_; - std::string yunit_; - std::string xunit_; + std::string yname_, yunit_; + imc::datatype dattyp_; + std::string xname_, xunit_; std::vector ydata_; std::vector xdata_; - // provide JSON sttring of metadata + // group reference the channel belongs to + std::string group_uuid_, group_name_; + + // constructor takes channel's block environment + channel(channel_env chnenv, std::map* blocks): + chnenv_(chnenv), blocks_(blocks) + { + std::vector prms = blocks->at(chnenv_.CNuuid_).get_parameters(); + name_ = blocks->at(chnenv_.CNuuid_).get_parameter(prms[6]); + } + + // get info string + std::string get_info(int width = 20) + { + std::stringstream ss; + ss<<"uuid:"<(ydata_) + <<"\",\"xdata\":\""<(xdata_) + <<"\",\"aff. blocks\":\""< channel_envs_; + // list groups and channels (including their affiliate blocks) + std::map channels_; public: @@ -224,11 +224,13 @@ namespace imc if ( blk.get_key().name_ == "CS" || blk.get_key().name_ == "CC" || blk.get_key().name_ == "CG" || blk.get_key().name_ == "CB" ) { + // provide UUID for channel chnenv.uuid_ = chnenv.CNuuid_; - channel_envs_.insert( - std::pair(chnenv.CNuuid_,chnenv) + + // create channel object and add it to the map of channels + channels_.insert( std::pair + (chnenv.CNuuid_,imc::channel(chnenv,&mapblocks_)) ); - std::cout< get_channels() + { + std::vector chns; + for ( std::map::iterator it = channels_.begin(); + it != channels_.end(); ++it) + { + chns.push_back(it->second.get_json()); + } + return chns; + } + + // get particular channel including data by its uuid + imc::channel get_channel(std::string uuid) + { + if ( channels_.count(uuid) ) + { + return channels_.at(uuid); + } + else + { + throw std::runtime_error(std::string("channel does not exist:") + uuid); + } + } + // list a particular type of block std::vector list_blocks(imc::key mykey) { diff --git a/src/main.cpp b/src/main.cpp index 10957e8..9f30ac2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -180,26 +180,11 @@ int main(int argc, char* argv[]) std::cout<<"computational complexity: "< CBblocks = imcraw.list_blocks(imc::keys.at("CB")); - // for ( auto blk: CBblocks ) std::cout< CGblocks = imcraw.list_blocks(imc::keys.at("CG")); - // for ( auto blk: CGblocks ) std::cout< CCblocks = imcraw.list_blocks(imc::keys.at("CC")); - // for ( auto blk: CCblocks ) std::cout< CNblocks = imcraw.list_blocks(imc::keys.at("CN")); - // for ( auto blk: CNblocks ) std::cout< CSblocks = imcraw.list_blocks(imc::keys.at("CS")); - // for ( auto blk: CSblocks ) std::cout< groups = imcraw.list_groups(); - // for ( auto blk: groups ) std::cout< channels = imcraw.get_channels(); + for ( auto el: channels ) std::cout< channels = imcraw.list_channels(); - // for ( auto chn: channels ) - // { - // std::cout<