16#ifndef CODINGMODELDISPATCHER_H
17#define CODINGMODELDISPATCHER_H
28#include <boost/type.hpp>
29#include <boost/mpl/for_each.hpp>
35namespace data_compression
50template <
typename ModelDefinition>
68 using code_type =
typename container_type::wrapped_type::code_type;
77 template <
typename ValueType,
typename WeightType>
92 return static_cast<typename T::wrapped_type::base_type&
>(*stage).addWeight(
value,
weight);
106 template <
typename ValueType,
typename WeightType>
107 bool addWeight(ValueType
v, WeightType
w,
bool switchToNextModel =
true)
127 template <
typename T>
130 T& stage =
static_cast<T&
>(mContainer);
131 return (*stage).init();
144 boost::mpl::for_each<typename container_type::types, boost::type<boost::mpl::_>>(
initFctr(mContainer));
160 template <
typename T>
163 T& stage =
static_cast<T&
>(mContainer);
164 return (*stage).GenerateHuffmanTree();
176 boost::mpl::for_each<typename container_type::types, boost::type<boost::mpl::_>>(
generateFctr(mContainer));
181 template <
typename CodeType,
typename ValueType>
185 encodeFctr(ValueType _v, CodeType& _code, uint16_t& _codeLength) : code(_code),
value(_v), codeLength(_codeLength)
192 template <
typename T>
195 code = (*stage).Encode(
value, codeLength);
202 uint16_t& codeLength;
211 template <
typename CodeType,
typename ValueType>
212 bool encode(ValueType
v, CodeType& code, uint16_t& codeLength,
bool switchToNextModel =
true)
222 template <
typename CodeType,
typename ValueType>
226 decodeFctr(ValueType& _v, CodeType _code, uint16_t& _codeLength) : code(_code),
value(_v), codeLength(_codeLength)
233 template <
typename T>
236 value = (*stage).Decode(code, codeLength);
243 uint16_t& codeLength;
254 template <
typename ValueType,
typename CodeType>
255 bool decode(ValueType&
v, CodeType code, uint16_t& codeLength,
bool switchToNextModel =
true)
268 template <
typename T>
271 return T::wrapped_type::orderMSB;
289 template <
typename T>
292 T& stage =
static_cast<T&
>(mContainer);
293 if (T::level::value > 0) {
296 mOut << T::level::value <<
" " << (*stage).getName() << std::endl;
297 (*stage).write(mOut);
314 boost::mpl::for_each<typename container_type::types, boost::type<boost::mpl::_>>(
315 writeFctr(ofile.good() ? ofile : std::cout, mContainer));
329 template <
typename T>
332 T& stage =
static_cast<T&
>(mContainer);
339 if (std::stoi(
level) != T::level::value ||
name.compare((*stage).getName())) {
340 std::cerr <<
"Format error: expecting level '" << T::level::value <<
"' and name '" << (*stage).getName()
341 <<
"', got: " <<
level <<
" " <<
name << std::endl;
343 std::cout <<
"reading configuration for model " <<
name << std::endl;
344 std::getline(mIn, remaining);
366 boost::mpl::for_each<typename container_type::types, boost::type<boost::mpl::_>>(
readFctr(input, mContainer));
functor to add weight to probability model at runtime container level
return_type operator()(T &stage)
addWeightFctr(ValueType _v, WeightType _w)
Functor to execute decoding on runtime container level.
return_type operator()(T &stage)
decodeFctr(ValueType &_v, CodeType _code, uint16_t &_codeLength)
functor to execute encoding on runtime container level
encodeFctr(ValueType _v, CodeType &_code, uint16_t &_codeLength)
return_type operator()(T &stage)
return_type operator()(boost::type< T >)
generateFctr(container_type &container)
return_type operator()(T &stage)
return_type operator()(boost::type< T >)
initFctr(container_type &container)
return_type operator()(boost::type< T >)
readFctr(std::istream &in, container_type &container)
writeFctr(std::ostream &out, container_type &container)
return_type operator()(boost::type< T >)
std::ostream & return_type
Runtime dispatcher interface for probability model definitions.
container_type & operator*()
return highest stage of runtime container
int write(const char *filename=nullptr)
~CodingModelDispatcher()=default
typename mpl::make_mpl_vector< ModelDefinition >::type definition_type
bool getCodingDirection()
int read(const char *filename)
bool addWeight(ValueType v, WeightType w, bool switchToNextModel=true)
static int getNumberOfModels()
get the number of models in the definition
typename create_rtc< definition_type, RuntimeContainer<> >::type container_type
typename container_type::wrapped_type::code_type code_type
bool encode(ValueType v, CodeType &code, uint16_t &codeLength, bool switchToNextModel=true)
bool decode(ValueType &v, CodeType code, uint16_t &codeLength, bool switchToNextModel=true)
typename VectorTraits< T, typename boost::mpl::begin< T >::type >::type type
the tarits type, always a sequence
GLuint const GLchar * name
GLuint GLuint GLfloat weight
GLsizei const GLfloat * value
GLint GLint GLsizei GLint GLenum GLenum type
GLubyte GLubyte GLubyte GLubyte w
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
A general runtime container for a compile time sequence This file is part of https://github....
create the runtime container type The runtime container type is build from a list of data types,...