class mrpt::config::CConfigFileMemory

Overview

This class implements a config file-like interface over a memory-stored string list.

Use base class CConfigFileBase ‘s methods read_{int,float,double,string,...}() and write() to actually read and write values.

It can also parse a YAML text block and expose its fields (up to the first level of hierarchy, as allowed by INI-like files). This can be used to port MRPT classes relying on INI files to using YAML files transparently. This feature required building MRPT with yaml-cpp, and is provided by CConfigFileMemory::setContentFromYAML().

See: Configuration file format in MRPT

YAML support was introduced in MRPT 1.9.9

#include <mrpt/config/CConfigFileMemory.h>

class CConfigFileMemory: public mrpt::config::CConfigFileBase
{
public:
    // structs

    struct Impl;

    // construction

    CConfigFileMemory();
    CConfigFileMemory(const CConfigFileMemory&);
    CConfigFileMemory(CConfigFileMemory&&);
    CConfigFileMemory(const std::vector<std::string>& stringList);
    CConfigFileMemory(const std::string& str);

    // methods

    CConfigFileMemory& operator = (const CConfigFileMemory&);
    CConfigFileMemory& operator = (CConfigFileMemory&&);
    void setContent(const std::vector<std::string>& stringList);
    void setContent(const std::string& str);
    std::string getContent() const;
    virtual void clear();
    virtual void getAllSections(std::vector<std::string>& sections) const;
    virtual void getAllKeys(const std::string& section, std::vector<std::string>& keys) const;
};

Inherited Members

public:
    // methods

    CConfigFileBase& operator = (const CConfigFileBase&);
    CConfigFileBase& operator = (CConfigFileBase&&);
    virtual void getAllSections(std::vector<std::string>& sections) const = 0;
    virtual void getAllKeys(const std::string& section, std::vector<std::string>& keys) const = 0;
    virtual void clear() = 0;

Construction

CConfigFileMemory()

Empty constructor.

Upon construction, call any of the “setContent” method

CConfigFileMemory(const std::vector<std::string>& stringList)

Constructor and initialize from a list of strings.

CConfigFileMemory(const std::string& str)

Constructor and initialize from string with the whole “config file”.

Methods

void setContent(const std::vector<std::string>& stringList)

Changes the contents of the virtual “config file”.

void setContent(const std::string& str)

Changes the contents of the virtual “config file”.

std::string getContent() const

Return the current contents of the virtual “config file”.

virtual void clear()

Empties the virtual “config file”.

virtual void getAllSections(std::vector<std::string>& sections) const

Returns a list with all the section names.

virtual void getAllKeys(
    const std::string& section,
    std::vector<std::string>& keys
    ) const

Returns a list with all the keys into a section.