Parcourir la source

Refactoring: coding style

Eric Ramat il y a 7 ans
Parent
commit
b378ae6911

+ 46 - 36
src/artis/kernel/AbstractAtomicModel.hpp

@@ -50,7 +50,7 @@ public:
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >(
                    true,
-                   boost::core::demangle(typeid(T).name()), // .erase(0,6),
+                   boost::core::demangle(typeid(T).name()),
                    utils::DoubleTime::null,
                    utils::CONSTRUCT);
         utils::Trace < utils::DoubleTime >::trace().flush();
@@ -112,6 +112,7 @@ public:
         if (type::last_time != t) {
             throw utils::InvalidGet("Variable not computed");
         }
+
         Any value = Internals < T, U, V >::get(index);
 
         return static_cast < const T* >(this)->*(value.get < T, W >());
@@ -123,6 +124,7 @@ public:
         if (type::last_time != t) {
             throw utils::InvalidGet("Variable not computed");
         }
+
         Any value = Internals < T, U, V >::get(index);
 
         switch (value_type) {
@@ -178,76 +180,84 @@ public:
     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_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_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_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);}
+    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
+    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)
+                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
+    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::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
+    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::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
+    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);
     }
-
-
 };
 
 } }

+ 88 - 95
src/artis/kernel/AbstractCoupledModel.hpp

@@ -77,10 +77,10 @@ public:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >(
-                   true,
-                   boost::core::demangle(typeid(T).name()), // .erase(0,6),
-                   utils::DoubleTime::null,
-                   utils::CONSTRUCT);
+                true,
+                boost::core::demangle(typeid(T).name()),
+                utils::DoubleTime::null,
+                utils::CONSTRUCT);
         utils::Trace < utils::DoubleTime >::trace().flush();
 #endif
     }
@@ -294,10 +294,10 @@ public:
                     "/[" + std::to_string(i) + "]" +
                     boost::core::demangle(typeid(*this).name());
             } else {
-                return p + "/" + boost::core::demangle(typeid(*this).name()); // .erase(0,6);
+                return p + "/" + boost::core::demangle(typeid(*this).name());
             }
         } else {
-            return boost::core::demangle(typeid(*this).name()); // .erase(0,6);
+            return boost::core::demangle(typeid(*this).name());
         }
     }
 
@@ -345,101 +345,94 @@ public:
         }
     }
 
-    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_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_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_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);}
+    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
+    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)
+                from_kernel,
+                AbstractCoupledModel < T, U, V, W >::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
+    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::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 trace_externals(bool from_kernel, typename U::type t, utils::TraceType type = utils::NONE) const
+    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::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();
             }
         }
     }
 
-    void trace_model(bool from_kernel, typename U::type t, utils::TraceType type = utils::NONE) const
+    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);
-        typename AbstractCoupledModel::Submodels::const_iterator it =
-                submodels.begin();
 
-//        while (it != submodels.end()) {
-//            it->second->trace_model(from_kernel, t, type);
-//            ++it;
-//        }
+        // typename AbstractCoupledModel::Submodels::const_iterator it =
+        //     submodels.begin();
+
+        // while (it != submodels.end()) {
+        //     it->second->trace_model(from_kernel, t, type);
+        //     ++it;
+        // }
     }
 
 protected:
-//     void change_internal(unsigned int index, double T::* var)
-//     {
-//         submodel_internals.erase(index);
-//         Internals < T, U, V >::internal(index, var);
-//     }
-
-//     void change_internal(unsigned int index, int T::* var)
-//     {
-//         submodel_internals.erase(index);
-//         Internals < T, U, V >::internalI(index, var);
-//     }
-
-//     void change_internal(unsigned int index, bool T::* var)
-//     {
-//         submodel_internals.erase(index);
-//         Internals < T, U, V >::internalB(index, var);
-//     }
-
     void link_internal_(unsigned int index, std::string var_name,
                         type* model, int sub_index, std::string sub_var_name)
     {
@@ -447,15 +440,15 @@ protected:
             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::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
@@ -471,15 +464,15 @@ protected:
 
 #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::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
         }
@@ -495,15 +488,15 @@ protected:
             it->second->set_parent(this);
 
 #ifdef WITH_TRACE
-        utils::Trace < utils::DoubleTime >::trace()
+            utils::Trace < utils::DoubleTime >::trace()
                 << utils::TraceElement < utils::DoubleTime >(
-                       true,
-                       AbstractCoupledModel < T, U, V, W >::path(this),
-                       utils::DoubleTime::null,
-                       utils::SUBMODEL_ADD)
+                    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();
+                    AbstractCoupledModel < T, U, V, W >::path(it->second));
+            utils::Trace < utils::DoubleTime >::trace().flush();
 #endif
 
         }
@@ -519,13 +512,13 @@ protected:
 
 #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::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
     }

+ 14 - 10
src/artis/kernel/AbstractModel.hpp

@@ -82,12 +82,12 @@ public:
         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;
@@ -136,10 +136,14 @@ public:
 
     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;
+    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; }

+ 44 - 35
src/artis/utils/Trace.hpp

@@ -65,13 +65,6 @@ static const std::vector <std::string> TraceTypesStr = {
 class KernelInfo
 {
 public:
-    const std::string& var() const {return _var;}
-    const std::string& value() const {return _value;}
-    const std::string& tgt_model() const {return _tgt_model;}
-    const std::string& tgt_internal_var() const {return _tgt_internal_var;}
-    bool is_internal_var() const {return _internal_var;}
-    bool empty() const {return _empty;}
-
     KernelInfo() :
         _var(""), _internal_var(false), _value(""),
         _tgt_model(""), _tgt_internal_var(""), _empty(true)
@@ -101,9 +94,26 @@ public:
         _empty(false)
     { }
 
+    const std::string& var() const
+    { return _var; }
+
+    const std::string& value() const
+    { return _value; }
+
+    const std::string& tgt_model() const
+    { return _tgt_model; }
+
+    const std::string& tgt_internal_var() const
+    { return _tgt_internal_var; }
 
+    bool is_internal_var() const
+    { return _internal_var; }
 
-    std::string to_string() const {
+    bool empty() const
+    { return _empty; }
+
+    std::string to_string() const
+    {
         std::ostringstream ss;
         if( not _var.empty() ){
             ss << ":";
@@ -111,7 +121,6 @@ public:
                 ss << "*";
             ss << _var;
         }
-
         if( not _value.empty()) {
             ss << "=" << _value;
         }
@@ -121,18 +130,16 @@ public:
                 ss << ":" << _tgt_internal_var;
             }
         }
-
         return ss.str();
     }
 
 private:
-    std::string         _var;
-    bool                _internal_var;
-    std::string         _value;
-    std::string         _tgt_model;
-    std::string         _tgt_internal_var;
-    bool                _empty;
-
+    std::string _var;
+    bool        _internal_var;
+    std::string _value;
+    std::string _tgt_model;
+    std::string _tgt_internal_var;
+    bool        _empty;
 };
 
 template < class Time >
@@ -150,8 +157,8 @@ class TraceElement
     friend class artis::kernel::Externals;
 
 private:
-    TraceElement(bool from_kernel, const std::string& model_name, typename Time::type time,
-                 TraceType type) :
+    TraceElement(bool from_kernel, const std::string& model_name,
+                 typename Time::type time, TraceType type) :
         _model_name(model_name), _time(time), _type(type),
         _from_kernel(from_kernel)
     { }
@@ -199,9 +206,8 @@ private:
     typename Time::type _time;
     TraceType           _type;
     std::string         _comment;
-    KernelInfo         _kernel_info;
-    bool _from_kernel;
-
+    KernelInfo          _kernel_info;
+    bool                _from_kernel;
 };
 
 template < class Time >
@@ -210,6 +216,7 @@ class TraceElements : public std::vector < TraceElement < Time > >
 public:
     TraceElements()
     { }
+
     virtual ~TraceElements()
     { }
 
@@ -269,8 +276,8 @@ public:
         return result;
     }
 
-
-    std::string to_string(artis::utils::DateFormat date_format = artis::utils::DATE_FORMAT_EXTENDED) const
+    std::string to_string(artis::utils::DateFormat date_format =
+                          artis::utils::DATE_FORMAT_EXTENDED) const
     {
         std::ostringstream ss;
 
@@ -278,13 +285,15 @@ public:
              TraceElements < Time >::begin();
              it != TraceElements < Time >::end(); ++it) {
             ss << (it->from_kernel() ? "KERNEL" : "TRACE ");
-            if(it->get_time() != Time::null) {
-               ss << "(" << utils::DateTime::toJulianDayFmt(it->get_time(), date_format) << ")";
+            if (it->get_time() != Time::null) {
+                ss << "(" << utils::DateTime::toJulianDayFmt(it->get_time(),
+                                                             date_format)
+                   << ")";
             }
             ss << ": ";
             ss << "<" + TraceTypesStr[it->get_type()] + ">";
             ss << " " << it->get_model_name();
-            if(not it->get_kernel_info().empty()) {
+            if (not it->get_kernel_info().empty()) {
                 ss << it->get_kernel_info().to_string();
             }
             if (not it->get_comment().empty()) {
@@ -361,8 +370,8 @@ private:
 
 template < class Time >
 artis::utils::Trace < Time >& operator<<(
-        artis::utils::Trace < Time >& trace,
-        const artis::utils::TraceElement < Time >& e)
+    artis::utils::Trace < Time >& trace,
+    const artis::utils::TraceElement < Time >& e)
 {
     std::lock_guard < std::mutex > lock(trace.mutex());
 
@@ -372,8 +381,8 @@ artis::utils::Trace < Time >& operator<<(
 
 template < class Time >
 artis::utils::Trace < Time >& operator<<(
-        artis::utils::Trace < Time >& trace,
-        const artis::utils::KernelInfo& info)
+    artis::utils::Trace < Time >& trace,
+    const artis::utils::KernelInfo& info)
 {
     std::lock_guard < std::mutex > lock(trace.mutex());
 
@@ -383,8 +392,8 @@ artis::utils::Trace < Time >& operator<<(
 
 template < class Time >
 artis::utils::Trace < Time >& operator<<(
-        artis::utils::Trace < Time >& trace,
-        const std::string& str)
+    artis::utils::Trace < Time >& trace,
+    const std::string& str)
 {
     std::lock_guard < std::mutex > lock(trace.mutex());
 
@@ -394,8 +403,8 @@ artis::utils::Trace < Time >& operator<<(
 
 template < class Time >
 artis::utils::Trace < Time >& operator<<(
-        artis::utils::Trace < Time >& trace,
-        typename Time::type t)
+    artis::utils::Trace < Time >& trace,
+    typename Time::type t)
 {
     std::lock_guard < std::mutex > lock(trace.mutex());