28 #include "Requirement.h"
29 #include "StringRequirement.h"
30 #include "IntegerRequirement.h"
31 #include "NumberRequirement.h"
32 #include "ObjectRequirement.h"
33 #include "RequirementLoader.h"
47 std::unique_ptr<Requirement>
item_;
66 std::set<T> Y(X.begin(), X.end());
67 return X.size() == Y.size();
97 item_->ClearNotices();
125 virtual void Parse(Value json,
const std::string& path)
override
130 if(json.isMember(
"items") && json[
"items"].isObject())
133 item_->Parse(json[
"items"], path);
135 else if(json.isMember(
"items") && json[
"items"].isArray())
137 for(
auto& item : json[
"items"])
141 items_.push_back(std::move(iptr));
142 items_.back()->Parse(item, path);
147 if(json.isMember(
"additionalItems") && json[
"additionalItems"].isBool())
148 addItems_ = json[
"additionalItems"].asBool();
150 if(json.isMember(
"minItems") && json[
"minItems"].isInt())
153 min_ = json[
"minItems"].asInt();
156 if(json.isMember(
"maxItems") && json[
"maxItems"].isInt())
159 max_ = json[
"maxItems"].asInt();
162 if(json.isMember(
"uniqueItems") && json[
"uniqueItems"].isBool())
163 unique_ = json[
"uniqueItems"].asBool();
171 virtual void Validate(
const Value& json,
const std::string& path)
override
175 PushError(path +
": Must be of type \"array\"");
182 for(
const auto& item : json)
184 item_->Validate(item, path +
"/" + std::to_string(i));
189 for(
const auto& error :
item_->GetErrors())
192 for(
const auto& notice :
item_->GetNotices())
200 PushError(path +
": There cannot be any additional items in the array");
202 int iv = std::min((
int)
items_.size(), (
int)json.size());
203 for(
int i = 0; i < iv; ++i)
205 items_[i]->Validate(json[i], path);
217 PushError(path +
": There must be at least " + std::to_string(
min_) +
" elements in the array");
220 PushError(path +
": There must be no more than " + std::to_string(
max_) +
" elements in the array");
223 PushError(path +
": Entries must be unique");
bool IsUnique(T X)
Test if set is unique.
bool setMax_
True if maximum has been set.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value and fill array.
bool setMin_
True if minimum has been set.
bool addItems_
True if items can be added.
virtual void Validate(const Value &json, const std::string &path) override
Validate json value.
virtual void Reset() override
Reset array.
RequireList items_
List of Requirements.
virtual void ClearNotices() override
Clear notices for all Requirements.
bool unique_
True if all Requirements are unique.
std::unique_ptr< Requirement > item_
Single Requirement.
virtual void ClearErrors() override
Clear list of error messages for all Requirements.
ArrayRequirement()
Constructor.
Helper class to load Requirement.
std::unique_ptr< Requirement > LoadRequirement(const Value &json)
Load specific requirement.
Requirements on input files.
void PushNotice(const std::string ¬ice)
Add message to list of notices.
std::vector< std::string > GetNotices()
Get list of notices.
std::vector< std::string > GetErrors()
Get list of error messages.
virtual void ClearNotices()
Clear list of notice messages.
virtual void ClearErrors()
Clear list of error messages.
void PushError(const std::string &error)
Add error to list of error messages.
std::vector< std::unique_ptr< Requirement > > RequireList
List of Requirements.