GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
PropClass.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Damien Andre IRCER/UNILIM, Limoges France
4 // <damien.andre@unilim.fr>
5 // - Jean-luc Charles Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
6 // <jean-luc.charles@ensam.eu>
7 // - Jeremie Girardot Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UPHF, Valenciennes France
10 // <cedric.hubert@uphf.fr>
11 // - Ivan Iordanoff Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2019 D. Andre, JL. Charles, J. Girardot, C. Hubert, I. Iordanoff
15 //
16 // This program is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // This program is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this program. If not, see <http://www.gnu.org/licenses/>.
28 
29 
30 #ifndef _LibCore_PropClass_H
31 #define _LibCore_PropClass_H
32 
33 #include <boost/serialization/version.hpp>
34 #include <boost/serialization/map.hpp>
35 #include <vector>
36 
37 #include "GranOO3/Core/Prop.hpp"
38 #include "GranOO3/Core/Macro.hpp"
39 
40 namespace GranOO3
41 {
42  namespace Core
43  {
44 
45  template <class C>
46  class PropClass
47  {
48 
49  public:
50  // Constructors and destructor
52  virtual ~PropClass();
53 
54  // Physical property management
55  template<class T> T& new_object(); // If a prop object already exist, It does nothing
56  template<class T> T& get();
57  template<class T> const T& get() const;
58  template<class T> bool prop_exist() const;
59  template<class T> void add_prop(Core::Prop<C>*);
61 
62  std::string info() const;
63 
64  private:
65  PropClass(const PropClass&) = delete;
66  PropClass & operator=(const PropClass &) = delete;
67 
68  //SERIALIZATION
70  template<class Archive> void save(Archive&, const unsigned int ) const;
71  template<class Archive> void load(Archive&, const unsigned int);
73 
74  protected:
75  std::vector<Core::Prop<C>*> _prop;
76  };
77 
78 
79 
80  // PropClassWrapper that allows an easy access to properties via
81  // the class that own these properties. It works with the
82  // GRANOO_CLASS(CLASS) macro see libCore/Macro.hpp
83  template<bool>
85  {
86  };
87 
88  template<>
89  struct PropWrapper<false>
90  {
91  template<class T2> static Null& prop(T2& p) {
92  SafeModeAssert(true, "This class does not contain property");
93  return Null::null;
94  }
95 
96  template<class T2> static const Null& get_prop(const T2& p) {
97  SafeModeAssert(true, "This class does not contain property");
98  return Null::null;
99  }
100 
101  template<class T2> static Null& new_prop() {
102  SafeModeAssert(true, "This class does not contain property");
103  return Null::null;
104  }
105 
106  };
107 
108  template<>
109  struct PropWrapper<true>
110  {
111  template<class T1, class T2> static T1& prop(T2& p) {
113  T1& t = pc.template get<T1>();
114  return (t);
115  }
116 
117  template<class T1, class T2> static const T1& get_prop(const T2& p) {
118  const PropClass<typename T1::Owner>& pc = static_cast<const PropClass<typename T1::Owner>&>(p);
119  const T1& t = pc.template get<T1>();
120  return (t);
121  }
122 
123  template<class T1, class T2> static T1& new_prop(T2& p) {
124  PropClass<T2>& pc = static_cast<PropClass<T2>&>(p);
125  if (pc.template prop_exist<T1>())
126  return pc.template get<T1>();
127 
128  T1& t = pc.template new_object<T1>();
129  return (t);
130  }
131 
132  };
133 
134 
135 
136  }
137 }
138 
139 #include "GranOO3/Core/PropClass.tpp"
140 
141 #endif
142 
#define SafeModeAssert(condition, message)
Definition: Macro.hpp:47
Definition: Null.hpp:47
static Null null
Definition: Null.hpp:49
Definition: PropClass.hpp:47
std::vector< Core::Prop< C > * > _prop
Definition: PropClass.hpp:75
std::string info() const
void save(Archive &, const unsigned int) const
void add_prop(Core::Prop< C > *)
PropClass & operator=(const PropClass &)=delete
void remove_prop(Core::Prop< C > *)
PropClass(const PropClass &)=delete
void load(Archive &, const unsigned int)
friend class boost::serialization::access
Definition: PropClass.hpp:69
const T & get() const
Definition: PropClass.hpp:85
Definition: Common.hpp:198
const T1
Definition: Exprtk.hpp:16489
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t t(t+t)") define_sfop3(16
const T1 const T2
Definition: Exprtk.hpp:16511
static Null & new_prop()
Definition: PropClass.hpp:101
static Null & prop(T2 &p)
Definition: PropClass.hpp:91
static const Null & get_prop(const T2 &p)
Definition: PropClass.hpp:96
static T1 & new_prop(T2 &p)
Definition: PropClass.hpp:123
static T1 & prop(T2 &p)
Definition: PropClass.hpp:111
static const T1 & get_prop(const T2 &p)
Definition: PropClass.hpp:117