Parcourir la source

nested namespace and move some classes to new namespace

Eric Ramat il y a 2 ans
Parent
commit
51a9b479da
94 fichiers modifiés avec 3092 ajouts et 3417 suppressions
  1. 43 39
      CMakeLists.txt
  2. 0 7
      src/CMakeLists.txt
  3. 4 4
      src/artis-star/common/CMakeLists.txt
  4. 27 46
      src/artis-star/common/Coordinator.hpp
  5. 20 35
      src/artis-star/common/GraphManager.hpp
  6. 27 44
      src/artis-star/common/Links.hpp
  7. 77 130
      src/artis-star/common/Model.hpp
  8. 12 22
      src/artis-star/common/Node.hpp
  9. 2 8
      src/artis-star/common/Parameters.hpp
  10. 19 32
      src/artis-star/common/RootCoordinator.hpp
  11. 7 14
      src/artis-star/common/Scheduler.hpp
  12. 9 18
      src/artis-star/common/Simulator.hpp
  13. 0 278
      src/artis-star/common/Value.hpp
  14. 21 39
      src/artis-star/common/context/Context.hpp
  15. 45 42
      src/artis-star/common/context/State.hpp
  16. 31 29
      src/artis-star/common/context/StateValues.hpp
  17. 18 25
      src/artis-star/common/Bag.hpp
  18. 12 0
      src/artis-star/common/event/CMakeLists.txt
  19. 40 55
      src/artis-star/common/ExternalEvent.hpp
  20. 22 32
      src/artis-star/common/InternalEvent.hpp
  21. 311 0
      src/artis-star/common/event/Value.hpp
  22. 2 1
      src/artis-star/common/observer/CMakeLists.txt
  23. 74 0
      src/artis-star/common/observer/DiscreteTimeIterator.hpp
  24. 54 0
      src/artis-star/common/observer/EventIterator.hpp
  25. 7 55
      src/artis-star/common/observer/Iterator.hpp
  26. 13 29
      src/artis-star/common/observer/Observer.hpp
  27. 7 61
      src/artis-star/common/observer/Output.hpp
  28. 49 0
      src/artis-star/common/observer/TimedIterator.hpp
  29. 30 49
      src/artis-star/common/observer/View.hpp
  30. 1 2
      src/artis-star/common/scheduler/CMakeLists.txt
  31. 25 38
      src/artis-star/common/scheduler/HeapScheduler.hpp
  32. 5 13
      src/artis-star/common/scheduler/SchedulerHandle.hpp
  33. 21 38
      src/artis-star/common/scheduler/VectorScheduler.hpp
  34. 48 69
      src/artis-star/common/Any.hpp
  35. 12 0
      src/artis-star/common/state/CMakeLists.txt
  36. 29 44
      src/artis-star/common/States.hpp
  37. 1 3
      src/artis-star/common/time/DoubleTime.hpp
  38. 1 3
      src/artis-star/common/time/IntegerTime.hpp
  39. 2 5
      src/artis-star/common/time/Limits.hpp
  40. 7 9
      src/artis-star/common/time/RationalTime.hpp
  41. 2 5
      src/artis-star/common/time/Time.hpp
  42. 1 1
      src/artis-star/common/utils/CMakeLists.txt
  43. 26 20
      src/artis-star/common/utils/FormalismType.hpp
  44. 34 24
      src/artis-star/common/utils/FunctionType.hpp
  45. 12 13
      src/artis-star/common/utils/LevelType.hpp
  46. 0 0
      src/artis-star/common/utils/Macro.hpp
  47. 4 9
      src/artis-star/common/utils/Multithreading.hpp
  48. 3 7
      src/artis-star/common/utils/String.hpp
  49. 51 87
      src/artis-star/common/utils/Trace.hpp
  50. 37 56
      src/artis-star/kernel/devs/Coordinator.hpp
  51. 27 46
      src/artis-star/kernel/devs/Dynamics.hpp
  52. 27 38
      src/artis-star/kernel/devs/GraphManager.hpp
  53. 33 55
      src/artis-star/kernel/devs/Simulator.hpp
  54. 40 59
      src/artis-star/kernel/dsde/Coordinator.hpp
  55. 63 100
      src/artis-star/kernel/dsde/Executive.hpp
  56. 33 41
      src/artis-star/kernel/dsde/GraphManager.hpp
  57. 30 46
      src/artis-star/kernel/dtss/Coordinator.hpp
  58. 33 56
      src/artis-star/kernel/dtss/Dynamics.hpp
  59. 45 60
      src/artis-star/kernel/dtss/GraphManager.hpp
  60. 23 34
      src/artis-star/kernel/dtss/Policy.hpp
  61. 34 57
      src/artis-star/kernel/dtss/Simulator.hpp
  62. 13 19
      src/artis-star/kernel/fddevs/Coordinator.hpp
  63. 35 60
      src/artis-star/kernel/fddevs/Dynamics.hpp
  64. 10 14
      src/artis-star/kernel/fddevs/GraphManager.hpp
  65. 32 55
      src/artis-star/kernel/fddevs/Simulator.hpp
  66. 9 17
      src/artis-star/kernel/pdevs/Context.hpp
  67. 40 59
      src/artis-star/kernel/pdevs/Coordinator.hpp
  68. 38 65
      src/artis-star/kernel/pdevs/Dynamics.hpp
  69. 40 60
      src/artis-star/kernel/pdevs/GraphManager.hpp
  70. 23 41
      src/artis-star/kernel/pdevs/Simulator.hpp
  71. 15 20
      src/artis-star/kernel/pdevs/mpi/Coordinator.hpp
  72. 12 17
      src/artis-star/kernel/pdevs/mpi/GraphManager.hpp
  73. 44 45
      src/artis-star/kernel/pdevs/mpi/LogicalProcessor.hpp
  74. 22 37
      src/artis-star/kernel/pdevs/mpi/ModelProxy.hpp
  75. 90 122
      src/artis-star/kernel/pdevs/multithreading/Coordinator.hpp
  76. 4 9
      src/artis-star/kernel/qss/Data.hpp
  77. 67 85
      src/artis-star/kernel/qss/Derivative.hpp
  78. 95 114
      src/artis-star/kernel/qss/Integrator.hpp
  79. 75 95
      src/artis-star/kernel/qss/MultiDerivative.hpp
  80. 98 123
      src/artis-star/kernel/qss/Quantifier.hpp
  81. 1 2
      src/artis-star/kernel/sss/CMakeLists.txt
  82. 59 0
      src/artis-star/kernel/sss/Context.hpp
  83. 35 53
      src/artis-star/kernel/sss/Coordinator.hpp
  84. 26 40
      src/artis-star/kernel/sss/Dynamics.hpp
  85. 35 46
      src/artis-star/kernel/sss/GraphManager.hpp
  86. 23 42
      src/artis-star/kernel/sss/Model.hpp
  87. 28 45
      src/artis-star/kernel/sss/Simulator.hpp
  88. 20 0
      tests/CMakeLists.txt
  89. 57 0
      tests/common_bag.cpp
  90. 63 0
      tests/common_context.cpp
  91. 92 0
      tests/common_observe.cpp
  92. 60 0
      tests/common_state.cpp
  93. 87 0
      tests/common_value.cpp
  94. 51 0
      tests/kernel_pdevs_simulator.cpp

+ 43 - 39
CMakeLists.txt

@@ -2,6 +2,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
 PROJECT(ARTIS_STAR CXX C)
 ENABLE_TESTING()
 
+SET(CMAKE_CXX_STANDARD 17)
+SET(CMAKE_CXX_STANDARD_REQUIRED ON)
+
 SET(ARTIS_MAJOR 1)
 SET(ARTIS_MINOR 0)
 SET(ARTIS_PATCH 0)
@@ -12,14 +15,14 @@ SET(ARTIS_NAME "artis-star")
 SET(ARTIS_NAME_VERSION "${ARTIS_NAME}-${ARTIS_VERSION}")
 SET(ARTIS_LOCALE_NAME "${ARTIS_NAME}-${ARTIS_MAJOR}-${ARTIS_MINOR}")
 IF ("${ARTIS_EXTRA}" STREQUAL "")
-  SET(ARTIS_COMPLETE "${ARTIS_MAJOR}.${ARTIS_MINOR}.${ARTIS_PATCH}")
+    SET(ARTIS_COMPLETE "${ARTIS_MAJOR}.${ARTIS_MINOR}.${ARTIS_PATCH}")
 ELSE ("${ARTIS_EXTRA}" STREQUAL "")
-  SET(ARTIS_COMPLETE "${ARTIS_MAJOR}.${ARTIS_MINOR}.${ARTIS_PATCH}-${ARTIS_EXTRA}")
+    SET(ARTIS_COMPLETE "${ARTIS_MAJOR}.${ARTIS_MINOR}.${ARTIS_PATCH}-${ARTIS_EXTRA}")
 ENDIF ("${ARTIS_EXTRA}" STREQUAL "")
 SET(ARTIS_NAME_COMPLETE "${ARTIS_NAME}-${ARTIS_COMPLETE}")
 
 #
- # Installation variables
+# Installation variables
 #
 
 SET(ARTIS_LIBRARY_DIRS "lib/artis-star-${ARTIS_VERSION_SHORT}")
@@ -29,33 +32,33 @@ SET(ARTIS_MANPAGE_PATH "share/man/man1")
 SET(ARTIS_SHARE_DIRS "share/artis-star-${ARTIS_VERSION_SHORT}")
 
 #
- # Append the library version information to the library target
- # properties.
+# Append the library version information to the library target
+# properties.
 #
 
-SET (ARTIS_LIBRARY_PROPERTIES VERSION 0)
-SET (ARTIS_APP_PROPERTIES SOVERSION "${ARTIS_MAJOR}.${ARTIS_MINOR}"
-  VERSION "${ARTIS_MAJOR}.${ARTIS_MINOR}")
+SET(ARTIS_LIBRARY_PROPERTIES VERSION 0)
+SET(ARTIS_APP_PROPERTIES SOVERSION "${ARTIS_MAJOR}.${ARTIS_MINOR}"
+        VERSION "${ARTIS_MAJOR}.${ARTIS_MINOR}")
 
 #
- # Debug mode
+# Debug mode
 #
 
 IF (CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)
-  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
-  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++11 -pthread")
-  IF (UNIX)
-    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
-    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
-  ENDIF (UNIX)
+    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
+    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++17 -pthread")
+    IF (UNIX)
+        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
+        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
+    ENDIF (UNIX)
 ENDIF (CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)
 
 if (CMAKE_BUILD_TYPE STREQUAL "")
-  SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build" FORCE)
+    SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build" FORCE)
 endif ()
 
 #
- # Modules
+# Modules
 #
 
 INCLUDE(CheckIncludeFileCXX)
@@ -64,17 +67,17 @@ INCLUDE(CheckLibraryExists)
 INCLUDE(CMakeDetermineCCompiler)
 
 #
- # Boost libraries
+# Boost libraries
 #
 
-set( Boost_USE_STATIC_LIBS OFF )
-set( Boost_USE_MULTITHREADED ON )
-set( Boost_USE_STATIC_RUNTIME OFF )
+set(Boost_USE_STATIC_LIBS OFF)
+set(Boost_USE_MULTITHREADED ON)
+set(Boost_USE_STATIC_RUNTIME OFF)
 
-find_package( Boost 1.71 COMPONENTS mpi timer serialization system )
+find_package(Boost 1.71 COMPONENTS mpi serialization unit_test_framework)
 
 #
- # Generate the config.h
+# Generate the config.h
 #
 
 CHECK_INCLUDE_FILE_CXX(cxxabi.h ARTIS_HAVE_GCC_ABI_DEMANGLE)
@@ -83,7 +86,7 @@ CHECK_INCLUDE_FILE_CXX(signal.h ARTIS_HAVE_SIGNAL)
 INCLUDE_DIRECTORIES(${ARTIS_STAR_BINARY_DIR})
 
 #
- # Generate the artis.pc pkg-config file.
+# Generate the artis.pc pkg-config file.
 #
 
 SET(ARTIS_PKGCONFIG_PREFIXPATH "${CMAKE_INSTALL_PREFIX}")
@@ -91,30 +94,31 @@ SET(ARTIS_PKGCONFIG_BOOSTINCLUDE_DIRS "${Boost_INCLUDE_DIRS}")
 SET(ARTIS_PKGCONFIG_LIBDIR "lib")
 
 CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/src/artis-star.pc.in
-  ${ARTIS_STAR_BINARY_DIR}/artis-star-${ARTIS_VERSION_SHORT}.pc @ONLY)
+        ${ARTIS_STAR_BINARY_DIR}/artis-star-${ARTIS_VERSION_SHORT}.pc @ONLY)
 INSTALL(FILES ${ARTIS_STAR_BINARY_DIR}/artis-star-${ARTIS_VERSION_SHORT}.pc
-  DESTINATION lib/pkgconfig)
+        DESTINATION lib/pkgconfig)
 
 #
- # Install the README
+# Install the README
 #
 
-IF(UNIX)
-  INSTALL(FILES "README" DESTINATION "${ARTIS_SHARE_DIRS}")
-  INSTALL(FILES "COPYING" DESTINATION "${ARTIS_SHARE_DIRS}")
-ELSE(UNIX)
-  INSTALL(FILES "README" DESTINATION "${ARTIS_SHARE_DIRS}" RENAME "Readme.txt")
-  INSTALL(FILES "COPYING" DESTINATION "${ARTIS_SHARE_DIRS}" RENAME "CopyRight.txt")
-ENDIF(UNIX)
+IF (UNIX)
+    INSTALL(FILES "README" DESTINATION "${ARTIS_SHARE_DIRS}")
+    INSTALL(FILES "COPYING" DESTINATION "${ARTIS_SHARE_DIRS}")
+ELSE (UNIX)
+    INSTALL(FILES "README" DESTINATION "${ARTIS_SHARE_DIRS}" RENAME "Readme.txt")
+    INSTALL(FILES "COPYING" DESTINATION "${ARTIS_SHARE_DIRS}" RENAME "CopyRight.txt")
+ENDIF (UNIX)
 
 #
- # Browse the src subdirectory
+# Browse the src subdirectory
 #
 
 ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(tests)
 
 #
- # Status
+# Status
 #
 
 MESSAGE(STATUS "- - - -")
@@ -122,11 +126,11 @@ MESSAGE(STATUS "${ARTIS_NAME_COMPLETE} configured successfully")
 MESSAGE(STATUS "Using ${CMAKE_INSTALL_PREFIX} for installation")
 MESSAGE(STATUS "Build type ${CMAKE_BUILD_TYPE}")
 IF (ARTIS_HAVE_GCC_ABI_DEMANGLE)
-  MESSAGE(STATUS "Build with GCC ABI Demangle...: yes")
+    MESSAGE(STATUS "Build with GCC ABI Demangle...: yes")
 ENDIF (ARTIS_HAVE_GCC_ABI_DEMANGLE)
 IF (ARTIS_HAVE_EXECINFO)
-  MESSAGE(STATUS "Build with execinfo.h.........: yes")
+    MESSAGE(STATUS "Build with execinfo.h.........: yes")
 ENDIF (ARTIS_HAVE_EXECINFO)
 IF (Boost_FOUND)
-  MESSAGE(STATUS "Build with boost..............: yes")
+    MESSAGE(STATUS "Build with boost..............: yes")
 ENDIF (Boost_FOUND)

+ 0 - 7
src/CMakeLists.txt

@@ -1,8 +1 @@
-#IF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
-#    message("TRACE on")
-#    add_definitions(-DWITH_TRACE)
-#ELSE ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
-#    message("TRACE off")
-#ENDIF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
-
 ADD_SUBDIRECTORY(artis-star)

+ 4 - 4
src/artis-star/common/CMakeLists.txt

@@ -6,15 +6,15 @@ INCLUDE_DIRECTORIES(
 LINK_DIRECTORIES(
         ${Boost_LIBRARY_DIRS})
 
-SET(COMMON_HPP Any.hpp Bag.hpp Coordinator.hpp ExternalEvent.hpp
-        GraphManager.hpp InternalEvent.hpp Links.hpp Macro.hpp Model.hpp
-        Node.hpp Parameters.hpp RootCoordinator.hpp Scheduler.hpp Simulator.hpp States.hpp
-        Value.hpp)
+SET(COMMON_HPP Coordinator.hpp GraphManager.hpp Links.hpp Model.hpp Node.hpp Parameters.hpp RootCoordinator.hpp
+        Scheduler.hpp Simulator.hpp)
 
 INSTALL(FILES ${COMMON_HPP} DESTINATION ${ARTIS_INCLUDE_DIRS}/common)
 
 ADD_SUBDIRECTORY(context)
+ADD_SUBDIRECTORY(event)
 ADD_SUBDIRECTORY(observer)
 ADD_SUBDIRECTORY(scheduler)
+ADD_SUBDIRECTORY(state)
 ADD_SUBDIRECTORY(time)
 ADD_SUBDIRECTORY(utils)

+ 27 - 46
src/artis-star/common/Coordinator.hpp

@@ -27,43 +27,38 @@
 #ifndef COMMON_COORDINATOR
 #define COMMON_COORDINATOR
 
-#include <artis-star/common/Bag.hpp>
-#include <artis-star/common/ExternalEvent.hpp>
+#include "artis-star/common/event/Bag.hpp"
+#include "artis-star/common/event/ExternalEvent.hpp"
 #include <artis-star/common/Links.hpp>
 #include <artis-star/common/Model.hpp>
 #include <artis-star/common/Node.hpp>
 
 #include <sstream>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-template<class Time>
+template<typename Time>
 class Model;
 
-template<class Time>
+template<typename Time>
 class GraphManager;
 
-template<class Time>
-class Coordinator : public virtual Model<Time>
-{
+template<typename Time>
+class Coordinator : public virtual Model<Time> {
 public :
   Coordinator(const std::string &name)
-      : Model<Time>(name)
-  {}
+    : Model<Time>(name) {}
 
-  virtual ~Coordinator()
-  {}
+  virtual ~Coordinator() {}
 
   virtual GraphManager<Time> &get_graph_manager() = 0;
 
   virtual const GraphManager<Time> &get_graph_manager() const = 0;
 
-  virtual const Model<Time> *get_submodel(unsigned int index) const
-  {
+  virtual const Model<Time> *get_sub_model(unsigned int index) const {
     const GraphManager<Time> &graph_manager = get_graph_manager();
     typename common::ModelMap<Time>::const_iterator it = graph_manager.child_map().find(
-        index);
+      index);
 
     if (it != graph_manager.child_map().end()) {
       return it->second;
@@ -72,11 +67,10 @@ public :
     }
   }
 
-  virtual const Model<Time> *get_submodel(unsigned int index, unsigned int rank) const
-  {
+  virtual const Model<Time> *get_sub_model(unsigned int index, unsigned int rank) const {
     const GraphManager<Time> &graph_manager = get_graph_manager();
     typename common::ModelsMap<Time>::const_iterator it = graph_manager.children_map().find(
-        index);
+      index);
 
     if (it != graph_manager.children_map().end() and it->second.size() > rank) {
       return it->second.at(rank);
@@ -85,11 +79,10 @@ public :
     }
   }
 
-  virtual unsigned int get_submodel_number(unsigned int index) const
-  {
+  virtual unsigned int get_sub_model_number(unsigned int index) const {
     const GraphManager<Time> &graph_manager = get_graph_manager();
     typename common::ModelsMap<Time>::const_iterator it = graph_manager.children_map().find(
-        index);
+      index);
 
     if (it != graph_manager.children_map().end()) {
       return it->second.size();
@@ -98,11 +91,9 @@ public :
     }
   }
 
-  void input_port(common::Port p)
-  { Coordinator<Time>::add_in_port(p); }
+  void input_port(common::Port p) { Coordinator<Time>::add_in_port(p); }
 
-  void input_ports(std::initializer_list<common::Port> list)
-  {
+  void input_ports(std::initializer_list<common::Port> list) {
     for (typename std::initializer_list<common::Port>::iterator it = list.begin();
          it != list.end();
          ++it) {
@@ -110,14 +101,11 @@ public :
     }
   }
 
-  virtual bool is_atomic() const
-  { return false; }
+  virtual bool is_atomic() const { return false; }
 
-  void output_port(common::Port p)
-  { Coordinator<Time>::add_out_port(p); }
+  void output_port(common::Port p) { Coordinator<Time>::add_out_port(p); }
 
-  void output_ports(std::initializer_list<common::Port> list)
-  {
+  void output_ports(std::initializer_list<common::Port> list) {
     for (typename std::initializer_list<common::Port>::iterator it = list.begin();
          it != list.end();
          ++it) {
@@ -125,25 +113,21 @@ public :
     }
   }
 
-  virtual void remove_model(const typename Time::type &t, common::Model<Time> *model)
-  {
+  virtual void remove_model(const typename Time::type &t, common::Model<Time> *model) {
     model->finish(t);
   }
 
-  void restore(const common::context::State<Time> &state)
-  {
+  void restore(const common::context::State<Time> &state) {
     Model<Time>::restore(state);
     get_graph_manager().restore(state);
   }
 
-  void save(common::context::State<Time> &state) const
-  {
+  void save(common::context::State<Time> &state) const {
     Model<Time>::save(state);
     get_graph_manager().save(state);
   }
 
-  virtual std::string to_string(int /* level */) const
-  {
+  virtual std::string to_string(int /* level */) const {
     std::ostringstream ss;
 
     ss << "Coordinator " << Coordinator<Time>::get_name();
@@ -153,15 +137,13 @@ public :
 // DEVS methods
   virtual void finish(const typename Time::type &t) = 0;
 
-  virtual common::Value
-  observe(const typename Time::type &t, unsigned int index) const = 0;
+  virtual common::event::Value observe(const typename Time::type &t, unsigned int index) const = 0;
 
   virtual void output(const typename Time::type &t) = 0;
 
-  virtual void
-  post_event(const typename Time::type &t, const common::ExternalEvent<Time> &event) = 0;
+  virtual void post_event(const typename Time::type &t, const common::event::ExternalEvent<Time> &event) = 0;
 
-  virtual typename Time::type dispatch_events(const common::Bag<Time> &bag,
+  virtual typename Time::type dispatch_events(const common::event::Bag<Time> &bag,
                                               const typename Time::type &t) = 0;
 
   virtual typename Time::type start(const typename Time::type &t) = 0;
@@ -169,7 +151,6 @@ public :
   virtual typename Time::type transition(const typename Time::type &t) = 0;
 };
 
-}
 } // namespace artis common
 
 #endif

+ 20 - 35
src/artis-star/common/GraphManager.hpp

@@ -35,30 +35,24 @@
 
 #include <sstream>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-template<class Time>
-class GraphManager
-{
+template<typename Time>
+class GraphManager {
 public:
   GraphManager(common::Coordinator<Time> *coordinator)
-      :
-      _coordinator(coordinator)
-  {}
+    :
+    _coordinator(coordinator) {}
 
-  virtual ~GraphManager()
-  {}
+  virtual ~GraphManager() {}
 
-  virtual void add_child(unsigned int index, common::Model<Time> *child)
-  {
+  virtual void add_child(unsigned int index, common::Model<Time> *child) {
     _children.push_back(child);
     _child_map[index] = child;
     child->set_parent(_coordinator);
   }
 
-  virtual void add_children(unsigned int index, common::Model<Time> *child)
-  {
+  virtual void add_children(unsigned int index, common::Model<Time> *child) {
     _children.push_back(child);
     if (_children_map.find(index) == _children_map.end()) {
       _children_map[index] = Models<Time>();
@@ -67,23 +61,17 @@ public:
     child->set_parent(_coordinator);
   }
 
-  const common::Models<Time> &children() const
-  { return _children; }
+  const common::Models<Time> &children() const { return _children; }
 
-  const common::ModelMap<Time> &child_map() const
-  { return _child_map; }
+  const common::ModelMap<Time> &child_map() const { return _child_map; }
 
-  common::Model<Time> *child_map(size_t index) const
-  { return _child_map.at(index); }
+  common::Model<Time> *child_map(size_t index) const { return _child_map.at(index); }
 
-  const common::ModelsMap<Time> &children_map() const
-  { return _children_map; }
+  const common::ModelsMap<Time> &children_map() const { return _children_map; }
 
-  common::Coordinator<Time> *coordinator() const
-  { return _coordinator; }
+  common::Coordinator<Time> *coordinator() const { return _coordinator; }
 
-  virtual void remove_child(unsigned int index)
-  {
+  virtual void remove_child(unsigned int index) {
     common::Model<Time> *child = _child_map[index];
 
     _children.erase(std::find(_children.begin(), _children.end(), child));
@@ -91,22 +79,20 @@ public:
     _child_map.erase(index);
   }
 
-  void restore(const common::context::State<Time> &state)
-  {
+  void restore(const common::context::State<Time> &state) {
     for (typename common::ModelMap<Time>::iterator it = _child_map.begin(); it != _child_map.end();
          ++it) {
-      it->second->restore(state.get_substate(it->first));
+      it->second->restore(state.get_sub_state(it->first));
     }
   }
 
-  void save(common::context::State<Time> &state) const
-  {
+  void save(common::context::State<Time> &state) const {
     for (typename common::ModelMap<Time>::const_iterator it = _child_map.begin();
          it != _child_map.end(); ++it) {
-      context::State<Time> substate;
+      context::State <Time> sub_state;
 
-      it->second->save(substate);
-      state.add_substate(it->first, substate);
+      it->second->save(sub_state);
+      state.add_sub_state(it->first, sub_state);
     }
   }
 
@@ -117,7 +103,6 @@ protected:
   common::Coordinator<Time> *_coordinator;
 };
 
-}
 } // namespace artis common
 
 #endif

+ 27 - 44
src/artis-star/common/Links.hpp

@@ -33,69 +33,57 @@
 #include <map>
 #include <sstream>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-template<class Time>
+template<typename Time>
 class Node;
 
-template<class Time>
-class Links : public std::multimap<Node<Time>, Node<Time> >
-{
-  typedef std::multimap<Node<Time>, Node<Time> > type;
+template<typename Time>
+class Links : public std::multimap<Node<Time>, Node<Time> > {
+  typedef std::multimap<Node<Time>, Node<Time>> type;
 
 public:
   typedef std::pair<
-      typename Links<Time>::const_iterator,
-      typename Links<Time>::const_iterator
+    typename Links<Time>::const_iterator,
+    typename Links<Time>::const_iterator
   > Result;
 
-  Links()
-  {}
+  Links() = default;
 
-  virtual ~Links()
-  {}
+  virtual ~Links() = default;
 
   void add(Model<Time> *out_model, unsigned int out_port_index,
-           Model<Time> *in_model, unsigned int in_port_index)
-  {
-    type::insert(std::pair<Node<Time>, Node<Time> >(
-        Node<Time>(out_model, out_port_index),
-        Node<Time>(in_model, in_port_index)));
+           Model<Time> *in_model, unsigned int in_port_index) {
+    type::insert(std::make_pair(Node<Time>(out_model, out_port_index), Node<Time>(in_model, in_port_index)));
   }
 
-  bool exist(Model<Time> *out_model,
-             unsigned int out_port_index,
-             Model<Time> *in_model,
-             unsigned int in_port_index) const
-  {
+  bool exist(Model<Time> *out_model, unsigned int out_port_index,
+             Model<Time> *in_model, unsigned int in_port_index) const {
     std::pair<typename Links<Time>::const_iterator,
-              typename Links<Time>::const_iterator> it =
-        type::equal_range(Node<Time>(out_model, out_port_index));
+      typename Links<Time>::const_iterator> it =
+      type::equal_range(Node<Time>(out_model, out_port_index));
     typename Links<Time>::const_iterator it2 = it.first;
     bool found = false;
 
     while (not found and it2 != it.second) {
       found = it2->second == Node<Time>(
-          in_model, in_port_index);
+        in_model, in_port_index);
       ++it2;
     }
     return found;
   }
 
-  typename Links<Time>::const_iterator
-  find(Model<Time> *out_model, unsigned int out_port_index,
-       Model<Time> *in_model, unsigned int in_port_index) const
-  {
+  typename Links<Time>::const_iterator find(Model<Time> *out_model, unsigned int out_port_index,
+                                            Model<Time> *in_model, unsigned int in_port_index) const {
     std::pair<typename Links<Time>::const_iterator,
-              typename Links<Time>::const_iterator> it =
-        type::equal_range(Node<Time>(out_model, out_port_index));
+      typename Links<Time>::const_iterator> it =
+      type::equal_range(Node<Time>(out_model, out_port_index));
     typename Links<Time>::const_iterator it2 = it.first;
     bool found = false;
 
     while (not found and it2 != it.second) {
       found = it2->second == Node<Time>(
-          in_model, in_port_index);
+        in_model, in_port_index);
       if (not found) {
         ++it2;
       }
@@ -103,22 +91,19 @@ public:
     return it2;
   }
 
-  Links::Result find(Model<Time> *out_model, unsigned int out_port_index) const
-  {
+  Links::Result find(Model<Time> *out_model, unsigned int out_port_index) const {
     return type::equal_range(common::Node<Time>(out_model, out_port_index));
   }
 
   void remove(common::Model<Time> *src_model, unsigned int src_port_index,
-              common::Model<Time> *dst_model, unsigned int dst_port_index)
-  {
+              common::Model<Time> *dst_model, unsigned int dst_port_index) {
     typename Links<Time>::const_iterator result = find(src_model, src_port_index,
                                                        dst_model, dst_port_index);
 
     this->erase(result);
   }
 
-  void remove_links(common::Model<Time> *model)
-  {
+  void remove_links(common::Model<Time> *model) {
     typename Links<Time>::iterator it = this->begin();
 
     while (it != this->end()) {
@@ -131,8 +116,7 @@ public:
     }
   }
 
-  std::string to_string(int level = 0) const
-  {
+  std::string to_string(int level = 0) const {
     std::stringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "Links:" << std::endl;
@@ -141,17 +125,16 @@ public:
       ss << common::String::make_spaces((level + 1) * 2)
          << it->first.get_model()->get_name() << "::"
          << it->first.get_model()->get_out_port_name(
-             it->first.get_port_index())
+           it->first.get_port_index())
          << " -> "
          << it->second.get_model()->get_name() << "::"
          << it->second.get_model()->get_out_port_name(
-             it->second.get_port_index()) << std::endl;
+           it->second.get_port_index()) << std::endl;
     }
     return ss.str();
   }
 };
 
-}
 } // namespace artis common
 
 #endif

+ 77 - 130
src/artis-star/common/Model.hpp

@@ -27,11 +27,11 @@
 #ifndef COMMON_MODEL
 #define COMMON_MODEL
 
-#include <artis-star/common/Bag.hpp>
-#include <artis-star/common/ExternalEvent.hpp>
-#include <artis-star/common/InternalEvent.hpp>
+#include "artis-star/common/event/Bag.hpp"
+#include "artis-star/common/event/ExternalEvent.hpp"
+#include "artis-star/common/event/InternalEvent.hpp"
 #include <artis-star/common/Scheduler.hpp>
-#include <artis-star/common/Value.hpp>
+#include "artis-star/common/event/Value.hpp"
 #include <artis-star/common/context/State.hpp>
 
 #include <algorithm>
@@ -39,20 +39,20 @@
 #include <map>
 #include <sstream>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-template<class Time>
+namespace event {
+template<typename Time>
 class ExternalEvent;
 
-template<class Time>
+template<typename Time>
 class InternalEvent;
 
-template<class Time>
+template<typename Time>
 class Bag;
+}
 
-struct Port
-{
+struct Port {
   unsigned int index;
   std::string name;
 };
@@ -60,41 +60,35 @@ struct Port
 typedef std::vector<unsigned int> Ports;
 typedef std::map<unsigned int, std::string> PortMap;
 
-template<class Time>
-class Model
-{
+template<typename Time>
+class Model {
 public:
   Model(const std::string &name)
-      :
-      _tl(0), _tn(0), _parent(0), _name(name), _inputs(0)
-  {}
+    :
+    _tl(0), _tn(0), _parent(0), _name(name), _inputs(0) {}
 
-  virtual ~Model()
-  {
+  virtual ~Model() {
     if (_inputs) {
       delete _inputs;
     }
   }
 
   // structure
-  void add_in_port(const Port &port)
-  {
+  void add_in_port(const Port &port) {
     assert(not exist_in_port(port.index));
 
     _in_ports.push_back(port.index);
     _in_port_map[port.index] = port.name;
   }
 
-  void add_out_port(const Port &port)
-  {
+  void add_out_port(const Port &port) {
     assert(not exist_out_port(port.index));
 
     _out_ports.push_back(port.index);
     _out_port_map[port.index] = port.name;
   }
 
-  void delete_in_port(const Port &port)
-  {
+  void delete_in_port(const Port &port) {
     assert(not exist_in_port(port.index));
 
     _in_ports.erase(std::find(_in_ports.begin(), _in_ports.end(),
@@ -102,8 +96,7 @@ public:
     _in_port_map.erase(port.index);
   }
 
-  void delete_out_port(const Port &port)
-  {
+  void delete_out_port(const Port &port) {
     assert(not exist_out_port(port.index));
 
     _out_ports.erase(std::find(_out_ports.begin(), _out_ports.end(),
@@ -111,18 +104,15 @@ public:
     _out_port_map.erase(port.index);
   }
 
-  bool exist_in_port(unsigned int port_index) const
-  {
+  bool exist_in_port(unsigned int port_index) const {
     return _in_port_map.find(port_index) != _in_port_map.end();
   }
 
-  bool exist_out_port(unsigned int port_index) const
-  {
+  bool exist_out_port(unsigned int port_index) const {
     return _out_port_map.find(port_index) != _out_port_map.end();
   }
 
-  std::string get_full_name() const
-  {
+  std::string get_full_name() const {
     if (_parent) {
       return _parent->get_full_name() + ":" + _name;
     } else {
@@ -130,34 +120,27 @@ public:
     }
   }
 
-  std::string get_in_port_name(unsigned int port_index) const
-  {
+  std::string get_in_port_name(unsigned int port_index) const {
     assert(exist_in_port(port_index));
 
     return _in_port_map.find(port_index)->second;
   }
 
-  size_t get_in_port_number() const
-  { return _in_port_map.size(); }
+  size_t get_in_port_number() const { return _in_port_map.size(); }
 
-  std::string get_out_port_name(unsigned int port_index) const
-  {
+  std::string get_out_port_name(unsigned int port_index) const {
     assert(exist_out_port(port_index));
 
     return _out_port_map.find(port_index)->second;
   }
 
-  size_t get_out_port_number() const
-  { return _out_port_map.size(); }
+  size_t get_out_port_number() const { return _out_port_map.size(); }
 
-  const std::string &get_name() const
-  { return _name; }
+  const std::string &get_name() const { return _name; }
 
-  Model<Time> *get_parent() const
-  { return _parent; }
+  Model<Time> *get_parent() const { return _parent; }
 
-  virtual const Model<Time> *get_submodel(unsigned int index) const
-  {
+  virtual const Model<Time> *get_sub_model(unsigned int index) const {
     (void) index;
 
     assert(false);
@@ -165,9 +148,8 @@ public:
     return nullptr;
   }
 
-  virtual const Model<Time> *get_submodel(unsigned int index,
-                                          unsigned int rank) const
-  {
+  virtual const Model<Time> *get_sub_model(unsigned int index,
+                                           unsigned int rank) const {
     (void) index;
     (void) rank;
 
@@ -176,8 +158,7 @@ public:
     return nullptr;
   }
 
-  virtual unsigned int get_submodel_number(unsigned int index) const
-  {
+  virtual unsigned int get_sub_model_number(unsigned int index) const {
     (void) index;
 
     assert(false);
@@ -187,11 +168,9 @@ public:
 
   virtual bool is_atomic() const = 0;
 
-  virtual bool is_remote() const
-  { return false; }
+  virtual bool is_remote() const { return false; }
 
-  virtual std::string observable_name(unsigned int observable_index) const
-  {
+  virtual std::string observable_name(unsigned int observable_index) const {
     (void) observable_index;
 
     assert(false);
@@ -199,89 +178,76 @@ public:
     return std::string();
   }
 
-  std::string path() const
-  {
+  std::string path() const {
     return (_parent != nullptr ? _parent->path() : "") + ":" + get_name();
   }
 
-  virtual void restore(const common::context::State<Time> &state)
-  {
+  virtual void restore(const common::context::State<Time> &state) {
     _tl = state.last_time();
     _tn = state.next_time();
   }
 
-  virtual void save(common::context::State<Time> &state) const
-  {
+  virtual void save(common::context::State<Time> &state) const {
     state.last_time(_tl);
     state.next_time(_tn);
   }
 
-  void set_parent(Model<Time> *parent)
-  { _parent = parent; }
+  void set_parent(Model<Time> *parent) { _parent = parent; }
 
   virtual std::string to_string(int /* level */) const = 0;
 
   // event
-  void add_event(const common::ExternalEvent<Time> &message)
-  {
+  void add_event(const common::event::ExternalEvent<Time> &message) {
     if (_inputs == 0) {
-      _inputs = new Bag<Time>;
+      _inputs = new common::event::Bag<Time>;
     }
     _inputs->push_back(message);
   }
 
-  void clear_bag()
-  {
+  void clear_bag() {
     if (_inputs) {
       delete _inputs;
       _inputs = 0;
     }
   }
 
-  unsigned int event_number() const
-  {
+  unsigned int event_number() const {
     return _inputs ? _inputs->size() : 0;
   }
 
-  const common::Bag<Time> &get_bag()
-  {
+  const common::event::Bag<Time> &get_bag() {
     if (_inputs == 0) {
-      _inputs = new Bag<Time>;
+      _inputs = new common::event::Bag<Time>;
     }
     return *_inputs;
   }
 
   // time
-  typename Time::type get_tl() const
-  { return _tl; }
+  typename Time::type get_tl() const { return _tl; }
 
-  typename Time::type get_tn() const
-  { return _tn; }
+  typename Time::type get_tn() const { return _tn; }
 
   // devs methods
-  virtual void finish(const typename Time::type &t) = 0;
+  virtual void finish(const typename Time::type & /* t */) = 0;
 
-  virtual common::Value observe(const typename Time::type &t,
-                                unsigned int index) const = 0;
+  virtual common::event::Value observe(const typename Time::type & /* t */,
+                                       unsigned int /* index */) const = 0;
 
-  virtual void output(const typename Time::type &t) = 0;
+  virtual void output(const typename Time::type & /* t */) = 0;
 
-  virtual void post_event(const typename Time::type &t,
-                          const common::ExternalEvent<Time> &event) = 0;
+  virtual void post_event(const typename Time::type & /* t */,
+                          const common::event::ExternalEvent<Time> & /* event */) = 0;
 
-  virtual typename Time::type start(const typename Time::type &t) = 0;
+  virtual typename Time::type start(const typename Time::type & /* t */) = 0;
 
-  virtual typename Time::type transition(const typename Time::type &t) = 0;
+  virtual typename Time::type transition(const typename Time::type & /* t */) = 0;
 
-  virtual typename Time::type lookahead(const typename Time::type &t) const
-  { return t; }
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
   // scheduler
-  void handle(SchedulerHandle handle)
-  { _handle.handle(handle); }
+  void handle(SchedulerHandle handle) { _handle.handle(handle); }
 
-  const SchedulerHandle &handle() const
-  { return _handle.handle(); }
+  const SchedulerHandle &handle() const { return _handle.handle(); }
 
 protected:
   typename Time::type _tl;
@@ -295,28 +261,22 @@ private :
   Ports _out_ports;
   PortMap _out_port_map;
 
-  Bag<Time> *_inputs;
+  common::event::Bag<Time> *_inputs;
   SchedulerHandle _handle;
 };
 
-template<class Time>
-class ModelMap : public std::map<unsigned int, Model<Time> *>
-{
+template<typename Time>
+class ModelMap : public std::map<unsigned int, Model<Time> *> {
 public:
-  ModelMap()
-  {}
+  ModelMap() {}
 
-  virtual ~ModelMap()
-  {}
+  virtual ~ModelMap() {}
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::ostringstream ss;
 
     ss << "{ ";
-    for (typename ModelMap<Time>::const_iterator it =
-        ModelMap<Time>::begin();
-         it != ModelMap<Time>::end(); ++it) {
+    for (typename ModelMap<Time>::const_iterator it = ModelMap<Time>::begin(); it != ModelMap<Time>::end(); ++it) {
       ss << it->second->get_name() << " ";
     }
     ss << "}";
@@ -324,24 +284,18 @@ public:
   }
 };
 
-template<class Time>
-class Models : public std::vector<Model<Time> *>
-{
+template<typename Time>
+class Models : public std::vector<Model<Time> *> {
 public:
-  Models()
-  {}
+  Models() {}
 
-  virtual ~Models()
-  {}
+  virtual ~Models() {}
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::ostringstream ss;
 
     ss << "{ ";
-    for (typename Models<Time>::const_iterator it =
-        Models<Time>::begin();
-         it != Models<Time>::end(); ++it) {
+    for (typename Models<Time>::const_iterator it = Models<Time>::begin(); it != Models<Time>::end(); ++it) {
       ss << (*it)->get_name() << " ";
     }
     ss << "}";
@@ -349,24 +303,18 @@ public:
   }
 };
 
-template<class Time>
-class ModelsMap : public std::map<unsigned int, Models<Time> >
-{
+template<typename Time>
+class ModelsMap : public std::map<unsigned int, Models<Time> > {
 public:
-  ModelsMap()
-  {}
+  ModelsMap() {}
 
-  virtual ~ModelsMap()
-  {}
+  virtual ~ModelsMap() {}
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::ostringstream ss;
 
     ss << "{ ";
-    for (typename ModelsMap<Time>::const_iterator it =
-        ModelsMap<Time>::begin();
-         it != ModelsMap<Time>::end(); ++it) {
+    for (typename ModelsMap<Time>::const_iterator it = ModelsMap<Time>::begin(); it != ModelsMap<Time>::end(); ++it) {
       ss << it->second.to_string() << " ";
     }
     ss << "}";
@@ -374,7 +322,6 @@ public:
   }
 };
 
-}
 } // namespace artis common
 
 #endif

+ 12 - 22
src/artis-star/common/Node.hpp

@@ -31,45 +31,36 @@
 
 #include <string>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-template<class Time>
+template<typename Time>
 class Model;
 
-template<class Time>
-class Node
-{
+template<typename Time>
+class Node {
 public :
   Node(Model<Time> *model, unsigned int port_index)
-      : _model(model), _port_index(port_index)
-  {
+    : _model(model), _port_index(port_index) {
     _id = std::hash<std::string>()(model->get_name() +
-        std::to_string(port_index));
+                                   std::to_string(port_index));
   }
 
   Node(const Node<Time> &other)
-      : _model(other._model), _port_index(other._port_index), _id(other._id)
-  {}
+    : _model(other._model), _port_index(other._port_index), _id(other._id) {}
 
-  virtual ~Node()
-  {}
+  virtual ~Node() {}
 
-  bool operator<(const Node<Time> &o) const
-  {
+  bool operator<(const Node<Time> &o) const {
     return _id < o._id;
   }
 
-  bool operator==(const Node<Time> &o) const
-  {
+  bool operator==(const Node<Time> &o) const {
     return _id == o._id;
   }
 
-  unsigned int get_port_index() const
-  { return _port_index; }
+  unsigned int get_port_index() const { return _port_index; }
 
-  Model<Time> *get_model() const
-  { return _model; }
+  Model<Time> *get_model() const { return _model; }
 
 private :
   Model<Time> *_model;
@@ -77,7 +68,6 @@ private :
   int _id;
 };
 
-}
 } // namespace artis common
 
 #endif

+ 2 - 8
src/artis-star/common/Parameters.hpp

@@ -27,17 +27,11 @@
 #ifndef COMMON_PARAMETERS
 #define COMMON_PARAMETERS
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-class NoParameters
-{
-public:
-  NoParameters()
-  {}
+struct NoParameters {
 };
 
-}
 } // namespace artis common
 
 #endif

+ 19 - 32
src/artis-star/common/RootCoordinator.hpp

@@ -35,50 +35,41 @@
 #include <sstream>
 #include <string>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-template<class Time, class Coordinator>
-class RootCoordinator
-{
+template<typename Time, typename Coordinator>
+class RootCoordinator {
 public :
   RootCoordinator(const common::context::Context<Time> &context,
                   const std::string &root_name,
                   const typename Coordinator::parameters_type &parameters,
                   const typename Coordinator::graph_parameters_type &graph_parameters)
-      :
-      _root(root_name, parameters, graph_parameters), _observer(&_root),
-      _t_max(context.end()), _tn(context.begin())
-  {}
+    :
+    _root(root_name, parameters, graph_parameters), _observer(&_root),
+    _t_max(context.end()), _tn(context.begin()) {}
 
   RootCoordinator(const common::context::Context<Time> &context,
                   const std::string &root_name,
                   const typename Coordinator::parameters_type &parameters)
-      :
-      _root(root_name, parameters, NoParameters()), _observer(&_root),
-      _t_max(context.end()), _tn(context.begin())
-  {}
+    :
+    _root(root_name, parameters, NoParameters()), _observer(&_root),
+    _t_max(context.end()), _tn(context.begin()) {}
 
   RootCoordinator(const common::context::Context<Time> &context,
                   const std::string &root_name)
-      :
-      _root(root_name, NoParameters(), NoParameters()), _observer(&_root),
-      _t_max(context.end()), _tn(context.begin())
-  {}
+    :
+    _root(root_name, NoParameters(), NoParameters()), _observer(&_root),
+    _t_max(context.end()), _tn(context.begin()) {}
 
-  virtual ~RootCoordinator()
-  {}
+  virtual ~RootCoordinator() {}
 
-  void attachView(const std::string &name, observer::View<Time> *view)
-  {
+  void attachView(const std::string &name, observer::View <Time> *view) {
     _observer.attachView(name, view);
   }
 
-  const observer::Observer<Time> &observer() const
-  { return _observer; }
+  const observer::Observer <Time> &observer() const { return _observer; }
 
-  void run(const common::context::Context<Time> &context)
-  {
+  void run(const common::context::Context<Time> &context) {
 //             DSDE synchroniser
 //               When receive (START,t)
 //                  send (START,0) to child
@@ -110,17 +101,14 @@ public :
     }
   }
 
-  void save(common::context::Context<Time> &context) const
-  {
+  void save(common::context::Context<Time> &context) const {
     _root.save(context.state());
     context.saved();
   }
 
-  void switch_to_timed_observer(double step)
-  { _observer.switch_to_timed_observer(step); }
+  void switch_to_timed_observer(double step) { _observer.switch_to_timed_observer(step); }
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::ostringstream ss;
 
     ss << _root.to_string(0);
@@ -134,7 +122,6 @@ private :
   typename Time::type _tn;
 };
 
-}
 } // namespace artis common
 
 #endif

+ 7 - 14
src/artis-star/common/Scheduler.hpp

@@ -30,33 +30,26 @@
 #include <artis-star/common/scheduler/HeapScheduler.hpp>
 #include <artis-star/common/time/DoubleTime.hpp>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
 struct SchedulerHandle;
 
 typedef typename artis::common::scheduler::HeapScheduler<
-    common::DoubleTime, SchedulerHandle>::type SchedulerType;
+  common::DoubleTime, SchedulerHandle>::type SchedulerType;
 
-struct SchedulerHandle
-{
-  SchedulerHandle()
-  {}
+struct SchedulerHandle {
+  SchedulerHandle() {}
 
   SchedulerHandle(const SchedulerType::handle_type &handle)
-      : _handle(handle)
-  {}
+    : _handle(handle) {}
 
-  const SchedulerHandle &handle() const
-  { return *this; }
+  const SchedulerHandle &handle() const { return *this; }
 
-  void handle(const SchedulerHandle &handle)
-  { _handle = handle._handle; }
+  void handle(const SchedulerHandle &handle) { _handle = handle._handle; }
 
   SchedulerType::handle_type _handle;
 };
 
-}
 } // namespace artis common
 
 #endif

+ 9 - 18
src/artis-star/common/Simulator.hpp

@@ -31,25 +31,19 @@
 
 #include <sstream>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-template<class Time>
-class Simulator : public virtual Model<Time>
-{
+template<typename Time>
+class Simulator : public virtual Model<Time> {
 public :
   Simulator(const std::string &name)
-      : Model<Time>(name)
-  {}
+    : Model<Time>(name) {}
 
-  virtual ~Simulator()
-  {}
+  virtual ~Simulator() = default;
 
-  virtual bool is_atomic() const
-  { return true; }
+  virtual bool is_atomic() const { return true; }
 
-  virtual std::string to_string(int /* level */) const
-  {
+  virtual std::string to_string(int /* level */) const {
     std::ostringstream ss;
 
     ss << "Simulator " << Simulator<Time>::get_name();
@@ -59,20 +53,17 @@ public :
 // DEVS methods
   virtual void finish(const typename Time::type &t) = 0;
 
-  virtual common::Value observe(const typename Time::type &t,
-                                unsigned int index) const = 0;
+  virtual common::event::Value observe(const typename Time::type &t, unsigned int index) const = 0;
 
   virtual void output(const typename Time::type &t) = 0;
 
-  virtual void post_event(const typename Time::type &t,
-                          const common::ExternalEvent<Time> &event) = 0;
+  virtual void post_event(const typename Time::type &t, const common::event::ExternalEvent<Time> &event) = 0;
 
   virtual typename Time::type start(const typename Time::type &t) = 0;
 
   virtual typename Time::type transition(const typename Time::type &t) = 0;
 };
 
-}
 } // namespace artis common
 
 #endif

+ 0 - 278
src/artis-star/common/Value.hpp

@@ -1,278 +0,0 @@
-/**
- * @file common/Value.hpp
- * @author The ARTIS Development Team
- * See the AUTHORS or Authors.txt file
- */
-
-/*
- * ARTIS - the multimodeling and simulation environment
- * This file is a part of the ARTIS environment
- *
- * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef COMMON_VALUE
-#define COMMON_VALUE
-
-#include <boost/serialization/serialization.hpp>
-#include <boost/serialization/array.hpp>
-
-#include <cassert>
-#include <cstring>
-#include <numeric>
-#include <string>
-#include <typeinfo>
-#include <vector>
-
-namespace artis {
-namespace common {
-
-class Value
-{
-public:
-  Value()
-      : _content(nullptr), _size(0)
-  {}
-
-  template<typename T>
-  Value(const T &value)
-  { assign(&value, sizeof(T), typeid(T).hash_code()); }
-
-  template<typename T>
-  Value(const T *value, size_t size)
-  { assign(value, sizeof(T) * size, typeid(T *).hash_code()); }
-
-  template<typename T>
-  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()); }
-
-  Value(const char *value, unsigned int size)
-  { assign(value, size * sizeof(char), typeid(char *).hash_code()); }
-
-  Value(const Value &value)
-  {
-    if (value._content) {
-      assign(value._content, value._size, value._type_id);
-    } else {
-      _content = nullptr;
-      _size = 0;
-      _type_id = 0;
-    }
-  }
-
-  virtual ~Value()
-  {
-    if (_content != nullptr)
-      delete[] _content;
-  }
-
-  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
-  {
-    assert(_type_id == typeid(T).hash_code());
-
-    value = *(T *) (_content);
-  }
-
-  template<typename T>
-  void operator()(T *&value) const
-  {
-    assert(_type_id == typeid(T *).hash_code());
-
-    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);
-
-    for (size_t i = 0; i < size; ++i) {
-      value.push_back(((T *) (_content))[i]);
-    }
-  }
-
-  Value &operator=(const Value &value)
-  {
-    if (_content != nullptr) {
-      delete _content;
-    }
-    if (value._content) {
-      assign(value._content, value._size, value._type_id);
-    } else {
-      _content = nullptr;
-      _size = 0;
-      _type_id = 0;
-    }
-    return *this;
-  }
-
-  template<typename Z>
-  size_t size() const
-  {
-
-    assert(is_type<Z*>());
-
-    return _size / sizeof(Z);
-  }
-
-  std::string to_string() const
-  {
-    if (is_null()) {
-      return "<null>";
-    } else if (is_type<double>()) {
-      double v;
-
-      operator()(v);
-      return std::to_string(v);
-    } else if (is_type<int>()) {
-      int v;
-
-      operator()(v);
-      return std::to_string(v);
-    } else if (is_type<unsigned int>()) {
-      unsigned int v;
-
-      operator()(v);
-      return std::to_string(v);
-    } else if (is_type<bool>()) {
-      bool v;
-
-      operator()(v);
-      return v ? "true" : "false";
-    } else if (is_type<char>()) {
-      char v;
-
-      operator()(v);
-      return std::to_string(v);
-    } else if (is_type<double *>()) {
-      double *v;
-      std::string str;
-      size_t size = _size / sizeof(double);
-
-      operator()(v);
-      for (size_t i = 0; i < size; ++i) {
-        str += std::to_string(v[i]) + std::string(" ");
-      }
-      return str;
-    } else if (is_type<int *>()) {
-      int *v;
-      std::string str;
-      size_t size = _size / sizeof(int);
-
-      operator()(v);
-      for (size_t i = 0; i < size; ++i) {
-        str += std::to_string(v[i]) + std::string(" ");
-      }
-      return str;
-    } else if (is_type<unsigned int *>()) {
-      unsigned int *v;
-      std::string str;
-      size_t size = _size / sizeof(unsigned int);
-
-      operator()(v);
-      for (size_t i = 0; i < size; ++i) {
-        str += std::to_string(v[i]) + std::string(" ");
-      }
-      return str;
-    } else if (is_type<bool *>()) {
-      bool *v;
-      std::string str;
-      size_t size = _size / sizeof(bool);
-
-      operator()(v);
-      for (size_t i = 0; i < size; ++i) {
-        str += std::to_string(v[i]) + std::string(" ");
-      }
-      return str;
-    } else if (is_type<char *>()) {
-      char *v;
-
-      operator()(v);
-      return std::string(v, _size / sizeof(char));
-    } else {
-      return "<unstringify>";
-    }
-  }
-
-private:
-  void assign(const void *content, size_t size, size_t type_id)
-  {
-    _content = new char[size];
-    std::memcpy(_content, content, size);
-    _size = size;
-    _type_id = type_id;
-  }
-
-  friend class boost::serialization::access;
-
-  template<class Archive>
-  void serialize(Archive &ar, const unsigned int version)
-  {
-    (void) version;
-
-    ar & _size;
-    if (Archive::is_loading::value) {
-      assert(_content == nullptr);
-      _content = new char[_size];
-    }
-    ar & boost::serialization::make_array<char>(_content, _size);
-    ar & _type_id;
-  }
-
-  char *_content;
-  size_t _size;
-  size_t _type_id;
-};
-
-}
-} // namespace artis common
-
-#endif

+ 21 - 39
src/artis-star/common/context/Context.hpp

@@ -31,36 +31,26 @@
 
 #include <boost/serialization/serialization.hpp>
 
-namespace artis {
-namespace common {
-namespace context {
+namespace artis::common::context {
 
-template<class Time>
-class Context
-{
+template<typename Time>
+class Context {
 public:
   Context()
-      : _begin(-1), _end(-1), _valid(false)
-  {}
+    : _begin(-1), _end(-1), _valid(false) {}
 
   Context(const typename Time::type &begin, const typename Time::type &end)
-      : _begin(begin), _end(end), _valid(false)
-  {}
+    : _begin(begin), _end(end), _valid(false) {}
 
-  virtual ~Context()
-  {}
+  virtual ~Context() = default;
 
-  const typename Time::type &begin() const
-  { return _begin; }
+  const typename Time::type &begin() const { return _begin; }
 
-  const typename Time::type &end() const
-  { return _end; }
+  const typename Time::type &end() const { return _end; }
 
-  void end(const typename Time::type &end)
-  { _end = end; }
+  void end(const typename Time::type &end) { _end = end; }
 
-  const Context &operator=(const Context &context)
-  {
+  Context &operator=(const Context &context) {
     _begin = context._begin;
     _end = context._end;
     _valid = context._valid;
@@ -68,32 +58,26 @@ public:
     return *this;
   }
 
-  void saved()
-  { _valid = true; }
+  void saved() { _valid = true; }
 
-  const State<Time> &state() const
-  { return _state; }
+  const State <Time> &state() const { return _state; }
 
-  State<Time> &state()
-  { return _state; }
+  State <Time> &state() { return _state; }
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     return "begin: " + std::to_string(_begin) +
-        "; end: " + std::to_string(_end) +
-        "; valid: " + (_valid ? "true" : "false") +
-        "; state: " + _state.to_string();
+           "; end: " + std::to_string(_end) +
+           "; valid: " + (_valid ? "true" : "false") +
+           "; state: { " + _state.to_string() + " }";
   }
 
-  bool valid() const
-  { return _valid; }
+  bool valid() const { return _valid; }
 
 private:
   friend class boost::serialization::access;
 
-  template<class Archive>
-  void serialize(Archive &ar, const unsigned int version)
-  {
+  template<typename Archive>
+  void serialize(Archive &ar, const unsigned int version) {
     (void) version;
 
     ar & _begin;
@@ -104,12 +88,10 @@ private:
 
   typename Time::type _begin;
   typename Time::type _end;
-  State<Time> _state;
+  State <Time> _state;
   bool _valid;
 };
 
-}
-}
 }
 
 #endif

+ 45 - 42
src/artis-star/common/context/State.hpp

@@ -35,64 +35,70 @@
 #include <boost/serialization/map.hpp>
 #include <boost/serialization/vector.hpp>
 
-namespace artis {
-namespace common {
-namespace context {
+namespace artis::common::context {
 
-template<class Time>
-class State
-{
+template<typename Time>
+class State {
   typedef std::map<unsigned int, State<Time> > Substates;
 
 public:
   State()
-      : _last_time(-1), _next_time(-1)
-  {}
+    : _last_time(-1), _next_time(-1) {}
 
-  virtual ~State()
-  {}
+  State(const State &) = default;
 
-  void add_state(unsigned int variable_key, const Value &value)
-  {
+  State(State &&) = default;
+
+  virtual ~State() = default;
+
+  void add_state(unsigned int variable_key, const event::Value &value) {
     _values.add_state(variable_key, value);
   }
 
-  void add_substate(unsigned int model_key, State &state)
-  {
-    _substates.insert(std::make_pair(model_key, state));
+  void add_sub_state(unsigned int model_key, State &state) {
+    _sub_states.insert(std::make_pair(model_key, state));
   }
 
-  const Value &get_state(unsigned int variable_key) const
-  {
+  const event::Value &get_state(unsigned int variable_key) const {
     return _values.get_state(variable_key);
   }
 
-  const State<Time> &get_substate(unsigned int model_key) const
-  {
-    return _substates.find(model_key)->second;
+  const State<Time> &get_sub_state(unsigned int model_key) const {
+    return _sub_states.find(model_key)->second;
   }
 
-  typename Time::type last_time() const
-  { return _last_time; }
+  typename Time::type last_time() const { return _last_time; }
+
+  void last_time(typename Time::type time) { _last_time = time; }
+
+  typename Time::type next_time() const { return _next_time; }
 
-  void last_time(typename Time::type t)
-  { _last_time = t; }
+  void next_time(typename Time::type time) { _next_time = time; }
 
-  typename Time::type next_time() const
-  { return _next_time; }
+  State& operator=(const State& state) {
+    _values = state._values;
+    _sub_states = state._sub_states;
+    _last_time = state._last_time;
+    _next_time = state._next_time;
+    return *this;
+  }
 
-  void next_time(typename Time::type t)
-  { _next_time = t; }
+  State& operator=(State&& state) {
+    _values = state._values;
+    _sub_states = state._sub_states;
+    _last_time = state._last_time;
+    _next_time = state._next_time;
+    return *this;
+  }
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::string str = "last_time: " + std::to_string(_last_time) +
-        "; next_time: " + std::to_string(_next_time) +
-        "; values: " + _values.to_string() + "; sub_states: [ ";
+                      "; next_time: " + std::to_string(_next_time) +
+                      "; values: { " + _values.to_string() + " } ; sub_states: [ ";
 
-    for (typename Substates::const_iterator it = _substates.begin();
-         it != _substates.end(); ++it) {
-      str += it->second.to_string() + " ";
+    for (typename Substates::const_iterator it = _sub_states.begin();
+         it != _sub_states.end(); ++it) {
+      str += "{ " + it->second.to_string() + "} ";
     }
     str += "]";
     return str;
@@ -101,25 +107,22 @@ public:
 private:
   friend class boost::serialization::access;
 
-  template<class Archive>
-  void serialize(Archive &ar, const unsigned int version)
-  {
+  template<typename Archive>
+  void serialize(Archive &ar, const unsigned int version) {
     (void) version;
 
     ar & _values;
-    ar & _substates;
+    ar & _sub_states;
     ar & _last_time;
     ar & _next_time;
   }
 
   StateValues _values;
-  Substates _substates;
+  Substates _sub_states;
   typename Time::type _last_time;
   typename Time::type _next_time;
 };
 
-}
-}
 }
 
 #endif

+ 31 - 29
src/artis-star/common/context/StateValues.hpp

@@ -27,47 +27,50 @@
 #ifndef COMMON_CONTEXT_STATE_VALUES_HPP
 #define COMMON_CONTEXT_STATE_VALUES_HPP
 
-#include <artis-star/common/Value.hpp>
+#include "artis-star/common/event/Value.hpp"
 
 #include <map>
 
 #include <boost/serialization/serialization.hpp>
 #include <boost/serialization/map.hpp>
 
-namespace artis {
-namespace common {
-namespace context {
+namespace artis::common::context {
 
-class StateValues
-{
+class StateValues {
 public:
-  StateValues()
-  {}
+  StateValues() = default;
+  StateValues(const StateValues&) = default;
+  StateValues(StateValues&&) = default;
 
-  virtual ~StateValues()
-  {}
+  virtual ~StateValues() = default;
 
-  void add_state(unsigned int key, const Value &value)
-  { _states[key] = value; }
+  void add_state(unsigned int key, const event::Value &value) { _states[key] = value; }
 
-  const Value &get_state(unsigned int key) const
-  {
-    std::map<unsigned int, Value>::const_iterator it =
-        _states.find(key);
+  const event::Value &get_state(unsigned int key) const {
+    Values::const_iterator it = _states.find(key);
 
     if (it != _states.end()) {
       return it->second;
-    } else {
-      assert(false);
-      return it->second;
     }
+
+    assert(false);
+
+    return it->second;
+  }
+
+  StateValues& operator=(const StateValues& values) {
+    _states = values._states;
+    return *this;
   }
 
-  std::string to_string() const
-  {
+  StateValues& operator=(StateValues&& values) {
+    _states = values._states;
+    return *this;
+  }
+
+  std::string to_string() const {
     std::string str = "states: [ ";
-    for (std::map<unsigned int, Value>::const_iterator it =
-        _states.begin(); it != _states.end(); ++it) {
+    for (Values::const_iterator it = _states.begin(); it != _states.end(); ++it) {
       str += it->second.to_string() + " ";
     }
     str += "]";
@@ -75,21 +78,20 @@ public:
   }
 
 private:
+  typedef std::map<unsigned int, event::Value> Values;
+
   friend class boost::serialization::access;
 
-  template<class Archive>
-  void serialize(Archive &ar, const unsigned int version)
-  {
+  template<typename Archive>
+  void serialize(Archive &ar, const unsigned int version) {
     (void) version;
 
     ar & _states;
   }
 
-  std::map<unsigned int, Value> _states;
+  Values _states;
 };
 
-}
-}
 }
 
 #endif

+ 18 - 25
src/artis-star/common/Bag.hpp

@@ -24,10 +24,10 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef COMMON_BAG
-#define COMMON_BAG
+#ifndef COMMON_EVENT_BAG
+#define COMMON_EVENT_BAG
 
-#include <artis-star/common/ExternalEvent.hpp>
+#include "artis-star/common/event/ExternalEvent.hpp"
 
 #include <boost/serialization/vector.hpp>
 
@@ -35,30 +35,26 @@
 #include <string>
 #include <vector>
 
-namespace artis {
-namespace common {
+namespace artis::common::event {
 
-template<class Time>
+template<typename Time>
 class ExternalEvent;
 
-template<class Time>
-class Bag : public std::vector<ExternalEvent<Time> >
-{
+template<typename Time>
+class Bag : public std::vector<ExternalEvent<Time> > {
 public:
   Bag() = default;
 
-  Bag(const ExternalEvent<Time> &event)
-  { this->push_back(event); }
+  Bag(const ExternalEvent<Time> &event) { this->push_back(event); }
 
   virtual ~Bag() = default;
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::ostringstream ss;
 
     ss << "{ ";
     for (typename Bag<Time>::const_iterator it =
-        Bag<Time>::begin();
+      Bag<Time>::begin();
          it != Bag<Time>::end(); ++it) {
       ss << it->to_string() << " ";
     }
@@ -69,27 +65,24 @@ public:
 private:
   friend class boost::serialization::access;
 
-  template<class Archive>
-  void save(Archive &ar, const unsigned int version) const
-  {
+  template<typename Archive>
+  void save(Archive &ar, const unsigned int version) const {
     (void) version;
 
-    ar & *dynamic_cast < const std::vector<ExternalEvent<Time> > * >(
-        this);
+    ar & *dynamic_cast < const std::vector <ExternalEvent<Time>> * >(
+      this);
   }
 
-  template<class Archive>
-  void load(Archive &ar, const unsigned int version)
-  {
+  template<typename Archive>
+  void load(Archive &ar, const unsigned int version) {
     (void) version;
 
-    ar & *dynamic_cast < std::vector<ExternalEvent<Time> > * >(this);
+    ar & *dynamic_cast < std::vector <ExternalEvent<Time>> * >(this);
   }
 
   BOOST_SERIALIZATION_SPLIT_MEMBER()
 };
 
-}
-} // namespace artis common
+} // namespace artis common event
 
 #endif

+ 12 - 0
src/artis-star/common/event/CMakeLists.txt

@@ -0,0 +1,12 @@
+INCLUDE_DIRECTORIES(
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
+
+LINK_DIRECTORIES(
+        ${Boost_LIBRARY_DIRS})
+
+SET(COMMON_EVENT_HPP Bag.hpp ExternalEvent.hpp InternalEvent.hpp Value.hpp)
+
+INSTALL(FILES ${COMMON_EVENT_HPP} DESTINATION
+        ${ARTIS_INCLUDE_DIRS}/common/event)

+ 40 - 55
src/artis-star/common/ExternalEvent.hpp

@@ -24,12 +24,12 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef COMMON_EXTERNAL_EVENT
-#define COMMON_EXTERNAL_EVENT
+#ifndef COMMON_EVENT_EXTERNAL_EVENT
+#define COMMON_EVENT_EXTERNAL_EVENT
 
-#include <artis-star/common/Model.hpp>
-#include <artis-star/common/Node.hpp>
-#include <artis-star/common/Value.hpp>
+#include "artis-star/common/Model.hpp"
+#include "artis-star/common/Node.hpp"
+#include "Value.hpp"
 
 #include <boost/serialization/serialization.hpp>
 #include <boost/serialization/nvp.hpp>
@@ -38,94 +38,79 @@
 #include <string>
 #include <vector>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-template<class Time>
+template<typename Time>
 class Node;
 
-template<class Time>
+template<typename Time>
 class Model;
 
-template<class Time>
-class ExternalEvent
-{
+namespace event {
+
+template<typename Time>
+class ExternalEvent {
 public:
   ExternalEvent(const Value &data)
-      :
-      _port_index(-1), _model(nullptr), _data(data)
-  {}
+    :
+    _port_index(-1), _model(nullptr), _data(data) {}
 
   ExternalEvent(int port_index)
-      :
-      _port_index(port_index), _model(nullptr), _data(Value())
-  {}
+    :
+    _port_index(port_index), _model(nullptr), _data(Value()) {}
 
   ExternalEvent(int port_index, const Value &data)
-      :
-      _port_index(port_index), _model(nullptr), _data(data)
-  {}
+    :
+    _port_index(port_index), _model(nullptr), _data(data) {}
 
   ExternalEvent(const Node<Time> &node, const Value &data)
-      :
-      _port_index(node.get_port_index()),
-      _model(node.get_model()),
-      _data(data)
-  {}
+    :
+    _port_index(node.get_port_index()),
+    _model(node.get_model()),
+    _data(data) {}
 
   ExternalEvent(const ExternalEvent &event)
-      :
-      _port_index(event._port_index), _model(event._model),
-      _data(event._data)
-  {}
+    :
+    _port_index(event._port_index), _model(event._model),
+    _data(event._data) {}
 
   ExternalEvent()
-      : _port_index(-2), _model(nullptr)
-  {}
+    : _port_index(-2), _model(nullptr) {}
 
   virtual ~ExternalEvent() = default;
 
-  const Value &data() const
-  { return _data; }
+  const Value &data() const { return _data; }
 
-  void data(const Value &data)
-  { _data = data; }
+  void data(const Value &data) { _data = data; }
 
-  Model<Time> *get_model() const
-  { return _model; }
+  Model<Time> *get_model() const { return _model; }
 
-  bool is_void() const
-  { return _port_index == -2; }
+  bool is_void() const { return _port_index == -2; }
 
-  bool on_port(int port_index) const
-  {
+  bool on_port(int port_index) const {
 
     assert(_port_index != -1);
 
     return _port_index == port_index;
   }
 
-  ExternalEvent &operator=(const ExternalEvent &e)
-  {
+  ExternalEvent &operator=(const ExternalEvent &e) {
     _port_index = e._port_index;
     _model = e._model;
     _data = e._data;
     return *this;
   }
 
-  int port_index() const
-  {
+  int port_index() const {
 
     assert(_port_index != -1);
 
     return _port_index;
   }
 
-  void set_model(Model<Time> *model)
-  { _model = model; }
+  void set_model(Model<Time> *model) { _model = model; }
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::ostringstream ss;
 
     ss << "( ";
@@ -148,9 +133,8 @@ public:
 private:
   friend class boost::serialization::access;
 
-  template<class Archive>
-  void serialize(Archive &ar, const unsigned int version)
-  {
+  template<typename Archive>
+  void serialize(Archive &ar, const unsigned int version) {
     (void) version;
 
     ar & _port_index;
@@ -165,10 +149,11 @@ private:
   Value _data;
 };
 
-template<class Time>
+template<typename Time>
 ExternalEvent<Time> ExternalEvent<Time>::Void;
 
 }
-} // namespace artis common
+
+} // namespace artis common event
 
 #endif

+ 22 - 32
src/artis-star/common/InternalEvent.hpp

@@ -24,58 +24,49 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef COMMON_INTERNAL_EVENT
-#define COMMON_INTERNAL_EVENT
+#ifndef COMMON_EVENT_INTERNAL_EVENT
+#define COMMON_EVENT_INTERNAL_EVENT
 
-#include <artis-star/common/Model.hpp>
+#include "artis-star/common/Model.hpp"
 
 #include <functional>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-template<class Time>
+template<typename Time>
 class Model;
 
-template<class Time>
-class InternalEvent
-{
+namespace event {
+
+template<typename Time>
+class InternalEvent {
 public:
   InternalEvent(const typename Time::type &time, Model<Time> *model)
-      : _time(time), _model(model)
-  {}
+    : _time(time), _model(model) {}
 
-  virtual ~InternalEvent()
-  {}
+  virtual ~InternalEvent() {}
 
-  Model<Time> *get_model() const
-  { return _model; }
+  Model<Time> *get_model() const { return _model; }
 
-  typename Time::type get_time() const
-  { return _time; }
+  typename Time::type get_time() const { return _time; }
 
-  bool operator<(InternalEvent const &e) const
-  {
+  bool operator<(InternalEvent const &e) const {
     return _time < e._time;
   }
 
-  bool operator>(InternalEvent const &e) const
-  {
+  bool operator>(InternalEvent const &e) const {
     return _time > e._time;
   }
 
-  bool operator>=(InternalEvent const &e) const
-  {
+  bool operator>=(InternalEvent const &e) const {
     return _time >= e._time;
   }
 
-  bool operator==(InternalEvent const &e) const
-  {
+  bool operator==(InternalEvent const &e) const {
     return _time == e._time;
   }
 
-  void set_time(typename Time::type time)
-  { _time = time; }
+  void set_time(typename Time::type time) { _time = time; }
 
 private:
   typename Time::type _time;
@@ -84,13 +75,12 @@ private:
 
 template<typename Event>
 struct EventCompare
-    : std::binary_function<Event, Event, bool>
-{
-  bool operator()(const Event &left, const Event &right) const
-  { return left >= right; }
+  : std::binary_function<Event, Event, bool> {
+  bool operator()(const Event &left, const Event &right) const { return left >= right; }
 };
 
 }
-} // namespace artis common
+
+} // namespace artis common event
 
 #endif

+ 311 - 0
src/artis-star/common/event/Value.hpp

@@ -0,0 +1,311 @@
+/**
+ * @file common/Value.hpp
+ * @author The ARTIS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * ARTIS - the multimodeling and simulation environment
+ * This file is a part of the ARTIS environment
+ *
+ * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef COMMON_EVENT_VALUE
+#define COMMON_EVENT_VALUE
+
+#include <boost/serialization/serialization.hpp>
+#include <boost/serialization/array.hpp>
+
+#include <cassert>
+#include <cstring>
+#include <functional>
+#include <map>
+#include <numeric>
+#include <string>
+#include <typeinfo>
+#include <vector>
+
+namespace artis::common::event {
+
+class Value {
+public:
+  Value()
+    : _content(nullptr), _size(0), _type_id(0) {}
+
+  template<typename T>
+  Value(const T &value) { assign(&value, sizeof(T), typeid(T).hash_code()); }
+
+  template<typename T>
+  Value(const T *value, size_t size) { assign(value, sizeof(T) * size, typeid(T *).hash_code()); }
+
+  template<typename T>
+  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()); }
+
+  Value(const char *value, unsigned int size) { assign(value, size * sizeof(char), typeid(char *).hash_code()); }
+
+  Value(const Value &value) {
+    if (value._content != nullptr) {
+      assign(value._content, value._size, value._type_id);
+    } else {
+      _content = nullptr;
+      _size = 0;
+      _type_id = 0;
+    }
+  }
+
+  Value(Value &&value) : _content(value._content), _size(value._size), _type_id(value._type_id) {
+    value._content = nullptr;
+    value._size = 0;
+    value._type_id = 0;
+  }
+
+  virtual ~Value() {
+    delete[] _content;
+  }
+
+  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 {
+
+    assert(_type_id == typeid(T).hash_code());
+
+    value = *(T *) (_content);
+  }
+
+  template<typename T>
+  void operator()(T *&value) const {
+
+    assert(_type_id == typeid(T *).hash_code());
+
+    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);
+
+    for (size_t i = 0; i < size; ++i) {
+      value.push_back(((T *) (_content))[i]);
+    }
+  }
+
+  Value &operator=(const Value &value) {
+    delete[] _content;
+    if (value._content != nullptr) {
+      assign(value._content, value._size, value._type_id);
+    } else {
+      _content = nullptr;
+      _size = 0;
+      _type_id = 0;
+    }
+    return *this;
+  }
+
+  Value &operator=(Value &&value) {
+    delete[] _content;
+    _content = value._content;
+    value._content = nullptr;
+    _size = value._size;
+    value._size = 0;
+    _type_id = value._type_id;
+    value._type_id = 0;
+    return *this;
+  }
+
+  template<typename Z>
+  size_t size() const {
+
+    assert(is_type<Z *>());
+
+    return _size / sizeof(Z);
+  }
+
+  std::string to_string() const {
+    if (is_null()) {
+      return "<null>";
+    }
+
+    auto it = convert.find(_type_id);
+
+    if (it != convert.cend()) {
+      return it->second(*this);
+    }
+    return "<unstringify>";
+  }
+
+private:
+  typedef std::map<unsigned long, std::function<std::string(const artis::common::event::Value &)>> ConvertFunctions;
+
+  static const ConvertFunctions convert;
+
+  void assign(const void *content, size_t size, size_t type_id) {
+    _content = new char[size];
+    std::memcpy(_content, content, size);
+    _size = size;
+    _type_id = type_id;
+  }
+
+  friend class boost::serialization::access;
+
+  template<typename Archive>
+  void serialize(Archive &ar, const unsigned int version) {
+    (void) version;
+
+    ar & _size;
+    if (Archive::is_loading::value) {
+      assert(_content == nullptr);
+      _content = new char[_size];
+    }
+    ar & boost::serialization::make_array<char>(_content, _size);
+    ar & _type_id;
+  }
+
+  char *_content = nullptr;
+  size_t _size = 0;
+  size_t _type_id = 0;
+};
+
+std::ostream& operator<<(std::ostream& o, const Value& value) {
+  o << value.to_string();
+  return o;
+}
+
+const Value::ConvertFunctions Value::convert = {
+  {
+    typeid(double).hash_code(),         [](const Value &value) {
+    double v;
+
+    value.operator()(v);
+    return std::to_string(v);
+  }},
+  {
+    typeid(int).hash_code(),            [](const Value &value) {
+    int v;
+
+    value.operator()(v);
+    return std::to_string(v);
+  }},
+  {
+    typeid(unsigned int).hash_code(),   [](const Value &value) {
+    unsigned int v;
+
+    value.operator()(v);
+    return std::to_string(v);
+  }},
+  {
+    typeid(bool).hash_code(),           [](const Value &value) {
+    bool v;
+
+    value.operator()(v);
+    return v ? "true" : "false";
+  }},
+  {
+    typeid(char).hash_code(),           [](const Value &value) {
+    char v;
+
+    value.operator()(v);
+    return std::string(&v, 1);
+  }},
+  {
+    typeid(double *).hash_code(),       [](const Value &value) {
+
+    double *v;
+    std::string str;
+    size_t size = value._size / sizeof(double);
+
+    value.operator()(v);
+    for (size_t i = 0; i < size; ++i) {
+      str += std::to_string(v[i]) + std::string(" ");
+    }
+    return str;
+  }},
+  {
+    typeid(int *).hash_code(),          [](const Value &value) {
+    int *v;
+    std::string str;
+    size_t size = value._size / sizeof(int);
+
+    value.operator()(v);
+    for (size_t i = 0; i < size; ++i) {
+      str += std::to_string(v[i]) + std::string(" ");
+    }
+    return str;
+  }},
+  {
+    typeid(unsigned int *).hash_code(), [](const Value &value) {
+    unsigned int *v;
+    std::string str;
+    size_t size = value._size / sizeof(unsigned int);
+
+    value.operator()(v);
+    for (size_t i = 0; i < size; ++i) {
+      str += std::to_string(v[i]) + std::string(" ");
+    }
+    return str;
+  }},
+  {
+    typeid(bool *).hash_code(),         [](const Value &value) {
+    bool *v;
+    std::string str;
+    size_t size = value._size / sizeof(bool);
+
+    value.operator()(v);
+    for (size_t i = 0; i < size; ++i) {
+      str += (v[i] ? "true" : "false") + std::string(" ");
+    }
+    return str;
+  }},
+  {
+    typeid(char *).hash_code(),         [](const Value &value) {
+    char *v;
+
+    value.operator()(v);
+    return std::string(v, value._size / sizeof(char));
+  }
+  }};
+
+} // namespace artis common
+
+#endif

+ 2 - 1
src/artis-star/common/observer/CMakeLists.txt

@@ -3,7 +3,8 @@ INCLUDE_DIRECTORIES(
 
 LINK_DIRECTORIES()
 
-SET(COMMON_OBSERVER_HPP Iterator.hpp Observer.hpp Output.hpp View.hpp)
+SET(COMMON_OBSERVER_HPP DiscreteTimeIterator.hpp EventIterator.hpp Iterator.hpp Observer.hpp Output.hpp
+        TimedIterator.hpp View.hpp)
 
 INSTALL(FILES ${COMMON_OBSERVER_HPP} DESTINATION
         ${ARTIS_INCLUDE_DIRS}/common/observer)

+ 74 - 0
src/artis-star/common/observer/DiscreteTimeIterator.hpp

@@ -0,0 +1,74 @@
+/**
+ * @file common/observer/DiscreteTimeIterator.hpp
+ * @author The ARTIS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * ARTIS - the multimodeling and simulation environment
+ * This file is a part of the ARTIS environment
+ *
+ * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ARTIS_COMMON_OBSERVER_DISCRETE_TIME_ITERATOR_HPP
+#define ARTIS_COMMON_OBSERVER_DISCRETE_TIME_ITERATOR_HPP
+
+#include <artis-star/common/observer/View.hpp>
+#include <artis-star/common/observer/Iterator.hpp>
+
+namespace artis::common::observer {
+
+template<typename Time>
+class DiscreteTimeIterator : public Iterator<Time> {
+public:
+  DiscreteTimeIterator(const typename View<Time>::Values &view,
+                       const typename Time::type &start, const typename Time::type &step)
+    : Iterator<Time>(view), _step(step), _time(start) {
+    _last_value = &Iterator<Time>::operator*();
+    while (Iterator<Time>::operator*().first <= start
+           and Iterator<Time>::has_next()) {
+      Iterator<Time>::operator++();
+      if (Iterator<Time>::operator*().first == start) {
+        _last_value = &Iterator<Time>::operator*();
+      }
+    }
+  }
+
+  virtual ~DiscreteTimeIterator() = default;
+
+  void operator++() override {
+    _time += _step;
+    _last_value = &Iterator<Time>::operator*();
+    while (Iterator<Time>::operator*().first <= _time and Iterator<Time>::has_next()) {
+      Iterator<Time>::operator++();
+      if (Iterator<Time>::operator*().first == _time) {
+        _last_value = &Iterator<Time>::operator*();
+      }
+    }
+  }
+
+  const std::pair<double, common::event::Value> &operator*() const override { return *_last_value; }
+
+private:
+  typename Time::type _step;
+  typename Time::type _time;
+  const std::pair<double, common::event::Value> *_last_value;
+};
+
+}
+
+#endif

+ 54 - 0
src/artis-star/common/observer/EventIterator.hpp

@@ -0,0 +1,54 @@
+/**
+ * @file common/observer/EventIterator.hpp
+ * @author See the AUTHORS file
+ */
+
+/*
+ * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ARTIS_COMMON_OBSERVER_EVENT_ITERATOR_HPP
+#define ARTIS_COMMON_OBSERVER_EVENT_ITERATOR_HPP
+
+#include <artis-star/common/observer/Iterator.hpp>
+
+namespace artis::common::observer {
+
+template<typename Time>
+struct EventIterator {
+  typedef artis::common::observer::Iterator<Time> iterator_type;
+
+  double begin(const std::vector <Iterator<Time>> &its) const { return next_time(0, its); }
+
+  iterator_type build(const typename View<Time>::Values &view) const { return iterator_type(view); }
+
+  bool is_valid(double time, const iterator_type &it) const { return (*it).first == time; }
+
+  double next_time(double /* time */, const std::vector <Iterator<Time>> &its) const {
+    double min = std::numeric_limits<double>::max();
+
+    for (const auto &it: its) {
+      if (min > (*it).first) {
+        min = (*it).first;
+      }
+    }
+    return min;
+  }
+};
+
+}
+
+#endif

+ 7 - 55
src/artis-star/common/observer/Iterator.hpp

@@ -1,5 +1,5 @@
 /**
- * @file common/observer/View.hpp
+ * @file common/observer/Iterator.hpp
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  */
@@ -29,75 +29,27 @@
 
 #include <artis-star/common/observer/View.hpp>
 
-namespace artis {
-namespace observer {
+namespace artis::common::observer {
 
 template<typename Time>
-class Iterator
-{
+class Iterator {
 public:
   Iterator(const typename View<Time>::Values &view)
-      : _view(view), _iterator(view.begin())
-  {}
+    : _view(view), _iterator(view.begin()) {}
 
   virtual ~Iterator() = default;
 
-  bool has_next() const
-  { return _iterator != _view.end(); }
+  bool has_next() const { return _iterator != _view.end(); }
 
-  virtual void operator++()
-  { _iterator++; }
+  virtual void operator++() { _iterator++; }
 
-  virtual const std::pair<double, common::Value> &operator*() const
-  { return *_iterator; }
+  virtual const std::pair<double, common::event::Value> &operator*() const { return *_iterator; }
 
 private:
   const typename View<Time>::Values &_view;
   typename View<Time>::Values::const_iterator _iterator;
 };
 
-template<typename Time>
-class DiscreteTimeIterator : public Iterator<Time>
-{
-public:
-  DiscreteTimeIterator(const typename View<Time>::Values &view,
-                       const typename Time::type &start, const typename Time::type &step)
-      : Iterator<Time>(view), _step(step), _time(start)
-  {
-    _last_value = &Iterator<Time>::operator*();
-    while (Iterator<Time>::operator*().first <= start
-        and Iterator<Time>::has_next()) {
-      Iterator<Time>::operator++();
-      if (Iterator<Time>::operator*().first == start) {
-        _last_value = &Iterator<Time>::operator*();
-      }
-    }
-  }
-
-  virtual ~DiscreteTimeIterator() = default;
-
-  void operator++() override
-  {
-    _time += _step;
-    _last_value = &Iterator<Time>::operator*();
-    while (Iterator<Time>::operator*().first <= _time and Iterator<Time>::has_next()) {
-      Iterator<Time>::operator++();
-      if (Iterator<Time>::operator*().first == _time) {
-        _last_value = &Iterator<Time>::operator*();
-      }
-    }
-  }
-
-  const std::pair<double, common::Value> &operator*() const override
-  { return *_last_value; }
-
-private:
-  typename Time::type _step;
-  typename Time::type _time;
-  const std::pair<double, common::Value> *_last_value;
-};
-
-}
 }
 
 #endif

+ 13 - 29
src/artis-star/common/observer/Observer.hpp

@@ -32,37 +32,28 @@
 
 #include <vector>
 
-namespace artis {
-namespace observer {
+namespace artis::common::observer {
 
 template<typename Time>
-class Observer
-{
+class Observer {
 public:
   typedef std::map<std::string, View<Time> *> Views;
 
   Observer(const common::Model<Time> *model)
-      :
-      _step(0),
-      _model(model)
-  {}
+    : _step(0), _model(model) {}
 
-  virtual ~Observer()
-  {
-    for (typename Views::iterator it = _views.begin(); it != _views.end();
-         ++it) {
+  virtual ~Observer() {
+    for (typename Views::iterator it = _views.begin(); it != _views.end(); ++it) {
       delete it->second;
     }
   }
 
-  void attachView(const std::string &name, View<Time> *view)
-  {
+  void attachView(const std::string &name, View<Time> *view) {
     _views[name] = view;
     view->attachModel(_model);
   }
 
-  Views *cloneViews() const
-  {
+  Views *cloneViews() const {
     Views *v = new Views();
 
     for (typename Views::const_iterator it = _views.begin();
@@ -72,19 +63,15 @@ public:
     return v;
   }
 
-  const View<Time> &view(const std::string &name) const
-  {
+  const View<Time> &view(const std::string &name) const {
     return *_views.find(name)->second;
   }
 
-  const Views &views() const
-  { return _views; }
+  const Views &views() const { return _views; }
 
-  void init()
-  {}
+  void init() {}
 
-  void observe(double t, double next_t)
-  {
+  void observe(double t, double next_t) {
     if (_step == 0) {
       observe(t);
     } else {
@@ -97,8 +84,7 @@ public:
     }
   }
 
-  void switch_to_timed_observer(double step)
-  {
+  void switch_to_timed_observer(double step) {
 
     assert(step > 0);
 
@@ -106,8 +92,7 @@ public:
   }
 
 private:
-  void observe(double t)
-  {
+  void observe(double t) {
     for (typename Views::iterator it = _views.begin(); it != _views.end();
          ++it) {
       it->second->observe(t, _step == 0);
@@ -119,7 +104,6 @@ private:
   Views _views;
 };
 
-}
 }
 
 #endif

+ 7 - 61
src/artis-star/common/observer/Output.hpp

@@ -1,5 +1,5 @@
 /**
- * @file observer/Output.hpp
+ * @file common/observer/Output.hpp
  * @author See the AUTHORS file
  */
 
@@ -23,80 +23,27 @@
 #ifndef ARTIS_COMMON_OBSERVER_OUTPUT_HPP
 #define ARTIS_COMMON_OBSERVER_OUTPUT_HPP
 
-#include <artis-star/common/observer/Iterator.hpp>
 #include <artis-star/common/observer/Observer.hpp>
 #include <artis-star/common/observer/View.hpp>
 
 #include <boost/format.hpp>
 #include <fstream>
 
-namespace artis {
-namespace observer {
-
-template<typename Time>
-struct EventIterator
-{
-  typedef artis::observer::Iterator<Time> iterator_type;
-
-  double begin(const std::vector <Iterator<Time>> &its) const
-  { return next_time(0, its); }
-
-  iterator_type build(const typename View<Time>::Values &view) const
-  { return iterator_type(view); }
-
-  bool is_valid(double time, const iterator_type &it) const
-  { return (*it).first == time; }
-
-  double next_time(double /* time */, const std::vector <Iterator<Time>> &its) const
-  {
-    double min = std::numeric_limits<double>::max();
-
-    for (const auto &it: its) {
-      if (min > (*it).first) {
-        min = (*it).first;
-      }
-    }
-    return min;
-  }
-};
-
-template<typename Time>
-struct TimedIterator
-{
-  typedef artis::observer::DiscreteTimeIterator<Time> iterator_type;
-  double _begin;
-  double _step;
-
-  double begin(const std::vector <DiscreteTimeIterator<Time>> & /* its */) const
-  { return _begin; }
-
-  iterator_type build(const typename View<Time>::Values &view) const
-  { return iterator_type(view, _begin, _step); }
-
-  bool is_valid(double /* time */, const iterator_type & /* it */) const
-  { return true; }
-
-  double next_time(double time, const std::vector <DiscreteTimeIterator<Time>> & /* its */) const
-  { return time + _step; }
-};
+namespace artis::common::observer {
 
 template<typename Time, typename Iterator>
-class Output
-{
+class Output {
 public:
   Output(const Observer <Time> &observer)
-      : _observer(observer)
-  {}
+    : _observer(observer) {}
 
-  virtual ~Output()
-  {}
+  virtual ~Output() {}
 
-  void operator()(double /* begin */, double end, const Iterator &iterator) const
-  {
+  void operator()(double /* begin */, double end, const Iterator &iterator) const {
     const typename Observer<Time>::Views &views = _observer.views();
 
     for (typename Observer<Time>::Views::const_iterator it =
-        views.begin(); it != views.end(); ++it) {
+      views.begin(); it != views.end(); ++it) {
       std::ofstream o((boost::format("%1%.csv") % it->first).str());
       const typename View<Time>::SelectorValues &values = it->second->values();
       std::vector<typename Iterator::iterator_type> its;
@@ -142,7 +89,6 @@ private:
   const Observer <Time> &_observer;
 };
 
-}
 }
 
 #endif

+ 49 - 0
src/artis-star/common/observer/TimedIterator.hpp

@@ -0,0 +1,49 @@
+/**
+ * @file common/observer/TimedIterator.hpp
+ * @author See the AUTHORS file
+ */
+
+/*
+ * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ARTIS_COMMON_OBSERVER_TIMED_ITERATOR_HPP
+#define ARTIS_COMMON_OBSERVER_TIMED_ITERATOR_HPP
+
+#include <artis-star/common/observer/DiscreteTimeIterator.hpp>
+
+namespace artis::common::observer {
+
+template<typename Time>
+struct TimedIterator {
+  typedef artis::common::observer::DiscreteTimeIterator<Time> iterator_type;
+  double _begin;
+  double _step;
+
+  double begin(const std::vector <DiscreteTimeIterator<Time>> & /* its */) const { return _begin; }
+
+  iterator_type build(const typename View<Time>::Values &view) const { return iterator_type(view, _begin, _step); }
+
+  bool is_valid(double /* time */, const iterator_type & /* it */) const { return true; }
+
+  double next_time(double time, const std::vector <DiscreteTimeIterator<Time>> & /* its */) const {
+    return time + _step;
+  }
+};
+
+}
+
+#endif

+ 30 - 49
src/artis-star/common/observer/View.hpp

@@ -29,43 +29,36 @@
 
 #include <artis-star/common/Model.hpp>
 #include <artis-star/common/time/DoubleTime.hpp>
-#include <artis-star/common/Value.hpp>
+#include "artis-star/common/event/Value.hpp"
 
 #include <boost/format.hpp>
 #include <boost/lexical_cast.hpp>
 
-namespace artis {
-namespace observer {
+namespace artis::common::observer {
 
 template<typename Time>
-class View
-{
+class View {
   typedef std::vector<int> Selector;
 
 public:
-  typedef std::vector <std::pair<double, common::Value>> Values;
-  typedef std::map <std::string, Values> VariableValues;
-  typedef std::map <std::string, VariableValues> SelectorValues;
+  typedef std::vector<std::pair<double, common::event::Value>> Values;
+  typedef std::map<std::string, Values> VariableValues;
+  typedef std::map<std::string, VariableValues> SelectorValues;
   template<typename W>
-  using ValueVector = std::vector <std::pair<double, W>>;
+  using ValueVector = std::vector<std::pair<double, W>>;
 
-  enum vars
-  {
+  enum vars {
     ALL = -1
   };
 
   View()
-      : _model(0)
-  {}
+    : _model(0) {}
 
-  virtual ~View()
-  {}
+  virtual ~View() {}
 
-  void attachModel(const artis::common::Model<Time> *m)
-  { _model = m; }
+  void attachModel(const artis::common::Model<Time> *m) { _model = m; }
 
-  View *clone() const
-  {
+  View *clone() const {
     View *v = new View();
 
     // v->_selectors = _selectors;
@@ -84,9 +77,7 @@ public:
     return v;
   }
 
-  const Values &
-  get(const std::string &selector_name, const std::string &variable_name) const
-  {
+  const Values &get(const std::string &selector_name, const std::string &variable_name) const {
     SelectorValues::const_iterator it = _values.find(selector_name);
 
     if (it != _values.end()) {
@@ -103,9 +94,7 @@ public:
   }
 
   template<typename W>
-  ValueVector<W>
-  get(const std::string &selector_name, const std::string &variable_name) const
-  {
+  ValueVector<W> get(const std::string &selector_name, const std::string &variable_name) const {
     SelectorValues::const_iterator it = _values.find(selector_name);
 
     if (it != _values.end()) {
@@ -131,8 +120,7 @@ public:
     }
   }
 
-  const Values &get(const std::string &selector_name) const
-  {
+  const Values &get(const std::string &selector_name) const {
     SelectorValues::const_iterator it = _values.find(selector_name);
 
     if (it != _values.end()) {
@@ -145,8 +133,7 @@ public:
   }
 
   template<typename W>
-  ValueVector<W> get(const std::string &selector_name) const
-  {
+  ValueVector<W> get(const std::string &selector_name) const {
     SelectorValues::const_iterator it = _values.find(selector_name);
 
     if (it != _values.end()) {
@@ -167,31 +154,29 @@ public:
     }
   }
 
-  void observe(double time, const common::Model <common::DoubleTime> *model,
-               const std::string &selector_name, unsigned int variable_index)
-  {
+  void observe(double time, const common::Model<common::DoubleTime> *model,
+               const std::string &selector_name, unsigned int variable_index) {
     std::string path = (boost::format("%1%:%2%") % model->path() %
-        model->observable_name(variable_index)).str();
+                        model->observable_name(variable_index)).str();
     VariableValues &values = _values[selector_name];
 
     if (values.find(path) == values.end()) {
       values[path] = Values();
     }
     values[path].push_back(
-        std::make_pair(time, model->observe(time, variable_index)));
+      std::make_pair(time, model->observe(time, variable_index)));
   }
 
   void observe(const Selector &chain, unsigned int i,
-               double time, const common::Model <common::DoubleTime> *model,
-               const std::string &selector_name, unsigned int variable_index)
-  {
+               double time, const common::Model<common::DoubleTime> *model,
+               const std::string &selector_name, unsigned int variable_index) {
     assert(model != nullptr);
 
     while (i < chain.size() - 1 and chain[i + 1] != ALL and model) {
 
       assert(chain[i] >= 0);
 
-      model = model->get_submodel((unsigned int) chain[i]);
+      model = model->get_sub_model((unsigned int) chain[i]);
       ++i;
     }
     if (i < chain.size() - 1 and chain[i + 1] == ALL) {
@@ -199,13 +184,13 @@ public:
       assert(model != nullptr);
 
       for (size_t model_index = 0;
-           model_index < model->get_submodel_number(chain[i]);
+           model_index < model->get_sub_model_number(chain[i]);
            ++model_index) {
 
         assert(chain[i] >= 0);
 
         observe(chain, i + 2, time,
-                model->get_submodel((unsigned int) chain[i], model_index),
+                model->get_sub_model((unsigned int) chain[i], model_index),
                 selector_name, variable_index);
       }
     } else {
@@ -215,11 +200,10 @@ public:
     }
   }
 
-  virtual void observe(double time, bool trim)
-  {
+  virtual void observe(double time, bool trim) {
     for (typename Selectors::const_iterator it = _selectors.begin();
          it != _selectors.end(); ++it) {
-      const common::Model <common::DoubleTime> *model = _model;
+      const common::Model<common::DoubleTime> *model = _model;
 
       if (it->second.size() > 1) {
         size_t i = 0;
@@ -261,23 +245,20 @@ public:
     }
   }
 
-  void selector(const std::string &name, const Selector &chain)
-  {
+  void selector(const std::string &name, const Selector &chain) {
     _selectors[name] = chain;
   }
 
-  const SelectorValues &values() const
-  { return _values; }
+  const SelectorValues &values() const { return _values; }
 
 private:
-  typedef std::map <std::string, Selector> Selectors;
+  typedef std::map<std::string, Selector> Selectors;
 
   Selectors _selectors;
   SelectorValues _values;
   const artis::common::Model<Time> *_model;
 };
 
-}
 }
 
 #endif

+ 1 - 2
src/artis-star/common/scheduler/CMakeLists.txt

@@ -6,8 +6,7 @@ INCLUDE_DIRECTORIES(
 LINK_DIRECTORIES(
         ${Boost_LIBRARY_DIRS})
 
-SET(COMMON_SCHEDULER_HPP HeapScheduler.hpp SchedulerHandle.hpp
-        VectorScheduler.hpp)
+SET(COMMON_SCHEDULER_HPP HeapScheduler.hpp SchedulerHandle.hpp VectorScheduler.hpp)
 
 INSTALL(FILES ${COMMON_SCHEDULER_HPP} DESTINATION
         ${ARTIS_INCLUDE_DIRS}/common/scheduler)

+ 25 - 38
src/artis-star/common/scheduler/HeapScheduler.hpp

@@ -27,49 +27,42 @@
 #ifndef COMMON_SCHEDULER_HEAP_SCHEDULER_HPP
 #define COMMON_SCHEDULER_HEAP_SCHEDULER_HPP
 
-#include <artis-star/common/InternalEvent.hpp>
+#include "artis-star/common/event/InternalEvent.hpp"
 
 #include <boost/heap/fibonacci_heap.hpp>
 
 #include <sstream>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-template<class Time>
+template<typename Time>
 class Model;
 
-template<class Time>
+template<typename Time>
 class Models;
 
 namespace scheduler {
 
-template<class Time, class T>
+template<typename Time, typename T>
 class HeapScheduler :
-    public boost::heap::fibonacci_heap<
-        InternalEvent<Time>,
-        boost::heap::compare<
-            EventCompare<InternalEvent<Time> > > >
-{
+  public boost::heap::fibonacci_heap<event::InternalEvent<Time>,
+    boost::heap::compare<event::EventCompare<event::InternalEvent<Time>
+    > > > {
 public:
   typedef HeapScheduler<Time, T> type;
   typedef Model<Time> model_type;
   typedef Models<Time> models_type;
-  typedef InternalEvent<Time> internal_event_type;
+  typedef event::InternalEvent<Time> internal_event_type;
 
-  HeapScheduler()
-  {}
+  HeapScheduler() {}
 
-  virtual ~HeapScheduler()
-  {}
+  virtual ~HeapScheduler() {}
 
-  model_type *get_current_model()
-  {
+  model_type *get_current_model() {
     return type::top().get_model();
   }
 
-  models_type get_current_models(const typename Time::type &time) const
-  {
+  models_type get_current_models(const typename Time::type &time) const {
     models_type models;
     typename models_type::iterator it;
 
@@ -89,15 +82,14 @@ public:
   }
 
   models_type get_current_models(const typename Time::type &begin,
-                                 const typename Time::type &end) const
-  {
+                                 const typename Time::type &end) const {
     models_type models;
     typename models_type::iterator it;
 
     for (typename type::ordered_iterator it = type::ordered_begin();
          it != type::ordered_end() and (std::abs(it->get_time() - begin) < 1e-6
-             or (it->get_time() > begin
-                 and it->get_time() < end)); ++it) {
+                                        or (it->get_time() > begin
+                                            and it->get_time() < end)); ++it) {
       std::string str = it->get_model()->get_name();
       auto it2 = find_if(models.begin(), models.end(),
                          [&str](const model_type *obj) {
@@ -111,20 +103,17 @@ public:
     return models;
   }
 
-  typename Time::type get_current_time() const
-  {
+  typename Time::type get_current_time() const {
     return type::top().get_time();
   }
 
-  void init(typename Time::type time, model_type *model)
-  {
+  void init(typename Time::type time, model_type *model) {
     model->handle(T(type::push(internal_event_type(time, model))));
   }
 
-  void put(typename Time::type time, const model_type *model)
-  {
+  void put(typename Time::type time, const model_type *model) {
     typename Time::type previous_time =
-        (*model->handle()._handle).get_time();
+      (*model->handle()._handle).get_time();
 
     if (previous_time != time) {
       (*model->handle()._handle).set_time(time);
@@ -136,13 +125,11 @@ public:
     }
   }
 
-  void remove_model(model_type *model)
-  {
+  void remove_model(model_type *model) {
     type::erase(model->handle()._handle);
   }
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::stringstream ss;
 
     ss << "Scheduler = { ";
@@ -156,8 +143,8 @@ public:
   }
 };
 
-}
-}
-} // namespace artis common scheduler
+} // namespace scheduler
+
+} // namespace artis common
 
 #endif

+ 5 - 13
src/artis-star/common/scheduler/SchedulerHandle.hpp

@@ -27,24 +27,16 @@
 #ifndef COMMON_SCHEDULER_SCHEDULER_HANDLE_HPP
 #define COMMON_SCHEDULER_SCHEDULER_HANDLE_HPP
 
-namespace artis {
-namespace common {
-namespace scheduler {
+namespace artis::common::scheduler {
 
-struct NoSchedulerHandle
-{
-  NoSchedulerHandle()
-  {}
+struct NoSchedulerHandle {
+  NoSchedulerHandle() {}
 
-  const NoSchedulerHandle &handle() const
-  { return *this; }
+  const NoSchedulerHandle &handle() const { return *this; }
 
-  void handle(const NoSchedulerHandle & /* handle */)
-  {}
+  void handle(const NoSchedulerHandle & /* handle */) {}
 };
 
-}
-}
 } // namespace artis common scheduler
 
 #endif

+ 21 - 38
src/artis-star/common/scheduler/VectorScheduler.hpp

@@ -27,39 +27,31 @@
 #ifndef COMMON_SCHEDULER_VECTOR_SCHEDULER_HPP
 #define COMMON_SCHEDULER_VECTOR_SCHEDULER_HPP
 
-#include <artis-star/common/InternalEvent.hpp>
+#include "artis-star/common/event/InternalEvent.hpp"
 #include <artis-star/common/scheduler/SchedulerHandle.hpp>
 
 #include <algorithm>
 #include <sstream>
 
-namespace artis {
-namespace common {
-namespace scheduler {
+namespace artis::common::scheduler {
 
-template<class Time>
+template<typename Time>
 class VectorScheduler :
-    protected std::vector<InternalEvent<Time, NoSchedulerHandle> >
-{
+  protected std::vector<InternalEvent<Time>> {
 public:
-  VectorScheduler()
-  {}
+  VectorScheduler() {}
 
-  virtual ~VectorScheduler()
-  {}
+  virtual ~VectorScheduler() {}
 
-  Model<Time, NoSchedulerHandle> *get_current_model()
-  {
+  Model<Time> *get_current_model() {
     return VectorScheduler<Time>::front().get_model();
   }
 
-  Models<Time, NoSchedulerHandle> get_current_models(
-      typename Time::type time) const
-  {
-    Models<Time, NoSchedulerHandle> models;
+  Models<Time> get_current_models(typename Time::type time) const {
+    Models<Time> models;
 
     for (typename VectorScheduler<Time>::const_iterator it =
-        VectorScheduler<Time>::begin();
+      VectorScheduler<Time>::begin();
          it != VectorScheduler<Time>::end() and it->get_time() == time;
          ++it) {
       models.push_back(it->get_model());
@@ -67,34 +59,27 @@ public:
     return models;
   }
 
-  typename Time::type get_current_time() const
-  { return VectorScheduler<Time>::front().get_time(); }
+  typename Time::type get_current_time() const { return VectorScheduler<Time>::front().get_time(); }
 
-  void init(typename Time::type time,
-            Model<Time, NoSchedulerHandle> *model)
-  {
-    VectorScheduler<Time>::push_back(
-        InternalEvent<Time, NoSchedulerHandle>(time, model));
-    std::sort(VectorScheduler<Time>::begin(),
-              VectorScheduler<Time>::end());
+  void init(typename Time::type time, Model<Time> *model) {
+    VectorScheduler<Time>::push_back(InternalEvent<Time>(time, model));
+    std::sort(VectorScheduler<Time>::begin(), VectorScheduler<Time>::end());
   }
 
-  void put(typename Time::type time, Model<Time, NoSchedulerHandle> *model)
-  {
+  void put(typename Time::type time, Model<Time> *model) {
     remove(model);
     VectorScheduler<Time>::push_back(
-        InternalEvent<Time, NoSchedulerHandle>(time, model));
+      InternalEvent<Time>(time, model));
     std::sort(VectorScheduler<Time>::begin(),
               VectorScheduler<Time>::end());
   }
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::stringstream ss;
 
     ss << "Scheduler = { ";
     for (typename VectorScheduler<Time>::const_iterator it =
-        VectorScheduler<Time>::begin();
+      VectorScheduler<Time>::begin();
          it != VectorScheduler<Time>::end(); ++it) {
       ss << "(" << it->get_time() << " -> " << it->get_model()->get_name()
          << ") ";
@@ -104,10 +89,10 @@ public:
   }
 
 private:
-  void remove(Model<Time, NoSchedulerHandle> *model)
-  {
+
+  void remove(Model<Time> *model) {
     typename VectorScheduler<Time>::iterator jt =
-        VectorScheduler<Time>::begin();
+      VectorScheduler<Time>::begin();
 
     while (jt != VectorScheduler<Time>::end()) {
       if (jt->get_model() == model) {
@@ -119,8 +104,6 @@ private:
   }
 };
 
-}
-}
 } // namespace artis common scheduler
 
 #endif

+ 48 - 69
src/artis-star/common/Any.hpp

@@ -24,39 +24,32 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef COMMON_ANY_HPP
-#define COMMON_ANY_HPP
+#ifndef COMMON_STATE_ANY_HPP
+#define COMMON_STATE_ANY_HPP
 
-#include <artis-star/common/Value.hpp>
+#include "artis-star/common/event/Value.hpp"
 
 #include <string>
 #include <tuple>
 #include <utility>
 #include <vector>
 
-namespace artis {
-namespace common {
+namespace artis::common::state {
 
-class Any
-{
+class Any {
 private:
-  struct base
-  {
-    virtual ~base()
-    {}
+  struct base {
+    virtual ~base() {}
 
     virtual base *clone() const = 0;
   };
 
   template<typename T, typename V>
-  struct data : base
-  {
+  struct data : base {
     data(V T::* const &value)
-        : value_(value)
-    {}
+      : value_(value) {}
 
-    base *clone() const
-    { return new data<T, V>(*this); }
+    base *clone() const { return new data<T, V>(*this); }
 
     V T::* value_;
   };
@@ -65,38 +58,30 @@ private:
 
 public:
   Any()
-      : ptr_(nullptr)
-  {}
+    : ptr_(nullptr) {}
 
   template<typename T, typename V>
   Any(V T::* const &value)
-      : ptr_(new data<T, V>(value))
-  {}
+    : ptr_(new data<T, V>(value)) {}
 
   Any(Any const &other)
-      : ptr_(other.ptr_ ? other.ptr_->clone() : nullptr)
-  {}
+    : ptr_(other.ptr_ ? other.ptr_->clone() : nullptr) {}
 
-  virtual ~Any()
-  {
+  virtual ~Any() {
     if (ptr_) {
       delete ptr_;
     }
   }
 
-  void operator=(Any const &other)
-  { Any(other).swap(*this); }
+  void operator=(Any const &other) { Any(other).swap(*this); }
 
-  void swap(Any &other)
-  { std::swap(ptr_, other.ptr_); }
+  void swap(Any &other) { std::swap(ptr_, other.ptr_); }
 
   template<typename T, typename V>
-  V T::* get() const
-  { return dynamic_cast < data<T, V> * >(ptr_)->value_; }
+  V T::* get() const { return dynamic_cast < data<T, V> * >(ptr_)->value_; }
 
   template<typename T, typename V>
-  void get(T *o, V &value) const
-  {
+  void get(T *o, V &value) const {
     data<T, V> *q = dynamic_cast < data<T, V> * >(ptr_);
 
     if (q) {
@@ -106,19 +91,16 @@ public:
     }
   }
 
-  bool is_null() const
-  { return ptr_ == nullptr; }
+  bool is_null() const { return ptr_ == nullptr; }
 
   template<typename T, typename V>
-  void put(T *o, const V &value)
-  {
+  void put(T *o, const V &value) {
     V T::* p = dynamic_cast <data<T, V> * >(ptr_)->value_;
     o->*(p) = value;
   }
 
   template<typename T>
-  void restore(T *o, const common::Value &value)
-  {
+  void restore(T *o, const common::event::Value &value) {
     if (value.is_type<double>()) {
       double v;
 
@@ -165,50 +147,49 @@ public:
   }
 
   template<typename T>
-  common::Value save(const T *o) const
-  {
+  common::event::Value save(const T *o) const {
     if (ptr_) {
       data<T, double> *q_double =
-          dynamic_cast < data<T, double> * >(ptr_);
+        dynamic_cast < data<T, double> * >(ptr_);
 
       if (q_double) {
-        return common::Value(o->*(q_double->value_));
+        return common::event::Value(o->*(q_double->value_));
       } else {
         data<T, unsigned int> *q_uint =
-            dynamic_cast < data<T, unsigned int> * >(ptr_);
+          dynamic_cast < data<T, unsigned int> * >(ptr_);
 
         if (q_uint) {
-          return common::Value(o->*(q_uint->value_));
+          return common::event::Value(o->*(q_uint->value_));
         } else {
           data<T, int> *q_int =
-              dynamic_cast < data<T, int> * >(ptr_);
+            dynamic_cast < data<T, int> * >(ptr_);
 
           if (q_int) {
-            return common::Value(o->*(q_int->value_));
+            return common::event::Value(o->*(q_int->value_));
           } else {
             data<T, bool> *q_bool =
-                dynamic_cast < data<T, bool> * >(ptr_);
+              dynamic_cast < data<T, bool> * >(ptr_);
 
             if (q_bool) {
-              return common::Value(o->*(q_bool->value_));
+              return common::event::Value(o->*(q_bool->value_));
             } else {
               data<T, std::vector < double> > *q_double_v =
-                  dynamic_cast < data<T, std::vector < double> > * > (ptr_);
+                dynamic_cast < data<T, std::vector < double> > * > (ptr_);
 
               if (q_double_v) {
-                return common::Value(o->*(q_double_v->value_));
+                return common::event::Value(o->*(q_double_v->value_));
               } else {
                 data<T, std::vector < int> > *q_int_v =
-                    dynamic_cast < data<T, std::vector < int> > * > (ptr_);
+                  dynamic_cast < data<T, std::vector < int> > * > (ptr_);
 
                 if (q_int_v) {
-                  return common::Value(o->*(q_int_v->value_));
+                  return common::event::Value(o->*(q_int_v->value_));
                 } else {
                   data<T, std::vector < bool> > *q_bool_v =
-                      dynamic_cast < data<T, std::vector < bool> > * > (ptr_);
+                    dynamic_cast < data<T, std::vector < bool> > * > (ptr_);
 
                   if (q_bool_v) {
-                    return common::Value(o->*(q_bool_v->value_));
+                    return common::event::Value(o->*(q_bool_v->value_));
                   }
                 }
               }
@@ -218,54 +199,53 @@ public:
       }
     }
     assert(false);
-    return common::Value();
+    return common::event::Value();
   }
 
   template<typename T>
-  std::string to_string(const T *o) const
-  {
+  std::string to_string(const T *o) const {
     if (ptr_) {
       data<T, double> *q_double =
-          dynamic_cast < data<T, double> * >(ptr_);
+        dynamic_cast < data<T, double> * >(ptr_);
 
       if (q_double) {
         return std::to_string(o->*(q_double->value_));
       } else {
         data<T, unsigned int> *q_uint =
-            dynamic_cast < data<T, unsigned int> * >(ptr_);
+          dynamic_cast < data<T, unsigned int> * >(ptr_);
 
         if (q_uint) {
           return std::to_string(o->*(q_uint->value_));
         } else {
           data<T, int> *q_int =
-              dynamic_cast < data<T, int> * >(ptr_);
+            dynamic_cast < data<T, int> * >(ptr_);
 
           if (q_int) {
             return std::to_string(o->*(q_int->value_));
           } else {
             data<T, bool> *q_bool =
-                dynamic_cast < data<T, bool> * >(ptr_);
+              dynamic_cast < data<T, bool> * >(ptr_);
 
             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_);
+                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_);
+                  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_);
+                    dynamic_cast < data<T, std::vector <
+                                           bool> > * > (ptr_);
 
                   if (q_bool_v) {
                     return "";
@@ -284,7 +264,6 @@ public:
   }
 };
 
-}
 }
 
 #endif

+ 12 - 0
src/artis-star/common/state/CMakeLists.txt

@@ -0,0 +1,12 @@
+INCLUDE_DIRECTORIES(
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
+
+LINK_DIRECTORIES(
+        ${Boost_LIBRARY_DIRS})
+
+SET(COMMON_STATE_HPP Any.hpp States.hpp)
+
+INSTALL(FILES ${COMMON_STATE_HPP} DESTINATION
+        ${ARTIS_INCLUDE_DIRS}/common/state)

+ 29 - 44
src/artis-star/common/States.hpp

@@ -24,57 +24,46 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef COMMON_STATES_HPP
-#define COMMON_STATES_HPP
+#ifndef COMMON_STATE_STATES_HPP
+#define COMMON_STATE_STATES_HPP
 
-#include <artis-star/common/context/State.hpp>
-#include <artis-star/common/Any.hpp>
-#include <artis-star/common/Macro.hpp>
+#include "artis-star/common/context/State.hpp"
+#include "artis-star/common/state/Any.hpp"
+#include "artis-star/common/utils/Macro.hpp"
 
 #include <vector>
 
-namespace artis {
-namespace common {
+namespace artis::common::state {
 
 template<typename Time, typename Dyn>
-class States
-{
+class States {
 public:
-  template<class W>
-  struct element
-  {
+  template<typename W>
+  struct element {
     unsigned int index;
     const std::string name;
     W Dyn::* var;
 
     element(unsigned int index, const std::string &name, W Dyn::* var)
-        :
-        index(index), name(name), var(var)
-    {}
+      : index(index), name(name), var(var) {}
   };
 
-  States()
-  {}
+  States() {}
 
-  virtual ~States()
-  {}
+  virtual ~States() {}
 
-  common::Any &get(unsigned int index)
-  { return states.at(index); }
+  common::state::Any &get(unsigned int index) { return states.at(index); }
 
-  const common::Any &get(unsigned int index) const
-  { return states.at(index); }
+  const common::state::Any &get(unsigned int index) const { return states.at(index); }
 
-  unsigned int state_number() const
-  { return states.size(); }
+  unsigned int state_number() const { return states.size(); }
 
-  template<class W>
-  void S_(std::initializer_list<element<W> > list)
-  {
+  template<typename W>
+  void S_(std::initializer_list<element<W>> list) {
     for (typename std::initializer_list<element<W> >::iterator it =
-        list.begin(); it != list.end(); ++it) {
+      list.begin(); it != list.end(); ++it) {
       if (states.size() <= it->index) {
-        states.resize(it->index + 1, common::Any());
+        states.resize(it->index + 1, common::state::Any());
         state_names.resize(it->index + 1, std::string());
       }
       states[it->index] = it->var;
@@ -82,11 +71,10 @@ public:
     }
   }
 
-  virtual void restore(Dyn *model, const common::context::State<Time> &state)
-  {
+  virtual void restore(Dyn *model, const common::context::State<Time> &state) {
     unsigned int index = 0;
 
-    for (typename std::vector<common::Any>::iterator it = states.begin();
+    for (typename std::vector<common::state::Any>::iterator it = states.begin();
          it != states.end(); ++it) {
       if (not it->is_null()) {
         it->restore<Dyn>(model, state.get_state(index));
@@ -95,12 +83,11 @@ public:
     }
   }
 
-  virtual void save(const Dyn *model, common::context::State<Time> &state) const
-  {
+  virtual void save(const Dyn *model, common::context::State<Time> &state) const {
     unsigned int index = 0;
 
-    for (typename std::vector<common::Any>::const_iterator it =
-        states.begin(); it != states.end(); ++it) {
+    for (typename std::vector<common::state::Any>::const_iterator it =
+      states.begin(); it != states.end(); ++it) {
       if (not it->is_null()) {
         state.add_state(index, it->save<Dyn>(model));
       }
@@ -108,23 +95,21 @@ public:
     }
   }
 
-  template<class W>
-  void state_(unsigned int index, const std::string &name, W Dyn::* var)
-  {
+  template<typename W>
+  void state_(unsigned int index, const std::string &name, W Dyn::* var) {
     if (states.size() <= index) {
-      states.resize(index + 1, common::Any());
+      states.resize(index + 1, common::state::Any());
       state_names.resize(index + 1, std::string());
     }
-    states[index] = common::Any(var);
+    states[index] = common::state::Any(var);
     state_names[index] = name;
   }
 
 private:
-  std::vector<common::Any> states;
+  std::vector<common::state::Any> states;
   std::vector<std::string> state_names;
 };
 
-}
 }
 
 #define DECLARE_STATE(W, index, var)                                    \

+ 1 - 3
src/artis-star/common/time/DoubleTime.hpp

@@ -30,12 +30,10 @@
 #include <artis-star/common/time/Limits.hpp>
 #include <artis-star/common/time/Time.hpp>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
 typedef Time<double, Limits<double> > DoubleTime;
 
-}
 } // namespace artis common
 
 #endif

+ 1 - 3
src/artis-star/common/time/IntegerTime.hpp

@@ -32,12 +32,10 @@
 
 #include <limits>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
 typedef Time<int, Limits<int> > IntegerTime;
 
-}
 } // namespace artis common
 
 #endif

+ 2 - 5
src/artis-star/common/time/Limits.hpp

@@ -29,18 +29,15 @@
 
 #include <limits>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
 template<typename T>
-struct Limits
-{
+struct Limits {
   static constexpr T negative_infinity = std::numeric_limits<T>::lowest();
   static constexpr T positive_infinity = std::numeric_limits<T>::max();
   static constexpr T null = 0;
 };
 
-}
 } // namespace artis common
 
 #endif

+ 7 - 9
src/artis-star/common/time/RationalTime.hpp

@@ -31,21 +31,19 @@
 
 #include <boost/rational.hpp>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-struct RationalLimits
-{
+struct RationalLimits {
   static constexpr boost::rational<int>
-      negative_infinity = boost::rational<int>(std::numeric_limits<int>::lowest());
+  negative_infinity = boost::rational<int>(std::numeric_limits<int>::lowest());
   static constexpr boost::rational<int>
-      positive_infinity = boost::rational<int>(std::numeric_limits<int>::max());
-  static constexpr boost::rational<int> null = boost::rational<int>();
+  positive_infinity = boost::rational<int>(std::numeric_limits<int>::max());
+  static constexpr boost::rational<int>
+  null = boost::rational<int>();
 };
 
-typedef Time<boost::rational<int>, RationalLimits> RationalTime;
+typedef Time <boost::rational<int>, RationalLimits> RationalTime;
 
-}
 } // namespace artis common
 
 #endif

+ 2 - 5
src/artis-star/common/time/Time.hpp

@@ -27,12 +27,10 @@
 #ifndef COMMON_TIME_TIME
 #define COMMON_TIME_TIME
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
 template<typename Type, typename Limits>
-struct Time
-{
+struct Time {
   static Type negative_infinity;
   static Type infinity;
   static Type null;
@@ -48,7 +46,6 @@ Type Time<Type, Limits>::infinity = Limits::positive_infinity;
 template<typename Type, typename Limits>
 Type Time<Type, Limits>::null = Limits::null;
 
-}
 } // namespace artis common
 
 #endif

+ 1 - 1
src/artis-star/common/utils/CMakeLists.txt

@@ -6,7 +6,7 @@ INCLUDE_DIRECTORIES(
 LINK_DIRECTORIES(
         ${Boost_LIBRARY_DIRS})
 
-SET(COMMON_UTILS_HPP FormalismType.hpp FunctionType.hpp LevelType.hpp Multithreading.hpp String.hpp Trace.hpp)
+SET(COMMON_UTILS_HPP FormalismType.hpp FunctionType.hpp LevelType.hpp Macro.hpp Multithreading.hpp String.hpp Trace.hpp)
 
 INSTALL(FILES ${COMMON_UTILS_HPP} DESTINATION
         ${ARTIS_INCLUDE_DIRS}/common/utils)

+ 26 - 20
src/artis-star/common/utils/FormalismType.hpp

@@ -29,37 +29,43 @@
 
 #include <string>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-class FormalismType
-{
+class FormalismType {
 public:
-  enum Values
-  {
+  enum Values {
     NONE = 0, DEVS, DSDE, PDEVS, QSS, DTSS, GDEVS, CELLDEVS, FDDEVS, DESS, SSS
   };
 
-  static std::string to_string(const FormalismType::Values &s)
-  {
+  static std::string to_string(const FormalismType::Values &s) {
     switch (s) {
-    case NONE:return "none";
-    case DEVS:return "devs";
-    case DSDE:return "dsde";
-    case PDEVS:return "pdevs";
-    case QSS:return "qss";
-    case DTSS:return "dtss";
-    case GDEVS:return "gdevs";
-    case CELLDEVS:return "celldevs";
-    case FDDEVS:return "fddevs";
-    case DESS:return "dess";
-    case SSS:return "sss";
+      case NONE:
+        return "none";
+      case DEVS:
+        return "devs";
+      case DSDE:
+        return "dsde";
+      case PDEVS:
+        return "pdevs";
+      case QSS:
+        return "qss";
+      case DTSS:
+        return "dtss";
+      case GDEVS:
+        return "gdevs";
+      case CELLDEVS:
+        return "celldevs";
+      case FDDEVS:
+        return "fddevs";
+      case DESS:
+        return "dess";
+      case SSS:
+        return "sss";
     };
     return "";
   }
 };
 
-}
 }
 
 #endif

+ 34 - 24
src/artis-star/common/utils/FunctionType.hpp

@@ -29,42 +29,52 @@
 
 #include <string>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-class FunctionType
-{
+class FunctionType {
 public:
-  enum Values
-  {
+  enum Values {
     NONE = 0, CONSTRUCTOR, FINISH, I_MESSAGE, POST_EVENT, S_MESSAGE, Y_MESSAGE,
     DELTA_INT, DELTA_EXT, DELTA_CONF, TA, LAMBDA, START, OUTPUT, TRANSITION
   };
 
-  static std::string to_string(const FunctionType::Values &s)
-  {
+  static std::string to_string(const FunctionType::Values &s) {
     switch (s) {
-    case NONE:return "none";
-    case CONSTRUCTOR:return "constructor";
-    case FINISH:return "finish";
-    case I_MESSAGE:return "i_message";
-    case POST_EVENT:return "post_event";
-    case S_MESSAGE:return "s_message";
-    case Y_MESSAGE:return "y_message";
-    case DELTA_INT:return "delta_int";
-    case DELTA_EXT:return "delta_ext";
-    case DELTA_CONF:return "delta_conf";
-    case TA:return "ta";
-    case LAMBDA:return "lambda";
-    case START:return "start";
-    case OUTPUT:return "output";
-    case TRANSITION:return "transition";
+      case NONE:
+        return "none";
+      case CONSTRUCTOR:
+        return "constructor";
+      case FINISH:
+        return "finish";
+      case I_MESSAGE:
+        return "i_message";
+      case POST_EVENT:
+        return "post_event";
+      case S_MESSAGE:
+        return "s_message";
+      case Y_MESSAGE:
+        return "y_message";
+      case DELTA_INT:
+        return "delta_int";
+      case DELTA_EXT:
+        return "delta_ext";
+      case DELTA_CONF:
+        return "delta_conf";
+      case TA:
+        return "ta";
+      case LAMBDA:
+        return "lambda";
+      case START:
+        return "start";
+      case OUTPUT:
+        return "output";
+      case TRANSITION:
+        return "transition";
     };
     return "";
   }
 };
 
-}
 }
 
 #endif

+ 12 - 13
src/artis-star/common/utils/LevelType.hpp

@@ -29,30 +29,29 @@
 
 #include <string>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-class LevelType
-{
+class LevelType {
 public:
-  enum Values
-  {
+  enum Values {
     NONE = 0, COMMON, FORMALISM, USER
   };
 
-  static std::string to_string(const LevelType::Values &s)
-  {
+  static std::string to_string(const LevelType::Values &s) {
     switch (s) {
-    case NONE:return "none";
-    case COMMON:return "common";
-    case FORMALISM:return "formalism";
-    case USER:return "user";
+      case NONE:
+        return "none";
+      case COMMON:
+        return "common";
+      case FORMALISM:
+        return "formalism";
+      case USER:
+        return "user";
     };
     return "";
   }
 };
 
-}
 }
 
 #endif

src/artis-star/common/Macro.hpp → src/artis-star/common/utils/Macro.hpp


+ 4 - 9
src/artis-star/common/utils/Multithreading.hpp

@@ -30,23 +30,18 @@
 #include <memory>
 #include <queue>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-struct Message
-{
+struct Message {
   virtual ~Message() = default;
 };
 
-struct Close : Message
-{
+struct Close : Message {
 };
 
-class MessageQueue : public std::queue<std::shared_ptr < Message>>
-{
+class MessageQueue : public std::queue<std::shared_ptr<Message>> {
 };
 
-}
 }  // namespace artis common
 
 #endif

+ 3 - 7
src/artis-star/common/utils/String.hpp

@@ -29,14 +29,11 @@
 
 #include <string>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-class String
-{
+class String {
 public:
-  static std::string make_spaces(unsigned int number)
-  {
+  static std::string make_spaces(unsigned int number) {
     std::string str;
 
     for (unsigned int i = 0; i < number; ++i) {
@@ -46,7 +43,6 @@ public:
   }
 };
 
-}
 }  // namespace artis common
 
 #endif

+ 51 - 87
src/artis-star/common/utils/Trace.hpp

@@ -38,51 +38,38 @@
 #include <sstream>
 #include <vector>
 
-namespace artis {
-namespace common {
+namespace artis::common {
 
-template<class Time>
-class TraceElement
-{
+template<typename Time>
+class TraceElement {
 public:
   TraceElement()
-      : _time(Time::null), _formalism_type(FormalismType::NONE),
-        _function_type(FunctionType::NONE), _level_type(LevelType::NONE)
-  {}
+    : _time(Time::null), _formalism_type(FormalismType::NONE),
+      _function_type(FunctionType::NONE), _level_type(LevelType::NONE) {}
 
   TraceElement(const std::string &model_name, typename Time::type time,
                const FormalismType::Values &formalism_type,
                const FunctionType::Values &function_type, const LevelType::Values &level_type)
-      : _model_name(model_name), _time(time), _formalism_type(formalism_type),
-        _function_type(function_type), _level_type(level_type)
-  {}
+    : _model_name(model_name), _time(time), _formalism_type(formalism_type),
+      _function_type(function_type), _level_type(level_type) {}
 
-  virtual ~TraceElement()
-  {}
+  virtual ~TraceElement() {}
 
-  const std::string &get_comment() const
-  { return _comment; }
+  const std::string &get_comment() const { return _comment; }
 
-  const std::string &get_model_name() const
-  { return _model_name; }
+  const std::string &get_model_name() const { return _model_name; }
 
-  typename Time::type get_time() const
-  { return _time; }
+  typename Time::type get_time() const { return _time; }
 
-  const FormalismType::Values &get_formalism_type() const
-  { return _formalism_type; }
+  const FormalismType::Values &get_formalism_type() const { return _formalism_type; }
 
-  const FunctionType::Values &get_function_type() const
-  { return _function_type; }
+  const FunctionType::Values &get_function_type() const { return _function_type; }
 
-  const LevelType::Values &get_level_type() const
-  { return _level_type; }
+  const LevelType::Values &get_level_type() const { return _level_type; }
 
-  void set_comment(const std::string &comment)
-  { _comment = comment; }
+  void set_comment(const std::string &comment) { _comment = comment; }
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::ostringstream ss;
 
     ss << "TRACE: " << get_model_name() << " at " << get_time() << " <";
@@ -104,18 +91,14 @@ private:
   std::string _comment;
 };
 
-template<class Time>
-class TraceElements : public std::vector<TraceElement<Time> >
-{
+template<typename Time>
+class TraceElements : public std::vector<TraceElement<Time> > {
 public:
-  TraceElements()
-  {}
+  TraceElements() {}
 
-  virtual ~TraceElements()
-  {}
+  virtual ~TraceElements() {}
 
-  TraceElements filter_model_name(const std::string &model_name) const
-  {
+  TraceElements filter_model_name(const std::string &model_name) const {
     TraceElements<Time> result;
 
     std::copy_if(TraceElements<Time>::begin(),
@@ -126,8 +109,7 @@ public:
     return result;
   }
 
-  TraceElements filter_time(typename Time::type time) const
-  {
+  TraceElements filter_time(typename Time::type time) const {
     TraceElements result;
 
     std::copy_if(TraceElements<Time>::begin(),
@@ -136,8 +118,7 @@ public:
     return result;
   }
 
-  TraceElements filter_formalism_type(const FormalismType::Values &type) const
-  {
+  TraceElements filter_formalism_type(const FormalismType::Values &type) const {
     TraceElements result;
 
     std::copy_if(TraceElements<Time>::begin(),
@@ -146,8 +127,7 @@ public:
     return result;
   }
 
-  TraceElements filter_function_type(const FunctionType::Values &type) const
-  {
+  TraceElements filter_function_type(const FunctionType::Values &type) const {
     TraceElements result;
 
     std::copy_if(TraceElements<Time>::begin(),
@@ -156,8 +136,7 @@ public:
     return result;
   }
 
-  TraceElements filter_level_type(const LevelType::Values &type) const
-  {
+  TraceElements filter_level_type(const LevelType::Values &type) const {
     TraceElements result;
 
     std::copy_if(TraceElements<Time>::begin(),
@@ -166,8 +145,7 @@ public:
     return result;
   }
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::ostringstream ss;
 
     for (typename TraceElements<Time>::const_iterator it = TraceElements<Time>::begin();
@@ -185,15 +163,12 @@ public:
   }
 };
 
-template<class Time>
-class Trace
-{
+template<typename Time>
+class Trace {
 public:
-  virtual ~Trace()
-  {}
+  virtual ~Trace() {}
 
-  static Trace &trace()
-  {
+  static Trace &trace() {
 //                std::call_once(_flag, []() { _instance.reset(new Trace()); });
     if (!_instance) {
       _instance.reset(new Trace());
@@ -201,15 +176,12 @@ public:
     return *_instance;
   }
 
-  void clear()
-  { _trace.clear(); }
+  void clear() { _trace.clear(); }
 
-  const TraceElements<Time> &elements() const
-  { return _trace; }
+  const TraceElements<Time> &elements() const { return _trace; }
 
-  void flush()
-  {
-    std::lock_guard<std::mutex> lock(_mutex);
+  void flush() {
+    std::lock_guard <std::mutex> lock(_mutex);
 
     if (_sstream) {
       _element.set_comment(_sstream->str());
@@ -219,14 +191,11 @@ public:
     _trace.push_back(_element);
   }
 
-  std::mutex &mutex()
-  { return _mutex; }
+  std::mutex &mutex() { return _mutex; }
 
-  void set_element(const TraceElement<Time> &element)
-  { _element = element; }
+  void set_element(const TraceElement<Time> &element) { _element = element; }
 
-  std::ostringstream &sstream()
-  {
+  std::ostringstream &sstream() {
     if (_sstream == 0) {
       _sstream = new std::ostringstream();
     }
@@ -234,10 +203,9 @@ public:
   }
 
 private:
-  Trace()
-  { _sstream = 0; }
+  Trace() { _sstream = 0; }
 
-  static std::shared_ptr<Trace<Time> > _instance;
+  static std::shared_ptr <Trace<Time>> _instance;
 //            static std::once_flag _flag;
 
   TraceElements<Time> _trace;
@@ -246,41 +214,37 @@ private:
   std::mutex _mutex;
 };
 
-}
 } // namespace artis common
 
-template<class Time>
+template<typename Time>
 artis::common::Trace<Time> &
-operator<<(artis::common::Trace<Time> &trace, const artis::common::TraceElement<Time> &e)
-{
-  std::lock_guard<std::mutex> lock(trace.mutex());
+operator<<(artis::common::Trace<Time> &trace, const artis::common::TraceElement<Time> &e) {
+  std::lock_guard <std::mutex> lock(trace.mutex());
 
   trace.set_element(e);
   return trace;
 }
 
-template<class Time>
-artis::common::Trace<Time> &operator<<(artis::common::Trace<Time> &trace, const std::string &str)
-{
-  std::lock_guard<std::mutex> lock(trace.mutex());
+template<typename Time>
+artis::common::Trace<Time> &operator<<(artis::common::Trace<Time> &trace, const std::string &str) {
+  std::lock_guard <std::mutex> lock(trace.mutex());
 
   trace.sstream() << str;
   return trace;
 }
 
-template<class Time>
-artis::common::Trace<Time> &operator<<(artis::common::Trace<Time> &trace, typename Time::type t)
-{
-  std::lock_guard<std::mutex> lock(trace.mutex());
+template<typename Time>
+artis::common::Trace<Time> &operator<<(artis::common::Trace<Time> &trace, typename Time::type t) {
+  std::lock_guard <std::mutex> lock(trace.mutex());
 
   trace.sstream() << t;
   return trace;
 }
 
-template<class Time>
-std::shared_ptr<artis::common::Trace<Time> > artis::common::Trace<Time>::_instance = nullptr;
+template<typename Time>
+std::shared_ptr <artis::common::Trace<Time>> artis::common::Trace<Time>::_instance = nullptr;
 
-//template<class Time>
+//template<typename Time>
 //std::once_flag artis::common::Trace<Time>::_flag;
 
 #endif

+ 37 - 56
src/artis-star/kernel/devs/Coordinator.hpp

@@ -35,16 +35,14 @@
 
 #include <cassert>
 
-namespace artis {
-namespace devs {
-
-template<class Time,
-    class GraphManager,
-    class Select,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
-class Coordinator : public common::Coordinator<Time>
-{
+namespace artis::devs {
+
+template<typename Time,
+  typename GraphManager,
+  typename Select,
+  typename Parameters = common::NoParameters,
+  typename GraphParameters = common::NoParameters>
+class Coordinator : public common::Coordinator<Time> {
   typedef Coordinator<Time, GraphManager, Parameters, GraphParameters> type;
 
 public:
@@ -53,23 +51,19 @@ public:
 
   Coordinator(const std::string &name, const Parameters &parameters,
               const GraphParameters &graph_parameters)
-      :
-      common::Model<Time>(name),
-      common::Coordinator<Time>(name),
-      _graph_manager(this, parameters, graph_parameters),
-      _d_star(nullptr)
-  {}
+    :
+    common::Model<Time>(name),
+    common::Coordinator<Time>(name),
+    _graph_manager(this, parameters, graph_parameters),
+    _d_star(nullptr) {}
 
   virtual ~Coordinator() = default;
 
-  GraphManager &get_graph_manager()
-  { return _graph_manager; }
+  GraphManager &get_graph_manager() { return _graph_manager; }
 
-  const GraphManager &get_graph_manager() const
-  { return _graph_manager; }
+  const GraphManager &get_graph_manager() const { return _graph_manager; }
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     std::ostringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "p-devs coordinator \""
@@ -78,16 +72,14 @@ public:
     return ss.str();
   }
 
-  void restore(const common::context::State<Time> &state)
-  {
+  void restore(const common::context::State<Time> &state) {
     common::Coordinator<Time>::restore(state);
-    for (auto &child : _graph_manager.children()) {
+    for (auto &child: _graph_manager.children()) {
       _event_table.init(child->get_tn(), child);
     }
   }
 
-  virtual void finish(const typename Time::type &t)
-  {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
     (void) t;
 #else
@@ -100,8 +92,7 @@ public:
 #endif
   }
 
-  typename Time::type start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message (i, t) at time t
 //                  for-each d ∈ D do
 //                    send i-message (i, t) to child d
@@ -123,7 +114,7 @@ public:
 
     assert(_graph_manager.children().size() > 0);
 
-    for (auto &child : _graph_manager.children()) {
+    for (auto &child: _graph_manager.children()) {
       _event_table.init(child->start(t), child);
     }
     this->_tl = t;
@@ -143,8 +134,7 @@ public:
     return this->_tn;
   }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
 //                When *-message (*, t)
 //                  if t != tn then Error
 //                  d* = first({d | (d, th,d) ∈ (event-list & tn,d = tn) })
@@ -193,8 +183,7 @@ public:
 
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message (x, t)
 //                  if not (tl <= t <= tn) then Error
 //                  receivers = { r | r ∈ D, N ∈ Ir, Z(N,r)(x) isn't empty }
@@ -233,7 +222,7 @@ public:
     common::Trace<Time>::trace().flush();
 #endif
 
-    for (auto &model : receivers) {
+    for (auto &model: receivers) {
       _event_table.put(model->transition(t), model);
     }
     if (_d_star) {
@@ -261,8 +250,7 @@ public:
   }
 
   void post_event(const typename Time::type &t,
-                  const common::ExternalEvent<Time> &event)
-  {
+                  const common::event::ExternalEvent<Time> &event) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -291,9 +279,8 @@ public:
 
   }
 
-  typename Time::type dispatch_events(const common::Bag<Time> &bag,
-                                      const typename Time::type &t)
-  {
+  typename Time::type dispatch_events(const common::event::Bag<Time> &bag,
+                                      const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -325,24 +312,21 @@ public:
     return this->_tn;
   }
 
-  common::Value observe(const typename Time::type & /* t */,
-                        unsigned int /* index */) const
-  {
+  common::event::Value observe(const typename Time::type & /* t */,
+                        unsigned int /* index */) const {
     assert(false);
-    return common::Value();
+    return common::event::Value();
   }
 
-  typename Time::type lookahead(const typename Time::type &t) const
-  {
+  typename Time::type lookahead(const typename Time::type &t) const {
     return _graph_manager.lookahead(t);
   }
 
   common::Models<Time> get_imm_without_receivers(const common::Models<Time> &IMM,
-                                                 const common::Models<Time> &receivers) const
-  {
+                                                 const common::Models<Time> &receivers) const {
     common::Models<Time> imm;
 
-    for (auto &model : IMM) {
+    for (auto &model: IMM) {
       if (std::find(receivers.begin(), receivers.end(),
                     model) == receivers.end()) {
         imm.push_back(model);
@@ -351,11 +335,10 @@ public:
     return imm;
   }
 
-  common::Models<Time> get_receivers() const
-  {
+  common::Models<Time> get_receivers() const {
     common::Models<Time> receivers;
 
-    for (auto &model : _graph_manager.children()) {
+    for (auto &model: _graph_manager.children()) {
       if (model->event_number() > 0) {
         receivers.push_back(model);
       }
@@ -363,9 +346,8 @@ public:
     return receivers;
   }
 
-  void update_event_table(typename Time::type t)
-  {
-    for (auto &model : _graph_manager.children()) {
+  void update_event_table(typename Time::type t) {
+    for (auto &model: _graph_manager.children()) {
       if (model->event_number() > 0) {
         _event_table.put(t, model);
       }
@@ -378,7 +360,6 @@ protected:
   common::Model<Time> *_d_star;
 };
 
-}
 } // namespace artis devs
 
 #endif

+ 27 - 46
src/artis-star/kernel/devs/Dynamics.hpp

@@ -27,23 +27,20 @@
 #ifndef DEVS_DYNAMICS
 #define DEVS_DYNAMICS
 
-#include <artis-star/common/Bag.hpp>
-#include <artis-star/common/ExternalEvent.hpp>
+#include "artis-star/common/event/Bag.hpp"
+#include "artis-star/common/event/ExternalEvent.hpp"
 #include <artis-star/common/Parameters.hpp>
-#include <artis-star/common/States.hpp>
+#include "artis-star/common/state/States.hpp"
 #include <artis-star/kernel/devs/Simulator.hpp>
 
-namespace artis {
-namespace devs {
+namespace artis::devs {
 
-template<class Time, class Dyn, class Parameters = common::NoParameters>
-class Dynamics : public common::States<Time, Dyn>
-{
+template<typename Time, typename Dyn, typename Parameters = common::NoParameters>
+class Dynamics : public common::state::States<Time, Dyn> {
   typedef devs::Simulator<Time, Dyn, Parameters> Simulator;
 
 public:
-  struct Observable
-  {
+  struct Observable {
     unsigned int index;
     std::string name;
   };
@@ -51,48 +48,36 @@ public:
   typedef std::map<unsigned int, std::string> Observables;
 
   Dynamics(const std::string &name, const Context<Time, Dyn, Parameters> &context)
-      :
-      _name(name), _simulator(context.simulator())
-  {}
+    :
+    _name(name), _simulator(context.simulator()) {}
 
-  virtual ~Dynamics()
-  {}
+  virtual ~Dynamics() {}
 
-  virtual void dint(typename Time::type /* t */)
-  {}
+  virtual void dint(typename Time::type /* t */) {}
 
   virtual void dext(typename Time::type /* t */, typename Time::type /* e */,
-                    const common::ExternalEvent<Time> & /* event */)
-  {}
+                    const common::event::ExternalEvent<Time> & /* event */) {}
 
-  virtual void start(typename Time::type /* time */)
-  {}
+  virtual void start(typename Time::type /* time */) {}
 
   virtual typename Time::type
-  ta(typename Time::type /* time */) const
-  { return Time::infinity; }
+  ta(typename Time::type /* time */) const { return Time::infinity; }
 
-  virtual common::ExternalEvent<Time>
-  lambda(typename Time::type /* time */) const
-  { return common::ExternalEvent<Time>(); }
+  virtual common::event::ExternalEvent<Time>
+  lambda(typename Time::type /* time */) const { return common::event::ExternalEvent<Time>(); }
 
-  virtual common::Value observe(const typename Time::type & /* t */,
-                                unsigned int /* index */) const
-  { return common::Value(); }
+  virtual common::event::Value observe(const typename Time::type & /* t */,
+                                       unsigned int /* index */) const { return common::event::Value(); }
 
-  virtual typename Time::type lookahead(const typename Time::type &t) const
-  { return t; }
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
-  const std::string &get_name() const
-  { return _name; }
+  const std::string &get_name() const { return _name; }
 
-  void observable(Observable observable)
-  {
+  void observable(Observable observable) {
     _observables[observable.index] = observable.name;
   }
 
-  void observables(std::initializer_list<Observable> list)
-  {
+  void observables(std::initializer_list<Observable> list) {
     for (typename std::initializer_list<Observable>::iterator it = list.begin();
          it != list.end();
          ++it) {
@@ -100,21 +85,18 @@ public:
     }
   }
 
-  virtual std::string observable_name(unsigned int observable_index) const
-  {
+  virtual std::string observable_name(unsigned int observable_index) const {
     assert(_observables.find(observable_index) != _observables.end());
 
     return _observables.find(observable_index)->second;
   }
 
-  void restore(const common::context::State<Time> &state)
-  {
-    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+  void restore(const common::context::State<Time> &state) {
+    common::state::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
   }
 
-  void save(common::context::State<Time> &state) const
-  {
-    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+  void save(common::context::State<Time> &state) const {
+    common::state::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
   }
 
 private:
@@ -123,7 +105,6 @@ private:
   Observables _observables;
 };
 
-}
 } // namespace artis devs
 
 #endif

+ 27 - 38
src/artis-star/kernel/devs/GraphManager.hpp

@@ -35,14 +35,12 @@
 
 #include <sstream>
 
-namespace artis {
-namespace devs {
-
-template<class Time,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
-class GraphManager : public common::GraphManager<Time>
-{
+namespace artis::devs {
+
+template<typename Time,
+  typename Parameters = common::NoParameters,
+  typename GraphParameters = common::NoParameters>
+class GraphManager : public common::GraphManager<Time> {
 public:
   typedef GraphManager<Time, Parameters, GraphParameters> type;
   typedef std::pair<common::Model<Time> *, common::Model<Time> *> Link;
@@ -51,15 +49,13 @@ public:
   GraphManager(common::Coordinator<Time> *coordinator,
                const Parameters & /* parameters */,
                const GraphParameters & /* graph_parameters */)
-      :
-      common::GraphManager<Time>(coordinator)
-  {}
+    :
+    common::GraphManager<Time>(coordinator) {}
 
   ~GraphManager() override = default;
 
-  void dispatch_events(common::Bag<Time> bag, typename Time::type t)
-  {
-    for (auto &ymsg : bag) {
+  void dispatch_events(common::event::Bag<Time> bag, typename Time::type t) {
+    for (auto &ymsg: bag) {
       auto it = std::find_if(_links.begin(), _links.end(),
                              [&ymsg](const Link &link) { return link.first == ymsg.get_model(); });
 
@@ -68,35 +64,31 @@ public:
         if (it->second == common::GraphManager<Time>::_coordinator) {
           dispatch_events_to_parent(ymsg.data(), t);
         } else { // event on input port of internal model
-          it->second->post_event(t, common::ExternalEvent<Time>(ymsg.data()));
+          it->second->post_event(t, common::event::ExternalEvent<Time>(ymsg.data()));
         }
       }
     }
   }
 
   virtual void
-  dispatch_events_to_parent(const common::Value &content, typename Time::type t)
-  {
-    common::Bag<Time> ymessages;
+  dispatch_events_to_parent(const common::event::Value &content, typename Time::type t) {
+    common::event::Bag<Time> ymessages;
 
-    ymessages.push_back(common::ExternalEvent<Time>(content));
+    ymessages.push_back(common::event::ExternalEvent<Time>(content));
     if (common::GraphManager<Time>::_coordinator->get_parent()) {
       dynamic_cast < common::Coordinator<Time> * >(common::GraphManager<Time>::_coordinator
-          ->get_parent())
-          ->dispatch_events(ymessages, t);
+        ->get_parent())
+        ->dispatch_events(ymessages, t);
     }
   }
 
-  bool exist_link(common::Model<Time> *src_model, common::Model<Time> *dst_model) const
-  {
+  bool exist_link(common::Model<Time> *src_model, common::Model<Time> *dst_model) const {
     return _links.find(std::make_pair(src_model, dst_model));
   }
 
-  virtual typename Time::type lookahead(const typename Time::type &t) const
-  { return t; }
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
-  void post_event(typename Time::type t, const common::ExternalEvent<Time> &event)
-  {
+  void post_event(typename Time::type t, const common::event::ExternalEvent<Time> &event) {
     auto it = std::find_if(_links.begin(), _links.end(),
                            [this](const Link &link) {
                              return link.first == common::GraphManager<Time>::_coordinator;
@@ -104,16 +96,15 @@ public:
 
     if (it != _links.end()) {
       it->second->post_event(t,
-                             common::ExternalEvent<Time>(event.data()));
+                             common::event::ExternalEvent<Time>(event.data()));
     }
   }
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     std::ostringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "Children :" << std::endl;
-    for (auto &child : common::GraphManager<Time>::_children) {
+    for (auto &child: common::GraphManager<Time>::_children) {
       ss << child->to_string(level + 1);
     }
     ss << common::String::make_spaces(level * 2) << "Links:" << std::endl;
@@ -125,14 +116,13 @@ public:
     return ss.str();
   }
 
-  void add_link(common::Model<Time> *src_model, common::Model<Time> *dst_model)
-  {
+  void add_link(common::Model<Time> *src_model, common::Model<Time> *dst_model) {
     assert((src_model != common::GraphManager<Time>::_coordinator and
-        dst_model != common::GraphManager<Time>::_coordinator and
-        src_model != dst_model) or
-        (src_model == common::GraphManager<Time>::_coordinator and
+            dst_model != common::GraphManager<Time>::_coordinator and
+            src_model != dst_model) or
+           (src_model == common::GraphManager<Time>::_coordinator and
             dst_model != common::GraphManager<Time>::_coordinator) or
-        (src_model != common::GraphManager<Time>::_coordinator and
+           (src_model != common::GraphManager<Time>::_coordinator and
             dst_model == common::GraphManager<Time>::_coordinator));
 
     _links.push_back(std::make_pair(src_model, dst_model));
@@ -142,7 +132,6 @@ private:
   Links _links;
 };
 
-}
 } // namespace artis devs
 
 #endif

+ 33 - 55
src/artis-star/kernel/devs/Simulator.hpp

@@ -33,72 +33,59 @@
 #include <artis-star/common/utils/String.hpp>
 #include <artis-star/common/utils/Trace.hpp>
 
-namespace artis {
-namespace devs {
+namespace artis::devs {
 
-template<class Time, class Dynamics, class Parameters>
+template<typename Time, typename Dynamics, typename Parameters>
 class Simulator;
 
-template<class Time, class Dynamics,
-    class Parameters = common::NoParameters>
-class Context
-{
+template<typename Time, typename Dynamics,
+  class Parameters = common::NoParameters>
+class Context {
   typedef devs::Simulator<Time, Dynamics, Parameters> Simulator;
 
 public:
   Context(const Parameters &parameters, Simulator *simulator)
-      :
-      _parameters(parameters), _simulator(simulator)
-  {}
+    :
+    _parameters(parameters), _simulator(simulator) {}
 
-  virtual ~Context()
-  {}
+  virtual ~Context() {}
 
-  const Parameters &parameters() const
-  { return _parameters; }
+  const Parameters &parameters() const { return _parameters; }
 
-  Simulator *simulator() const
-  { return _simulator; }
+  Simulator *simulator() const { return _simulator; }
 
 private:
   const Parameters &_parameters;
   Simulator *_simulator;
 };
 
-template<class Time, class Dynamics,
-    class Parameters = common::NoParameters>
-class Simulator : public common::Simulator<Time>
-{
+template<typename Time, typename Dynamics,
+  typename Parameters = common::NoParameters>
+class Simulator : public common::Simulator<Time> {
   typedef Simulator<Time, Dynamics, Parameters> type;
 
 public :
   Simulator(const std::string &name, const Parameters &parameters)
-      :
-      common::Model<Time>(name),
-      common::Simulator<Time>(name),
-      _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this))
-  {}
+    :
+    common::Model<Time>(name),
+    common::Simulator<Time>(name),
+    _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)) {}
 
-  ~Simulator() override
-  {}
+  ~Simulator() override {}
 
-  const Dynamics &dynamics() const
-  { return _dynamics; }
+  const Dynamics &dynamics() const { return _dynamics; }
 
-  virtual void restore(const common::context::State<Time> &state)
-  {
+  virtual void restore(const common::context::State<Time> &state) {
     common::Simulator<Time>::restore(state);
     _dynamics.restore(state);
   }
 
-  virtual void save(common::context::State<Time> &state) const
-  {
+  virtual void save(common::context::State<Time> &state) const {
     common::Simulator<Time>::save(state);
     _dynamics.save(state);
   }
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     std::ostringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "p-devs simulator \""
@@ -106,8 +93,7 @@ public :
     return ss.str();
   }
 
-  virtual void finish(const typename Time::type &t)
-  {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
     (void) t;
 #else
@@ -120,8 +106,7 @@ public :
 #endif
   }
 
-  typename Time::type start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message(t)
 //                  tl = t - e
 //                  tn = tl + ta(s)
@@ -161,17 +146,14 @@ public :
     return type::_tn;
   }
 
-  common::Value observe(const typename Time::type &t,
-                        unsigned int index) const
-  { return _dynamics.observe(t, index); }
+  common::event::Value observe(const typename Time::type &t,
+                               unsigned int index) const { return _dynamics.observe(t, index); }
 
-  virtual std::string observable_name(unsigned int observable_index) const
-  {
+  virtual std::string observable_name(unsigned int observable_index) const {
     return _dynamics.observable_name(observable_index);
   }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
 //                When *-message(t)
 //                  if (t != tn) then Error
 //                  y = lambda(s)
@@ -190,12 +172,12 @@ public :
 
     assert(t == type::_tn);
 
-    common::ExternalEvent<Time> event(_dynamics.lambda(t));
+    common::event::ExternalEvent<Time> event(_dynamics.lambda(t));
 
     if (not event.is_void()) {
       event.set_model(this);
       dynamic_cast < common::Coordinator<Time> * >(
-          type::get_parent())->dispatch_events(common::Bag<Time>(event), t);
+        type::get_parent())->dispatch_events(common::event::Bag<Time>(event), t);
     }
 
 #ifdef WITH_TRACE
@@ -210,8 +192,7 @@ public :
 
   }
 
-  void post_event(const typename Time::type &t, const common::ExternalEvent<Time> &event)
-  {
+  void post_event(const typename Time::type &t, const common::event::ExternalEvent<Time> &event) {
 
 #ifndef WITH_TRACE
     (void) t;
@@ -228,8 +209,7 @@ public :
     type::add_event(event);
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message(t)
 //                  if not (tl <= t <= tn) then Error
 //                  if (x is empty and t = tn) then
@@ -288,8 +268,7 @@ public :
     return type::_tn;
   }
 
-  typename Time::type lookahead(const typename Time::type &t) const
-  {
+  typename Time::type lookahead(const typename Time::type &t) const {
     return _dynamics.lookahead(t);
   }
 
@@ -297,7 +276,6 @@ private :
   Dynamics _dynamics;
 };
 
-}
 } // namespace artis devs
 
 #endif

+ 40 - 59
src/artis-star/kernel/dsde/Coordinator.hpp

@@ -38,16 +38,14 @@
 
 #include <cassert>
 
-namespace artis {
-namespace dsde {
-
-template<class Time,
-    class GraphManager,
-    class Executive,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
-class Coordinator : public common::Coordinator<Time>
-{
+namespace artis::dsde {
+
+template<typename Time,
+  typename GraphManager,
+  typename Executive,
+  typename Parameters = common::NoParameters,
+  typename GraphParameters = common::NoParameters>
+class Coordinator : public common::Coordinator<Time> {
   typedef Coordinator<Time, GraphManager, Executive, Parameters, GraphParameters> type;
 
 public:
@@ -56,26 +54,21 @@ public:
 
   Coordinator(const std::string &name, const Parameters &parameters,
               const GraphParameters &graph_parameters)
-      :
-      common::Model<Time>(name),
-      common::Coordinator<Time>(name),
-      _graph_manager(this, parameters, graph_parameters),
-      _executive(parameters, graph_parameters, _graph_manager)
-  {
+    :
+    common::Model<Time>(name),
+    common::Coordinator<Time>(name),
+    _graph_manager(this, parameters, graph_parameters),
+    _executive(parameters, graph_parameters, _graph_manager) {
     _graph_manager.add_child(0, &_executive);
   }
 
-  virtual ~Coordinator()
-  {}
+  virtual ~Coordinator() {}
 
-  GraphManager &get_graph_manager()
-  { return _graph_manager; }
+  GraphManager &get_graph_manager() { return _graph_manager; }
 
-  const GraphManager &get_graph_manager() const
-  { return _graph_manager; }
+  const GraphManager &get_graph_manager() const { return _graph_manager; }
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     std::ostringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "dsde coordinator \""
@@ -84,16 +77,14 @@ public:
     return ss.str();
   }
 
-  void restore(const common::context::State<Time> &state)
-  {
+  void restore(const common::context::State <Time> &state) {
     common::Coordinator<Time>::restore(state);
-    for (auto &child : _graph_manager.children()) {
+    for (auto &child: _graph_manager.children()) {
       _event_table.init(child->get_tn(), child);
     }
   }
 
-  virtual void finish(const typename Time::type &t)
-  {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
     (void) t;
 #endif
@@ -108,8 +99,7 @@ public:
 #endif
   }
 
-  typename Time::type start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
 //             Network Simulator Start Message
 //                When receive (START,t)
 //                  send (START,t) to {I | I ∈ C}
@@ -130,7 +120,7 @@ public:
 
     assert(_graph_manager.children().size() > 0);
 
-    for (auto &child : _graph_manager.children()) {
+    for (auto &child: _graph_manager.children()) {
       _event_table.init(child->start(t), child);
     }
     type::_tl = t;
@@ -150,8 +140,7 @@ public:
     return type::_tn;
   }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
 //             Network Simulator Output Function
 //                When receive (OUTPUT,t)
 //                  if t = tn then
@@ -175,7 +164,7 @@ public:
 
     assert(t == type::_tn);
 
-    common::Models<Time> I_N = _event_table.get_current_models(t);
+    common::Models <Time> I_N = _event_table.get_current_models(t);
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -187,7 +176,7 @@ public:
     common::Trace<Time>::trace().flush();
 #endif
 
-    for (auto &model : I_N) {
+    for (auto &model: I_N) {
       model->output(t);
     }
 
@@ -204,8 +193,7 @@ public:
 
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
 //             Network Simulator Transition
 //                When receive (TRANSITION,t,x)
 //                  if t ∉ [tl ,tn ] then ERROR endIf
@@ -231,7 +219,7 @@ public:
 
     assert(t >= type::_tl and t <= type::_tn);
 
-    common::Models<Time> receivers = _event_table.get_current_models(t);
+    common::Models <Time> receivers = _event_table.get_current_models(t);
 
     add_models_with_inputs(receivers);
 
@@ -247,7 +235,7 @@ public:
 
     bool found = false;
 
-    for (auto &model : receivers) {
+    for (auto &model: receivers) {
       if (model != &_executive) {
         _event_table.put(model->transition(t), model);
       } else {
@@ -258,7 +246,7 @@ public:
       _event_table.put(_executive.transition(t), &_executive);
 
       if (not _graph_manager.new_models().empty()) {
-        for (auto &child : _graph_manager.new_models()) {
+        for (auto &child: _graph_manager.new_models()) {
           _event_table.init(child->start(t), child);
         }
         _graph_manager.clear_new_models();
@@ -285,8 +273,7 @@ public:
   }
 
   void post_event(const typename Time::type &t,
-                  const common::ExternalEvent<Time> &event)
-  {
+                  const common::event::ExternalEvent <Time> &event) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -316,9 +303,8 @@ public:
   }
 
   typename Time::type dispatch_events(
-      const common::Bag<Time> &bag,
-      const typename Time::type &t)
-  {
+    const common::event::Bag <Time> &bag,
+    const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -350,16 +336,14 @@ public:
     return type::_tn;
   }
 
-  common::Value observe(const typename Time::type & /* t */,
-                        unsigned int /* index */) const
-  {
+  common::event::Value observe(const typename Time::type & /* t */,
+                        unsigned int /* index */) const {
     assert(false);
-    return common::Value();
+    return common::event::Value();
   }
 
-  void add_models_with_inputs(common::Models<Time> &receivers)
-  {
-    for (auto &model : _graph_manager.children()) {
+  void add_models_with_inputs(common::Models <Time> &receivers) {
+    for (auto &model: _graph_manager.children()) {
       if (model->event_number() > 0) {
         if (std::find(receivers.begin(), receivers.end(), model)
             == receivers.end()) {
@@ -369,15 +353,13 @@ public:
     }
   }
 
-  void remove_model(const typename Time::type &t, common::Model<Time> *model) override
-  {
+  void remove_model(const typename Time::type &t, common::Model <Time> *model) override {
     common::Coordinator<Time>::remove_model(t, model);
     _event_table.remove_model(model);
   }
 
-  void update_event_table(typename Time::type t)
-  {
-    for (auto &model : _graph_manager.children()) {
+  void update_event_table(typename Time::type t) {
+    for (auto &model: _graph_manager.children()) {
       if (model->event_number() > 0) {
         _event_table.put(t, model);
       }
@@ -390,7 +372,6 @@ protected:
   common::SchedulerType _event_table;
 };
 
-}
 } // namespace artis dsde
 
 #endif

+ 63 - 100
src/artis-star/kernel/dsde/Executive.hpp

@@ -30,38 +30,31 @@
 #include <artis-star/kernel/dsde/GraphManager.hpp>
 #include <artis-star/kernel/pdevs/Dynamics.hpp>
 
-namespace artis {
-namespace dsde {
+namespace artis::dsde {
 
-template<class Time, class Dynamics, class Parameters, class GraphParameters>
+template<typename Time, typename Dynamics, typename Parameters, typename GraphParameters>
 class ExecutiveSimulator;
 
-template<class Time, class Dynamics,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
-class ExecutiveContext
-{
+template<typename Time, typename Dynamics,
+  typename Parameters = common::NoParameters,
+  typename GraphParameters = common::NoParameters>
+class ExecutiveContext {
   typedef ExecutiveSimulator<Time, Dynamics, Parameters, GraphParameters> Simulator;
 
 public:
   ExecutiveContext(const Parameters &parameters, const GraphParameters &graph_parameters,
                    Simulator *simulator)
-      :
-      _parameters(parameters), _graph_parameters(graph_parameters),
-      _simulator(simulator)
-  {}
+    :
+    _parameters(parameters), _graph_parameters(graph_parameters),
+    _simulator(simulator) {}
 
-  virtual ~ExecutiveContext()
-  {}
+  virtual ~ExecutiveContext() {}
 
-  const GraphParameters &graph_parameters() const
-  { return _graph_parameters; }
+  const GraphParameters &graph_parameters() const { return _graph_parameters; }
 
-  const Parameters &parameters() const
-  { return _parameters; }
+  const Parameters &parameters() const { return _parameters; }
 
-  Simulator *simulator() const
-  { return _simulator; }
+  Simulator *simulator() const { return _simulator; }
 
 private:
   const Parameters &_parameters;
@@ -69,44 +62,37 @@ private:
   Simulator *_simulator;
 };
 
-template<class Time, class Dynamics,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
-class ExecutiveSimulator : public common::Simulator<Time>
-{
+template<typename Time, typename Dynamics,
+  typename Parameters = common::NoParameters,
+  typename GraphParameters = common::NoParameters>
+class ExecutiveSimulator : public common::Simulator<Time> {
   typedef ExecutiveSimulator<Time, Dynamics, Parameters, GraphParameters> type;
 
 public :
   ExecutiveSimulator(const Parameters &parameters,
                      const GraphParameters &graph_parameters,
                      GraphManager<Time, Parameters, GraphParameters> &graph_manager)
-      :
-      common::Model<Time>("executive"),
-      common::Simulator<Time>("executive"),
-      _dynamics(ExecutiveContext<Time, Dynamics, Parameters, GraphParameters>(
-          parameters, graph_parameters, this), graph_manager)
-  {}
+    :
+    common::Model<Time>("executive"),
+    common::Simulator<Time>("executive"),
+    _dynamics(ExecutiveContext<Time, Dynamics, Parameters, GraphParameters>(
+      parameters, graph_parameters, this), graph_manager) {}
 
-  ~ExecutiveSimulator()
-  {}
+  ~ExecutiveSimulator() {}
 
-  const Dynamics &dynamics() const
-  { return _dynamics; }
+  const Dynamics &dynamics() const { return _dynamics; }
 
-  virtual void restore(const common::context::State<Time> &state)
-  {
+  virtual void restore(const common::context::State<Time> &state) {
     common::Simulator<Time>::restore(state);
     _dynamics.restore(state);
   }
 
-  virtual void save(common::context::State<Time> &state) const
-  {
+  virtual void save(common::context::State<Time> &state) const {
     common::Simulator<Time>::save(state);
     _dynamics.save(state);
   }
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     std::ostringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "executive simulator \""
@@ -114,8 +100,7 @@ public :
     return ss.str();
   }
 
-  virtual void finish(const typename Time::type &t)
-  {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
     (void) t;
 #endif
@@ -130,8 +115,7 @@ public :
 #endif
   }
 
-  typename Time::type start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message(t)
 //                  tl = t - e
 //                  tn = tl + ta(s)
@@ -165,12 +149,10 @@ public :
     return type::_tn;
   }
 
-  common::Value observe(const typename Time::type &t,
-                        unsigned int index) const
-  { return _dynamics.observe(t, index); }
+  common::event::Value observe(const typename Time::type &t,
+                               unsigned int index) const { return _dynamics.observe(t, index); }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
 //                When *-message(t)
 //                  if (t = tn) then
 //                    y = lambda(s)
@@ -188,14 +170,14 @@ public :
 #endif
 
     if (t == type::_tn) {
-      common::Bag<Time> bag = _dynamics.lambda(t);
+      common::event::Bag<Time> bag = _dynamics.lambda(t);
 
       if (not bag.empty()) {
-        for (auto &event : bag) {
+        for (auto &event: bag) {
           event.set_model(this);
         }
         dynamic_cast < common::Coordinator<Time> * >(
-            type::get_parent())->dispatch_events(bag, t);
+          type::get_parent())->dispatch_events(bag, t);
       }
     }
 
@@ -212,8 +194,7 @@ public :
   }
 
   void post_event(const typename Time::type &t,
-                  const common::ExternalEvent<Time> &event)
-  {
+                  const common::event::ExternalEvent<Time> &event) {
 
 #ifndef WITH_TRACE
     (void) t;
@@ -243,8 +224,7 @@ public :
 
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message(t)
 //                  if (x is empty and t = tn) then
 //                    s = delta_int(s)
@@ -300,59 +280,46 @@ private :
   Dynamics _dynamics;
 };
 
-template<class Time, class Dyn, class Parameters = common::NoParameters, class GraphParameters = common::NoParameters>
-class ExecutiveDynamics : public common::States<Time, Dyn>
-{
+template<typename Time, typename Dyn, class Parameters = common::NoParameters, class GraphParameters = common::NoParameters>
+class ExecutiveDynamics : public common::state::States<Time, Dyn> {
   typedef dsde::ExecutiveSimulator<Time, Dyn, Parameters, GraphParameters> Simulator;
 
 public:
   ExecutiveDynamics(
-      const ExecutiveContext<Time, Dyn, Parameters, GraphParameters> &context)
-      :
-      _simulator(context.simulator()), _name("executive")
-  {}
+    const ExecutiveContext<Time, Dyn, Parameters, GraphParameters> &context)
+    :
+    _simulator(context.simulator()), _name("executive") {}
 
-  virtual ~ExecutiveDynamics()
-  {}
+  virtual ~ExecutiveDynamics() {}
 
   virtual void dconf(typename Time::type /* t */, typename Time::type /* e */,
-                     const common::Bag<Time> & /* bag */)
-  {}
+                     const common::event::Bag<Time> & /* bag */) {}
 
-  virtual void dint(typename Time::type /* t */)
-  {}
+  virtual void dint(typename Time::type /* t */) {}
 
   virtual void dext(typename Time::type /* t */, typename Time::type /* e */,
-                    const common::Bag<Time> & /* bag */)
-  {}
+                    const common::event::Bag<Time> & /* bag */) {}
 
   virtual typename Time::type
-  start(typename Time::type /* time */)
-  { return Time::infinity; }
+  start(typename Time::type /* time */) { return Time::infinity; }
 
   virtual typename Time::type
-  ta(typename Time::type /* time */) const
-  { return Time::infinity; }
+  ta(typename Time::type /* time */) const { return Time::infinity; }
 
-  virtual common::Bag<Time>
-  lambda(typename Time::type /* time */) const
-  { return common::Bag<Time>(); }
+  virtual common::event::Bag<Time>
+  lambda(typename Time::type /* time */) const { return common::event::Bag<Time>(); }
 
-  virtual common::Value observe(const typename Time::type & /* t */,
-                                unsigned int /* index */) const
-  { return common::Value(); }
+  virtual common::event::Value observe(const typename Time::type & /* t */,
+                                       unsigned int /* index */) const { return common::event::Value(); }
 
-  const std::string &get_name() const
-  { return _name; }
+  const std::string &get_name() const { return _name; }
 
-  void restore(const common::context::State<Time> &state)
-  {
-    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+  void restore(const common::context::State<Time> &state) {
+    common::state::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
   }
 
-  void save(common::context::State<Time> &state) const
-  {
-    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+  void save(common::context::State<Time> &state) const {
+    common::state::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
   }
 
 private:
@@ -360,28 +327,24 @@ private:
   std::string _name;
 };
 
-template<class Time, class Dyn, class Parameters = common::NoParameters, class GraphParameters = common::NoParameters>
-class Executive : public dsde::ExecutiveDynamics<Time, Dyn, Parameters, GraphParameters>
-{
+template<typename Time, typename Dyn, typename Parameters = common::NoParameters, typename GraphParameters = common::NoParameters>
+class Executive : public dsde::ExecutiveDynamics<Time, Dyn, Parameters, GraphParameters> {
 public:
   Executive(const ExecutiveContext<Time, Dyn, Parameters, GraphParameters> &context,
             dsde::GraphManager<Time, Parameters, GraphParameters> &graph_manager)
-      :
-      dsde::ExecutiveDynamics<Time, Dyn, Parameters, GraphParameters>(context),
-      _graph_manager(graph_manager)
-  {}
+    :
+    dsde::ExecutiveDynamics<Time, Dyn, Parameters, GraphParameters>(context),
+    _graph_manager(graph_manager) {}
 
   ~Executive() override = default;
 
 protected:
-  dsde::GraphManager<Time, Parameters, GraphParameters> &graph_manager()
-  { return _graph_manager; }
+  dsde::GraphManager<Time, Parameters, GraphParameters> &graph_manager() { return _graph_manager; }
 
 private:
   dsde::GraphManager<Time, Parameters, GraphParameters> &_graph_manager;
 };
 
-}
 }
 
 #endif

+ 33 - 41
src/artis-star/kernel/dsde/GraphManager.hpp

@@ -31,73 +31,65 @@
 
 #include <vector>
 
-namespace artis {
-namespace dsde {
-
-template<class Time,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
-class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters>
-{
+namespace artis::dsde {
+
+template<typename Time,
+  typename Parameters = common::NoParameters,
+  typename GraphParameters = common::NoParameters>
+class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters> {
 public:
-  typedef pdevs::GraphManager<Time, Parameters, GraphParameters> super;
+  typedef pdevs::GraphManager <Time, Parameters, GraphParameters> super;
   typedef GraphManager<Time, Parameters, GraphParameters> type;
 
-  GraphManager(common::Coordinator<Time> *coordinator,
+  GraphManager(common::Coordinator <Time> *coordinator,
                const Parameters &parameters,
                const GraphParameters &graph_parameters)
-      :
-      pdevs::GraphManager<Time, Parameters, GraphParameters>(coordinator, parameters,
-                                                             graph_parameters)
-  {}
+    :
+    pdevs::GraphManager<Time, Parameters, GraphParameters>(coordinator, parameters,
+                                                           graph_parameters) {}
 
-  ~GraphManager() override
-  {
+  ~GraphManager() override {
     for (auto m: _models) {
       delete m;
     }
   }
 
-  virtual void add_dynamic_child(unsigned int index, common::Model<Time> *child)
-  {
+  virtual void add_dynamic_child(unsigned int index, common::Model <Time> *child) {
     super::add_child(index, child);
     _models.push_back(child);
     _new_models.push_back(child);
   }
 
-  virtual void add_dynamic_children(unsigned int index, common::Model<Time> *child)
-  {
+  virtual void add_dynamic_children(unsigned int index, common::Model <Time> *child) {
     super::add_children(index, child);
     _models.push_back(child);
     _new_models.push_back(child);
   }
 
   void add_link(unsigned int source_model_index, unsigned int source_port_index,
-                unsigned int destination_model_index, unsigned int destination_port_index)
-  {
-    common::Model<Time> *source_model = super::child_map(source_model_index);
-    common::Model<Time> *destination_model = super::child_map(destination_model_index);
+                unsigned int destination_model_index, unsigned int destination_port_index) {
+    common::Model <Time> *source_model = super::child_map(source_model_index);
+    common::Model <Time> *destination_model = super::child_map(destination_model_index);
 
     assert(source_model and destination_model);
 
     this->out({source_model, source_port_index})
-        >> this->in({destination_model, destination_port_index});
+      >> this->in({destination_model, destination_port_index});
   }
 
-  void clear_new_models()
-  { _new_models.clear(); }
+  void clear_new_models() { _new_models.clear(); }
+
+  std::vector<common::Model < Time> *> &
 
-  std::vector<common::Model<Time> *> &new_models()
-  { return _new_models; }
+  new_models() { return _new_models; }
 
-  void remove_dynamic_child(const typename Time::type &t, unsigned int index)
-  {
+  void remove_dynamic_child(const typename Time::type &t, unsigned int index) {
     size_t new_index = index
-        - (pdevs::GraphManager<Time, Parameters, GraphParameters>::_children.size()
-            - _models.size());
+                       - (pdevs::GraphManager<Time, Parameters, GraphParameters>::_children.size()
+                          - _models.size());
 
     new_index -= std::count_if(_models.begin(), _models.end(),
-                               [](common::Model<Time> *model) { return model == nullptr; });
+                               [](common::Model <Time> *model) { return model == nullptr; });
     type::coordinator()->remove_model(t, _models[new_index]);
     super::remove_child(index);
     this->remove_links(_models[new_index]);
@@ -106,10 +98,9 @@ public:
   }
 
   void remove_link(unsigned int source_model_index, unsigned int source_port_index,
-                   unsigned int destination_model_index, unsigned int destination_port_index)
-  {
-    common::Model<Time> *source_model = super::child_map(source_model_index);
-    common::Model<Time> *destination_model = super::child_map(destination_model_index);
+                   unsigned int destination_model_index, unsigned int destination_port_index) {
+    common::Model <Time> *source_model = super::child_map(source_model_index);
+    common::Model <Time> *destination_model = super::child_map(destination_model_index);
 
     assert(source_model and destination_model);
 
@@ -118,11 +109,12 @@ public:
   }
 
 private:
-  std::vector<common::Model<Time> *> _models;
-  std::vector<common::Model<Time> *> _new_models;
+  std::vector<common::Model < Time> *>
+  _models;
+  std::vector<common::Model < Time> *>
+  _new_models;
 };
 
-}
 }
 
 #endif

+ 30 - 46
src/artis-star/kernel/dtss/Coordinator.hpp

@@ -33,20 +33,17 @@
 
 #include <cassert>
 
-namespace artis {
-namespace dtss {
+namespace artis::dtss {
 
-template<class Time>
-struct Parameters
-{
+template<typename Time>
+struct Parameters {
   typename Time::type time_step;
 };
 
-template<class Time, class Policy, class GraphManager,
-    class Parameters = Parameters<Time>,
-    class GraphParameters = common::NoParameters>
-class Coordinator : public common::Coordinator<Time>
-{
+template<typename Time, typename Policy, typename GraphManager,
+  typename Parameters = Parameters<Time>,
+  typename GraphParameters = common::NoParameters>
+class Coordinator : public common::Coordinator<Time> {
   typedef Coordinator<Time, Policy, GraphManager, Parameters, GraphParameters> type;
 
 public:
@@ -55,24 +52,19 @@ public:
 
   Coordinator(const std::string &name, const Parameters &parameters,
               const GraphParameters &graph_parameters)
-      :
-      common::Model<Time>(name),
-      common::Coordinator<Time>(name),
-      _graph_manager(this, parameters, graph_parameters),
-      _time_step(parameters.time_step)
-  {}
+    :
+    common::Model<Time>(name),
+    common::Coordinator<Time>(name),
+    _graph_manager(this, parameters, graph_parameters),
+    _time_step(parameters.time_step) {}
 
-  virtual ~Coordinator()
-  {}
+  virtual ~Coordinator() {}
 
-  GraphManager &get_graph_manager()
-  { return _graph_manager; }
+  GraphManager &get_graph_manager() { return _graph_manager; }
 
-  const GraphManager &get_graph_manager() const
-  { return _graph_manager; }
+  const GraphManager &get_graph_manager() const { return _graph_manager; }
 
-  virtual void finish(const typename Time::type &t)
-  {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
     (void) t;
 #endif
@@ -87,8 +79,7 @@ public:
 #endif
   }
 
-  typename Time::type start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -103,7 +94,7 @@ public:
 
     assert(_graph_manager.children().size() > 0);
 
-    for (auto &child : _graph_manager.children()) {
+    for (auto &child: _graph_manager.children()) {
       child->start(t);
     }
     type::_tl = t;
@@ -123,9 +114,8 @@ public:
     return type::_tn;
   }
 
-  typename Time::type dispatch_events(const common::Bag<Time> &bag,
-                                      const typename Time::type &t)
-  {
+  typename Time::type dispatch_events(const common::event::Bag<Time> &bag,
+                                      const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -154,20 +144,17 @@ public:
     return type::_tn;
   }
 
-  common::Value observe(const typename Time::type & /* t */,
-                        unsigned int /* index */) const
-  {
+  common::event::Value observe(const typename Time::type & /* t */,
+                               unsigned int /* index */) const {
     assert(false);
-    return common::Value();
+    return common::event::Value();
   }
 
-  typename Time::type lookahead(const typename Time::type &t) const
-  {
+  typename Time::type lookahead(const typename Time::type &t) const {
     return _graph_manager.lookahead(t);
   }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -181,7 +168,7 @@ public:
 #endif
 
     if (t == type::_tn) {
-      for (auto &model : _graph_manager.children()) {
+      for (auto &model: _graph_manager.children()) {
         model->output(t);
       }
     }
@@ -199,8 +186,7 @@ public:
   }
 
   void post_event(const typename Time::type &t,
-                  const common::ExternalEvent<Time> &event)
-  {
+                  const common::event::ExternalEvent<Time> &event) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -230,8 +216,7 @@ public:
 
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -245,11 +230,11 @@ public:
 #endif
 
     if (t == type::_tn) {
-      for (auto &event : _policy.bag()) {
+      for (auto &event: _policy.bag()) {
         post_event(t, event);
       }
       _policy.clear();
-      for (auto &model : _graph_manager.children()) {
+      for (auto &model: _graph_manager.children()) {
         model->transition(t);
       }
       type::_tl = t;
@@ -276,7 +261,6 @@ private:
   Policy _policy;
 };
 
-}
 } // namespace artis dtss
 
 #endif

+ 33 - 56
src/artis-star/kernel/dtss/Dynamics.hpp

@@ -27,24 +27,20 @@
 #ifndef DTSS_DYNAMICS
 #define DTSS_DYNAMICS
 
-#include <artis-star/common/Bag.hpp>
-#include <artis-star/common/ExternalEvent.hpp>
+#include "artis-star/common/event/Bag.hpp"
+#include "artis-star/common/event/ExternalEvent.hpp"
 #include <artis-star/common/Parameters.hpp>
-#include <artis-star/common/States.hpp>
+#include "artis-star/common/state/States.hpp"
 #include <artis-star/kernel/dtss/Simulator.hpp>
 
-namespace artis {
-namespace dtss {
+namespace artis::dtss {
 
-template<class Time, class Dyn,
-    class Parameters = common::NoParameters>
-class Dynamics : public common::States<Time, Dyn>
-{
+template<typename Time, typename Dyn, typename Parameters = common::NoParameters>
+class Dynamics : public common::state::States<Time, Dyn> {
   typedef dtss::Simulator<Time, Dyn, Parameters> Simulator;
 
 public:
-  struct Observable
-  {
+  struct Observable {
     unsigned int index;
     std::string name;
   };
@@ -52,54 +48,42 @@ public:
   typedef std::map<unsigned int, std::string> Observables;
 
   Dynamics(const std::string &name, const Context<Time, Dyn, Parameters> &context)
-      :
-      _name(name), _simulator(context.simulator())
-  {}
+    :
+    _name(name), _simulator(context.simulator()) {}
 
-  virtual ~Dynamics()
-  {}
+  virtual ~Dynamics() {}
 
-  virtual void transition(const common::Bag<Time> & /* x */,
-                          const typename Time::type & /* t */)
-  {}
+  virtual void transition(const common::event::Bag<Time> & /* x */,
+                          const typename Time::type & /* t */) {}
 
-  virtual void start(const typename Time::type & /* time */)
-  {}
+  virtual void start(const typename Time::type & /* time */) {}
 
-  virtual common::Bag<Time> lambda(
-      const typename Time::type & /* time */) const
-  { return common::Bag<Time>(); }
+  virtual common::event::Bag<Time> lambda(
+    const typename Time::type & /* time */) const { return common::event::Bag<Time>(); }
 
-  virtual common::Value observe(const typename Time::type & /* t */,
-                                unsigned int /* index */) const
-  { return common::Value(); }
+  virtual common::event::Value observe(const typename Time::type & /* t */,
+                                       unsigned int /* index */) const { return common::event::Value(); }
 
-  virtual typename Time::type lookahead(const typename Time::type &t) const
-  { return t; }
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
-  const std::string &get_name() const
-  { return _name; }
+  const std::string &get_name() const { return _name; }
 
-  void input_port(common::Port p)
-  {
+  void input_port(common::Port p) {
     _simulator->add_in_port(p);
   }
 
-  void input_ports(std::initializer_list<common::Port> list)
-  {
+  void input_ports(std::initializer_list<common::Port> list) {
     for (typename std::initializer_list<common::Port>::iterator it =
-        list.begin(); it != list.end(); ++it) {
+      list.begin(); it != list.end(); ++it) {
       _simulator->add_in_port(*it);
     }
   }
 
-  void observable(Observable observable)
-  {
+  void observable(Observable observable) {
     _observables[observable.index] = observable.name;
   }
 
-  void observables(std::initializer_list<Observable> list)
-  {
+  void observables(std::initializer_list<Observable> list) {
     for (typename std::initializer_list<Observable>::iterator it = list.begin();
          it != list.end();
          ++it) {
@@ -107,38 +91,32 @@ public:
     }
   }
 
-  virtual std::string observable_name(unsigned int observable_index) const
-  {
+  virtual std::string observable_name(unsigned int observable_index) const {
     assert(_observables.find(observable_index) != _observables.end());
 
     return _observables.find(observable_index)->second;
   }
 
-  void output_port(common::Port p)
-  {
+  void output_port(common::Port p) {
     _simulator->add_out_port(p);
   }
 
-  void output_ports(std::initializer_list<common::Port> list)
-  {
+  void output_ports(std::initializer_list<common::Port> list) {
     for (typename std::initializer_list<common::Port>::iterator it =
-        list.begin(); it != list.end(); ++it) {
+      list.begin(); it != list.end(); ++it) {
       _simulator->add_out_port(*it);
     }
   }
 
-  void restore(const common::context::State<Time> &state)
-  {
-    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+  void restore(const common::context::State<Time> &state) {
+    common::state::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
   }
 
-  void save(common::context::State<Time> &state) const
-  {
-    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+  void save(common::context::State<Time> &state) const {
+    common::state::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
   }
 
-  const typename Time::type &time_step() const
-  { return _simulator->time_step(); }
+  const typename Time::type &time_step() const { return _simulator->time_step(); }
 
 private:
   std::string _name;
@@ -146,7 +124,6 @@ private:
   Observables _observables;
 };
 
-}
 } // namespace artis dtss
 
 #endif

+ 45 - 60
src/artis-star/kernel/dtss/GraphManager.hpp

@@ -33,62 +33,53 @@
 #include <artis-star/common/Model.hpp>
 #include <artis-star/common/Parameters.hpp>
 
-namespace artis {
-namespace dtss {
-
-template<class Time,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
-class GraphManager : public common::GraphManager<Time>
-{
+namespace artis::dtss {
+
+template<typename Time,
+  typename Parameters = common::NoParameters,
+  typename GraphParameters = common::NoParameters>
+class GraphManager : public common::GraphManager<Time> {
 public:
   typedef GraphManager<Time, Parameters, GraphParameters> type;
 
-  struct ModelPort
-  {
-    common::Model<Time> *model;
+  struct ModelPort {
+    common::Model <Time> *model;
     unsigned int port_index;
     type *graph_manager;
 
-    ModelPort(common::Model<Time> *model, unsigned int port_index)
-        : model(model),
-          port_index(port_index),
-          graph_manager(nullptr)
-    {}
+    ModelPort(common::Model <Time> *model, unsigned int port_index)
+      : model(model),
+        port_index(port_index),
+        graph_manager(nullptr) {}
 
-    void operator>>(const ModelPort &dst)
-    {
+    void operator>>(const ModelPort &dst) {
       graph_manager->add_link(model, port_index, dst.model, dst.port_index);
     }
   };
 
-  GraphManager(common::Coordinator<Time> *coordinator,
+  GraphManager(common::Coordinator <Time> *coordinator,
                const Parameters & /* parameters */,
                const GraphParameters & /* graph_parameters */)
-      :
-      common::GraphManager<Time>(coordinator)
-  {}
+    :
+    common::GraphManager<Time>(coordinator) {}
 
   ~GraphManager() override = default;
 
-  ModelPort in(ModelPort p)
-  {
+  ModelPort in(ModelPort p) {
     p.graph_manager = this;
     return p;
   }
 
-  ModelPort out(ModelPort p)
-  {
+  ModelPort out(ModelPort p) {
     p.graph_manager = this;
     return p;
   }
 
-  void dispatch_events(common::Bag<Time> bag, typename Time::type t)
-  {
-    for (auto &ymsg : bag) {
+  void dispatch_events(common::event::Bag <Time> bag, typename Time::type t) {
+    for (auto &ymsg: bag) {
       typename common::Links<Time>::Result result_model = _link_list.find(
-          ymsg.get_model(),
-          ymsg.port_index());
+        ymsg.get_model(),
+        ymsg.port_index());
 
       for (typename common::Links<Time>::const_iterator it = result_model.first;
            it != result_model.second; ++it) {
@@ -97,50 +88,46 @@ public:
           dispatch_events_to_parent(it->second, ymsg.data(), t);
         } else { // event on input port of internal model
           it->second.get_model()->post_event(t,
-                                             common::ExternalEvent<Time>(it->second, ymsg.data()));
+                                             common::event::ExternalEvent<Time>(it->second, ymsg.data()));
         }
       }
     }
   }
 
   virtual void
-  dispatch_events_to_parent(common::Node<Time> node, const common::Value &content,
-                            typename Time::type t)
-  {
-    common::Bag<Time> ymessages;
+  dispatch_events_to_parent(common::Node <Time> node, const common::event::Value &content,
+                            typename Time::type t) {
+    common::event::Bag <Time> ymessages;
 
-    ymessages.push_back(common::ExternalEvent<Time>(node, content));
+    ymessages.push_back(common::event::ExternalEvent<Time>(node, content));
 
     if (common::GraphManager<Time>::_coordinator->get_parent()) {
-      dynamic_cast < common::Coordinator<Time> * >(common::GraphManager<Time>::_coordinator
-          ->get_parent())
-          ->dispatch_events(ymessages, t);
+      dynamic_cast < common::Coordinator <Time> * >(common::GraphManager<Time>::_coordinator
+        ->get_parent())
+        ->dispatch_events(ymessages, t);
     }
   }
 
-  virtual typename Time::type lookahead(const typename Time::type &t) const
-  { return t; }
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
-  void post_event(typename Time::type t, const common::ExternalEvent<Time> &event)
-  {
+  void post_event(typename Time::type t, const common::event::ExternalEvent <Time> &event) {
     typename common::Links<Time>::Result result =
-        _link_list.find(common::GraphManager<Time>::_coordinator,
-                        event.port_index());
+      _link_list.find(common::GraphManager<Time>::_coordinator,
+                      event.port_index());
 
     for (typename common::Links<Time>::const_iterator it_r = result.first;
          it_r != result.second;
          ++it_r) {
       it_r->second.get_model()->post_event(t,
-                                           common::ExternalEvent<Time>(it_r->second, event.data()));
+                                           common::event::ExternalEvent<Time>(it_r->second, event.data()));
     }
   }
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     std::ostringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "Children :" << std::endl;
-    for (auto &child : common::GraphManager<Time>::_children) {
+    for (auto &child: common::GraphManager<Time>::_children) {
       ss << child->to_string(level + 1);
     }
     ss << _link_list.to_string(level);
@@ -148,18 +135,17 @@ public:
   }
 
 private:
-  void add_link(common::Model<Time> *src_model, unsigned int src_port_index,
-                common::Model<Time> *dst_model, unsigned int dst_port_index)
-  {
+  void add_link(common::Model <Time> *src_model, unsigned int src_port_index,
+                common::Model <Time> *dst_model, unsigned int dst_port_index) {
     assert((src_model != common::GraphManager<Time>::_coordinator and
-        dst_model != common::GraphManager<Time>::_coordinator and
-        src_model->exist_out_port(src_port_index) and
-        dst_model->exist_in_port(dst_port_index)) or
-        (src_model == common::GraphManager<Time>::_coordinator and
+            dst_model != common::GraphManager<Time>::_coordinator and
+            src_model->exist_out_port(src_port_index) and
+            dst_model->exist_in_port(dst_port_index)) or
+           (src_model == common::GraphManager<Time>::_coordinator and
             dst_model != common::GraphManager<Time>::_coordinator and
             src_model->exist_in_port(src_port_index) and
             dst_model->exist_in_port(dst_port_index)) or
-        (src_model != common::GraphManager<Time>::_coordinator and
+           (src_model != common::GraphManager<Time>::_coordinator and
             dst_model == common::GraphManager<Time>::_coordinator and
             src_model->exist_out_port(src_port_index) and
             dst_model->exist_out_port(dst_port_index)));
@@ -167,10 +153,9 @@ private:
     _link_list.add(src_model, src_port_index, dst_model, dst_port_index);
   }
 
-  common::Links<Time> _link_list;
+  common::Links <Time> _link_list;
 };
 
-}
 } // namespace artis dtss
 
 #endif

+ 23 - 34
src/artis-star/kernel/dtss/Policy.hpp

@@ -27,83 +27,72 @@
 #ifndef DTSS_POLICY
 #define DTSS_POLICY
 
-#include <artis-star/common/Bag.hpp>
+#include "artis-star/common/event/Bag.hpp"
 
 #include <cassert>
 
-namespace artis {
-namespace dtss {
+namespace artis::dtss {
 
-class Policy
-{
+class Policy {
 public:
   Policy() = default;
 
   virtual ~Policy() = default;
 
-  const common::Bag<common::DoubleTime> &bag() const
-  { return _bag; }
+  const common::event::Bag <common::DoubleTime> &bag() const { return _bag; }
 
-  void clear()
-  { _bag.clear(); }
+  void clear() { _bag.clear(); }
 
-  void push(const common::ExternalEvent<common::DoubleTime> &event)
-  { _bag.push_back(event); }
+  void push(const common::event::ExternalEvent <common::DoubleTime> &event) { _bag.push_back(event); }
 
 private:
-  common::Bag<common::DoubleTime> _bag;
+  common::event::Bag <common::DoubleTime> _bag;
 };
 
-class AllEventsPolicy : public Policy
-{
+class AllEventsPolicy : public Policy {
 public:
   AllEventsPolicy() = default;
 
   virtual ~AllEventsPolicy() = default;
 
   virtual void operator()(
-      typename common::DoubleTime::type /* t */,
-      const common::ExternalEvent<common::DoubleTime> &event,
-      typename common::DoubleTime::type /* tl */,
-      typename common::DoubleTime::type /* tn */)
-  {
+    typename common::DoubleTime::type /* t */,
+    const common::event::ExternalEvent <common::DoubleTime> &event,
+    typename common::DoubleTime::type /* tl */,
+    typename common::DoubleTime::type /* tn */) {
     push(event);
   }
 };
 
-class LastBagPolicy : public Policy
-{
+class LastBagPolicy : public Policy {
 public:
   LastBagPolicy() = default;
 
   virtual ~LastBagPolicy() = default;
 
   virtual void operator()(
-      typename common::DoubleTime::type /* t */,
-      const common::ExternalEvent<common::DoubleTime> &event,
-      typename common::DoubleTime::type /* tl */,
-      typename common::DoubleTime::type /* tn */)
-  {
+    typename common::DoubleTime::type /* t */,
+    const common::event::ExternalEvent <common::DoubleTime> &event,
+    typename common::DoubleTime::type /* tl */,
+    typename common::DoubleTime::type /* tn */) {
     clear();
     push(event);
   }
 };
 
-class IgnorePolicy : public Policy
-{
+class IgnorePolicy : public Policy {
 public:
   IgnorePolicy() = default;
+
   virtual ~IgnorePolicy() = default;
 
   virtual void operator()(
-      typename common::DoubleTime::type /* t */,
-      const common::ExternalEvent<common::DoubleTime> & /* event */,
-      typename common::DoubleTime::type /* tl */,
-      typename common::DoubleTime::type /* tn */)
-  {}
+    typename common::DoubleTime::type /* t */,
+    const common::event::ExternalEvent <common::DoubleTime> & /* event */,
+    typename common::DoubleTime::type /* tl */,
+    typename common::DoubleTime::type /* tn */) {}
 };
 
-}
 }
 
 #endif

+ 34 - 57
src/artis-star/kernel/dtss/Simulator.hpp

@@ -34,68 +34,54 @@
 
 #include <cassert>
 
-namespace artis {
-namespace dtss {
+namespace artis::dtss {
 
-template<class Time, class Dynamics, class Parameters>
+template<typename Time, typename Dynamics, typename Parameters>
 class Simulator;
 
-template<class Time, class Dynamics,
-    class Parameters = common::NoParameters>
-class Context
-{
+template<typename Time, typename Dynamics, typename Parameters = common::NoParameters>
+class Context {
   typedef dtss::Simulator<Time, Dynamics, Parameters> Simulator;
 
 public:
   Context(const Parameters &parameters, Simulator *simulator)
-      :
-      _parameters(parameters), _simulator(simulator)
-  {}
+    :
+    _parameters(parameters), _simulator(simulator) {}
 
-  virtual ~Context()
-  {}
+  virtual ~Context() {}
 
-  const Parameters &parameters() const
-  { return _parameters; }
+  const Parameters &parameters() const { return _parameters; }
 
-  Simulator *simulator() const
-  { return _simulator; }
+  Simulator *simulator() const { return _simulator; }
 
 private:
   const Parameters &_parameters;
   Simulator *_simulator;
 };
 
-template<class Time, class Dynamics,
-    class Parameters = common::NoParameters>
-class Simulator : public common::Simulator<Time>
-{
+template<typename Time, typename Dynamics, typename Parameters = common::NoParameters>
+class Simulator : public common::Simulator<Time> {
   typedef Simulator<Time, Dynamics, Parameters> type;
 
 public:
   Simulator(const std::string &name, const Parameters &parameters)
-      :
-      common::Model<Time>(name),
-      common::Simulator<Time>(name),
-      _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)),
-      _time_step(parameters.time_step)
-  {}
-
-  ~Simulator()
-  {}
-
-  virtual void restore(const common::context::State<Time> &state)
-  {
+    :
+    common::Model<Time>(name),
+    common::Simulator<Time>(name),
+    _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)),
+    _time_step(parameters.time_step) {}
+
+  ~Simulator() {}
+
+  virtual void restore(const common::context::State<Time> &state) {
     _dynamics.restore(state);
   }
 
-  virtual void save(common::context::State<Time> &state) const
-  {
+  virtual void save(common::context::State<Time> &state) const {
     _dynamics.save(state);
   }
 
-  virtual void finish(const typename Time::type &t)
-  {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
     (void) t;
 #endif
@@ -110,8 +96,7 @@ public:
 #endif
   }
 
-  typename Time::type start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -142,22 +127,18 @@ public:
     return type::_tn;
   }
 
-  typename Time::type lookahead(const typename Time::type &t) const
-  {
+  typename Time::type lookahead(const typename Time::type &t) const {
     return _dynamics.lookahead(t);
   }
 
-  common::Value observe(const typename Time::type &t,
-                        unsigned int index) const
-  { return _dynamics.observe(t, index); }
+  common::event::Value observe(const typename Time::type &t,
+                               unsigned int index) const { return _dynamics.observe(t, index); }
 
-  virtual std::string observable_name(unsigned int observable_index) const
-  {
+  virtual std::string observable_name(unsigned int observable_index) const {
     return _dynamics.observable_name(observable_index);
   }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -170,14 +151,14 @@ public:
 #endif
 
     if (t == type::_tn) {
-      common::Bag<Time> bag = _dynamics.lambda(t);
+      common::event::Bag<Time> bag = _dynamics.lambda(t);
 
       if (not bag.empty()) {
-        for (auto &event : bag) {
+        for (auto &event: bag) {
           event.set_model(this);
         }
         dynamic_cast < common::Coordinator<Time> * >(
-            type::get_parent())->dispatch_events(bag, t);
+          type::get_parent())->dispatch_events(bag, t);
       }
     }
 
@@ -194,8 +175,7 @@ public:
   }
 
   void post_event(const typename Time::type &t,
-                  const common::ExternalEvent<Time> &event)
-  {
+                  const common::event::ExternalEvent<Time> &event) {
 
 #ifndef WITH_TRACE
     (void) t;
@@ -225,8 +205,7 @@ public:
 
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -260,15 +239,13 @@ public:
     return type::_tn;
   }
 
-  const typename Time::type &time_step() const
-  { return _time_step; }
+  const typename Time::type &time_step() const { return _time_step; }
 
 private :
   Dynamics _dynamics;
   typename Time::type _time_step;
 };
 
-}
 } // namespace artis dtss
 
 #endif

+ 13 - 19
src/artis-star/kernel/fddevs/Coordinator.hpp

@@ -29,31 +29,26 @@
 
 #include <artis-star/kernel/pdevs/Coordinator.hpp>
 
-namespace artis {
-namespace fddevs {
+namespace artis::fddevs {
 
-template<class Time,
-    class GraphManager,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
+template<typename Time,
+  typename GraphManager,
+  typename Parameters = common::NoParameters,
+  typename GraphParameters = common::NoParameters>
 class Coordinator
-    : public pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters>
-{
+  : public pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters> {
 public:
   Coordinator(const std::string &name, const Parameters &parameters,
               const GraphParameters &graph_parameters)
-      :
-      common::Model<Time>(name),
-      pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters>(name,
-                                                                          parameters,
-                                                                          graph_parameters)
-  {}
+    :
+    common::Model<Time>(name),
+    pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters>(name,
+                                                                        parameters,
+                                                                        graph_parameters) {}
 
-  virtual ~Coordinator()
-  {}
+  virtual ~Coordinator() {}
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     std::ostringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "fddevs coordinator \""
@@ -63,7 +58,6 @@ public:
   }
 };
 
-}
 } // namespace artis fddevs
 
 #endif

+ 35 - 60
src/artis-star/kernel/fddevs/Dynamics.hpp

@@ -27,81 +27,64 @@
 #ifndef FDDEVS_DYNAMICS
 #define FDDEVS_DYNAMICS
 
-#include <artis-star/common/Bag.hpp>
-#include <artis-star/common/ExternalEvent.hpp>
+#include "artis-star/common/event/Bag.hpp"
+#include "artis-star/common/event/ExternalEvent.hpp"
 #include <artis-star/common/Parameters.hpp>
-#include <artis-star/common/States.hpp>
+#include "artis-star/common/state/States.hpp"
 #include <artis-star/kernel/fddevs/Simulator.hpp>
 
 #include <string>
 #include <vector>
 
-namespace artis {
-namespace fddevs {
+namespace artis::fddevs {
 
-template<class Time, class Dyn, class StateValues, class Parameters = common::NoParameters>
-class Dynamics : public common::States<Time, Dyn>
-{
+template<typename Time, typename Dyn, typename StateValues, typename Parameters = common::NoParameters>
+class Dynamics : public common::state::States<Time, Dyn> {
   typedef fddevs::Simulator<Time, Dyn, Parameters> Simulator;
 
 public:
-  Dynamics(const std::string &name, const Context<Time, Dyn, Parameters> &context)
-      :
-      _name(name), _simulator(context.simulator())
-  {}
+  Dynamics(const std::string &name, const Context <Time, Dyn, Parameters> &context)
+    :
+    _name(name), _simulator(context.simulator()) {}
 
-  virtual ~Dynamics()
-  {}
+  virtual ~Dynamics() {}
 
   // definition
-  void initial_state(const StateValues &state)
-  { _initial_state = state; }
+  void initial_state(const StateValues &state) { _initial_state = state; }
 
   // < X, Y, S, s0, tau, delta_x, sigma, delta_tau, lambda >
-  virtual void delta_tau(typename Time::type /* t */)
-  {}
+  virtual void delta_tau(typename Time::type /* t */) {}
 
   virtual void delta_x(typename Time::type /* t */, typename Time::type /* e */,
-                       const common::Bag<Time> & /* bag */)
-  {}
+                       const common::event::Bag <Time> & /* bag */) {}
 
-  virtual void initial_state(typename Time::type /* time */)
-  { state(_initial_state); }
+  virtual void initial_state(typename Time::type /* time */) { state(_initial_state); }
 
-  virtual common::Bag<Time>
-  lambda(typename Time::type /* time */) const
-  { return common::Bag<Time>(); }
+  virtual common::event::Bag <Time>
+  lambda(typename Time::type /* time */) const { return common::event::Bag<Time>(); }
 
   virtual bool rho(typename Time::type /* time */,
-                   const common::Bag<common::DoubleTime> & /* bag */) const
-  { return false; }
+                   const common::event::Bag <common::DoubleTime> & /* bag */) const { return false; }
 
   virtual typename Time::type
-  tau(typename Time::type /* time */) const
-  { return Time::infinity; }
+  tau(typename Time::type /* time */) const { return Time::infinity; }
 
-  virtual typename Time::type lookahead(const typename Time::type &t) const
-  { return t; }
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
   // observation
-  virtual common::Value observe(const typename Time::type & /* t */,
-                                unsigned int /* index */) const
-  { return common::Value(); }
+  virtual common::event::Value observe(const typename Time::type & /* t */,
+                                unsigned int /* index */) const { return common::event::Value(); }
 
   // structure
-  const std::string &get_name() const
-  { return _name; }
+  const std::string &get_name() const { return _name; }
 
-  void input_port(common::Port p)
-  {
+  void input_port(common::Port p) {
     _simulator->add_in_port(p);
   }
 
-  size_t input_port_number() const
-  { return _simulator->get_in_port_number(); }
+  size_t input_port_number() const { return _simulator->get_in_port_number(); }
 
-  void input_ports(std::initializer_list<common::Port> list)
-  {
+  void input_ports(std::initializer_list <common::Port> list) {
     for (typename std::initializer_list<common::Port>::iterator it = list.begin();
          it != list.end();
          ++it) {
@@ -109,40 +92,33 @@ public:
     }
   }
 
-  void output_port(common::Port p)
-  {
+  void output_port(common::Port p) {
     _simulator->add_out_port(p);
   }
 
-  size_t output_port_number() const
-  { return _simulator->get_out_port_number(); }
+  size_t output_port_number() const { return _simulator->get_out_port_number(); }
 
-  void output_ports(std::initializer_list<common::Port> list)
-  {
+  void output_ports(std::initializer_list <common::Port> list) {
     for (typename std::initializer_list<common::Port>::iterator it =
-        list.begin(); it != list.end(); ++it) {
+      list.begin(); it != list.end(); ++it) {
       _simulator->add_out_port(*it);
     }
   }
 
   // state
-  void restore(const common::context::State<Time> &state)
-  {
-    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+  void restore(const common::context::State <Time> &state) {
+    common::state::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
   }
 
-  void save(common::context::State<Time> &state) const
-  {
-    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+  void save(common::context::State <Time> &state) const {
+    common::state::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
   }
 
-  void state(const StateValues &new_state)
-  {
+  void state(const StateValues &new_state) {
     _state = new_state;
   }
 
-  const StateValues &state() const
-  { return _state; }
+  const StateValues &state() const { return _state; }
 
 private:
   std::string _name;
@@ -155,7 +131,6 @@ private:
   StateValues _state;
 };
 
-}
 } // namespace artis fddevs
 
 #endif

+ 10 - 14
src/artis-star/kernel/fddevs/GraphManager.hpp

@@ -29,27 +29,23 @@
 
 #include <artis-star/kernel/pdevs/GraphManager.hpp>
 
-namespace artis {
-namespace fddevs {
-
-template<class Time,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
-class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters>
-{
+namespace artis::fddevs {
+
+template<typename Time,
+  typename Parameters = common::NoParameters,
+  typename GraphParameters = common::NoParameters>
+class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters> {
 public:
-  GraphManager(common::Coordinator<Time> *coordinator,
+  GraphManager(common::Coordinator <Time> *coordinator,
                const Parameters &parameters,
                const GraphParameters &graph_parameters)
-      :
-      pdevs::GraphManager<Time, Parameters, GraphParameters>(coordinator, parameters,
-                                                             graph_parameters)
-  {}
+    :
+    pdevs::GraphManager<Time, Parameters, GraphParameters>(coordinator, parameters,
+                                                           graph_parameters) {}
 
   ~GraphManager() override = default;
 };
 
-}
 } // namespace artis fddevs
 
 #endif

+ 32 - 55
src/artis-star/kernel/fddevs/Simulator.hpp

@@ -35,72 +35,57 @@
 
 #include <cassert>
 
-namespace artis {
-namespace fddevs {
+namespace artis::fddevs {
 
-template<class Time, class Dynamics, class Parameters>
+template<typename Time, typename Dynamics, typename Parameters>
 class Simulator;
 
-template<class Time, class Dynamics,
-    class Parameters = common::NoParameters>
-class Context
-{
+template<typename Time, typename Dynamics, typename Parameters = common::NoParameters>
+class Context {
   typedef fddevs::Simulator<Time, Dynamics, Parameters> Simulator;
 
 public:
   Context(const Parameters &parameters, Simulator *simulator)
-      :
-      _parameters(parameters), _simulator(simulator)
-  {}
+    :
+    _parameters(parameters), _simulator(simulator) {}
 
-  virtual ~Context()
-  {}
+  virtual ~Context() {}
 
-  const Parameters &parameters() const
-  { return _parameters; }
+  const Parameters &parameters() const { return _parameters; }
 
-  Simulator *simulator() const
-  { return _simulator; }
+  Simulator *simulator() const { return _simulator; }
 
 private:
   const Parameters &_parameters;
   Simulator *_simulator;
 };
 
-template<class Time, class Dynamics,
-    class Parameters = common::NoParameters>
-class Simulator : public common::Simulator<Time>
-{
+template<typename Time, typename Dynamics, typename Parameters = common::NoParameters>
+class Simulator : public common::Simulator<Time> {
   typedef Simulator<Time, Dynamics, Parameters> type;
 
 public :
   Simulator(const std::string &name, const Parameters &parameters)
-      :
-      common::Model<Time>(name),
-      common::Simulator<Time>(name),
-      _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this))
-  {}
+    :
+    common::Model<Time>(name),
+    common::Simulator<Time>(name),
+    _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)) {}
 
-  ~Simulator()
-  {}
+  ~Simulator() {}
 
-  const Dynamics &dynamics() const
-  { return _dynamics; }
+  const Dynamics &dynamics() const { return _dynamics; }
 
-  virtual void restore(const common::context::State<Time> &state)
-  {
+  virtual void restore(const common::context::State <Time> &state) {
     common::Simulator<Time>::restore(state);
     _dynamics.restore(state);
   }
 
-  virtual void save(common::context::State<Time> &state) const
-  {
+  virtual void save(common::context::State <Time> &state) const {
     common::Simulator<Time>::save(state);
     _dynamics.save(state);
   }
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     std::ostringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "p-devs simulator \""
@@ -108,8 +93,7 @@ public :
     return ss.str();
   }
 
-  virtual void finish(const typename Time::type &t)
-  {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
     (void) t;
 #endif
@@ -124,8 +108,7 @@ public :
 #endif
   }
 
-  typename Time::type start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message(t)
 //                  tl = t - e
 //                  tn = tl + ta(s)
@@ -165,12 +148,10 @@ public :
     return type::_tn;
   }
 
-  common::Value observe(const typename Time::type &t,
-                        unsigned int index) const
-  { return _dynamics.observe(t, index); }
+  common::event::Value observe(const typename Time::type &t,
+                        unsigned int index) const { return _dynamics.observe(t, index); }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
 //                When *-message(t)
 //                  if (t = tn) then
 //                    y = lambda(s)
@@ -188,10 +169,10 @@ public :
 #endif
 
     if (t == type::_tn) {
-      common::Bag<Time> bag = _dynamics.lambda(t);
+      common::event::Bag <Time> bag = _dynamics.lambda(t);
 
       if (not bag.empty()) {
-        for (auto &event : bag) {
+        for (auto &event: bag) {
           event.set_model(this);
         }
 
@@ -206,15 +187,14 @@ public :
 common::Trace<Time>::trace().flush();
 #endif
 
-        dynamic_cast < common::Coordinator<Time> * >(
-            type::get_parent())->dispatch_events(bag, t);
+        dynamic_cast < common::Coordinator <Time> * >(
+          type::get_parent())->dispatch_events(bag, t);
       }
     }
   }
 
   void post_event(const typename Time::type &t,
-                  const common::ExternalEvent<Time> &event)
-  {
+                  const common::event::ExternalEvent <Time> &event) {
 
 #ifndef WITH_TRACE
     (void) t;
@@ -244,8 +224,7 @@ common::Trace<Time>::trace().flush();
 
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message(t)
 //                  if (x is empty and t = tn) then
 //                    s = delta_int(s)
@@ -310,8 +289,7 @@ common::Trace<Time>::trace().flush();
     return type::_tn;
   }
 
-  typename Time::type lookahead(const typename Time::type &t) const
-  {
+  typename Time::type lookahead(const typename Time::type &t) const {
     return _dynamics.lookahead(t);
   }
 
@@ -319,7 +297,6 @@ private :
   Dynamics _dynamics;
 };
 
-}
 } // namespace artis fddevs
 
 #endif

+ 9 - 17
src/artis-star/kernel/pdevs/Context.hpp

@@ -27,39 +27,31 @@
 #ifndef PDEVS_CONTEXT
 #define PDEVS_CONTEXT
 
-namespace artis {
-namespace pdevs {
+namespace artis::pdevs {
 
-template<class Time, class Dynamics, class Parameters>
+template<typename Time, typename Dynamics, typename Parameters>
 class Simulator;
 
-template<class Time, class Dynamics,
-    class Parameters = common::NoParameters>
-class Context
-{
+template<typename Time, typename Dynamics, typename Parameters = common::NoParameters>
+class Context {
   typedef pdevs::Simulator<Time, Dynamics, Parameters> Simulator;
 
 public:
   Context(const Parameters &parameters, Simulator *simulator)
-      :
-      _parameters(parameters), _simulator(simulator)
-  {}
+    :
+    _parameters(parameters), _simulator(simulator) {}
 
-  virtual ~Context()
-  {}
+  virtual ~Context() {}
 
-  const Parameters &parameters() const
-  { return _parameters; }
+  const Parameters &parameters() const { return _parameters; }
 
-  Simulator *simulator() const
-  { return _simulator; }
+  Simulator *simulator() const { return _simulator; }
 
 private:
   const Parameters &_parameters;
   Simulator *_simulator;
 };
 
-}
 } // namespace artis pdevs
 
 #endif

+ 40 - 59
src/artis-star/kernel/pdevs/Coordinator.hpp

@@ -35,15 +35,13 @@
 
 #include <cassert>
 
-namespace artis {
-namespace pdevs {
-
-template<class Time,
-    class GraphManager,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
-class Coordinator : public common::Coordinator<Time>
-{
+namespace artis::pdevs {
+
+template<typename Time,
+  typename GraphManager,
+  typename Parameters = common::NoParameters,
+  typename GraphParameters = common::NoParameters>
+class Coordinator : public common::Coordinator<Time> {
   typedef Coordinator<Time, GraphManager, Parameters, GraphParameters> type;
 
 public:
@@ -52,23 +50,18 @@ public:
 
   Coordinator(const std::string &name, const Parameters &parameters,
               const GraphParameters &graph_parameters)
-      :
-      common::Model<Time>(name),
-      common::Coordinator<Time>(name),
-      _graph_manager(this, parameters, graph_parameters)
-  {}
+    :
+    common::Model<Time>(name),
+    common::Coordinator<Time>(name),
+    _graph_manager(this, parameters, graph_parameters) {}
 
-  virtual ~Coordinator()
-  {}
+  virtual ~Coordinator() {}
 
-  GraphManager &get_graph_manager()
-  { return _graph_manager; }
+  GraphManager &get_graph_manager() { return _graph_manager; }
 
-  const GraphManager &get_graph_manager() const
-  { return _graph_manager; }
+  const GraphManager &get_graph_manager() const { return _graph_manager; }
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     std::ostringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "p-devs coordinator \""
@@ -77,16 +70,14 @@ public:
     return ss.str();
   }
 
-  void restore(const common::context::State<Time> &state)
-  {
+  void restore(const common::context::State <Time> &state) {
     common::Coordinator<Time>::restore(state);
-    for (auto &child : _graph_manager.children()) {
+    for (auto &child: _graph_manager.children()) {
       _event_table.init(child->get_tn(), child);
     }
   }
 
-  virtual void finish(const typename Time::type &t)
-  {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
     (void) t;
 #endif
@@ -101,8 +92,7 @@ public:
 #endif
   }
 
-  typename Time::type start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message (i, t) at time t
 //                  for-each d ∈ D do
 //                    send i-message to child d
@@ -124,7 +114,7 @@ public:
 
     assert(_graph_manager.children().size() > 0);
 
-    for (auto &child : _graph_manager.children()) {
+    for (auto &child: _graph_manager.children()) {
       _event_table.init(child->start(t), child);
     }
     type::_tl = t;
@@ -144,8 +134,7 @@ public:
     return type::_tn;
   }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
 //                When *-message (*, t)
 //                  if t != tn then Error
 //                  IMM = {d | (d, th,d) ∈ (event-list & tn,d = tn) }
@@ -166,7 +155,7 @@ public:
 
     assert(t == type::_tn);
 
-    common::Models<Time> IMM = _event_table.get_current_models(t);
+    common::Models <Time> IMM = _event_table.get_current_models(t);
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -178,7 +167,7 @@ public:
     common::Trace<Time>::trace().flush();
 #endif
 
-    for (auto &model : IMM) {
+    for (auto &model: IMM) {
       model->output(t);
     }
 
@@ -195,8 +184,7 @@ public:
 
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message (x, t)
 //                  if not (tl <= t <= tn) then Error
 //                  receivers = { r | r ∈ children, N ∈ Ir, Z(N,r)(x) isn't empty }
@@ -222,8 +210,8 @@ public:
 
     assert(t >= type::_tl and t <= type::_tn);
 
-    common::Models<Time> receivers = get_receivers();
-    common::Models<Time> IMM = _event_table.get_current_models(t);
+    common::Models <Time> receivers = get_receivers();
+    common::Models <Time> IMM = _event_table.get_current_models(t);
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -236,10 +224,10 @@ public:
     common::Trace<Time>::trace().flush();
 #endif
 
-    for (auto &model : receivers) {
+    for (auto &model: receivers) {
       _event_table.put(model->transition(t), model);
     }
-    for (auto &model : IMM) {
+    for (auto &model: IMM) {
       if (std::find(receivers.begin(), receivers.end(), model) == receivers.end()) {
         _event_table.put(model->transition(t), model);
       }
@@ -263,8 +251,7 @@ public:
     return type::_tn;
   }
 
-  void post_event(const typename Time::type &t, const common::ExternalEvent<Time> &event)
-  {
+  void post_event(const typename Time::type &t, const common::event::ExternalEvent <Time> &event) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -293,9 +280,8 @@ public:
 
   }
 
-  typename Time::type dispatch_events(const common::Bag<Time> &bag,
-                                      const typename Time::type &t)
-  {
+  typename Time::type dispatch_events(const common::event::Bag <Time> &bag,
+                                      const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -327,23 +313,20 @@ public:
     return type::_tn;
   }
 
-  common::Value observe(const typename Time::type & /* t */,
-                        unsigned int /* index */) const
-  {
+  common::event::Value observe(const typename Time::type & /* t */,
+                        unsigned int /* index */) const {
     assert(false);
-    return common::Value();
+    return common::event::Value();
   }
 
-  typename Time::type lookahead(const typename Time::type &t) const
-  {
+  typename Time::type lookahead(const typename Time::type &t) const {
     return _graph_manager.lookahead(t);
   }
 
-  common::Models<Time> get_receivers() const
-  {
-    common::Models<Time> receivers;
+  common::Models <Time> get_receivers() const {
+    common::Models <Time> receivers;
 
-    for (auto &model : _graph_manager.children()) {
+    for (auto &model: _graph_manager.children()) {
       if (model->event_number() > 0) {
         receivers.push_back(model);
       }
@@ -351,9 +334,8 @@ public:
     return receivers;
   }
 
-  void update_event_table(typename Time::type t)
-  {
-    for (auto &model : _graph_manager.children()) {
+  void update_event_table(typename Time::type t) {
+    for (auto &model: _graph_manager.children()) {
       if (model->event_number() > 0) {
         _event_table.put(t, model);
       }
@@ -365,7 +347,6 @@ protected:
   common::SchedulerType _event_table;
 };
 
-}
 } // namespace artis pdevs
 
 #endif

+ 38 - 65
src/artis-star/kernel/pdevs/Dynamics.hpp

@@ -27,26 +27,23 @@
 #ifndef PDEVS_DYNAMICS
 #define PDEVS_DYNAMICS
 
-#include <artis-star/common/Bag.hpp>
-#include <artis-star/common/ExternalEvent.hpp>
-#include <artis-star/common/Parameters.hpp>
-#include <artis-star/common/States.hpp>
-#include <artis-star/kernel/pdevs/Simulator.hpp>
+#include "artis-star/common/event/Bag.hpp"
+#include "artis-star/common/event/ExternalEvent.hpp"
+#include "artis-star/common/Parameters.hpp"
+#include "artis-star/common/state/States.hpp"
+#include "artis-star/kernel/pdevs/Simulator.hpp"
 
 #include <string>
 #include <vector>
 
-namespace artis {
-namespace pdevs {
+namespace artis::pdevs {
 
-template<class Time, class Dyn, class Parameters = common::NoParameters>
-class Dynamics : public common::States<Time, Dyn>
-{
+template<typename Time, typename Dyn, typename Parameters = common::NoParameters>
+class Dynamics : public common::state::States<Time, Dyn> {
   typedef pdevs::Simulator<Time, Dyn, Parameters> Simulator;
 
 public:
-  struct Observable
-  {
+  struct Observable {
     unsigned int index;
     std::string name;
   };
@@ -54,60 +51,45 @@ public:
   typedef std::map<unsigned int, std::string> Observables;
 
   Dynamics(const std::string &name, const Context<Time, Dyn, Parameters> &context)
-      :
-      _name(name), _simulator(context.simulator())
-  {}
+    :
+    _name(name), _simulator(context.simulator()) {}
 
-  virtual ~Dynamics()
-  {}
+  virtual ~Dynamics() {}
 
   virtual void
   dconf(const typename Time::type & /* t */, const typename Time::type & /* e */,
-        const common::Bag<Time> & /* bag */)
-  {}
+        const common::event::Bag<Time> & /* bag */) {}
 
-  virtual void dint(const typename Time::type & /* t */)
-  {}
+  virtual void dint(const typename Time::type & /* t */) {}
 
   virtual void
   dext(const typename Time::type & /* t */, const typename Time::type & /* e */,
-       const common::Bag<Time> & /* bag */)
-  {}
+       const common::event::Bag<Time> & /* bag */) {}
 
-  virtual void start(const typename Time::type & /* time */)
-  {}
+  virtual void start(const typename Time::type & /* time */) {}
 
   virtual typename Time::type
-  ta(const typename Time::type & /* time */) const
-  { return Time::infinity; }
+  ta(const typename Time::type & /* time */) const { return Time::infinity; }
 
-  virtual common::Bag<Time>
-  lambda(const typename Time::type & /* time */) const
-  { return common::Bag<Time>(); }
+  virtual common::event::Bag<Time>
+  lambda(const typename Time::type & /* time */) const { return common::event::Bag<Time>(); }
 
-  virtual common::Value observe(const typename Time::type & /* t */,
-                                unsigned int /* index */) const
-  { return common::Value(); }
+  virtual common::event::Value observe(const typename Time::type & /* t */,
+                                       unsigned int /* index */) const { return common::event::Value(); }
 
-  virtual typename Time::type lookahead(const typename Time::type &t) const
-  { return t; }
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
-  const std::string &get_name() const
-  { return _name; }
+  const std::string &get_name() const { return _name; }
 
-  std::string get_full_name() const
-  { return _simulator->get_full_name(); }
+  std::string get_full_name() const { return _simulator->get_full_name(); }
 
-  void input_port(common::Port p)
-  {
+  void input_port(common::Port p) {
     _simulator->add_in_port(p);
   }
 
-  size_t input_port_number() const
-  { return _simulator->get_in_port_number(); }
+  size_t input_port_number() const { return _simulator->get_in_port_number(); }
 
-  void input_ports(std::initializer_list<common::Port> list)
-  {
+  void input_ports(std::initializer_list<common::Port> list) {
     for (typename std::initializer_list<common::Port>::iterator it = list.begin();
          it != list.end();
          ++it) {
@@ -115,13 +97,11 @@ public:
     }
   }
 
-  void observable(Observable observable)
-  {
+  void observable(Observable observable) {
     _observables[observable.index] = observable.name;
   }
 
-  void observables(std::initializer_list<Observable> list)
-  {
+  void observables(std::initializer_list<Observable> list) {
     for (typename std::initializer_list<Observable>::iterator it = list.begin();
          it != list.end();
          ++it) {
@@ -129,37 +109,31 @@ public:
     }
   }
 
-  virtual std::string observable_name(unsigned int observable_index) const
-  {
+  virtual std::string observable_name(unsigned int observable_index) const {
     assert(_observables.find(observable_index) != _observables.end());
 
     return _observables.find(observable_index)->second;
   }
 
-  void output_port(common::Port p)
-  {
+  void output_port(common::Port p) {
     _simulator->add_out_port(p);
   }
 
-  size_t output_port_number() const
-  { return _simulator->get_out_port_number(); }
+  size_t output_port_number() const { return _simulator->get_out_port_number(); }
 
-  void output_ports(std::initializer_list<common::Port> list)
-  {
+  void output_ports(std::initializer_list<common::Port> list) {
     for (typename std::initializer_list<common::Port>::iterator it =
-        list.begin(); it != list.end(); ++it) {
+      list.begin(); it != list.end(); ++it) {
       _simulator->add_out_port(*it);
     }
   }
 
-  void restore(const common::context::State<Time> &state)
-  {
-    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+  void restore(const common::context::State<Time> &state) {
+    common::state::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
   }
 
-  void save(common::context::State<Time> &state) const
-  {
-    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+  void save(common::context::State<Time> &state) const {
+    common::state::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
   }
 
 private:
@@ -168,7 +142,6 @@ private:
   Observables _observables;
 };
 
-}
 } // namespace artis pdevs
 
 #endif

+ 40 - 60
src/artis-star/kernel/pdevs/GraphManager.hpp

@@ -36,31 +36,24 @@
 
 #include <sstream>
 
-namespace artis {
-namespace pdevs {
-
-template<class Time,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
-class GraphManager : public common::GraphManager<Time>
-{
+namespace artis::pdevs {
+
+template<typename Time, typename Parameters = common::NoParameters, typename GraphParameters = common::NoParameters>
+class GraphManager : public common::GraphManager<Time> {
 public:
   typedef GraphManager<Time, Parameters, GraphParameters> type;
 
-  struct ModelPort
-  {
+  struct ModelPort {
     common::Model<Time> *model;
     unsigned int port_index;
     type *graph_manager;
 
     ModelPort(common::Model<Time> *model, unsigned int port_index)
-        : model(model),
-          port_index(port_index),
-          graph_manager(nullptr)
-    {}
+      : model(model),
+        port_index(port_index),
+        graph_manager(nullptr) {}
 
-    void operator>>(const ModelPort &dst)
-    {
+    void operator>>(const ModelPort &dst) {
       graph_manager->add_link(model, port_index, dst.model, dst.port_index);
     }
   };
@@ -68,30 +61,26 @@ public:
   GraphManager(common::Coordinator<Time> *coordinator,
                const Parameters & /* parameters */,
                const GraphParameters & /* graph_parameters */)
-      :
-      common::GraphManager<Time>(coordinator)
-  {}
+    :
+    common::GraphManager<Time>(coordinator) {}
 
   ~GraphManager() override = default;
 
-  ModelPort in(ModelPort p)
-  {
+  ModelPort in(ModelPort p) {
     p.graph_manager = this;
     return p;
   }
 
-  ModelPort out(ModelPort p)
-  {
+  ModelPort out(ModelPort p) {
     p.graph_manager = this;
     return p;
   }
 
-  void dispatch_events(common::Bag<Time> bag, typename Time::type t)
-  {
-    for (auto &ymsg : bag) {
+  void dispatch_events(common::event::Bag<Time> bag, typename Time::type t) {
+    for (auto &ymsg: bag) {
       typename common::Links<Time>::Result result_model = _link_list.find(
-          ymsg.get_model(),
-          ymsg.port_index());
+        ymsg.get_model(),
+        ymsg.port_index());
 
       for (typename common::Links<Time>::const_iterator it = result_model.first;
            it != result_model.second; ++it) {
@@ -100,56 +89,51 @@ public:
           dispatch_events_to_parent(it->second, ymsg.data(), t);
         } else { // event on input port of internal model
           it->second.get_model()->post_event(t,
-                                             common::ExternalEvent<Time>(it->second, ymsg.data()));
+                                             common::event::ExternalEvent<Time>(it->second, ymsg.data()));
         }
       }
     }
   }
 
   virtual void
-  dispatch_events_to_parent(common::Node<Time> node, const common::Value &content,
-                            typename Time::type t)
-  {
-    common::Bag<Time> ymessages;
+  dispatch_events_to_parent(common::Node<Time> node, const common::event::Value &content,
+                            typename Time::type t) {
+    common::event::Bag<Time> ymessages;
 
-    ymessages.push_back(common::ExternalEvent<Time>(node, content));
+    ymessages.push_back(common::event::ExternalEvent<Time>(node, content));
 
     if (common::GraphManager<Time>::_coordinator->get_parent()) {
       dynamic_cast < common::Coordinator<Time> * >(common::GraphManager<Time>::_coordinator
-          ->get_parent())
-          ->dispatch_events(ymessages, t);
+        ->get_parent())
+        ->dispatch_events(ymessages, t);
     }
   }
 
   bool exist_link(common::Model<Time> *src_model, unsigned int src_port_index,
-                  common::Model<Time> *dst_model, unsigned int dst_port_index) const
-  {
+                  common::Model<Time> *dst_model, unsigned int dst_port_index) const {
     return _link_list.exist(src_model, src_port_index, dst_model, dst_port_index);
   }
 
-  virtual typename Time::type lookahead(const typename Time::type &t) const
-  { return t; }
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
-  void post_event(typename Time::type t, const common::ExternalEvent<Time> &event)
-  {
+  void post_event(typename Time::type t, const common::event::ExternalEvent<Time> &event) {
     typename common::Links<Time>::Result result =
-        _link_list.find(common::GraphManager<Time>::_coordinator,
-                        event.port_index());
+      _link_list.find(common::GraphManager<Time>::_coordinator,
+                      event.port_index());
 
     for (typename common::Links<Time>::const_iterator it_r = result.first;
          it_r != result.second;
          ++it_r) {
       it_r->second.get_model()->post_event(t,
-                                           common::ExternalEvent<Time>(it_r->second, event.data()));
+                                           common::event::ExternalEvent<Time>(it_r->second, event.data()));
     }
   }
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     std::ostringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "Children :" << std::endl;
-    for (auto &child : common::GraphManager<Time>::_children) {
+    for (auto &child: common::GraphManager<Time>::_children) {
       ss << child->to_string(level + 1);
     }
     ss << _link_list.to_string(level);
@@ -158,31 +142,28 @@ public:
 
 protected:
   void remove_link(common::Model<Time> *src_model, unsigned int src_port_index,
-                   common::Model<Time> *dst_model, unsigned int dst_port_index)
-  {
+                   common::Model<Time> *dst_model, unsigned int dst_port_index) {
     assert(exist_link(src_model, src_port_index, dst_model, dst_port_index));
 
     _link_list.remove(src_model, src_port_index, dst_model, dst_port_index);
   }
 
-  void remove_links(common::Model<Time> *model)
-  {
+  void remove_links(common::Model<Time> *model) {
     _link_list.remove_links(model);
   }
 
 private:
   void add_link(common::Model<Time> *src_model, unsigned int src_port_index,
-                common::Model<Time> *dst_model, unsigned int dst_port_index)
-  {
+                common::Model<Time> *dst_model, unsigned int dst_port_index) {
     assert((src_model != common::GraphManager<Time>::_coordinator and
-        dst_model != common::GraphManager<Time>::_coordinator and
-        src_model->exist_out_port(src_port_index) and
-        dst_model->exist_in_port(dst_port_index)) or
-        (src_model == common::GraphManager<Time>::_coordinator and
+            dst_model != common::GraphManager<Time>::_coordinator and
+            src_model->exist_out_port(src_port_index) and
+            dst_model->exist_in_port(dst_port_index)) or
+           (src_model == common::GraphManager<Time>::_coordinator and
             dst_model != common::GraphManager<Time>::_coordinator and
             src_model->exist_in_port(src_port_index) and
             dst_model->exist_in_port(dst_port_index)) or
-        (src_model != common::GraphManager<Time>::_coordinator and
+           (src_model != common::GraphManager<Time>::_coordinator and
             dst_model == common::GraphManager<Time>::_coordinator and
             src_model->exist_out_port(src_port_index) and
             dst_model->exist_out_port(dst_port_index)));
@@ -193,7 +174,6 @@ private:
   common::Links<Time> _link_list;
 };
 
-}
 } // namespace artis pdevs
 
 #endif

+ 23 - 41
src/artis-star/kernel/pdevs/Simulator.hpp

@@ -34,43 +34,34 @@
 #include <artis-star/common/utils/Trace.hpp>
 #include <artis-star/kernel/pdevs/Context.hpp>
 
-namespace artis {
-namespace pdevs {
+namespace artis::pdevs {
 
-template<class Time, class Dynamics,
-    class Parameters = common::NoParameters>
-class Simulator : public common::Simulator<Time>
-{
+template<typename Time, typename Dynamics, typename Parameters = common::NoParameters>
+class Simulator : public common::Simulator<Time> {
   typedef Simulator<Time, Dynamics, Parameters> type;
 
 public :
   Simulator(const std::string &name, const Parameters &parameters)
-      :
-      common::Model<Time>(name),
-      common::Simulator<Time>(name),
-      _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this))
-  {}
+    :
+    common::Model<Time>(name),
+    common::Simulator<Time>(name),
+    _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)) {}
 
-  ~Simulator()
-  {}
+  ~Simulator() {}
 
-  const Dynamics &dynamics() const
-  { return _dynamics; }
+  const Dynamics &dynamics() const { return _dynamics; }
 
-  virtual void restore(const common::context::State <Time> &state)
-  {
+  virtual void restore(const common::context::State <Time> &state) {
     common::Simulator<Time>::restore(state);
     _dynamics.restore(state);
   }
 
-  virtual void save(common::context::State <Time> &state) const
-  {
+  virtual void save(common::context::State <Time> &state) const {
     common::Simulator<Time>::save(state);
     _dynamics.save(state);
   }
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     std::ostringstream ss;
 
     ss << common::String::make_spaces(level * 2) << "p-devs simulator \""
@@ -78,8 +69,7 @@ public :
     return ss.str();
   }
 
-  virtual void finish(const typename Time::type &t)
-  {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
     (void) t;
 #else
@@ -92,8 +82,7 @@ public :
 #endif
   }
 
-  typename Time::type start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message(t)
 //                  tl = t - e
 //                  tn = tl + ta(s)
@@ -133,18 +122,15 @@ public :
     return type::_tn;
   }
 
-  common::Value observe(const typename Time::type &t, unsigned int index) const
-  {
+  common::event::Value observe(const typename Time::type &t, unsigned int index) const {
     return _dynamics.observe(t, index);
   }
 
-  virtual std::string observable_name(unsigned int observable_index) const
-  {
+  virtual std::string observable_name(unsigned int observable_index) const {
     return _dynamics.observable_name(observable_index);
   }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
 //                When *-message(t)
 //                  if (t = tn) then
 //                    y = lambda(s)
@@ -162,14 +148,14 @@ public :
 #endif
 
     if (t == type::_tn) {
-      common::Bag <Time> bag = _dynamics.lambda(t);
+      common::event::Bag <Time> bag = _dynamics.lambda(t);
 
       if (not bag.empty()) {
-        for (auto &event : bag) {
+        for (auto &event: bag) {
           event.set_model(this);
         }
         dynamic_cast < common::Coordinator <Time> * >(
-            type::get_parent())->dispatch_events(bag, t);
+          type::get_parent())->dispatch_events(bag, t);
       }
     }
 
@@ -185,8 +171,7 @@ public :
 
   }
 
-  void post_event(const typename Time::type &t, const common::ExternalEvent <Time> &event)
-  {
+  void post_event(const typename Time::type &t, const common::event::ExternalEvent <Time> &event) {
 
 #ifndef WITH_TRACE
     (void) t;
@@ -214,8 +199,7 @@ public :
 
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message(t)
 //                  if (x is empty and t = tn) then
 //                    s = delta_int(s)
@@ -272,8 +256,7 @@ public :
     return type::_tn;
   }
 
-  typename Time::type lookahead(const typename Time::type &t) const
-  {
+  typename Time::type lookahead(const typename Time::type &t) const {
     return _dynamics.lookahead(t);
   }
 
@@ -281,7 +264,6 @@ private :
   Dynamics _dynamics;
 };
 
-}
 } // namespace artis pdevs
 
 #endif

+ 15 - 20
src/artis-star/kernel/pdevs/mpi/Coordinator.hpp

@@ -34,37 +34,32 @@ namespace artis {
 namespace pdevs {
 namespace mpi {
 
-template<class Time,
-    class GraphManager,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
+template<typename Time,
+  class GraphManager,
+  class Parameters = common::NoParameters,
+  class GraphParameters = common::NoParameters>
 class Coordinator : public pdevs::Coordinator<Time, GraphManager,
-                                              Parameters, GraphParameters>
-{
+  Parameters, GraphParameters> {
   typedef pdevs::Coordinator<Time, GraphManager,
-                             Parameters, GraphParameters> parent_type;
+    Parameters, GraphParameters> parent_type;
   typedef Coordinator<Time, GraphManager,
-                      Parameters, GraphParameters> type;
+    Parameters, GraphParameters> type;
 
 public:
   Coordinator(const std::string &name,
               const Parameters &parameters,
               const GraphParameters &graph_parameters)
-      :
-      common::Model<Time>(name),
-      pdevs::Coordinator<Time, GraphManager,
-                         Parameters, GraphParameters>(name, parameters,
-                                                      graph_parameters)
-  {}
+    :
+    common::Model<Time>(name),
+    pdevs::Coordinator<Time, GraphManager,
+      Parameters, GraphParameters>(name, parameters,
+                                   graph_parameters) {}
 
-  virtual ~Coordinator()
-  {}
+  virtual ~Coordinator() {}
 
-  virtual bool is_remote() const
-  { return true; }
+  virtual bool is_remote() const { return true; }
 
-  void set_logical_processor(LogicalProcessor<Time> *logical_processor)
-  {
+  void set_logical_processor(LogicalProcessor <Time> *logical_processor) {
     parent_type::_graph_manager.set_logical_processor(logical_processor);
   }
 };

+ 12 - 17
src/artis-star/kernel/pdevs/mpi/GraphManager.hpp

@@ -36,35 +36,30 @@ namespace artis {
 namespace pdevs {
 namespace mpi {
 
-template<class Time,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
-class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters>
-{
+template<typename Time,
+  class Parameters = common::NoParameters,
+  class GraphParameters = common::NoParameters>
+class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters> {
 public:
-  GraphManager(common::Coordinator<Time> *coordinator,
+  GraphManager(common::Coordinator <Time> *coordinator,
                const Parameters &parameters,
                const GraphParameters &graph_parameters)
-      :
-      pdevs::GraphManager<Time, GraphParameters>(coordinator, parameters, graph_parameters)
-  {}
+    :
+    pdevs::GraphManager<Time, GraphParameters>(coordinator, parameters, graph_parameters) {}
 
-  virtual ~GraphManager()
-  {}
+  virtual ~GraphManager() {}
 
-  virtual void dispatch_events_to_parent(common::Node<Time> node,
+  virtual void dispatch_events_to_parent(common::Node <Time> node,
                                          const common::Value &content,
-                                         typename Time::type t)
-  {
+                                         typename Time::type t) {
     _logical_processor->dispatch_events_to_parent(node, content, t);
   }
 
   void set_logical_processor(
-      LogicalProcessor<Time> *logical_processor)
-  { _logical_processor = logical_processor; }
+    LogicalProcessor <Time> *logical_processor) { _logical_processor = logical_processor; }
 
 private:
-  LogicalProcessor<Time> *_logical_processor;
+  LogicalProcessor <Time> *_logical_processor;
 };
 
 }

+ 44 - 45
src/artis-star/kernel/pdevs/mpi/LogicalProcessor.hpp

@@ -35,66 +35,65 @@ namespace artis {
 namespace pdevs {
 namespace mpi {
 
-template<class Time>
-class LogicalProcessor
-{
+template<typename Time>
+class LogicalProcessor {
   typedef LogicalProcessor<Time> type;
 
 public:
-  LogicalProcessor(common::Model<Time> *model, int rank, int parent)
-      :
-      _rank(rank),
-      _parent(parent),
-      _model(model)
-  {}
+  LogicalProcessor(common::Model <Time> *model, int rank, int parent)
+    :
+    _rank(rank),
+    _parent(parent),
+    _model(model) {}
 
-  virtual ~LogicalProcessor()
-  {}
+  virtual ~LogicalProcessor() {}
 
-  void dispatch_events_to_parent(common::Node<Time> node,
+  void dispatch_events_to_parent(common::Node <Time> node,
                                  const common::Value &content,
-                                 typename Time::type t)
-  {
+                                 typename Time::type t) {
     (void) t;
 
     _output_bag.push_back(
-        common::ExternalEvent<Time>(node, content));
+      common::ExternalEvent<Time>(node, content));
   }
 
-  void loop()
-  {
+  void loop() {
     typename Time::type t;
 
     for (;;) {
       boost::mpi::status msg = _communicator.probe();
 
       switch (msg.tag()) {
-      case finish_send_tag:return;
-      case output_send_tag: {
-        _communicator.recv(_parent, output_send_tag, t);
-        _model->output(t);
-        _communicator.send(_parent, output_receive_tag,
-                           _output_bag);
-        _output_bag.clear();
-        break;
-      }
-      case post_event_send_tag: {
-        common::ExternalEvent<Time> event;
-
-        _communicator.recv(_parent, post_event_send_tag, t);
-        _communicator.recv(_parent, post_event_send_tag, event);
-        _model->post_event(t, event);
-        break;
-      }
-      case start_send_tag:_communicator.recv(_parent, start_send_tag, t);
-        _communicator.send(_parent, tn_receive_tag,
-                           _model->start(t));
-        break;
-      case transition_send_tag:_communicator.recv(_parent, transition_send_tag, t);
-        _communicator.send(_parent, tn_receive_tag,
-                           _model->transition(t));
-        break;
-      default:throw std::runtime_error("Invalid tag");
+        case finish_send_tag:
+          return;
+        case output_send_tag: {
+          _communicator.recv(_parent, output_send_tag, t);
+          _model->output(t);
+          _communicator.send(_parent, output_receive_tag,
+                             _output_bag);
+          _output_bag.clear();
+          break;
+        }
+        case post_event_send_tag: {
+          common::ExternalEvent <Time> event;
+
+          _communicator.recv(_parent, post_event_send_tag, t);
+          _communicator.recv(_parent, post_event_send_tag, event);
+          _model->post_event(t, event);
+          break;
+        }
+        case start_send_tag:
+          _communicator.recv(_parent, start_send_tag, t);
+          _communicator.send(_parent, tn_receive_tag,
+                             _model->start(t));
+          break;
+        case transition_send_tag:
+          _communicator.recv(_parent, transition_send_tag, t);
+          _communicator.send(_parent, tn_receive_tag,
+                             _model->transition(t));
+          break;
+        default:
+          throw std::runtime_error("Invalid tag");
       }
     }
   };
@@ -103,8 +102,8 @@ private:
   int _rank;
   int _parent;
   boost::mpi::communicator _communicator;
-  common::Model<Time> *_model;
-  common::Bag<Time> _output_bag;
+  common::Model <Time> *_model;
+  common::Bag <Time> _output_bag;
 };
 
 }

+ 22 - 37
src/artis-star/kernel/pdevs/mpi/ModelProxy.hpp

@@ -36,8 +36,7 @@ namespace artis {
 namespace pdevs {
 namespace mpi {
 
-enum Tags
-{
+enum Tags {
   finish_send_tag,
   output_send_tag,
   post_event_send_tag,
@@ -47,47 +46,38 @@ enum Tags
   tn_receive_tag
 };
 
-template<class Time>
-class ModelProxy : public common::Model<Time>
-{
-  typedef common::Model<Time> parent_type;
+template<typename Time>
+class ModelProxy : public common::Model<Time> {
+  typedef common::Model <Time> parent_type;
   typedef ModelProxy<Time> type;
 
 public:
   ModelProxy(const std::string &name, int rank, bool atomic)
-      :
-      common::Model<Time>(name), _atomic(atomic), _rank(rank)
-  {}
+    :
+    common::Model<Time>(name), _atomic(atomic), _rank(rank) {}
 
-  virtual ~ModelProxy()
-  { _communicator.send(_rank, finish_send_tag); }
+  virtual ~ModelProxy() { _communicator.send(_rank, finish_send_tag); }
 
-  virtual bool is_atomic() const
-  { return _atomic; }
+  virtual bool is_atomic() const { return _atomic; }
 
-  virtual void restore(const common::context::State<Time> &state)
-  {
+  virtual void restore(const common::context::State <Time> &state) {
 // TODO
   }
 
-  virtual void save(common::context::State<Time> &state) const
-  {
+  virtual void save(common::context::State <Time> &state) const {
 // TODO
   }
 
-  virtual std::string to_string(int level) const
-  {
+  virtual std::string to_string(int level) const {
     (void) level;
 
     return std::string();
   }
 
-  virtual void finish(const typename Time::type & /* t */)
-  {}
+  virtual void finish(const typename Time::type & /* t */) {}
 
   virtual common::Value observe(const typename Time::type &t,
-                                unsigned int index) const
-  {
+                                unsigned int index) const {
     (void) t;
     (void) index;
 
@@ -96,8 +86,7 @@ public:
     return common::Value();
   }
 
-  virtual void output(const typename Time::type &t)
-  {
+  virtual void output(const typename Time::type &t) {
     try {
       typename common::Bag<Time> bag;
 
@@ -111,8 +100,7 @@ public:
   }
 
   virtual void post_event(const typename Time::type &t,
-                          const common::ExternalEvent<Time> &event)
-  {
+                          const common::ExternalEvent <Time> &event) {
     try {
       _communicator.send(_rank, post_event_send_tag, t);
       _communicator.send(_rank, post_event_send_tag, event);
@@ -122,18 +110,16 @@ public:
     }
   }
 
-  virtual typename Time::type dispatch_events(common::Bag<Time> &bag,
-                                              const typename Time::type &t)
-  {
-    for (auto &event : bag) {
+  virtual typename Time::type dispatch_events(common::Bag <Time> &bag,
+                                              const typename Time::type &t) {
+    for (auto &event: bag) {
       event.set_model(this);
     }
-    return dynamic_cast < common::Coordinator<Time> * >(
-        parent_type::get_parent())->dispatch_events(bag, t);
+    return dynamic_cast < common::Coordinator <Time> * >(
+      parent_type::get_parent())->dispatch_events(bag, t);
   }
 
-  virtual typename Time::type start(const typename Time::type &t)
-  {
+  virtual typename Time::type start(const typename Time::type &t) {
     try {
       _communicator.send(_rank, start_send_tag, t);
 
@@ -149,8 +135,7 @@ public:
     return type::_tn;
   }
 
-  virtual typename Time::type transition(const typename Time::type &t)
-  {
+  virtual typename Time::type transition(const typename Time::type &t) {
     try {
       _communicator.send(_rank, transition_send_tag, t);
 

+ 90 - 122
src/artis-star/kernel/pdevs/multithreading/Coordinator.hpp

@@ -34,115 +34,97 @@
 #include <mutex>
 #include <thread>
 
-namespace artis {
-namespace pdevs {
-namespace multithreading {
+namespace artis::pdevs::multithreading {
 
-template<class Time>
-struct start_message : common::Message
-{
+template<typename Time>
+struct start_message : common::Message {
   explicit start_message(typename Time::type t)
-      : _t(t)
-  {}
+    : _t(t) {}
 
   typename Time::type _t;
 };
 
-template<class Time>
-struct transition_message : common::Message
-{
+template<typename Time>
+struct transition_message : common::Message {
   explicit transition_message(typename Time::type t)
-      : _t(t)
-  {}
+    : _t(t) {}
 
   typename Time::type _t;
 };
 
-template<class Time>
-struct done_start_message : common::Message
-{
+template<typename Time>
+struct done_start_message : common::Message {
   explicit done_start_message(typename Time::type tn,
-                              common::Model <Time> *child)
-      :
-      _tn(tn), _child(child)
-  {}
+                              common::Model<Time> *child)
+    :
+    _tn(tn), _child(child) {}
 
   typename Time::type _tn;
-  common::Model <Time> *_child;
+  common::Model<Time> *_child;
 };
 
-template<class Time>
-struct done_transition_message : common::Message
-{
+template<typename Time>
+struct done_transition_message : common::Message {
   explicit done_transition_message(typename Time::type tn,
-                                   common::Model <Time> *child)
-      :
-      _tn(tn), _child(child)
-  {}
+                                   common::Model<Time> *child)
+    :
+    _tn(tn), _child(child) {}
 
   typename Time::type _tn;
-  common::Model <Time> *_child;
+  common::Model<Time> *_child;
 };
 
-struct Queues
-{
-  std::shared_ptr <common::MessageQueue> child_queue;
-  std::shared_ptr <common::MessageQueue> parent_queue;
+struct Queues {
+  std::shared_ptr<common::MessageQueue> child_queue;
+  std::shared_ptr<common::MessageQueue> parent_queue;
   std::mutex mutex;
   std::condition_variable condition;
 
-  Queues() : child_queue(new common::MessageQueue), parent_queue(new common::MessageQueue)
-  {}
+  Queues() : child_queue(new common::MessageQueue), parent_queue(new common::MessageQueue) {}
 
-  bool empty() const
-  { return child_queue->empty() and parent_queue->empty(); }
+  bool empty() const { return child_queue->empty() and parent_queue->empty(); }
 
-  std::shared_ptr <common::Message> pop_child_queue()
-  {
-    std::unique_lock <std::mutex> lock(mutex);
-    std::shared_ptr <common::Message> message = child_queue->front();
+  std::shared_ptr<common::Message> pop_child_queue() {
+    std::unique_lock<std::mutex> lock(mutex);
+    std::shared_ptr<common::Message> message = child_queue->front();
 
     child_queue->pop();
     return message;
   }
 
-  std::shared_ptr <common::Message> pop_parent_queue()
-  {
-    std::unique_lock <std::mutex> lock(mutex);
-    std::shared_ptr <common::Message> message = parent_queue->front();
+  std::shared_ptr<common::Message> pop_parent_queue() {
+    std::unique_lock<std::mutex> lock(mutex);
+    std::shared_ptr<common::Message> message = parent_queue->front();
 
     parent_queue->pop();
     return message;
   }
 
-  void push_child_queue(const std::shared_ptr <common::Message> &message)
-  {
-    std::unique_lock <std::mutex> lock(mutex);
+  void push_child_queue(const std::shared_ptr<common::Message> &message) {
+    std::unique_lock<std::mutex> lock(mutex);
 
     child_queue->push(message);
     condition.notify_one();
   }
 
-  void push_parent_queue(const std::shared_ptr <common::Message> &message)
-  {
-    std::unique_lock <std::mutex> lock(mutex);
+  void push_parent_queue(const std::shared_ptr<common::Message> &message) {
+    std::unique_lock<std::mutex> lock(mutex);
 
     parent_queue->push(message);
     condition.notify_one();
   }
 };
 
-template<class Time,
-    class GraphManager,
-    class Parameters = common::NoParameters,
-    class GraphParameters = common::NoParameters>
+template<typename Time,
+  typename GraphManager,
+  typename Parameters = common::NoParameters,
+  typename GraphParameters = common::NoParameters>
 class Coordinator
-    : public pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters>
-{
+  : public pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters> {
   typedef pdevs::Coordinator<Time, GraphManager,
-                             Parameters, GraphParameters> parent_type;
+    Parameters, GraphParameters> parent_type;
   typedef Coordinator<Time, GraphManager,
-                      Parameters, GraphParameters> type;
+    Parameters, GraphParameters> type;
   typedef done_start_message<Time> done_start_message_type;
   typedef start_message<Time> start_message_type;
   typedef done_transition_message<Time> done_transition_message_type;
@@ -152,73 +134,66 @@ public:
   Coordinator(const std::string &name,
               const Parameters &parameters,
               const GraphParameters &graph_parameters)
-      :
-      common::Model<Time>(name),
-      pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters>(
-          name, parameters, graph_parameters),
-      _queues(new Queues)
-  {
+    :
+    common::Model<Time>(name),
+    pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters>(
+      name, parameters, graph_parameters),
+    _queues(new Queues) {
     type::_graph_manager.init();
     _thread = std::make_shared<std::thread>([&] { loop(); });
   }
 
-  virtual ~Coordinator()
-  {
+  virtual ~Coordinator() {
     done();
     _thread->join();
   }
 
-  void attach_child(common::Model <Time> *model,
-                    const std::shared_ptr <Queues> &child_queue)
-  {
+  void attach_child(common::Model<Time> *model,
+                    const std::shared_ptr<Queues> &child_queue) {
     _child_queues[model] = child_queue;
   }
 
-  void attach_parent(const std::shared_ptr <Queues> &parent_queue)
-  {
+  void attach_parent(const std::shared_ptr<Queues> &parent_queue) {
     _parent_queue = parent_queue;
   }
 
-  void done()
-  {
+  void done() {
     _queues->push_parent_queue(std::shared_ptr<artis::common::Message>(new artis::common::Close));
   }
 
-  const std::shared_ptr <Queues> &get_queue() const
-  {
+  const std::shared_ptr<Queues> &get_queue() const {
     return _queues;
   }
 
-  bool process(const common::Message *message)
-  {
+  bool process(const common::Message *message) {
     if (const done_transition_message<Time>
-        *m = dynamic_cast< const done_transition_message<Time> *>(message)) {
+      *m = dynamic_cast< const done_transition_message<Time> *>(message)) {
       type::_event_table.put(m->_tn, m->_child);
       --_received;
       if (_received == 0) {
-        std::unique_lock <std::mutex> lock(_received_mutex);
+        std::unique_lock<std::mutex> lock(_received_mutex);
 
         _received_condition.notify_one();
       }
     } else if (const transition_message<Time>
-        *m = dynamic_cast< const transition_message<Time> *>(message)) {
+      *m = dynamic_cast< const transition_message<Time> *>(message)) {
       typename Time::type tn = transition(m->_t);
 
       _parent_queue
-          ->push_parent_queue(
-              std::shared_ptr<common::Message>(new done_transition_message_type(tn, this)));
+        ->push_parent_queue(
+          std::shared_ptr<common::Message>(new done_transition_message_type(tn, this)));
     } else if (const start_message<Time> *m = dynamic_cast< const start_message<Time> *>(message)) {
       typename Time::type tn = start(m->_t);
 
       _parent_queue
-          ->push_parent_queue(
-              std::shared_ptr<common::Message>(new done_start_message_type(tn, this)));
+        ->push_parent_queue(
+          std::shared_ptr<common::Message>(new done_start_message_type(tn, this)));
     } else if (const done_start_message<Time>
-        *m = dynamic_cast< const done_start_message<Time> *>(message)) {
+      *m = dynamic_cast< const done_start_message<Time> *>(message)) {
       type::_event_table.init(m->_tn, m->_child);
       --_received;
       if (_received == 0) {
-        std::unique_lock <std::mutex> lock(_received_mutex);
+        std::unique_lock<std::mutex> lock(_received_mutex);
 
         _received_condition.notify_one();
       }
@@ -228,23 +203,22 @@ public:
     return true;
   }
 
-  void loop()
-  {
+  void loop() {
     while (true) {
       {
-        std::unique_lock <std::mutex> lock(_queues->mutex);
+        std::unique_lock<std::mutex> lock(_queues->mutex);
 
         while (_queues->empty()) {
           _queues->condition.wait(lock);
         }
       }
       if (not _queues->child_queue->empty()) {
-        std::shared_ptr <common::Message> message = _queues->pop_child_queue();
+        std::shared_ptr<common::Message> message = _queues->pop_child_queue();
 
         process(message.get());
       }
       if (not _queues->parent_queue->empty()) {
-        std::shared_ptr <common::Message> message = _queues->pop_parent_queue();
+        std::shared_ptr<common::Message> message = _queues->pop_parent_queue();
 
         if (not process(message.get())) {
           break;
@@ -253,11 +227,9 @@ public:
     }
   }
 
-  typename Time::type
-  start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
     _received = 0;
-    for (auto &child : parent_type::_graph_manager.children()) {
+    for (auto &child: parent_type::_graph_manager.children()) {
       if (child->is_atomic()) {
         type::_event_table.init(child->start(type::_tn), child);
       } else {
@@ -266,11 +238,11 @@ public:
     }
 
     if (_received > 0) {
-      std::unique_lock <std::mutex> lock(_received_mutex);
+      std::unique_lock<std::mutex> lock(_received_mutex);
 
-      for (const auto &q:_child_queues) {
+      for (const auto &q: _child_queues) {
         q.second
-            ->push_child_queue(std::shared_ptr<artis::common::Message>(new start_message<Time>(t)));
+          ->push_child_queue(std::shared_ptr<artis::common::Message>(new start_message<Time>(t)));
       }
       _received_condition.wait(lock);
     }
@@ -280,36 +252,34 @@ public:
     return type::_tn;
   }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
 
     assert(t == type::_tn);
 
-    common::Models <Time> IMM = type::_event_table.get_current_models(t);
+    common::Models<Time> IMM = type::_event_table.get_current_models(t);
 
-    for (auto &model : IMM) {
+    for (auto &model: IMM) {
       model->output(t);
     }
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
     assert(t >= type::_tl and t <= type::_tn);
 
-    common::Models <Time> receivers = type::get_receivers();
-    common::Models <Time> IMM = type::_event_table.get_current_models(t);
+    common::Models<Time> receivers = type::get_receivers();
+    common::Models<Time> IMM = type::_event_table.get_current_models(t);
 //    common::Models <Time>
 //        IMM = type::_event_table.get_current_models(t, type::_graph_manager.lookahead(t));
 
     _received = 0;
-    for (auto &model : receivers) {
+    for (auto &model: receivers) {
       if (model->is_atomic()) {
         type::_event_table.put(model->transition(t), model);
       } else {
         ++_received;
       }
     }
-    for (auto &model : IMM) {
+    for (auto &model: IMM) {
       if (std::find(receivers.begin(), receivers.end(), model) == receivers.end()) {
         if (model->is_atomic()) {
           type::_event_table.put(model->transition(model->get_tn()), model);
@@ -320,29 +290,29 @@ public:
     }
 
     if (_received > 0) {
-      std::unique_lock <std::mutex> lock(_received_mutex);
+      std::unique_lock<std::mutex> lock(_received_mutex);
 
       if (not receivers.empty()) {
         std::for_each(receivers.begin(), receivers.end(),
-                      [this, t](common::Model <Time> *model) {
+                      [this, t](common::Model<Time> *model) {
                         auto it = _child_queues.find(model);
 
                         if (it != _child_queues.end()) {
                           it->second->push_child_queue(
-                              std::shared_ptr<artis::common::Message>(
-                                  new transition_message<Time>(t)));
+                            std::shared_ptr<artis::common::Message>(
+                              new transition_message<Time>(t)));
                         }
                       });
       }
       if (not IMM.empty()) {
         std::for_each(IMM.begin(), IMM.end(),
-                      [this, t](common::Model <Time> *model) {
+                      [this, t](common::Model<Time> *model) {
                         auto it = _child_queues.find(model);
 
                         if (it != _child_queues.end()) {
                           it->second->push_child_queue(
-                              std::shared_ptr<artis::common::Message>(
-                                  new transition_message<Time>(model->get_tn())));
+                            std::shared_ptr<artis::common::Message>(
+                              new transition_message<Time>(model->get_tn())));
                         }
                       });
       }
@@ -356,17 +326,15 @@ public:
   }
 
 private:
-  std::shared_ptr <std::thread> _thread;
-  std::shared_ptr <Queues> _queues;
+  std::shared_ptr<std::thread> _thread;
+  std::shared_ptr<Queues> _queues;
   unsigned int _received;
   std::mutex _received_mutex;
   std::condition_variable _received_condition;
-  std::shared_ptr <Queues> _parent_queue;
-  std::map<common::Model < Time> *, std::shared_ptr <Queues >> _child_queues;
+  std::shared_ptr<Queues> _parent_queue;
+  std::map<common::Model<Time> *, std::shared_ptr<Queues >> _child_queues;
 };
 
-}
-}
 } // namespace artis pdevs multithreading
 
 #endif

+ 4 - 9
src/artis-star/kernel/qss/Data.hpp

@@ -27,26 +27,21 @@
 #ifndef QSS_DATA
 #define QSS_DATA
 
-namespace artis {
-namespace qss {
+namespace artis::qss {
 
-struct IntegratorData
-{
+struct IntegratorData {
   double value;
 };
 
-struct DerivativeData
-{
+struct DerivativeData {
   double x_dot;
 };
 
-struct QuantifierData
-{
+struct QuantifierData {
   double up;
   double down;
 };
 
-}
 }
 
 #endif

+ 67 - 85
src/artis-star/kernel/qss/Derivative.hpp

@@ -30,33 +30,25 @@
 #include <artis-star/kernel/pdevs/Dynamics.hpp>
 #include <artis-star/kernel/qss/Data.hpp>
 
-namespace artis {
-namespace qss {
+namespace artis::qss {
 
-template<class Time, class Dyn, class Parameters = common::NoParameters>
-class Derivative : public artis::pdevs::Dynamics<Time, Dyn, Parameters>
-{
+template<typename Time, typename Dyn, typename Parameters = common::NoParameters>
+class Derivative : public artis::pdevs::Dynamics<Time, Dyn, Parameters> {
 public:
-  struct input
-  {
-    enum values
-    {
+  struct input {
+    enum values {
       RESET = 0, IN
     };
   };
 
-  struct output
-  {
-    enum values
-    {
+  struct output {
+    enum values {
       OUT = 0
     };
   };
 
-  struct var
-  {
-    enum values
-    {
+  struct var {
+    enum values {
       VALUE
     };
   };
@@ -64,37 +56,33 @@ public:
   typedef Derivative<Time, Dyn, Parameters> type;
 
   Derivative(const std::string &name, const artis::pdevs::Context<Time, Dyn, Parameters> &context)
-      :
-      artis::pdevs::Dynamics<Time, Dyn, Parameters>(name, context),
-      _external_number(0), _internal_number(0)
-  {
+    :
+    artis::pdevs::Dynamics<Time, Dyn, Parameters>(name, context),
+    _external_number(0), _internal_number(0) {
     DECLARE_STATES(int,
                    ((state::PHASE, &type::_phase)));
     DECLARE_STATES(unsigned int,
                    ((state::INPUT_NUMBER, &type::_input_number)));
     DECLARE_STATES(double,
                    ((state::OUTPUT_VALUE, &type::_output_value),
-                       (state::LAST_OUTPUT, &type::_last_output)));
+                     (state::LAST_OUTPUT, &type::_last_output)));
 
     this->input_ports({{input::RESET, "reset"},
-                       {input::IN, "in"}});
+                       {input::IN,    "in"}});
     this->output_port({output::OUT, "out"});
     this->observable({var::VALUE, "value"});
   }
 
-  virtual ~Derivative()
-  {}
+  virtual ~Derivative() {}
 
-  int external(const std::string &name, double Dyn::* var)
-  {
+  int external(const std::string &name, double Dyn::* var) {
     ++_external_number;
     this->state_(state::LAST_OUTPUT + _external_number + 1, name, var);
     this->input_port({input::IN + _external_number, name});
     return input::IN + _external_number;
   }
 
-  void internal(const std::string &name, double Dyn::* var)
-  {
+  void internal(const std::string &name, double Dyn::* var) {
     assert(_internal_number == 0);
 
     ++_internal_number;
@@ -104,14 +92,12 @@ public:
   virtual double compute() const = 0;
 
   virtual void dconf(const typename Time::type &t, typename Time::type e,
-                     const common::Bag<Time> &bag)
-  {
+                     const common::event::Bag<Time> &bag) {
     dint(t);
     dext(t, e, bag);
   }
 
-  virtual void dint(const typename Time::type & /* time */)
-  {
+  virtual void dint(const typename Time::type & /* time */) {
     if (_phase == phase::RESPONSE) {
       _last_output = _output_value;
     }
@@ -119,10 +105,9 @@ public:
   }
 
   virtual void dext(const typename Time::type &t, typename Time::type e,
-                    const common::Bag<Time> &bag)
-  {
+                    const common::event::Bag<Time> &bag) {
     std::for_each(bag.begin(), bag.end(),
-                  [this, t, e](const common::ExternalEvent<Time> &event) {
+                  [this, t, e](const common::event::ExternalEvent<Time> &event) {
                     if (event.on_port(input::RESET)) {
                       _input_number = 0;
                       _phase = phase::INIT;
@@ -131,86 +116,84 @@ public:
 
                       event.data()(data);
                       this->get((event.port_index() - 1) + state::LAST_OUTPUT + 1).put(
-                          dynamic_cast<Dyn *>(this), data.value);
+                        dynamic_cast<Dyn *>(this), data.value);
                       switch (_phase) {
-                      case phase::INIT: {
-                        ++_input_number;
-                        if (_input_number == this->state_number() - (state::LAST_OUTPUT + 1)) {
-                          _output_value = compute();
-                          _phase = phase::RESPONSE;
+                        case phase::INIT: {
+                          ++_input_number;
+                          if (_input_number == this->state_number() - (state::LAST_OUTPUT + 1)) {
+                            _output_value = compute();
+                            _phase = phase::RESPONSE;
+                          }
+                          break;
                         }
-                        break;
-                      }
-                      case phase::WAIT:
-                      case phase::RESPONSE: {
-                        double value = compute();
-
-                        if (value != _last_output) {
-                          _output_value = value;
-                          _phase = phase::RESPONSE;
-                        } else {
-                          _phase = phase::WAIT;
+                        case phase::WAIT:
+                        case phase::RESPONSE: {
+                          double value = compute();
+
+                          if (value != _last_output) {
+                            _output_value = value;
+                            _phase = phase::RESPONSE;
+                          } else {
+                            _phase = phase::WAIT;
+                          }
                         }
                       }
-                      }
                     }
                   });
   }
 
-  virtual void start(const typename Time::type & /* time */)
-  {
+  virtual void start(const typename Time::type & /* time */) {
     _input_number = 0;
     _phase = phase::INIT;
   }
 
-  virtual typename Time::type ta(const typename Time::type & /* time */)
-  {
+  virtual typename Time::type ta(const typename Time::type & /* time */) {
     switch (_phase) {
-    case phase::INIT:return Time::infinity;
-    case phase::WAIT:return Time::infinity;
-    case phase::RESPONSE:return 0;
+      case phase::INIT:
+        return Time::infinity;
+      case phase::WAIT:
+        return Time::infinity;
+      case phase::RESPONSE:
+        return 0;
     }
     return Time::infinity;
   }
 
-  virtual common::Bag<Time> lambda(const typename Time::type & /* time */) const
-  {
-    common::Bag<Time> msgs;
+  virtual common::event::Bag<Time> lambda(const typename Time::type & /* time */) const {
+    common::event::Bag<Time> msgs;
 
     switch (_phase) {
-    case phase::INIT:break;
-    case phase::WAIT:break;
-    case phase::RESPONSE: {
-      const DerivativeData data = {_output_value};
-
-      msgs.push_back(common::ExternalEvent<Time>(output::OUT, data));
-    }
+      case phase::INIT:
+        break;
+      case phase::WAIT:
+        break;
+      case phase::RESPONSE: {
+        const DerivativeData data = {_output_value};
+
+        msgs.push_back(common::event::ExternalEvent<Time>(output::OUT, data));
+      }
     }
     return msgs;
   }
 
-  virtual common::Value observe(const typename Time::type & /* t */,
-                                unsigned int index) const
-  {
+  virtual common::event::Value observe(const typename Time::type & /* t */, unsigned int index) const {
     switch (index) {
-    case var::VALUE:return (double) (_output_value);
-    default:return common::Value();
+      case var::VALUE:
+        return (double) (_output_value);
+      default:
+        return common::event::Value();
     }
   }
 
 private:
-  struct phase
-  {
-    enum values
-    {
+  struct phase {
+    enum values {
       INIT = 0, WAIT, RESPONSE
     };
   };
 
-  struct state
-  {
-    enum values
-    {
+  struct state {
+    enum values {
       PHASE = 0, INPUT_NUMBER, OUTPUT_VALUE, LAST_OUTPUT
     };
   };
@@ -225,7 +208,6 @@ private:
   double _last_output;
 };
 
-}
 }
 
 #endif

+ 95 - 114
src/artis-star/kernel/qss/Integrator.hpp

@@ -30,116 +30,103 @@
 #include <artis-star/kernel/pdevs/Dynamics.hpp>
 #include <artis-star/kernel/qss/Data.hpp>
 
-namespace artis {
-namespace qss {
+namespace artis::qss {
 
-struct IntegratorParameters
-{
+struct IntegratorParameters {
   double x_0;
 };
 
-template<class Time>
+template<typename Time>
 class Integrator
-    : public artis::pdevs::Dynamics<Time, Integrator<Time>, IntegratorParameters>
-{
+  : public artis::pdevs::Dynamics<Time, Integrator<Time>, IntegratorParameters> {
 public:
-  struct input
-  {
-    enum values
-    {
+  struct input {
+    enum values {
       QUANTA, X_DOT, RESET
     };
   };
 
-  struct output
-  {
-    enum values
-    {
+  struct output {
+    enum values {
       OUT
     };
   };
 
-  struct var
-  {
-    enum values
-    {
+  struct var {
+    enum values {
       VALUE
     };
   };
 
   Integrator(const std::string &name,
              const artis::pdevs::Context<Time, Integrator<Time>, IntegratorParameters> &context)
-      :
-      artis::pdevs::Dynamics<Time, Integrator<Time>, IntegratorParameters>(name,
-                                                                           context)
-  {
+    :
+    artis::pdevs::Dynamics<Time, Integrator<Time>, IntegratorParameters>(name,
+                                                                         context) {
     DECLARE_STATES(int, ((state::PHASE, &Integrator<Time>::_phase)));
     DECLARE_STATES(typename Time::type,
                    ((state::LAST_OUT_DATE, &Integrator<Time>::_last_output_date)));
     DECLARE_STATES(double, ((state::UP_THRESHOLD, &Integrator<Time>::_up_threshold),
-        (state::DOWN_THRESHOLD, &Integrator<Time>::_down_threshold),
-        (state::LAST_OUT_VALUE, &Integrator<Time>::_last_output_value),
-        (state::INIT_VALUE, &Integrator<Time>::_init_value),
-        (state::CURRENT_VALUE, &Integrator<Time>::_current_value),
-        (state::EXPECTED_VALUE, &Integrator<Time>::_expected_value)));
-    DECLARE_STATES(std::vector<double>,
+      (state::DOWN_THRESHOLD, &Integrator<Time>::_down_threshold),
+      (state::LAST_OUT_VALUE, &Integrator<Time>::_last_output_value),
+      (state::INIT_VALUE, &Integrator<Time>::_init_value),
+      (state::CURRENT_VALUE, &Integrator<Time>::_current_value),
+      (state::EXPECTED_VALUE, &Integrator<Time>::_expected_value)));
+    DECLARE_STATES(std::vector < double > ,
                    ((state::ARCHIVE_X_DOT, &Integrator<Time>::_archive_x_dot)));
-    DECLARE_STATES(std::vector<typename Time::type>,
+    DECLARE_STATES(std::vector < typename Time::type > ,
                    ((state::ARCHIVE_DATE, &Integrator<Time>::_archive_date)));
 
     this->input_ports({
-                          {input::QUANTA, "quanta"},
-                          {input::X_DOT, "x_dot"},
-                          {input::RESET, "reset"}});
+                        {input::QUANTA, "quanta"},
+                        {input::X_DOT,  "x_dot"},
+                        {input::RESET,  "reset"}});
     this->output_port({output::OUT, "out"});
     this->observable({var::VALUE, "value"});
 
     _init_value = context.parameters().x_0;
   }
 
-  virtual ~Integrator()
-  {}
+  virtual ~Integrator() {}
 
   virtual void dconf(typename Time::type t, typename Time::type e,
-                     const common::Bag<Time> &bag)
-  {
+                     const common::event::Bag <Time> &bag) {
     dint(t);
     dext(t, e, bag);
   }
 
-  virtual void dint(const typename Time::type &time)
-  {
+  virtual void dint(const typename Time::type &time) {
     switch (_phase) {
-    case phase::RUNNING: {
-      double last_derivative_value = _archive_x_dot.back();
-
-      _last_output_value = _expected_value;
-      _last_output_date = time;
-      _archive_x_dot.clear();
-      _archive_date.clear();
-      _archive_x_dot.push_back(last_derivative_value);
-      _archive_date.push_back(time);
-      _current_value = _expected_value;
-      _phase = phase::WAIT_FOR_QUANTA;
-      break;
-    }
-    case phase::INIT: {
-      _phase = phase::WAIT_FOR_BOTH;
-      _last_output_value = _current_value;
-      _last_output_date = time;
-      break;
-    }
-    default:assert(false);
+      case phase::RUNNING: {
+        double last_derivative_value = _archive_x_dot.back();
+
+        _last_output_value = _expected_value;
+        _last_output_date = time;
+        _archive_x_dot.clear();
+        _archive_date.clear();
+        _archive_x_dot.push_back(last_derivative_value);
+        _archive_date.push_back(time);
+        _current_value = _expected_value;
+        _phase = phase::WAIT_FOR_QUANTA;
+        break;
+      }
+      case phase::INIT: {
+        _phase = phase::WAIT_FOR_BOTH;
+        _last_output_value = _current_value;
+        _last_output_date = time;
+        break;
+      }
+      default:
+        assert(false);
     }
   }
 
   virtual void dext(const typename Time::type &t, const typename Time::type &e,
-                    const common::Bag<Time> &bag)
-  {
+                    const common::event::Bag <Time> &bag) {
     bool reset = false;
 
     std::for_each(bag.begin(), bag.end(),
-                  [this, t, e, &reset](const common::ExternalEvent<Time> &event) {
+                  [this, t, e, &reset](const common::event::ExternalEvent <Time> &event) {
                     if (event.on_port(input::QUANTA)) {
                       QuantifierData data;
 
@@ -184,89 +171,88 @@ public:
     }
   }
 
-  virtual void start(const typename Time::type & /* time */)
-  {
+  virtual void start(const typename Time::type & /* time */) {
     _current_value = _init_value;
     _phase = phase::INIT;
   }
 
-  virtual typename Time::type ta(const typename Time::type & /* time */)
-  {
+  virtual typename Time::type ta(const typename Time::type & /* time */) {
     double current_derivative;
 
     switch (_phase) {
-    case phase::INIT:return 0;
-    case phase::RUNNING:
+      case phase::INIT:
+        return 0;
+      case phase::RUNNING:
 
-      assert(_archive_date.size() > 0);
+        assert(_archive_date.size() > 0);
 
-      current_derivative = _archive_x_dot.back();
-      if (current_derivative == 0) {
-        return Time::infinity;
-      }
-      if (current_derivative > 0) {
+        current_derivative = _archive_x_dot.back();
+        if (current_derivative == 0) {
+          return Time::infinity;
+        }
+        if (current_derivative > 0) {
 
-        assert(_up_threshold - _current_value >= 0);
+          assert(_up_threshold - _current_value >= 0);
 
-        return (_up_threshold - _current_value) / current_derivative;
-      } else {
+          return (_up_threshold - _current_value) / current_derivative;
+        } else {
 
-        assert(_down_threshold - _current_value <= 0);
+          assert(_down_threshold - _current_value <= 0);
 
-        return (_down_threshold - _current_value) / current_derivative;
-      }
-    default:return Time::infinity;
+          return (_down_threshold - _current_value) / current_derivative;
+        }
+      default:
+        return Time::infinity;
     }
   }
 
-  virtual common::Bag<Time> lambda(const typename Time::type & /* time */) const
-  {
-    common::Bag<Time> msgs;
+  virtual common::event::Bag <Time> lambda(const typename Time::type & /* time */) const {
+    common::event::Bag <Time> msgs;
 
     switch (_phase) {
-    case phase::RUNNING: {
-      const IntegratorData data = {_expected_value};
+      case phase::RUNNING: {
+        const IntegratorData data = {_expected_value};
 
-      msgs.push_back(common::ExternalEvent<Time>(output::OUT, data));
-      break;
-    }
-    case phase::INIT: {
-      const IntegratorData data = {_current_value};
+        msgs.push_back(common::event::ExternalEvent<Time>(output::OUT, data));
+        break;
+      }
+      case phase::INIT: {
+        const IntegratorData data = {_current_value};
 
-      msgs.push_back(common::ExternalEvent<Time>(output::OUT, data));
-      break;
-    }
-    default:break;
+        msgs.push_back(common::event::ExternalEvent<Time>(output::OUT, data));
+        break;
+      }
+      default:
+        break;
     }
     return msgs;
   }
 
-  virtual common::Value observe(const typename Time::type & /* t */,
-                                unsigned int index) const
-  {
+  virtual common::event::Value observe(const typename Time::type & /* t */,
+                                unsigned int index) const {
     switch (index) {
-    case var::VALUE:return (double) (_current_value);
-    default:return common::Value();
+      case var::VALUE:
+        return (double) (_current_value);
+      default:
+        return common::event::Value();
     }
   }
 
 private:
-  double current_value(const typename Time::type &time) const
-  {
+  double current_value(const typename Time::type &time) const {
     double val = _last_output_value;
 
     if (_archive_date.size() > 0) {
       for (size_t i = 0; i < _archive_date.size() - 1; i++) {
         val +=
-            (_archive_date[i + 1] - _archive_date[i]) * _archive_x_dot[i];
+          (_archive_date[i + 1] - _archive_date[i]) * _archive_x_dot[i];
       }
       val += (time - _archive_date.back()) * _archive_x_dot.back();
     }
     return val;
   }
 
-  double expected_value(const typename Time::type & /* time */) const
-  {
+  double expected_value(const typename Time::type & /* time */) const {
     double current_derivative = _archive_x_dot.back();
 
     if (current_derivative == 0) {
@@ -277,10 +263,8 @@ private:
     return _down_threshold;
   }
 
-  struct phase
-  {
-    enum values
-    {
+  struct phase {
+    enum values {
       INIT,
       WAIT_FOR_QUANTA,
       WAIT_FOR_X_DOT,
@@ -289,10 +273,8 @@ private:
     };
   };
 
-  struct state
-  {
-    enum values
-    {
+  struct state {
+    enum values {
       PHASE,
       LAST_OUT_DATE,
       UP_THRESHOLD,
@@ -322,7 +304,6 @@ private:
   std::vector<typename Time::type> _archive_date;
 };
 
-}
 }
 
 #endif

+ 75 - 95
src/artis-star/kernel/qss/MultiDerivative.hpp

@@ -29,25 +29,19 @@
 
 #include <artis-star/kernel/pdevs/Dynamics.hpp>
 
-namespace artis {
-namespace qss {
+namespace artis::qss {
 
-template<class Time, class Dyn, class Parameters = common::NoParameters>
-class MultiDerivative : public artis::pdevs::Dynamics<Time, Dyn, Parameters>
-{
+template<typename Time, typename Dyn, typename Parameters = common::NoParameters>
+class MultiDerivative : public artis::pdevs::Dynamics<Time, Dyn, Parameters> {
 public:
-  struct input
-  {
-    enum values
-    {
+  struct input {
+    enum values {
       RESET = 0, INTERNAL = 1, EXTERNAL = 1000
     };
   };
 
-  struct var
-  {
-    enum values
-    {
+  struct var {
+    enum values {
       VALUE
     };
   };
@@ -56,26 +50,23 @@ public:
 
   MultiDerivative(const std::string &name,
                   const artis::pdevs::Context<Time, Dyn, Parameters> &context)
-      :
-      artis::pdevs::Dynamics<Time, Dyn, Parameters>(name, context),
-      _external_number(0), _internal_number(0), _variable_number(0)
-  {
+    :
+    artis::pdevs::Dynamics<Time, Dyn, Parameters>(name, context),
+    _external_number(0), _internal_number(0), _variable_number(0) {
     DECLARE_STATES(int,
                    ((state::PHASE, &type::_phase)));
     DECLARE_STATES(unsigned int,
                    ((state::INPUT_NUMBER, &type::_input_number)));
-    DECLARE_STATES(std::vector<double>,
+    DECLARE_STATES(std::vector < double > ,
                    ((state::OUTPUT_VALUES, &type::_output_values),
-                       (state::LAST_OUTPUTS, &type::_last_outputs)));
+                     (state::LAST_OUTPUTS, &type::_last_outputs)));
 
     this->input_port({input::RESET, "reset"});
   }
 
-  virtual ~MultiDerivative()
-  {}
+  virtual ~MultiDerivative() {}
 
-  int external(const std::string &name, double Dyn::* var)
-  {
+  int external(const std::string &name, double Dyn::* var) {
     this->state_(state::LAST_OUTPUTS + _variable_number + 1, name, var);
     this->input_port({input::EXTERNAL + _external_number, name});
     ++_variable_number;
@@ -83,8 +74,7 @@ public:
     return input::EXTERNAL + _external_number - 1;
   }
 
-  void internal(const std::string &name, double Dyn::* var)
-  {
+  void internal(const std::string &name, double Dyn::* var) {
 
     assert(_external_number == 0);
 
@@ -99,14 +89,12 @@ public:
   virtual std::vector<double> compute() = 0;
 
   virtual void dconf(const typename Time::type &t, typename Time::type e,
-                     const common::Bag<Time> &bag)
-  {
+                     const common::event::Bag <Time> &bag) {
     dint(t);
     dext(t, e, bag);
   }
 
-  virtual void dint(const typename Time::type & /* t */)
-  {
+  virtual void dint(const typename Time::type & /* t */) {
     if (_phase == phase::RESPONSE) {
       _last_outputs.assign(_output_values.begin(), _output_values.end());
     }
@@ -114,10 +102,9 @@ public:
   }
 
   virtual void dext(const typename Time::type &t, typename Time::type e,
-                    const common::Bag<Time> &bag)
-  {
+                    const common::event::Bag <Time> &bag) {
     std::for_each(bag.begin(), bag.end(),
-                  [this, t, e](const common::ExternalEvent<Time> &event) {
+                  [this, t, e](const common::event::ExternalEvent <Time> &event) {
                     if (event.on_port(input::RESET)) {
                       _input_number = 0;
                       _phase = phase::INIT;
@@ -128,107 +115,105 @@ public:
                       if (event.port_index() >= input::INTERNAL
                           and event.port_index() < input::EXTERNAL) {
                         this->get((event.port_index() - input::INTERNAL) + state::LAST_OUTPUTS + 1)
-                            .put(
-                                static_cast<Dyn *>(this), data.value);
+                          .put(
+                            static_cast<Dyn *>(this), data.value);
                       } else {
 
                         assert(event.port_index() >= input::EXTERNAL);
 
                         this->get((event.port_index() - input::EXTERNAL) + state::LAST_OUTPUTS + 1)
-                            .put(
-                                static_cast<Dyn *>(this), data.value);
+                          .put(
+                            static_cast<Dyn *>(this), data.value);
                       }
                       switch (_phase) {
-                      case phase::INIT: {
-                        ++_input_number;
-                        if (_input_number == this->state_number() - (state::LAST_OUTPUTS + 1)) {
+                        case phase::INIT: {
+                          ++_input_number;
+                          if (_input_number == this->state_number() - (state::LAST_OUTPUTS + 1)) {
+                            std::vector<double> values = compute();
+
+                            assign_values(values);
+                            _phase = phase::RESPONSE;
+                          }
+                          break;
+                        }
+                        case phase::WAIT:
+                        case phase::RESPONSE: {
                           std::vector<double> values = compute();
 
-                          assign_values(values);
-                          _phase = phase::RESPONSE;
-                        }
-                        break;
-                      }
-                      case phase::WAIT:
-                      case phase::RESPONSE: {
-                        std::vector<double> values = compute();
-
-                        if (is_different_values(values)) {
-                          assign_values(values);
-                          _phase = phase::RESPONSE;
-                        } else {
-                          _phase = phase::WAIT;
+                          if (is_different_values(values)) {
+                            assign_values(values);
+                            _phase = phase::RESPONSE;
+                          } else {
+                            _phase = phase::WAIT;
+                          }
                         }
                       }
-                      }
                     }
                   });
   }
 
-  virtual void start(const typename Time::type & /* time */)
-  {
+  virtual void start(const typename Time::type & /* time */) {
     _output_values = std::vector<double>(_internal_number);
     _last_outputs = std::vector<double>(_internal_number);
     _input_number = 0;
     _phase = phase::INIT;
   }
 
-  virtual typename Time::type ta(const typename Time::type & /* time */)
-  {
+  virtual typename Time::type ta(const typename Time::type & /* time */) {
     switch (_phase) {
-    case phase::INIT:return Time::infinity;
-    case phase::WAIT:return Time::infinity;
-    case phase::RESPONSE:return 0;
+      case phase::INIT:
+        return Time::infinity;
+      case phase::WAIT:
+        return Time::infinity;
+      case phase::RESPONSE:
+        return 0;
     }
     return Time::infinity;
   }
 
-  virtual common::Bag<Time> lambda(const typename Time::type & /* time */) const
-  {
-    common::Bag<Time> msgs;
+  virtual common::event::Bag <Time> lambda(const typename Time::type & /* time */) const {
+    common::event::Bag <Time> msgs;
 
     switch (_phase) {
-    case phase::INIT:break;
-    case phase::WAIT:break;
-    case phase::RESPONSE: {
-      unsigned int index = 0;
-
-      for (double value: _output_values) {
-        if (value != _last_outputs[index]) {
-          const DerivativeData data = {value};
-
-          msgs.push_back(common::ExternalEvent<Time>(index, data));
+      case phase::INIT:
+        break;
+      case phase::WAIT:
+        break;
+      case phase::RESPONSE: {
+        unsigned int index = 0;
+
+        for (double value: _output_values) {
+          if (value != _last_outputs[index]) {
+            const DerivativeData data = {value};
+
+            msgs.push_back(common::event::ExternalEvent<Time>(index, data));
+          }
+          ++index;
         }
-        ++index;
       }
     }
-    }
     return msgs;
   }
 
-  virtual common::Value observe(const typename Time::type & /* t */,
-                                unsigned int index) const
-  {
+  virtual common::event::Value observe(const typename Time::type & /* t */,
+                                unsigned int index) const {
     if (index >= var::VALUE and index <= var::VALUE + _internal_number) {
       return (double) (_output_values[index - var::VALUE]);
     } else {
-      return common::Value();
+      return common::event::Value();
     }
   }
 
-  unsigned int variable_number() const
-  { return _internal_number; }
+  unsigned int variable_number() const { return _internal_number; }
 
 private:
-  void assign_values(const std::vector<double> &values)
-  {
+  void assign_values(const std::vector<double> &values) {
     for (unsigned int index = 0; index < _internal_number; ++index) {
       _output_values[index] = values[index];
     }
   }
 
-  bool is_different_values(const std::vector<double> &values)
-  {
+  bool is_different_values(const std::vector<double> &values) {
     bool different = false;
     unsigned int index = 0;
 
@@ -242,18 +227,14 @@ private:
     return different;
   }
 
-  struct phase
-  {
-    enum values
-    {
+  struct phase {
+    enum values {
       INIT = 0, WAIT, RESPONSE
     };
   };
 
-  struct state
-  {
-    enum values
-    {
+  struct state {
+    enum values {
       PHASE = 0, INPUT_NUMBER, OUTPUT_VALUES, LAST_OUTPUTS
     };
   };
@@ -269,7 +250,6 @@ private:
   std::vector<double> _last_outputs;
 };
 
-}
 }
 
 #endif

+ 98 - 123
src/artis-star/kernel/qss/Quantifier.hpp

@@ -32,58 +32,50 @@
 
 #include <cmath>
 
-namespace artis {
-namespace qss {
+namespace artis::qss {
 
-struct QuantifierParameters
-{
+struct QuantifierParameters {
   bool allow_offsets;
   bool zero_init_offset;
   double quantum;
   unsigned int archive_length;
 };
 
-template<class Time>
+template<typename Time>
 class Quantifier
-    : public artis::pdevs::Dynamics<Time, Quantifier<Time>, QuantifierParameters>
-{
+  : public artis::pdevs::Dynamics<Time, Quantifier<Time>, QuantifierParameters> {
 public:
-  struct input
-  {
-    enum values
-    {
+  struct input {
+    enum values {
       IN, RESET
     };
   };
 
-  struct output
-  {
-    enum values
-    {
+  struct output {
+    enum values {
       OUT
     };
   };
 
   Quantifier(const std::string &name,
              const artis::pdevs::Context<Time, Quantifier<Time>, QuantifierParameters> &context)
-      :
-      artis::pdevs::Dynamics<Time, Quantifier<Time>, QuantifierParameters>(name, context)
-  {
+    :
+    artis::pdevs::Dynamics<Time, Quantifier<Time>, QuantifierParameters>(name, context) {
     DECLARE_STATES(int,
                    ((state::PHASE, &Quantifier<Time>::_phase),
-                       (state::ADAPTIVE_STATE, &Quantifier<Time>::_adaptive_state)));
+                     (state::ADAPTIVE_STATE, &Quantifier<Time>::_adaptive_state)));
     DECLARE_STATES(unsigned int,
                    ((state::STEP_NUMBER, &Quantifier<Time>::_step_number)));
     DECLARE_STATES(double,
                    ((state::OFFSET, &Quantifier<Time>::_offset),
-                       (state::UP_THRESHOLD, &Quantifier<Time>::_up_threshold),
-                       (state::DOWN_THRESHOLD, &Quantifier<Time>::_down_threshold)));
+                     (state::UP_THRESHOLD, &Quantifier<Time>::_up_threshold),
+                     (state::DOWN_THRESHOLD, &Quantifier<Time>::_down_threshold)));
 
-    this->input_ports({{input::IN, "in"},
+    this->input_ports({{input::IN,    "in"},
                        {input::RESET, "reset"}});
     this->output_port({output::OUT, "out"});
-    this->observables({{var::UP, "up"},
-                       {var::DOWN, "down"},
+    this->observables({{var::UP,    "up"},
+                       {var::DOWN,  "down"},
                        {var::VALUE, "value"}});
 
     _adaptive = context.parameters().allow_offsets;
@@ -98,33 +90,32 @@ public:
     assert(_past_length > 2);
   }
 
-  virtual ~Quantifier()
-  {}
+  virtual ~Quantifier() {}
 
   virtual void dconf(const typename Time::type &t, const typename Time::type &e,
-                     const common::Bag<Time> &bag)
-  {
+                     const common::event::Bag<Time> &bag) {
     dint(t);
     dext(t, e, bag);
   }
 
-  virtual void dint(const typename Time::type & /* t */)
-  {
+  virtual void dint(const typename Time::type & /* t */) {
     switch (_phase) {
-    case phase::INIT:break;
-    case phase::IDLE:break;
-    case phase::RESPONSE:_phase = phase::IDLE;
-      break;
+      case phase::INIT:
+        break;
+      case phase::IDLE:
+        break;
+      case phase::RESPONSE:
+        _phase = phase::IDLE;
+        break;
     }
   }
 
   virtual void dext(const typename Time::type &t, const typename Time::type &e,
-                    const common::Bag<Time> &bag)
-  {
+                    const common::event::Bag<Time> &bag) {
     bool reset = false;
 
     std::for_each(bag.begin(), bag.end(),
-                  [this, t, e, &reset](const common::ExternalEvent<Time> &event) {
+                  [this, t, e, &reset](const common::event::ExternalEvent<Time> &event) {
                     if (event.on_port(input::IN)) {
                       IntegratorData data;
                       double shifting_factor;
@@ -147,36 +138,38 @@ public:
                             _step_number--;
                           }
                           switch (_adaptive_state) {
-                          case adaptive_state::IMPOSSIBLE:update_thresholds();
-                            break;
-                          case adaptive_state::POSSIBLE:
-                            if (value >= _up_threshold) {
-                              store_change(_step_size, t);
-                            } else {
-                              store_change(-_step_size, t);
-                            }
-                            shifting_factor = shift_quanta();
-
-                            assert(shifting_factor >= 0
-                                       and shifting_factor <= 1);
-
-                            if (shifting_factor != 0 and shifting_factor != 1) {
+                            case adaptive_state::IMPOSSIBLE:
+                              update_thresholds();
+                              break;
+                            case adaptive_state::POSSIBLE:
                               if (value >= _up_threshold) {
-                                update_thresholds(shifting_factor,
-                                                  direction::DIRECTION_DOWN);
+                                store_change(_step_size, t);
+                              } else {
+                                store_change(-_step_size, t);
+                              }
+                              shifting_factor = shift_quanta();
+
+                              assert(shifting_factor >= 0
+                                     and shifting_factor <= 1);
+
+                              if (shifting_factor != 0 and shifting_factor != 1) {
+                                if (value >= _up_threshold) {
+                                  update_thresholds(shifting_factor,
+                                                    direction::DIRECTION_DOWN);
+                                } else {
+                                  update_thresholds(shifting_factor,
+                                                    direction::DIRECTION_UP);
+                                }
+                                _adaptive_state = adaptive_state::DONE;
                               } else {
-                                update_thresholds(shifting_factor,
-                                                  direction::DIRECTION_UP);
+                                update_thresholds();
                               }
-                              _adaptive_state = adaptive_state::DONE;
-                            } else {
+                              break;
+                            case adaptive_state::DONE:
+                              init_step_number_and_offset(value);
+                              _adaptive_state = adaptive_state::POSSIBLE;
                               update_thresholds();
-                            }
-                            break;
-                          case adaptive_state::DONE:init_step_number_and_offset(value);
-                            _adaptive_state = adaptive_state::POSSIBLE;
-                            update_thresholds();
-                            break;
+                              break;
                           }
                         }
                       }
@@ -193,45 +186,46 @@ public:
     }
   }
 
-  virtual void start(const typename Time::type & /* time */)
-  {
+  virtual void start(const typename Time::type & /* time */) {
     _offset = 0;
     _phase = phase::INIT;
   }
 
-  virtual typename Time::type ta(const typename Time::type & /* time */)
-  {
+  virtual typename Time::type ta(const typename Time::type & /* time */) {
     switch (_phase) {
-    case phase::INIT:
-    case phase::IDLE:return Time::infinity;
-    case phase::RESPONSE:return 0.0;
+      case phase::INIT:
+      case phase::IDLE:
+        return Time::infinity;
+      case phase::RESPONSE:
+        return 0.0;
     }
     return Time::infinity;
   }
 
-  virtual common::Bag<Time> lambda(const typename Time::type & /* time */) const
-  {
-    common::Bag<Time> msgs;
+  virtual common::event::Bag<Time> lambda(const typename Time::type & /* time */) const {
+    common::event::Bag<Time> msgs;
     const QuantifierData data = {_up_threshold, _down_threshold};
 
-    msgs.push_back(common::ExternalEvent<Time>(output::OUT, data));
+    msgs.push_back(common::event::ExternalEvent<Time>(output::OUT, data));
     return msgs;
   }
 
-  virtual common::Value observe(const typename Time::type & /* t */,
-                                unsigned int index) const
-  {
+  virtual common::event::Value observe(const typename Time::type & /* t */,
+                                unsigned int index) const {
     switch (index) {
-    case var::UP:return (double) _up_threshold;
-    case var::DOWN:return (double) _down_threshold;
-    case var::VALUE:return (double) (_up_threshold - _down_threshold);
-    default:return common::Value();
+      case var::UP:
+        return (double) _up_threshold;
+      case var::DOWN:
+        return (double) _down_threshold;
+      case var::VALUE:
+        return (double) (_up_threshold - _down_threshold);
+      default:
+        return common::event::Value();
     }
   }
 
 private:
-  void init_step_number_and_offset(double value)
-  {
+  void init_step_number_and_offset(double value) {
     _step_number = static_cast<long int>(std::floor(value / _step_size));
     if (_zero_init_offset) {
       _offset = 0;
@@ -240,8 +234,7 @@ private:
     }
   }
 
-  bool monotonous(unsigned int range)
-  {
+  bool monotonous(unsigned int range) {
     if ((range + 1) > _archive.size()) {
       return false;
     }
@@ -253,8 +246,7 @@ private:
     return true;
   }
 
-  bool oscillating(unsigned int range)
-  {
+  bool oscillating(unsigned int range) {
     if ((range + 1) > _archive.size()) {
       return false;
     }
@@ -266,8 +258,7 @@ private:
     return true;
   }
 
-  double shift_quanta()
-  {
+  double shift_quanta() {
     double factor = 0;
 
     if (oscillating(_past_length - 1) and
@@ -282,11 +273,11 @@ private:
         if (0 != (_archive[i + 2].date - _archive[i].date)) {
           if ((_archive.back().value * _archive[i + 1].value) > 0) {
             local_estim =
-                1 - (_archive[i + 1].date - _archive[i].date) /
-                    (_archive[i + 2].date - _archive[i].date);
+              1 - (_archive[i + 1].date - _archive[i].date) /
+                  (_archive[i + 2].date - _archive[i].date);
           } else {
             local_estim = (_archive[i + 1].date - _archive[i].date) /
-                (_archive[i + 2].date - _archive[i].date);
+                          (_archive[i + 2].date - _archive[i].date);
           }
           acc += local_estim;
           cnt++;
@@ -299,8 +290,7 @@ private:
     return factor;
   }
 
-  void store_change(double val, const typename Time::type &time)
-  {
+  void store_change(double val, const typename Time::type &time) {
     record_t record;
 
     record.date = time;
@@ -311,32 +301,27 @@ private:
     }
   }
 
-  void update_thresholds()
-  {
+  void update_thresholds() {
     auto step_number = static_cast<double>(_step_number);
 
     _up_threshold = _offset + _step_size * (step_number + 1);
     _down_threshold = _offset + _step_size * (step_number - 1);
   }
 
-  void update_thresholds(double factor)
-  {
+  void update_thresholds(double factor) {
     auto step_number = static_cast<double>(_step_number);
 
     _up_threshold = _offset + _step_size * (step_number + (1 - factor));
     _down_threshold = _offset + _step_size * (step_number - (1 - factor));
   }
 
-  struct direction
-  {
-    enum values
-    {
+  struct direction {
+    enum values {
       DIRECTION_UP, DIRECTION_DOWN
     };
   };
 
-  void update_thresholds(double factor, const typename direction::values &d)
-  {
+  void update_thresholds(double factor, const typename direction::values &d) {
     auto step_number = static_cast<double>(_step_number);
 
     if (d == direction::DIRECTION_UP) {
@@ -348,40 +333,31 @@ private:
     }
   }
 
-  struct state
-  {
-    enum values
-    {
+  struct state {
+    enum values {
       PHASE, ADAPTIVE_STATE, STEP_NUMBER, OFFSET, UP_THRESHOLD, DOWN_THRESHOLD
     };
   };
 
-  struct var
-  {
-    enum values
-    {
+  struct var {
+    enum values {
       UP, DOWN, VALUE
     };
   };
 
-  struct phase
-  {
-    enum values
-    {
+  struct phase {
+    enum values {
       INIT, IDLE, RESPONSE
     };
   };
 
-  struct adaptive_state
-  {
-    enum values
-    {
+  struct adaptive_state {
+    enum values {
       IMPOSSIBLE, POSSIBLE, DONE
     };
   };
 
-  struct record_t
-  {
+  struct record_t {
     double value;
     typename Time::type date;
   };
@@ -405,7 +381,6 @@ private:
   std::deque<record_t> _archive;
 };
 
-}
 }
 
 #endif

+ 1 - 2
src/artis-star/kernel/sss/CMakeLists.txt

@@ -6,7 +6,6 @@ INCLUDE_DIRECTORIES(
 LINK_DIRECTORIES(
         ${Boost_LIBRARY_DIRS})
 
-SET(SSS_HPP Coordinator.hpp Dynamics.hpp GraphManager.hpp Model.hpp
-        Simulator.hpp)
+SET(SSS_HPP Context.hpp Coordinator.hpp Dynamics.hpp GraphManager.hpp Model.hpp Simulator.hpp)
 
 INSTALL(FILES ${SSS_HPP} DESTINATION ${ARTIS_INCLUDE_DIRS}/kernel/sss)

+ 59 - 0
src/artis-star/kernel/sss/Context.hpp

@@ -0,0 +1,59 @@
+/**
+ * @file kernel/sss/Context.hpp
+ * @author The ARTIS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * ARTIS - the multimodeling and simulation environment
+ * This file is a part of the ARTIS environment
+ *
+ * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SSS_CONTEXT
+#define SSS_CONTEXT
+
+#include <artis-star/common/Parameters.hpp>
+
+namespace artis::sss {
+
+template<typename Time, typename Dynamics, typename Parameters>
+class Simulator;
+
+template<typename Time, typename Dynamics, typename Parameters = common::NoParameters>
+class Context {
+  typedef sss::Simulator<Time, Dynamics, Parameters> Simulator;
+
+public:
+  Context(const Parameters &parameters, Simulator *simulator)
+    :
+    _parameters(parameters), _simulator(simulator) {}
+
+  virtual ~Context() {}
+
+  const Parameters &parameters() const { return _parameters; }
+
+  Simulator *simulator() const { return _simulator; }
+
+private:
+  const Parameters &_parameters;
+  Simulator *_simulator;
+};
+
+} // namespace artis sss
+
+#endif

+ 35 - 53
src/artis-star/kernel/sss/Coordinator.hpp

@@ -35,28 +35,24 @@
 
 #include <cassert>
 
-namespace artis {
-namespace sss {
+namespace artis::sss {
 
-template<class Time>
-class Parameters
-{
+template<typename Time>
+class Parameters {
 public:
   Parameters(typename Time::type time_step)
-      : _time_step(time_step)
-  {}
+    : _time_step(time_step) {}
 
   typename Time::type _time_step;
 };
 
-template<class Time, class Policy, class GraphManager,
-    class Parameters = Parameters<Time>,
-    class GraphParameters = common::NoParameters>
+template<typename Time, typename Policy, class GraphManager,
+  class Parameters = Parameters<Time>,
+  class GraphParameters = common::NoParameters>
 class Coordinator : public common::Coordinator<Time>,
-                    public sss::Model<Time>
-{
+                    public sss::Model<Time> {
   typedef Coordinator<Time, Policy, GraphManager,
-                      Parameters, GraphParameters> type;
+    Parameters, GraphParameters> type;
 
 public:
   typedef Parameters parameters_type;
@@ -65,62 +61,52 @@ public:
   Coordinator(const std::string &name,
               const Parameters &parameters,
               const GraphParameters &graph_parameters)
-      :
-      common::Model<Time>(name),
-      common::Coordinator<Time>(name),
-      sss::Model<Time>(name),
-      _graph_manager(this, graph_parameters),
-      _time_step(parameters._time_step)
-  {}
+    :
+    common::Model<Time>(name),
+    common::Coordinator<Time>(name),
+    sss::Model<Time>(name),
+    _graph_manager(this, graph_parameters),
+    _time_step(parameters._time_step) {}
 
-  virtual ~Coordinator()
-  {}
+  virtual ~Coordinator() {}
 
-  GraphManager &get_graph_manager()
-  { return _graph_manager; }
+  GraphManager &get_graph_manager() { return _graph_manager; }
 
-  const GraphManager &get_graph_manager() const
-  { return _graph_manager; }
+  const GraphManager &get_graph_manager() const { return _graph_manager; }
 
-  virtual bool is_atomic() const
-  { return common::Coordinator<Time>::is_atomic(); }
+  virtual bool is_atomic() const { return common::Coordinator<Time>::is_atomic(); }
 
-  virtual std::string to_string(int level) const
-  { return common::Coordinator<Time>::to_string(level); }
+  virtual std::string to_string(int level) const { return common::Coordinator<Time>::to_string(level); }
 
-  typename Time::type start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
     assert(_graph_manager.children().size() > 0);
 
     type::_tl = t;
     type::_tn = t;
-    for (auto &child : _graph_manager.children()) {
+    for (auto &child: _graph_manager.children()) {
       child->start(t);
     }
     return type::_tn;
   }
 
-  typename Time::type dispatch_events(const common::Bag<Time> &bag,
-                                      const typename Time::type &t)
-  {
+  typename Time::type dispatch_events(const common::event::Bag <Time> &bag,
+                                      const typename Time::type &t) {
     _graph_manager.dispatch_events(bag, t);
     return type::_tn;
   }
 
-  void observation(std::ostream &file) const
-  {
-    for (auto &child : _graph_manager.children()) {
+  void observation(std::ostream &file) const {
+    for (auto &child: _graph_manager.children()) {
       child->observation(file);
     }
   }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
     if (t == type::_tn) {
-      for (auto &model : _graph_manager.children()) {
+      for (auto &model: _graph_manager.children()) {
         model->update_buffer(t);
       }
-      for (auto &model : _graph_manager.children()) {
+      for (auto &model: _graph_manager.children()) {
         if (not model->is_send() && model->is_marked()) {
           model->output(t);
           model->send();
@@ -130,8 +116,7 @@ public:
   }
 
   void post_event(const typename Time::type &t,
-                  const common::ExternalEvent<Time> &event)
-  {
+                  const common::event::ExternalEvent <Time> &event) {
     if (t == type::_tn) {
       _graph_manager.post_event(t, event);
     } else {
@@ -139,15 +124,14 @@ public:
     }
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
     if (t == type::_tn) {
       bool end = true;
 
-      for (auto &event : _policy.bag()) {
+      for (auto &event: _policy.bag()) {
         post_event(t, event);
       }
-      for (auto &model : _graph_manager.children()) {
+      for (auto &model: _graph_manager.children()) {
         if (not model->is_marked()) {
           if (model->all_ports_are_assigned()) {
             model->transition(t);
@@ -168,7 +152,7 @@ public:
       }
 
       if (end) {
-        for (auto &model : _graph_manager.children()) {
+        for (auto &model: _graph_manager.children()) {
           model->unmark();
           model->unsend();
         }
@@ -180,8 +164,7 @@ public:
     return type::_tn;
   }
 
-  virtual void update_buffer(typename Time::type /* time */)
-  {}
+  virtual void update_buffer(typename Time::type /* time */) {}
 
 private:
   GraphManager _graph_manager;
@@ -189,7 +172,6 @@ private:
   Policy _policy;
 };
 
-}
 } // namespace artis sss
 
 #endif

+ 26 - 40
src/artis-star/kernel/sss/Dynamics.hpp

@@ -27,67 +27,53 @@
 #ifndef SSS_DYNAMICS
 #define SSS_DYNAMICS
 
-#include <artis-star/common/Bag.hpp>
-#include <artis-star/common/ExternalEvent.hpp>
-#include <artis-star/common/Parameters.hpp>
-#include <artis-star/common/States.hpp>
-
-namespace artis {
-namespace sss {
-
-template<class Time,
-    class Parameters = common::NoParameters>
-class Dynamics : public common::States<Time, Dyn>
-{
+#include <artis-star/kernel/sss/Context.hpp>
+#include <artis-star/kernel/sss/Simulator.hpp>
+#include "artis-star/common/state/States.hpp"
+
+namespace artis::sss {
+
+template<typename Time, typename Dyn, typename Parameters = common::NoParameters>
+class Dynamics : public common::state::States<Time, Dyn> {
+  typedef sss::Simulator<Time, Dyn, Parameters> Simulator;
+
 public:
-  Dynamics(const std::string &name, const Parameters & /* parameters */)
-      :
-      _name(name)
-  {}
+  Dynamics(const std::string &name, const Context<Time, Dyn, Parameters> &context)
+    :
+    _name(name), _simulator(context.simulator()) {}
 
-  virtual ~Dynamics()
-  {}
+  virtual ~Dynamics() = default;
 
-  virtual void transition(const common::Bag<Time> & /* x */,
-                          typename Time::type /* t */)
-  {}
+  virtual void transition(const common::event::Bag<Time> & /* x */,
+                          typename Time::type /* t */) {}
 
-  virtual typename Time::type
-  start(typename Time::type/* time */)
-  { return Time::infinity; }
+  virtual typename Time::type start(typename Time::type/* time */) { return Time::infinity; }
 
-  common::Bag<Time> lambda(
-      typename Time::type /* time */) const
-  { return common::Bag<Time>(); }
+  common::event::Bag<Time> lambda(typename Time::type /* time */) const { return common::event::Bag<Time>(); }
 
-  virtual void observation(std::ostream & /* file */) const
-  {}
+  virtual void observation(std::ostream & /* file */) const {}
 
-  const std::string &get_name() const
-  { return _name; }
+  const std::string &get_name() const { return _name; }
 
-  void restore(const common::context::State<Time> &state)
-  {
-    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+  void restore(const common::context::State<Time> &state) {
+    common::state::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
     _simulator->set_tn(state.last_time());
     _simulator->set_tl(state.next_time());
   }
 
-  void save(common::context::State<Time> &state) const
-  {
-    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+  void save(common::context::State<Time> &state) const {
+    common::state::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
     state.last_time(_simulator->get_tn());
     state.next_time(_simulator->get_tl());
   }
 
-  virtual void update_buffer(typename Time::type /* time */)
-  {}
+  virtual void update_buffer(typename Time::type /* time */) {}
 
 private:
   std::string _name;
+  Simulator *_simulator;
 };
 
-}
 } // namespace artis sss
 
 #endif

+ 35 - 46
src/artis-star/kernel/sss/GraphManager.hpp

@@ -34,88 +34,78 @@
 
 #include <artis-star/kernel/sss/Model.hpp>
 
-namespace artis {
-namespace sss {
+namespace artis::sss {
 
-template<class Time,
-    class GraphParameters = common::NoParameters>
-class GraphManager : public common::GraphManager<Time>
-{
+template<typename Time, typename GraphParameters = common::NoParameters>
+class GraphManager : public common::GraphManager<Time> {
 public:
   GraphManager(common::Coordinator<Time> *coordinator,
                const GraphParameters & /* parameters */)
-      :
-      common::GraphManager<Time>(coordinator)
-  {}
+    :
+    common::GraphManager<Time>(coordinator) {}
 
-  virtual ~GraphManager()
-  {}
+  virtual ~GraphManager() {}
 
   void add_link(common::Model<Time> *src_model,
                 const std::string &src_port_name,
                 common::Model<Time> *dst_model,
-                const std::string &dst_port_name)
-  {
-    assert((src_model != _coordinator and
-        dst_model != _coordinator and
-        src_model->exist_out_port(src_port_name) and
-        dst_model->exist_in_port(dst_port_name)) or
-        (src_model == _coordinator and
-            dst_model != _coordinator and
+                const std::string &dst_port_name) {
+    assert((src_model != common::GraphManager<Time>::_coordinator and
+            dst_model != common::GraphManager<Time>::_coordinator and
+            src_model->exist_out_port(src_port_name) and
+            dst_model->exist_in_port(dst_port_name)) or
+           (src_model == common::GraphManager<Time>::_coordinator and
+            dst_model != common::GraphManager<Time>::_coordinator and
             src_model->exist_in_port(src_port_name) and
             dst_model->exist_in_port(dst_port_name)) or
-        (src_model != _coordinator and
-            dst_model == _coordinator and
+           (src_model != common::GraphManager<Time>::_coordinator and
+            dst_model == common::GraphManager<Time>::_coordinator and
             src_model->exist_out_port(src_port_name) and
             dst_model->exist_out_port(dst_port_name)));
 
     _link_list.add(src_model, src_port_name, dst_model, dst_port_name);
   }
 
-  void dispatch_events(common::Bag<Time> bag,
-                       typename Time::type t)
-  {
-    for (auto &ymsg : bag) {
+  void dispatch_events(common::event::Bag<Time> bag,
+                       typename Time::type t) {
+    for (auto &ymsg: bag) {
       typename common::Links<Time>::Result result_model =
-          _link_list.find(ymsg.get_model(),
-                          ymsg.get_port_name());
+        _link_list.find(ymsg.get_model(),
+                        ymsg.get_port_name());
 
       for (typename common::Links<Time>::const_iterator it =
-          result_model.first; it != result_model.second; ++it) {
+        result_model.first; it != result_model.second; ++it) {
         // event on output port of coupled model
-        if (it->second.get_model() == _coordinator) {
-          common::Bag<Time> ymessages;
+        if (it->second.get_model() == common::GraphManager<Time>::_coordinator) {
+          common::event::Bag<Time> ymessages;
 
           ymessages.push_back(
-              common::ExternalEvent<Time>(
-                  it->second,
-                  ymsg.data()));
-          if (_coordinator->get_parent()) {
+            common::event::ExternalEvent<Time>(it->second, ymsg.data()));
+          if (common::GraphManager<Time>::_coordinator->get_parent()) {
             dynamic_cast < common::Coordinator<
-                Time> * >(_coordinator->get_parent())
-                ->dispatch_events(ymessages, t);
+              Time> * >(common::GraphManager<Time>::_coordinator->get_parent())
+              ->dispatch_events(ymessages, t);
           }
         } else { // event on input port of internal model
           it->second.get_model()->post_event(
-              t, common::ExternalEvent<Time>(
-                  it->second,
-                  ymsg.data()));
+            t, common::event::ExternalEvent<Time>(
+              it->second,
+              ymsg.data()));
         }
       }
     }
   }
 
   void post_event(typename Time::type t,
-                  const common::ExternalEvent<Time> &event)
-  {
+                  const common::event::ExternalEvent<Time> &event) {
     typename common::Links<Time>::Result result =
-        _link_list.find(_coordinator, event.get_port_name());
+      _link_list.find(common::GraphManager<Time>::_coordinator, event.get_port_name());
 
     for (typename common::Links<Time>::const_iterator it_r =
-        result.first; it_r != result.second; ++it_r) {
+      result.first; it_r != result.second; ++it_r) {
       it_r->second.get_model()->post_event(
-          t, common::ExternalEvent<Time>(it_r->second,
-                                         event.data()));
+        t, common::event::ExternalEvent<Time>(it_r->second,
+                                              event.data()));
     }
   }
 
@@ -123,7 +113,6 @@ private:
   common::Links<Time> _link_list;
 };
 
-}
 } // namespace artis sss
 
 #endif

+ 23 - 42
src/artis-star/kernel/sss/Model.hpp

@@ -29,32 +29,27 @@
 
 #include <artis-star/common/Model.hpp>
 
-namespace artis {
-namespace sss {
+namespace artis::sss {
 
-template<class Time>
-class Model : public virtual common::Model<Time>
-{
+template<typename Time>
+class Model : public virtual common::Model<Time> {
 public:
   Model(const std::string &name)
-      :
-      common::Model<Time>(name)
-  {
+    :
+    common::Model<Time>(name) {
     assigned = 0;
     _mark = false;
     _send = false;
   }
 
-  virtual ~Model()
-  {}
+  virtual ~Model() {}
 
   virtual void update_buffer(typename Time::type /* time */) = 0;
 
-  void add_event(const common::ExternalEvent<Time> &message)
-  {
+  void add_event(const common::event::ExternalEvent <Time> &message) {
     common::Model<Time>::add_event(message);
     std::map<std::string, bool>::iterator it =
-        port_assigned.find(message.get_port_name());
+      port_assigned.find(message.get_port_name());
 
     if (it != port_assigned.end() and not it->second) {
       port_assigned[message.get_port_name()] = true;
@@ -62,19 +57,16 @@ public:
     }
   }
 
-  void add_in_port(const std::string &port_name, bool sync)
-  {
+  void add_in_port(const std::string &port_name, bool sync) {
     common::Model<Time>::add_in_port(port_name);
     if (sync) {
       port_assigned[port_name] = false;
     }
   }
 
-  bool all_ports_are_assigned() const
-  { return assigned == port_assigned.size(); }
+  bool all_ports_are_assigned() const { return assigned == port_assigned.size(); }
 
-  void clear_bag()
-  {
+  void clear_bag() {
     common::Model<Time>::clear_bag();
 
     for (auto &p: port_assigned) {
@@ -83,23 +75,17 @@ public:
     assigned = 0;
   }
 
-  bool is_marked() const
-  { return _mark; }
+  bool is_marked() const { return _mark; }
 
-  bool is_send() const
-  { return _send; }
+  bool is_send() const { return _send; }
 
-  void mark()
-  { _mark = true; }
+  void mark() { _mark = true; }
 
-  void send()
-  { _send = true; }
+  void send() { _send = true; }
 
-  void unmark()
-  { _mark = false; }
+  void unmark() { _mark = false; }
 
-  void unsend()
-  { _send = false; }
+  void unsend() { _send = false; }
 
 private:
   std::map<std::string, bool> port_assigned;
@@ -108,23 +94,19 @@ private:
   bool _send;
 };
 
-template<class Time>
-class Models : public std::vector<sss::Model<Time> *>
-{
+template<typename Time>
+class Models : public std::vector<sss::Model<Time> *> {
 public:
-  Models()
-  {}
+  Models() {}
 
-  virtual ~Models()
-  {}
+  virtual ~Models() {}
 
-  std::string to_string() const
-  {
+  std::string to_string() const {
     std::ostringstream ss;
 
     ss << "{ ";
     for (typename Models<Time>::const_iterator it =
-        Models<Time>::begin();
+      Models<Time>::begin();
          it != Models<Time>::end(); ++it) {
       ss << (*it)->get_name() << " ";
     }
@@ -133,7 +115,6 @@ public:
   }
 };
 
-}
 } // namespace artis sss
 
 #endif

+ 28 - 45
src/artis-star/kernel/sss/Simulator.hpp

@@ -36,50 +36,40 @@
 
 #include <cassert>
 
-namespace artis {
-namespace sss {
+namespace artis::sss {
 
-template<class Time, class Dynamics,
-    class Parameters = common::NoParameters>
+template<typename Time, typename Dynamics, typename Parameters = common::NoParameters>
 class Simulator : public common::Simulator<Time>,
-                  public sss::Model<Time>
-{
+                  public sss::Model<Time> {
   typedef Simulator<Time, Dynamics, Parameters> type;
 
 public:
   Simulator(const std::string &name, const typename Time::type &time_step,
             const Parameters &parameters)
-      :
-      common::Model<Time>(name),
-      common::Simulator<Time>(name),
-      sss::Model<Time>(name),
-      _dynamics(name, parameters),
-      _time_step(time_step)
-  {}
-
-  ~Simulator()
-  {}
-
-  virtual bool is_atomic() const
-  { return common::Simulator<Time>::is_atomic(); }
-
-  virtual void restore(const common::context::State<Time> &state)
-  {
+    :
+    common::Model<Time>(name),
+    common::Simulator<Time>(name),
+    sss::Model<Time>(name),
+    _dynamics(name, parameters),
+    _time_step(time_step) {}
+
+  ~Simulator() {}
+
+  virtual bool is_atomic() const { return common::Simulator<Time>::is_atomic(); }
+
+  virtual void restore(const common::context::State <Time> &state) {
     common::Simulator<Time>::restore(state);
     _dynamics.restore(state);
   }
 
-  virtual void save(context::State <Time> &state) const
-  {
+  virtual void save(common::context::State <Time> &state) const {
     common::Simulator<Time>::save(state);
     _dynamics.save(state);
   }
 
-  virtual std::string to_string(int level) const
-  { return common::Simulator<Time>::to_string(level); }
+  virtual std::string to_string(int level) const { return common::Simulator<Time>::to_string(level); }
 
-  virtual void finish(const typename Time::type &t)
-  {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
     (void) t;
 #endif
@@ -94,8 +84,7 @@ public:
 #endif
   }
 
-  typename Time::type start(const typename Time::type &t)
-  {
+  typename Time::type start(const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -122,13 +111,11 @@ public:
     return type::_tn;
   }
 
-  void observation(std::ostream &file) const
-  {
+  void observation(std::ostream &file) const {
     _dynamics.observation(file);
   }
 
-  void output(const typename Time::type &t)
-  {
+  void output(const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -138,14 +125,14 @@ public:
 #endif
 
     if (t == type::_tn) {
-      common::Bag<Time> bag = _dynamics.lambda(t);
+      common::event::Bag <Time> bag = _dynamics.lambda(t);
 
       if (not bag.empty()) {
-        for (auto &event : bag) {
+        for (auto &event: bag) {
           event.set_model(this);
         }
-        dynamic_cast < common::Coordinator<Time> * >(
-            type::get_parent())->dispatch_events(bag, t);
+        dynamic_cast < common::Coordinator <Time> * >(
+          type::get_parent())->dispatch_events(bag, t);
       }
     }
 
@@ -159,8 +146,7 @@ public:
   }
 
   void post_event(const typename Time::type &t,
-                  const common::ExternalEvent<Time> &event)
-  {
+                  const common::event::ExternalEvent <Time> &event) {
 
 #ifndef WITH_TRACE
     (void) t;
@@ -186,8 +172,7 @@ public:
 
   }
 
-  typename Time::type transition(const typename Time::type &t)
-  {
+  typename Time::type transition(const typename Time::type &t) {
 
 #ifdef WITH_TRACE
     common::Trace<Time>::trace()
@@ -222,15 +207,13 @@ public:
     return type::_tn;
   }
 
-  virtual void update_buffer(typename Time::type time)
-  { _dynamics.update_buffer(time); }
+  virtual void update_buffer(typename Time::type time) { _dynamics.update_buffer(time); }
 
 private :
   Dynamics _dynamics;
   typename Time::type _time_step;
 };
 
-}
 } // namespace artis sss
 
 #endif

+ 20 - 0
tests/CMakeLists.txt

@@ -0,0 +1,20 @@
+INCLUDE_DIRECTORIES(
+        ${CMAKE_SOURCE_DIR}/src
+        ${ARTIS_INCLUDE_DIRS}
+        ${Boost_INCLUDE_DIRS})
+
+LINK_DIRECTORIES()
+
+ADD_EXECUTABLE(common_bag_tests common_bag.cpp)
+ADD_EXECUTABLE(common_context_tests common_context.cpp)
+ADD_EXECUTABLE(common_observe_tests common_observe.cpp)
+ADD_EXECUTABLE(common_state_tests common_state.cpp)
+ADD_EXECUTABLE(common_value_tests common_value.cpp)
+ADD_EXECUTABLE(kernel_pdevs_simulator_tests kernel_pdevs_simulator.cpp)
+
+TARGET_LINK_LIBRARIES(common_bag_tests ${Boost_LIBRARIES})
+TARGET_LINK_LIBRARIES(common_context_tests ${Boost_LIBRARIES})
+TARGET_LINK_LIBRARIES(common_observe_tests ${Boost_LIBRARIES})
+TARGET_LINK_LIBRARIES(common_state_tests ${Boost_LIBRARIES})
+TARGET_LINK_LIBRARIES(common_value_tests ${Boost_LIBRARIES})
+TARGET_LINK_LIBRARIES(kernel_pdevs_simulator_tests ${Boost_LIBRARIES})

+ 57 - 0
tests/common_bag.cpp

@@ -0,0 +1,57 @@
+/**
+ * @file tests/common_bag.cpp
+ * @author The ARTIS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * ARTIS - the multimodeling and simulation environment
+ * This file is a part of the ARTIS environment
+ *
+ * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <artis-star/common/event/Bag.hpp>
+#include <artis-star/common/time/DoubleTime.hpp>
+
+#define BOOST_TEST_MODULE Common_Bag_Tests
+
+#include <boost/test/unit_test.hpp>
+
+/*************************************************
+ * Tests
+ *************************************************/
+
+BOOST_AUTO_TEST_CASE(Common_Bag_TestCase_1)
+{
+  artis::common::event::Bag<artis::common::DoubleTime> bag;
+
+  BOOST_REQUIRE_EQUAL(bag.size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(Common_Bag_TestCase_2)
+{
+  artis::common::event::Bag<artis::common::DoubleTime> bag;
+  artis::common::event::ExternalEvent<artis::common::DoubleTime> event(0);
+  int data{};
+
+  event.data((int)1);
+  bag.push_back(event);
+  bag.back().data()(data);
+
+  BOOST_REQUIRE_EQUAL(bag.size(), 1);
+  BOOST_REQUIRE_EQUAL(data, 1);
+}

+ 63 - 0
tests/common_context.cpp

@@ -0,0 +1,63 @@
+/**
+ * @file tests/common_context.cpp
+ * @author The ARTIS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * ARTIS - the multimodeling and simulation environment
+ * This file is a part of the ARTIS environment
+ *
+ * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <artis-star/common/context/Context.hpp>
+#include <artis-star/common/time/DoubleTime.hpp>
+
+#define BOOST_TEST_MODULE Common_Context_Tests
+
+#include <boost/test/unit_test.hpp>
+
+/*************************************************
+ * Tests
+ *************************************************/
+
+BOOST_AUTO_TEST_CASE(Common_Context_TestCase_1)
+{
+  artis::common::context::Context<artis::common::DoubleTime> context;
+
+  BOOST_REQUIRE_EQUAL(context.begin(), -1);
+  BOOST_REQUIRE_EQUAL(context.end(), -1);
+  BOOST_REQUIRE_EQUAL(context.valid(), false);
+}
+
+BOOST_AUTO_TEST_CASE(Common_Context_TestCase_2)
+{
+  artis::common::context::Context<artis::common::DoubleTime> context(0, 500);
+
+  BOOST_REQUIRE_EQUAL(context.begin(), 0);
+  BOOST_REQUIRE_EQUAL(context.end(), 500);
+  BOOST_REQUIRE_EQUAL(context.valid(), false);
+}
+
+BOOST_AUTO_TEST_CASE(Common_Context_TestCase_3)
+{
+  artis::common::context::Context<artis::common::DoubleTime> context(0, 500);
+
+  BOOST_REQUIRE_EQUAL(context.to_string(), "begin: 0.000000; end: 500.000000; valid: false;"
+                                           " state: { last_time: -1.000000; next_time: -1.000000;"
+                                           " values: { states: [ ] } ; sub_states: [ ] }");
+}

+ 92 - 0
tests/common_observe.cpp

@@ -0,0 +1,92 @@
+/**
+ * @file tests/common_observe.cpp
+ * @author The ARTIS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * ARTIS - the multimodeling and simulation environment
+ * This file is a part of the ARTIS environment
+ *
+ * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "artis-star/common/context/Context.hpp"
+#include "artis-star/common/observer/Observer.hpp"
+#include "artis-star/common/observer/View.hpp"
+#include "artis-star/kernel/pdevs/Dynamics.hpp"
+#include "artis-star/kernel/pdevs/Simulator.hpp"
+#include <artis-star/common/time/DoubleTime.hpp>
+
+#define BOOST_TEST_MODULE Common_Observe_Tests
+
+#include <boost/test/unit_test.hpp>
+
+/*************************************************
+ * Tests
+ *************************************************/
+
+class MyDynamics : public artis::pdevs::Dynamics<artis::common::DoubleTime, MyDynamics> {
+public:
+  struct vars {
+    enum values {
+      VALUE = 0
+    };
+  };
+
+  MyDynamics(const std::string &name,
+             const artis::pdevs::Context<artis::common::DoubleTime, MyDynamics, artis::common::NoParameters> &context)
+    : artis::pdevs::Dynamics<artis::common::DoubleTime, MyDynamics, artis::common::NoParameters>(name, context) {
+    observables({{vars::VALUE, "value"}});
+  }
+
+  artis::common::event::Value observe(const artis::common::DoubleTime::type & /* t */,
+                                      unsigned int index) const override {
+    if (index == vars::VALUE) {
+      return (int) 1;
+    }
+    return {};
+  }
+};
+
+BOOST_AUTO_TEST_CASE(Common_Observe_TestCase_1)
+{
+  artis::pdevs::Simulator<artis::common::DoubleTime, MyDynamics> model("A", {});
+  artis::common::observer::View<artis::common::DoubleTime> view;
+  artis::common::event::Value ref{1};
+
+  view.attachModel(&model);
+  view.selector("value", {MyDynamics::vars::VALUE});
+  view.observe(0, true);
+
+  BOOST_REQUIRE_EQUAL(view.get("value").back().second, ref);
+}
+
+BOOST_AUTO_TEST_CASE(Common_Observe_TestCase_2)
+{
+  artis::pdevs::Simulator<artis::common::DoubleTime, MyDynamics> model("A", {});
+  auto view = new artis::common::observer::View<artis::common::DoubleTime>();
+  artis::common::observer::Observer<artis::common::DoubleTime> observer(&model);
+  artis::common::event::Value ref{1};
+
+  view->selector("value", {MyDynamics::vars::VALUE});
+  observer.attachView("global", view);
+  observer.init();
+  observer.observe(0, 1);
+
+  BOOST_REQUIRE_EQUAL(observer.views().at("global")->get("value").back().second, ref);
+  BOOST_REQUIRE_EQUAL(observer.view("global").get("value").back().second, ref);
+}

+ 60 - 0
tests/common_state.cpp

@@ -0,0 +1,60 @@
+/**
+ * @file tests/common_state.cpp
+ * @author The ARTIS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * ARTIS - the multimodeling and simulation environment
+ * This file is a part of the ARTIS environment
+ *
+ * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <artis-star/common/context/State.hpp>
+#include <artis-star/common/time/DoubleTime.hpp>
+
+#define BOOST_TEST_MODULE Common_State_Tests
+
+#include <boost/test/unit_test.hpp>
+
+/*************************************************
+ * Tests
+ *************************************************/
+
+BOOST_AUTO_TEST_CASE(Common_State_TestCase_1)
+{
+  artis::common::context::State<artis::common::DoubleTime> state;
+
+  BOOST_REQUIRE_EQUAL(state.last_time(), -1);
+  BOOST_REQUIRE_EQUAL(state.next_time(), -1);
+}
+
+BOOST_AUTO_TEST_CASE(Common_State_TestCase_2)
+{
+  artis::common::context::State<artis::common::DoubleTime> state;
+  artis::common::event::Value first_value{1};
+  artis::common::event::Value second_value{2};
+
+  state.add_state(0, first_value);
+  state.add_state(1, second_value);
+
+  BOOST_CHECK(state.get_state(0) == first_value);
+  BOOST_CHECK(state.get_state(1) == second_value);
+
+  BOOST_CHECK(state.get_state(0) == artis::common::event::Value{1});
+  BOOST_CHECK(state.get_state(1) == artis::common::event::Value{2});
+}

+ 87 - 0
tests/common_value.cpp

@@ -0,0 +1,87 @@
+/**
+ * @file tests/common_value.cpp
+ * @author The ARTIS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * ARTIS - the multimodeling and simulation environment
+ * This file is a part of the ARTIS environment
+ *
+ * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "artis-star/common/event/Value.hpp"
+
+#define BOOST_TEST_MODULE Common_Value_Tests
+
+#include <boost/test/unit_test.hpp>
+
+/*************************************************
+ * Tests
+ *************************************************/
+
+BOOST_AUTO_TEST_CASE(Common_Value_TestCase_1)
+{
+  artis::common::event::Value first_value{1};
+  artis::common::event::Value second_value{1};
+
+  BOOST_CHECK(first_value == second_value);
+}
+
+BOOST_AUTO_TEST_CASE(Common_Value_TestCase_2)
+{
+  artis::common::event::Value int_value{1};
+  artis::common::event::Value unsigned_int_value{(unsigned int) 1};
+  artis::common::event::Value double_value{0.5};
+  artis::common::event::Value bool_value{true};
+  artis::common::event::Value char_value{'a'};
+
+  BOOST_REQUIRE_EQUAL(int_value.to_string(), "1");
+  BOOST_REQUIRE_EQUAL(unsigned_int_value.to_string(), "1");
+  BOOST_REQUIRE_EQUAL(double_value.to_string(), "0.500000");
+  BOOST_REQUIRE_EQUAL(bool_value.to_string(), "true");
+  BOOST_REQUIRE_EQUAL(char_value.to_string(), "a");
+}
+
+BOOST_AUTO_TEST_CASE(Common_Value_TestCase_3)
+{
+  int int_values[] = {1, 2, 3};
+  artis::common::event::Value int_value{int_values, 3};
+  unsigned int unsigned_int_values[] = {1, 2, 3};
+  artis::common::event::Value unsigned_int_value{unsigned_int_values, 3};
+  double double_values[] = {0.5, 0.6, 1.2};
+  artis::common::event::Value double_value{double_values, 3};
+  bool bool_values[] = {true, false, true, false};
+  artis::common::event::Value bool_value{bool_values, 4};
+  char char_values[] = {'a', 'b', 'c'};
+  artis::common::event::Value char_value{char_values, 3};
+
+  BOOST_REQUIRE_EQUAL(int_value.to_string(), "1 2 3 ");
+  BOOST_REQUIRE_EQUAL(unsigned_int_value.to_string(), "1 2 3 ");
+  BOOST_REQUIRE_EQUAL(double_value.to_string(), "0.500000 0.600000 1.200000 ");
+  BOOST_REQUIRE_EQUAL(bool_value.to_string(), "true false true false ");
+  BOOST_REQUIRE_EQUAL(char_value.to_string(), "abc");
+}
+
+BOOST_AUTO_TEST_CASE(Common_Value_TestCase_4)
+{
+  struct S {
+  } s;
+  artis::common::event::Value value{s};
+
+  BOOST_REQUIRE_EQUAL(value.to_string(), "<unstringify>");
+}

+ 51 - 0
tests/kernel_pdevs_simulator.cpp

@@ -0,0 +1,51 @@
+/**
+ * @file tests/common_model.cpp
+ * @author The ARTIS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * ARTIS - the multimodeling and simulation environment
+ * This file is a part of the ARTIS environment
+ *
+ * Copyright (C) 2013-2021 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "artis-star/kernel/pdevs/Dynamics.hpp"
+#include "artis-star/kernel/pdevs/Simulator.hpp"
+#include <artis-star/common/time/DoubleTime.hpp>
+
+#define BOOST_TEST_MODULE Kernel_Pdevs_Simulator_Tests
+
+#include <boost/test/unit_test.hpp>
+
+/*************************************************
+ * Tests
+ *************************************************/
+
+BOOST_AUTO_TEST_CASE(Kernel_Pdevs_Simulator_TestCase_1)
+{
+  class Inactive : public artis::pdevs::Dynamics<artis::common::DoubleTime, Inactive> {
+  public:
+    Inactive(const std::string &name,
+             const artis::pdevs::Context<artis::common::DoubleTime, Inactive, artis::common::NoParameters> &context)
+      : artis::pdevs::Dynamics<artis::common::DoubleTime, Inactive, artis::common::NoParameters>(name, context) {}
+  };
+
+  artis::pdevs::Simulator<artis::common::DoubleTime, Inactive> model("A", {});
+
+  BOOST_REQUIRE_EQUAL(model.get_name(), "A");
+}