libcruft-util/json/schema/base.cpp

47 lines
2.0 KiB
C++
Raw Normal View History

/*
* 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 "base.hpp"
#include "type.hpp"
#include "length.hpp"
#include "inequality.hpp"
#include "properties.hpp"
2018-07-12 13:06:11 +10:00
#include "enum.hpp"
using util::json::schema::constraint::base;
///////////////////////////////////////////////////////////////////////////////
std::unique_ptr<base>
base::instantiate (std::string const &name, ::json::tree::node const &def)
{
if (name == "type") return std::make_unique<type> (def);
if (name == "minLength") return std::make_unique<min_length> (def);
if (name == "maxLength") return std::make_unique<max_length> (def);
if (name == "minimum") return std::make_unique<minimum> (def);
2018-07-12 16:08:36 +10:00
if (name == "exclusiveMaximum") return std::make_unique<exclusive_maximum> (def);
if (name == "exclusiveMinimum") return std::make_unique<exclusive_minimum> (def);
2018-07-12 16:21:56 +10:00
if (name == "multipleOf") return std::make_unique<multiple_of > (def);
if (name == "maximum") return std::make_unique<maximum> (def);
if (name == "properties") return std::make_unique<properties> (def);
if (name == "patternProperties") return std::make_unique<pattern_properties> (def);
if (name == "additionalProperties") return std::make_unique<additional_properties> (def);
if (name == "enum") return std::make_unique<enumeration> (def);
throw unknown_constraint (name);
}