|
@@ -62,6 +62,8 @@ class Value {
|
|
|
|
|
|
virtual bool operator==(const Base &other) const = 0;
|
|
virtual bool operator==(const Base &other) const = 0;
|
|
|
|
|
|
|
|
+ virtual size_t size() const = 0;
|
|
|
|
+
|
|
virtual std::string to_string() const = 0;
|
|
virtual std::string to_string() const = 0;
|
|
|
|
|
|
virtual const std::type_info &type() const noexcept = 0;
|
|
virtual const std::type_info &type() const noexcept = 0;
|
|
@@ -124,6 +126,16 @@ class Value {
|
|
return ss.str();
|
|
return ss.str();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ size_t size() const override {
|
|
|
|
+ if (type() == typeid(std::vector<T>)) {
|
|
|
|
+ return std::any_cast<const std::vector<T> &>(*this).size();
|
|
|
|
+ } else if (type() == typeid(std::string)) {
|
|
|
|
+ return std::any_cast<const std::string &>(*this).size();
|
|
|
|
+ } else if (type() == typeid(std::valarray<T>)) {
|
|
|
|
+ return std::any_cast<const std::valarray<T> &>(*this).size();
|
|
|
|
+ } else { return 1; }
|
|
|
|
+ }
|
|
|
|
+
|
|
const std::type_info &type() const noexcept override { return std::any::type(); }
|
|
const std::type_info &type() const noexcept override { return std::any::type(); }
|
|
|
|
|
|
private:
|
|
private:
|
|
@@ -133,7 +145,7 @@ class Value {
|
|
public:
|
|
public:
|
|
Value() : _data(nullptr) {}
|
|
Value() : _data(nullptr) {}
|
|
|
|
|
|
- Value(const Value& value) : _data(value._data) {}
|
|
|
|
|
|
+ Value(const Value &value) : _data(value._data) {}
|
|
|
|
|
|
template<typename T, std::enable_if_t<not HasToString<T>::Has, bool> = true>
|
|
template<typename T, std::enable_if_t<not HasToString<T>::Has, bool> = true>
|
|
Value(const T &value) : _data(new Data<T>(value)) {}
|
|
Value(const T &value) : _data(new Data<T>(value)) {}
|
|
@@ -155,7 +167,7 @@ public:
|
|
template<typename Z>
|
|
template<typename Z>
|
|
bool is_type() const { return _data->type() == typeid(Z); }
|
|
bool is_type() const { return _data->type() == typeid(Z); }
|
|
|
|
|
|
- Value& operator=(const Value &other) {
|
|
|
|
|
|
+ Value &operator=(const Value &other) {
|
|
_data = other._data;
|
|
_data = other._data;
|
|
return *this;
|
|
return *this;
|
|
}
|
|
}
|
|
@@ -179,9 +191,9 @@ public:
|
|
dynamic_cast<Data<T> *>(_data.get())->operator()(value);
|
|
dynamic_cast<Data<T> *>(_data.get())->operator()(value);
|
|
}
|
|
}
|
|
|
|
|
|
- std::string to_string() const {
|
|
|
|
- return _data->to_string();
|
|
|
|
- }
|
|
|
|
|
|
+ size_t size() const { return _data->size(); }
|
|
|
|
+
|
|
|
|
+ std::string to_string() const { return _data->to_string(); }
|
|
|
|
|
|
private:
|
|
private:
|
|
friend class boost::serialization::access;
|
|
friend class boost::serialization::access;
|
|
@@ -194,7 +206,7 @@ private:
|
|
std::shared_ptr<Base> _data;
|
|
std::shared_ptr<Base> _data;
|
|
};
|
|
};
|
|
|
|
|
|
-std::ostream& operator<<(std::ostream& o, const artis::common::event::Value& value);
|
|
|
|
|
|
+std::ostream &operator<<(std::ostream &o, const artis::common::event::Value &value);
|
|
|
|
|
|
} // namespace artis common event
|
|
} // namespace artis common event
|
|
|
|
|