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

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
//---------------------------------------------------------------------------//