79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
|
/*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*
|
||
|
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||
|
*/
|
||
|
|
||
|
#include "combine.hpp"
|
||
|
|
||
|
#include "../tree.hpp"
|
||
|
|
||
|
#include "../../iterator.hpp"
|
||
|
|
||
|
using util::json::schema::constraint::combine;
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
combine::combine (::json::tree::node const &def)
|
||
|
{
|
||
|
for (auto const &[key,val]: def.as_object ()) {
|
||
|
if (key == "$schema") {
|
||
|
m_version = val->as_string ();
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (key == "default") {
|
||
|
m_default = val->clone ();
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
m_constraints.push_back (instantiate (key, *val));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
combine::output_iterator
|
||
|
combine::validate (output_iterator res, ::json::tree::node &data) const noexcept
|
||
|
{
|
||
|
for (auto const &i: m_constraints)
|
||
|
res = i->validate (res, data);
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
std::ostream&
|
||
|
combine::describe (std::ostream &os) const
|
||
|
{
|
||
|
return os << "{ combine: [ ";
|
||
|
for (auto const &i: m_constraints)
|
||
|
os << *i << ", ";
|
||
|
return os << " ] }";
|
||
|
}
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
bool
|
||
|
combine::has_default (void) const
|
||
|
{
|
||
|
return !!m_default;
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
std::unique_ptr<::json::tree::node>
|
||
|
combine::default_value (void) const
|
||
|
{
|
||
|
return m_default->clone ();
|
||
|
}
|