Browse Source

Add new operator() to Value class for std::vector

Eric Ramat 5 months ago
parent
commit
d45229e530
1 changed files with 15 additions and 3 deletions
  1. 15 3
      src/artis-star/common/Value.hpp

+ 15 - 3
src/artis-star/common/Value.hpp

@@ -52,9 +52,7 @@ public:
 
   template<typename T>
   Value(T *value, size_t size)
-  {
-    assign(value, sizeof(T) * size, typeid(T *).hash_code());
-  }
+  { assign(value, sizeof(T) * size, typeid(T *).hash_code()); }
 
   Value(void *content, size_t size)
   { assign(content, size, typeid(void *).hash_code()); }
@@ -100,6 +98,20 @@ public:
     value = (T *) (_content);
   }
 
+  template<typename T>
+  void operator()(std::vector <T> &value) const
+  {
+    assert(_type_id == typeid(T *).hash_code());
+
+    size_t size = _size / sizeof(T);
+
+    assert(size > 1);
+
+    for (size_t i = 0; i < size; ++i) {
+      value.push_back(((T *) (_content))[i]);
+    }
+  }
+
   template<typename Z>
   bool is_type() const
   { return _type_id == typeid(Z).hash_code(); }