}
}
+bool IntegerAttribute::operator<=(const int& antecedent)
+{
+ if (antecedent < __closedLowerBound || antecedent > __closedUpperBound)
+ return false;
+
+ if (antecedent <= __openLowerBound || antecedent >= __openUpperBound)
+ return false;
+
+ if (!__targets.empty() && __targets.find(antecedent) == __targets.end())
+ return false;
+
+ if (!__nonTargets.empty() && __nonTargets.find(antecedent) != __targets.end())
+ return false;
+
+ return true;
+}
+
+bool IntegerAttribute::operator<=(const std::string& antecedent)
+{
+ return false;
+}
+
StringAttribute::StringAttribute(const std::string& name) :
Attribute(name)
jsonNode[KEY_NON_TARGET].append(nonTarget);
}
}
+
+bool StringAttribute::operator<=(const int& antecedent)
+{
+ return false;
+}
+
+bool StringAttribute::operator<=(const std::string& antecedent)
+{
+ if (!__targets.empty() && __targets.find(antecedent) == __targets.end())
+ return false;
+
+ if (!__nonTargets.empty() && __nonTargets.find(antecedent) != __targets.end())
+ return false;
+
+ return true;
+}
virtual ~Attribute();
+ const std::string& getName() const;
+
virtual Attribute::Type getType() const = 0;
virtual void toJson(Json::Value& jsonNode) const = 0;
- const std::string& getName() const;
+ virtual bool operator<=(const int& antecedent) = 0;
+ virtual bool operator<=(const std::string& antecedent) = 0;
static Attribute* build(const std::string& name, Json::Value& jsonNode);
void toJson(Json::Value& jsonNode) const;
+ bool operator<=(const int& antecedent);
+ bool operator<=(const std::string& antecedent);
+
private:
int __closedLowerBound;
int __closedUpperBound;
void toJson(Json::Value& jsonNode) const;
+ bool operator<=(const int& antecedent);
+ bool operator<=(const std::string& antecedent);
+
private:
std::set<std::string> __targets;
std::set<std::string> __nonTargets;
jsonNode[KEY_DISJUNCTION] = __disjunction;
}
+bool JobContext::operator<=(const Json::Value& antecedent)
+{
+ auto isSatisfied = [&](Attribute*& attr)->bool {
+ const char* name = attr->getName().c_str();
+ const Json::Value* value = antecedent.find(name, name + strlen(name));
+
+ if (!value)
+ return false;
+
+ if (value->isInt())
+ return (*attr) <= value->asInt();
+
+ if (value->isString())
+ return (*attr) <= value->asString();
+
+ return false;
+ };
+
+ if (isDisjunction()) { /* Legacy support */
+ for (auto& attr : __attributes) {
+ if (isSatisfied(attr))
+ return true;
+ }
+
+ return __attributes.empty();
+ }
+
+ for (auto& attr : __attributes) {
+ if (!isSatisfied(attr))
+ return false;
+ }
+
+ return true;
+}
+
bool JobContext::isDisjunction() const
{
return __disjunction;
void toJson(Json::Value& jsonNode) const;
+ bool operator<=(const Json::Value& antecedent);
+
/* Legacy support */
bool isDisjunction() const;
JobContext& setDisjunction(bool disjunction);