diff --git a/lib/imc_block.hpp b/lib/imc_block.hpp index bea9d58..a90d8cd 100644 --- a/lib/imc_block.hpp +++ b/lib/imc_block.hpp @@ -13,7 +13,7 @@ namespace imc { - // define "magic bytes" announcing start/end of blocks and separation within + // 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 diff --git a/lib/imc_meta.hpp b/lib/imc_meta.hpp deleted file mode 100644 index cd2dc31..0000000 --- a/lib/imc_meta.hpp +++ /dev/null @@ -1,48 +0,0 @@ -//---------------------------------------------------------------------------// - -#ifndef IMCMETA -#define IMCMETA - -//---------------------------------------------------------------------------// - -namespace imc -{ - struct info - { - // timestamp of measurement - std::string timestamp_; - bool valid_; - - // device and software - std::string origin_; - }; - - struct abscissa - { - // name of entity - std::string name_; - - // its unit - std::string unit_; - }; - - struct channel - { - // name of channel - std::string name_; - - // unit of channel's measurement entity - std::string unit_; - - // datatype of channel - imc::datatype daty_; - - // entity measurement depends on, i.e. channel's abscissa (mostly time) - abscissa channel_xaxis_; - }; - -} - -#endif - -//---------------------------------------------------------------------------// diff --git a/lib/imc_objects.hpp b/lib/imc_objects.hpp new file mode 100644 index 0000000..2fca2e9 --- /dev/null +++ b/lib/imc_objects.hpp @@ -0,0 +1,84 @@ +//---------------------------------------------------------------------------// + +#ifndef IMCOBJECTS +#define IMCOBJECTS + +//---------------------------------------------------------------------------// + +namespace imc +{ + // start of group of keys (corresponds to key CK) + struct group_keys + { + int version_; + int length_; + bool closed_; // corresponds to true = 1 and false = 0 in file + + // get info string + std::string get_info(int width = 20) + { + std::stringstream ss; + ss< rawblocks_; + // check computational complexity for parsing blocks + unsigned long int cplxcnt_; + // collect meta-information, channel definition, etc. imc::info imcinfo_; imc::channel imcchannel_; @@ -36,17 +39,20 @@ namespace imc // constructor raw() {}; - raw(std::string raw_file): raw_file_(raw_file) { this->parse_blocks(); }; + raw(std::string raw_file): raw_file_(raw_file) { set_file(raw_file); }; // provide new raw-file void set_file(std::string raw_file) { raw_file_ = raw_file; + this->fill_buffer(); this->parse_blocks(); } - // list all blocks in buffer - void parse_blocks() + private: + + // open file and stream data into buffer + void fill_buffer() { // open file and put data in buffer try { @@ -61,11 +67,20 @@ namespace imc std::string("failed to open raw-file and stream data in buffer: ") + e.what() ); } + } + + // parse all raw blocks in buffer + void parse_blocks() + { + // reset counter to identify computational complexity + cplxcnt_ = 0; // start parsing raw-blocks in buffer for ( std::vector::iterator it=buffer_.begin(); it!=buffer_.end(); ++it ) { + cplxcnt_++; + // check for "magic byte" if ( *it == ch_bgn_ ) { @@ -110,6 +125,12 @@ namespace imc // add block to list rawblocks_.push_back(blk); + + // skip the remaining block according to its length + if ( it-buffer_.begin()+length < buffer_.size() ) + { + std::advance(it,length); + } } else { @@ -146,12 +167,26 @@ namespace imc } } + public: + + // provide buffer size + unsigned long int buffer_size() + { + return buffer_.size(); + } + // get blocks std::vector& blocks() { return rawblocks_; } + // get computational complexity + unsigned long int& computational_complexity() + { + return cplxcnt_; + } + // collect meta data void parse_meta() { diff --git a/src/main.cpp b/src/main.cpp index 816f8ed..0e00d71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -178,6 +178,9 @@ int main(int argc, char* argv[]) // if ( blk.get_key() == std::string("CR") ) // for ( auto prm: blk.get_parameters() ) std::cout<::iterator it = imc::keys.begin();