47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
|
#include "controller.h"
|
||
|
#include "policy.h"
|
||
|
#include <algorithm>
|
||
|
|
||
|
Controller::Controller(Initializer&& initializer) :
|
||
|
_keywords(initializer.keywords),
|
||
|
_interaction_message(initializer.message)
|
||
|
{}
|
||
|
|
||
|
Controller::~Controller()
|
||
|
{}
|
||
|
|
||
|
bool Controller::validateInput(const std::string &input_word) const
|
||
|
{
|
||
|
return std::find(_keywords.begin(), _keywords.end(), input_word) != _keywords.end();
|
||
|
}
|
||
|
|
||
|
void Controller::setValidationPolicies(const std::list<std::shared_ptr<Policy>>& policies)
|
||
|
{
|
||
|
_validation_policies = policies;
|
||
|
}
|
||
|
|
||
|
Controller::ValidationResult Controller::validatePolicies() const
|
||
|
{
|
||
|
if (_validation_policies.empty())
|
||
|
return {true, ""};
|
||
|
|
||
|
std::string interaction_output;
|
||
|
|
||
|
bool success = true;
|
||
|
for (const auto& policy : _validation_policies)
|
||
|
{
|
||
|
const auto check_result = policy->check();
|
||
|
interaction_output += (check_result.commentary + "\n\n");
|
||
|
if (!check_result.satisfied)
|
||
|
{
|
||
|
success = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
interaction_output.pop_back();
|
||
|
interaction_output.pop_back();
|
||
|
|
||
|
return {success, interaction_output};
|
||
|
}
|