#ifndef _C4_YML_STD_VECTOR_HPP_ #define _C4_YML_STD_VECTOR_HPP_ #include "c4/yml/node.hpp" #include #include namespace c4 { namespace yml { // vector is a sequence-like type, and it requires child nodes // in the data tree hierarchy (a SEQ node in ryml parlance). // So it should be serialized via write()/read(). template void write(c4::yml::NodeRef *n, std::vector const& vec) { *n |= c4::yml::SEQ; for(V const& v : vec) n->append_child() << v; } /** read the node members, overwriting existing vector entries. */ template bool read(c4::yml::ConstNodeRef const& n, std::vector *vec) { C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast") vec->resize(static_cast(n.num_children())); C4_SUPPRESS_WARNING_GCC_POP size_t pos = 0; for(ConstNodeRef const child : n) child >> (*vec)[pos++]; return true; } /** read the node members, overwriting existing vector entries. * specialization: std::vector uses std::vector::reference as * the return value of its operator[]. */ template bool read(c4::yml::ConstNodeRef const& n, std::vector *vec) { C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast") vec->resize(static_cast(n.num_children())); C4_SUPPRESS_WARNING_GCC_POP size_t pos = 0; bool tmp = {}; for(ConstNodeRef const child : n) { child >> tmp; (*vec)[pos++] = tmp; } return true; } } // namespace yml } // namespace c4 #endif // _C4_YML_STD_VECTOR_HPP_