wrapper for imc::object, include imc::object in imc::block

This commit is contained in:
Mario Fink 2021-02-09 20:57:44 +01:00
parent a808a001a9
commit 4f3e816dbf
5 changed files with 266 additions and 73 deletions

View File

@ -9,6 +9,9 @@
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include "imc_parameter.hpp"
#include "imc_object.hpp"
//---------------------------------------------------------------------------// //---------------------------------------------------------------------------//
namespace imc namespace imc
@ -16,59 +19,6 @@ namespace imc
// define "magic bytes" announcing start/end of blocks and separation of parameters 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; 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 // define properties of a raw file block
class block class block
{ {
@ -85,7 +35,10 @@ namespace imc
// offset of first/last byte of parameters in block (separated by ch_sep_) // offset of first/last byte of parameters in block (separated by ch_sep_)
// w.r.t. to first byte of block (=0) // w.r.t. to first byte of block (=0)
std::vector<parameter> parameters_; std::vector<imc::parameter> parameters_;
// particular imc object
imc::rawobject imc_object_;
public: public:
@ -142,9 +95,9 @@ namespace imc
} }
// access members // access members
imc::key& get_key() { return thekey_; } imc::key get_key() { return thekey_; }
unsigned long int& get_begin() { return begin_; } unsigned long int get_begin() { return begin_; }
unsigned long int& get_end() { return end_; } unsigned long int get_end() { return end_; }
// get list of parameters // get list of parameters
std::vector<parameter>& get_parameters() std::vector<parameter>& get_parameters()

View File

@ -1,7 +1,9 @@
//---------------------------------------------------------------------------// //---------------------------------------------------------------------------//
#ifndef IMCOBJECTS #ifndef IMCOBJECT
#define IMCOBJECTS #define IMCOBJECT
#include "imc_key.hpp"
//---------------------------------------------------------------------------// //---------------------------------------------------------------------------//
@ -14,6 +16,12 @@ namespace imc
int length_; int length_;
bool closed_; // corresponds to true = 1 and false = 0 in file bool closed_; // corresponds to true = 1 and false = 0 in file
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -32,6 +40,12 @@ namespace imc
std::string name_; std::string name_;
std::string comment_; std::string comment_;
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -51,6 +65,12 @@ namespace imc
std::string text_; std::string text_;
std::string comment_; std::string comment_;
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -79,6 +99,12 @@ namespace imc
fieldtype fldtype_; fieldtype fldtype_;
int dimension_; // corresponding to fieldtype \in {1,} int dimension_; // corresponding to fieldtype \in {1,}
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -97,6 +123,12 @@ namespace imc
bool calibration_; bool calibration_;
std::string unit_; std::string unit_;
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -114,6 +146,12 @@ namespace imc
int component_index_; int component_index_;
bool analog_digital_; bool analog_digital_;
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -151,6 +189,12 @@ namespace imc
unsigned long int number_subsequent_samples_; unsigned long int number_subsequent_samples_;
unsigned long int distance_bytes_; unsigned long int distance_bytes_;
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -183,6 +227,12 @@ namespace imc
bool user_info_; bool user_info_;
bool new_event_; bool new_event_;
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -209,6 +259,12 @@ namespace imc
bool calibration_; // 1 = true: calibration, 0 = false: no calibration bool calibration_; // 1 = true: calibration, 0 = false: no calibration
std::string unit_; std::string unit_;
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -230,6 +286,12 @@ namespace imc
std::string name_; std::string name_;
std::string comment_; std::string comment_;
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -249,6 +311,12 @@ namespace imc
// std::vector<unsigned char> rawdata_; // std::vector<unsigned char> rawdata_;
unsigned long int begin_buffer_, end_buffer_; unsigned long int begin_buffer_, end_buffer_;
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -267,6 +335,12 @@ namespace imc
std::string generator_; std::string generator_;
bool comment_; bool comment_;
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) std::string get_info(int width = 20)
{ {
@ -283,6 +357,12 @@ namespace imc
{ {
std::string timestamp_; std::string timestamp_;
// construct members by parsing particular parameters from buffer
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter> parameters)
{
}
// get info string // get info string
std::string get_info(int width = 20) 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<unsigned char>* buffer,
const std::vector<parameter> 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 #endif
//---------------------------------------------------------------------------// //---------------------------------------------------------------------------//

73
lib/imc_parameter.hpp Normal file
View File

@ -0,0 +1,73 @@
//---------------------------------------------------------------------------//
#ifndef IMCPARAMETER
#define IMCPARAMETER
#include <iomanip>
#include <map>
#include <string>
#include <sstream>
#include <vector>
//---------------------------------------------------------------------------//
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
//---------------------------------------------------------------------------//

View File

@ -10,7 +10,7 @@
#include "imc_key.hpp" #include "imc_key.hpp"
#include "imc_block.hpp" #include "imc_block.hpp"
#include "imc_datatype.hpp" #include "imc_datatype.hpp"
#include "imc_objects.hpp" #include "imc_object.hpp"
//---------------------------------------------------------------------------// //---------------------------------------------------------------------------//
@ -25,12 +25,13 @@ namespace imc
std::vector<unsigned char> buffer_; std::vector<unsigned char> buffer_;
// list of imc-blocks // list of imc-blocks
std::vector<block> rawblocks_; std::vector<imc::block> rawblocks_;
// check computational complexity for parsing blocks // check computational complexity for parsing blocks
unsigned long int cplxcnt_; unsigned long int cplxcnt_;
// collect meta-information, channel definition, etc. // collect meta-information, channel definition, etc.
std::vector<imc::keygroup> keygroups_;
public: 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: public:
// provide buffer size // provide buffer size

View File

@ -175,24 +175,12 @@ int main(int argc, char* argv[])
{ {
std::cout<<blk.get_key().get_info()<<"\n"; std::cout<<blk.get_key().get_info()<<"\n";
std::cout<<blk.get_info()<<"\n"; std::cout<<blk.get_info()<<"\n";
// if ( blk.get_key() == std::string("CR") )
// for ( auto prm: blk.get_parameters() ) std::cout<<prm.get_info()<<"\n";
} }
std::cout<<"number of blocks: "<<imcraw.blocks().size()<<"\n"; std::cout<<"number of blocks: "<<imcraw.blocks().size()<<"\n";
std::cout<<"computational complexity: "<<imcraw.computational_complexity() std::cout<<"computational complexity: "<<imcraw.computational_complexity()
<<"/"<<imcraw.buffer_size()<<"\n"; <<"/"<<imcraw.buffer_size()<<"\n";
} }
// for ( std::map<std::string,imc::key>::iterator it = imc::keys.begin();
// it != imc::keys.end(); ++it )
// {
// std::cout<<it->second.get_info()<<"\n";
// }
//
// std::vector<unsigned char> buff;
// imc::block blk(imc::keys.at("CF"),0,100,"data.raw",&buff);
// std::cout<<blk.get_info()<<"\n";
return 0; return 0;
} }