Function get_array_of
Summary
#include <include/cpptoml.h>
(1) template <class T>
array_of_trait< T >::return_type get_array_of(const std::string &key) const
(2) template <>
array_of_trait< array >::return_type get_array_of(const std::string &key) const
Function overload
Synopsis
#include <include/cpptoml.h>
template <class T>
array_of_trait< T >::return_type get_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.
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.
Source
Lines 1480-1500 in include/cpptoml.h.
template <class T>
inline typename array_of_trait<T>::return_type
get_array_of(const std::string& key) const
{
if (auto v = get_array(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_array_of(const std::string &key) const
Description
Helper function that attempts to get an array of arrays for a given key.
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.
Source
Lines 1636-1657 in include/cpptoml.h.
template <>
inline typename array_of_trait<array>::return_type
table::get_array_of<array>(const std::string& key) const
{
if (auto v = get_array(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 {};
}