MMTF-C++
The C++ language MMTF libraries
mmtf::MapDecoder Class Reference

Helper class to decode msgpack maps into object fields. More...

#include <map_decoder.hpp>

Public Member Functions

 MapDecoder (const msgpack::object &obj)
 Initialize object given a msgpack object. Reads out all key-value pairs and converts key to string if possible (warns otherwise). More...
 
template<typename T >
void decode (const std::string &key, bool required, T &target)
 Extract value from map and decode into target. More...
 
void checkExtraKeys ()
 Check if there are any keys, that were not decoded. This is to be called after all expected fields have been decoded. A warning is written to stderr for each non-decoded key. More...
 

Detailed Description

Helper class to decode msgpack maps into object fields.

Constructor & Destructor Documentation

◆ MapDecoder()

mmtf::MapDecoder::MapDecoder ( const msgpack::object &  obj)
inline

Initialize object given a msgpack object. Reads out all key-value pairs and converts key to string if possible (warns otherwise).

Exceptions
mmtf::DecodeErrorif obj is not a map.

Member Function Documentation

◆ checkExtraKeys()

void mmtf::MapDecoder::checkExtraKeys ( )
inline

Check if there are any keys, that were not decoded. This is to be called after all expected fields have been decoded. A warning is written to stderr for each non-decoded key.

◆ decode()

template<typename T >
void mmtf::MapDecoder::decode ( const std::string &  key,
bool  required,
T &  target 
)

Extract value from map and decode into target.

Parameters
[in]keyKey into msgpack map.
[in]requiredTrue if field is required by MMTF specs.
[out]targetStore decoded value into this field.

If msgpack type is not as expected, we write a warning to stderr. If conversion to the target type fails, msgpack throws an exception. If a required field is missing in the map or if binary decoding fails, we throw an mmtf::DecodeError.


The documentation for this class was generated from the following file: