GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Export.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 
31 #ifndef _libCore_Export_hpp_
32 #define _libCore_Export_hpp_
33 
34 #include <functional>
36 
37 namespace GranOO3
38 {
39  namespace Core
40  {
41 
42 
43  // This is the bindings for the gddViewer export
44  class Export
45  {
46  public:
47  template<typename T1,typename T2> static
48  void add(const std::string & key,
49  const std::string & unit,
50  T2 (T1::*Fct)() const);
51 
52  template<typename T> static
54 
55  // template<typename T1,typename T2, typename T3> static
56  // void AddProp(const std::string& key,
57  // const std::string& unit,
58  // T2 (T1::*Fct)() const);
59 
60  template<typename T>
61  class Prop
62  {
63  public:
64  template<typename T1,typename T2> static
65  void add(const std::string& key,
66  const std::string& unit,
67  T2 (T1::*Fct)() const) {
68  const std::string the_key = T::class_ID() + ExportMethod::get_separator() + T1::class_ID() + ExportMethod::get_separator() + key;
69  T* &item = *new T*(0);
70 
71  const T1& (T::*Fct1)() const = &T::template get_PropSafe<T1>;
72  std::function<const T2 ()> f = std::bind(Fct, std::bind(Fct1, std::ref(item)));
73 
74  std::vector<std::function<double ()> > vec_function;
75  std::vector<std::string> vec_key;
76 
77  ConvertToDoubleFunction(f, the_key, vec_function, vec_key);
78  for (unsigned int i = 0; i < vec_function.size(); ++i) {
79  new ExportMethodT<T> (vec_key[i], unit, vec_function[i], item);
80  }
81  }
82 
83  };
84 
85  private:
86  template<typename T> static
87  void ConvertToDoubleFunction(std::function<T ()>,
88  const std::string& key,
89  std::vector<std::function<double ()> >&,
90  std::vector<std::string>&);
91  };
92 
93 
94  template<typename T1,typename T2>
95  inline void
96  Export::add(const std::string& key,
97  const std::string& unit,
98  T2 (T1::*Fct)() const) {
99  const std::string the_key = T1::class_ID() + ExportMethod::get_separator() + key;
100 
101  // Dynamic allocation of a pointer of type "T1 *" => will remain after method exit !
102  // effective adresse will be given later ....
103  T1* &item = *new T1*(0);
104  std::function<const T2 ()> f = std::bind(Fct, std::ref(item));
105 
106  std::vector<std::function<double ()> > vec_function;
107  std::vector<std::string> vec_key;
108 
109  ConvertToDoubleFunction(f, the_key, vec_function, vec_key);
110  SafeModeAssert(vec_function.size() == vec_key.size(), "");
111  SafeModeAssert(vec_function.size() > 0, "");
112 
113  for (unsigned int i = 0; i < vec_function.size(); ++i)
114  new ExportMethodT<T1> (vec_key[i], unit, vec_function[i], item);
115  }
116 
117  }
118 }
119 
120 
121 #endif
#define SafeModeAssert(condition, message)
Definition: Macro.hpp:47
Definition: Export.hpp:62
static void add(const std::string &key, const std::string &unit, T2(T1::*Fct)() const)
Definition: Export.hpp:65
Definition: Export.hpp:45
static T get_null_value()
static void ConvertToDoubleFunction(std::function< T()>, const std::string &key, std::vector< std::function< double()> > &, std::vector< std::string > &)
static void add(const std::string &key, const std::string &unit, T2(T1::*Fct)() const)
Definition: Export.hpp:96
static std::string get_separator()
Definition: ExportMethod.cpp:40
Definition: ExportMethodT.hpp:46
Definition: Common.hpp:198
const T1
Definition: Exprtk.hpp:16489
const T1 const T2
Definition: Exprtk.hpp:16511