浏览代码

Add vector to Any/Value

Eric Ramat 7 年之前
父节点
当前提交
ec52f3530a
共有 3 个文件被更改,包括 75 次插入2 次删除
  1. 8 2
      src/artis/context/Context.hpp
  2. 26 0
      src/artis/context/Value.hpp
  3. 41 0
      src/artis/kernel/Any.hpp

+ 8 - 2
src/artis/context/Context.hpp

@@ -54,8 +54,14 @@ public:
     void end(double end)
     { _end = end; }
 
-    const Context& operator=(const Context& /* context */)
-    { assert(false); }
+    const Context& operator=(const Context& context)
+    {
+        _begin = context._begin;
+        _end = context._end;
+        _valid = context._valid;
+        _state = context._state;
+        return *this;
+    }
 
     void saved()
     { _valid = true; }

+ 26 - 0
src/artis/context/Value.hpp

@@ -32,6 +32,8 @@
 #if WIN32
 #include <string>
 #endif
+#include <vector>
+
 namespace artis { namespace context {
 
 class Value
@@ -99,6 +101,21 @@ public:
 
             get_content(v);
             return v ? "true" : "false";
+        } if (is_double_vector()) {
+            std::vector < double > v;
+
+            get_content(v);
+            return "";
+        } else if (is_int_vector()) {
+            std::vector < int > v;
+
+            get_content(v);
+            return "";
+        } else if (is_bool_vector()) {
+            std::vector < bool > v;
+
+            get_content(v);
+            return "";
         } else {
             assert(false);
         }
@@ -107,12 +124,21 @@ public:
     bool is_bool() const
     { return _type_id == typeid(bool).hash_code(); }
 
+    bool is_bool_vector() const
+    { return _type_id == typeid(std::vector < bool >).hash_code(); }
+
     bool is_int() const
     { return _type_id == typeid(int).hash_code(); }
 
+    bool is_int_vector() const
+    { return _type_id == typeid(std::vector < int >).hash_code(); }
+
     bool is_double() const
     { return _type_id == typeid(double).hash_code(); }
 
+    bool is_double_vector() const
+    { return _type_id == typeid(std::vector < double >).hash_code(); }
+
 private:
     void assign(const void* content, size_t size, size_t type_id)
     {

+ 41 - 0
src/artis/kernel/Any.hpp

@@ -26,6 +26,7 @@
 #include <artis/context/Value.hpp>
 
 #include <string>
+#include <vector>
 
 namespace artis { namespace kernel {
 
@@ -104,6 +105,21 @@ public:
         } else if (value.is_bool()) {
             bool v;
 
+            value.get_content(v);
+            put(o, v);
+        } else if (value.is_double_vector()) {
+            std::vector < double > v;
+
+            value.get_content(v);
+            put(o, v);
+        } else if (value.is_int_vector()) {
+            std::vector < int > v;
+
+            value.get_content(v);
+            put(o, v);
+        } else if (value.is_bool_vector()) {
+            std::vector < bool > v;
+
             value.get_content(v);
             put(o, v);
         } else {
@@ -132,6 +148,31 @@ public:
 
                     if (q_bool) {
                         return context::Value(o->*(q_bool->value_));
+                    } else {
+                        data < T, std::vector < double > >* q_double_v =
+                            dynamic_cast < data < T, std::vector <
+                                double > >* >(ptr_);
+
+                        if (q_double_v) {
+                            return context::Value(o->*(q_double_v->value_));
+                        } else {
+                            data < T, std::vector < int > >* q_int_v =
+                                dynamic_cast < data < T, std::vector <
+                                    int > >* >(ptr_);
+
+                            if (q_int_v) {
+                                return context::Value(o->*(q_int_v->value_));
+                            } else {
+                                data < T, std::vector < bool > >* q_bool_v =
+                                    dynamic_cast < data < T, std::vector <
+                                        bool > >* >(ptr_);
+
+                                if (q_bool_v) {
+                                    return context::Value(
+                                        o->*(q_bool_v->value_));
+                                }
+                            }
+                        }
                     }
                 }
             }