From 4f3e816dbf0c80fa943c87e9a4ae7b796c4ecb47 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Tue, 9 Feb 2021 20:57:44 +0100 Subject: [PATCH] wrapper for imc::object, include imc::object in imc::block --- lib/imc_block.hpp | 67 ++------- lib/{imc_objects.hpp => imc_object.hpp} | 173 +++++++++++++++++++++++- lib/imc_parameter.hpp | 73 ++++++++++ lib/imc_raw.hpp | 14 +- src/main.cpp | 12 -- 5 files changed, 266 insertions(+), 73 deletions(-) rename lib/{imc_objects.hpp => imc_object.hpp} (67%) create mode 100644 lib/imc_parameter.hpp diff --git a/lib/imc_block.hpp b/lib/imc_block.hpp index a90d8cd..eeae1e5 100644 --- a/lib/imc_block.hpp +++ b/lib/imc_block.hpp @@ -9,6 +9,9 @@ #include #include +#include "imc_parameter.hpp" +#include "imc_object.hpp" + //---------------------------------------------------------------------------// namespace imc @@ -16,59 +19,6 @@ namespace imc // define "magic bytes" announcing start/end of blocks and separation of parameters within const unsigned char ch_bgn_ = 0x7c, ch_end_ = 0x3b, ch_sep_ = 0x2c; - // single parameter (in a block) is determined by offset of its first/last byte - class parameter - { - // offset of first/last byte of parameter - unsigned long int begin_, end_; - - public: - - parameter(unsigned long int begin, unsigned long int end): - begin_(begin), end_(end) - { - if ( end_ < begin_ ) - { - throw std::logic_error("parameter: offset of first byte larger than last byte's offset"); - } - } - - // set members - void begin(unsigned long int begin) - { - if ( end_ < begin ) - { - throw std::logic_error("parameter: offset of first byte larger than last byte's offset"); - } - begin_ = begin; - } - void end(unsigned long int end) - { - if ( end < begin_ ) - { - throw std::logic_error("parameter: offset of first byte larger than last byte's offset"); - } - end_ = end; - } - - // access members - unsigned long int& begin() { return begin_; } - unsigned long int& end() { return end_; } - - // comparison operator - bool operator==(const parameter& param) - { - return ( this->begin_ == param.begin_ && this->end_ == param.end_ ); - } - - // get info - std::string get_info() - { - return ( std::string("[") + std::to_string(begin_) + std::string(",") - + std::to_string(end_) + std::string("]") ); - } - }; - // define properties of a raw file block class block { @@ -85,7 +35,10 @@ namespace imc // offset of first/last byte of parameters in block (separated by ch_sep_) // w.r.t. to first byte of block (=0) - std::vector parameters_; + std::vector parameters_; + + // particular imc object + imc::rawobject imc_object_; public: @@ -142,9 +95,9 @@ namespace imc } // access members - imc::key& get_key() { return thekey_; } - unsigned long int& get_begin() { return begin_; } - unsigned long int& get_end() { return end_; } + imc::key get_key() { return thekey_; } + unsigned long int get_begin() { return begin_; } + unsigned long int get_end() { return end_; } // get list of parameters std::vector& get_parameters() diff --git a/lib/imc_objects.hpp b/lib/imc_object.hpp similarity index 67% rename from lib/imc_objects.hpp rename to lib/imc_object.hpp index 325987e..8937a3c 100644 --- a/lib/imc_objects.hpp +++ b/lib/imc_object.hpp @@ -1,7 +1,9 @@ //---------------------------------------------------------------------------// -#ifndef IMCOBJECTS -#define IMCOBJECTS +#ifndef IMCOBJECT +#define IMCOBJECT + +#include "imc_key.hpp" //---------------------------------------------------------------------------// @@ -14,6 +16,12 @@ namespace imc int length_; bool closed_; // corresponds to true = 1 and false = 0 in file + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -32,6 +40,12 @@ namespace imc std::string name_; std::string comment_; + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -51,6 +65,12 @@ namespace imc std::string text_; std::string comment_; + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -79,6 +99,12 @@ namespace imc fieldtype fldtype_; int dimension_; // corresponding to fieldtype \in {1,} + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -97,6 +123,12 @@ namespace imc bool calibration_; std::string unit_; + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -114,6 +146,12 @@ namespace imc int component_index_; bool analog_digital_; + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -151,6 +189,12 @@ namespace imc unsigned long int number_subsequent_samples_; unsigned long int distance_bytes_; + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -183,6 +227,12 @@ namespace imc bool user_info_; bool new_event_; + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -209,6 +259,12 @@ namespace imc bool calibration_; // 1 = true: calibration, 0 = false: no calibration std::string unit_; + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -230,6 +286,12 @@ namespace imc std::string name_; std::string comment_; + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -249,6 +311,12 @@ namespace imc // std::vector rawdata_; unsigned long int begin_buffer_, end_buffer_; + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -267,6 +335,12 @@ namespace imc std::string generator_; bool comment_; + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -283,6 +357,12 @@ namespace imc { std::string timestamp_; + // construct members by parsing particular parameters from buffer + void parse(const std::vector* buffer, const std::vector parameters) + { + + } + // get info string std::string get_info(int width = 20) { @@ -294,6 +374,95 @@ namespace imc } + +namespace imc { + + // create wrapper for imc_object types + // (not particular memory-efficient but it simplifies the remaining stuff + // considerable and the structs are pretty small anyway! ) + class rawobject + { + keygroup kyg_; // 0 + group grp_; // 1 + text txt_; // 2 + datafield dtf_; // 3 + abscissa abs_; // 4 + component cmt_; // 5 + packaging pkg_; // 6 + buffer bfr_; // 7 + range rng_; // 8 + channel chn_; // 9 + data dat_; // 10 + origin_data org_; // 11 + triggertime trt_; // 12 + + void parse(imc::key key, const std::vector* buffer, + const std::vector parameters) + { + if ( key.name_ == std::string("CK") ) + { + kyg_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("CB") ) + { + grp_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("CT") ) + { + txt_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("CG") ) + { + dtf_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("CD") && key.version_ == 1 ) + { + abs_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("CC") ) + { + cmt_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("CP") ) + { + cmt_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("Cb") ) + { + bfr_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("CR") ) + { + rng_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("CN") ) + { + chn_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("CS") ) + { + dat_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("NO") ) + { + org_.parse(buffer,parameters); + } + else if ( key.name_ == std::string("NT") ) + { + trt_.parse(buffer,parameters); + } + } + + // provide info string + std::string get_info(int width = 20) + { + return kyg_.get_info(); + } + }; + + +} + #endif //---------------------------------------------------------------------------// diff --git a/lib/imc_parameter.hpp b/lib/imc_parameter.hpp new file mode 100644 index 0000000..2ad5fe1 --- /dev/null +++ b/lib/imc_parameter.hpp @@ -0,0 +1,73 @@ +//---------------------------------------------------------------------------// + +#ifndef IMCPARAMETER +#define IMCPARAMETER + +#include +#include +#include +#include +#include + +//---------------------------------------------------------------------------// + +namespace imc +{ + // single parameter (in a block) is determined by offset of its first/last byte + class parameter + { + // offset of first/last byte of parameter + unsigned long int begin_, end_; + + public: + + parameter(unsigned long int begin, unsigned long int end): + begin_(begin), end_(end) + { + if ( end_ < begin_ ) + { + throw std::logic_error("parameter: offset of first byte larger than last byte's offset"); + } + } + + // set members + void begin(unsigned long int begin) + { + if ( end_ < begin ) + { + throw std::logic_error("parameter: offset of first byte larger than last byte's offset"); + } + begin_ = begin; + } + void end(unsigned long int end) + { + if ( end < begin_ ) + { + throw std::logic_error("parameter: offset of first byte larger than last byte's offset"); + } + end_ = end; + } + + // access members + const unsigned long int& begin() { return begin_; } + const unsigned long int& end() { return end_; } + + // comparison operator + bool operator==(const parameter& param) + { + return ( this->begin_ == param.begin_ && this->end_ == param.end_ ); + } + + // get info + std::string get_info() + { + return ( std::string("[") + std::to_string(begin_) + std::string(",") + + std::to_string(end_) + std::string("]") ); + } + }; + +} + +#endif + +//---------------------------------------------------------------------------// diff --git a/lib/imc_raw.hpp b/lib/imc_raw.hpp index c673a8f..682bb54 100644 --- a/lib/imc_raw.hpp +++ b/lib/imc_raw.hpp @@ -10,7 +10,7 @@ #include "imc_key.hpp" #include "imc_block.hpp" #include "imc_datatype.hpp" -#include "imc_objects.hpp" +#include "imc_object.hpp" //---------------------------------------------------------------------------// @@ -25,12 +25,13 @@ namespace imc std::vector buffer_; // list of imc-blocks - std::vector rawblocks_; + std::vector rawblocks_; // check computational complexity for parsing blocks unsigned long int cplxcnt_; // collect meta-information, channel definition, etc. + std::vector keygroups_; public: @@ -164,6 +165,15 @@ namespace imc } } + // // extract imc objects + // void list_keygroup() + // { + // for ( auto &blk: this->rawblocks_ ) + // { + // if ( blk.get_key().name_ == std::string("CK") ) + // } + // } + public: // provide buffer size diff --git a/src/main.cpp b/src/main.cpp index 0e00d71..8de9ab4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -175,24 +175,12 @@ int main(int argc, char* argv[]) { std::cout<::iterator it = imc::keys.begin(); - // it != imc::keys.end(); ++it ) - // { - // std::cout<second.get_info()<<"\n"; - // } - // - // std::vector buff; - // imc::block blk(imc::keys.at("CF"),0,100,"data.raw",&buff); - // std::cout<