Implement validators and modificators for controllers
parent
159b7e4673
commit
5030b71e3f
@ -0,0 +1,7 @@
|
||||
#include "modificator.h"
|
||||
|
||||
Modificator::Modificator()
|
||||
{}
|
||||
|
||||
Modificator::~Modificator()
|
||||
{}
|
@ -0,0 +1,13 @@
|
||||
#ifndef MODIFICATOR_H
|
||||
#define MODIFICATOR_H
|
||||
|
||||
class Modificator
|
||||
{
|
||||
public:
|
||||
explicit Modificator();
|
||||
virtual ~Modificator();
|
||||
|
||||
virtual void run() const = 0;
|
||||
};
|
||||
|
||||
#endif // MODIFICATOR_H
|
@ -0,0 +1,23 @@
|
||||
#include "removecontrollersmodificator.h"
|
||||
#include "location.h"
|
||||
|
||||
RemoveControllersModificator::RemoveControllersModificator()
|
||||
{}
|
||||
|
||||
RemoveControllersModificator::~RemoveControllersModificator()
|
||||
{}
|
||||
|
||||
void RemoveControllersModificator::run() const
|
||||
{
|
||||
_location->removeControllers(_controllers_to_remove);
|
||||
_location->setInteractionMessage(_new_location_message);
|
||||
}
|
||||
|
||||
void RemoveControllersModificator::setDependentObjects(const std::shared_ptr<Location>& location,
|
||||
const std::list<std::shared_ptr<Controller>>& controllers,
|
||||
const std::string& new_message)
|
||||
{
|
||||
_location = location;
|
||||
_controllers_to_remove = controllers;
|
||||
_new_location_message = new_message;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef REMOVECONTROLLERSMODIFICATOR_H
|
||||
#define REMOVECONTROLLERSMODIFICATOR_H
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <list>
|
||||
|
||||
#include "modificator.h"
|
||||
|
||||
class Location;
|
||||
class Controller;
|
||||
|
||||
class RemoveControllersModificator : public Modificator
|
||||
{
|
||||
public:
|
||||
explicit RemoveControllersModificator();
|
||||
virtual ~RemoveControllersModificator() override;
|
||||
|
||||
virtual void run() const override;
|
||||
|
||||
void setDependentObjects(const std::shared_ptr<Location>& location,
|
||||
const std::list<std::shared_ptr<Controller>>& controllers,
|
||||
const std::string& new_message);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Location> _location;
|
||||
std::list<std::shared_ptr<Controller>> _controllers_to_remove;
|
||||
std::string _new_location_message;
|
||||
};
|
||||
|
||||
#endif // REMOVECONTROLLERSMODIFICATOR_H
|
@ -0,0 +1,29 @@
|
||||
#include "allpoliciesvalidator.h"
|
||||
#include "policy.h"
|
||||
|
||||
AllPoliciesValidator::AllPoliciesValidator(const std::list<std::shared_ptr<Policy>>& policies) :
|
||||
Validator(policies)
|
||||
{}
|
||||
|
||||
AllPoliciesValidator::~AllPoliciesValidator()
|
||||
{}
|
||||
|
||||
Validator::ValidateResult AllPoliciesValidator::validate(const std::shared_ptr<Actor> &actor) const
|
||||
{
|
||||
Validator::ValidateResult validate_result{true, ""};
|
||||
|
||||
for (const auto& policy : _validation_policies)
|
||||
{
|
||||
const auto result = policy->check(actor);
|
||||
validate_result.validate_output += result.commentary;
|
||||
validate_result.validate_output += "\n\n";
|
||||
|
||||
if (!result.satisfied)
|
||||
{
|
||||
validate_result.success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return validate_result;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#ifndef ALLPOLICIESVALIDATOR_H
|
||||
#define ALLPOLICIESVALIDATOR_H
|
||||
|
||||
#include "validator.h"
|
||||
|
||||
class AllPoliciesValidator : public Validator
|
||||
{
|
||||
public:
|
||||
explicit AllPoliciesValidator(const std::list<std::shared_ptr<Policy>>& policies);
|
||||
virtual ~AllPoliciesValidator() override;
|
||||
|
||||
virtual ValidateResult validate(const std::shared_ptr<Actor>& actor) const override;
|
||||
};
|
||||
|
||||
#endif // ALLPOLICIESVALIDATOR_H
|
@ -0,0 +1,29 @@
|
||||
#include "anypolicyvalidator.h"
|
||||
#include "policy.h"
|
||||
|
||||
AnyPolicyValidator::AnyPolicyValidator(const std::list<std::shared_ptr<Policy>>& policies) :
|
||||
Validator(policies)
|
||||
{}
|
||||
|
||||
AnyPolicyValidator::~AnyPolicyValidator()
|
||||
{}
|
||||
|
||||
Validator::ValidateResult AnyPolicyValidator::validate(const std::shared_ptr<Actor> &actor) const
|
||||
{
|
||||
Validator::ValidateResult validate_result{false, ""};
|
||||
|
||||
for (const auto& policy : _validation_policies)
|
||||
{
|
||||
const auto result = policy->check(actor);
|
||||
|
||||
if (result.satisfied)
|
||||
{
|
||||
validate_result.validate_output += result.commentary;
|
||||
validate_result.validate_output += "\n\n";
|
||||
validate_result.success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return validate_result;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#ifndef ANYPOLICYVALIDATOR_H
|
||||
#define ANYPOLICYVALIDATOR_H
|
||||
|
||||
#include "validator.h"
|
||||
|
||||
class AnyPolicyValidator : public Validator
|
||||
{
|
||||
public:
|
||||
explicit AnyPolicyValidator(const std::list<std::shared_ptr<Policy>>& policies);
|
||||
virtual ~AnyPolicyValidator() override;
|
||||
|
||||
virtual ValidateResult validate(const std::shared_ptr<Actor>& actor) const override;
|
||||
};
|
||||
|
||||
#endif // ANYPOLICYVALIDATOR_H
|
@ -0,0 +1,8 @@
|
||||
#include "validator.h"
|
||||
|
||||
Validator::Validator(const std::list<std::shared_ptr<Policy>>& policies) :
|
||||
_validation_policies(policies)
|
||||
{}
|
||||
|
||||
Validator::~Validator()
|
||||
{}
|
@ -0,0 +1,29 @@
|
||||
#ifndef VALIDATOR_H
|
||||
#define VALIDATOR_H
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class Policy;
|
||||
class Actor;
|
||||
|
||||
class Validator
|
||||
{
|
||||
public:
|
||||
explicit Validator(const std::list<std::shared_ptr<Policy>>& policies);
|
||||
virtual ~Validator() = 0;
|
||||
|
||||
struct ValidateResult
|
||||
{
|
||||
bool success = false;
|
||||
std::string validate_output;
|
||||
};
|
||||
|
||||
virtual ValidateResult validate(const std::shared_ptr<Actor>& actor) const = 0;
|
||||
|
||||
protected:
|
||||
std::list<std::shared_ptr<Policy>> _validation_policies;
|
||||
};
|
||||
|
||||
#endif // VALIDATOR_H
|
Loading…
Reference in New Issue