Function get_qualified_array_of

Summary

#include <include/cpptoml.h>

(1) template <class T>
    array_of_trait< T >::return_type get_qualified_array_of(const std::string &key) const

(2) template <>
    array_of_trait< array >::return_type get_qualified_array_of(const std::string &key) const

Function overload

Synopsis

#include <include/cpptoml.h>

template <class T>
array_of_trait< T >::return_type get_qualified_array_of(const std::string &key) const

Description

Helper function that attempts to get an array of values of a given type corresponding to the template parameter for a given key. Will resolve "qualified keys".

If the key doesn't exist, doesn't exist as an array type, or one or more keys inside the array type are not of type T, an empty option is returned. Otherwise, an option containing a vector of the values is returned.

Mentioned in

Source

Lines 1512-1532 in include/cpptoml.h.

template <class T>
inline typename array_of_trait<T>::return_type
get_qualified_array_of(const std::string& key) const
{
    if (auto v = get_array_qualified(key))
    {
        std::vector<T> result;
        result.reserve(v->get().size());
        for (const auto& b : v->get())
        {
            if (auto val = b->as<T>())
                result.push_back(val->get());
            else
                return {};
        }
        return {std::move(result)};
    }
    return {};
}

Synopsis

#include <include/cpptoml.h>

template <>
array_of_trait< array >::return_type get_qualified_array_of(const std::string &key) const

Description

Helper function that attempts to get an array of arrays for a given key. Will resolve "qualified keys".

If the key doesn't exist, doesn't exist as an array type, or one or more keys inside the array type are not of type T, an empty option is returned. Otherwise, an option containing a vector of the values is returned.

Mentioned in

Source

Lines 1668-1689 in include/cpptoml.h.

template <>
inline typename array_of_trait<array>::return_type
table::get_qualified_array_of<array>(const std::string& key) const
{
    if (auto v = get_array_qualified(key))
    {
        std::vector<std::shared_ptr<array>> result;
        result.reserve(v->get().size());

        for (const auto& b : v->get())
        {
            if (auto val = b->as_array())
                result.push_back(val);
            else
                return {};
        }

        return {std::move(result)};
    }

    return {};
}





Add Discussion as Guest

Log in