67 #ifndef DAL_STATIC_STORED_OBJECTS_H__    68 #define DAL_STATIC_STORED_OBJECTS_H__    78 #include "getfem/getfem_arch_config.h"    80 #ifdef GETFEM_HAVE_OPENMP    81   #include <boost/atomic.hpp>    82   typedef boost::atomic_bool atomic_bool;
    83   typedef boost::atomic<int> atomic_int;
    85   typedef int   atomic_int;
    86   typedef bool  atomic_bool;
    89 #define DAL_STORED_OBJECT_DEBUG 0    94 #if DAL_STORED_OBJECT_DEBUG   101   class static_stored_object;
   102   void stored_debug_created(
const static_stored_object *o,
   103                             const std::string &name);
   104   void stored_debug_added(
const static_stored_object *o);
   105   void stored_debug_deleted(
const static_stored_object *o);
   106   void stored_debug_destroyed(
const static_stored_object *o,
   107                               const std::string &name);
   108 # define DAL_STORED_OBJECT_DEBUG_CREATED(o, name) stored_debug_created(o, name)   109 # define DAL_STORED_OBJECT_DEBUG_ADDED(o)   stored_debug_added(o)   110 # define DAL_STORED_OBJECT_DEBUG_DELETED(o) stored_debug_deleted(o)   111 # define DAL_STORED_OBJECT_DEBUG_DESTROYED(o, name) \   112                                             stored_debug_destroyed(o, name)   114 # define DAL_STORED_OBJECT_DEBUG_CREATED(o, name)   115 # define DAL_STORED_OBJECT_DEBUG_ADDED(o)   116 # define DAL_STORED_OBJECT_DEBUG_DELETED(o)   117 # define DAL_STORED_OBJECT_DEBUG_DESTROYED(o, name)   120   enum permanence { PERMANENT_STATIC_OBJECT = 0, 
   121     STRONG_STATIC_OBJECT = 1,    
   122     STANDARD_STATIC_OBJECT = 2,  
   123     WEAK_STATIC_OBJECT = 3,      
   124     AUTODELETE_STATIC_OBJECT = 4 
   128   class static_stored_object_key {
   130     virtual bool compare(
const static_stored_object_key &)
 const {
   131       GMM_ASSERT1(
false, 
"This method should not be called");
   135     bool operator < (
const static_stored_object_key &o)
 const {
   137       if (
typeid(*this).before(
typeid(o))) 
return true;
   138       if (
typeid(o).before(
typeid(*
this))) 
return false;
   142     virtual ~static_stored_object_key() {}
   147   template <
typename var_type>
   148   class simple_key : 
virtual public static_stored_object_key {
   151     virtual bool compare(
const static_stored_object_key &oo)
 const {
   152       const simple_key &o = 
dynamic_cast<const simple_key &
>(oo);
   155     simple_key(var_type aa) : a(aa) {}
   158 #define DAL_SIMPLE_KEY(class_name, var_type)                            \   159   struct class_name : public dal::simple_key<var_type> {                \   160   class_name(var_type aa) : dal::simple_key<var_type>(aa) {}            \   163 #define DAL_DOUBLE_KEY(class_name, var_type1, var_type2)                \   164   struct class_name :                                                   \   165   public dal::simple_key<std::pair<var_type1,var_type2> > {             \   166   class_name(var_type1 aa, var_type2 bb) :                              \   167   dal::simple_key<std::pair<var_type1,var_type2> >                      \   168   (std::make_pair(aa,bb)) {}                                            \   171 #define DAL_TRIPLE_KEY(class_name, var_type1, var_type2, var_type3)     \   172   struct class_name :                                                   \   173   public dal::simple_key<std::pair<var_type1,                           \   174                                    std::pair<var_type2,var_type3> > > { \   175   class_name(var_type1 aa, var_type2 bb, var_type3 cc) :                \   176     dal::simple_key<std::pair<var_type1,                                \   177                               std::pair<var_type2, var_type3> > >       \   178     (std::make_pair(aa,std::make_pair(bb,cc))) {}                       \   181 #define DAL_FOUR_KEY(class_name,var_type1,var_type2,var_type3,var_type4)\   182   struct class_name : public                                            \   183   dal::simple_key<std::pair                                             \   184                   <var_type1, std::pair<var_type2, std::pair            \   185                                         <var_type3,var_type4> > > > {   \   186     class_name(var_type1 aa, var_type2 bb, var_type3 cc,var_type4 dd) : \   187       dal::simple_key<std::pair                                         \   188                       <var_type1, std::pair<var_type2,                  \   189                                             std::pair<var_type3,        \   191       (std::make_pair(aa,std::make_pair(bb,std::make_pair(cc, dd)))) {} \   195   typedef std::shared_ptr<const static_stored_object_key>
   196     pstatic_stored_object_key;
   204   typedef std::shared_ptr<const static_stored_object> pstatic_stored_object;
   206   pstatic_stored_object_key key_of_stored_object(pstatic_stored_object o);
   215   void add_dependency(pstatic_stored_object o1, pstatic_stored_object o2);
   218   bool del_dependency(pstatic_stored_object o1, pstatic_stored_object o2);
   222                          permanence perm = STANDARD_STATIC_OBJECT);
   226     pstatic_stored_object dep1,
   227     permanence perm = STANDARD_STATIC_OBJECT) {
   234     pstatic_stored_object dep1, pstatic_stored_object dep2,
   235     permanence perm = STANDARD_STATIC_OBJECT) {
   243                     pstatic_stored_object dep1, pstatic_stored_object dep2,
   244                     pstatic_stored_object dep3,
   245                     permanence perm = STANDARD_STATIC_OBJECT) {
   254                     pstatic_stored_object dep1, pstatic_stored_object dep2,
   255                     pstatic_stored_object dep3, pstatic_stored_object dep4,
   256                     permanence perm = STANDARD_STATIC_OBJECT) {
   266                          bool ignore_unstored=
false);
   279     bool ignore_unstored);
   287     pstatic_stored_object p;
   289     const permanence perm;
   290     std::set<pstatic_stored_object> dependent_object;
   291     std::set<pstatic_stored_object> dependencies;
   293       : p(o), perm(perma) {valid = 
true;}
   295       : perm(STANDARD_STATIC_OBJECT) {valid = 
true;}
   297       : p(enr_o.p), perm(enr_o.perm), dependent_object(enr_o.dependent_object),
   298       dependencies(enr_o.dependencies){valid = 
static_cast<bool>(enr_o.perm);}
   305     pstatic_stored_object_key p;
   307     { 
return (*p) < (*(o.p)); }
   315     public std::map<enr_static_stored_object_key, enr_static_stored_object> {
   317     typedef std::map<pstatic_stored_object,pstatic_stored_object_key>
   322     pstatic_stored_object
   324     bool has_dependent_objects(pstatic_stored_object o) 
const;
   330     iterator iterator_of_object_(pstatic_stored_object o);
   334     bool del_dependency_(pstatic_stored_object o1,
   335     pstatic_stored_object o2);
   339     bool del_dependent_(pstatic_stored_object o1,
   340     pstatic_stored_object o2);
   344     bool add_dependency_(pstatic_stored_object o1,
   345     pstatic_stored_object o2);
   349     bool add_dependent_(pstatic_stored_object o1,
   350     pstatic_stored_object o2);
   351     void basic_delete_(std::list<pstatic_stored_object> &to_delete);
   353     getfem::lock_factory locks_;
   354     stored_key_tab stored_keys_;
   360   template<
typename OBJECT_TYPE>
   363     typedef typename stored_object_tab::iterator iterator;
   364     std::list<pstatic_stored_object> delete_object_list;
   370       iterator itb = stored_objects.begin();
   371       iterator ite = stored_objects.end();
   373       for(iterator it = itb; it != ite; ++it){
   374         const OBJECT_TYPE *p_object
   375           = std::dynamic_pointer_cast<
const OBJECT_TYPE>(it->second.p).
get();
   376         if(p_object != 0) delete_object_list.push_back(it->second.p);
   380       for(
size_t thread = 0; thread<getfem::num_threads();thread++)
   385         iterator itb = stored_objects.begin();
   386         iterator ite = stored_objects.end();
   388         for(iterator it = itb; it != ite; ++it){
   389           const OBJECT_TYPE *p_object
   390             = std::dynamic_pointer_cast<
const OBJECT_TYPE>(it->second.p).
get();
   391           if(p_object != 0) delete_object_list.push_back(it->second.p);
 Pointer to a key with a coherent order. 
void test_stored_objects(void)
Test the validity of the whole global storage. 
base class for static stored objects 
void list_stored_objects(std::ostream &ost)
Show a list of stored objects (for debugging purpose). 
void del_stored_object(const pstatic_stored_object &o, bool ignore_unstored)
Delete an object and the object which depend on it. 
Tools for multithreaded, OpenMP and Boost based parallelization. 
pstatic_stored_object search_stored_object(pstatic_stored_object_key k)
Gives a pointer to an object from a key pointer. 
static T & instance()
Instance from the current thread. 
defines and typedefs for namespace dal 
void add_stored_object(pstatic_stored_object_key k, pstatic_stored_object o, permanence perm)
Add an object with two optional dependencies. 
A simple singleton implementation. 
bool del_dependency(pstatic_stored_object o1, pstatic_stored_object o2)
remove a dependency. 
void add_dependency(pstatic_stored_object o1, pstatic_stored_object o2)
Add a dependency, object o1 will depend on object o2. 
void del_stored_objects(std::list< pstatic_stored_object > &to_delete, bool ignore_unstored)
Delete a list of objects and their dependencies. 
Pointer to an object with the dependencies. 
bool exists_stored_object(pstatic_stored_object o)
Test if an object is stored. 
size_t nb_stored_objects(void)
Return the number of stored objects (for debugging purpose). 
void delete_specific_type_stored_objects(bool all_thread=false)
delete all the specific type of stored objects