Class base

Synopsis

#include <include/cpptoml.h>

class base : public std::enable_shared_from_this<base>

Description

A generic base TOML value used for type erasure.

Inheritance

Ancestors: std::enable_shared_from_this< base >

Decsendents: array, table, table_array

Methods

base
~base
acceptbase implementation of accept() that calls visitor.visit() on the concrete class.
as overloadAttempts to coerce the TOML element into a concrete TOML value of type T.
as_arrayConverts the TOML element to an array.
as_tableConverts the TOML element into a table.
as_table_arrayConverts the TOML element into a table array.
clone
is_arrayDetermines if the TOML element is an array of "leaf" elements.
is_tableDetermines if the given TOML element is a table.
is_table_arrayDetermines if the given TOML element is an array of tables.
is_valueDetermines if the given TOML element is a value.

Source

Lines 498-601 in include/cpptoml.h.

class base : public std::enable_shared_from_this<base>
{
  public:
    virtual ~base() = default;

    virtual std::shared_ptr<base> clone() const = 0;

    /**
     * Determines if the given TOML element is a value.
     */
    virtual bool is_value() const
    {
        return false;
    }

    /**
     * Determines if the given TOML element is a table.
     */
    virtual bool is_table() const
    {
        return false;
    }

    /**
     * Converts the TOML element into a table.
     */
    std::shared_ptr<table> as_table()
    {
        if (is_table())
            return std::static_pointer_cast<table>(shared_from_this());
        return nullptr;
    }
    /**
     * Determines if the TOML element is an array of "leaf" elements.
     */
    virtual bool is_array() const
    {
        return false;
    }

    /**
     * Converts the TOML element to an array.
     */
    std::shared_ptr<array> as_array()
    {
        if (is_array())
            return std::static_pointer_cast<array>(shared_from_this());
        return nullptr;
    }

    /**
     * Determines if the given TOML element is an array of tables.
     */
    virtual bool is_table_array() const
    {
        return false;
    }

    /**
     * Converts the TOML element into a table array.
     */
    std::shared_ptr<table_array> as_table_array()
    {
        if (is_table_array())
            return std::static_pointer_cast<table_array>(shared_from_this());
        return nullptr;
    }

    /**
     * Attempts to coerce the TOML element into a concrete TOML value
     * of type T.
     */
    template <class T>
    std::shared_ptr<value<T>> as();

    template <class T>
    std::shared_ptr<const value<T>> as() const;

    template <class Visitor, class... Args>
    void accept(Visitor&& visitor, Args&&... args) const;

#if defined(CPPTOML_NO_RTTI)
    base_type type() const
    {
        return type_;
    }

  protected:
    base(const base_type t) : type_(t)
    {
        // nothing
    }

  private:
    const base_type type_ = base_type::NONE;

#else
  protected:
    base()
    {
        // nothing
    }
#endif
};





Add Discussion as Guest

Log in