Cleaning the feature not conditional do the true design

This commit is contained in:
samcake 2015-11-02 14:17:07 -08:00
parent 543f322ffe
commit c2687b4998
4 changed files with 31 additions and 20 deletions

View file

@ -26,6 +26,7 @@
#include "Logging.h"
#include "impl/conditionals/AndConditional.h"
#include "impl/conditionals/NotConditional.h"
#include "impl/conditionals/EndpointConditional.h"
#include "impl/conditionals/ScriptConditional.h"
@ -838,18 +839,16 @@ Conditional::Pointer UserInputMapper::parseConditional(const QJsonValue& value)
auto input = findDeviceInput(conditionalToken);
auto endpoint = endpointFor(input);
if (!endpoint) {
return Conditional::Pointer();
}
auto conditional = std::make_shared<EndpointConditional>(endpoint);
if (!conditionalModifier.isEmpty()) {
if (conditionalModifier == JSON_CONDITIONAL_MODIFIER_NOT) {
return std::make_shared<NotEndpointConditional>(endpoint);
return std::make_shared<NotConditional>(conditional);
}
}
// Default and conditional behavior
return std::make_shared<EndpointConditional>(endpoint);
return conditional;
}
return Conditional::parse(value);

View file

@ -23,13 +23,5 @@ private:
Endpoint::Pointer _endpoint;
};
class NotEndpointConditional : public Conditional {
public:
NotEndpointConditional(Endpoint::Pointer endpoint) : _endpoint(endpoint) {}
virtual bool satisfied() override { return _endpoint && _endpoint->value() == 0.0; }
private:
Endpoint::Pointer _endpoint;
};
}
#endif

View file

@ -6,10 +6,16 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// NOTE: we don't need to include this header unless/until we add additional symbols.
// By removing this header we prevent these warnings on windows:
//
// warning LNK4221: This object file does not define any previously undefined public symbols,
// so it will not be used by any link operation that consumes this library
//
//#include "NotConditional.h"
#include "NotConditional.h"
using namespace controller;
bool NotConditional::satisfied() {
if (_operand) {
return (!_operand->satisfied());
} else {
return false;
}
}

View file

@ -12,5 +12,19 @@
#include "../Conditional.h"
namespace controller {
class NotConditional : public Conditional {
public:
using Pointer = std::shared_ptr<NotConditional>;
NotConditional(Conditional::Pointer operand) : _operand(operand) { }
virtual bool satisfied() override;
private:
Conditional::Pointer _operand;
};
}
#endif