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