LIBINT  2.6.0
purgeable.h
1 /*
2  * Copyright (C) 2004-2019 Edward F. Valeev
3  *
4  * This file is part of Libint.
5  *
6  * Libint is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Libint is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Libint. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef _libint2_src_bin_libint_purgeable_h_
22 #define _libint2_src_bin_libint_purgeable_h_
23 
24 #include <dgvertex.h>
25 #include <vector>
26 #include <boost/type_traits.hpp>
27 
28 namespace libint2 {
29 
33  template <typename T>
36  static bool purgeable() {
37 
38  bool result = false;
39 
40  if (boost::is_base_of<DGVertex,T>::value == true) { // can only purge DGVertex objects
41  result = true;
42  }
43 
44  return result;
45  }
46 
48  static bool purge(const T* ref) {
49 
50  bool result = false;
51 
52  try {
53  const DGVertex* dgv_ptr = dynamic_cast<const DGVertex*>(ref);
54  if (dgv_ptr->dg() == 0)
55  result = true;
56  }
57  catch(...) {
58  }
59 
60  return result;
61  }
62  };
63 
64 
69  public:
70  virtual ~AbstractPurgeableStack() {}
71  virtual void purge() =0;
72  };
73 
78  template <typename T, typename Policy = DefaultPurgingPolicy<T> >
80  {
81  protected:
82  typedef Policy PurgingPolicy;
83 
84  virtual ~PurgeableStack() {}
85  };
86 
89  public:
90  typedef PurgeableStacks this_type;
92 
93  static this_type* Instance();
94 
95  void purge();
96  void register_stack(stack_type* stack);
97 
98  private:
99  PurgeableStacks() {}
100  static this_type* instance_;
101  std::vector<stack_type*> stacks_;
102  };
103 
104 };
105 
106 #endif
static bool purge(const T *ref)
returns true if obj should be purged
Definition: purgeable.h:48
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
PurgeableStack is a container that can be purged by calling purge() method.
Definition: purgeable.h:68
const DirectedGraph * dg() const
Returns pointer to the DirectedGraph to which this DGVertex belongs to.
Definition: dgvertex.h:152
This is a vertex of a Directed Graph (DG)
Definition: dgvertex.h:43
Collection of AbstractPurgeableStack objects.
Definition: purgeable.h:88
Determines whether an object should be purged from a stack.
Definition: purgeable.h:34
PurgeableStack is an AbstractPurgeableStack that contains objects of type T.
Definition: purgeable.h:79
static bool purgeable()
returns true if objects of this type can be purged
Definition: purgeable.h:36