Parcourir la source

Remove null and equal values in view

Eric Ramat il y a 3 ans
Parent
commit
b30c7c2e64

+ 1 - 1
src/artis-star/common/ExternalEvent.hpp

@@ -134,7 +134,7 @@ public:
     }
     ss << (_model ? _model->get_name() : "<>")
        << " , ";
-    if (not _data.empty()) {
+    if (not _data.is_null()) {
       ss << _data.to_string();
     } else {
       ss << "null";

+ 13 - 7
src/artis-star/common/Value.hpp

@@ -63,7 +63,7 @@ public:
     assign(v, sizeof(T) * value.size(), typeid(T *).hash_code());
   }
 
-  Value(const std::vector <bool> &value)
+  Value(const std::vector<bool> &value)
   {
     size_t size = sizeof(bool) * value.size();
 
@@ -98,9 +98,19 @@ public:
       delete[] _content;
   }
 
-  bool empty() const
+  bool is_null() const
   { return _content == nullptr; }
 
+  template<typename Z>
+  bool is_type() const
+  { return _type_id == typeid(Z).hash_code(); }
+
+  bool operator==(const Value &other) const
+  {
+    return _type_id == other._type_id and _size == other._size
+        and std::memcmp(_content, other._content, _size) == 0;
+  }
+
   template<typename T>
   void operator()(T &value) const
   {
@@ -129,10 +139,6 @@ public:
     }
   }
 
-  template<typename Z>
-  bool is_type() const
-  { return _type_id == typeid(Z).hash_code(); }
-
   Value &operator=(const Value &value)
   {
     if (_content != nullptr) {
@@ -159,7 +165,7 @@ public:
 
   std::string to_string() const
   {
-    if (empty()) {
+    if (is_null()) {
       return "<null>";
     } else if (is_type<double>()) {
       double v;

+ 28 - 3
src/artis-star/common/observer/View.hpp

@@ -136,7 +136,7 @@ public:
 
       return it->second.begin()->second;
     } else {
-      assert(false);
+      throw std::range_error("selector name not found");
     }
   }
 
@@ -178,8 +178,7 @@ public:
         assert(chain[i] >= 0);
 
         observe(chain, i + 2, time,
-                model->get_submodel((unsigned int) chain[i],
-                                    model_index),
+                model->get_submodel((unsigned int) chain[i], model_index),
                 selector_name, variable_index);
       }
     } else {
@@ -205,6 +204,32 @@ public:
         }
       }
     }
+
+    bool ok = true;
+    auto it = _values.begin();
+
+    while (it != _values.end() and ok) {
+      const auto &v = it->second.begin()->second;
+
+      if (v.back().second.is_null()) {
+        ++it;
+      } else {
+        if (v.size() > 1) {
+          if (v.back().second == v[v.size() - 2].second) {
+            ++it;
+          } else {
+            ok = false;
+          }
+        } else {
+          ok = false;
+        }
+      }
+    }
+    if (ok) {
+      for (auto &v: _values) {
+        v.second.begin()->second.pop_back();
+      }
+    }
   }
 
   void selector(const std::string &name, const Selector &chain)