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