Add non-template Value getters to PropertyValue
Reviewers: mtomic, mferencevic Reviewed By: mtomic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2216
This commit is contained in:
parent
e9a7623288
commit
e83abaaa5a
@ -7,6 +7,16 @@
|
|||||||
|
|
||||||
#include "utils/exceptions.hpp"
|
#include "utils/exceptions.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception raised by the PropertyValue system. Typically when
|
||||||
|
* trying to perform operations (such as addition) on PropertyValues
|
||||||
|
* of incompatible Types.
|
||||||
|
*/
|
||||||
|
class PropertyValueException : public utils::StacktraceException {
|
||||||
|
public:
|
||||||
|
using utils::StacktraceException::StacktraceException;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulation of a value and its type in a class that has no compile-time
|
* Encapsulation of a value and its type in a class that has no compile-time
|
||||||
* info about the type.
|
* info about the type.
|
||||||
@ -92,6 +102,69 @@ class PropertyValue {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
T &Value();
|
T &Value();
|
||||||
|
|
||||||
|
bool ValueBool() const {
|
||||||
|
if (type_ != Type::Bool) {
|
||||||
|
throw PropertyValueException("This value isn't a bool!");
|
||||||
|
}
|
||||||
|
return bool_v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t ValueInt() const {
|
||||||
|
if (type_ != Type::Int) {
|
||||||
|
throw PropertyValueException("This value isn't a int!");
|
||||||
|
}
|
||||||
|
return int_v;
|
||||||
|
}
|
||||||
|
|
||||||
|
double ValueDouble() const {
|
||||||
|
if (type_ != Type::Double) {
|
||||||
|
throw PropertyValueException("This value isn't a double!");
|
||||||
|
}
|
||||||
|
return double_v;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &ValueString() const {
|
||||||
|
if (type_ != Type::String) {
|
||||||
|
throw PropertyValueException("The value isn't a string!");
|
||||||
|
}
|
||||||
|
return string_v;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<PropertyValue> &ValueList() const {
|
||||||
|
if (type_ != Type::List) {
|
||||||
|
throw PropertyValueException("The value isn't a list!");
|
||||||
|
}
|
||||||
|
return list_v;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::map<std::string, PropertyValue> &ValueMap() const {
|
||||||
|
if (type_ != Type::Map) {
|
||||||
|
throw PropertyValueException("The value isn't a map!");
|
||||||
|
}
|
||||||
|
return map_v;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string &ValueString() {
|
||||||
|
if (type_ != Type::String) {
|
||||||
|
throw PropertyValueException("The value isn't a string!");
|
||||||
|
}
|
||||||
|
return string_v;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<PropertyValue> &ValueList() {
|
||||||
|
if (type_ != Type::List) {
|
||||||
|
throw PropertyValueException("The value isn't a list!");
|
||||||
|
}
|
||||||
|
return list_v;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, PropertyValue> &ValueMap() {
|
||||||
|
if (type_ != Type::Map) {
|
||||||
|
throw PropertyValueException("The value isn't a map!");
|
||||||
|
}
|
||||||
|
return map_v;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DestroyValue();
|
void DestroyValue();
|
||||||
|
|
||||||
@ -113,16 +186,6 @@ class PropertyValue {
|
|||||||
Type type_;
|
Type type_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* An exception raised by the PropertyValue system. Typically when
|
|
||||||
* trying to perform operations (such as addition) on PropertyValues
|
|
||||||
* of incompatible Types.
|
|
||||||
*/
|
|
||||||
class PropertyValueException : public utils::StacktraceException {
|
|
||||||
public:
|
|
||||||
using utils::StacktraceException::StacktraceException;
|
|
||||||
};
|
|
||||||
|
|
||||||
// stream output
|
// stream output
|
||||||
std::ostream &operator<<(std::ostream &os, const PropertyValue::Type type);
|
std::ostream &operator<<(std::ostream &os, const PropertyValue::Type type);
|
||||||
std::ostream &operator<<(std::ostream &os, const PropertyValue &value);
|
std::ostream &operator<<(std::ostream &os, const PropertyValue &value);
|
||||||
|
Loading…
Reference in New Issue
Block a user