Function as

Summary

#include <include/cpptoml.h>

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

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

(3) template <>
    std::shared_ptr< value< double > > as()

(4) template <>
    std::shared_ptr< const value< double > > as() const

Function overload

Synopsis

#include <include/cpptoml.h>

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

Description

Attempts to coerce the TOML element into a concrete TOML value of type T.

Source

Lines 679-690 in include/cpptoml.h. Line 571 in include/cpptoml.h.

template <class T>
inline std::shared_ptr<value<T>> base::as()
{
#if defined(CPPTOML_NO_RTTI)
    if (type() == base_type_traits<T>::type)
        return std::static_pointer_cast<value<T>>(shared_from_this());
    else
        return nullptr;
#else
    return std::dynamic_pointer_cast<value<T>>(shared_from_this());
#endif
}

Synopsis

#include <include/cpptoml.h>

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

Description

No description yet.

Source

Lines 717-728 in include/cpptoml.h. Line 574 in include/cpptoml.h.

template <class T>
inline std::shared_ptr<const value<T>> base::as() const
{
#if defined(CPPTOML_NO_RTTI)
    if (type() == base_type_traits<T>::type)
        return std::static_pointer_cast<const value<T>>(shared_from_this());
    else
        return nullptr;
#else
    return std::dynamic_pointer_cast<const value<T>>(shared_from_this());
#endif
}

Synopsis

#include <include/cpptoml.h>

template <>
std::shared_ptr< value< double > > as()

Description

No description yet.

Source

Lines 694-715 in include/cpptoml.h.

template <>
inline std::shared_ptr<value<double>> base::as()
{
#if defined(CPPTOML_NO_RTTI)
    if (type() == base_type::FLOAT)
        return std::static_pointer_cast<value<double>>(shared_from_this());

    if (type() == base_type::INT)
    {
        auto v = std::static_pointer_cast<value<int64_t>>(shared_from_this());
        return make_value<double>(static_cast<double>(v->get()));
    }
#else
    if (auto v = std::dynamic_pointer_cast<value<double>>(shared_from_this()))
        return v;

    if (auto v = std::dynamic_pointer_cast<value<int64_t>>(shared_from_this()))
        return make_value<double>(static_cast<double>(v->get()));
#endif

    return nullptr;
}

Synopsis

#include <include/cpptoml.h>

template <>
std::shared_ptr< const value< double > > as() const

Description

No description yet.

Source

Lines 732-761 in include/cpptoml.h.

template <>
inline std::shared_ptr<const value<double>> base::as() const
{
#if defined(CPPTOML_NO_RTTI)
    if (type() == base_type::FLOAT)
        return std::static_pointer_cast<const value<double>>(
            shared_from_this());

    if (type() == base_type::INT)
    {
        auto v = as<int64_t>();
        // the below has to be a non-const value<double> due to a bug in
        // libc++: https://llvm.org/bugs/show_bug.cgi?id=18843
        return make_value<double>(static_cast<double>(v->get()));
    }
#else
    if (auto v
        = std::dynamic_pointer_cast<const value<double>>(shared_from_this()))
        return v;

    if (auto v = as<int64_t>())
    {
        // the below has to be a non-const value<double> due to a bug in
        // libc++: https://llvm.org/bugs/show_bug.cgi?id=18843
        return make_value<double>(static_cast<double>(v->get()));
    }
#endif

    return nullptr;
}





Add Discussion as Guest

Log in