[
https://issues.apache.org/jira/browse/MINIFICPP-479?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16719104#comment-16719104
]
ASF GitHub Bot commented on MINIFICPP-479:
------------------------------------------
Github user arpadboda commented on a diff in the pull request:
https://github.com/apache/nifi-minifi-cpp/pull/460#discussion_r241048231
--- Diff: libminifi/include/core/state/Value.h ---
@@ -74,94 +157,215 @@ class BoolValue : public Value {
explicit BoolValue(bool value)
: Value(value ? "true" : "false"),
value(value) {
+ setTypeId<bool>();
+ }
+ explicit BoolValue(const std::string &strvalue)
+ : Value(strvalue) {
+ bool l;
+ std::istringstream(strvalue) >> std::boolalpha >> l;
+ value = l; // avoid warnings
}
- bool getValue() {
+
+ bool getValue() const {
return value;
}
protected:
+
+ virtual bool getValue(int &ref) {
+ if (ref == 1) {
+ ref = true;
+ return true;
+ } else if (ref == 0) {
+ ref = false;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ virtual bool getValue(int64_t &ref) {
+ if (ref == 1) {
+ ref = true;
+ return true;
+ } else if (ref == 0) {
+ ref = false;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ virtual bool getValue(uint64_t &ref) {
+ if (ref == 1) {
+ ref = true;
+ return true;
+ } else if (ref == 0) {
+ ref = false;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ virtual bool getValue(bool &ref) {
+ ref = value;
+ return true;
+ }
+
bool value;
};
-class Int64Value : public Value {
+class UInt64Value : public Value {
public:
- explicit Int64Value(uint64_t value)
+ explicit UInt64Value(uint64_t value)
: Value(std::to_string(value)),
value(value) {
+ setTypeId<uint64_t>();
+ }
+ explicit UInt64Value(const std::string &strvalue)
+ : Value(strvalue),
+ value(std::stoull(strvalue)) {
+ setTypeId<uint64_t>();
}
- uint64_t getValue() {
+
+ uint64_t getValue() const {
return value;
}
protected:
+
+ virtual bool getValue(int &ref) {
+ return false;
+ }
+
+ virtual bool getValue(int64_t &ref) {
+ if (value < std::numeric_limits<int64_t>::max()) {
+ ref = value;
+ return true;
+ }
+ return false;
+ }
+
+ virtual bool getValue(uint64_t &ref) {
+ ref = value;
+ return true;
+ }
+
+ virtual bool getValue(bool &ref) {
+ return false;
+ }
+
uint64_t value;
};
+class Int64Value : public Value {
+ public:
+ explicit Int64Value(int64_t value)
+ : Value(std::to_string(value)),
+ value(value) {
+ setTypeId<int64_t>();
+ }
+ explicit Int64Value(const std::string &strvalue)
+ : Value(strvalue),
+ value(std::stoll(strvalue)) {
+ setTypeId<int64_t>();
+ }
+
+ int64_t getValue() {
+ return value;
+ }
+ protected:
+
+ virtual bool getValue(int &ref) {
+ return false;
+ }
+
+ virtual bool getValue(int64_t &ref) {
+ ref = value;
+ return true;
+ }
+
+ virtual bool getValue(uint64_t &ref) {
+ if (value >= 0) {
+ ref = value;
+ return true;
+ }
+ return true;
+ }
+
+ virtual bool getValue(bool &ref) {
+ return false;
+ }
-static inline std::shared_ptr<Value> createValue(
- const bool &object) {
+ int64_t value;
+};
+
+static inline std::shared_ptr<Value> createValue(const bool &object) {
return std::make_shared<BoolValue>(object);
}
-static inline std::shared_ptr<Value> createValue(
- const char *object) {
+static inline std::shared_ptr<Value> createValue(const char *object) {
return std::make_shared<Value>(object);
}
-static inline std::shared_ptr<Value> createValue(
- char *object) {
+static inline std::shared_ptr<Value> createValue(char *object) {
return std::make_shared<Value>(std::string(object));
}
-static inline std::shared_ptr<Value> createValue(
- const std::string &object) {
+static inline std::shared_ptr<Value> createValue(const std::string
&object) {
return std::make_shared<Value>(object);
}
-
-static inline std::shared_ptr<Value> createValue(
- const uint32_t &object) {
- return std::make_shared<Int64Value>(object);
+static inline std::shared_ptr<Value> createValue(const uint32_t &object) {
+ return std::make_shared<UInt64Value>(object);
+}
+#if ( defined(__APPLE__) || defined(__MACH__) || defined(DARWIN) )
+static inline std::shared_ptr<Value> createValue(const size_t &object) {
+ return std::make_shared<UInt64Value>(object);
+}
+#endif
+static inline std::shared_ptr<Value> createValue(const uint64_t &object) {
+ return std::make_shared<UInt64Value>(object);
}
-static inline std::shared_ptr<Value> createValue(
- const uint64_t &object) {
+
+static inline std::shared_ptr<Value> createValue(const int64_t &object) {
return std::make_shared<Int64Value>(object);
}
-static inline std::shared_ptr<Value> createValue(
- const int &object) {
+static inline std::shared_ptr<Value> createValue(const int &object) {
return std::make_shared<IntValue>(object);
}
-
/**
* Purpose: ValueNode is the AST container for a value
*/
class ValueNode {
public:
ValueNode()
: value_(nullptr) {
-
}
+ ValueNode(ValueNode &&vn) = default;
+ ValueNode(const ValueNode &vn) = default;
+
/**
* Define the representations and eventual storage relationships through
* createValue
*/
template<typename T>
- auto operator=(
- const T ref) -> typename std::enable_if<std::is_same<T, int >::value
||
- std::is_same<T, uint32_t >::value ||
- std::is_same<T, uint64_t >::value ||
- std::is_same<T, bool >::value ||
- std::is_same<T, char* >::value ||
- std::is_same<T, const char* >::value ||
- std::is_same<T, std::string>::value,ValueNode&>::type {
+ auto operator=(const T ref) -> typename std::enable_if<std::is_same<T,
int >::value ||
--- End diff --
Guess std::is_integral<T> would help here reducing this.
> Incorporate property validation information into manifest
> ---------------------------------------------------------
>
> Key: MINIFICPP-479
> URL: https://issues.apache.org/jira/browse/MINIFICPP-479
> Project: NiFi MiNiFi C++
> Issue Type: Improvement
> Reporter: Andrew Christianson
> Assignee: Mr TheSegfault
> Priority: Major
>
> High-level intent is to avoid round-trip to c2 to know that flow is valid
> (or, invalid in common/trivial ways).
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)