Parcourir la source

Change copyright, reformat code et update DateTime class

Eric Ramat il y a 4 ans
Parent
commit
4e47d85a25
49 fichiers modifiés avec 3797 ajouts et 3814 suppressions
  1. 1 1
      AUTHORS
  2. 3 3
      src/CMakeLists.txt
  3. 5 5
      src/artis/CMakeLists.txt
  4. 5 3
      src/artis/builder/Builder.cpp
  5. 119 120
      src/artis/builder/Builder.hpp
  6. 1 1
      src/artis/builder/CMakeLists.txt
  7. 90 94
      src/artis/builder/ModelFactory.hpp
  8. 1 1
      src/artis/context/CMakeLists.txt
  9. 52 60
      src/artis/context/Context.hpp
  10. 56 57
      src/artis/context/State.hpp
  11. 95 99
      src/artis/context/StateValues.hpp
  12. 124 122
      src/artis/context/Value.hpp
  13. 184 193
      src/artis/kernel/AbstractAtomicModel.hpp
  14. 418 425
      src/artis/kernel/AbstractCoupledModel.hpp
  15. 106 106
      src/artis/kernel/AbstractModel.hpp
  16. 5 3
      src/artis/kernel/Any.cpp
  17. 162 165
      src/artis/kernel/Any.hpp
  18. 3 3
      src/artis/kernel/CMakeLists.txt
  19. 147 151
      src/artis/kernel/Externals.hpp
  20. 100 105
      src/artis/kernel/Internals.hpp
  21. 2 3
      src/artis/kernel/Macro.hpp
  22. 25 26
      src/artis/kernel/Node.hpp
  23. 5 3
      src/artis/kernel/Simulator.cpp
  24. 47 51
      src/artis/kernel/Simulator.hpp
  25. 80 83
      src/artis/kernel/States.hpp
  26. 1 1
      src/artis/lib.cpp
  27. 1 1
      src/artis/lib.hpp
  28. 2 2
      src/artis/observer/CMakeLists.txt
  29. 5 3
      src/artis/observer/Observer.cpp
  30. 57 59
      src/artis/observer/Observer.hpp
  31. 5 3
      src/artis/observer/Output.cpp
  32. 51 51
      src/artis/observer/Output.hpp
  33. 5 3
      src/artis/observer/View.cpp
  34. 110 112
      src/artis/observer/View.hpp
  35. 4 4
      src/artis/utils/CMakeLists.txt
  36. 689 640
      src/artis/utils/DateTime.cpp
  37. 304 305
      src/artis/utils/DateTime.hpp
  38. 14 13
      src/artis/utils/DoubleTime.hpp
  39. 69 88
      src/artis/utils/Exception.hpp
  40. 5 3
      src/artis/utils/ParametersReader.cpp
  41. 12 13
      src/artis/utils/ParametersReader.hpp
  42. 157 162
      src/artis/utils/Singleton.hpp
  43. 12 11
      src/artis/utils/Time.hpp
  44. 7 5
      src/artis/utils/Trace.cpp
  45. 347 359
      src/artis/utils/Trace.hpp
  46. 2 2
      src/test/CMakeLists.txt
  47. 56 45
      src/test/models.hpp
  48. 14 14
      src/test/test-context.cpp
  49. 32 32
      src/test/test.cpp

+ 1 - 1
AUTHORS

@@ -6,7 +6,7 @@ Copyright
 =========
 
 - ULCO
-  - Copyright © 2013-2017
+  - Copyright © 2012-2019
   - Université du Littoral Côte d'Opale
   - http://www.univ-littoral.fr
 

+ 3 - 3
src/CMakeLists.txt

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

+ 5 - 5
src/artis/CMakeLists.txt

@@ -1,5 +1,5 @@
 INCLUDE_DIRECTORIES(
-  ${CMAKE_SOURCE_DIR}/src)
+        ${CMAKE_SOURCE_DIR}/src)
 
 ADD_SUBDIRECTORY(builder)
 ADD_SUBDIRECTORY(context)
@@ -13,11 +13,11 @@ get_property(artis-lib_SRCS GLOBAL PROPERTY artis-lib_SRCS)
 add_library(artis-lib SHARED ${artis-lib_SRCS})
 
 set_target_properties(artis-lib PROPERTIES
-  VERSION 0
-  OUTPUT_NAME "artis-${ARTIS_VERSION_SHORT}"
-  CLEAN_DIRECT_OUTPUT 1)
+        VERSION 0
+        OUTPUT_NAME "artis-${ARTIS_VERSION_SHORT}"
+        CLEAN_DIRECT_OUTPUT 1)
 
 target_link_libraries(artis-lib ${Boost_LIBRARIES})
 
 install(TARGETS artis-lib RUNTIME DESTINATION bin LIBRARY DESTINATION
-  lib ARCHIVE DESTINATION lib)
+        lib ARCHIVE DESTINATION lib)

+ 5 - 3
src/artis/builder/Builder.cpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -22,6 +22,8 @@
 
 #include <artis/builder/Builder.hpp>
 
-namespace artis { namespace builder {
+namespace artis {
+    namespace builder {
 
-} }
+    }
+}

+ 119 - 120
src/artis/builder/Builder.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -31,142 +31,141 @@
 
 #include <sstream>
 
-namespace artis { namespace builder {
+namespace artis {
+    namespace builder {
 
-template < typename F, typename T, typename U, typename V, typename W >
-class Builder
-{
-public:
-    Builder(const std::string& json)
-    {
-        std::stringstream ss;
+        template<typename F, typename T, typename U, typename V, typename W>
+        class Builder {
+        public:
+            Builder(const std::string& json)
+            {
+                std::stringstream ss;
 
-        ss << json;
-        boost::property_tree::read_json(ss, tree);
-    }
+                ss << json;
+                boost::property_tree::read_json(ss, tree);
+            }
 
-    virtual ~Builder()
-    { }
-
-    T* build()
-    { return dynamic_cast < T* >(build_model(tree)); }
-
-private:
-    kernel::AbstractModel < U, V >* build_model(
-        boost::property_tree::ptree const& pt)
-    {
-        using boost::property_tree::ptree;
-
-        kernel::AbstractModel < U, V >* model = nullptr;
-        kernel::AbstractModels < U, V > submodels;
-        std::string name;
-        ptree::const_iterator it_type = pt.end();
-        ptree::const_iterator it_name = pt.end();
-        ptree::const_iterator it_states = pt.end();
-        ptree::const_iterator it_internals = pt.end();
-        ptree::const_iterator it_externals = pt.end();
-        ptree::const_iterator it_submodels = pt.end();
-
-        for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
-            if (it->first == "type") {
-                it_type = it;
-            } else if (it->first == "name") {
-                it_name = it;
-            } else if (it->first == "states") {
-                it_states = it;
-            } else if (it->first == "internals") {
-                it_internals = it;
-            } else if (it->first == "externals") {
-                it_externals = it;
-            } else if (it->first == "submodels") {
-                it_submodels = it;
+            virtual ~Builder() { }
+
+            T* build() { return dynamic_cast < T* >(build_model(tree)); }
+
+        private:
+            kernel::AbstractModel<U, V>* build_model(
+                    boost::property_tree::ptree const& pt)
+            {
+                using boost::property_tree::ptree;
+
+                kernel::AbstractModel<U, V>* model = nullptr;
+                kernel::AbstractModels<U, V> submodels;
+                std::string name;
+                ptree::const_iterator it_type = pt.end();
+                ptree::const_iterator it_name = pt.end();
+                ptree::const_iterator it_states = pt.end();
+                ptree::const_iterator it_internals = pt.end();
+                ptree::const_iterator it_externals = pt.end();
+                ptree::const_iterator it_submodels = pt.end();
+
+                for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
+                    if (it->first == "type") {
+                        it_type = it;
+                    } else if (it->first == "name") {
+                        it_name = it;
+                    } else if (it->first == "states") {
+                        it_states = it;
+                    } else if (it->first == "internals") {
+                        it_internals = it;
+                    } else if (it->first == "externals") {
+                        it_externals = it;
+                    } else if (it->first == "submodels") {
+                        it_submodels = it;
+                    }
+                }
+
+                // name
+                if (it_name != pt.end()) {
+                    name = it_type->second.get_value<std::string>();
+                }
+                // submodels
+                if (it_submodels != pt.end()) {
+                    for (ptree::const_iterator itm = it_submodels->second.begin();
+                         itm != it_submodels->second.end(); ++itm) {
+                        submodels.push_back(build_model(itm->second));
+                    }
+                }
+                // states
+                if (it_states != pt.end()) {
+                    build_states(it_states->second, model);
+                }
+                // internals
+                if (it_internals != pt.end()) {
+                    build_internals(it_internals->second, model);
+                }
+                // externals
+                if (it_externals != pt.end()) {
+                    build_externals(it_externals->second, model);
+                }
+                // type
+                if (it_type != pt.end()) {
+                    model = F::factory().create(
+                            it_type->second.get_value<std::string>(), submodels);
+                }
+                return model;
             }
-        }
-
-        // name
-        if (it_name != pt.end()) {
-            name = it_type->second.get_value < std::string >();
-        }
-        // submodels
-        if (it_submodels != pt.end()) {
-            for (ptree::const_iterator itm = it_submodels->second.begin();
-                 itm != it_submodels->second.end(); ++itm) {
-                submodels.push_back(build_model(itm->second));
+
+            void build_internals(boost::property_tree::ptree const& pt,
+                    kernel::AbstractModel<U, V>* model)
+            {
+                using boost::property_tree::ptree;
+
+                for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
+                    build_variable(it->second, model);
+                }
             }
-        }
-        // states
-        if (it_states != pt.end()) {
-            build_states(it_states->second, model);
-        }
-        // internals
-        if (it_internals != pt.end()) {
-            build_internals(it_internals->second, model);
-        }
-        // externals
-        if (it_externals != pt.end()) {
-            build_externals(it_externals->second, model);
-        }
-        // type
-        if (it_type != pt.end()) {
-            model = F::factory().create(
-                    it_type->second.get_value < std::string >(), submodels);
-        }
-        return model;
-    }
 
-    void build_internals(boost::property_tree::ptree const& pt,
-                         kernel::AbstractModel < U, V >* model)
-    {
-        using boost::property_tree::ptree;
+            void build_externals(boost::property_tree::ptree const& pt,
+                    kernel::AbstractModel<U, V>* model)
+            {
+                using boost::property_tree::ptree;
 
-        for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
-            build_variable(it->second, model);
-        }
-    }
+                for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
+                    build_variable(it->second, model);
+                }
+            }
 
-    void build_externals(boost::property_tree::ptree const& pt,
-                         kernel::AbstractModel < U, V >* model)
-    {
-        using boost::property_tree::ptree;
+            void build_states(boost::property_tree::ptree const& pt,
+                    kernel::AbstractModel<U, V>* model)
+            {
+                using boost::property_tree::ptree;
 
-        for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
-            build_variable(it->second, model);
-        }
-    }
+                for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
+                    build_variable(it->second, model);
+                }
+            }
 
-    void build_states(boost::property_tree::ptree const& pt,
-                      kernel::AbstractModel < U, V >* model)
-    {
-        using boost::property_tree::ptree;
+            void build_variable(boost::property_tree::ptree const& pt,
+                    kernel::AbstractModel<U, V>* /* model */)
+            {
+                using boost::property_tree::ptree;
 
-        for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
-            build_variable(it->second, model);
-        }
-    }
+                std::string name;
+                std::string type;
 
-    void build_variable(boost::property_tree::ptree const& pt,
-                        kernel::AbstractModel < U, V >* /* model */)
-    {
-        using boost::property_tree::ptree;
+                for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
+                    if (it->first == "name") {
+                        name = it->second.get_value<std::string>();
+                    } else if (it->first == "type") {
+                        type = it->second.get_value<std::string>();
+                    }
+                }
 
-        std::string name;
-        std::string type;
+                std::cout << name << ": " << type << std::endl;
 
-        for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
-            if (it->first == "name") {
-                name = it->second.get_value < std::string >();
-            } else if (it->first == "type") {
-                type = it->second.get_value < std::string >();
             }
-        }
 
-        std::cout << name << ": " << type << std::endl;
+            boost::property_tree::ptree tree;
+        };
 
     }
-
-    boost::property_tree::ptree tree;
-};
-
-} }
+}
 
 #endif

+ 1 - 1
src/artis/builder/CMakeLists.txt

@@ -1,5 +1,5 @@
 INCLUDE_DIRECTORIES(
-  ${CMAKE_SOURCE_DIR}/src)
+        ${CMAKE_SOURCE_DIR}/src)
 
 LINK_DIRECTORIES()
 

+ 90 - 94
src/artis/builder/ModelFactory.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -32,104 +32,100 @@
 
 #include <artis/kernel/AbstractModel.hpp>
 
-namespace artis { namespace builder {
-
-template < typename M, typename U, typename V >
-class ObjectCreator
-{
-public:
-    ObjectCreator()
-    { }
-    virtual ~ObjectCreator()
-    { }
-
-    virtual std::string get() const = 0;
-
-    virtual M* operator()(artis::kernel::AbstractModels < U,
-                          V > submodels) const = 0;
-};
-
-template < typename M, typename I, typename O, typename U, typename V >
-class ModelFactory
-{
-    typedef ModelFactory < M, I, O, U, V > type;
-
-public:
-    virtual ~ModelFactory()
-    { }
-
-    bool add(const I& id, O* creator)
-    {
-        std::lock_guard < std::mutex > lock(_mutex);
-        return creators.insert(typename Creators::value_type(
-                                   creator->get(),
-                                   std::make_pair(id, creator))).second;
-    }
-
-    M* create(const std::string& id, artis::kernel::AbstractModels < U,
-              V > submodels)
-    {
-        std::lock_guard < std::mutex > lock(_mutex);
-        typename Creators::const_iterator it = creators.find(id);
-
-        if (it != creators.end()) {
-            return (*it->second.second)(submodels);
-        } else {
-            return nullptr;
-        }
-    }
-
-    static ModelFactory& factory()
-    {
-        std::call_once(_flag, [] ()
-                       { _instance.reset(new ModelFactory()); });
-        return *_instance;
-    }
-
-    int make_id()
-    {
-        std::lock_guard < std::mutex > lock(_mutex);
-        return ++id;
-    }
+namespace artis {
+    namespace builder {
+
+        template<typename M, typename U, typename V>
+        class ObjectCreator {
+        public:
+            ObjectCreator() { }
+
+            virtual ~ObjectCreator() { }
+
+            virtual std::string get() const = 0;
+
+            virtual M* operator()(artis::kernel::AbstractModels<U,
+                    V> submodels) const = 0;
+        };
+
+        template<typename M, typename I, typename O, typename U, typename V>
+        class ModelFactory {
+            typedef ModelFactory<M, I, O, U, V> type;
+
+        public:
+            virtual ~ModelFactory() { }
+
+            bool add(const I& id, O* creator)
+            {
+                std::lock_guard<std::mutex> lock(_mutex);
+                return creators.insert(typename Creators::value_type(
+                        creator->get(),
+                        std::make_pair(id, creator))).second;
+            }
+
+            M* create(const std::string& id, artis::kernel::AbstractModels<U,
+                    V> submodels)
+            {
+                std::lock_guard<std::mutex> lock(_mutex);
+                typename Creators::const_iterator it = creators.find(id);
+
+                if (it != creators.end()) {
+                    return (*it->second.second)(submodels);
+                } else {
+                    return nullptr;
+                }
+            }
+
+            static ModelFactory& factory()
+            {
+                std::call_once(_flag, []() { _instance.reset(new ModelFactory()); });
+                return *_instance;
+            }
+
+            int make_id()
+            {
+                std::lock_guard<std::mutex> lock(_mutex);
+                return ++id;
+            }
+
+            bool remove(const I& id)
+            {
+                std::lock_guard<std::mutex> lock(_mutex);
+                typename Creators::const_iterator it = creators.find(id);
+
+                if (it != creators.end()) {
+                    creators.erase(it);
+                    return true;
+                } else {
+                    return false;
+                }
+            }
+
+        private:
+            ModelFactory() { id = -1; }
+
+            typedef std::pair<I, O*> Creator;
+            typedef std::map<std::string, Creator> Creators;
+
+            static std::shared_ptr<type> _instance;
+            static std::once_flag _flag;
+            std::mutex _mutex;
+
+            Creators creators;
+            int id;
+        };
 
-    bool remove(const I& id)
-    {
-        std::lock_guard < std::mutex > lock(_mutex);
-        typename Creators::const_iterator it = creators.find(id);
-
-        if (it != creators.end()) {
-            creators.erase(it);
-            return true;
-        } else {
-            return false;
-        }
     }
+}
 
-private:
-    ModelFactory()
-    { id = -1; }
-
-    typedef std::pair < I, O* > Creator;
-    typedef std::map < std::string, Creator > Creators;
-
-    static std::shared_ptr < type > _instance;
-    static std::once_flag           _flag;
-    std::mutex                      _mutex;
-
-    Creators creators;
-    int      id;
-};
-
-} }
-
-template < typename M, typename I, typename O, typename U, typename V >
-std::shared_ptr < artis::builder::ModelFactory < M, I, O, U, V > >
-artis::builder::ModelFactory < M, I, O, U, V >::_instance;
+template<typename M, typename I, typename O, typename U, typename V>
+std::shared_ptr<artis::builder::ModelFactory<M, I, O, U, V> >
+        artis::builder::ModelFactory<M, I, O, U, V>::_instance;
 
-template < typename M, typename I, typename O, typename U, typename V >
-std::once_flag artis::builder::ModelFactory < M, I, O, U, V >::_flag;
+template<typename M, typename I, typename O, typename U, typename V>
+std::once_flag artis::builder::ModelFactory<M, I, O, U, V>::_flag;
 
-#define DECLARE_MODEL(mdl, type, fct, U, V )                            \
+#define DECLARE_MODEL(mdl, type, fct, U, V)                            \
     class creator_##mdl : public artis::builder::ObjectCreator < type, U, V > { \
     public:                                                             \
     creator_##mdl()                                                     \

+ 1 - 1
src/artis/context/CMakeLists.txt

@@ -1,5 +1,5 @@
 INCLUDE_DIRECTORIES(
-  ${CMAKE_SOURCE_DIR}/src)
+        ${CMAKE_SOURCE_DIR}/src)
 
 LINK_DIRECTORIES()
 

+ 52 - 60
src/artis/context/Context.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -27,82 +27,74 @@
 
 #include <boost/serialization/serialization.hpp>
 
-namespace artis { namespace context {
+namespace artis {
+    namespace context {
 
-template < typename U >
-class Context
-{
-public:
-    Context() : _begin(-1), _end(-1), _valid(false)
-    { }
+        template<typename U>
+        class Context {
+        public:
+            Context()
+                    :_begin(-1), _end(-1), _valid(false) { }
 
-    Context(double begin, double end) : _begin(begin), _end(end), _valid(false)
-    { }
+            Context(double begin, double end)
+                    :_begin(begin), _end(end), _valid(false) { }
 
-    virtual ~Context()
-    { }
+            virtual ~Context() { }
 
-    double begin() const
-    { return _begin; }
+            double begin() const { return _begin; }
 
-    void begin(double begin)
-    { _begin = begin; }
+            void begin(double begin) { _begin = begin; }
 
-    double end() const
-    { return _end; }
+            double end() const { return _end; }
 
-    void end(double end)
-    { _end = end; }
+            void end(double end) { _end = end; }
 
-    const Context& operator=(const Context& context)
-    {
-        _begin = context._begin;
-        _end = context._end;
-        _valid = context._valid;
-        _state = context._state;
-        return *this;
-    }
+            const Context& operator=(const Context& context)
+            {
+                _begin = context._begin;
+                _end = context._end;
+                _valid = context._valid;
+                _state = context._state;
+                return *this;
+            }
 
-    void saved()
-    { _valid = true; }
+            void saved() { _valid = true; }
 
-    const State < U >& state() const
-    { return _state; }
+            const State<U>& state() const { return _state; }
 
-    State < U >& state()
-    { return _state; }
+            State<U>& state() { return _state; }
 
-    std::string to_string() const
-    {
-        return "begin: " + std::to_string(_begin) +
-            "; end: " + std::to_string(_end) +
-            "; valid: " + (_valid ? "true" : "false") +
-            "; state: " + _state.to_string();
-    }
+            std::string to_string() const
+            {
+                return "begin: " + std::to_string(_begin) +
+                        "; 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;
+        private:
+            friend class boost::serialization::access;
 
-    template < class Archive >
-    void serialize(Archive & ar, const unsigned int version)
-    {
-        (void) version;
+            template<class Archive>
+            void serialize(Archive& ar, const unsigned int version)
+            {
+                (void) version;
 
-        ar & _begin;
-        ar & _end;
-        ar & _state;
-        ar & _valid;
-    }
+                ar & _begin;
+                ar & _end;
+                ar & _state;
+                ar & _valid;
+            }
 
-    double      _begin;
-    double      _end;
-    State < U > _state;
-    bool        _valid;
-};
+            double _begin;
+            double _end;
+            State<U> _state;
+            bool _valid;
+        };
 
-} }
+    }
+}
 
 #endif

+ 56 - 57
src/artis/context/State.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -31,81 +31,80 @@
 #include <boost/serialization/map.hpp>
 #include <boost/serialization/vector.hpp>
 
-namespace artis { namespace context {
+namespace artis {
+    namespace context {
 
-template < typename U >
-class State
-{
-    typedef std::map < unsigned int, State < U > > Substates;
+        template<typename U>
+        class State {
+            typedef std::map<unsigned int, State<U> > Substates;
 
-public:
-    State() : _last_time(-1)
-    { }
+        public:
+            State()
+                    :_last_time(-1) { }
 
-    virtual ~State()
-    { }
+            virtual ~State() { }
 
-    void add_external(unsigned int variable_key, const Value& value)
-    { _values.add_external(variable_key, value); }
+            void add_external(unsigned int variable_key, const Value& value)
+            {
+                _values.add_external(variable_key, value);
+            }
 
-    void add_internal(unsigned int variable_key, const Value& value)
-    { _values.add_internal(variable_key, value); }
+            void add_internal(unsigned int variable_key, const Value& value)
+            {
+                _values.add_internal(variable_key, value);
+            }
 
-    void add_state(unsigned int variable_key, const Value& value)
-    { _values.add_state(variable_key, value); }
+            void add_state(unsigned int variable_key, const 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_substate(unsigned int model_key, State& state)
+            {
+                _substates.insert(std::make_pair(model_key, state));
+            }
 
-    const Value& get_external(unsigned int variable_key) const
-    { return _values.get_external(variable_key); }
+            const Value& get_external(unsigned int variable_key) const { return _values.get_external(variable_key); }
 
-    const Value& get_internal(unsigned int variable_key) const
-    { return _values.get_internal(variable_key); }
+            const Value& get_internal(unsigned int variable_key) const { return _values.get_internal(variable_key); }
 
-    const Value& get_state(unsigned int variable_key) const
-    { return _values.get_state(variable_key); }
+            const Value& get_state(unsigned int variable_key) const { return _values.get_state(variable_key); }
 
-    const State < U >& get_substate(unsigned int model_key) const
-    { return _substates.find(model_key)->second; }
+            const State<U>& get_substate(unsigned int model_key) const { return _substates.find(model_key)->second; }
 
-    typename U::type last_time() const
-    { return _last_time; }
+            typename U::type last_time() const { return _last_time; }
 
-    void last_time(typename U::type t)
-    { _last_time = t; }
+            void last_time(typename U::type t) { _last_time = t; }
 
-    std::string to_string() const
-    {
-        std::string str = "last_time: " + std::to_string(_last_time) +
-            "; values: " + _values.to_string() + "; sub_states: [ ";
+            std::string to_string() const
+            {
+                std::string str = "last_time: " + std::to_string(_last_time) +
+                        "; values: " + _values.to_string() + "; sub_states: [ ";
 
-        for (typename Substates::const_iterator it = _substates.begin();
-             it != _substates.end(); ++it) {
-            str += it->second.to_string() + " ";
-        }
-        str += "]";
-        return str;
-    }
+                for (typename Substates::const_iterator it = _substates.begin();
+                     it != _substates.end(); ++it) {
+                    str += it->second.to_string() + " ";
+                }
+                str += "]";
+                return str;
+            }
 
-private:
-    friend class boost::serialization::access;
+        private:
+            friend class boost::serialization::access;
 
-    template < class Archive >
-    void serialize(Archive & ar, const unsigned int version)
-    {
-        (void) version;
+            template<class Archive>
+            void serialize(Archive& ar, const unsigned int version)
+            {
+                (void) version;
 
-        ar & _values;
-        ar & _substates;
-        ar & _last_time;
-    }
+                ar & _values;
+                ar & _substates;
+                ar & _last_time;
+            }
 
-    StateValues      _values;
-    Substates        _substates;
-    typename U::type _last_time;
-};
+            StateValues _values;
+            Substates _substates;
+            typename U::type _last_time;
+        };
 
-} }
+    }
+}
 
 #endif

+ 95 - 99
src/artis/context/StateValues.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -30,105 +30,101 @@
 #include <boost/serialization/serialization.hpp>
 #include <boost/serialization/map.hpp>
 
-namespace artis { namespace context {
+namespace artis {
+    namespace context {
+
+        class StateValues {
+        public:
+            StateValues() { }
+
+            virtual ~StateValues() { }
+
+            void add_external(unsigned int key, const Value& value) { _externals[key] = value; }
+
+            void add_internal(unsigned int key, const Value& value) { _internals[key] = value; }
+
+            void add_state(unsigned int key, const Value& value) { _states[key] = value; }
+
+            const Value& get_external(unsigned int key) const
+            {
+                std::map<unsigned int, Value>::const_iterator it =
+                        _externals.find(key);
+
+                if (it != _externals.end()) {
+                    return it->second;
+                } else {
+                    assert(false);
+                    return it->second;
+                }
+            }
+
+            const Value& get_internal(unsigned int key) const
+            {
+                std::map<unsigned int, Value>::const_iterator it =
+                        _internals.find(key);
+
+                if (it != _internals.end()) {
+                    return it->second;
+                } else {
+                    assert(false);
+                    return it->second;
+                }
+            }
+
+            const Value& get_state(unsigned int key) const
+            {
+                std::map<unsigned int, Value>::const_iterator it =
+                        _states.find(key);
+
+                if (it != _states.end()) {
+                    return it->second;
+                } else {
+                    assert(false);
+                    return it->second;
+                }
+            }
+
+            std::string to_string() const
+            {
+                std::string str = "externals: [ ";
+
+                for (std::map<unsigned int, Value>::const_iterator it =
+                        _externals.begin(); it != _externals.end(); ++it) {
+                    str += it->second.to_string() + " ";
+                }
+                str += "]; internals: [ ";
+                for (std::map<unsigned int, Value>::const_iterator it =
+                        _internals.begin(); it != _internals.end(); ++it) {
+                    str += it->second.to_string() + " ";
+                }
+                str += "]; states: [ ";
+                for (std::map<unsigned int, Value>::const_iterator it =
+                        _states.begin(); it != _states.end(); ++it) {
+                    str += it->second.to_string() + " ";
+                }
+                str += "]";
+                return str;
+            }
+
+        private:
+            friend class boost::serialization::access;
+
+            template<class Archive>
+            void serialize(Archive& ar, const unsigned int version)
+            {
+                (void) version;
+
+                ar & _externals;
+                ar & _internals;
+                ar & _states;
+            }
+
+            std::map<unsigned int, Value> _externals;
+            std::map<unsigned int, Value> _internals;
+            std::map<unsigned int, Value> _states;
+        };
 
-class StateValues
-{
-public:
-    StateValues()
-    { }
-
-    virtual ~StateValues()
-    { }
-
-    void add_external(unsigned int key, const Value& value)
-    { _externals[key] = value; }
-
-    void add_internal(unsigned int key, const Value& value)
-    { _internals[key] = value; }
-
-    void add_state(unsigned int key, const Value& value)
-    { _states[key] = value; }
-
-    const Value& get_external(unsigned int key) const
-    {
-        std::map < unsigned int, Value >::const_iterator it =
-            _externals.find(key);
-
-        if (it != _externals.end()) {
-            return it->second;
-        } else {
-            assert(false);
-            return it->second;
-        }
-    }
-
-    const Value& get_internal(unsigned int key) const
-    {
-        std::map < unsigned int, Value >::const_iterator it =
-            _internals.find(key);
-
-        if (it != _internals.end()) {
-            return it->second;
-        } else {
-            assert(false);
-            return it->second;
-        }
-    }
-
-    const Value& get_state(unsigned int key) const
-    {
-        std::map < unsigned int, Value >::const_iterator it =
-            _states.find(key);
-
-        if (it != _states.end()) {
-            return it->second;
-        } else {
-            assert(false);
-            return it->second;
-        }
-    }
-
-    std::string to_string() const
-    {
-        std::string str = "externals: [ ";
-
-        for (std::map < unsigned int, Value >::const_iterator it =
-                 _externals.begin(); it != _externals.end(); ++it) {
-            str += it->second.to_string() + " ";
-        }
-        str += "]; internals: [ ";
-        for (std::map < unsigned int, Value >::const_iterator it =
-                 _internals.begin(); it != _internals.end(); ++it) {
-            str += it->second.to_string() + " ";
-        }
-        str += "]; states: [ ";
-        for (std::map < unsigned int, Value >::const_iterator it =
-                 _states.begin(); it != _states.end(); ++it) {
-            str += it->second.to_string() + " ";
-        }
-        str += "]";
-        return str;
     }
-
-private:
-    friend class boost::serialization::access;
-
-    template < class Archive >
-    void serialize(Archive & ar, const unsigned int version)
-    {
-        (void) version;
-
-        ar & _externals;
-        ar & _internals;
-        ar & _states;
-    }
-
-    std::map < unsigned int, Value > _externals;
-    std::map < unsigned int, Value > _internals;
-    std::map < unsigned int, Value > _states;
-};
-
-} }
+}
 
 #endif

+ 124 - 122
src/artis/context/Value.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -28,7 +28,9 @@
 #include <boost/version.hpp>
 
 #if BOOST_VERSION > 106200
+
 #include <boost/serialization/array_wrapper.hpp>
+
 #endif
 
 #include <algorithm>
@@ -42,128 +44,128 @@
 #include <typeinfo>
 #include <vector>
 
-namespace artis { namespace context {
-
-class Value
-{
-public:
-    Value() : _content(nullptr), _size(0)
-    { }
-
-    template < typename T >
-    Value(T value) : _content(nullptr), _size(0)
-    { assign(&value, sizeof(T), typeid(T).hash_code()); }
-
-    Value(void* content, size_t size) : _content(nullptr), _size(0)
-    { assign(content, size, typeid(void*).hash_code()); }
-
-    Value(const char* value, unsigned int size) : _content(nullptr), _size(0)
-    { assign(value, size * sizeof(char), typeid(char*).hash_code()); }
-
-    Value(const Value& value) : _content(nullptr), _size(0)
-    {
-        if (value._content) {
-            assign(value._content, value._size, value._type_id);
-        }
-    }
-
-    virtual ~Value()
-    { if (_content) delete[] _content; }
-
-    bool empty() const
-    { return _content == nullptr; }
-
-    template < typename T >
-    void get_content(T& value) const
-    {
-        assert(_type_id == typeid(T).hash_code());
-
-        value = *(T*)(_content);
-    }
+namespace artis {
+    namespace context {
+
+        class Value {
+        public:
+            Value()
+                    :_content(nullptr), _size(0) { }
+
+            template<typename T>
+            Value(T value)
+                    : _content(nullptr), _size(0) { assign(&value, sizeof(T), typeid(T).hash_code()); }
+
+            Value(void* content, size_t size)
+                    :_content(nullptr), _size(0) { assign(content, size, typeid(void*).hash_code()); }
+
+            Value(const char* value, unsigned int size)
+                    :_content(nullptr), _size(0) { assign(value, size * sizeof(char), typeid(char*).hash_code()); }
+
+            Value(const Value& value)
+                    :_content(nullptr), _size(0)
+            {
+                if (value._content) {
+                    assign(value._content, value._size, value._type_id);
+                }
+            }
+
+            virtual ~Value() { if (_content) delete[] _content; }
+
+            bool empty() const { return _content == nullptr; }
+
+            template<typename T>
+            void get_content(T& value) const
+            {
+                assert(_type_id == typeid(T).hash_code());
+
+                value = *(T*) (_content);
+            }
+
+            const Value& operator=(const Value& value)
+            {
+                if (_content) delete[] _content;
+                _content = nullptr;
+                _size = 0;
+                if (value._content) {
+                    assign(value._content, value._size, value._type_id);
+                }
+                return *this;
+            }
+
+            std::string to_string() const
+            {
+                if (is_type<double>()) {
+                    double v;
+
+                    get_content(v);
+                    return std::to_string(v);
+                } else if (is_type<int>()) {
+                    int v;
+
+                    get_content(v);
+                    return std::to_string(v);
+                } else if (is_type<bool>()) {
+                    bool v;
+
+                    get_content(v);
+                    return v ? "true" : "false";
+                }
+                if (is_type<std::vector<double> >()) {
+                    std::vector<double> v;
+
+                    get_content(v);
+                    return "";
+                } else if (is_type<std::vector<int> >()) {
+                    std::vector<int> v;
+
+                    get_content(v);
+                    return "";
+                } else if (is_type<std::vector<bool> >()) {
+                    std::vector<bool> v;
+
+                    get_content(v);
+                    return "";
+                } else {
+                    assert(false);
+                }
+            }
+
+            template<typename Z>
+            bool is_type() const { return _type_id == typeid(Z).hash_code(); }
+
+        private:
+            void assign(const void* content, size_t size, size_t type_id)
+            {
+                _content = new char[size < 16 ? 16 : 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;
+        };
 
-    const Value& operator=(const Value& value)
-    {
-        if (_content) delete[] _content;
-        _content = nullptr;
-        _size = 0;
-        if (value._content) {
-            assign(value._content, value._size, value._type_id);
-        }
-        return *this;
     }
-
-    std::string to_string() const
-    {
-        if (is_type < double >()) {
-            double v;
-
-            get_content(v);
-            return std::to_string(v);
-        } else if (is_type < int >()) {
-            int v;
-
-            get_content(v);
-            return std::to_string(v);
-        } else if (is_type < bool >()) {
-            bool v;
-
-            get_content(v);
-            return v ? "true" : "false";
-        } if (is_type < std::vector < double > >()) {
-            std::vector < double > v;
-
-            get_content(v);
-            return "";
-        } else if (is_type < std::vector < int > >()) {
-            std::vector < int > v;
-
-            get_content(v);
-            return "";
-        } else if (is_type < std::vector < bool > >()) {
-            std::vector < bool > v;
-
-            get_content(v);
-            return "";
-        } else {
-            assert(false);
-        }
-    }
-
-    template < typename Z >
-    bool is_type() const
-    { return _type_id == typeid(Z).hash_code(); }
-
-private:
-    void assign(const void* content, size_t size, size_t type_id)
-    {
-        _content = new char[size < 16 ? 16 : 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;
-};
-
-} }
+}
 
 #endif

+ 184 - 193
src/artis/kernel/AbstractAtomicModel.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -33,240 +33,231 @@
 
 #include <sstream>
 
-namespace artis { namespace kernel {
-
-template < typename T, typename U, typename V >
-class AbstractAtomicModel : public AbstractModel < U, V >,
-                            public States < T, U, V >,
-                            public Internals < T, U, V >,
-                            public Externals < T, U, V >
-{
-    typedef AbstractModel < U, V > type;
-
-    using Externals < T, U, V >::restore;
-    using Internals < T, U, V >::restore;
-    using States < T, U, V >::restore;
-    using Externals < T, U, V >::save;
-    using Internals < T, U, V >::save;
-    using States < T, U, V >::save;
-
-public:
-    AbstractAtomicModel(const type* parent = 0) : type(parent)
-    {
+namespace artis {
+    namespace kernel {
+
+        template<typename T, typename U, typename V>
+        class AbstractAtomicModel : public AbstractModel<U, V>,
+                                    public States<T, U, V>,
+                                    public Internals<T, U, V>,
+                                    public Externals<T, U, V> {
+            typedef AbstractModel<U, V> type;
+
+            using Externals<T, U, V>::restore;
+            using Internals<T, U, V>::restore;
+            using States<T, U, V>::restore;
+            using Externals<T, U, V>::save;
+            using Internals<T, U, V>::save;
+            using States<T, U, V>::save;
+
+        public:
+            AbstractAtomicModel(const type* parent = 0)
+                    :type(parent)
+            {
 #ifdef WITH_TRACE
-        utils::Trace < utils::DoubleTime >::trace()
-            << utils::TraceElement < utils::DoubleTime >(
-                   true,
-                   boost::core::demangle(typeid(T).name()),
-                   utils::DoubleTime::null,
-                   utils::CONSTRUCT);
-        utils::Trace < utils::DoubleTime >::trace().flush();
+                utils::Trace<utils::DoubleTime>::trace()
+                        << utils::TraceElement<utils::DoubleTime>(
+                                true,
+                                boost::core::demangle(typeid(T).name()),
+                                utils::DoubleTime::null,
+                                utils::CONSTRUCT);
+                utils::Trace<utils::DoubleTime>::trace().flush();
 #endif
-    }
+            }
 
-    virtual ~AbstractAtomicModel()
-    {
+            virtual ~AbstractAtomicModel()
+            {
 #ifdef WITH_TRACE
-        trace_element(true, utils::DoubleTime::null,
-                      utils::DESTRUCT);
+                trace_element(true, utils::DoubleTime::null,
+                        utils::DESTRUCT);
 #endif
-    }
+            }
 
-    virtual const Node < U >* atomic(unsigned int /* index */) const
-    { return this; }
+            virtual const Node<U>* atomic(unsigned int /* index */) const { return this; }
 
-    virtual void after(typename U::type t)
-    {
+            virtual void after(typename U::type t)
+            {
 
 #ifdef WITH_TRACE
-        trace_element(true, t, utils::AFTER_COMPUTE);
-        trace_internals(true, t, utils::AFTER_COMPUTE);
+                trace_element(true, t, utils::AFTER_COMPUTE);
+                trace_internals(true, t, utils::AFTER_COMPUTE);
 #else
-        (void) t;
+                (void) t;
 #endif
 
-    }
+            }
 
-    virtual void before(typename U::type t)
-    {
+            virtual void before(typename U::type t)
+            {
 
 #ifdef WITH_TRACE
-        trace_element(true, t, utils::BEFORE_COMPUTE);
-        trace_internals(true, t, utils::BEFORE_COMPUTE);
-        trace_externals(true, t, utils::BEFORE_COMPUTE);
+                trace_element(true, t, utils::BEFORE_COMPUTE);
+                trace_internals(true, t, utils::BEFORE_COMPUTE);
+                trace_externals(true, t, utils::BEFORE_COMPUTE);
 #else
-        (void) t;
+                (void) t;
 #endif
 
-    }
+            }
 
-    virtual bool check(typename U::type t) const
-    { return Externals < T, U, V >::check(t); }
+            virtual bool check(typename U::type t) const { return Externals<T, U, V>::check(t); }
 
-    virtual void compute(typename U::type t, bool update) = 0;
+            virtual void compute(typename U::type t, bool update) = 0;
 
-    virtual const Any& get(typename U::type t, unsigned int index) const
-    {
-        if (type::last_time != t) {
-            throw utils::InvalidGet("Variable not computed");
-        }
-        return Internals < T, U, V >::get(index);
-    }
+            virtual const Any& get(typename U::type t, unsigned int index) const
+            {
+                if (type::last_time != t) {
+                    throw utils::InvalidGet("Variable not computed");
+                }
+                return Internals<T, U, V>::get(index);
+            }
 
-    template < typename W >
-    W get(typename U::type t, unsigned int index) const
-    {
-        if (type::last_time != t) {
-            throw utils::InvalidGet("Variable not computed");
-        }
+            template<typename W>
+            W get(typename U::type t, unsigned int index) const
+            {
+                if (type::last_time != t) {
+                    throw utils::InvalidGet("Variable not computed");
+                }
 
-        Any value = Internals < T, U, V >::get(index);
+                Any value = Internals<T, U, V>::get(index);
 
-        return static_cast < const T* >(this)->*(value.get < T, W >());
-    }
+                return static_cast < const T* >(this)->*(value.get<T, W>());
+            }
+
+            virtual std::string get(const ValueTypeID& value_type, typename U::type t,
+                    unsigned int index) const
+            {
+                if (type::last_time != t) {
+                    throw utils::InvalidGet("Variable not computed");
+                }
+
+                Any value = Internals<T, U, V>::get(index);
+
+                switch (value_type) {
+                case DOUBLE: {
+                    std::ostringstream ss;
+
+                    ss << std::setprecision(10)
+                       << static_cast < const T* >(this)->*(
+                               value.get<T, double>());
+                    return ss.str();
+                }
+                case INT:
+                    return std::to_string(
+                            static_cast < const T* >(this)->*(value.get<T, int>()));
+                case BOOL:
+                    return std::to_string(
+                            static_cast < const T* >(this)->*(value.get<T, bool>()));
+                default:
+                    return "NA";
+                }
+            }
 
-    virtual std::string get(const ValueTypeID& value_type, typename U::type t,
-                            unsigned int index) const
-    {
-        if (type::last_time != t) {
-            throw utils::InvalidGet("Variable not computed");
-        }
+            virtual void init(typename U::type t, const V& parameters) = 0;
 
-        Any value = Internals < T, U, V >::get(index);
+            virtual bool is_atomic() const { return true; }
 
-        switch (value_type) {
-        case DOUBLE:
-            {
-                std::ostringstream ss;
+            bool is_computed(typename U::type t, unsigned int /* index */) const { return type::last_time == t; }
+
+            bool is_stable(typename U::type t) const { return type::last_time == t; }
 
-                ss << std::setprecision(10)
-                   << static_cast < const T* >(this)->*(
-                       value.get < T, double >());
-                return ss.str();
+            virtual bool is_updated() const { return Externals<T, U, V>::updated; }
+
+            virtual void restore(const context::State<U>& state)
+            {
+                Externals<T, U, V>::restore(this, state);
+                Internals<T, U, V>::restore(this, state);
+                States<T, U, V>::restore(this, state);
+                type::last_time = state.last_time();
             }
-        case INT:
-            return std::to_string(
-                static_cast < const T* >(this)->*(value.get < T, int >()));
-        case BOOL:
-            return std::to_string(
-                static_cast < const T* >(this)->*(value.get < T, bool >()));
-        default: return "NA";
-        }
-    }
 
-    virtual void init(typename U::type t, const V& parameters) = 0;
+            virtual void save(context::State<U>& state) const
+            {
+                Externals<T, U, V>::save(this, state);
+                Internals<T, U, V>::save(this, state);
+                States<T, U, V>::save(this, state);
+                state.last_time(type::last_time);
+            }
 
-    virtual bool is_atomic() const
-    { return true; }
+            virtual void stable() { Externals<T, U, V>::updated = false; }
 
-    bool is_computed(typename U::type t, unsigned int /* index */) const
-    { return type::last_time == t; }
+            virtual void trace_element(typename U::type t,
+                    utils::TraceType type = utils::NONE,
+                    std::string comment = "") const { trace_element(false, t, type, comment); }
 
-    bool is_stable(typename U::type t) const
-    { return type::last_time == t; }
+            virtual void trace_internals(typename U::type t,
+                    utils::TraceType type) const { trace_internals(false, t, type); }
 
-    virtual bool is_updated() const
-    { return Externals < T, U, V >::updated; }
+            virtual void trace_externals(typename U::type t,
+                    utils::TraceType type = utils::NONE) const { trace_externals(false, t, type); }
 
-    virtual void restore(const context::State < U >& state)
-    {
-        Externals < T, U, V >::restore(this, state);
-        Internals < T, U, V >::restore(this, state);
-        States < T, U, V >::restore(this, state);
-        type::last_time = state.last_time();
-    }
+            virtual void trace_model(typename U::type t,
+                    utils::TraceType type = utils::NONE) const { trace_model(false, t, type); }
 
-    virtual void save(context::State < U >& state) const
-    {
-        Externals < T, U, V >::save(this, state);
-        Internals < T, U, V >::save(this, state);
-        States < T, U, V >::save(this, state);
-        state.last_time(type::last_time);
-    }
+        private:
+            void trace_element(bool from_kernel, typename U::type t,
+                    utils::TraceType type = utils::NONE,
+                    std::string comment = "") const
+            {
+                utils::Trace<utils::DoubleTime>::trace()
+                        << utils::TraceElement<utils::DoubleTime>(
+                                from_kernel,
+                                AbstractAtomicModel<T, U, V>::path(this),
+                                t, type)
+                        << comment;
+                utils::Trace<utils::DoubleTime>::trace().flush();
+            }
 
-    virtual void stable()
-    { Externals < T, U, V >::updated = false; }
-
-    virtual void trace_element(typename U::type t,
-            utils::TraceType type = utils::NONE,
-            std::string comment = "") const
-    { trace_element(false, t, type, comment); }
-
-    virtual void trace_internals(typename U::type t,
-            utils::TraceType type) const
-    { trace_internals(false, t, type); }
-
-    virtual void trace_externals(typename U::type t,
-            utils::TraceType type = utils::NONE) const
-    { trace_externals(false, t, type); }
-
-    virtual void trace_model(typename U::type t,
-            utils::TraceType type = utils::NONE) const
-    { trace_model(false, t, type); }
-
-private:
-    void trace_element(bool from_kernel, typename U::type t,
-                       utils::TraceType type = utils::NONE,
-                       std::string comment = "") const
-    {
-        utils::Trace < utils::DoubleTime >::trace()
-            << utils::TraceElement < utils::DoubleTime >(
-                from_kernel,
-                AbstractAtomicModel < T, U, V >::path(this),
-                t, type)
-            << comment;
-        utils::Trace < utils::DoubleTime >::trace().flush();
-    }
+            void trace_internals(bool from_kernel, typename U::type t,
+                    utils::TraceType type) const
+            {
+                for (size_t i = 0; i < Internals<T, U, V>::size(); ++i) {
+                    if (not Internals<T, U, V>::get(i).is_null()) {
+                        utils::Trace<utils::DoubleTime>::trace()
+                                << utils::TraceElement<utils::DoubleTime>(
+                                        from_kernel,
+                                        AbstractAtomicModel<T, U, V>::path(this),
+                                        t, type)
+                                << utils::KernelInfo(
+                                        Internals<T, U, V>::name(i), true,
+                                        Internals<T, U, V>::get(i).to_string(
+                                                dynamic_cast < const T* >(this))
+                                );
+                        utils::Trace<utils::DoubleTime>::trace().flush();
+                    }
+                }
+            }
 
-    void trace_internals(bool from_kernel, typename U::type t,
-                         utils::TraceType type) const
-    {
-        for (size_t i = 0; i < Internals < T, U, V >::size(); ++i) {
-            if (not Internals < T, U, V >::get(i).is_null()) {
-                utils::Trace < utils::DoubleTime >::trace()
-                    << utils::TraceElement < utils::DoubleTime >(
-                        from_kernel,
-                        AbstractAtomicModel < T, U, V >::path(this),
-                        t, type)
-                    << utils::KernelInfo(
-                        Internals < T, U, V >::name(i), true,
-                        Internals < T, U, V >::get(i).to_string(
-                            dynamic_cast < const T* >(this))
-                        );
-                utils::Trace < utils::DoubleTime >::trace().flush();
+            void trace_externals(bool from_kernel, typename U::type t,
+                    utils::TraceType type = utils::NONE) const
+            {
+                for (size_t i = 0; i < Externals<T, U, V>::size(); ++i) {
+                    if (not Externals<T, U, V>::get(i).is_null()) {
+                        utils::Trace<utils::DoubleTime>::trace()
+                                << utils::TraceElement<utils::DoubleTime>(
+                                        from_kernel,
+                                        AbstractAtomicModel<T, U, V>::path(this),
+                                        t, type)
+                                << utils::KernelInfo(
+                                        Externals<T, U, V>::name(i), false,
+                                        Externals<T, U, V>::get(i).to_string(
+                                                dynamic_cast < const T* >(this))
+                                );
+                        utils::Trace<utils::DoubleTime>::trace().flush();
+                    }
+                }
             }
-        }
-    }
 
-    void trace_externals(bool from_kernel, typename U::type t,
-                         utils::TraceType type = utils::NONE) const
-    {
-        for (size_t i = 0; i < Externals < T, U, V >::size(); ++i) {
-            if (not Externals < T, U, V >::get(i).is_null()) {
-                utils::Trace < utils::DoubleTime >::trace()
-                    << utils::TraceElement < utils::DoubleTime >(
-                        from_kernel,
-                        AbstractAtomicModel < T, U, V >::path(this),
-                        t, type)
-                    << utils::KernelInfo(
-                        Externals < T, U, V >::name(i), false,
-                        Externals < T, U, V >::get(i).to_string(
-                            dynamic_cast < const T* >(this))
-                        );
-                utils::Trace < utils::DoubleTime >::trace().flush();
+            void trace_model(bool from_kernel, typename U::type t,
+                    utils::TraceType type = utils::NONE) const
+            {
+                trace_element(from_kernel, t, type);
+                trace_internals(from_kernel, t, type);
+                trace_externals(from_kernel, t, type);
             }
-        }
-    }
+        };
 
-    void trace_model(bool from_kernel, typename U::type t,
-                     utils::TraceType type = utils::NONE) const
-    {
-        trace_element(from_kernel, t, type);
-        trace_internals(from_kernel, t, type);
-        trace_externals(from_kernel, t, type);
     }
-};
-
-} }
+}
 
 #endif

+ 418 - 425
src/artis/kernel/AbstractCoupledModel.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -34,508 +34,500 @@
 #include <functional>
 #include <vector>
 
-namespace artis { namespace kernel {
-
-template < typename T, typename U, typename V, typename W >
-class Simulator;
-
-template < typename T, typename U, typename V, typename W >
-class AbstractCoupledModel : public AbstractModel < U, V >,
-                             public States < T, U, V >,
-                             public Internals < T, U, V >,
-                             public Externals < T, U, V >
-{
-    typedef AbstractModel < U, V > type;
-    typedef std::map < int, type* > Submodels;
-    typedef std::map < int,
-                       std::vector < type* > > Setsubmodels;
-    typedef std::map < int, std::pair < type*,
-                                        int > > SubModelInternals;
-
-    using Externals < T, U, V >::restore;
-    using Internals < T, U, V >::restore;
-    using States < T, U, V >::restore;
-    using Externals < T, U, V >::save;
-    using Internals < T, U, V >::save;
-    using States < T, U, V >::save;
+namespace artis {
+    namespace kernel {
+
+        template<typename T, typename U, typename V, typename W>
+        class Simulator;
+
+        template<typename T, typename U, typename V, typename W>
+        class AbstractCoupledModel : public AbstractModel<U, V>,
+                                     public States<T, U, V>,
+                                     public Internals<T, U, V>,
+                                     public Externals<T, U, V> {
+            typedef AbstractModel<U, V> type;
+            typedef std::map<int, type*> Submodels;
+            typedef std::map<int,
+                    std::vector<type*> > Setsubmodels;
+            typedef std::map<int, std::pair<type*,
+                    int> > SubModelInternals;
+
+            using Externals<T, U, V>::restore;
+            using Internals<T, U, V>::restore;
+            using States<T, U, V>::restore;
+            using Externals<T, U, V>::save;
+            using Internals<T, U, V>::save;
+            using States<T, U, V>::save;
 
 #ifdef WITH_TRACE
-    friend class Simulator < T, U, V, W >;
+
+            friend class Simulator<T, U, V, W>;
+
 #endif
 
-public:
-    struct Var
-    {
-        unsigned int index;
-        type* model;
-        int sub_index;
-        std::string var_name;
-        std::string sub_var_name;
-
-        Var (unsigned int index, std::string var_name,
-             type* model, int sub_index, std::string sub_var_name) :
-            index(index), model(model), sub_index(sub_index),
-            var_name(var_name), sub_var_name(sub_var_name)
-        { }
-    };
-
-    AbstractCoupledModel(const type* parent = 0) : type(parent)
-    {
+        public:
+            struct Var {
+                unsigned int index;
+                type* model;
+                int sub_index;
+                std::string var_name;
+                std::string sub_var_name;
+
+                Var(unsigned int index, std::string var_name,
+                        type* model, int sub_index, std::string sub_var_name)
+                        :
+                        index(index), model(model), sub_index(sub_index),
+                        var_name(var_name), sub_var_name(sub_var_name) { }
+            };
+
+            AbstractCoupledModel(const type* parent = 0)
+                    :type(parent)
+            {
 #ifdef WITH_TRACE
-        utils::Trace < utils::DoubleTime >::trace()
-            << utils::TraceElement < utils::DoubleTime >(
-                true,
-                boost::core::demangle(typeid(T).name()),
-                utils::DoubleTime::null,
-                utils::CONSTRUCT);
-        utils::Trace < utils::DoubleTime >::trace().flush();
+                utils::Trace<utils::DoubleTime>::trace()
+                        << utils::TraceElement<utils::DoubleTime>(
+                                true,
+                                boost::core::demangle(typeid(T).name()),
+                                utils::DoubleTime::null,
+                                utils::CONSTRUCT);
+                utils::Trace<utils::DoubleTime>::trace().flush();
 #endif
-    }
+            }
 
-    virtual ~AbstractCoupledModel()
-    {
+            virtual ~AbstractCoupledModel()
+            {
 #ifdef WITH_TRACE
-        trace_element(true, utils::DoubleTime::null,
-                      utils::DESTRUCT);
+                trace_element(true, utils::DoubleTime::null,
+                        utils::DESTRUCT);
 #endif
-    }
+            }
 
-    virtual void after(typename U::type t)
-    {
+            virtual void after(typename U::type t)
+            {
 
 #ifdef WITH_TRACE
-        trace_element(true, t, utils::AFTER_COMPUTE);
-        trace_internals(true, t, utils::AFTER_COMPUTE);
+                trace_element(true, t, utils::AFTER_COMPUTE);
+                trace_internals(true, t, utils::AFTER_COMPUTE);
 #else
-        (void) t;
+                (void) t;
 #endif
 
-    }
+            }
 
-    virtual const Node < U >* atomic(unsigned int index) const
-    {
-        typename AbstractCoupledModel::SubModelInternals::const_iterator it =
-            submodel_internals.find(index);
+            virtual const Node<U>* atomic(unsigned int index) const
+            {
+                typename AbstractCoupledModel::SubModelInternals::const_iterator it =
+                        submodel_internals.find(index);
 
-        if (it == submodel_internals.end()) {
-            return this;
-        } else {
-            return it->second.first->atomic(it->second.second);
-        }
-    }
+                if (it == submodel_internals.end()) {
+                    return this;
+                } else {
+                    return it->second.first->atomic(it->second.second);
+                }
+            }
 
-    virtual void before(typename U::type t)
-    {
+            virtual void before(typename U::type t)
+            {
 
 #ifdef WITH_TRACE
-        trace_element(true, t, utils::BEFORE_COMPUTE);
-        trace_internals(true, t, utils::BEFORE_COMPUTE);
-        trace_externals(true, t, utils::BEFORE_COMPUTE);
+                trace_element(true, t, utils::BEFORE_COMPUTE);
+                trace_internals(true, t, utils::BEFORE_COMPUTE);
+                trace_externals(true, t, utils::BEFORE_COMPUTE);
 #else
-        (void) t;
+                (void) t;
 #endif
 
-    }
+            }
 
-    virtual void build(W& /* parameters */)
-    { }
+            virtual void build(W& /* parameters */) { }
 
-    virtual void build(W& /* parameters */, const std::string& /* json */)
-    { }
+            virtual void build(W& /* parameters */, const std::string& /* json */) { }
 
-    virtual bool check(typename U::type t) const
-    { return Externals < T, U, V >::check(t); }
+            virtual bool check(typename U::type t) const { return Externals<T, U, V>::check(t); }
 
-    virtual void compute(typename U::type t, bool update) = 0;
+            virtual void compute(typename U::type t, bool update) = 0;
 
-    virtual const Any& get(typename U::type t, unsigned int index) const
-    {
-        typename AbstractCoupledModel::SubModelInternals::const_iterator it =
-            submodel_internals.find(index);
+            virtual const Any& get(typename U::type t, unsigned int index) const
+            {
+                typename AbstractCoupledModel::SubModelInternals::const_iterator it =
+                        submodel_internals.find(index);
 
-        if (it == submodel_internals.end()) {
-            if (type::last_time != t) {
-                throw utils::InvalidGet("Variable not computed");
+                if (it == submodel_internals.end()) {
+                    if (type::last_time != t) {
+                        throw utils::InvalidGet("Variable not computed");
+                    }
+                    return Internals<T, U, V>::get(index);
+                } else {
+                    return it->second.first->get(t, it->second.second);
+                }
             }
-            return Internals < T, U, V >::get(index);
-        } else {
-            return it->second.first->get(t, it->second.second);
-        }
-    }
 
-    template < typename Z, typename K >
-    Z get(typename U::type t, unsigned int index) const
-    {
-        typename AbstractCoupledModel::SubModelInternals::const_iterator it =
-            submodel_internals.find(index);
+            template<typename Z, typename K>
+            Z get(typename U::type t, unsigned int index) const
+            {
+                typename AbstractCoupledModel::SubModelInternals::const_iterator it =
+                        submodel_internals.find(index);
+
+                if (it == submodel_internals.end()) {
+                    if (type::last_time != t) {
+                        throw utils::InvalidGet("Variable not computed");
+                    }
+                    const Any& value = Internals<T, U, V>::get(index);
+
+                    return static_cast < const T* >(this)->*(value.get<T, Z>());
+                } else {
+                    const Any& value = it->second.first->get(t, it->second.second);
+                    const Node<U>* object = it->second.first->atomic(
+                            it->second.second);
+
+                    return static_cast < const K* >(object)->*(value.get<K, Z>());
+                }
+            }
 
-        if (it == submodel_internals.end()) {
-            if (type::last_time != t) {
-                throw utils::InvalidGet("Variable not computed");
+            virtual std::string get(const ValueTypeID& value_type, typename U::type t,
+                    unsigned int index) const
+            {
+                typename AbstractCoupledModel::SubModelInternals::const_iterator it =
+                        submodel_internals.find(index);
+
+                if (it == submodel_internals.end()) {
+                    Any value = Internals<T, U, V>::get(index);
+
+                    switch (value_type) {
+                    case DOUBLE:
+                        return std::to_string(
+                                static_cast < const T* >(this)->*(value.get<T,
+                                        double>()));
+                    case INT:
+                        return std::to_string(
+                                static_cast < const T* >(this)->*(value.get<T, int>()));
+                    case BOOL:
+                        return std::to_string(
+                                static_cast < const T* >(this)->*(value.get<T, bool>()));
+                    default:
+                        return "NA";
+                    }
+                } else {
+                    return it->second.first->get(value_type, t, it->second.second);
+                }
             }
-            const Any& value = Internals < T, U, V >::get(index);
 
-            return static_cast < const T* >(this)->*(value.get < T, Z >());
-        } else {
-            const Any& value = it->second.first->get(t, it->second.second);
-            const Node < U >* object = it->second.first->atomic(
-                it->second.second);
+            virtual void init(typename U::type t, const V& parameters) = 0;
 
-            return static_cast < const K* >(object)->*(value.get < K, Z >());
-        }
-    }
+            virtual bool is_atomic() const { return false; }
 
-    virtual std::string get(const ValueTypeID& value_type, typename U::type t,
-                            unsigned int index) const
-    {
-        typename AbstractCoupledModel::SubModelInternals::const_iterator it =
-            submodel_internals.find(index);
-
-        if (it == submodel_internals.end()) {
-            Any value = Internals < T, U, V >::get(index);
-
-            switch (value_type) {
-            case DOUBLE:
-                return std::to_string(
-                    static_cast < const T* >(this)->*(value.get < T,
-                                                      double >()));
-            case INT:
-                return std::to_string(
-                    static_cast < const T* >(this)->*(value.get < T, int >()));
-            case BOOL:
-                return std::to_string(
-                    static_cast < const T* >(this)->*(value.get < T, bool >()));
-            default: return "NA";
+            bool is_computed(typename U::type t, unsigned int index) const
+            {
+                typename AbstractCoupledModel::SubModelInternals::const_iterator it =
+                        submodel_internals.find(index);
+
+                if (it == submodel_internals.end()) {
+                    return false;
+                } else {
+                    return it->second.first->is_computed(t, it->second.second);
+                }
             }
-        } else {
-            return it->second.first->get(value_type, t, it->second.second);
-        }
-    }
 
-    virtual void init(typename U::type t, const V& parameters) = 0;
+            bool is_stable(typename U::type t) const
+            {
+                typename AbstractCoupledModel::SubModelInternals::const_iterator it =
+                        submodel_internals.begin();
+                bool stable = true;
 
-    virtual bool is_atomic() const
-    { return false; }
+                while (it != submodel_internals.end() and stable) {
+                    stable = it->second.first->is_stable(t);
+                    ++it;
+                }
+                return stable;
+            }
 
-    bool is_computed(typename U::type t, unsigned int index) const
-    {
-        typename AbstractCoupledModel::SubModelInternals::const_iterator it =
-            submodel_internals.find(index);
+            virtual bool is_updated() const { return Externals<T, U, V>::updated; }
 
-        if (it == submodel_internals.end()) {
-            return false;
-        } else {
-            return it->second.first->is_computed(t, it->second.second);
-        }
-    }
+            virtual const Node<U>* get_submodel(unsigned int index) const
+            {
+                typename AbstractCoupledModel::Submodels::const_iterator it =
+                        submodels.find(index);
 
-    bool is_stable(typename U::type t) const
-    {
-        typename AbstractCoupledModel::SubModelInternals::const_iterator it =
-            submodel_internals.begin();
-        bool stable = true;
-
-        while (it != submodel_internals.end() and stable) {
-            stable = it->second.first->is_stable(t);
-            ++it;
-        }
-        return stable;
-    }
+                if (it != submodels.end()) {
+                    return it->second;
+                } else {
+                    return 0;
+                }
+            }
 
-    virtual bool is_updated() const
-    { return Externals < T, U, V >::updated; }
+            virtual const Node<U>* get_submodel(unsigned int index,
+                    unsigned int rank) const
+            {
+                typename AbstractCoupledModel::Setsubmodels::const_iterator it =
+                        setsubmodels.find(index);
 
-    virtual const Node < U >* get_submodel(unsigned int index) const
-    {
-        typename AbstractCoupledModel::Submodels::const_iterator it =
-            submodels.find(index);
+                if (it != setsubmodels.end() and it->second.size() > rank) {
+                    return it->second.at(rank);
+                } else {
+                    return 0;
+                }
+            }
 
-        if (it != submodels.end()) {
-            return it->second;
-        } else {
-            return 0;
-        }
-    }
+            virtual std::string path_index(const AbstractModel<U, V>* child,
+                    int& index) const
+            {
+                typename Setsubmodels::const_iterator it = setsubmodels.begin();
+                bool found = false;
+
+                index = -1;
+                while (not found and it != setsubmodels.end()) {
+                    typename std::vector<type*>::const_iterator itm =
+                            it->second.begin();
+
+                    index = 0;
+                    while (not found and itm != it->second.end()) {
+                        found = *itm == child;
+                        if (not found) {
+                            ++index;
+                            ++itm;
+                        }
+                    }
+                    index = found ? index : -1;
+                    ++it;
+                }
+                if (type::parent) {
+                    int i;
+                    std::string p = type::parent->path_index(this, i);
+
+                    if (i >= 0) {
+                        return p +
+                                "/[" + std::to_string(i) + "]" +
+                                boost::core::demangle(typeid(*this).name());
+                    } else {
+                        return p + "/" + boost::core::demangle(typeid(*this).name());
+                    }
+                } else {
+                    return boost::core::demangle(typeid(*this).name());
+                }
+            }
 
-    virtual const Node < U >* get_submodel(unsigned int index,
-                                           unsigned int rank) const
-    {
-        typename AbstractCoupledModel::Setsubmodels::const_iterator it =
-            setsubmodels.find(index);
-
-        if (it != setsubmodels.end() and it->second.size() > rank) {
-            return it->second.at(rank);
-        } else {
-            return 0;
-        }
-    }
+            virtual void restore(const context::State<U>& state)
+            {
+                typename AbstractCoupledModel::Submodels::const_iterator it =
+                        submodels.begin();
 
-    virtual std::string path_index(const AbstractModel < U, V >* child,
-                                   int& index) const
-    {
-        typename Setsubmodels::const_iterator it = setsubmodels.begin();
-        bool found = false;
-
-        index = -1;
-        while (not found and it != setsubmodels.end()) {
-            typename std::vector < type* >::const_iterator itm =
-                it->second.begin();
-
-            index = 0;
-            while (not found and itm != it->second.end()) {
-                found = *itm == child;
-                if (not found) {
-                    ++index;
-                    ++itm;
+                while (it != submodels.end()) {
+                    it->second->restore(state.get_substate(it->first));
+                    ++it;
                 }
+                States<T, U, V>::restore(this, state);
+                Internals<T, U, V>::restore(this, state);
+                Externals<T, U, V>::restore(this, state);
             }
-            index = found ? index : -1;
-            ++it;
-        }
-        if (type::parent) {
-            int i;
-            std::string p = type::parent->path_index(this, i);
-
-            if (i >= 0) {
-                return p +
-                    "/[" + std::to_string(i) + "]" +
-                    boost::core::demangle(typeid(*this).name());
-            } else {
-                return p + "/" + boost::core::demangle(typeid(*this).name());
-            }
-        } else {
-            return boost::core::demangle(typeid(*this).name());
-        }
-    }
 
-    virtual void restore(const context::State < U >& state)
-    {
-        typename AbstractCoupledModel::Submodels::const_iterator it =
-            submodels.begin();
-
-        while (it != submodels.end()) {
-            it->second->restore(state.get_substate(it->first));
-            ++it;
-        }
-        States < T, U, V >::restore(this, state);
-        Internals < T, U, V >::restore(this, state);
-        Externals < T, U, V >::restore(this, state);
-    }
+            virtual void save(context::State<U>& state) const
+            {
+                typename AbstractCoupledModel::Submodels::const_iterator it =
+                        submodels.begin();
 
-    virtual void save(context::State < U >& state) const
-    {
-        typename AbstractCoupledModel::Submodels::const_iterator it =
-            submodels.begin();
-
-        while (it != submodels.end()) {
-            context::State < U > substate;
-
-            it->second->save(substate);
-            state.add_substate(it->first, substate);
-            ++it;
-        }
-        States < T, U, V >::save(this, state);
-        Internals < T, U, V >::save(this, state);
-        Externals < T, U, V >::save(this, state);
-    }
+                while (it != submodels.end()) {
+                    context::State<U> substate;
 
-    virtual void stable()
-    { Externals < T, U, V >::updated = false; }
-
-    void submodel(unsigned int index, type* model)
-    {
-        if (model) {
-            submodels[index] = model;
-            model->set_parent(this);
-        } else {
-            submodels[index] = 0;
-        }
-    }
+                    it->second->save(substate);
+                    state.add_substate(it->first, substate);
+                    ++it;
+                }
+                States<T, U, V>::save(this, state);
+                Internals<T, U, V>::save(this, state);
+                Externals<T, U, V>::save(this, state);
+            }
 
-    virtual void trace_element(typename U::type t,
-                               utils::TraceType type = utils::NONE,
-                               std::string comment = "") const
-    { trace_element(false, t, type, comment); }
-
-    virtual void trace_internals(typename U::type t,
-                                 utils::TraceType type) const
-    { trace_internals(false, t, type); }
-
-    virtual void trace_externals(typename U::type t,
-                                 utils::TraceType type = utils::NONE) const
-    { trace_externals(false, t, type); }
-
-    virtual void trace_model(typename U::type t,
-                             utils::TraceType type = utils::NONE) const
-    { trace_model(false, t, type); }
-
-private:
-    void trace_element(bool from_kernel, typename U::type t,
-                       utils::TraceType type = utils::NONE,
-                       std::string comment = "") const
-    {
-        utils::Trace < utils::DoubleTime >::trace()
-            << utils::TraceElement < utils::DoubleTime >(
-                from_kernel,
-                AbstractCoupledModel < T, U, V, W >::path(this),
-                t, type)
-            << comment;
-        utils::Trace < utils::DoubleTime >::trace().flush();
-    }
+            virtual void stable() { Externals<T, U, V>::updated = false; }
 
-    void trace_internals(bool from_kernel, typename U::type t,
-                         utils::TraceType type) const
-    {
-        for (size_t i = 0; i < Internals < T, U, V >::size(); ++i) {
-            if (not Internals < T, U, V >::get(i).is_null()) {
-                utils::Trace < utils::DoubleTime >::trace()
-                    << utils::TraceElement < utils::DoubleTime >(
-                        from_kernel,
-                        AbstractCoupledModel < T, U, V, W >::path(this),
-                        t, type)
-                    << utils::KernelInfo(
-                        Internals < T, U, V >::name(i), true,
-                        Internals < T, U, V >::get(i).to_string(
-                            dynamic_cast < const T* >(this))
-                        );
-                utils::Trace < utils::DoubleTime >::trace().flush();
+            void submodel(unsigned int index, type* model)
+            {
+                if (model) {
+                    submodels[index] = model;
+                    model->set_parent(this);
+                } else {
+                    submodels[index] = 0;
+                }
             }
-        }
-    }
 
-    void trace_externals(bool from_kernel, typename U::type t,
-                         utils::TraceType type = utils::NONE) const
-    {
-        for (size_t i = 0; i < Externals < T, U, V >::size(); ++i) {
-            if (not Externals < T, U, V >::get(i).is_null()) {
-                utils::Trace < utils::DoubleTime >::trace()
-                    << utils::TraceElement < utils::DoubleTime >(
-                        from_kernel,
-                        AbstractCoupledModel < T, U, V, W >::path(this),
-                        t, type)
-                    << utils::KernelInfo(
-                        Externals < T, U, V >::name(i), false,
-                        Externals < T, U, V >::get(i).to_string(
-                            dynamic_cast < const T* >(this))
-                        );
-                utils::Trace < utils::DoubleTime >::trace().flush();
+            virtual void trace_element(typename U::type t,
+                    utils::TraceType type = utils::NONE,
+                    std::string comment = "") const { trace_element(false, t, type, comment); }
+
+            virtual void trace_internals(typename U::type t,
+                    utils::TraceType type) const { trace_internals(false, t, type); }
+
+            virtual void trace_externals(typename U::type t,
+                    utils::TraceType type = utils::NONE) const { trace_externals(false, t, type); }
+
+            virtual void trace_model(typename U::type t,
+                    utils::TraceType type = utils::NONE) const { trace_model(false, t, type); }
+
+        private:
+            void trace_element(bool from_kernel, typename U::type t,
+                    utils::TraceType type = utils::NONE,
+                    std::string comment = "") const
+            {
+                utils::Trace<utils::DoubleTime>::trace()
+                        << utils::TraceElement<utils::DoubleTime>(
+                                from_kernel,
+                                AbstractCoupledModel<T, U, V, W>::path(this),
+                                t, type)
+                        << comment;
+                utils::Trace<utils::DoubleTime>::trace().flush();
             }
-        }
-    }
 
-    void trace_model(bool from_kernel, typename U::type t,
-                     utils::TraceType type = utils::NONE) const
-    {
-        trace_element(from_kernel, t, type);
-        trace_internals(from_kernel, t, type);
-        trace_externals(from_kernel, t, type);
+            void trace_internals(bool from_kernel, typename U::type t,
+                    utils::TraceType type) const
+            {
+                for (size_t i = 0; i < Internals<T, U, V>::size(); ++i) {
+                    if (not Internals<T, U, V>::get(i).is_null()) {
+                        utils::Trace<utils::DoubleTime>::trace()
+                                << utils::TraceElement<utils::DoubleTime>(
+                                        from_kernel,
+                                        AbstractCoupledModel<T, U, V, W>::path(this),
+                                        t, type)
+                                << utils::KernelInfo(
+                                        Internals<T, U, V>::name(i), true,
+                                        Internals<T, U, V>::get(i).to_string(
+                                                dynamic_cast < const T* >(this))
+                                );
+                        utils::Trace<utils::DoubleTime>::trace().flush();
+                    }
+                }
+            }
 
-        // typename AbstractCoupledModel::Submodels::const_iterator it =
-        //     submodels.begin();
+            void trace_externals(bool from_kernel, typename U::type t,
+                    utils::TraceType type = utils::NONE) const
+            {
+                for (size_t i = 0; i < Externals<T, U, V>::size(); ++i) {
+                    if (not Externals<T, U, V>::get(i).is_null()) {
+                        utils::Trace<utils::DoubleTime>::trace()
+                                << utils::TraceElement<utils::DoubleTime>(
+                                        from_kernel,
+                                        AbstractCoupledModel<T, U, V, W>::path(this),
+                                        t, type)
+                                << utils::KernelInfo(
+                                        Externals<T, U, V>::name(i), false,
+                                        Externals<T, U, V>::get(i).to_string(
+                                                dynamic_cast < const T* >(this))
+                                );
+                        utils::Trace<utils::DoubleTime>::trace().flush();
+                    }
+                }
+            }
 
-        // while (it != submodels.end()) {
-        //     it->second->trace_model(from_kernel, t, type);
-        //     ++it;
-        // }
-    }
+            void trace_model(bool from_kernel, typename U::type t,
+                    utils::TraceType type = utils::NONE) const
+            {
+                trace_element(from_kernel, t, type);
+                trace_internals(from_kernel, t, type);
+                trace_externals(from_kernel, t, type);
 
-protected:
-    void link_internal_(unsigned int index, std::string var_name,
-                        type* model, int sub_index, std::string sub_var_name)
-    {
-        submodel_internals[index] =
-            std::pair < type*, int >(model, sub_index);
+                // typename AbstractCoupledModel::Submodels::const_iterator it =
+                //     submodels.begin();
+
+                // while (it != submodels.end()) {
+                //     it->second->trace_model(from_kernel, t, type);
+                //     ++it;
+                // }
+            }
+
+        protected:
+            void link_internal_(unsigned int index, std::string var_name,
+                    type* model, int sub_index, std::string sub_var_name)
+            {
+                submodel_internals[index] =
+                        std::pair<type*, int>(model, sub_index);
 #ifdef WITH_TRACE
-        utils::Trace < utils::DoubleTime >::trace()
-            << utils::TraceElement < utils::DoubleTime >(
-                true,
-                AbstractCoupledModel < T, U, V, W >::path(this),
-                utils::DoubleTime::null,
-                utils::INTERNAL_LINK)
-            << utils::KernelInfo(
-                var_name,
-                AbstractCoupledModel < T, U, V, W >::path(model),
-                sub_var_name);
-        utils::Trace < utils::DoubleTime >::trace().flush();
+                utils::Trace<utils::DoubleTime>::trace()
+                        << utils::TraceElement<utils::DoubleTime>(
+                                true,
+                                AbstractCoupledModel<T, U, V, W>::path(this),
+                                utils::DoubleTime::null,
+                                utils::INTERNAL_LINK)
+                        << utils::KernelInfo(
+                                var_name,
+                                AbstractCoupledModel<T, U, V, W>::path(model),
+                                sub_var_name);
+                utils::Trace<utils::DoubleTime>::trace().flush();
 
 #endif
-    }
+            }
 
-    void I_(std::initializer_list < Var > internals)
-    {
-        for (typename std::initializer_list < Var >::iterator it =
-                 internals.begin(); it != internals.end(); ++it) {
+            void I_(std::initializer_list<Var> internals)
+            {
+                for (typename std::initializer_list<Var>::iterator it =
+                        internals.begin(); it != internals.end(); ++it) {
 
-            submodel_internals[it->index] =
-                std::pair < type*, int >(it->model, it->sub_index);
+                    submodel_internals[it->index] =
+                            std::pair<type*, int>(it->model, it->sub_index);
 
 #ifdef WITH_TRACE
-            utils::Trace < utils::DoubleTime >::trace()
-                << utils::TraceElement < utils::DoubleTime >(
-                    true,
-                    AbstractCoupledModel < T, U, V, W >::path(this),
-                    utils::DoubleTime::null,
-                    utils::INTERNAL_LINK)
-                << utils::KernelInfo(
-                    it->var_name,
-                    AbstractCoupledModel < T, U, V, W >::path(it->model),
-                    it->sub_var_name);
-            utils::Trace < utils::DoubleTime >::trace().flush();
+                    utils::Trace<utils::DoubleTime>::trace()
+                            << utils::TraceElement<utils::DoubleTime>(
+                                    true,
+                                    AbstractCoupledModel<T, U, V, W>::path(this),
+                                    utils::DoubleTime::null,
+                                    utils::INTERNAL_LINK)
+                            << utils::KernelInfo(
+                                    it->var_name,
+                                    AbstractCoupledModel<T, U, V, W>::path(it->model),
+                                    it->sub_var_name);
+                    utils::Trace<utils::DoubleTime>::trace().flush();
 #endif
-        }
-    }
+                }
+            }
 
-    void SM_(std::initializer_list < std::pair <  unsigned int,
-             type* > > models)
-    {
-        for (typename std::initializer_list < std::pair <  unsigned int,
-                 type* > >::iterator it =
-                 models.begin(); it != models.end(); ++it) {
-            submodels[it->first] = it->second;
-            it->second->set_parent(this);
+            void SM_(std::initializer_list<std::pair<unsigned int,
+                    type*> > models)
+            {
+                for (typename std::initializer_list<std::pair<unsigned int,
+                        type*> >::iterator it =
+                        models.begin(); it != models.end(); ++it) {
+                    submodels[it->first] = it->second;
+                    it->second->set_parent(this);
 
 #ifdef WITH_TRACE
-            utils::Trace < utils::DoubleTime >::trace()
-                << utils::TraceElement < utils::DoubleTime >(
-                    true,
-                    AbstractCoupledModel < T, U, V, W >::path(this),
-                    utils::DoubleTime::null,
-                    utils::SUBMODEL_ADD)
-                << utils::KernelInfo(
-                    AbstractCoupledModel < T, U, V, W >::path(it->second));
-            utils::Trace < utils::DoubleTime >::trace().flush();
+                    utils::Trace<utils::DoubleTime>::trace()
+                            << utils::TraceElement<utils::DoubleTime>(
+                                    true,
+                                    AbstractCoupledModel<T, U, V, W>::path(this),
+                                    utils::DoubleTime::null,
+                                    utils::SUBMODEL_ADD)
+                            << utils::KernelInfo(
+                                    AbstractCoupledModel<T, U, V, W>::path(it->second));
+                    utils::Trace<utils::DoubleTime>::trace().flush();
 #endif
 
-        }
-    }
+                }
+            }
 
-    void setsubmodel(unsigned int index, type* model)
-    {
-        if (setsubmodels.find(index) == setsubmodels.end()) {
-            setsubmodels[index] = std::vector < type* >();
-        }
-        setsubmodels[index].push_back(model);
-        model->set_parent(this);
+            void setsubmodel(unsigned int index, type* model)
+            {
+                if (setsubmodels.find(index) == setsubmodels.end()) {
+                    setsubmodels[index] = std::vector<type*>();
+                }
+                setsubmodels[index].push_back(model);
+                model->set_parent(this);
 
 #ifdef WITH_TRACE
-        utils::Trace < utils::DoubleTime >::trace()
-            << utils::TraceElement < utils::DoubleTime >(
-                true,
-                AbstractCoupledModel < T, U, V, W >::path(this),
-                utils::DoubleTime::null,
-                utils::SUBMODEL_ADD)
-            << utils::KernelInfo(
-                AbstractCoupledModel < T, U, V, W >::path(model));
-        utils::Trace < utils::DoubleTime >::trace().flush();
+                utils::Trace<utils::DoubleTime>::trace()
+                        << utils::TraceElement<utils::DoubleTime>(
+                                true,
+                                AbstractCoupledModel<T, U, V, W>::path(this),
+                                utils::DoubleTime::null,
+                                utils::SUBMODEL_ADD)
+                        << utils::KernelInfo(
+                                AbstractCoupledModel<T, U, V, W>::path(model));
+                utils::Trace<utils::DoubleTime>::trace().flush();
 #endif
-    }
-
-private:
-    SubModelInternals submodel_internals;
-    Submodels submodels;
-    Setsubmodels setsubmodels;
-};
+            }
 
+        private:
+            SubModelInternals submodel_internals;
+            Submodels submodels;
+            Setsubmodels setsubmodels;
+        };
 
 #define InternalS(index, var, sub_index) link_internal_(index, std::string(ESCAPEQUOTE(index)), var, sub_index, std::string(ESCAPEQUOTE(index)))
 #define ITEM_S(index, var, sub_index) Var(index, std::string(ESCAPEQUOTE(index)), var, sub_index, std::string(ESCAPEQUOTE(index)))
@@ -587,6 +579,7 @@ private:
 #define Submodels(L) SM_(UNWRAP_Sub_2 L)
 
 
-} }
+    }
+}
 
 #endif

+ 106 - 106
src/artis/kernel/AbstractModel.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -23,7 +23,6 @@
 #ifndef __ARTIS_KERNEL_ABSTRACT_MODEL_HPP
 #define __ARTIS_KERNEL_ABSTRACT_MODEL_HPP
 
-
 #include <artis/kernel/Node.hpp>
 #include <artis/context/State.hpp>
 #include <artis/utils/DoubleTime.hpp>
@@ -32,132 +31,133 @@
 #include <boost/core/demangle.hpp>
 
 #include <typeinfo>
+
 #if WIN32
 #include <iso646.h>
 #endif
 
-namespace artis { namespace kernel {
+namespace artis {
+    namespace kernel {
 
-template < typename Time, typename Parameters >
-class AbstractModel : public Node < Time >
-{
-    typedef AbstractModel < Time, Parameters > type;
+        template<typename Time, typename Parameters>
+        class AbstractModel : public Node<Time> {
+            typedef AbstractModel<Time, Parameters> type;
 
-public:
-    AbstractModel(const AbstractModel < Time, Parameters >* parent = 0) :
-        parent(parent), last_time(-1)
-    { }
+        public:
+            AbstractModel(const AbstractModel<Time, Parameters>* parent = 0)
+                    :
+                    parent(parent), last_time(-1) { }
 
-    virtual ~AbstractModel()
-    { }
+            virtual ~AbstractModel() { }
 
-    virtual void after(typename Time::type t) = 0;
+            virtual void after(typename Time::type t) = 0;
 
-    virtual const Node < Time >* atomic(unsigned int index) const = 0;
+            virtual const Node<Time>* atomic(unsigned int index) const = 0;
 
-    virtual void before(typename Time::type t) = 0;
+            virtual void before(typename Time::type t) = 0;
 
-    virtual bool check(typename Time::type /* t */) const
-    { return true; }
+            virtual bool check(typename Time::type /* t */) const { return true; }
 
-    virtual void compute(typename Time::type t, bool update) = 0;
+            virtual void compute(typename Time::type t, bool update) = 0;
 
-    virtual void init(typename Time::type t, const Parameters& parameters) = 0;
+            virtual void init(typename Time::type t, const Parameters& parameters) = 0;
 
-    virtual bool is_atomic() const = 0;
+            virtual bool is_atomic() const = 0;
 
-    virtual bool is_computed(typename Time::type t) const
-    { return last_time == t; }
+            virtual bool is_computed(typename Time::type t) const { return last_time == t; }
 
-    virtual bool is_stable(typename Time::type t) const = 0;
+            virtual bool is_stable(typename Time::type t) const = 0;
 
-    virtual bool is_computed(typename Time::type t,
-                             unsigned int index) const = 0;
+            virtual bool is_computed(typename Time::type t,
+                    unsigned int index) const = 0;
 
-    virtual bool is_updated() const = 0;
+            virtual bool is_updated() const = 0;
 
-    virtual void operator()(typename Time::type t)
-    {
-        before(t);
-        if (check(t) and (last_time != t or
-                          (last_time == t and is_updated()))) {
+            virtual void operator()(typename Time::type t)
+            {
+                before(t);
+                if (check(t) and (last_time != t or
+                        (last_time == t and is_updated()))) {
 #ifdef WITH_TRACE
-            utils::Trace < utils::DoubleTime >::trace()
-                << utils::TraceElement < utils::DoubleTime >(
-                    true,
-                    AbstractModel < Time, Parameters >::path(this),
-                    t, utils::COMPUTE);
-            utils::Trace < utils::DoubleTime >::trace().flush();
+                    utils::Trace<utils::DoubleTime>::trace()
+                            << utils::TraceElement<utils::DoubleTime>(
+                                    true,
+                                    AbstractModel<Time, Parameters>::path(this),
+                                    t, utils::COMPUTE);
+                    utils::Trace<utils::DoubleTime>::trace().flush();
 #endif
-            compute(t, last_time == t);
-            last_time = t;
-            stable();
-        }
-        after(t);
-    }
+                    compute(t, last_time == t);
+                    last_time = t;
+                    stable();
+                }
+                after(t);
+            }
+
+            virtual std::string path(
+                    const AbstractModel<Time, Parameters>* child) const
+            {
+                int index = -1;
+                std::string p = type::parent ? type::parent->path_index(child, index) :
+                                "";
+
+                if (index >= 0) {
+                    return p +
+                            "/[" + std::to_string(index) + "]" +
+                            boost::core::demangle(typeid(*child).name()); // .erase(0,6);
+                } else {
+                    return (p.empty() ? "" : p + "/") +
+                            boost::core::demangle(typeid(*child).name()); // .erase(0,6);
+                }
+            }
+
+            virtual std::string path_index(
+                    const AbstractModel<Time, Parameters>* child, int& index) const
+            {
+                (void) child;
+                int i = -1;
+                std::string p = type::parent ? type::parent->path_index(this, index) :
+                                "";
+
+                index = -1;
+                if (i >= 0) {
+                    return p +
+                            "/[" + std::to_string(i) + "]" +
+                            boost::core::demangle(typeid(*this).name());
+                } else {
+                    return (p.empty() ? "" : p + "/") +
+                            boost::core::demangle(typeid(*this).name());
+                }
+            }
+
+            virtual void restore(const context::State<Time>& state) = 0;
+
+            virtual void save(context::State<Time>& state) const = 0;
+
+            virtual void trace_element(typename Time::type t, utils::TraceType type,
+                    std::string comment = "") const = 0;
+
+            virtual void trace_internals(typename Time::type t,
+                    utils::TraceType type) const = 0;
+
+            virtual void trace_externals(typename Time::type t,
+                    utils::TraceType type) const = 0;
+
+            virtual void trace_model(typename Time::type t,
+                    utils::TraceType type) const = 0;
+
+            void set_parent(const AbstractModel<Time, Parameters>* p) { parent = p; }
+
+            virtual void stable() = 0;
+
+        protected:
+            const AbstractModel<Time, Parameters>* parent;
+            typename Time::type last_time;
+        };
+
+        template<typename Time, typename Parameters>
+        using AbstractModels = std::vector<AbstractModel<Time, Parameters>*>;
 
-    virtual std::string path(
-        const AbstractModel < Time, Parameters >* child) const
-    {
-        int index = -1;
-        std::string p = type::parent ? type::parent->path_index(child, index) :
-            "";
-
-        if (index >= 0) {
-            return p +
-                "/[" + std::to_string(index) + "]" +
-                boost::core::demangle(typeid(*child).name()); // .erase(0,6);
-        } else {
-            return (p.empty() ? "" : p + "/") +
-                boost::core::demangle(typeid(*child).name()); // .erase(0,6);
-        }
     }
-
-    virtual std::string path_index(
-        const AbstractModel < Time, Parameters >* child, int& index) const
-    {
-        (void) child;
-        int i = -1;
-        std::string p = type::parent ? type::parent->path_index(this, index) :
-            "";
-
-        index = -1;
-        if (i >= 0) {
-            return p +
-                "/[" + std::to_string(i) + "]" +
-                boost::core::demangle(typeid(*this).name());
-        } else {
-            return (p.empty() ? "" : p + "/") +
-                boost::core::demangle(typeid(*this).name());
-        }
-    }
-
-    virtual void restore(const context::State < Time >& state) = 0;
-
-    virtual void save(context::State < Time >& state) const = 0;
-
-    virtual void trace_element(typename Time::type t, utils::TraceType type,
-                               std::string comment = "") const = 0;
-    virtual void trace_internals(typename Time::type t,
-                                 utils::TraceType type) const = 0;
-    virtual void trace_externals(typename Time::type t,
-                                 utils::TraceType type) const = 0;
-    virtual void trace_model(typename Time::type t,
-                             utils::TraceType type) const = 0;
-
-    void set_parent(const AbstractModel < Time, Parameters >* p)
-    { parent = p; }
-
-    virtual void stable() = 0;
-
-protected:
-    const AbstractModel < Time, Parameters >* parent;
-    typename Time::type                       last_time;
-};
-
-template < typename Time, typename Parameters >
-using AbstractModels = std::vector < AbstractModel < Time, Parameters >* >;
-
-} }
+}
 
 #endif

+ 5 - 3
src/artis/kernel/Any.cpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -22,7 +22,8 @@
 
 #include <artis/kernel/Any.hpp>
 
-namespace artis { namespace kernel {
+namespace artis {
+    namespace kernel {
 
 // context::Value find_not_null_value::operator()(
 //     const context::Value& left,
@@ -37,4 +38,5 @@ namespace artis { namespace kernel {
 //     }
 // }
 
-} }
+    }
+}

+ 162 - 165
src/artis/kernel/Any.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -30,10 +30,13 @@
 #include <utility>
 #include <vector>
 
-namespace artis { namespace kernel {
+namespace artis {
+    namespace kernel {
 
-enum ValueTypeID { DOUBLE, INT, BOOL, DOUBLE_VECTOR, INT_VECTOR, BOOL_VECTOR,
-                   STRING, USER };
+        enum ValueTypeID {
+            DOUBLE, INT, BOOL, DOUBLE_VECTOR, INT_VECTOR, BOOL_VECTOR,
+            STRING, USER
+        };
 
 // template < typename H, typename T >
 // struct typelist
@@ -74,213 +77,206 @@ enum ValueTypeID { DOUBLE, INT, BOOL, DOUBLE_VECTOR, INT_VECTOR, BOOL_VECTOR,
 
 // typedef TYPELIST((double, int, bool)) value_types;
 
-class Any
-{
-private:
-    struct base
-    {
-        virtual ~base() { }
-        virtual base* clone() const = 0;
-    };
+        class Any {
+        private:
+            struct base {
+                virtual ~base() { }
 
-    template < typename T, typename V >
-    struct data : base
-    {
-        data(V T::* const& value) : value_(value)
-        { }
+                virtual base* clone() const = 0;
+            };
 
-        base* clone() const { return new data < T, V >(*this); }
+            template<typename T, typename V>
+            struct data : base {
+                data(V T::* const& value)
+                        :value_(value) { }
 
-        V T::* value_;
-    };
+                base* clone() const { return new data<T, V>(*this); }
 
-    base* ptr_;
+                V T::* value_;
+            };
+
+            base* ptr_;
 
 /*    template < typename V >
       friend struct ValueType; */
 
-public:
-    Any() : ptr_(nullptr)
-    { }
-
-    template < typename T, typename V >
-    Any(V T::* const& value) : ptr_(new data < T, V >(value))
-    { }
+        public:
+            Any()
+                    :ptr_(nullptr) { }
 
-    Any(Any const& other) : ptr_(other.ptr_? other.ptr_->clone() : nullptr)
-    { }
+            template<typename T, typename V>
+            Any(V T::* const& value)
+                    : ptr_(new data<T, V>(value)) { }
 
-    virtual ~Any()
-    { if (ptr_) delete ptr_; }
+            Any(Any const& other)
+                    :ptr_(other.ptr_ ? other.ptr_->clone() : nullptr) { }
 
-    void operator=(Any const& other)
-    { Any(other).swap(*this); }
+            virtual ~Any() { if (ptr_) delete ptr_; }
 
-    void swap(Any& other)
-    { std::swap(ptr_, other.ptr_); }
+            void operator=(Any const& other) { Any(other).swap(*this); }
 
-    template < typename T, typename V >
-    V T::* get() const
-    { return dynamic_cast < data < T, V >* >(ptr_)->value_; }
+            void swap(Any& other) { std::swap(ptr_, other.ptr_); }
 
-    bool is_null() const
-    { return ptr_ == nullptr; }
+            template<typename T, typename V>
+            V T::* get() const { return dynamic_cast < data<T, V>* >(ptr_)->value_; }
 
-    template < typename T, typename V >
-    void put(T* o, const V& value )
-    {
-        V T::* p = dynamic_cast <
-            data < T, V >* >(ptr_)->value_;
-        o->*(p) = value;
-    }
+            bool is_null() const { return ptr_ == nullptr; }
 
-    template < typename T >
-    void restore(T* o, const context::Value& value)
-    {
-        if (value.is_type < double >()) {
-            double v;
-
-            value.get_content(v);
-            put(o, v);
-        } else if (value.is_type < int >()) {
-            int v;
-
-            value.get_content(v);
-            put(o, v);
-        } else if (value.is_type < bool >()) {
-            bool v;
-
-            value.get_content(v);
-            put(o, v);
-        } else if (value.is_type < std::vector < double > >()) {
-            std::vector < double > v;
-
-            value.get_content(v);
-            put(o, v);
-        } else if (value.is_type < std::vector < int > >()) {
-            std::vector < int > v;
-
-            value.get_content(v);
-            put(o, v);
-        } else if (value.is_type < std::vector < bool > >()) {
-            std::vector < bool > v;
-
-            value.get_content(v);
-            put(o, v);
-        } else {
-            assert(false);
-        }
-    }
+            template<typename T, typename V>
+            void put(T* o, const V& value)
+            {
+                V T::* p = dynamic_cast <
+                        data<T, V>* >(ptr_)->value_;
+                o->*(p) = value;
+            }
 
-    template < typename T >
-    context::Value save(const T* o) const
-    {
-        if (ptr_) {
-            data < T, double >* q_double =
-                dynamic_cast < data < T, double >* >(ptr_);
-
-            if (q_double) {
-                return context::Value(o->*(q_double->value_));
-            } else {
-                data < T, int >* q_int =
-                    dynamic_cast < data < T, int >* >(ptr_);
-
-                if (q_int) {
-                    return context::Value(o->*(q_int->value_));
+            template<typename T>
+            void restore(T* o, const context::Value& value)
+            {
+                if (value.is_type<double>()) {
+                    double v;
+
+                    value.get_content(v);
+                    put(o, v);
+                } else if (value.is_type<int>()) {
+                    int v;
+
+                    value.get_content(v);
+                    put(o, v);
+                } else if (value.is_type<bool>()) {
+                    bool v;
+
+                    value.get_content(v);
+                    put(o, v);
+                } else if (value.is_type<std::vector<double> >()) {
+                    std::vector<double> v;
+
+                    value.get_content(v);
+                    put(o, v);
+                } else if (value.is_type<std::vector<int> >()) {
+                    std::vector<int> v;
+
+                    value.get_content(v);
+                    put(o, v);
+                } else if (value.is_type<std::vector<bool> >()) {
+                    std::vector<bool> v;
+
+                    value.get_content(v);
+                    put(o, v);
                 } else {
-                    data < T, bool >* q_bool =
-                        dynamic_cast < data < T, bool >* >(ptr_);
+                    assert(false);
+                }
+            }
 
-                    if (q_bool) {
-                        return context::Value(o->*(q_bool->value_));
+            template<typename T>
+            context::Value save(const T* o) const
+            {
+                if (ptr_) {
+                    data<T, double>* q_double =
+                            dynamic_cast < data<T, double>* >(ptr_);
+
+                    if (q_double) {
+                        return context::Value(o->*(q_double->value_));
                     } else {
-                        data < T, std::vector < double > >* q_double_v =
-                            dynamic_cast < data < T, std::vector <
-                                double > >* >(ptr_);
+                        data<T, int>* q_int =
+                                dynamic_cast < data<T, int>* >(ptr_);
 
-                        if (q_double_v) {
-                            return context::Value(o->*(q_double_v->value_));
+                        if (q_int) {
+                            return context::Value(o->*(q_int->value_));
                         } else {
-                            data < T, std::vector < int > >* q_int_v =
-                                dynamic_cast < data < T, std::vector <
-                                    int > >* >(ptr_);
+                            data<T, bool>* q_bool =
+                                    dynamic_cast < data<T, bool>* >(ptr_);
 
-                            if (q_int_v) {
-                                return context::Value(o->*(q_int_v->value_));
+                            if (q_bool) {
+                                return context::Value(o->*(q_bool->value_));
                             } else {
-                                data < T, std::vector < bool > >* q_bool_v =
-                                    dynamic_cast < data < T, std::vector <
-                                        bool > >* >(ptr_);
+                                data<T, std::vector<double> >* q_double_v =
+                                        dynamic_cast < data<T, std::vector<
+                                                double> >* >(ptr_);
 
-                                if (q_bool_v) {
-                                    return context::Value(
-                                        o->*(q_bool_v->value_));
+                                if (q_double_v) {
+                                    return context::Value(o->*(q_double_v->value_));
+                                } else {
+                                    data<T, std::vector<int> >* q_int_v =
+                                            dynamic_cast < data<T, std::vector<
+                                                    int> >* >(ptr_);
+
+                                    if (q_int_v) {
+                                        return context::Value(o->*(q_int_v->value_));
+                                    } else {
+                                        data<T, std::vector<bool> >* q_bool_v =
+                                                dynamic_cast < data<T, std::vector<
+                                                        bool> >* >(ptr_);
+
+                                        if (q_bool_v) {
+                                            return context::Value(
+                                                    o->*(q_bool_v->value_));
+                                        }
+                                    }
                                 }
                             }
                         }
                     }
                 }
+                assert(false);
+                return context::Value();
             }
-        }
-        assert(false);
-        return context::Value();
-    }
 
-    template < typename T >
-    std::string to_string(const T* o) const
-    {
-        if (ptr_) {
-            data < T, double >* q_double =
-                dynamic_cast < data < T, double >* >(ptr_);
-
-            if (q_double) {
-                return std::to_string(o->*(q_double->value_));
-            } else {
-                data < T, int >* q_int =
-                    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_);
+            template<typename T>
+            std::string to_string(const T* o) const
+            {
+                if (ptr_) {
+                    data<T, double>* q_double =
+                            dynamic_cast < data<T, double>* >(ptr_);
 
-                    if (q_bool) {
-                        return o->*(q_bool->value_) ? "true": "false";
+                    if (q_double) {
+                        return std::to_string(o->*(q_double->value_));
                     } else {
-                        data < T, std::vector < double > >* q_double_v =
-                            dynamic_cast < data < T, std::vector <
-                                double > >* >(ptr_);
+                        data<T, int>* q_int =
+                                dynamic_cast < data<T, int>* >(ptr_);
 
-                        if (q_double_v) {
-                            return "";
+                        if (q_int) {
+                            return std::to_string(o->*(q_int->value_));
                         } else {
-                            data < T, std::vector < int > >* q_int_v =
-                                dynamic_cast < data < T, std::vector <
-                                    int > >* >(ptr_);
+                            data<T, bool>* q_bool =
+                                    dynamic_cast < data<T, bool>* >(ptr_);
 
-                            if (q_int_v) {
-                                return "";
+                            if (q_bool) {
+                                return o->*(q_bool->value_) ? "true" : "false";
                             } else {
-                                data < T, std::vector < bool > >* q_bool_v =
-                                    dynamic_cast < data < T, std::vector <
-                                        bool > >* >(ptr_);
+                                data<T, std::vector<double> >* q_double_v =
+                                        dynamic_cast < data<T, std::vector<
+                                                double> >* >(ptr_);
 
-                                if (q_bool_v) {
+                                if (q_double_v) {
                                     return "";
                                 } else {
-                                    return "NA";
+                                    data<T, std::vector<int> >* q_int_v =
+                                            dynamic_cast < data<T, std::vector<
+                                                    int> >* >(ptr_);
+
+                                    if (q_int_v) {
+                                        return "";
+                                    } else {
+                                        data<T, std::vector<bool> >* q_bool_v =
+                                                dynamic_cast < data<T, std::vector<
+                                                        bool> >* >(ptr_);
+
+                                        if (q_bool_v) {
+                                            return "";
+                                        } else {
+                                            return "NA";
+                                        }
+                                    }
                                 }
                             }
                         }
                     }
+                } else {
+                    return "NA";
                 }
             }
-        } else {
-            return "NA";
-        }
-    }
-};
+        };
 
 // template < typename C,
 //            typename T,
@@ -365,6 +361,7 @@ public:
 //     assert(false);
 // }
 
-} }
+    }
+}
 
 #endif

+ 3 - 3
src/artis/kernel/CMakeLists.txt

@@ -1,11 +1,11 @@
 INCLUDE_DIRECTORIES(
-  ${CMAKE_SOURCE_DIR}/src)
+        ${CMAKE_SOURCE_DIR}/src)
 
 LINK_DIRECTORIES()
 
 SET(ARTIS_KERNEL_HPP AbstractAtomicModel.hpp AbstractCoupledModel.hpp
-  AbstractModel.hpp Any.hpp Externals.hpp Internals.hpp Macro.hpp Node.hpp
-  Simulator.hpp States.hpp)
+        AbstractModel.hpp Any.hpp Externals.hpp Internals.hpp Macro.hpp Node.hpp
+        Simulator.hpp States.hpp)
 
 SET(ARTIS_KERNEL_CPP Any.cpp Simulator.cpp)
 

+ 147 - 151
src/artis/kernel/Externals.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -27,184 +27,180 @@
 #include <artis/kernel/Macro.hpp>
 
 #include <vector>
+
 #if WIN32
 #include <iso646.h>
 #endif
-namespace artis { namespace kernel {
-
-template < typename T, typename U, typename V >
-class Externals
-{
-    template < typename W >
-    struct element
-    {
-        unsigned int index;
-        const std::string name;
-        W T::* var;
-
-        element(unsigned int index, const std::string& name, W T::* var) :
-            index(index), name(name), var(var)
-        { }
-    };
-
-public:
-    Externals() : updated(false)
-    { }
-
-    virtual ~Externals()
-    { }
-
-    const Any& get(unsigned int index) const
-    { return externals.at(index).second; }
-
-    const std::string& name(unsigned int index) const
-    { return external_names.at(index); }
-
-    bool check(typename U::type t) const
-    {
-        bool OK = true;
-        typename std::vector <
-            std::pair < double,
-                        Any > >::const_iterator it = externals.begin();
-
-        while (it != externals.end() and OK) {
-            OK = it->first == t;
-            ++it;
-        }
-        return OK;
-    }
-
-    template < typename W >
-    void E_(std::initializer_list < element < W > > list)
-    {
-        for (typename std::initializer_list < element < W > >::iterator it =
-                 list.begin(); it != list.end(); ++it) {
-            if (externals.size() <= it->index) {
-                externals.resize(it->index + 1, std::make_pair(-1, Any()));
-                external_names.resize(it->index + 1, std::string());
+namespace artis {
+    namespace kernel {
+
+        template<typename T, typename U, typename V>
+        class Externals {
+            template<typename W>
+            struct element {
+                unsigned int index;
+                const std::string name;
+                W T::* var;
+
+                element(unsigned int index, const std::string& name, W T::* var)
+                        :
+                        index(index), name(name), var(var) { }
+            };
+
+        public:
+            Externals()
+                    :updated(false) { }
+
+            virtual ~Externals() { }
+
+            const Any& get(unsigned int index) const { return externals.at(index).second; }
+
+            const std::string& name(unsigned int index) const { return external_names.at(index); }
+
+            bool check(typename U::type t) const
+            {
+                bool OK = true;
+                typename std::vector<
+                        std::pair<double,
+                                Any> >::const_iterator it = externals.begin();
+
+                while (it != externals.end() and OK) {
+                    OK = it->first == t;
+                    ++it;
+                }
+                return OK;
             }
-            externals[it->index] = std::make_pair(-1, it->var);
-            external_names[it->index] = it->name;
+
+            template<typename W>
+            void E_(std::initializer_list<element<W> > list)
+            {
+                for (typename std::initializer_list<element<W> >::iterator it =
+                        list.begin(); it != list.end(); ++it) {
+                    if (externals.size() <= it->index) {
+                        externals.resize(it->index + 1, std::make_pair(-1, Any()));
+                        external_names.resize(it->index + 1, std::string());
+                    }
+                    externals[it->index] = std::make_pair(-1, it->var);
+                    external_names[it->index] = it->name;
 
 #ifdef WITH_TRACE
-            utils::Trace < utils::DoubleTime >::trace()
-                    << utils::TraceElement < utils::DoubleTime >(
-                           true,
-                           dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
-                           utils::DoubleTime::null,
-                           utils::EXTERNAL_DECL)
-                    << utils::KernelInfo(it->name, false);
-            utils::Trace < utils::DoubleTime >::trace().flush();
+                    utils::Trace<utils::DoubleTime>::trace()
+                            << utils::TraceElement<utils::DoubleTime>(
+                                    true,
+                                    dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
+                                    utils::DoubleTime::null,
+                                    utils::EXTERNAL_DECL)
+                            << utils::KernelInfo(it->name, false);
+                    utils::Trace<utils::DoubleTime>::trace().flush();
 #endif
-        }
-    }
+                }
+            }
 
-    template < typename W >
-    void external_(unsigned int index, const std::string& name, W T::* var)
-    {
-        if (externals.size() <= index) {
-            externals.resize(index + 1, std::make_pair(-1, Any()));
-            external_names.resize(index + 1, std::string());
-        }
-        externals[index] = std::make_pair(-1, var);
-        external_names[index] = name;
+            template<typename W>
+            void external_(unsigned int index, const std::string& name, W T::* var)
+            {
+                if (externals.size() <= index) {
+                    externals.resize(index + 1, std::make_pair(-1, Any()));
+                    external_names.resize(index + 1, std::string());
+                }
+                externals[index] = std::make_pair(-1, var);
+                external_names[index] = name;
 
 #ifdef WITH_TRACE
-        utils::Trace < utils::DoubleTime >::trace()
-                << utils::TraceElement < utils::DoubleTime >(
-                       true,
-                       dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
-                       utils::DoubleTime::null,
-                       utils::EXTERNAL_DECL)
-                << utils::KernelInfo(name, false);
-        utils::Trace < utils::DoubleTime >::trace().flush();
+                utils::Trace<utils::DoubleTime>::trace()
+                        << utils::TraceElement<utils::DoubleTime>(
+                                true,
+                                dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
+                                utils::DoubleTime::null,
+                                utils::EXTERNAL_DECL)
+                        << utils::KernelInfo(name, false);
+                utils::Trace<utils::DoubleTime>::trace().flush();
 #endif
-    }
+            }
 
-    bool is_ready(typename U::type t, unsigned int index) const
-    { return externals.at(index).first == t; }
+            bool is_ready(typename U::type t, unsigned int index) const { return externals.at(index).first == t; }
 
-    template < typename W >
-    void put(typename U::type t, unsigned int index, W value)
-    {
-        if (externals.at(index).first != t) {
-            Any v = externals.at(index).second;
+            template<typename W>
+            void put(typename U::type t, unsigned int index, W value)
+            {
+                if (externals.at(index).first != t) {
+                    Any v = externals.at(index).second;
 
-            v.put < T, W >(static_cast < T* >(this), value);
-            externals.at(index).first = t;
-            updated = true;
-        } else {
-            Any v = externals.at(index).second;
+                    v.put<T, W>(static_cast < T* >(this), value);
+                    externals.at(index).first = t;
+                    updated = true;
+                } else {
+                    Any v = externals.at(index).second;
 
-            if (static_cast < const T* >(this)->*(v.get < T, W >()) != value) {
-                v.put < T, W >(static_cast < T* >(this), value);
-                updated = true;
-            }
-        }
+                    if (static_cast < const T* >(this)->*(v.get<T, W>()) != value) {
+                        v.put<T, W>(static_cast < T* >(this), value);
+                        updated = true;
+                    }
+                }
 
 #ifdef WITH_TRACE
-        utils::Trace < utils::DoubleTime >::trace()
-                << utils::TraceElement < utils::DoubleTime >(
-                       true,
-                       dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
-                       t, utils::PUT)
-                << utils::KernelInfo(external_names[index], true,
-                                     get(index).to_string(dynamic_cast < const T* >(this)));
-        utils::Trace < utils::DoubleTime >::trace().flush();
+                utils::Trace<utils::DoubleTime>::trace()
+                        << utils::TraceElement<utils::DoubleTime>(
+                                true,
+                                dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
+                                t, utils::PUT)
+                        << utils::KernelInfo(external_names[index], true,
+                                get(index).to_string(dynamic_cast < const T* >(this)));
+                utils::Trace<utils::DoubleTime>::trace().flush();
 #endif
-    }
-
-    virtual void restore(AbstractModel < U, V >* model,
-                         const context::State < U >& state)
-    {
-        unsigned int index = 0;
-
-        for (typename std::vector < std::pair < typename U::type,
-                 Any > >::iterator it = externals.begin();
-             it != externals.end(); ++it) {
-            Any& value = it->second;
-
-            if (not value.is_null()) {
-                value.restore < T >(static_cast < T* >(model),
-                                    state.get_external(index));
             }
-            ++index;
-        }
-    }
 
-    virtual void save(const AbstractModel < U, V >* model,
-                      context::State < U >& state) const
-    {
-        unsigned int index = 0;
-
-        for (typename std::vector < std::pair < typename U::type,
-                 Any > >::const_iterator it = externals.begin();
-             it != externals.end(); ++it) {
-            const Any& value = it->second;
+            virtual void restore(AbstractModel<U, V>* model,
+                    const context::State<U>& state)
+            {
+                unsigned int index = 0;
+
+                for (typename std::vector<std::pair<typename U::type,
+                        Any> >::iterator it = externals.begin();
+                     it != externals.end(); ++it) {
+                    Any& value = it->second;
+
+                    if (not value.is_null()) {
+                        value.restore<T>(static_cast < T* >(model),
+                                state.get_external(index));
+                    }
+                    ++index;
+                }
+            }
 
-            if (not value.is_null()) {
-                state.add_external(index,
-                                   value.save < T >(
-                                       static_cast < const T* >(model)));
+            virtual void save(const AbstractModel<U, V>* model,
+                    context::State<U>& state) const
+            {
+                unsigned int index = 0;
+
+                for (typename std::vector<std::pair<typename U::type,
+                        Any> >::const_iterator it = externals.begin();
+                     it != externals.end(); ++it) {
+                    const Any& value = it->second;
+
+                    if (not value.is_null()) {
+                        state.add_external(index,
+                                value.save<T>(
+                                        static_cast < const T* >(model)));
+                    }
+                    ++index;
+                }
             }
-            ++index;
-        }
-    }
 
-    unsigned int size() const
-    { return externals.size(); }
+            unsigned int size() const { return externals.size(); }
 
-protected:
-    bool updated;
-    std::vector < std::pair < typename U::type, Any > > externals;
-    std::vector < std::string > external_names;
-};
+        protected:
+            bool updated;
+            std::vector<std::pair<typename U::type, Any> > externals;
+            std::vector<std::string> external_names;
+        };
 
 #define External(index, var)                                    \
         external_(index, std::string(ESCAPEQUOTE(index)), var)
 
-#define Externals(W,L) E_< W >(UNWRAP2 L)
+#define Externals(W, L) E_< W >(UNWRAP2 L)
 
-} } // namespace artis kernel
+    }
+} // namespace artis kernel
 
 #endif

+ 100 - 105
src/artis/kernel/Internals.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -29,128 +29,123 @@
 
 #include <vector>
 
-namespace artis { namespace kernel {
-
-template < typename T, typename U, typename V >
-class Internals
-{
-    template < typename W >
-    struct element
-    {
-        unsigned int index;
-        const std::string name;
-        W T::* var;
-
-        element(unsigned int index, const std::string& name, W T::* var) :
-            index(index), name(name), var(var)
-        { }
-    };
-
-public:
-    Internals()
-    { }
-
-    virtual ~Internals()
-    { }
-
-    const Any& get(unsigned int index) const
-    { return internals.at(index); }
-
-    template < typename W >
-    void I_(std::initializer_list < element < W > > list)
-    {
-        for (typename std::initializer_list <element < W > >::iterator it =
-             list.begin(); it != list.end(); ++it) {
-            if (internals.size() <= it->index) {
-                internals.resize(it->index + 1);
-                internal_names.resize(it->index + 1, std::string());
-            }
-            internals[it->index] = it->var;
-            internal_names[it->index] = it->name;
+namespace artis {
+    namespace kernel {
+
+        template<typename T, typename U, typename V>
+        class Internals {
+            template<typename W>
+            struct element {
+                unsigned int index;
+                const std::string name;
+                W T::* var;
+
+                element(unsigned int index, const std::string& name, W T::* var)
+                        :
+                        index(index), name(name), var(var) { }
+            };
+
+        public:
+            Internals() { }
+
+            virtual ~Internals() { }
+
+            const Any& get(unsigned int index) const { return internals.at(index); }
+
+            template<typename W>
+            void I_(std::initializer_list<element<W> > list)
+            {
+                for (typename std::initializer_list<element<W> >::iterator it =
+                        list.begin(); it != list.end(); ++it) {
+                    if (internals.size() <= it->index) {
+                        internals.resize(it->index + 1);
+                        internal_names.resize(it->index + 1, std::string());
+                    }
+                    internals[it->index] = it->var;
+                    internal_names[it->index] = it->name;
 
 #ifdef WITH_TRACE
-            utils::Trace < utils::DoubleTime >::trace()
-                    << utils::TraceElement < utils::DoubleTime >(
-                           true,
-                           dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
-                           utils::DoubleTime::null,
-                           utils::INTERNAL_DECL)
-                    << utils::KernelInfo(it->name, true);
-            utils::Trace < utils::DoubleTime >::trace().flush();
+                    utils::Trace<utils::DoubleTime>::trace()
+                            << utils::TraceElement<utils::DoubleTime>(
+                                    true,
+                                    dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
+                                    utils::DoubleTime::null,
+                                    utils::INTERNAL_DECL)
+                            << utils::KernelInfo(it->name, true);
+                    utils::Trace<utils::DoubleTime>::trace().flush();
 #endif
-        }
+                }
 
-    }
+            }
 
-    template < typename W >
-    void internal_(unsigned int index, const std::string& name, W T::* var)
-    {
-        if (internals.size() <= index) {
-            internals.resize(index + 1, Any());
-            internal_names.resize(index + 1, std::string());
-        }
-        internals[index] = Any(var);
-        internal_names[index] = name;
+            template<typename W>
+            void internal_(unsigned int index, const std::string& name, W T::* var)
+            {
+                if (internals.size() <= index) {
+                    internals.resize(index + 1, Any());
+                    internal_names.resize(index + 1, std::string());
+                }
+                internals[index] = Any(var);
+                internal_names[index] = name;
 
 #ifdef WITH_TRACE
-        utils::Trace < utils::DoubleTime >::trace()
-                << utils::TraceElement < utils::DoubleTime >(
-                       true,
-                       dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
-                       utils::DoubleTime::null,
-                       utils::INTERNAL_DECL)
-                << utils::KernelInfo(name, true);
-        utils::Trace < utils::DoubleTime >::trace().flush();
+                utils::Trace<utils::DoubleTime>::trace()
+                        << utils::TraceElement<utils::DoubleTime>(
+                                true,
+                                dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
+                                utils::DoubleTime::null,
+                                utils::INTERNAL_DECL)
+                        << utils::KernelInfo(name, true);
+                utils::Trace<utils::DoubleTime>::trace().flush();
 #endif
-    }
-
-    const std::string& name(unsigned int index) const
-    { return internal_names.at(index); }
-
-    virtual void restore(AbstractModel < U, V >* model,
-                         const context::State < U >& state)
-    {
-        unsigned int index = 0;
+            }
 
-        for (typename std::vector < Any >::iterator it = internals.begin();
-             it != internals.end(); ++it) {
-            if (not it->is_null()) {
-                it->restore < T >(static_cast < T* >(model),
-                                  state.get_internal(index));
+            const std::string& name(unsigned int index) const { return internal_names.at(index); }
+
+            virtual void restore(AbstractModel<U, V>* model,
+                    const context::State<U>& state)
+            {
+                unsigned int index = 0;
+
+                for (typename std::vector<Any>::iterator it = internals.begin();
+                     it != internals.end(); ++it) {
+                    if (not it->is_null()) {
+                        it->restore<T>(static_cast < T* >(model),
+                                state.get_internal(index));
+                    }
+                    ++index;
+                }
             }
-            ++index;
-        }
-    }
 
-    virtual void save(const AbstractModel < U, V >* model,
-                      context::State < U >& state) const
-    {
-        unsigned int index = 0;
-
-        for (typename std::vector < Any >::const_iterator it =
-             internals.begin(); it != internals.end(); ++it) {
-            if (not it->is_null()) {
-                state.add_internal(index,
-                                   it->save < T >(
-                                       static_cast < const T* >(model)));
+            virtual void save(const AbstractModel<U, V>* model,
+                    context::State<U>& state) const
+            {
+                unsigned int index = 0;
+
+                for (typename std::vector<Any>::const_iterator it =
+                        internals.begin(); it != internals.end(); ++it) {
+                    if (not it->is_null()) {
+                        state.add_internal(index,
+                                it->save<T>(
+                                        static_cast < const T* >(model)));
+                    }
+                    ++index;
+                }
             }
-            ++index;
-        }
-    }
 
-    unsigned int size() const
-    { return internals.size(); }
+            unsigned int size() const { return internals.size(); }
 
-private:
-    std::vector < std::string > internal_names;
-    std::vector < Any > internals;
-};
+        private:
+            std::vector<std::string> internal_names;
+            std::vector<Any> internals;
+        };
 
 #define Internal(index, var)                                    \
     internal_(index, std::string(ESCAPEQUOTE(index)), var)
 
-#define Internals(W,L) I_< W >(UNWRAP2 L)
+#define Internals(W, L) I_< W >(UNWRAP2 L)
 
-} } // namespace artis kernel
+    }
+} // namespace artis kernel
 
 #endif

+ 2 - 3
src/artis/kernel/Macro.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -53,11 +53,10 @@
 #define EXPAND(X) X
 #define PP_NARG(...) EXPAND( PP_NARG_(__VA_ARGS__, PP_RSEQ_N()) )
 #define PP_NARG_(...) EXPAND( PP_ARG_N(__VA_ARGS__) )
-#define PP_ARG_N(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10_,_11,_12,_13,_14,_15,_16,N, ...) N
+#define PP_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10_, _11, _12, _13, _14, _15, _16, N, ...) N
 #define PP_RSEQ_N() 16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
 #define LIST_(N) LIST_##N
 #define LIST_EVAL(N) LIST_(N)
 #define UNWRAP2(...) EXPAND( LIST_EVAL(EXPAND( PP_NARG(__VA_ARGS__) ))(__VA_ARGS__) )
 
-
 #endif

+ 25 - 26
src/artis/kernel/Node.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -27,37 +27,36 @@
 
 #include <cassert>
 
-namespace artis { namespace kernel {
+namespace artis {
+    namespace kernel {
 
-template < typename U >
-class Node
-{
-public:
-    Node()
-    { }
+        template<typename U>
+        class Node {
+        public:
+            Node() { }
 
-    virtual ~Node()
-    { }
+            virtual ~Node() { }
 
-    virtual const Any& get(typename U::type t, unsigned int index) const = 0;
+            virtual const Any& get(typename U::type t, unsigned int index) const = 0;
 
-    virtual std::string get(const ValueTypeID& value_type, typename U::type t,
-                            unsigned int index) const = 0;
+            virtual std::string get(const ValueTypeID& value_type, typename U::type t,
+                    unsigned int index) const = 0;
 
-    virtual const Node < U >* get_submodel(unsigned int /* index */) const
-    {
-        assert(false);
-        return 0;
-    }
+            virtual const Node<U>* get_submodel(unsigned int /* index */) const
+            {
+                assert(false);
+                return 0;
+            }
 
-    virtual const Node < U >* get_submodel(unsigned int /*index */,
-                                           unsigned int /* rank */) const
-    {
-        assert(false);
-        return 0;
-    }
-};
+            virtual const Node<U>* get_submodel(unsigned int /*index */,
+                    unsigned int /* rank */) const
+            {
+                assert(false);
+                return 0;
+            }
+        };
 
-} }
+    }
+}
 
 #endif

+ 5 - 3
src/artis/kernel/Simulator.cpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -22,6 +22,8 @@
 
 #include <artis/kernel/Simulator.hpp>
 
-namespace artis { namespace kernel {
+namespace artis {
+    namespace kernel {
 
-} }
+    }
+}

+ 47 - 51
src/artis/kernel/Simulator.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -29,65 +29,61 @@
 #include <artis/observer/View.hpp>
 #include <artis/utils/DoubleTime.hpp>
 
-namespace artis { namespace kernel {
+namespace artis {
+    namespace kernel {
 
-template < typename T, typename U, typename V, typename W >
-class Simulator
-{
-public:
-    Simulator(artis::kernel::AbstractCoupledModel < T, U, V, W >* model,
-              W& parameters) : _model(model), _observer(model)
-    { _model->build(parameters); }
+        template<typename T, typename U, typename V, typename W>
+        class Simulator {
+        public:
+            Simulator(artis::kernel::AbstractCoupledModel<T, U, V, W>* model,
+                    W& parameters)
+                    :_model(model), _observer(model) { _model->build(parameters); }
 
-    Simulator(artis::kernel::AbstractCoupledModel < T, U, V, W >* model,
-              W& parameters, const std::string& json)
-        : _model(model), _observer(model)
-    { _model->build(parameters, json); }
+            Simulator(artis::kernel::AbstractCoupledModel<T, U, V, W>* model,
+                    W& parameters, const std::string& json)
+                    :_model(model), _observer(model) { _model->build(parameters, json); }
 
-    virtual ~Simulator()
-    { delete _model; }
+            virtual ~Simulator() { delete _model; }
 
-    void attachView(const std::string& name, observer::View < U, V >* view)
-    { _observer.attachView(name, view); }
+            void attachView(const std::string& name, observer::View<U, V>* view) { _observer.attachView(name, view); }
 
-
-    void init(double time, const V& parameters)
-    {
-        _model->init(time, parameters);
-        _observer.init();
+            void init(double time, const V& parameters)
+            {
+                _model->init(time, parameters);
+                _observer.init();
 
 #ifdef WITH_TRACE
-        _model->trace_model(true,
-                            utils::DoubleTime::null,
-                            utils::INIT);
+                _model->trace_model(true,
+                        utils::DoubleTime::null,
+                        utils::INIT);
 #endif
-    }
-
-    const observer::Observer < U, V >& observer() const
-    { return _observer; }
-
-    void run(const context::Context < U >& context)
-    {
-        if (context.valid()) {
-            _model->restore(context.state());
-        }
-        for (double t = context.begin(); t <= context.end(); t++) {
-            (*_model)(t);
-            _observer.observe(t);
-        }
-    }
+            }
+
+            const observer::Observer<U, V>& observer() const { return _observer; }
+
+            void run(const context::Context<U>& context)
+            {
+                if (context.valid()) {
+                    _model->restore(context.state());
+                }
+                for (double t = context.begin(); t <= context.end(); t++) {
+                    (*_model)(t);
+                    _observer.observe(t);
+                }
+            }
+
+            void save(context::Context<U>& context) const
+            {
+                _model->save(context.state());
+                context.saved();
+            }
+
+        private:
+            artis::kernel::AbstractCoupledModel<T, U, V, W>* _model;
+            observer::Observer<U, V> _observer;
+        };
 
-    void save(context::Context < U >& context) const
-    {
-        _model->save(context.state());
-        context.saved();
     }
-
-private:
-    artis::kernel::AbstractCoupledModel < T, U, V, W >* _model;
-    observer::Observer < U, V >                         _observer;
-};
-
-} }
+}
 
 #endif

+ 80 - 83
src/artis/kernel/States.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -28,99 +28,96 @@
 
 #include <vector>
 
-namespace artis { namespace kernel {
-
-template < typename T, typename U, typename V >
-class States
-{
-    template < typename W >
-    struct element
-    {
-        unsigned int index;
-        const std::string name;
-        W T::* var;
-
-        element(unsigned int index, const std::string& name, W T::* var) :
-            index(index), name(name), var(var)
-        { }
-    };
-
-public:
-    States()
-    { }
-
-    virtual ~States()
-    { }
-
-    const Any& get(unsigned int index) const
-    { return states.at(index); }
-
-    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) {
-            if (states.size() <= it->index) {
-                states.resize(it->index + 1, Any());
-                state_names.resize(it->index + 1, std::string());
+namespace artis {
+    namespace kernel {
+
+        template<typename T, typename U, typename V>
+        class States {
+            template<typename W>
+            struct element {
+                unsigned int index;
+                const std::string name;
+                W T::* var;
+
+                element(unsigned int index, const std::string& name, W T::* var)
+                        :
+                        index(index), name(name), var(var) { }
+            };
+
+        public:
+            States() { }
+
+            virtual ~States() { }
+
+            const Any& get(unsigned int index) const { return states.at(index); }
+
+            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) {
+                    if (states.size() <= it->index) {
+                        states.resize(it->index + 1, Any());
+                        state_names.resize(it->index + 1, std::string());
+                    }
+                    states[it->index] = it->var;
+                    state_names[it->index] = it->name;
+                }
             }
-            states[it->index] = it->var;
-            state_names[it->index] = it->name;
-        }
-    }
-
-    virtual void restore(AbstractModel < U, V >* model,
-                         const context::State < U >& state)
-    {
-        unsigned int index = 0;
 
-        for (typename std::vector < Any >::iterator it = states.begin();
-             it != states.end(); ++it) {
-            if (not it->is_null()) {
-                it->restore < T >(static_cast < T* >(model),
-                                  state.get_state(index));
+            virtual void restore(AbstractModel<U, V>* model,
+                    const context::State<U>& state)
+            {
+                unsigned int index = 0;
+
+                for (typename std::vector<Any>::iterator it = states.begin();
+                     it != states.end(); ++it) {
+                    if (not it->is_null()) {
+                        it->restore<T>(static_cast < T* >(model),
+                                state.get_state(index));
+                    }
+                    ++index;
+                }
             }
-            ++index;
-        }
-    }
 
-    virtual void save(const AbstractModel < U, V >* model,
-                      context::State < U >& state) const
-    {
-        unsigned int index = 0;
-
-        for (typename std::vector < Any >::const_iterator it =
-                 states.begin(); it != states.end(); ++it) {
-            if (not it->is_null()) {
-                state.add_state(index,
-                                it->save < T >(
-                                    static_cast < const T* >(model)));
+            virtual void save(const AbstractModel<U, V>* model,
+                    context::State<U>& state) const
+            {
+                unsigned int index = 0;
+
+                for (typename std::vector<Any>::const_iterator it =
+                        states.begin(); it != states.end(); ++it) {
+                    if (not it->is_null()) {
+                        state.add_state(index,
+                                it->save<T>(
+                                        static_cast < const T* >(model)));
+                    }
+                    ++index;
+                }
             }
-            ++index;
-        }
-    }
 
-    template < typename W >
-    void state_(unsigned int index, const std::string& name, W T::* var)
-    {
-        if (states.size() <= index) {
-            states.resize(index + 1, Any());
-            state_names.resize(index + 1, std::string());
-        }
-        states[index] = Any(var);
-        state_names[index] = name;
-    }
+            template<typename W>
+            void state_(unsigned int index, const std::string& name, W T::* var)
+            {
+                if (states.size() <= index) {
+                    states.resize(index + 1, Any());
+                    state_names.resize(index + 1, std::string());
+                }
+                states[index] = Any(var);
+                state_names[index] = name;
+            }
 
-private:
-    std::vector < Any > states;
-    std::vector < std::string > state_names;
-};
+        private:
+            std::vector<Any> states;
+            std::vector<std::string> state_names;
+        };
 
 #define State(index, var)                                    \
         state_(index, std::string(ESCAPEQUOTE(index)), var)
 
-#define States(W,L) S_< W >(UNWRAP2 L)
+#define States(W, L) S_< W >(UNWRAP2 L)
 
-} }
+    }
+}
 
 #endif

+ 1 - 1
src/artis/lib.cpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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

+ 1 - 1
src/artis/lib.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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

+ 2 - 2
src/artis/observer/CMakeLists.txt

@@ -1,5 +1,5 @@
 INCLUDE_DIRECTORIES(
-  ${CMAKE_SOURCE_DIR}/src)
+        ${CMAKE_SOURCE_DIR}/src)
 
 LINK_DIRECTORIES()
 
@@ -10,4 +10,4 @@ SET(ARTIS_OBSERVER_CPP Observer.cpp Output.cpp View.cpp)
 ADD_SOURCES(artis-lib ${ARTIS_OBSERVER_HPP} ${ARTIS_OBSERVER_CPP})
 
 INSTALL(FILES ${ARTIS_OBSERVER_HPP} DESTINATION
-  ${ARTIS_INCLUDE_DIRS}/observer)
+        ${ARTIS_INCLUDE_DIRS}/observer)

+ 5 - 3
src/artis/observer/Observer.cpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -22,6 +22,8 @@
 
 #include <artis/observer/Observer.hpp>
 
-namespace artis { namespace observer {
+namespace artis {
+    namespace observer {
 
-} }
+    }
+}

+ 57 - 59
src/artis/observer/Observer.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -28,65 +28,63 @@
 
 #include <vector>
 
-namespace artis { namespace observer {
+namespace artis {
+    namespace observer {
+
+        template<typename U, typename V>
+        class Observer {
+        public:
+            typedef std::map<std::string, View<U, V>*> Views;
+
+            Observer(const artis::kernel::AbstractModel<U, V>* model)
+                    :
+                    _model(model) { }
+
+            virtual ~Observer()
+            {
+                for (typename Views::iterator it = _views.begin(); it != _views.end();
+                     ++it) {
+                    delete it->second;
+                }
+            }
+
+            void attachView(const std::string& name, View<U, V>* view)
+            {
+                _views[name] = view;
+                view->attachModel(_model);
+            }
+
+            Views* cloneViews() const
+            {
+                Views* v = new Views();
+
+                for (typename Views::const_iterator it = _views.begin();
+                     it != _views.end(); ++it) {
+                    (*v)[it->first] = it->second->clone();
+                }
+                return v;
+            }
+
+            const View<U, V>& view(const std::string& name) const { return *_views.find(name)->second; }
+
+            const Views& views() const { return _views; }
+
+            void init() { }
+
+            void observe(double t)
+            {
+                for (typename Views::iterator it = _views.begin(); it != _views.end();
+                     ++it) {
+                    it->second->observe(t);
+                }
+            }
+
+        private:
+            const artis::kernel::AbstractModel<U, V>* _model;
+            Views _views;
+        };
 
-template < typename U, typename V >
-class Observer
-{
-public:
-    typedef std::map < std::string, View < U, V >* > Views;
-
-    Observer(const artis::kernel::AbstractModel < U, V >* model) :
-        _model(model)
-    { }
-
-    virtual ~Observer()
-    {
-        for (typename Views::iterator it = _views.begin(); it != _views.end();
-             ++it) {
-            delete it->second;
-        }
-    }
-
-    void attachView(const std::string& name, View < U, V >* view)
-    {
-        _views[name] = view;
-        view->attachModel(_model);
-    }
-
-    Views* cloneViews() const
-    {
-        Views* v = new Views();
-
-        for (typename Views::const_iterator it = _views.begin();
-             it != _views.end(); ++it) {
-            (*v)[it->first] = it->second->clone();
-        }
-        return v;
     }
-
-    const View < U, V >& view(const std::string& name) const
-    { return *_views.find(name)->second; }
-
-    const Views& views() const
-    { return _views; }
-
-    void init()
-    { }
-
-    void observe(double t)
-    {
-        for (typename Views::iterator it = _views.begin(); it != _views.end();
-             ++it) {
-            it->second->observe(t);
-        }
-    }
-
-private:
-    const artis::kernel::AbstractModel < U, V >* _model;
-    Views                                        _views;
-};
-
-} }
+}
 
 #endif

+ 5 - 3
src/artis/observer/Output.cpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -22,6 +22,8 @@
 
 #include <artis/observer/Output.hpp>
 
-namespace artis { namespace observer {
+namespace artis {
+    namespace observer {
 
-} }
+    }
+}

+ 51 - 51
src/artis/observer/Output.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -29,67 +29,67 @@
 
 #include <boost/format.hpp>
 
-namespace artis { namespace observer {
+namespace artis {
+    namespace observer {
 
-template < typename U, typename V >
-class Output
-{
-public:
-    Output(const Observer < U, V >& observer) : _observer(observer)
-    { }
+        template<typename U, typename V>
+        class Output {
+        public:
+            Output(const Observer<U, V>& observer)
+                    :_observer(observer) { }
 
-    virtual ~Output()
-    { }
+            virtual ~Output() { }
 
-    void operator()(const std::string& path = "") const
-    {
-        const typename Observer < U, V >::Views& views = _observer.views();
+            void operator()(const std::string& path = "") const
+            {
+                const typename Observer<U, V>::Views& views = _observer.views();
 
-        for (typename Observer < U, V >::Views::const_iterator it =
-                 views.begin(); it != views.end(); ++it) {
-            std::ofstream o((boost::format("%1%/%2%.csv") % path %
-                             it->first).str());
-            typename View < U, V >::Values values = it->second->values();
-            double begin = it->second->begin();
-            double end = it->second->end();
+                for (typename Observer<U, V>::Views::const_iterator it =
+                        views.begin(); it != views.end(); ++it) {
+                    std::ofstream o((boost::format("%1%/%2%.csv") % path %
+                            it->first).str());
+                    typename View<U, V>::Values values = it->second->values();
+                    double begin = it->second->begin();
+                    double end = it->second->end();
 
-            o.precision(10);
-            // write header
-            o << "time";
-            for (typename View < U, V >::Values::const_iterator
-                     itv = values.begin(); itv != values.end(); ++itv) {
-                o << ";" << itv->first;
-            }
-            o << std::endl;
+                    o.precision(10);
+                    // write header
+                    o << "time";
+                    for (typename View<U, V>::Values::const_iterator
+                                 itv = values.begin(); itv != values.end(); ++itv) {
+                        o << ";" << itv->first;
+                    }
+                    o << std::endl;
 
-            // write values
-            for (double t = begin; t <= end; ++t) {
-                o << utils::DateTime::toJulianDay(t);
-                // o << t;
-                for (typename View < U, V >::Values::const_iterator itv =
-                         values.begin(); itv != values.end(); ++itv) {
-                    typename View < U, V >::Value::const_iterator itp =
-                        itv->second.begin();
+                    // write values
+                    for (double t = begin; t <= end; ++t) {
+                        o << utils::DateTime::toJulianDay(t);
+                        // o << t;
+                        for (typename View<U, V>::Values::const_iterator itv =
+                                values.begin(); itv != values.end(); ++itv) {
+                            typename View<U, V>::Value::const_iterator itp =
+                                    itv->second.begin();
 
-                    while (itp != itv->second.end() and itp->first < t) {
-                        ++itp;
-                    }
-                    o << ";";
-                    if (itp != itv->second.end()) {
-                        o << itp->second;
-                    } else {
-                        o << "NA";
+                            while (itp != itv->second.end() and itp->first < t) {
+                                ++itp;
+                            }
+                            o << ";";
+                            if (itp != itv->second.end()) {
+                                o << itp->second;
+                            } else {
+                                o << "NA";
+                            }
+                        }
+                        o << std::endl;
                     }
                 }
-                o << std::endl;
             }
-        }
-    }
 
-private:
-    const Observer < U, V >& _observer;
-};
+        private:
+            const Observer<U, V>& _observer;
+        };
 
-} }
+    }
+}
 
 #endif

+ 5 - 3
src/artis/observer/View.cpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -22,6 +22,8 @@
 
 #include <artis/observer/View.hpp>
 
-namespace model { namespace observer {
+namespace model {
+    namespace observer {
 
-} }
+    }
+}

+ 110 - 112
src/artis/observer/View.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -28,145 +28,143 @@
 
 #include <boost/lexical_cast.hpp>
 
-namespace artis { namespace observer {
+namespace artis {
+    namespace observer {
 
-template < typename U, typename V >
-class View
-{
-    typedef std::vector < unsigned int > Selector;
+        template<typename U, typename V>
+        class View {
+            typedef std::vector<unsigned int> Selector;
 
-public:
-    typedef std::vector < std::pair < double, std::string > > Value;
-    typedef std::map < std::string, Value > Values;
+        public:
+            typedef std::vector<std::pair<double, std::string> > Value;
+            typedef std::map<std::string, Value> Values;
 
-    View() : _model(0)
-    { }
+            View()
+                    :_model(0) { }
 
-    virtual ~View()
-    { }
+            virtual ~View() { }
 
-    void attachModel(const artis::kernel::AbstractModel < U, V >* m)
-    { _model = m; }
+            void attachModel(const artis::kernel::AbstractModel<U, V>* m) { _model = m; }
 
-    double begin() const
-    {
-        double t = utils::DoubleTime::infinity;
+            double begin() const
+            {
+                double t = utils::DoubleTime::infinity;
 
-        for (Values::const_iterator it = _values.begin(); it!= _values.end();
-             ++it) {
-            if (t > it->second.begin()->first) {
-                t = it->second.begin()->first;
+                for (Values::const_iterator it = _values.begin(); it != _values.end();
+                     ++it) {
+                    if (t > it->second.begin()->first) {
+                        t = it->second.begin()->first;
+                    }
+                }
+                return t;
             }
-        }
-        return t;
-    }
 
-    View* clone() const
-    {
-        View* v = new View();
+            View* clone() const
+            {
+                View* v = new View();
 
-        v->_selectors = _selectors;
-        for (Values::const_iterator it = _values.begin(); it!= _values.end();
-             ++it) {
+                v->_selectors = _selectors;
+                for (Values::const_iterator it = _values.begin(); it != _values.end();
+                     ++it) {
 
-            v->_values[it->first] = Value();
-            Value::const_iterator itp = it->second.begin();
+                    v->_values[it->first] = Value();
+                    Value::const_iterator itp = it->second.begin();
 
-            while (itp != it->second.end()) {
-                v->_values[it->first].push_back(*itp);
-                ++itp;
+                    while (itp != it->second.end()) {
+                        v->_values[it->first].push_back(*itp);
+                        ++itp;
+                    }
+                }
+                v->_model = 0;
+                return v;
             }
-        }
-        v->_model = 0;
-        return v;
-    }
 
-    double end() const
-    {
-        double t = 0;
+            double end() const
+            {
+                double t = 0;
 
-        for (Values::const_iterator it = _values.begin(); it!= _values.end();
-             ++it) {
-            if (t < it->second.back().first) {
-                t = it->second.back().first;
+                for (Values::const_iterator it = _values.begin(); it != _values.end();
+                     ++it) {
+                    if (t < it->second.back().first) {
+                        t = it->second.back().first;
+                    }
+                }
+                return t;
             }
-        }
-        return t;
-    }
 
-    double get(double t, const std::string& name) const
-    {
-        Values::const_iterator it = _values.find(name);
-
-        if (it != _values.end()) {
-            Value::const_iterator itp = it->second.begin();
-
-            while (itp != it->second.end() and itp->first < t) {
-                ++itp;
-            }
-            if (itp != it->second.end()) {
-                // TODO: to improve
-                return boost::lexical_cast < double >(itp->second);
-            } else {
+            double get(double t, const std::string& name) const
+            {
+                Values::const_iterator it = _values.find(name);
+
+                if (it != _values.end()) {
+                    Value::const_iterator itp = it->second.begin();
+
+                    while (itp != it->second.end() and itp->first < t) {
+                        ++itp;
+                    }
+                    if (itp != it->second.end()) {
+                        // TODO: to improve
+                        return boost::lexical_cast<double>(itp->second);
+                    } else {
+                        return 0;
+                    }
+                }
                 return 0;
             }
-        }
-        return 0;
-    }
 
-    const Value& get(const std::string& name) const
-    {
-        Values::const_iterator it = _values.find(name);
+            const Value& get(const std::string& name) const
+            {
+                Values::const_iterator it = _values.find(name);
 
-        if (it != _values.end()) {
-            return it->second;
-        } else {
-            assert(false);
-        }
-    }
-
-    virtual void observe(double time)
-    {
-        for (typename Selectors::const_iterator it = _selectors.begin();
-             it != _selectors.end(); ++it) {
-            const kernel::Node < utils::DoubleTime >* model = _model;
-
-            if (it->second.second.size() > 1) {
-                size_t i = 0;
-
-                while (i < it->second.second.size() - 1 and model) {
-                    model = model->get_submodel(it->second.second[i]);
-                    ++i;
+                if (it != _values.end()) {
+                    return it->second;
+                } else {
+                    assert(false);
                 }
             }
-            if (model) {
-                _values[it->first].push_back(
-                    std::make_pair(time,
-                                   model->get(it->second.first, time,
-                                              it->second.second.back())));
+
+            virtual void observe(double time)
+            {
+                for (typename Selectors::const_iterator it = _selectors.begin();
+                     it != _selectors.end(); ++it) {
+                    const kernel::Node<utils::DoubleTime>* model = _model;
+
+                    if (it->second.second.size() > 1) {
+                        size_t i = 0;
+
+                        while (i < it->second.second.size() - 1 and model) {
+                            model = model->get_submodel(it->second.second[i]);
+                            ++i;
+                        }
+                    }
+                    if (model) {
+                        _values[it->first].push_back(
+                                std::make_pair(time,
+                                        model->get(it->second.first, time,
+                                                it->second.second.back())));
+                    }
+                }
             }
-        }
-    }
 
-    void selector(const std::string& name, kernel::ValueTypeID value_type,
-                  const Selector& chain)
-    {
-        _selectors[name] = std::make_pair(value_type, chain);
-        _values[name] = Value();
-    }
+            void selector(const std::string& name, kernel::ValueTypeID value_type,
+                    const Selector& chain)
+            {
+                _selectors[name] = std::make_pair(value_type, chain);
+                _values[name] = Value();
+            }
 
-    const Values& values() const
-    { return _values;}
+            const Values& values() const { return _values; }
 
-private:
-    typedef std::map < std::string, std::pair < kernel::ValueTypeID,
-                                                Selector > > Selectors;
+        private:
+            typedef std::map<std::string, std::pair<kernel::ValueTypeID,
+                    Selector> > Selectors;
 
-    Selectors                                    _selectors;
-    Values                                       _values;
-    const artis::kernel::AbstractModel < U, V >* _model;
-};
+            Selectors _selectors;
+            Values _values;
+            const artis::kernel::AbstractModel<U, V>* _model;
+        };
 
-} }
+    }
+}
 
 #endif

+ 4 - 4
src/artis/utils/CMakeLists.txt

@@ -1,14 +1,14 @@
 INCLUDE_DIRECTORIES(
-  ${CMAKE_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS})
+        ${CMAKE_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES(
-  ${Boost_LIBRARY_DIRS})
+        ${Boost_LIBRARY_DIRS})
 
 SET(ARTIS_UTILS_CPP DateTime.cpp ParametersReader.cpp Trace.cpp)
 
 SET(ARTIS_UTILS_HPP DateTime.hpp DoubleTime.hpp Exception.hpp
-  ParametersReader.hpp Time.hpp Trace.hpp)
+        ParametersReader.hpp Time.hpp Trace.hpp)
 
 ADD_SOURCES(artis-lib ${ARTIS_UTILS_CPP} ${ARTIS_UTILS_HPP})
 

+ 689 - 640
src/artis/utils/DateTime.cpp

@@ -4,7 +4,13 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * This file is part of VLE, a framework for multi-modeling, simulation
+ * and analysis of complex dynamical systems.
+ * https://www.vle-project.org
+ *
+ * Copyright (c) 2003-2019 Gauthier Quesnel <gauthier.quesnel@inra.fr>
+ * Copyright (c) 2003-2019 ULCO http://www.univ-littoral.fr
+ * Copyright (c) 2007-2019 INRA http://www.inra.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
@@ -22,652 +28,695 @@
 
 #include <artis/utils/DateTime.hpp>
 
-#include <sstream>
 #include <regex>
-#include <ctime>
-#include <cmath>
-#if WIN32
-#include <iso646.h>
-#endif
-
-namespace artis { namespace utils {
-
-bool intern_isLeapYear(long year) noexcept
-{
-    if (year % 4 != 0)
-	return false;
-
-    if (year % 100 != 0)
-	return true;
-
-    if (year % 400 != 0)
-	return false;
-
-    return true;
-}
-
-long intern_aYear(long year) noexcept
-{
-    if (intern_isLeapYear(year))
-	return 366;
-
-    return 365;
-}
-
-long intern_aMonth(long year, long month) noexcept
-{
-    switch (month) {
-	case 1: return 31;
-	case 2:
-	if (intern_isLeapYear(year))
-            return 29;
-        return 28;
-	case 3: return 31;
-	case 4: return 30;
-	case 5: return 31;
-	case 6: return 30;
-	case 7: return 31;
-	case 8: return 31;
-	case 9: return 30;
-	case 10: return 31;
-	case 11: return 30;
-	case 12: return 31;
-	default:
-	    return std::numeric_limits<long>::min();
-    }
-}
-
-struct intern_date
-{
-    long myear;
-    long mmonth;
-    long mday;
-    long mhours;
-    long mminutes;
-    long mseconds;
-
-
-
-    intern_date() noexcept
-	: myear(1400)
-	, mmonth(1)
-	, mday(1)
-	, mhours(0)
-	, mminutes(0)
-	, mseconds(0)
-    {
-    }
-
-    intern_date(long year, long month, long day, double partofday) noexcept
-	: myear(year)
-	, mmonth(month)
-	, mday(day)
-	, mhours(0)
-	, mminutes(0)
-	, mseconds(0)
-    {
-	initPartOfDay(partofday);
-    }
-
-    intern_date(const intern_date& d) = default;
-    intern_date& operator=(const intern_date& d) = default;
-    intern_date(intern_date&& d) = default;
-    intern_date& operator=(intern_date&& d) = default;
-
-    void initPartOfDay(double partofday) noexcept //between 0 and 1
-    {
-	double f = partofday * 24.0;
-	mhours = std::floor(f);
-	f -= mhours;
-
-	f *= 60.0;
-	mminutes = std::floor(f);
-	f -= mminutes;
-
-	f *= 60.0;
-	mseconds = std::floor(f);
-    }
-
-    std::string toString(DateFormat fmt) noexcept
-    {
-	std::stringstream ss;
-
-    if (fmt != DATE_FORMAT_HMS) {
-	    ss << myear << "-";
-	    if (mmonth < 10) {
-		ss << "0";
-	    }
-	    ss << mmonth << "-";
-	    if (mday < 10) {
-		ss << "0";
-	    }
-	    ss << mday ;
-	}
-    if (fmt == DATE_FORMAT_EXTENDED) {
-	    ss << " ";
-	}
-    if (fmt != DATE_FORMAT_YMD) {
-	    if (mhours < 10) {
-		ss << "0";
-	    }
-	    ss << mhours << ":";
-	    if (mminutes < 10) {
-		ss << "0";
-	    }
-	    ss << mminutes << ":";
-	    if (mseconds < 10) {
-		ss << "0";
-	    }
-	    ss << mseconds;
-
-	}
-
-	return ss.str();
-    }
-
-    //format : not extended = "%Y-%m-%d"
-    //         extended     = "%Y-%m-%d %H:%M:%S"
-    //return true if no error
-    bool fromString(const std::string& date, DateFormat toparse) noexcept
-    {
-	bool error = false;
-
-    if (toparse == DATE_FORMAT_EXTENDED) {
-	    //parse "%Y-%m-%d %H:%M:%S"
-	    try {
-		std::regex regex("([^\\s]+)\\s([^\\s]+)");
-		std::sregex_iterator next(date.begin(), date.end(), regex);
-		std::sregex_iterator end;
-
-		if (next != end) {
-
-		    std::smatch match = *next;
-
-		    if (match.size() == 3) {
-            fromString(match[1].str(), DATE_FORMAT_YMD);
-            fromString(match[2].str(), DATE_FORMAT_HMS);
-		    } else {
-			error = true;
-		    }
-
-		} else {
-		    error =true;
-		}
-	    } catch (const std::exception& e ){
-		error = true;
-	    }
-	} else {
-	    //parse "%Y-%m-%d" or "%H:%M:%S"
-	    unsigned int nbmatches = 0;
-	    try {
-		std::regex regex("[0-9]+|[^0-9]");
-		std::sregex_iterator next(date.begin(), date.end(), regex);
-		std::sregex_iterator end;
-		while (next != end) {
-		    std::smatch match = *next;
-		    nbmatches++;
-		    if (nbmatches == 1) {
-            if (toparse == DATE_FORMAT_YMD) {
-			    myear = std::stol(match.str());
-			} else {
-			    mhours = std::stol(match.str());
-			}
-		    } else if (nbmatches == 3) {
-            if (toparse == DATE_FORMAT_YMD) {
-			    mmonth = std::stol(match.str());
-			} else {
-			    mminutes = std::stol(match.str());
-			}
-		    } else if (nbmatches == 5) {
-            if (toparse == DATE_FORMAT_YMD) {
-			    mday = std::stol(match.str());
-			} else {
-			    mseconds = std::stol(match.str());
-			}
-		    }
-		    next++;
-		}
-	    } catch (const std::exception& e ){
-		error = true;
-	    }
-	    error = error or (nbmatches != 5);
-	}
-	return error;
-    }
-
-    //init from julian day eg: 2454115.05486
-    void fromJulianDay(double julianDay) noexcept
-    {
-
-	double partofday, J;
-	partofday = std::modf(julianDay, &J);
-
-	initPartOfDay(partofday);
-
-	//parameters for gregorian calendar (cf wikipedia)
-	int y=4716;
-	int j=1401;
-	int m=2;
-	int n=12;
-	int r=4;
-	int p=1461;
-	int v=3;
-	int u=5;
-	int s=153;
-	int w=2;
-	int B=274277;
-	int C=-38;
-
-	long f = J + j + (((4 * J + B) / 146097) * 3) / 4 + C;
-	long e = r * f + v;
-	long g = (e % p) / r;
-	long h = u * g + w;
-	mday = (h % s) / u + 1;
-	mmonth = ((h / s + m) % n) + 1;
-	myear = (e / p) - y + (n + m - mmonth) / n;
-    }
-
-    bool equals(const intern_date& d) const noexcept
-    {
-	return (myear == d.myear and mmonth == d.mmonth and mday == d.mday);
-    }
-
-    bool inf(const intern_date& d) const noexcept
-    {
-	if (myear < d.myear)
-	    return true;
-
-	if (myear > d.myear)
-	    return false;
-
-	if (mmonth < d.mmonth)
-	    return true;
-
-	if (mmonth > d.mmonth)
-	    return false;
-
-	return mday < d.mday;
-    }
-
-    bool sup(const intern_date& d) const noexcept
-    {
-	if (myear < d.myear)
-	    return false;
-
-	if (myear > d.myear)
-	    return true;
-
-	if (mmonth < d.mmonth)
-	    return false;
-
-	if (mmonth > d.mmonth)
-	    return true;
-
-	return mday > d.mday;
-    }
-
-    //tells if a date is valid
-    bool isValid() const noexcept
-    {
-	if (1 > mmonth or mmonth > 12)
-	    return false;
-
-	if (1 > mday or mday > intern_aMonth(myear, mmonth))
-	    return false;
-
-	if (0 > mhours or mhours > 23)
-	    return false;
-
-	if (0 > mminutes or mminutes > 60)
-	    return false;
-
-	if (0 > mseconds or mseconds > 60)
-	    return false;
-
-	return true;
-    }
-
-    //add months to the current date
-    void addMonths(unsigned int months) noexcept
-    {
-	mmonth += months;
-	while (mmonth > 12) {
-	    myear ++;
-	    mmonth -= 12;
-	    long nbDaysInMonth = intern_aMonth(mmonth, myear);
-	    if (mday > nbDaysInMonth) {
-		mmonth ++;
-		mday -= nbDaysInMonth;
-	    }
-	}
-    }
-
-    //daynNumber as computed in boost gregorian calendar.. (in wikipedia)
-    //12h Jan 1, 4713 BC (-4713-01-BC)
-    long julianDayNumber() const noexcept
-    {
-	unsigned short a = static_cast<unsigned short>((14-mmonth)/12);
-	unsigned short y = static_cast<unsigned short>(myear + 4800 - a);
-	unsigned short m = static_cast<unsigned short>(mmonth + 12*a - 3);
-
-	return mday+((153*m+2)/5)+365*y+(y/4)-(y/100)+(y/400)-32045;
-    }
-
-    double julianDay() const noexcept
-    {
-	double res = static_cast<double>(julianDayNumber());
-	res += mhours/24.0;
-	res += mminutes/1440.0;
-	res += mseconds/86400.0;
-	return res;
-    }
-
-    //day of the year (1<>366)
-    long dayOfyear() const noexcept
-    {
-	long ret = 0;
-
-	for (long m = 1; m < mmonth; m++)
-	    ret += intern_aMonth(myear, m);
-
-	ret += mday;
-
-	return ret;
-    }
-
-    //days between a date and end of year (1<>366)
-    long daysUntilEndOfyear() const noexcept
-    {
-	return intern_aYear(myear) - dayOfyear();
-    }
-
-    //from boost date-time library
-    unsigned short dayOfWeek() noexcept
-    {
-	unsigned short a = static_cast<unsigned short>((14-mmonth)/12);
-	unsigned short y = static_cast<unsigned short>(myear - a);
-	unsigned short m = static_cast<unsigned short>(mmonth + 12*a - 2);
-	unsigned short d = static_cast<unsigned short>(
-		(mday + y + (y/4) - (y/100) + (y/400) + (31*m)/12) % 7);
-
-	return d;
-    }
-
-    //from boost date-time library
-    unsigned short weekOfYear() noexcept
-    {
-	unsigned long julianbegin = intern_date(myear, 1, 1, 0).julianDay();
-	unsigned long juliantoday = julianDay();
-	unsigned long day = (julianbegin + 3) % 7;
-	unsigned long week = (juliantoday + day - julianbegin + 4)/7;
-
-	if ((week >= 1) && (week <= 52))
-	    return week;
-
-	if (week == 53) {
-	    if((day==6) ||(day == 5 && intern_isLeapYear(myear))) {
-		return week; //under these circumstances week == 53.
-	    } else {
-		return 1; //monday - wednesday is in week 1 of next year
-	    }
-	}
-	//if the week is not in current year recalculate using the previous
-	//year as the beginning year
-	else if (week == 0) {
-	    julianbegin = intern_date(myear-1, 1, 1, 0).julianDay();
-	    day = (julianbegin + 3) % 7;
-	    week = (juliantoday + day - julianbegin + 4)/7;
-	    return week;
-	}
-
-	return week;  //not reachable -- well except
-	// if day == 5 and is_leap_year != true
-    }
-
-    //days between a date and end of month (0<>31)
-    long idaysUntilEndOfMonth() const noexcept
-    {
-	return intern_aMonth(myear, mmonth)-mday;
-    }
-
-    //nb days between two dates (negative if this is before)
-    long daysUntil(const intern_date& d) const noexcept
-    {
-	if (equals(d))
-	    return 0;
+#include <sstream>
 
-	if (sup(d))
-	    return -d.daysUntil(*this);
+#include <cmath>
+#include <ctime>
 
-	return d.julianDay() - julianDay();
-    }
-};
-
-
-//output format `2011-Jun-09 12:13:21'
-std::string DateTime::currentDate()
-{
-    time_t rawtime;
-    struct tm * timeinfo;
-
-    time (&rawtime);
-    timeinfo = localtime(&rawtime);
-
-    static const char mon_name[][4] = {
-	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
-	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-    };
-
-    char result[26];
-    sprintf(result, "%d-%.3s-%d %.2d:%.2d:%.2d \n",
-	    1900 + timeinfo->tm_year,
-	    mon_name[timeinfo->tm_mon],
-	    timeinfo->tm_mday,
-	    timeinfo->tm_hour,
-	    timeinfo->tm_min, timeinfo->tm_sec);
-
-    return result;
-}
-
-unsigned int DateTime::year(double time)
-{
-    intern_date d;
-    d.fromJulianDay(time);
-    return d.myear;
-}
-
-unsigned int DateTime::month(double time)
-{
-    intern_date d;
-    d.fromJulianDay(time);
-    return d.mmonth;
-}
-
-unsigned int DateTime::dayOfMonth(double time)
-{
-    intern_date d;
-    d.fromJulianDay(time);
-    return d.mday;
-}
-
-unsigned int DateTime::dayOfWeek(double time)
-{
-    intern_date d;
-    d.fromJulianDay(time);
-    return d.dayOfWeek();
-}
-
-unsigned int DateTime::dayOfYear(double time)
-{
-    intern_date d;
-    d.fromJulianDay(time);
-    return d.dayOfyear();
-}
-
-unsigned int DateTime::weekOfYear(double time)
-{
-    intern_date d;
-    d.fromJulianDay(time);
-    return d.weekOfYear();
-}
+namespace artis {
+    namespace utils {
+
+        bool
+        intern_isLeapYear(int year) noexcept
+        {
+            if (year % 4 != 0)
+                return false;
+
+            if (year % 100 != 0)
+                return true;
+
+            if (year % 400 != 0)
+                return false;
+
+            return true;
+        }
+
+        int
+        intern_aYear(int year) noexcept
+        {
+            if (intern_isLeapYear(year))
+                return 366;
+
+            return 365;
+        }
+
+        int
+        intern_aMonth(int year, int month) noexcept
+        {
+            switch (month) {
+            case 1:
+                return 31;
+            case 2:
+                if (intern_isLeapYear(year))
+                    return 29;
+                return 28;
+            case 3:
+                return 31;
+            case 4:
+                return 30;
+            case 5:
+                return 31;
+            case 6:
+                return 30;
+            case 7:
+                return 31;
+            case 8:
+                return 31;
+            case 9:
+                return 30;
+            case 10:
+                return 31;
+            case 11:
+                return 30;
+            case 12:
+                return 31;
+            default:
+                return std::numeric_limits<int>::min();
+            }
+        }
+
+        struct intern_date {
+            int myear{1400};
+            int mmonth{1};
+            int mday{1};
+            int mhours{0};
+            int mminutes{0};
+            int mseconds{0};
+
+            enum STR_FORMAT {
+                extended, //"%Y-%m-%d %H:%M:%S"
+                ymd,      //"%Y-%m-%d"
+                hms       //"%H:%M:%S"
+            };
+
+            intern_date() noexcept = default;
+
+            intern_date(int year, int month, int day, double partofday) noexcept
+                    :myear(year), mmonth(month), mday(day), mhours(0), mminutes(0), mseconds(0)
+            {
+                initPartOfDay(partofday);
+            }
+
+            intern_date(const intern_date& d) = default;
+
+            intern_date& operator=(const intern_date& d) = default;
+
+            intern_date(intern_date&& d) = default;
+
+            intern_date& operator=(intern_date&& d) = default;
+
+            void initPartOfDay(double partofday) noexcept // between 0 and 1
+            {
+                double f = partofday * 24.0;
+                mhours = static_cast<int>(std::floor(f));
+                f -= std::floor(f);
+
+                f *= 60.0;
+                mminutes = static_cast<int>(std::floor(f));
+                f -= std::floor(f);
+
+                f *= 60.0;
+                mseconds = static_cast<int>(std::floor(f));
+            }
+
+            std::string toString(STR_FORMAT fmt) noexcept
+            {
+                std::stringstream ss;
+
+                if (fmt != hms) {
+                    ss << myear << "-";
+                    if (mmonth < 10) {
+                        ss << "0";
+                    }
+                    ss << mmonth << "-";
+                    if (mday < 10) {
+                        ss << "0";
+                    }
+                    ss << mday;
+                }
+                if (fmt == extended) {
+                    ss << " ";
+                }
+                if (fmt != ymd) {
+                    if (mhours < 10) {
+                        ss << "0";
+                    }
+                    ss << mhours << ":";
+                    if (mminutes < 10) {
+                        ss << "0";
+                    }
+                    ss << mminutes << ":";
+                    if (mseconds < 10) {
+                        ss << "0";
+                    }
+                    ss << mseconds;
+                }
+                return ss.str();
+            }
+
+            std::string toString(DateFormat fmt) noexcept
+            {
+                std::stringstream ss;
+
+                if (fmt != DATE_FORMAT_HMS) {
+                    ss << myear << "-";
+                    if (mmonth < 10) {
+                        ss << "0";
+                    }
+                    ss << mmonth << "-";
+                    if (mday < 10) {
+                        ss << "0";
+                    }
+                    ss << mday;
+                }
+                if (fmt == DATE_FORMAT_EXTENDED) {
+                    ss << " ";
+                }
+                if (fmt != DATE_FORMAT_YMD) {
+                    if (mhours < 10) {
+                        ss << "0";
+                    }
+                    ss << mhours << ":";
+                    if (mminutes < 10) {
+                        ss << "0";
+                    }
+                    ss << mminutes << ":";
+                    if (mseconds < 10) {
+                        ss << "0";
+                    }
+                    ss << mseconds;
+                }
+                return ss.str();
+            }
+
+            // format : not extended = "%Y-%m-%d"
+            //         extended     = "%Y-%m-%d %H:%M:%S"
+            // return true if no error
+            bool fromString(const std::string& date, STR_FORMAT toparse) noexcept
+            {
+                bool error = false;
+
+                if (toparse == extended) {
+                    // parse "%Y-%m-%d %H:%M:%S"
+                    try {
+                        std::regex regex(R"(([^\s]+)\s([^\s]+))");
+                        std::sregex_iterator next(date.begin(), date.end(), regex);
+                        std::sregex_iterator end;
+
+                        if (next != end) {
+
+                            std::smatch match = *next;
+
+                            if (match.size() == 3) {
+                                fromString(match[1].str(), ymd);
+                                fromString(match[2].str(), hms);
+                            } else {
+                                error = true;
+                            }
+
+                        } else {
+                            error = true;
+                        }
+                    }
+                    catch (const std::exception& e) {
+                        error = true;
+                    }
+                } else {
+                    // parse "%Y-%m-%d" or "%H:%M:%S"
+                    int nbmatches = 0;
+
+                    try {
+                        std::regex regex("[0-9]+|[^0-9]");
+                        std::sregex_iterator next(date.begin(), date.end(), regex);
+                        std::sregex_iterator end;
+                        while (next != end) {
+                            std::smatch match = *next;
+                            nbmatches++;
+                            if (nbmatches == 1) {
+                                if (toparse == ymd) {
+                                    myear = std::stoi(match.str());
+                                } else {
+                                    mhours = std::stoi(match.str());
+                                }
+                            } else if (nbmatches == 3) {
+                                if (toparse == ymd) {
+                                    mmonth = std::stoi(match.str());
+                                } else {
+                                    mminutes = std::stoi(match.str());
+                                }
+                            } else if (nbmatches == 5) {
+                                if (toparse == ymd) {
+                                    mday = std::stoi(match.str());
+                                } else {
+                                    mseconds = std::stoi(match.str());
+                                }
+                            }
+                            next++;
+                        }
+                    }
+                    catch (const std::exception& e) {
+                        error = true;
+                    }
+                    error = error or (nbmatches != 5);
+                }
+                return error;
+            }
+
+            // init from julian day eg: 2454115.05486
+            void fromJulianDay(double julianDay) noexcept
+            {
+                double partofday, J;
+                partofday = std::modf(julianDay, &J);
+
+                initPartOfDay(partofday);
+
+                // parameters for gregorian calendar (cf wikipedia)
+                int y = 4716;
+                int j = 1401;
+                int m = 2;
+                int n = 12;
+                int r = 4;
+                int p = 1461;
+                int v = 3;
+                int u = 5;
+                int s = 153;
+                int w = 2;
+                int B = 274277;
+                int C = -38;
+
+                auto f =
+                        static_cast<int>(J + j + (((4 * J + B) / 146097) * 3) / 4 + C);
+                int e = r * f + v;
+                int g = (e % p) / r;
+                int h = u * g + w;
+                mday = (h % s) / u + 1;
+                mmonth = ((h / s + m) % n) + 1;
+                myear = (e / p) - y + (n + m - mmonth) / n;
+            }
+
+            bool equals(const intern_date& d) const noexcept
+            {
+                return (myear == d.myear and mmonth == d.mmonth and mday == d.mday);
+            }
+
+            bool inf(const intern_date& d) const noexcept
+            {
+                if (myear < d.myear)
+                    return true;
+
+                if (myear > d.myear)
+                    return false;
+
+                if (mmonth < d.mmonth)
+                    return true;
+
+                if (mmonth > d.mmonth)
+                    return false;
+
+                return mday < d.mday;
+            }
+
+            bool sup(const intern_date& d) const noexcept
+            {
+                if (myear < d.myear)
+                    return false;
+
+                if (myear > d.myear)
+                    return true;
+
+                if (mmonth < d.mmonth)
+                    return false;
+
+                if (mmonth > d.mmonth)
+                    return true;
+
+                return mday > d.mday;
+            }
+
+            // tells if a date is valid
+            bool isValid() const noexcept
+            {
+                if (1 > mmonth or mmonth > 12)
+                    return false;
+
+                if (1 > mday or mday > intern_aMonth(myear, mmonth))
+                    return false;
+
+                if (0 > mhours or mhours > 23)
+                    return false;
+
+                if (0 > mminutes or mminutes > 60)
+                    return false;
+
+                if (0 > mseconds or mseconds > 60)
+                    return false;
+
+                return true;
+            }
+
+            // add months to the current date
+            void addMonths(int months) noexcept
+            {
+                mmonth += months;
+                while (mmonth > 12) {
+                    myear++;
+                    mmonth -= 12;
+                    int nbDaysInMonth = intern_aMonth(mmonth, myear);
+                    if (mday > nbDaysInMonth) {
+                        mmonth++;
+                        mday -= nbDaysInMonth;
+                    }
+                }
+            }
+
+            // daynNumber as computed in boost gregorian calendar.. (in wikipedia)
+            // 12h Jan 1, 4713 BC (-4713-01-BC)
+            int julianDayNumber() const noexcept
+            {
+                auto a = static_cast<int>((14 - mmonth) / 12);
+                auto y = static_cast<int>(myear + 4800 - a);
+                auto m = static_cast<int>(mmonth + 12 * a - 3);
+
+                return mday + ((153 * m + 2) / 5) + 365 * y + (y / 4) - (y / 100) +
+                        (y / 400) - 32045;
+            }
+
+            double julianDay() const noexcept
+            {
+                auto res = static_cast<double>(julianDayNumber());
+                res += static_cast<double>(mhours) / 24.0;
+                res += static_cast<double>(mminutes) / 1440.0;
+                res += static_cast<double>(mseconds) / 86400.0;
+                return res;
+            }
+
+            // day of the year (1<>366)
+            int dayOfyear() const noexcept
+            {
+                int ret = 0;
+
+                for (int m = 1; m < mmonth; m++)
+                    ret += intern_aMonth(myear, m);
+
+                ret += mday;
+
+                return ret;
+            }
+
+            // days between a date and end of year (1<>366)
+            int daysUntilEndOfyear() const noexcept
+            {
+                return intern_aYear(myear) - dayOfyear();
+            }
+
+            // from boost date-time library
+            int dayOfWeek() noexcept
+            {
+                auto a = static_cast<int>((14 - mmonth) / 12);
+                auto y = static_cast<int>(myear - a);
+                auto m = static_cast<int>(mmonth + 12 * a - 2);
+                auto d = static_cast<int>(
+                        (mday + y + (y / 4) - (y / 100) + (y / 400) + (31 * m) / 12) % 7);
+
+                return d;
+            }
+
+            // from boost date-time library
+            int weekOfYear() noexcept
+            {
+                auto julianbegin =
+                        static_cast<int>(intern_date(myear, 1, 1, 0).julianDay());
+                auto juliantoday = static_cast<int>(julianDay());
+                int day = (julianbegin + 3) % 7;
+                int week = (juliantoday + day - julianbegin + 4) / 7;
+
+                if ((week >= 1) && (week <= 52))
+                    return static_cast<short>(week);
+
+                if (week == 53) {
+                    if ((day == 6) || (day == 5 && intern_isLeapYear(myear))) {
+                        return static_cast<short>(
+                                week); // under these circumstances week == 53.
+                    } else {
+                        return 1; // monday - wednesday is in week 1 of next year
+                    }
+                }
+                    // if the week is not in current year recalculate using the previous
+                    // year as the beginning year
+                else if (week == 0) {
+                    julianbegin =
+                            static_cast<int>(intern_date(myear - 1, 1, 1, 0).julianDay());
+                    day = (julianbegin + 3) % 7;
+                    week = (juliantoday + day - julianbegin + 4) / 7;
+                    return week;
+                }
+
+                return week; // not reachable -- well except
+                // if day == 5 and is_leap_year != true
+            }
+
+            // days between a date and end of month (0<>31)
+            int idaysUntilEndOfMonth() const noexcept
+            {
+                return intern_aMonth(myear, mmonth) - mday;
+            }
+
+            // nb days between two dates (negative if this is before)
+            int daysUntil(const intern_date& d) const noexcept
+            {
+                if (equals(d))
+                    return 0;
+
+                if (sup(d))
+                    return -d.daysUntil(*this);
+
+                return static_cast<int>(d.julianDay() - julianDay());
+            }
+        };
+
+// output format `2011-Jun-09 12:13:21'
+        std::string DateTime::currentDate()
+        {
+            static const char mon_name[][4] = {"Jan", "Feb", "Mar", "Apr",
+                                               "May", "Jun", "Jul", "Aug",
+                                               "Sep", "Oct", "Nov", "Dec"};
+
+            time_t rawtime;
+            struct tm* timeinfo;
+
+            time(&rawtime);
+            timeinfo = localtime(&rawtime);
+
+            char result[26];
+            sprintf(result, "%d-%.3s-%d %.2d:%.2d:%.2d \n",
+                    1900 + timeinfo->tm_year,
+                    mon_name[timeinfo->tm_mon],
+                    timeinfo->tm_mday,
+                    timeinfo->tm_hour,
+                    timeinfo->tm_min, timeinfo->tm_sec);
+
+            return result;
+        }
+
+        unsigned int DateTime::year(double time)
+        {
+            intern_date d;
+            d.fromJulianDay(time);
+            return d.myear;
+        }
+
+        unsigned int DateTime::month(double time)
+        {
+            intern_date d;
+            d.fromJulianDay(time);
+            return d.mmonth;
+        }
+
+        unsigned int DateTime::dayOfMonth(double time)
+        {
+            intern_date d;
+            d.fromJulianDay(time);
+            return d.mday;
+        }
+
+        unsigned int DateTime::dayOfWeek(double time)
+        {
+            intern_date d;
+            d.fromJulianDay(time);
+            return d.dayOfWeek();
+        }
+
+        unsigned int DateTime::dayOfYear(double time)
+        {
+            intern_date d;
+            d.fromJulianDay(time);
+            return d.dayOfyear();
+        }
+
+        unsigned int DateTime::weekOfYear(double time)
+        {
+            intern_date d;
+            d.fromJulianDay(time);
+            return d.weekOfYear();
+        }
 
 /*  - - - - - - - - - - - - - --ooOoo-- - - - - - - - - - - -  */
 
-bool DateTime::isLeapYear(double time)
-{
-    intern_date d;
-    d.fromJulianDay(time);
-    return intern_isLeapYear(d.myear);;
-}
+        bool DateTime::isLeapYear(double time)
+        {
+            intern_date d;
+            d.fromJulianDay(time);
+            return intern_isLeapYear(d.myear);;
+        }
 
 /*  - - - - - - - - - - - - - --ooOoo-- - - - - - - - - - - -  */
 
-double DateTime::aYear(double time)
-{
-    return isLeapYear(time) ? 366 : 365;
-}
-
-double DateTime::aMonth(double time)
-{
-    intern_date d;
-    d.fromJulianDay(time);
-    return(intern_aMonth(d.myear, d.mmonth));
-
-}
-
-double DateTime::years(double time, unsigned int n)
-{
-
-    intern_date d1;
-    d1.fromJulianDay(time);
-    intern_date d2(d1);
-    d2.myear += n;
-    return d2.julianDay() - d1.julianDay();
-}
-
-double DateTime::months(double time, unsigned int n)
-{
-
-    intern_date d1;
-    d1.fromJulianDay(time);
-    intern_date d2(d1);
-    d2.addMonths(n);
-    return d2.julianDay() - d1.julianDay();
-}
-
-DateTimeUnitOptions DateTime::convertUnit(const std::string& unit)
-{
-    if (unit == "day") {
-	return DATE_TIME_UNIT_DAY;
-    } else if (unit == "week") {
-	return DATE_TIME_UNIT_WEEK;
-    } else if (unit == "month") {
-	return DATE_TIME_UNIT_MONTH;
-    } else if (unit == "year") {
-	return DATE_TIME_UNIT_YEAR;
-    } else {
-	return DATE_TIME_UNIT_DAY;
-    }
-}
-
-double DateTime::duration(double time, double duration,
-	DateTimeUnitOptions unit)
-{
-    switch (unit) {
-	case DATE_TIME_UNIT_NONE:
-	case DATE_TIME_UNIT_DAY:
-	    return days(duration);
-	case DATE_TIME_UNIT_WEEK:
-	    return weeks(duration);
-	case DATE_TIME_UNIT_MONTH:
-	    return months(time, duration);
-	case DATE_TIME_UNIT_YEAR:
-	    return years(time, duration);
+        double DateTime::aYear(double time)
+        {
+            return isLeapYear(time) ? 366 : 365;
+        }
+
+        double DateTime::aMonth(double time)
+        {
+            intern_date d;
+            d.fromJulianDay(time);
+            return (intern_aMonth(d.myear, d.mmonth));
+        }
+
+        double DateTime::years(double time, unsigned int n)
+        {
+
+            intern_date d1;
+            d1.fromJulianDay(time);
+            intern_date d2(d1);
+            d2.myear += n;
+            return d2.julianDay() - d1.julianDay();
+        }
+
+        double DateTime::months(double time, unsigned int n)
+        {
+
+            intern_date d1;
+            d1.fromJulianDay(time);
+            intern_date d2(d1);
+            d2.addMonths(n);
+            return d2.julianDay() - d1.julianDay();
+        }
+
+        DateTimeUnitOptions DateTime::convertUnit(const std::string& unit)
+        {
+            if (unit == "day") {
+                return DATE_TIME_UNIT_DAY;
+            } else if (unit == "week") {
+                return DATE_TIME_UNIT_WEEK;
+            } else if (unit == "month") {
+                return DATE_TIME_UNIT_MONTH;
+            } else if (unit == "year") {
+                return DATE_TIME_UNIT_YEAR;
+            } else {
+                return DATE_TIME_UNIT_DAY;
+            }
+        }
+
+        double DateTime::duration(double time, double duration, DateTimeUnitOptions unit)
+        {
+            switch (unit) {
+            case DATE_TIME_UNIT_NONE:
+            case DATE_TIME_UNIT_DAY:
+                return days(static_cast<int>(duration));
+            case DATE_TIME_UNIT_WEEK:
+                return weeks(static_cast<int>(duration));
+            case DATE_TIME_UNIT_MONTH:
+                return months(time, static_cast<int>(duration));
+            case DATE_TIME_UNIT_YEAR:
+                return years(time, static_cast<int>(duration));
+            }
+            return 0;
+        }
+
+        std::string DateTime::toJulianDayNumber(int date)
+        {
+            intern_date d;
+            d.fromJulianDay(static_cast<double>(date));
+            return d.toString(intern_date::ymd);
+        }
+
+// parsing "2001-10-9"
+        long int DateTime::toJulianDayNumber(const std::string& date)
+        {
+            intern_date d;
+            d.fromString(date, intern_date::ymd);
+            return d.julianDayNumber();
+        }
+
+        std::string DateTime::toJulianDay(double date)
+        {
+            intern_date d;
+            d.fromJulianDay(date);
+            return d.toString(intern_date::extended);
+        }
+
+        std::string DateTime::toJulianDayFmt(double date, DateFormat format)
+        {
+            intern_date d;
+            d.fromJulianDay(date);
+            return d.toString(format);
+        }
+
+        // parsing "2001-10-9 hh:mm:ss"
+// if error, then try parsing "2001-10-9"
+        double DateTime::toJulianDay(const std::string& date)
+        {
+
+            intern_date d;
+            bool error = d.fromString(date, intern_date::extended);
+            if (error) {
+                d.fromString(date, intern_date::ymd);
+            }
+            return d.julianDay();
+        }
+
+        bool DateTime::isValidYear(double date)
+        {
+            intern_date d;
+            d.fromJulianDay(date);
+            bool valid = (1399 < d.myear and d.myear < 10000); // boost rule ?
+            return valid;
+        }
+
+        double DateTime::toTime(double date,
+                int& year,
+                int& month,
+                int& day,
+                int& hours,
+                int& minutes,
+                int& seconds)
+        {
+            intern_date d;
+            d.fromJulianDay(date);
+            year = d.myear;
+            month = d.mmonth;
+            day = d.mday;
+
+            hours = d.mhours;
+            minutes = d.mminutes;
+            seconds = d.mseconds;
+
+            return 0.0;
+        }
+
+        void DateTime::currentDate(int& year, int& month, int& day)
+        {
+
+            time_t rawtime;
+            struct tm* timeinfo;
+
+            time(&rawtime);
+            timeinfo = localtime(&rawtime);
+            year = timeinfo->tm_year;
+            month = timeinfo->tm_mon;
+            day = timeinfo->tm_mday;
+        }
     }
-    return 0;
-}
-
-std::string DateTime::toJulianDayNumber(unsigned long date)
-{
-    intern_date d;
-    d.fromJulianDay(static_cast<double>(date));
-    return d.toString(DATE_FORMAT_YMD);
-}
-
-
-//parsing "2001-10-9"
-long DateTime::toJulianDayNumber(const std::string& date)
-{
-    intern_date d;
-    d.fromString(date, DATE_FORMAT_YMD);
-    return d.julianDayNumber();
-}
-
-
-std::string DateTime::toJulianDay(double date)
-{
-    intern_date d;
-    d.fromJulianDay(date);
-    return d.toString(DATE_FORMAT_EXTENDED);
-}
-
-std::string DateTime::toJulianDayFmt(double date, DateFormat format){
-    intern_date d;
-    d.fromJulianDay(date);
-    return d.toString(format);
-}
-
-
-// parsing "2001-10-9 hh:mm:ss"
-double DateTime::toJulianDay(const std::string& date)
-{
-
-    intern_date d;
-    d.fromString(date, DATE_FORMAT_EXTENDED);
-    return d.julianDay();
-}
-
-
-
-bool DateTime::isValidYear(double date)
-{
-    intern_date d;
-    d.fromJulianDay(date);
-    bool valid = (1399 < d.myear and d.myear < 10000);//boost rule ?
-    return valid;
-}
-
-double DateTime::toTime(double date, long& year,
-	long& month, long& day,
-	long& hours, long& minutes,
-	long& seconds)
-{
-    intern_date d;
-    d.fromJulianDay(date);
-    year = d.myear;
-    month = d.mmonth;
-    day = d.mday;
-
-    hours = d.mhours;
-    minutes = d.mminutes;
-    seconds = d.mseconds;
-
-    return 0.0;
-}
-
-void DateTime::currentDate(long& year,
-	long& month,
-	long& day)
-{
-
-    time_t rawtime;
-    struct tm * timeinfo;
-
-    time (&rawtime);
-    timeinfo = localtime (&rawtime);
-    year = timeinfo->tm_year;
-    month = timeinfo->tm_mon;
-    day = timeinfo->tm_mday;
-}
-
-} }
+}

+ 304 - 305
src/artis/utils/DateTime.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -35,310 +35,309 @@
 
 #include <artis/utils/Exception.hpp>
 
-namespace artis { namespace utils {
-
-enum DateTimeUnitOptions
-{
-    DATE_TIME_UNIT_NONE,
-    DATE_TIME_UNIT_DAY,
-    DATE_TIME_UNIT_WEEK,
-    DATE_TIME_UNIT_MONTH,
-    DATE_TIME_UNIT_YEAR
-};
-
-enum DateFormat
-{
-    DATE_FORMAT_EXTENDED, //"%Y-%m-%d %H:%M:%S"
-    DATE_FORMAT_YMD,      //"%Y-%m-%d"
-    DATE_FORMAT_HMS       //"%H:%M:%S"
-};
-
-class DateTime
-{
-public:
-    /**
-     * @brief Write the current date and time conform to RFC 822.
-     * @code
-     * std::cout << "currentDate(): `"
-     *           << vle::utils::DateTime::currentDate()
-     *           << "'\n";
-     *
-     * // Display: currentDate(): `2011-Jun-09 12:13:21'
-     * @endcode
-     * @return string representation of date.
-     */
-    static std::string currentDate();
-
-                                  /* * * * */
-
-    /**
-     * @brief Get the year in the simulation time.
-     * @code
-     * vle::utils::DateTime::year(2451545) == 2000u;
-     * @endcode
-     * @param time The simulation time.
-     * @return An unsigned int.
-     */
-    static unsigned int year(double time);
-
-    /**
-     * @brief Get the month in the simulation time.
-     * @code
-     * vle::utils::DateTime::month(2451545) == 1u;
-     * @endcode
-     * @param time The simulation time.
-     * @return An unsigned int.
-     */
-    static unsigned int month(double time);
-
-    /**
-     * @brief Get the day of the month in the simulation time.
-     * @code
-     * vle::utils::DateTime::dayOfMonth((2451545)) == 1u;
-     * @endcode
-     * @param time The simulation time.
-     * @return An unsigned int.
-     */
-    static unsigned int dayOfMonth(double time);
-
-    /**
-     * @brief Get the day in the week of the simulation time.
-     * @code
-     * vle::utils::DateTime::dayOfWeek((2451545)) == 6u;
-     * @endcode
-     * @param time The simulation time.
-     * @return An unsigned int.
-     */
-    static unsigned int dayOfWeek(double time);
-
-    /**
-     * @brief Get the day in the year of the simulation time.
-     * @code
-     * vle::utils::DateTime::dayOfYear((2451545)) == 1u;
-     * @endcode
-     * @param time The simulation time.
-     * @return An unsigned int.
-     */
-    static unsigned int dayOfYear(double time);
-
-    /**
-     * @brief Get the week in the year of the simulation time.
-     * @code
-     * vle::utils::DateTime::dayOfYear((2451545)) == 1u;
-     * @endcode
-     * @param time The simulation time.
-     * @return An unsigned int.
-     */
-    static unsigned int weekOfYear(double time);
-
-    /**
-     * @brief Check if the simulation time is a leap year.
-     * @param time The simulation time.
-     * @return true if time is a leap year, false otherwise.
-     */
-    static bool isLeapYear(double time);
-
-    /**
-     * @brief Get the number of day in the year for the simulaton time.
-     * @code
-     * vle::utils::Datime::aYear(2451545) == 366;
-     * @endcode
-     * @param time The simulation time.
-     * @return number of day.
-     */
-    static double aYear(double time);
-
-    /**
-     * @brief Get the number of day in the month for the simulation time.
-     * @code
-     * vle::utils::Datime::aMonth(2451545) == 31;
-     * vle::utils::Datime::aMonth(2451576) == 29;
-     * @endcode
-     * @param time The simulation time.
-     * @return number of day.
-     */
-    static double aMonth(double time);
-
-    /**
-     * @brief Get the number of day in a week.
-     * @return Return 7.
-     */
-    static inline double aWeek() { return 7; }
-
-    /**
-     * @brief Get the number of day in a day.
-     * @return Return 1.
-     */
-    static inline double aDay() { return 1; }
-
-    /**
-     * @brief Get number of days in n-years from the simulation time.
-     * @code
-     * vle::utils::DateTime::years((2451545), 1), 366);
-     * vle::utils::DateTime::years((2451545), 2), 731);
-     * @endcode
-     * @param time The simulation time.
-     * @param n The number of years.
-     * @return The number of days in n-years.
-     */
-    static double years(double time, unsigned int n);
-
-    /**
-     * @brief Get number of days in n-months from the simulation time.
-     * @code
-     * vle::utils::DateTime::months((2451545), 2) = 60;
-     * @endcode
-     * @param time The simulation time.
-     * @param n The number of weeks.
-     * @return The number of days in n-months.
-     */
-    static double months(double time, unsigned int n);
-
-    /**
-     * @brief Get number of days in n-weeks.
-     * @param n Number of weeks.
-     * @return n * 7.
-     */
-    static inline double weeks(unsigned int n) { return (int)(7 * n); }
-
-    /**
-     * @brief Get number of days in n-days.
-     * @param n Number of days.
-     * @return n.
-     */
-    static inline double days(unsigned int n) { return (int)n; }
-
-    /**
-     * @brief Convert std::string unit ("day", "week", "month", "year") into
-     * the DateTime::Unit type.
-     * @param unit The std::string unit to convert.
-     * @return The convertion of Day if error.
-     */
-    static DateTimeUnitOptions convertUnit(const std::string& unit);
-
-    /**
-     * @brief A easy function to call days(), weeks(), months() or years()
-     * using a DateTime::Unit type.
-     * @param time The simulation date (useless for Day, Week).
-     * @param duration The number of DateTime::Unit.
-     * @param unit The unit.
-     * @return A number of day.
-     */
-    static double duration(double time,
-                           double duration,
-                           DateTimeUnitOptions unit);
-
-                                  /* * * * */
-
-    /**
-     * @brief Convert an julian day number into a string.
-     * @code
-     * vle::utils::DateTime::toJulianDayNumber(2452192) = "2001-10-9";
-     * @endcode
-     * @param date The date to convert.
-     * @return A string representation of the julian day.
-     */
-    static std::string toJulianDayNumber(unsigned long date);
-
-    /**
-     * @brief Convert a string into a julian day number;
-     * @code
-     * vle::utils::DateTime::toJulianDayNumber("2001-10-9") = 2452192;
-     * @endcode
-     * @param date The date to convert.
-     * @return A julian day number.
-     */
-    static long toJulianDayNumber(const std::string& date);
-
-    /**
-     * @brief Convert a julian date into a string.
-     * @code
-     * vle::utils::DateTime::toJulianDay(2454115.05486)) = "2001-10-9 hh:mm:ss";
-     * @endcode
-     * @param date The date to convert.
-     * @return A string representation of the julian day.
-     */
-    static std::string toJulianDay(double date);
-
-    /**
-     * @brief Convert a string into a julian day.
-     * @code
-     * vle::utils::DateTime::toJulianDay("2001-10-9 hh:mm:ss") = 2454115.05486;
-     * @endcode
-     * @param date The date to convert.
-     * @return A string representation of the julian day.
-     */
-    static double toJulianDay(const std::string& date);
-
-    /**
-     * @brief Convert a julian date into a string in a given format.
-     * @code
-     * artis::utils::DateTime::toJulianDay(2454115.05486, DATE_FORMAT_YMD)) = "2001-10-9";
-     * @endcode
-     * @param date The date to convert.
-     * @param format The string format from enum artis::utils::DateFormat.
-     * @return A string representation of the julian day.
-     */
-    static std::string toJulianDayFmt(double date, artis::utils::DateFormat format);
-
-                                  /* * * * */
-
-    /**
-     * @brief Check if the date is a valid year in gregorian calendard.
-     *
-     * @param date The date to check.
-     *
-     * @return True if date is a valid year, false otherwise.
-     */
-    static bool isValidYear(double date);
-
-    /**
-     * @brief Explode the specified date attribute to year, month, day in the
-     * month, hours, minutes and seconds.
-     *
-     * @param date The date to convert.
-     * @param year Output parameter to represent year.
-     * @param month Output parameter to represent month.
-     * @param day Output parameter to represent day in a month (1..31).
-     * @param hours Output parameter to represent hours in date.
-     * @param minutes Output parameter to represent minutes in date.
-     * @param seconds Output parameter to represent seconds in date.
-     *
-     * @throw utils::ArgError error to convert the date.
-     *
-     * @return The remainder of the conversion.
-     */
-    static double toTime(double date,
-                         long& year,
-                         long& month,
-                         long& day,
-                         long& hours,
-                         long& minutes,
-                         long& seconds);
-
-    /**
-     * @brief Explode current date to year, month, day in the
-     * month, hours, minutes and seconds.
-     *
-     * @param year Output parameter to represent year.
-     * @param month Output parameter to represent month.
-     * @param day Output parameter to represent day in a month (1..31).
-     *
-     */
-    static void currentDate(long& year,
-                            long& month,
-                            long& day);
-
-    static void format_date(const std::string& str, std::string& date)
-    {
-        std::vector < std::string > list;
-
-        boost::split(list, str, boost::is_any_of("-/"));
-        date = (boost::format("%1%/%2%/%3%") % list[2] % list[1] %
-                list[0]).str();
-    }
-};
+namespace artis {
+    namespace utils {
+
+        enum DateTimeUnitOptions {
+            DATE_TIME_UNIT_NONE,
+            DATE_TIME_UNIT_DAY,
+            DATE_TIME_UNIT_WEEK,
+            DATE_TIME_UNIT_MONTH,
+            DATE_TIME_UNIT_YEAR
+        };
+
+        enum DateFormat {
+            DATE_FORMAT_EXTENDED, //"%Y-%m-%d %H:%M:%S"
+            DATE_FORMAT_YMD,      //"%Y-%m-%d"
+            DATE_FORMAT_HMS       //"%H:%M:%S"
+        };
+
+        class DateTime {
+        public:
+            /**
+             * @brief Write the current date and time conform to RFC 822.
+             * @code
+             * std::cout << "currentDate(): `"
+             *           << vle::utils::DateTime::currentDate()
+             *           << "'\n";
+             *
+             * // Display: currentDate(): `2011-Jun-09 12:13:21'
+             * @endcode
+             * @return string representation of date.
+             */
+            static std::string currentDate();
+
+            /* * * * */
+
+            /**
+             * @brief Get the year in the simulation time.
+             * @code
+             * vle::utils::DateTime::year(2451545) == 2000u;
+             * @endcode
+             * @param time The simulation time.
+             * @return An unsigned int.
+             */
+            static unsigned int year(double time);
+
+            /**
+             * @brief Get the month in the simulation time.
+             * @code
+             * vle::utils::DateTime::month(2451545) == 1u;
+             * @endcode
+             * @param time The simulation time.
+             * @return An unsigned int.
+             */
+            static unsigned int month(double time);
+
+            /**
+             * @brief Get the day of the month in the simulation time.
+             * @code
+             * vle::utils::DateTime::dayOfMonth((2451545)) == 1u;
+             * @endcode
+             * @param time The simulation time.
+             * @return An unsigned int.
+             */
+            static unsigned int dayOfMonth(double time);
+
+            /**
+             * @brief Get the day in the week of the simulation time.
+             * @code
+             * vle::utils::DateTime::dayOfWeek((2451545)) == 6u;
+             * @endcode
+             * @param time The simulation time.
+             * @return An unsigned int.
+             */
+            static unsigned int dayOfWeek(double time);
+
+            /**
+             * @brief Get the day in the year of the simulation time.
+             * @code
+             * vle::utils::DateTime::dayOfYear((2451545)) == 1u;
+             * @endcode
+             * @param time The simulation time.
+             * @return An unsigned int.
+             */
+            static unsigned int dayOfYear(double time);
+
+            /**
+             * @brief Get the week in the year of the simulation time.
+             * @code
+             * vle::utils::DateTime::dayOfYear((2451545)) == 1u;
+             * @endcode
+             * @param time The simulation time.
+             * @return An unsigned int.
+             */
+            static unsigned int weekOfYear(double time);
+
+            /**
+             * @brief Check if the simulation time is a leap year.
+             * @param time The simulation time.
+             * @return true if time is a leap year, false otherwise.
+             */
+            static bool isLeapYear(double time);
+
+            /**
+             * @brief Get the number of day in the year for the simulaton time.
+             * @code
+             * vle::utils::Datime::aYear(2451545) == 366;
+             * @endcode
+             * @param time The simulation time.
+             * @return number of day.
+             */
+            static double aYear(double time);
+
+            /**
+             * @brief Get the number of day in the month for the simulation time.
+             * @code
+             * vle::utils::Datime::aMonth(2451545) == 31;
+             * vle::utils::Datime::aMonth(2451576) == 29;
+             * @endcode
+             * @param time The simulation time.
+             * @return number of day.
+             */
+            static double aMonth(double time);
+
+            /**
+             * @brief Get the number of day in a week.
+             * @return Return 7.
+             */
+            static inline double aWeek() { return 7; }
+
+            /**
+             * @brief Get the number of day in a day.
+             * @return Return 1.
+             */
+            static inline double aDay() { return 1; }
+
+            /**
+             * @brief Get number of days in n-years from the simulation time.
+             * @code
+             * vle::utils::DateTime::years((2451545), 1), 366);
+             * vle::utils::DateTime::years((2451545), 2), 731);
+             * @endcode
+             * @param time The simulation time.
+             * @param n The number of years.
+             * @return The number of days in n-years.
+             */
+            static double years(double time, unsigned int n);
+
+            /**
+             * @brief Get number of days in n-months from the simulation time.
+             * @code
+             * vle::utils::DateTime::months((2451545), 2) = 60;
+             * @endcode
+             * @param time The simulation time.
+             * @param n The number of weeks.
+             * @return The number of days in n-months.
+             */
+            static double months(double time, unsigned int n);
+
+            /**
+             * @brief Get number of days in n-weeks.
+             * @param n Number of weeks.
+             * @return n * 7.
+             */
+            static inline double weeks(unsigned int n) { return (int) (7 * n); }
+
+            /**
+             * @brief Get number of days in n-days.
+             * @param n Number of days.
+             * @return n.
+             */
+            static inline double days(unsigned int n) { return (int) n; }
+
+            /**
+             * @brief Convert std::string unit ("day", "week", "month", "year") into
+             * the DateTime::Unit type.
+             * @param unit The std::string unit to convert.
+             * @return The convertion of Day if error.
+             */
+            static DateTimeUnitOptions convertUnit(const std::string& unit);
+
+            /**
+             * @brief A easy function to call days(), weeks(), months() or years()
+             * using a DateTime::Unit type.
+             * @param time The simulation date (useless for Day, Week).
+             * @param duration The number of DateTime::Unit.
+             * @param unit The unit.
+             * @return A number of day.
+             */
+            static double duration(double time,
+                    double duration,
+                    DateTimeUnitOptions unit);
+
+            /* * * * */
+
+            /**
+             * @brief Convert an julian day number into a string.
+             * @code
+             * vle::utils::DateTime::toJulianDayNumber(2452192) = "2001-10-9";
+             * @endcode
+             * @param date The date to convert.
+             * @return A string representation of the julian day.
+             */
+            static std::string toJulianDayNumber(int date);
+
+            /**
+             * @brief Convert a string into a julian day number;
+             * @code
+             * vle::utils::DateTime::toJulianDayNumber("2001-10-9") = 2452192;
+             * @endcode
+             * @param date The date to convert.
+             * @return A julian day number.
+             */
+            static long toJulianDayNumber(const std::string& date);
+
+            /**
+             * @brief Convert a julian date into a string.
+             * @code
+             * vle::utils::DateTime::toJulianDay(2454115.05486)) = "2001-10-9 hh:mm:ss";
+             * @endcode
+             * @param date The date to convert.
+             * @return A string representation of the julian day.
+             */
+            static std::string toJulianDay(double date);
+
+            /**
+             * @brief Convert a string into a julian day.
+             * @code
+             * vle::utils::DateTime::toJulianDay("2001-10-9 hh:mm:ss") = 2454115.05486;
+             * @endcode
+             * @param date The date to convert.
+             * @return A string representation of the julian day.
+             */
+            static double toJulianDay(const std::string& date);
+
+            /**
+             * @brief Convert a julian date into a string in a given format.
+             * @code
+             * artis::utils::DateTime::toJulianDay(2454115.05486, DATE_FORMAT_YMD)) = "2001-10-9";
+             * @endcode
+             * @param date The date to convert.
+             * @param format The string format from enum artis::utils::DateFormat.
+             * @return A string representation of the julian day.
+             */
+            static std::string toJulianDayFmt(double date, artis::utils::DateFormat format);
+
+            /* * * * */
+
+            /**
+             * @brief Check if the date is a valid year in gregorian calendard.
+             *
+             * @param date The date to check.
+             *
+             * @return True if date is a valid year, false otherwise.
+             */
+            static bool isValidYear(double date);
+
+            /**
+             * @brief Explode the specified date attribute to year, month, day in the
+             * month, hours, minutes and seconds.
+             *
+             * @param date The date to convert.
+             * @param year Output parameter to represent year.
+             * @param month Output parameter to represent month.
+             * @param day Output parameter to represent day in a month (1..31).
+             * @param hours Output parameter to represent hours in date.
+             * @param minutes Output parameter to represent minutes in date.
+             * @param seconds Output parameter to represent seconds in date.
+             *
+             * @throw utils::ArgError error to convert the date.
+             *
+             * @return The remainder of the conversion.
+             */
+            static double toTime(double date,
+                    int& year,
+                    int& month,
+                    int& day,
+                    int& hours,
+                    int& minutes,
+                    int& seconds);
+
+            /**
+             * @brief Explode current date to year, month, day in the
+             * month, hours, minutes and seconds.
+             *
+             * @param year Output parameter to represent year.
+             * @param month Output parameter to represent month.
+             * @param day Output parameter to represent day in a month (1..31).
+             *
+             */
+            static void currentDate(int& year,
+                    int& month,
+                    int& day);
+
+            static void format_date(const std::string& str, std::string& date)
+            {
+                std::vector<std::string> list;
+
+                boost::split(list, str, boost::is_any_of("-/"));
+                date = (boost::format("%1%/%2%/%3%") % list[2] % list[1] %
+                        list[0]).str();
+            }
+        };
 
-} }
+    }
+}
 
 #endif

+ 14 - 13
src/artis/utils/DoubleTime.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -27,20 +27,21 @@
 
 #include <limits>
 
-namespace artis { namespace utils {
+namespace artis {
+    namespace utils {
 
-template < typename T >
-struct Limits
-{
-    static constexpr T negative_infinity =
-        -std::numeric_limits < T >::infinity();
-    static constexpr T positive_infinity =
-        std::numeric_limits < T >::infinity();
-    static constexpr T null = 0;
-};
+        template<typename T>
+        struct Limits {
+            static constexpr T negative_infinity =
+                    -std::numeric_limits<T>::infinity();
+            static constexpr T positive_infinity =
+                    std::numeric_limits<T>::infinity();
+            static constexpr T null = 0;
+        };
 
-typedef Time < double, Limits < double > > DoubleTime;
+        typedef Time<double, Limits<double> > DoubleTime;
 
-} }
+    }
+}
 
 #endif

+ 69 - 88
src/artis/utils/Exception.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -26,92 +26,73 @@
 #include <boost/format.hpp>
 #include <stdexcept>
 
-namespace artis { namespace utils {
-
-class BaseError : public std::runtime_error
-{
-public:
-    explicit BaseError(const std::string& argv = std::string())
-        : std::runtime_error(argv)
-    { }
-
-    explicit BaseError(const boost::format& argv)
-        : std::runtime_error(argv.str())
-    { }
-};
-
-class FileError : public BaseError
-{
-public:
-    explicit FileError(const std::string& argv = std::string())
-        : BaseError(argv)
-    { }
-
-    explicit FileError(const boost::format& argv)
-        : BaseError(argv)
-    { }
-};
-
-class ParseError : public BaseError
-{
-public:
-    explicit ParseError(const std::string& argv = std::string())
-        : BaseError(argv)
-    { }
-
-    explicit ParseError(const boost::format& argv)
-        : BaseError(argv)
-    { }
-};
-
-class ReadError : public BaseError
-{
-public:
-    explicit ReadError(const std::string& argv = std::string())
-        : BaseError(argv)
-    { }
-
-    explicit ReadError(const boost::format& argv)
-        : BaseError(argv)
-    { }
-};
-
-class InvalidFileFormat : public BaseError
-{
-public:
-    explicit InvalidFileFormat(const std::string& argv = std::string())
-        : BaseError(argv)
-    { }
-
-    explicit InvalidFileFormat(const boost::format& argv)
-        : BaseError(argv)
-    { }
-};
-
-class ErrorInContextFile : public BaseError
-{
-public:
-    explicit ErrorInContextFile(const std::string& argv = std::string())
-        : BaseError(argv)
-    { }
-
-    explicit ErrorInContextFile(const boost::format& argv)
-        : BaseError(argv)
-    { }
-};
-
-class InvalidGet : public BaseError
-{
-public:
-    explicit InvalidGet(const std::string& argv = std::string())
-        : BaseError(argv)
-    { }
-
-    explicit InvalidGet(const boost::format& argv)
-        : BaseError(argv)
-    { }
-};
-
-} }
+namespace artis {
+    namespace utils {
+
+        class BaseError : public std::runtime_error {
+        public:
+            explicit BaseError(const std::string& argv = std::string())
+                    :std::runtime_error(argv) { }
+
+            explicit BaseError(const boost::format& argv)
+                    :std::runtime_error(argv.str()) { }
+        };
+
+        class FileError : public BaseError {
+        public:
+            explicit FileError(const std::string& argv = std::string())
+                    :BaseError(argv) { }
+
+            explicit FileError(const boost::format& argv)
+                    :BaseError(argv) { }
+        };
+
+        class ParseError : public BaseError {
+        public:
+            explicit ParseError(const std::string& argv = std::string())
+                    :BaseError(argv) { }
+
+            explicit ParseError(const boost::format& argv)
+                    :BaseError(argv) { }
+        };
+
+        class ReadError : public BaseError {
+        public:
+            explicit ReadError(const std::string& argv = std::string())
+                    :BaseError(argv) { }
+
+            explicit ReadError(const boost::format& argv)
+                    :BaseError(argv) { }
+        };
+
+        class InvalidFileFormat : public BaseError {
+        public:
+            explicit InvalidFileFormat(const std::string& argv = std::string())
+                    :BaseError(argv) { }
+
+            explicit InvalidFileFormat(const boost::format& argv)
+                    :BaseError(argv) { }
+        };
+
+        class ErrorInContextFile : public BaseError {
+        public:
+            explicit ErrorInContextFile(const std::string& argv = std::string())
+                    :BaseError(argv) { }
+
+            explicit ErrorInContextFile(const boost::format& argv)
+                    :BaseError(argv) { }
+        };
+
+        class InvalidGet : public BaseError {
+        public:
+            explicit InvalidGet(const std::string& argv = std::string())
+                    :BaseError(argv) { }
+
+            explicit InvalidGet(const boost::format& argv)
+                    :BaseError(argv) { }
+        };
+
+    }
+}
 
 #endif

+ 5 - 3
src/artis/utils/ParametersReader.cpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -22,6 +22,8 @@
 
 #include <artis/utils/ParametersReader.hpp>
 
-namespace artis { namespace utils {
+namespace artis {
+    namespace utils {
 
-} }
+    }
+}

+ 12 - 13
src/artis/utils/ParametersReader.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -25,21 +25,20 @@
 
 #include <string>
 
-namespace artis { namespace utils {
+namespace artis {
+    namespace utils {
 
-template < typename ModelParameters >
-class ParametersReader
-{
-public:
-    ParametersReader()
-    { }
+        template<typename ModelParameters>
+        class ParametersReader {
+        public:
+            ParametersReader() { }
 
-    virtual ~ParametersReader()
-    { }
+            virtual ~ParametersReader() { }
 
-    virtual void load(const std::string& id, ModelParameters& parameters) = 0;
-};
+            virtual void load(const std::string& id, ModelParameters& parameters) = 0;
+        };
 
-} }
+    }
+}
 
 #endif

+ 157 - 162
src/artis/utils/Singleton.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -33,216 +33,211 @@
 
 #include <artis/utils/DateTime.hpp>
 
-namespace artis { namespace utils {
+namespace artis {
+    namespace utils {
 
-enum TraceType { NONE = 0, CHECK, COMPUTE, INIT, KERNEL, PUT };
+        enum TraceType {
+            NONE = 0, CHECK, COMPUTE, INIT, KERNEL, PUT
+        };
 
-template < class Time >
-class TraceElement
-{
-public:
-    TraceElement() : _time(Time::null), _type(NONE)
-    { }
+        template<class Time>
+        class TraceElement {
+        public:
+            TraceElement()
+                    :_time(Time::null), _type(NONE) { }
 
-    TraceElement(const std::string& model_name, typename Time::type time,
-                 TraceType type) :
-        _model_name(model_name), _time(time), _type(type)
-    { }
+            TraceElement(const std::string& model_name, typename Time::type time,
+                    TraceType type)
+                    :
+                    _model_name(model_name), _time(time), _type(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; }
 
-    TraceType get_type() const
-    { return _type; }
+            TraceType get_type() const { return _type; }
 
-    void set_comment(const std::string& comment)
-    { _comment = comment; }
+            void set_comment(const std::string& comment) { _comment = comment; }
 
-private:
-    std::string         _model_name;
-    typename Time::type _time;
-    TraceType           _type;
-    std::string         _comment;
-};
+        private:
+            std::string _model_name;
+            typename Time::type _time;
+            TraceType _type;
+            std::string _comment;
+        };
 
-template < class Time >
-class TraceElements : public std::vector < TraceElement < Time > >
-{
-public:
-    TraceElements()
-    { }
-    virtual ~TraceElements()
-    { }
-
-    TraceElements filter_model_name(
-        const std::string& model_name) const
-    {
-        TraceElements < Time > result;
-
-        std::copy_if(TraceElements < Time >::begin(),
-                     TraceElements < Time >::end(), std::back_inserter(result),
-                     [model_name](TraceElement < Time > const & x)
-                     { return x.get_model_name() == model_name; });
-        return result;
-    }
+        template<class Time>
+        class TraceElements : public std::vector<TraceElement<Time> > {
+        public:
+            TraceElements() { }
 
-    TraceElements filter_time(typename Time::type time) const
-    {
-        TraceElements result;
+            virtual ~TraceElements() { }
 
-        std::copy_if(TraceElements < Time >::begin(),
-                     TraceElements < Time >::end(), std::back_inserter(result),
-                     [time](TraceElement < Time > const & x)
-                     { return x.get_time() == time; });
-        return result;
-    }
+            TraceElements filter_model_name(
+                    const std::string& model_name) const
+            {
+                TraceElements<Time> result;
 
-    TraceElements filter_type(TraceType type) const
-    {
-        TraceElements result;
+                std::copy_if(TraceElements<Time>::begin(),
+                        TraceElements<Time>::end(), std::back_inserter(result),
+                        [model_name](TraceElement<Time> const& x) { return x.get_model_name() == model_name; });
+                return result;
+            }
 
-        std::copy_if(TraceElements < Time >::begin(),
-                     TraceElements < Time >::end(), std::back_inserter(result),
-                     [type](TraceElement < Time > const & x)
-                     { return x.get_type() == type; });
-        return result;
-    }
+            TraceElements filter_time(typename Time::type time) const
+            {
+                TraceElements result;
 
-    std::string to_string() const
-    {
-        std::ostringstream ss;
+                std::copy_if(TraceElements<Time>::begin(),
+                        TraceElements<Time>::end(), std::back_inserter(result),
+                        [time](TraceElement<Time> const& x) { return x.get_time() == time; });
+                return result;
+            }
 
-        for (typename TraceElements < Time >::const_iterator it =
-                 TraceElements < Time >::begin();
-             it != TraceElements < Time >::end(); ++it) {
-            ss << "TRACE: " << it->get_model_name() << " at "
-               << utils::DateTime::toJulianDay(it->get_time()) << " <";
-            switch (it->get_type())
+            TraceElements filter_type(TraceType type) const
             {
-            case NONE: ss << "none"; break;
-            case CHECK: ss << "check"; break;
-            case COMPUTE:  ss << "compute"; break;
-            case INIT: ss << "init"; break;
-            case KERNEL: ss << "kernel"; break;
-            case PUT: ss << "put"; break;
-            };
-            ss << ">";
-            if (not it->get_comment().empty()) {
-                ss << " => " << it->get_comment();
+                TraceElements result;
+
+                std::copy_if(TraceElements<Time>::begin(),
+                        TraceElements<Time>::end(), std::back_inserter(result),
+                        [type](TraceElement<Time> const& x) { return x.get_type() == type; });
+                return result;
             }
-            ss << std::endl;
-        }
-        return ss.str();
-    }
-};
 
-template < class Time >
-class Trace
-{
-public:
-    virtual ~Trace()
-    { }
-
-    static Trace& trace()
-    {
-        std::call_once(_flag, [] ()
-                       { _instance.reset(new Trace()); }
-            );
-        return *_instance;
-    }
+            std::string to_string() const
+            {
+                std::ostringstream ss;
+
+                for (typename TraceElements<Time>::const_iterator it =
+                        TraceElements<Time>::begin();
+                     it != TraceElements<Time>::end(); ++it) {
+                    ss << "TRACE: " << it->get_model_name() << " at "
+                       << utils::DateTime::toJulianDay(it->get_time()) << " <";
+                    switch (it->get_type()) {
+                    case NONE:
+                        ss << "none";
+                        break;
+                    case CHECK:
+                        ss << "check";
+                        break;
+                    case COMPUTE:
+                        ss << "compute";
+                        break;
+                    case INIT:
+                        ss << "init";
+                        break;
+                    case KERNEL:
+                        ss << "kernel";
+                        break;
+                    case PUT:
+                        ss << "put";
+                        break;
+                    };
+                    ss << ">";
+                    if (not it->get_comment().empty()) {
+                        ss << " => " << it->get_comment();
+                    }
+                    ss << std::endl;
+                }
+                return ss.str();
+            }
+        };
 
-    void clear()
-    { _trace.clear(); }
+        template<class Time>
+        class Trace {
+        public:
+            virtual ~Trace() { }
 
-    const TraceElements < Time >& elements() const
-    { return _trace; }
+            static Trace& trace()
+            {
+                std::call_once(_flag, []() { _instance.reset(new Trace()); }
+                );
+                return *_instance;
+            }
 
-    void flush()
-    {
-        if (_sstream) {
-            _element.set_comment(_sstream->str());
-            delete _sstream;
-            _sstream = 0;
-        }
-        _trace.push_back(_element);
-    }
+            void clear() { _trace.clear(); }
 
-    std::mutex& mutex()
-    { return _mutex; }
+            const TraceElements<Time>& elements() const { return _trace; }
 
-    void set_element(const TraceElement < Time >& element)
-    { _element = element; }
+            void flush()
+            {
+                if (_sstream) {
+                    _element.set_comment(_sstream->str());
+                    delete _sstream;
+                    _sstream = 0;
+                }
+                _trace.push_back(_element);
+            }
 
-    std::ostringstream& sstream()
-    {
-        if (_sstream == 0) {
-            _sstream = new std::ostringstream();
-        }
-        return *_sstream;
-    }
+            std::mutex& mutex() { return _mutex; }
 
-private:
-    Trace()
-    { _sstream = 0; }
+            void set_element(const TraceElement<Time>& element) { _element = element; }
 
-    static std::shared_ptr < Trace < Time > > _instance;
-    static std::once_flag                     _flag;
+            std::ostringstream& sstream()
+            {
+                if (_sstream == 0) {
+                    _sstream = new std::ostringstream();
+                }
+                return *_sstream;
+            }
+
+        private:
+            Trace() { _sstream = 0; }
 
-    TraceElements < Time > _trace;
-    TraceElement < Time >  _element;
-    std::ostringstream*    _sstream;
-    std::mutex             _mutex;
-};
+            static std::shared_ptr<Trace<Time> > _instance;
+            static std::once_flag _flag;
 
-} }
+            TraceElements<Time> _trace;
+            TraceElement<Time> _element;
+            std::ostringstream* _sstream;
+            std::mutex _mutex;
+        };
+
+    }
+}
 
-template < class Time >
-artis::utils::Trace < Time >& operator<<(
-    artis::utils::Trace < Time >& trace,
-    const artis::utils::TraceElement < Time >& e)
+template<class Time>
+artis::utils::Trace<Time>& operator<<(
+        artis::utils::Trace<Time>& trace,
+        const artis::utils::TraceElement<Time>& e)
 {
-    std::lock_guard < std::mutex > lock(trace.mutex());
+    std::lock_guard<std::mutex> lock(trace.mutex());
 
     trace.set_element(e);
     return trace;
 }
 
-template < class Time >
-artis::utils::Trace < Time >& operator<<(
-    artis::utils::Trace < Time >& trace,
-    const std::string& str)
+template<class Time>
+artis::utils::Trace<Time>& operator<<(
+        artis::utils::Trace<Time>& trace,
+        const std::string& str)
 {
-    std::lock_guard < std::mutex > lock(trace.mutex());
+    std::lock_guard<std::mutex> lock(trace.mutex());
 
     trace.sstream() << str;
     return trace;
 }
 
-template < class Time >
-artis::utils::Trace < Time >& operator<<(
-    artis::utils::Trace < Time >& trace,
-    typename Time::type t)
+template<class Time>
+artis::utils::Trace<Time>& operator<<(
+        artis::utils::Trace<Time>& trace,
+        typename Time::type t)
 {
-    std::lock_guard < std::mutex > lock(trace.mutex());
+    std::lock_guard<std::mutex> lock(trace.mutex());
 
     trace.sstream() << t;
     return trace;
 }
 
-template < class Time >
-std::shared_ptr < artis::utils::Trace < Time > >
-artis::utils::Trace < Time >::_instance;
+template<class Time>
+std::shared_ptr<artis::utils::Trace<Time> >
+        artis::utils::Trace<Time>::_instance;
 
-template < class Time >
-std::once_flag artis::utils::Trace < Time >::_flag;
+template<class Time>
+std::once_flag artis::utils::Trace<Time>::_flag;
 
 #endif

+ 12 - 11
src/artis/utils/Time.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -23,17 +23,18 @@
 #ifndef UTILS_TIME
 #define UTILS_TIME
 
-namespace artis { namespace utils {
+namespace artis {
+    namespace utils {
 
-template < typename Type, typename Limits >
-struct Time
-{
-    static constexpr Type negative_infinity = Limits::negative_infinity;
-    static constexpr Type infinity = Limits::positive_infinity;
-    static constexpr Type null = Limits::null;
-    typedef Type type;
-};
+        template<typename Type, typename Limits>
+        struct Time {
+            static constexpr Type negative_infinity = Limits::negative_infinity;
+            static constexpr Type infinity = Limits::positive_infinity;
+            static constexpr Type null = Limits::null;
+            typedef Type type;
+        };
 
-} }
+    }
+}
 
 #endif

+ 7 - 5
src/artis/utils/Trace.cpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -22,9 +22,11 @@
 
 #include <artis/utils/Trace.hpp>
 
-namespace artis { namespace utils {
+namespace artis {
+    namespace utils {
 
-std::map < std::string, int > artis::utils::KernelInfo::elt_dictionary;
-std::vector < std::string > artis::utils::KernelInfo::elt_names;
+        std::map<std::string, int> artis::utils::KernelInfo::elt_dictionary;
+        std::vector<std::string> artis::utils::KernelInfo::elt_names;
 
-} }
+    }
+}

+ 347 - 359
src/artis/utils/Trace.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -40,451 +40,439 @@
 #endif
 
 //fwd decl for friend classes in TraceElement
-namespace artis { namespace kernel {
-template < typename T, typename U, typename V, typename W >
-class AbstractCoupledModel;
-template < typename T, typename U, typename V >
-class AbstractAtomicModel;
-template < typename Time, typename Parameters >
-class AbstractModel;
-template < typename T, typename U, typename V >
-class Internals;
-template < typename T, typename U, typename V >
-class Externals;
-}}
-
-namespace artis { namespace utils {
-
-enum TraceType { NONE = 0, CHECK = 1, CONSTRUCT, SUBMODEL_ADD, INTERNAL_DECL,
-                 EXTERNAL_DECL, INTERNAL_LINK, INIT, START, BEFORE_COMPUTE,
-                 COMPUTE, PUT, AFTER_COMPUTE, DESTRUCT, KERNEL};
-static const std::vector <std::string> TraceTypesStr = {
-    "none", "check", "construct", "submodel_add", "internal_decl",
-    "external_decl", "internal_link", "init", "start", "before_compute",
-    "compute", "put", "after_compute", "destruct", "kernel"};
-
-class KernelInfo
-{
-public:
-    static std::map < std::string, int > elt_dictionary;
-    static std::vector < std::string > elt_names;
-    static unsigned int term(const std::string& v) {
-        if(elt_dictionary.find(v) == elt_dictionary.end()) {
-            elt_dictionary[v] = elt_names.size();
-            elt_names.push_back(v);
-        }
-        return elt_dictionary[v];
-    }
-    static const std::string & term(unsigned int i) {return elt_names[i];}
+namespace artis {
+    namespace kernel {
+        template<typename T, typename U, typename V, typename W>
+        class AbstractCoupledModel;
 
+        template<typename T, typename U, typename V>
+        class AbstractAtomicModel;
 
-    KernelInfo() :
-        _internal_var(false), _empty(true)
-    {
-        set_var("");
-        set_value("");
-        set_tgt_model("");
-        set_tgt_internal_var("");
-    }
+        template<typename Time, typename Parameters>
+        class AbstractModel;
 
-    KernelInfo(const std::string& var, bool internal_var,
-               const std::string& value) :
-         _internal_var(internal_var), _empty(false)
-    {
-        set_var(var);
-        set_value(value);
-        set_tgt_model("");
-        set_tgt_internal_var("");
-    }
+        template<typename T, typename U, typename V>
+        class Internals;
 
-    KernelInfo(const std::string& var, const std::string& tgt_model,
-               const std::string& tgt_internal_var) :
-        _internal_var(true), _empty(false)
-    {
-        set_var(var);
-        set_value("");
-        set_tgt_model(tgt_model);
-        set_tgt_internal_var(tgt_internal_var);
+        template<typename T, typename U, typename V>
+        class Externals;
     }
+}
 
-    KernelInfo(const std::string& var, bool internal_var) :
-        _internal_var(internal_var), _empty(false)
-    {
-        set_var(var);
-        set_value("");
-        set_tgt_model("");
-        set_tgt_internal_var("");
-    }
+namespace artis {
+    namespace utils {
+
+        enum TraceType {
+            NONE = 0, CHECK = 1, CONSTRUCT, SUBMODEL_ADD, INTERNAL_DECL,
+            EXTERNAL_DECL, INTERNAL_LINK, INIT, START, BEFORE_COMPUTE,
+            COMPUTE, PUT, AFTER_COMPUTE, DESTRUCT, KERNEL
+        };
+        static const std::vector<std::string> TraceTypesStr = {
+                "none", "check", "construct", "submodel_add", "internal_decl",
+                "external_decl", "internal_link", "init", "start", "before_compute",
+                "compute", "put", "after_compute", "destruct", "kernel"};
+
+        class KernelInfo {
+        public:
+            static std::map<std::string, int> elt_dictionary;
+            static std::vector<std::string> elt_names;
+
+            static unsigned int term(const std::string& v)
+            {
+                if (elt_dictionary.find(v) == elt_dictionary.end()) {
+                    elt_dictionary[v] = elt_names.size();
+                    elt_names.push_back(v);
+                }
+                return elt_dictionary[v];
+            }
 
-    KernelInfo(const std::string& tgt_model) :
-        _internal_var(false), _empty(false)
-    {
-        set_var("");
-        set_value("");
-        set_tgt_model(tgt_model);
-        set_tgt_internal_var("");
-    }
+            static const std::string& term(unsigned int i) { return elt_names[i]; }
+
+            KernelInfo()
+                    :
+                    _internal_var(false), _empty(true)
+            {
+                set_var("");
+                set_value("");
+                set_tgt_model("");
+                set_tgt_internal_var("");
+            }
+
+            KernelInfo(const std::string& var, bool internal_var,
+                    const std::string& value)
+                    :
+                    _internal_var(internal_var), _empty(false)
+            {
+                set_var(var);
+                set_value(value);
+                set_tgt_model("");
+                set_tgt_internal_var("");
+            }
+
+            KernelInfo(const std::string& var, const std::string& tgt_model,
+                    const std::string& tgt_internal_var)
+                    :
+                    _internal_var(true), _empty(false)
+            {
+                set_var(var);
+                set_value("");
+                set_tgt_model(tgt_model);
+                set_tgt_internal_var(tgt_internal_var);
+            }
+
+            KernelInfo(const std::string& var, bool internal_var)
+                    :
+                    _internal_var(internal_var), _empty(false)
+            {
+                set_var(var);
+                set_value("");
+                set_tgt_model("");
+                set_tgt_internal_var("");
+            }
 
-    void set_var(const std::string& v)
-    { _var = KernelInfo::term(v); }
+            KernelInfo(const std::string& tgt_model)
+                    :
+                    _internal_var(false), _empty(false)
+            {
+                set_var("");
+                set_value("");
+                set_tgt_model(tgt_model);
+                set_tgt_internal_var("");
+            }
 
-    void set_value(const std::string& v)
-    { _value = KernelInfo::term(v); }
+            void set_var(const std::string& v) { _var = KernelInfo::term(v); }
 
-    void set_tgt_model(const std::string& v)
-    { _tgt_model = KernelInfo::term(v); }
+            void set_value(const std::string& v) { _value = KernelInfo::term(v); }
 
-    void set_tgt_internal_var(const std::string& v)
-    { _tgt_internal_var = KernelInfo::term(v); }
+            void set_tgt_model(const std::string& v) { _tgt_model = KernelInfo::term(v); }
 
+            void set_tgt_internal_var(const std::string& v) { _tgt_internal_var = KernelInfo::term(v); }
 
-    const std::string& var() const
-    { return KernelInfo::term(_var); }
+            const std::string& var() const { return KernelInfo::term(_var); }
 
-    const std::string& value() const
-    { return KernelInfo::term(_value); }
+            const std::string& value() const { return KernelInfo::term(_value); }
 
-    const std::string& tgt_model() const
-    { return KernelInfo::term(_tgt_model); }
+            const std::string& tgt_model() const { return KernelInfo::term(_tgt_model); }
 
-    const std::string& tgt_internal_var() const
-    { return KernelInfo::term(_tgt_internal_var); }
+            const std::string& tgt_internal_var() const { return KernelInfo::term(_tgt_internal_var); }
 
-    unsigned int var_idx() const
-    { return _var; }
+            unsigned int var_idx() const { return _var; }
 
-    unsigned int tgt_internal_var_idx() const
-    { return _tgt_internal_var; }
+            unsigned int tgt_internal_var_idx() const { return _tgt_internal_var; }
 
-    unsigned int tgt_model_idx() const
-    { return _tgt_model; }
+            unsigned int tgt_model_idx() const { return _tgt_model; }
 
-    bool is_internal_var() const
-    { return _internal_var; }
+            bool is_internal_var() const { return _internal_var; }
 
-    bool empty() const
-    { return _empty; }
+            bool empty() const { return _empty; }
 
-    std::string to_string() const
-    {
-        std::ostringstream ss;
-        if( not KernelInfo::term(_var).empty() ){
-            ss << ":";
-            if (not _internal_var)
-                ss << "*";
-            ss << KernelInfo::term(_var);
-        }
-        if( not KernelInfo::term(_value).empty()) {
-            ss << "=" << KernelInfo::term(_value);
-        }
-        if(not KernelInfo::term(_tgt_model).empty()) {
-            ss << " -> " << KernelInfo::term(_tgt_model);
-            if(not KernelInfo::term(_tgt_internal_var).empty()) {
-                ss << ":" << KernelInfo::term(_tgt_internal_var);
+            std::string to_string() const
+            {
+                std::ostringstream ss;
+                if (not KernelInfo::term(_var).empty()) {
+                    ss << ":";
+                    if (not _internal_var)
+                        ss << "*";
+                    ss << KernelInfo::term(_var);
+                }
+                if (not KernelInfo::term(_value).empty()) {
+                    ss << "=" << KernelInfo::term(_value);
+                }
+                if (not KernelInfo::term(_tgt_model).empty()) {
+                    ss << " -> " << KernelInfo::term(_tgt_model);
+                    if (not KernelInfo::term(_tgt_internal_var).empty()) {
+                        ss << ":" << KernelInfo::term(_tgt_internal_var);
+                    }
+                }
+                return ss.str();
             }
-        }
-        return ss.str();
-    }
 
-private:
-    unsigned int _var;
-    unsigned int _value;
-    unsigned int _tgt_model;
-    unsigned int _tgt_internal_var;
-    bool        _internal_var;
-    bool        _empty;
-};
-
-template < class Time >
-class TraceElement
-{
-    template < typename T, typename U, typename V, typename W >
-    friend class artis::kernel::AbstractCoupledModel;
-    template < typename T, typename U, typename V >
-    friend class artis::kernel::AbstractAtomicModel;
-    template < typename T, typename P >
-    friend class artis::kernel::AbstractModel;
-    template < typename T, typename U, typename V >
-    friend class artis::kernel::Internals;
-    template < typename T, typename U, typename V >
-    friend class artis::kernel::Externals;
-
-private:
-    TraceElement(bool from_kernel, const std::string& model_name,
-                 typename Time::type time, TraceType type) :
-        _time(time), _type(type),
-        _from_kernel(from_kernel)
-    {
-        _model_name = KernelInfo::term(model_name);
-    }
+        private:
+            unsigned int _var;
+            unsigned int _value;
+            unsigned int _tgt_model;
+            unsigned int _tgt_internal_var;
+            bool _internal_var;
+            bool _empty;
+        };
+
+        template<class Time>
+        class TraceElement {
+            template<typename T, typename U, typename V, typename W>
+            friend
+            class artis::kernel::AbstractCoupledModel;
+
+            template<typename T, typename U, typename V>
+            friend
+            class artis::kernel::AbstractAtomicModel;
+
+            template<typename T, typename P>
+            friend
+            class artis::kernel::AbstractModel;
+
+            template<typename T, typename U, typename V>
+            friend
+            class artis::kernel::Internals;
+
+            template<typename T, typename U, typename V>
+            friend
+            class artis::kernel::Externals;
+
+        private:
+            TraceElement(bool from_kernel, const std::string& model_name,
+                    typename Time::type time, TraceType type)
+                    :
+                    _time(time), _type(type),
+                    _from_kernel(from_kernel)
+            {
+                _model_name = KernelInfo::term(model_name);
+            }
 
-public:
-    TraceElement() : _time(Time::null), _type(NONE),
-        _from_kernel(false)
-    { }
-
-    TraceElement(const std::string& model_name, typename Time::type time,
-                 TraceType type) :
-        _time(time), _type(type),
-        _from_kernel(false)
-    {
-        _model_name = KernelInfo::term(model_name);
-    }
+        public:
+            TraceElement()
+                    :_time(Time::null), _type(NONE),
+                     _from_kernel(false) { }
+
+            TraceElement(const std::string& model_name, typename Time::type time,
+                    TraceType type)
+                    :
+                    _time(time), _type(type),
+                    _from_kernel(false)
+            {
+                _model_name = KernelInfo::term(model_name);
+            }
 
-    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 KernelInfo::term(_model_name); }
+            const std::string& get_model_name() const { return KernelInfo::term(_model_name); }
 
-    unsigned int get_model_name_idx() const
-    { return _model_name; }
+            unsigned int get_model_name_idx() const { return _model_name; }
 
-    typename Time::type get_time() const
-    { return _time; }
+            typename Time::type get_time() const { return _time; }
 
-    TraceType get_type() const
-    { return _type; }
+            TraceType get_type() const { return _type; }
 
-    const KernelInfo& get_kernel_info() const
-    { return _kernel_info; }
+            const KernelInfo& get_kernel_info() const { return _kernel_info; }
 
-    void set_comment(const std::string& comment)
-    { _comment = comment; }
+            void set_comment(const std::string& comment) { _comment = comment; }
 
-    bool from_kernel() const
-    { return _from_kernel; }
+            bool from_kernel() const { return _from_kernel; }
 
-    void set_kernel_info(const KernelInfo& info)
-    { _kernel_info = info; }
+            void set_kernel_info(const KernelInfo& info) { _kernel_info = info; }
 
-    std::string to_string(artis::utils::DateFormat date_format =
+            std::string to_string(artis::utils::DateFormat date_format =
             artis::utils::DATE_FORMAT_EXTENDED) const
-    {
-        std::ostringstream ss;
-        ss << (from_kernel() ? "KERNEL" : "TRACE ");
-        if (get_time() != Time::null) {
-            ss << "(" << utils::DateTime::toJulianDayFmt(get_time(),
-                                                         date_format)
-               << ")";
-        }
-        ss << ": ";
-        ss << "<" + TraceTypesStr[get_type()] + ">";
-        ss << " " << get_model_name();
-        if (not get_kernel_info().empty()) {
-            ss << get_kernel_info().to_string();
-        }
-        if (not get_comment().empty()) {
-            ss << " => " << get_comment();
-        }
-        return ss.str();
+            {
+                std::ostringstream ss;
+                ss << (from_kernel() ? "KERNEL" : "TRACE ");
+                if (get_time() != Time::null) {
+                    ss << "(" << utils::DateTime::toJulianDayFmt(get_time(),
+                            date_format)
+                       << ")";
+                }
+                ss << ": ";
+                ss << "<" + TraceTypesStr[get_type()] + ">";
+                ss << " " << get_model_name();
+                if (not get_kernel_info().empty()) {
+                    ss << get_kernel_info().to_string();
+                }
+                if (not get_comment().empty()) {
+                    ss << " => " << get_comment();
+                }
+                return ss.str();
 
-    }
+            }
 
-private:
-    unsigned int        _model_name;
-    typename Time::type _time;
-    TraceType           _type;
-    std::string         _comment;
-    KernelInfo          _kernel_info;
-    bool                _from_kernel;
-};
-
-template < class Time >
-class TraceElements : public std::vector < TraceElement < Time > >
-{
-public:
-    TraceElements()
-    { }
-
-    virtual ~TraceElements()
-    { }
-
-    TraceElements filter_model_name(
-            const std::string& model_name) const
-    {
-        TraceElements < Time > result;
-
-        std::copy_if(
-                    TraceElements < Time >::begin(),
-                    TraceElements < Time >::end(), std::back_inserter(result),
-                    [model_name](TraceElement < Time > const & x) {
-            if (not x.get_kernel_info().empty()) {
-                if (x.get_kernel_info().tgt_model() == model_name) {
-                    return true;
-                }
+        private:
+            unsigned int _model_name;
+            typename Time::type _time;
+            TraceType _type;
+            std::string _comment;
+            KernelInfo _kernel_info;
+            bool _from_kernel;
+        };
+
+        template<class Time>
+        class TraceElements : public std::vector<TraceElement<Time> > {
+        public:
+            TraceElements() { }
+
+            virtual ~TraceElements() { }
+
+            TraceElements filter_model_name(
+                    const std::string& model_name) const
+            {
+                TraceElements<Time> result;
+
+                std::copy_if(
+                        TraceElements<Time>::begin(),
+                        TraceElements<Time>::end(), std::back_inserter(result),
+                        [model_name](TraceElement<Time> const& x) {
+                            if (not x.get_kernel_info().empty()) {
+                                if (x.get_kernel_info().tgt_model() == model_name) {
+                                    return true;
+                                }
+                            }
+                            return x.get_model_name() == model_name;
+                        });
+                return result;
             }
-            return x.get_model_name() == model_name;
-        });
-        return result;
-    }
 
-    TraceElements filter_time(typename Time::type time) const
-    {
-        TraceElements result;
+            TraceElements filter_time(typename Time::type time) const
+            {
+                TraceElements result;
 
-        std::copy_if(TraceElements < Time >::begin(),
-                     TraceElements < Time >::end(), std::back_inserter(result),
-                     [time](TraceElement < Time > const & x)
-        { return x.get_time() == time; });
-        return result;
-    }
+                std::copy_if(TraceElements<Time>::begin(),
+                        TraceElements<Time>::end(), std::back_inserter(result),
+                        [time](TraceElement<Time> const& x) { return x.get_time() == time; });
+                return result;
+            }
 
-    TraceElements filter_type(TraceType type) const
-    {
-        TraceElements result;
+            TraceElements filter_type(TraceType type) const
+            {
+                TraceElements result;
 
-        std::copy_if(TraceElements < Time >::begin(),
-                     TraceElements < Time >::end(), std::back_inserter(result),
-                     [type](TraceElement < Time > const & x)
-        { return x.get_type() == type; });
-        return result;
-    }
+                std::copy_if(TraceElements<Time>::begin(),
+                        TraceElements<Time>::end(), std::back_inserter(result),
+                        [type](TraceElement<Time> const& x) { return x.get_type() == type; });
+                return result;
+            }
 
-    TraceElements filter_variable(const std::string& var_name) const
-    {
-        TraceElements result;
-
-        std::copy_if(TraceElements < Time >::begin(),
-                     TraceElements < Time >::end(), std::back_inserter(result),
-                     [var_name](TraceElement < Time > const & x)
-        {   if(x.get_kernel_info().empty())
-                return false;
-            return ((x.get_kernel_info().var() == var_name)
-                    or (x.get_kernel_info().tgt_internal_var() == var_name));
-        });
-        return result;
-    }
+            TraceElements filter_variable(const std::string& var_name) const
+            {
+                TraceElements result;
+
+                std::copy_if(TraceElements<Time>::begin(),
+                        TraceElements<Time>::end(), std::back_inserter(result),
+                        [var_name](TraceElement<Time> const& x) {
+                            if (x.get_kernel_info().empty())
+                                return false;
+                            return ((x.get_kernel_info().var() == var_name)
+                                    or (x.get_kernel_info().tgt_internal_var() == var_name));
+                        });
+                return result;
+            }
 
-    std::string to_string(artis::utils::DateFormat date_format =
+            std::string to_string(artis::utils::DateFormat date_format =
             artis::utils::DATE_FORMAT_EXTENDED) const
-    {
-        std::ostringstream ss;
-
-        for (typename TraceElements < Time >::const_iterator it =
-             TraceElements < Time >::begin();
-             it != TraceElements < Time >::end(); ++it) {
-            ss << it->to_string(date_format) << std::endl;
-        }
-        return ss.str();
-    }
-};
+            {
+                std::ostringstream ss;
 
-template < class Time >
-class Trace
-{
-public:
-    virtual ~Trace()
-    { }
-
-    static Trace& trace()
-    {
-        std::call_once(_flag, [] ()
-        { _instance.reset(new Trace()); }
-        );
-        return *_instance;
-    }
+                for (typename TraceElements<Time>::const_iterator it =
+                        TraceElements<Time>::begin();
+                     it != TraceElements<Time>::end(); ++it) {
+                    ss << it->to_string(date_format) << std::endl;
+                }
+                return ss.str();
+            }
+        };
+
+        template<class Time>
+        class Trace {
+        public:
+            virtual ~Trace() { }
+
+            static Trace& trace()
+            {
+                std::call_once(_flag, []() { _instance.reset(new Trace()); }
+                );
+                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()
-    {
-        if (_sstream) {
-            _element.set_comment(_sstream->str());
-            delete _sstream;
-            _sstream = 0;
-        }
-        _trace.push_back(_element);
-    }
+            void flush()
+            {
+                if (_sstream) {
+                    _element.set_comment(_sstream->str());
+                    delete _sstream;
+                    _sstream = 0;
+                }
+                _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; }
 
-    void set_kernel_info(const KernelInfo& info)
-    { _element.set_kernel_info(info); }
+            void set_kernel_info(const KernelInfo& info) { _element.set_kernel_info(info); }
 
-    std::ostringstream& sstream()
-    {
-        if (_sstream == 0) {
-            _sstream = new std::ostringstream();
-        }
-        return *_sstream;
-    }
+            std::ostringstream& sstream()
+            {
+                if (_sstream == 0) {
+                    _sstream = new std::ostringstream();
+                }
+                return *_sstream;
+            }
 
-private:
-    Trace()
-    { _sstream = 0; }
+        private:
+            Trace() { _sstream = 0; }
 
-    static std::shared_ptr < Trace < Time > > _instance;
-    static std::once_flag                     _flag;
+            static std::shared_ptr<Trace<Time> > _instance;
+            static std::once_flag _flag;
 
-    TraceElements < Time > _trace;
-    TraceElement < Time >  _element;
-    std::ostringstream*    _sstream;
-    std::mutex             _mutex;
-};
+            TraceElements<Time> _trace;
+            TraceElement<Time> _element;
+            std::ostringstream* _sstream;
+            std::mutex _mutex;
+        };
 
-} }
+    }
+}
 
-template < class Time >
-artis::utils::Trace < Time >& operator<<(
-        artis::utils::Trace < Time >& trace,
-        const artis::utils::TraceElement < Time >& e)
+template<class Time>
+artis::utils::Trace<Time>& operator<<(
+        artis::utils::Trace<Time>& trace,
+        const artis::utils::TraceElement<Time>& e)
 {
-    std::lock_guard < std::mutex > lock(trace.mutex());
+    std::lock_guard<std::mutex> lock(trace.mutex());
 
     trace.set_element(e);
     return trace;
 }
 
-template < class Time >
-artis::utils::Trace < Time >& operator<<(
-        artis::utils::Trace < Time >& trace,
+template<class Time>
+artis::utils::Trace<Time>& operator<<(
+        artis::utils::Trace<Time>& trace,
         const artis::utils::KernelInfo& info)
 {
-    std::lock_guard < std::mutex > lock(trace.mutex());
+    std::lock_guard<std::mutex> lock(trace.mutex());
 
     trace.set_kernel_info(info);
     return trace;
 }
 
-template < class Time >
-artis::utils::Trace < Time >& operator<<(
-        artis::utils::Trace < Time >& trace,
+template<class Time>
+artis::utils::Trace<Time>& operator<<(
+        artis::utils::Trace<Time>& trace,
         const std::string& str)
 {
-    std::lock_guard < std::mutex > lock(trace.mutex());
+    std::lock_guard<std::mutex> lock(trace.mutex());
 
     trace.sstream() << str;
     return trace;
 }
 
-template < class Time >
-artis::utils::Trace < Time >& operator<<(
-        artis::utils::Trace < Time >& trace,
+template<class Time>
+artis::utils::Trace<Time>& operator<<(
+        artis::utils::Trace<Time>& trace,
         typename Time::type t)
 {
-    std::lock_guard < std::mutex > lock(trace.mutex());
+    std::lock_guard<std::mutex> lock(trace.mutex());
 
     trace.sstream() << t;
     return trace;
 }
 
-template < class Time >
-std::shared_ptr < artis::utils::Trace < Time > >
-artis::utils::Trace < Time >::_instance;
+template<class Time>
+std::shared_ptr<artis::utils::Trace<Time> >
+        artis::utils::Trace<Time>::_instance;
 
-template < class Time >
-std::once_flag artis::utils::Trace < Time >::_flag;
+template<class Time>
+std::once_flag artis::utils::Trace<Time>::_flag;
 
 #endif

+ 2 - 2
src/test/CMakeLists.txt

@@ -1,6 +1,6 @@
 INCLUDE_DIRECTORIES(
-  ${CMAKE_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS})
+        ${CMAKE_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES()
 

+ 56 - 45
src/test/models.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -29,35 +29,36 @@
 
 #include <memory>
 
+struct GlobalParameters {
+};
 
-struct GlobalParameters
-{ };
-
-struct ModelParameters
-{ };
+struct ModelParameters {
+};
 
-using Model = artis::kernel::AbstractModel < artis::utils::DoubleTime,
-                                             ModelParameters >;
-using Models = artis::kernel::AbstractModels < artis::utils::DoubleTime,
-        ModelParameters >;
+using Model = artis::kernel::AbstractModel<artis::utils::DoubleTime,
+        ModelParameters>;
+using Models = artis::kernel::AbstractModels<artis::utils::DoubleTime,
+        ModelParameters>;
 
-using Trace = artis::utils::Trace < artis::utils::DoubleTime >;
-using TraceElement = artis::utils::TraceElement < artis::utils::DoubleTime >;
+using Trace = artis::utils::Trace<artis::utils::DoubleTime>;
+using TraceElement = artis::utils::TraceElement<artis::utils::DoubleTime>;
 
-template < typename T >
-using AtomicModel = artis::kernel::AbstractAtomicModel <
-    T, artis::utils::DoubleTime, ModelParameters >;
+template<typename T>
+using AtomicModel = artis::kernel::AbstractAtomicModel<
+        T, artis::utils::DoubleTime, ModelParameters>;
 
-template < typename T >
-using CoupledModel = artis::kernel::AbstractCoupledModel <
-    T, artis::utils::DoubleTime, ModelParameters, GlobalParameters >;
+template<typename T>
+using CoupledModel = artis::kernel::AbstractCoupledModel<
+        T, artis::utils::DoubleTime, ModelParameters, GlobalParameters>;
 
-class AModel : public AtomicModel < AModel >
-{
+class AModel : public AtomicModel<AModel> {
 public:
-    enum externals { };
+    enum externals {
+    };
 
-    enum internals { DX, BX, IX };
+    enum internals {
+        DX, BX, IX
+    };
 
     AModel(Models = Models())
     {
@@ -66,8 +67,7 @@ public:
         Internal(DX, &AModel::_dx);
     }
 
-    virtual ~AModel()
-    { }
+    virtual ~AModel() { }
 
     void compute(double t, bool /* update */)
     {
@@ -98,23 +98,28 @@ public:
     double _dx;
 };
 
-class BModel : public AtomicModel < BModel >
-{
+class BModel : public AtomicModel<BModel> {
 public:
-    enum externals { IX, BX, DX };
-    enum internals { IY, IZ, BY, DY };
-    enum states { N };
+    enum externals {
+        IX, BX, DX
+    };
+    enum internals {
+        IY, IZ, BY, DY
+    };
+    enum states {
+        N
+    };
 
     BModel(Models = Models())
     {
         // external(IX, &BModel::_ix);
-        Externals(int, (( IX, &BModel::_ix )));
+        Externals(int, ((IX, &BModel::_ix)));
 
         External(BX, &BModel::_bx);
         External(DX, &BModel::_dx);
 
         // internal(IY, &BModel::_iy);
-        Internals(int, ( ( IY, &BModel::_iy ), ( IZ, &BModel::_iz ) ) );
+        Internals(int, ((IY, &BModel::_iy), (IZ, &BModel::_iz)));
 
         Internal(BY, &BModel::_by);
         Internal(DY, &BModel::_dy);
@@ -122,8 +127,7 @@ public:
         States(int, ((N, &BModel::_n)));
     }
 
-    virtual ~BModel()
-    { }
+    virtual ~BModel() { }
 
     void compute(double t, bool /* update */)
     {
@@ -167,14 +171,20 @@ private:
     int _n;
 };
 
-class RootModel : public CoupledModel < RootModel >
-{
+class RootModel : public CoupledModel<RootModel> {
 public:
-    enum submodels { A, B };
-    enum internals { IY, BY, DY, IZ, DX };
-    enum states { N };
-
-    RootModel(Models submodels) :
+    enum submodels {
+        A, B
+    };
+    enum internals {
+        IY, BY, DY, IZ, DX
+    };
+    enum states {
+        N
+    };
+
+    RootModel(Models submodels)
+            :
             _a(dynamic_cast < AModel* >(submodels[0])),
             _b(dynamic_cast < BModel* >(submodels[1]))
     {
@@ -191,7 +201,8 @@ public:
         // State(N, &RootModel::_n);
     }
 
-    RootModel() : _a(new AModel), _b(new BModel)
+    RootModel()
+            :_a(new AModel), _b(new BModel)
     {
         // submodels
         Submodels(((A, _a), (B, _b)));
@@ -215,13 +226,13 @@ public:
     void compute(double t, bool /* update */)
     {
         ::Trace::trace() << ::TraceElement(this->path(this), t,
-                                           artis::utils::COMPUTE)
+                artis::utils::COMPUTE)
                          << "Start";
         ::Trace::trace().flush();
         (*_a)(t);
-        _b->put < double >(t, BModel::DX, _a->get < double >(t, AModel::DX));
-        _b->put < int >(t, BModel::IX, _a->get < int >(t, AModel::IX));
-        _b->put < bool >(t, BModel::BX, _a->get < bool >(t, AModel::BX));
+        _b->put<double>(t, BModel::DX, _a->get<double>(t, AModel::DX));
+        _b->put<int>(t, BModel::IX, _a->get<int>(t, AModel::IX));
+        _b->put<bool>(t, BModel::BX, _a->get<bool>(t, AModel::BX));
         (*_b)(t);
 
         ++_n;

+ 14 - 14
src/test/test-context.cpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -35,11 +35,11 @@
 
 using namespace artis::kernel;
 
-typedef artis::kernel::Simulator < RootModel,
-                                   artis::utils::DoubleTime,
-                                   ModelParameters,
-                                   GlobalParameters > ASimulator;
-typedef artis::context::Context < artis::utils::DoubleTime > AContext;
+typedef artis::kernel::Simulator<RootModel,
+        artis::utils::DoubleTime,
+        ModelParameters,
+        GlobalParameters> ASimulator;
+typedef artis::context::Context<artis::utils::DoubleTime> AContext;
 
 int main()
 {
@@ -47,7 +47,7 @@ int main()
     ModelParameters modelParameters;
 
     AContext context(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
-                     artis::utils::DateTime::toJulianDayNumber("2016-1-5"));
+            artis::utils::DateTime::toJulianDayNumber("2016-1-5"));
 
     ::Trace::trace().clear();
 
@@ -55,7 +55,7 @@ int main()
         ASimulator simulator(new RootModel, globalParameters);
 
         simulator.init(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
-                       modelParameters);
+                modelParameters);
         simulator.run(context);
         simulator.save(context);
 
@@ -66,7 +66,7 @@ int main()
     }
 
     std::cout << ::Trace::trace().elements().filter_variable("BX").to_string(
-        artis::utils::DATE_FORMAT_YMD) << std::endl;
+            artis::utils::DATE_FORMAT_YMD) << std::endl;
 
     std::cout << "==== PAUSE ====" << std::endl;
 
@@ -77,14 +77,14 @@ int main()
         ASimulator simulator(new RootModel, globalParameters);
 
         new_context.begin(
-            artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
+                artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
         new_context.end(
-            artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
+                artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
         simulator.run(new_context);
     }
 
     std::cout << ::Trace::trace().elements().filter_type(
-        artis::utils::COMPUTE).to_string() << std::endl;
+            artis::utils::COMPUTE).to_string() << std::endl;
 
     std::cout << "==== PAUSE ====" << std::endl;
 
@@ -99,9 +99,9 @@ int main()
         ia >> new_context;
 
         new_context.begin(
-            artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
+                artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
         new_context.end(
-            artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
+                artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
         simulator.run(new_context);
     }
 

+ 32 - 32
src/test/test.cpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
+ * Copyright (C) 2012-2019 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
@@ -35,51 +35,51 @@
 using namespace artis::kernel;
 using namespace artis::builder;
 
-using Creator = ObjectCreator < Model, artis::utils::DoubleTime,
-                                ModelParameters >;
-using Factory = ModelFactory < Model, int, Creator, artis::utils::DoubleTime,
-                               ModelParameters >;
+using Creator = ObjectCreator<Model, artis::utils::DoubleTime,
+        ModelParameters>;
+using Factory = ModelFactory<Model, int, Creator, artis::utils::DoubleTime,
+        ModelParameters>;
 
 DECLARE_MODEL(AModel, ::Model, ::Factory, artis::utils::DoubleTime,
-              ModelParameters);
+        ModelParameters);
+
 DECLARE_MODEL(BModel, ::Model, ::Factory, artis::utils::DoubleTime,
-              ModelParameters);
+        ModelParameters);
+
 DECLARE_MODEL(RootModel, ::Model, ::Factory, artis::utils::DoubleTime,
-              ModelParameters);
+        ModelParameters);
 
-typedef artis::kernel::Simulator < RootModel,
-                                   artis::utils::DoubleTime,
-                                   ModelParameters,
-                                   GlobalParameters > ASimulator;
+typedef artis::kernel::Simulator<RootModel,
+        artis::utils::DoubleTime,
+        ModelParameters,
+        GlobalParameters> ASimulator;
 
-typedef artis::builder::Builder < ::Factory,
-                                  RootModel,
-                                  artis::utils::DoubleTime,
-                                  ModelParameters,
-                                  GlobalParameters > ABuilder;
+typedef artis::builder::Builder<::Factory,
+        RootModel,
+        artis::utils::DoubleTime,
+        ModelParameters,
+        GlobalParameters> ABuilder;
 
-typedef artis::context::Context < artis::utils::DoubleTime > AContext;
+typedef artis::context::Context<artis::utils::DoubleTime> AContext;
 
-class AView : public artis::observer::View < artis::utils::DoubleTime,
-                                             ModelParameters >
-{
+class AView : public artis::observer::View<artis::utils::DoubleTime,
+        ModelParameters> {
 public:
     AView()
     {
-        selector("A::I", INT, { RootModel::A, AModel::IX });
-        selector("A::B", BOOL, { RootModel::A, AModel::BX });
-        selector("A::D", DOUBLE, { RootModel::A, AModel::DX });
-        selector("B::I", INT, { RootModel::B, BModel::IY });
-        selector("B::B", BOOL, { RootModel::B, BModel::BY });
-        selector("B::D", DOUBLE, { RootModel::B, BModel::DY });
+        selector("A::I", INT, {RootModel::A, AModel::IX});
+        selector("A::B", BOOL, {RootModel::A, AModel::BX});
+        selector("A::D", DOUBLE, {RootModel::A, AModel::DX});
+        selector("B::I", INT, {RootModel::B, BModel::IY});
+        selector("B::B", BOOL, {RootModel::B, BModel::BY});
+        selector("B::D", DOUBLE, {RootModel::B, BModel::DY});
     }
 
-    virtual ~AView()
-    { }
+    virtual ~AView() { }
 };
 
-typedef artis::observer::Output < artis::utils::DoubleTime,
-                                  ModelParameters > AnOutput;
+typedef artis::observer::Output<artis::utils::DoubleTime,
+        ModelParameters> AnOutput;
 
 //TEST_CASE("Simulator_tests", "simple")
 int main()
@@ -129,7 +129,7 @@ int main()
                      "] }");
 
     AContext context(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
-                     artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
+            artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
     ASimulator simulator(builder.build(), globalParameters);
 
     simulator.attachView("Root", new AView);