libcruft-util/json/schema/base.cpp

40 lines
1.4 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"
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);
if (name == "maximum") return std::make_unique<maximum> (def);
if (name == "properties") return std::make_unique<properties> (def);
throw unknown_constraint (name);
}