SDK Base Utils

Header helpers classes and functions

template<typename EventType>
void Metavision::write_DAT_header(std::ostream &os, const GenericHeader::HeaderMap &header_map)

Writes the DAT header of a file.

Template Parameters

EventType – The type of events stored in the DAT file

Parameters
  • os – The stream used to store the DAT data

  • header_map – An optional map of data to be stored in the header

template<typename EventType>
std::string Metavision::get_DAT_header_as_string(const GenericHeader::HeaderMap &header_map = GenericHeader::HeaderMap())

Convenience function to get the DAT header as string.

Template Parameters

EventType – The type of events stored in the DAT file

Parameters

header_map – Additional information to be stored in the header

Returns

The string representing the DAT header

inline GenericHeader Metavision::make_DAT_header_map_with_geometry(int width, int height)

Convenience function to create a DAT header map to be added in the header using the camera geometry.

Parameters
  • width – Width of the camera sensor

  • height – Height of the camera sensor

Returns

The DAT header map

class Metavision::GenericHeader

A utility class to hold and format headers information.

A header is composed of fields composed of key (string) / value (string) pairs

Public Types

using HeaderMap = std::map<std::string, std::string>

Alias for the internal map holding the header information.

Public Functions

GenericHeader()

Default constructor.

GenericHeader(std::istream &stream)

Builds the header map by parsing the input stream.

The stream internal is expected to point to the start of the header (if any) This method effectively places the stream cursor at the end of header. The position of the cursor remains unchanged if no header is actually present.

Parameters

stream – The input stream to parse a header from

GenericHeader(const HeaderMap &header_map)

Builds the header map using a copy of the input HeaderMap.

Parameters

header_map – The header map to use for initialization

bool empty() const

Returns if the header is empty.

Returns

True if the header is empty, false otherwise

void add_date()

Adds the current date and time to the header (in the format Y-m-d H:M:S).

Note

The date is updated at each call to this method

void remove_date()

Removes the date if there was any in the header.

std::string get_date() const

Gets the date and time at which the associated file was recorded.

Returns

The current date and time in string format if it is found, or an empty string otherwise.

void set_field(const std::string &key, const std::string &value)

Adds a new field in the header.

Parameters
  • key – The key of the field in the header

  • value – The value of the field

void remove_field(const std::string &key)

Remove the input field (if exists)

std::string get_field(const std::string &key) const

Gets the value associated to the input key.

Returns

The value associated to the input key if it exists, or an empty string otherwise

const HeaderMap &get_header_map() const

Gets the HeaderMap holding the header information.

Returns

The header map

std::string to_string() const

Serializes the header map.

Returns

The header in a string format

Various

template<class T, bool acquire_shared_ptr = false>
class Metavision::ObjectPool

Class that creates a reusable pool of heap allocated objects.

The ObjectPool allocates objects that are returned to the pool upon destruction. acquire is used to allocate or re-use a previously allocated object instance. The object are made available through a std::unique_ptr or a std::shared_ptr according to the template acquire_shared_ptr. The smart pointers are given a custom deleter, which automatically adds the object back to the pool upon destruction.

Template Parameters
  • T – the type of object stored

  • acquire_shared_ptr – if true, the object are wrapped by a std::shared_ptr, otherwise a std::unique_ptr is returned instead

Public Functions

inline ObjectPool()

Default constructor that builds an unbounded object pool with an initial number of objects allocated make_unbounded.

inline void add(std::unique_ptr<T> t)

Adds an object to the pool.

Parameters

t – A unique_ptr storing the object

template<typename ...Args>
inline ptr_type acquire(Args&&... args)

Allocates or re-use a previously allocated object.

Parameters

args – Optional arguments to be passed when allocating the object

Returns

A unique or shared pointer to the allocated object

inline bool empty() const

Checks if the pool is empty.

Returns

true if the pool is empty, false if the pool contains object ready to be re-used

inline size_t size() const

Gets the number of objects in the pool.

Returns

The number of previously allocated and ready to-reuse objects in the pool

inline bool is_bounded() const

Checks the memory pool type i.e. bounded or unbounded.

Returns

true if the memory pool is bounded, false if it is unbounded

template<typename ...Args>
inline size_t arrange(size_t size, Args&&... args)

Ensure that the pool contains ‘size’ available objects, ready to be acquired.

Note

Only works for unbounded pool

Parameters
  • size – The maximum number of objects to be available

  • args – Optional arguments to be used when allocating the object

Returns

the number of newly allocated object in the pool

Public Static Functions

static inline ObjectPool<T, acquire_shared_ptr> make_bounded(size_t num_initial_objects = 64)

Creates an object pool with limited number of objects that can be allocated.

There won’t be memory allocation upon call to acquire if all objects in the memory pool are already used.

Parameters

num_initial_objects – Number of objects initially allocated in the pool

Returns

An object pool with bounded memory

template<typename ...Args>
static inline ObjectPool<T, acquire_shared_ptr> make_bounded(size_t num_initial_objects, Args&&... args)

Creates an object pool with limited number of objects that can be allocated.

There won’t be memory allocation upon call to acquire if all objects in the memory pool are already used.

Parameters
  • num_initial_objects – Number of objects initially allocated in the pool

  • args – The arguments forwarded to the object constructor during allocation

Returns

An object pool with bounded memory

template<typename ...Args>
static inline ObjectPool<T, acquire_shared_ptr> make_unbounded(size_t num_initial_objects = 64)

Creates an object pool with expendable memory usage.

A pool with unbounded memory will allocate a new object when all objects in the pool are already used and acquire is called.

Parameters

num_initial_objects – Number of objects initially allocated in the pool

Returns

An object pool with unbounded memory

template<typename ...Args>
static inline ObjectPool<T, acquire_shared_ptr> make_unbounded(size_t num_initial_objects, Args&&... args)

Creates an object pool with expendable memory usage.

A pool with unbounded memory will allocate a new object when all objects in the pool are already used and acquire is called.

Parameters
  • num_initial_objects – Number of objects initially allocated in the pool

  • args – The arguments forwarded to the object constructor during allocation

Returns

An object pool with unbounded memory

template<typename T>
using Metavision::SharedObjectPool = ObjectPool<T, true>

Convenience alias to use a ObjectPool returning shared pointers.

Template Parameters

T – the type of object stored in the pool

typedef long long Metavision::timestamp

Type to represent time in microseconds.

struct Metavision::SoftwareInfo

Stores information about the version of the software.

Public Types

enum class VersionSuffix

Supported version suffixes.

Values:

enumerator NONE
enumerator DEV

Public Functions

SoftwareInfo(int version_major, int version_minor, int version_patch, const std::string &version_suffix_string, const std::string &vcs_branch, const std::string &vcs_commit, const std::string &vcs_date)

Constructor.

Parameters
  • version_major – Major version number

  • version_minor – Minor version number

  • version_patch – Patch version number

  • version_suffix_string – Version suffix string

  • vcs_branch – VCS branch name

  • vcs_commit – VCS commit’s hash

  • vcs_date – VCS commit’s date

int get_version_major() const

Returns major version number.

int get_version_minor() const

Returns minor version number.

int get_version_patch() const

Returns patch version number.

std::string get_version_suffix() const

Returns version suffix string.

std::string get_version() const

Returns version as a string.

std::string get_vcs_branch() const

Returns version control software (vcs) branch.

std::string get_vcs_commit() const

Returns version control software (vcs) commit.

std::string get_vcs_date() const

Returns version control software (vcs) commit’s date.

Logging

MV_LOG_DEBUG(prefixFmt…)

Returns a logging operation of DEBUG level.

Convenience function to return a logging operation of DEBUG level using the current logging stream, an optional prefix format prefixFmt and automatically adding an end of line token at the end of the logging operation

Parameters
  • prefixFmt – (Optional) a format string that will be be output as the first message token

Returns

A logging operation of DEBUG level

MV_LOG_TRACE(prefixFmt…)

Returns a logging operation of TRACE level.

Convenience macro to return a logging operation of TRACE level using the current logging stream, an optional prefix format prefixFmt and automatically adding an end of line token at the end of the logging operation

Parameters
  • prefixFmt – (Optional) a format string that will be be output as the first message token

Returns

A logging operation of TRACE level

MV_LOG_INFO(prefixFmt…)

Returns a logging operation of INFO level.

Convenience function to return a logging operation of INFO level using the current logging stream, an optional prefix format prefixFmt and automatically adding an end of line token at the end of the logging operation

Parameters
  • prefixFmt – (Optional) a format string that will be be output as the first message token

Returns

A logging operation of INFO level

MV_LOG_WARNING(prefixFmt…)

Returns a logging operation of WARNING level.

Convenience function to return a logging operation of WARNING level using the current logging stream, an optional prefix format prefixFmt and automatically adding an end of line token at the end of the logging operation

Parameters
  • prefixFmt – (Optional) a format string that will be be output as the first message token

Returns

A logging operation of WARNING level

MV_LOG_ERROR(prefixFmt…)

Returns a logging operation of ERROR level.

Convenience function to return a logging operation of ERROR level using the current logging stream, an optional prefix format prefixFmt and automatically adding an end of line token at the end of the logging operation

Parameters
  • prefixFmt – (Optional) a format string that will be be output as the first message token

Returns

A logging operation of ERROR level

namespace Metavision::Log

Functions

template<LogLevel Level>
LoggingOperation<Level> &space(LoggingOperation<Level> &op)

Stream manipulator enabling the automatic addition of spaces between message tokens.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &&space(LoggingOperation<Level> &&op)

Stream manipulator enabling the automatic addition of spaces between message tokens.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &no_space(LoggingOperation<Level> &op)

Stream manipulator disabling the automatic addition of spaces between message tokens.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &&no_space(LoggingOperation<Level> &&op)

Stream manipulator disabling the automatic addition of spaces between message tokens.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &endline(LoggingOperation<Level> &op)

Stream manipulator enabling the automatic addition of and end of line token at the end of the operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &&endline(LoggingOperation<Level> &&op)

Stream manipulator enabling the automatic addition of and end of line token at the end of the operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &no_endline(LoggingOperation<Level> &op)

Stream manipulator disabling the automatic addition of and end of line token at the end of the operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &&no_endline(LoggingOperation<Level> &&op)

Stream manipulator disabling the automatic addition of and end of line token at the end of the operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &function(LoggingOperation<Level> &op)

Stream manipulator that outputs the function name associated to the logging operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &&function(LoggingOperation<Level> &&op)

Stream manipulator that outputs the function name associated to the logging operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &file(LoggingOperation<Level> &op)

Stream manipulator that outputs the file name associated to the logging operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &&file(LoggingOperation<Level> &&op)

Stream manipulator that outputs the file name associated to the logging operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &line(LoggingOperation<Level> &op)

Stream manipulator that outputs the line associated to the logging operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &&line(LoggingOperation<Level> &&op)

Stream manipulator that outputs the line associated to the logging operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &prefix(LoggingOperation<Level> &op)

Stream manipulator that outputs the prefix associated to the logging operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation

template<LogLevel Level>
LoggingOperation<Level> &&prefix(LoggingOperation<Level> &&op)

Stream manipulator that outputs the prefix associated to the logging operation.

Template Parameters

Level – The level of the logging operation

Parameters

op – The logging operation modified by this modifier

Returns

The modified logging operation