LIBINT  2.1.0-stable
equiv.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 #include <smart_ptr.h>
21 #include <global_macros.h>
22 
23 #ifndef _libint2_src_bin_libint_equiv_h_
24 #define _libint2_src_bin_libint_equiv_h_
25 
26 namespace libint2 {
27 
34  template <class T>
35  class PtrEquiv {
36 
37  public:
38 
40  typedef typename T::parent_type P;
41 
42  static bool equiv(const T& a, const T& b) {
43  return a==b;
44  }
45 
46  static bool equiv(const SafePtr<T>& a, const SafePtr<T>& b) {
47  return a->operator==(*b.get());
48  }
49 
50  static bool equiv(const T* a, const SafePtr<T>& b) {
51  return a->operator==(*b.get());
52  }
53 
54  static bool equiv(const SafePtr<T>& b, const T* a) {
55  return a->operator==(*b.get());
56  }
57 
58  static bool equiv(const T* a, const T& b) {
59  return a->operator==(b);
60  }
61 
62 #if !PTREQUIV_USE_TYPEID
63 
64  static bool equiv(const SafePtr<T>& a, const SafePtr<P>& b) {
65  SafePtr<T> b_cast = dynamic_pointer_cast<T,P>(b);
66  if (b_cast == 0)
67  return false;
68  else
69  return a->operator==(*b_cast.get());
70  }
71 
72  static bool equiv(const T* a, const SafePtr<P>& b) {
73  SafePtr<T> b_cast = dynamic_pointer_cast<T,P>(b);
74  if (b_cast == 0)
75  return false;
76  else
77  return a->operator==(*b_cast.get());
78  }
79 
80  static bool equiv(const T* a, const SafePtr<DGVertex>& b) {
81  SafePtr<T> b_cast = dynamic_pointer_cast<T,DGVertex>(b);
82  if (b_cast == 0)
83  return false;
84  else
85  return a->operator==(*b_cast.get());
86  }
87 
88 #else
89 
90  static bool equiv(const SafePtr<T>& a, const SafePtr<P>& b) {
91  if (a->typeid_ != b->typeid_)
92  return false;
93  else {
94  SafePtr<T> b_cast = static_pointer_cast<T,P>(b);
95  return a->operator==(*b_cast.get());
96  }
97  }
98 
99  static bool equiv(const T* a, const SafePtr<DGVertex>& b) {
100  if (a->typeid_ != b->typeid_)
101  return false;
102  else {
103 #if PTREQUIV_USE_KEY_TO_COMPARE
104  #if PTREQUIV_USE_INSTID
105  return a->instid_ == b->instid_;
106  #else
107  return a->label() == b->label();
108  #endif
109 #else
110  SafePtr<T> b_cast = static_pointer_cast<T,DGVertex>(b);
111  return a->operator==(*b_cast.get());
112 #endif
113  }
114  }
115 
116 #endif
117 
118  };
119 
120  /*
121  static bool equiv(const SafePtr<parent_type>& b, const SafePtr<T>& a) const {
122  SafePtr<T> b_cast = dynamic_pointer_cast<T,parent_type>(b);
123  if (b_cast == 0)
124  return false;
125  else
126  return a->operator==(*b_cast.get())
127  }
128  */
129 
130 };
131 
132 #endif
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
This is a vertex of a Directed Graph (DG)
Definition: dgvertex.h:42
T::parent_type P
A shortcut for T::parent_type.
Definition: equiv.h:40
PtrEquiv<T> provides a set of comparison functions named &#39;equiv&#39; which take as arguments a mix of ref...
Definition: equiv.h:35