Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
refactor with templated method
[simgrid.git] / src / instr / instr_paje_types.hpp
index 71a08d3..4ac25a5 100644 (file)
@@ -7,6 +7,7 @@
 #define INSTR_PAJE_TYPES_HPP
 
 #include "src/instr/instr_private.hpp"
+#include <sstream>
 #include <string>
 #include <vector>
 
@@ -24,6 +25,7 @@ class Type {
 public:
   std::map<std::string, Type*> children_;
   Container* issuer_ = nullptr;
+  std::stringstream stream_;
 
   Type(std::string name, std::string alias, std::string color, Type* father);
   virtual ~Type();
@@ -33,12 +35,15 @@ public:
   long long int get_id() { return id_; }
   bool isColored() { return not color_.empty(); }
 
-  Type* byName(std::string name);
-  ContainerType* getOrCreateContainerType(std::string name);
-  EventType* getOrCreateEventType(std::string name);
-  LinkType* getOrCreateLinkType(std::string name, Type* source, Type* dest);
-  StateType* getOrCreateStateType(std::string name);
-  VariableType* getOrCreateVariableType(std::string name, std::string color);
+  Type* by_name(std::string name);
+  LinkType* by_name_or_create(std::string name, Type* source, Type* dest);
+  VariableType* by_name_or_create(std::string name, std::string color);
+
+  template <class T> T* by_name_or_create(std::string name)
+  {
+    auto cont = children_.find(name);
+    return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second);
+  }
 
   void setCallingContainer(Container* container) { issuer_ = container; }
 
@@ -57,6 +62,7 @@ class VariableType : public Type {
 public:
   VariableType(std::string name, std::string color, Type* father);
   ~VariableType();
+  void instr_event(double now, double delta, const char* resource, double value);
   void setEvent(double timestamp, double value);
   void addEvent(double timestamp, double value);
   void subEvent(double timestamp, double value);