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

This commit is contained in:
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 <vector>
#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<parameter> parameters_;
std::vector<imc::parameter> 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<parameter>& get_parameters()