Browse Source

Fix value for std::vector<bool>

Eric Ramat 1 month ago
parent
commit
122d591743
2 changed files with 39 additions and 27 deletions
  1. 20 24
      src/artis-star/common/Any.hpp
  2. 19 3
      src/artis-star/common/Value.hpp

+ 20 - 24
src/artis-star/common/Any.hpp

@@ -139,22 +139,22 @@ public:
 
       value(v);
       put(o, v);
-    } else if (value.is_type<std::vector<double> >()) {
+    } else if (value.is_type < std::vector < double > > ()) {
       std::vector<double> v;
 
       value(v);
       put(o, v);
-    } else if (value.is_type<std::vector<unsigned int> >()) {
+    } else if (value.is_type < std::vector < unsigned int > > ()) {
       std::vector<unsigned int> v;
 
       value(v);
       put(o, v);
-    } else if (value.is_type<std::vector<int> >()) {
+    } else if (value.is_type < std::vector < int > > ()) {
       std::vector<int> v;
 
       value(v);
       put(o, v);
-    } else if (value.is_type<std::vector<bool> >()) {
+    } else if (value.is_type < std::vector < bool > > ()) {
       std::vector<bool> v;
 
       value(v);
@@ -192,27 +192,23 @@ public:
             if (q_bool) {
               return common::Value(o->*(q_bool->value_));
             } else {
-              data<T, std::vector<double> > *q_double_v =
-                  dynamic_cast < data<T, std::vector<
-                      double> > * >(ptr_);
+              data<T, std::vector < double> > *q_double_v =
+                  dynamic_cast < data<T, std::vector < double> > * > (ptr_);
 
               if (q_double_v) {
                 return common::Value(o->*(q_double_v->value_));
               } else {
-                data<T, std::vector<int> > *q_int_v =
-                    dynamic_cast < data<T, std::vector<
-                        int> > * >(ptr_);
+                data<T, std::vector < int> > *q_int_v =
+                    dynamic_cast < data<T, std::vector < int> > * > (ptr_);
 
                 if (q_int_v) {
                   return common::Value(o->*(q_int_v->value_));
                 } else {
-                  data<T, std::vector<bool> > *q_bool_v =
-                      dynamic_cast < data<T, std::vector<
-                          bool> > * >(ptr_);
+                  data<T, std::vector < bool> > *q_bool_v =
+                      dynamic_cast < data<T, std::vector < bool> > * > (ptr_);
 
                   if (q_bool_v) {
-                    return common::Value(
-                        o->*(q_bool_v->value_));
+                    return common::Value(o->*(q_bool_v->value_));
                   }
                 }
               }
@@ -253,23 +249,23 @@ public:
             if (q_bool) {
               return o->*(q_bool->value_) ? "true" : "false";
             } else {
-              data<T, std::vector<double> > *q_double_v =
-                  dynamic_cast < data<T, std::vector<
-                      double> > * >(ptr_);
+              data<T, std::vector < double> > *q_double_v =
+                  dynamic_cast < data<T, std::vector <
+                      double> > * > (ptr_);
 
               if (q_double_v) {
                 return "";
               } else {
-                data<T, std::vector<int> > *q_int_v =
-                    dynamic_cast < data<T, std::vector<
-                        int> > * >(ptr_);
+                data<T, std::vector < int> > *q_int_v =
+                    dynamic_cast < data<T, std::vector <
+                        int> > * > (ptr_);
 
                 if (q_int_v) {
                   return "";
                 } else {
-                  data<T, std::vector<bool> > *q_bool_v =
-                      dynamic_cast < data<T, std::vector<
-                          bool> > * >(ptr_);
+                  data<T, std::vector < bool> > *q_bool_v =
+                      dynamic_cast < data<T, std::vector <
+                          bool> > * > (ptr_);
 
                   if (q_bool_v) {
                     return "";

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

@@ -48,7 +48,7 @@ public:
   {}
 
   template<typename T>
-  Value(const T value)
+  Value(const T &value)
   { assign(&value, sizeof(T), typeid(T).hash_code()); }
 
   template<typename T>
@@ -56,8 +56,24 @@ public:
   { assign(value, sizeof(T) * size, typeid(T *).hash_code()); }
 
   template<typename T>
-  Value(const std::vector <T> &value, size_t size)
-  { assign(value.data(), sizeof(T) * value.size(), typeid(T *).hash_code()); }
+  Value(const std::vector <T> &value)
+  {
+    const T *v = value.data();
+
+    assign(v, sizeof(T) * value.size(), typeid(T *).hash_code());
+  }
+
+  Value(const std::vector <bool> &value)
+  {
+    size_t size = sizeof(bool) * value.size();
+
+    _content = new char[size];
+    for (size_t i = 0; i < value.size(); ++i) {
+      _content[i] = value[i];
+    }
+    _size = size;
+    _type_id = typeid(bool *).hash_code();
+  }
 
   Value(void *content, size_t size)
   { assign(content, size, typeid(void *).hash_code()); }