libcruft-util/json/schema/enum.cpp

40 lines
991 B
C++

#include "enum.hpp"
#include "../tree.hpp"
using util::json::schema::constraint::enumeration;
///////////////////////////////////////////////////////////////////////////////
enumeration::enumeration (::json::tree::node const &def)
{
for (auto const &i: def.as_array ())
m_values.push_back (i.clone ());
}
///////////////////////////////////////////////////////////////////////////////
enumeration::output_iterator
enumeration::validate (util::json::schema::constraint::base::output_iterator res,
::json::tree::node &target) const noexcept
{
for (auto const &i: m_values)
if (target == *i)
return res;
return *res++ = { .rule = *this, .target = target };
}
///////////////////////////////////////////////////////////////////////////////
std::ostream&
enumeration::describe (std::ostream &os) const
{
os << "{ enumeration: [ ";
for (auto const &i: m_values)
os << *i << ", ";
return os << " ] }";
}