LIBINT 2.9.0
equiv.h
1/*
2 * Copyright (C) 2004-2024 Edward F. Valeev
3 *
4 * This file is part of Libint compiler.
5 *
6 * Libint compiler 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 compiler 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 compiler. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#include <global_macros.h>
22#include <smart_ptr.h>
23
24#ifndef _libint2_src_bin_libint_equiv_h_
25#define _libint2_src_bin_libint_equiv_h_
26
27namespace libint2 {
28
35template <class T>
36class PtrEquiv {
37 public:
39 typedef typename T::parent_type P;
40
41 static bool equiv(const T& a, const T& b) { return a == b; }
42
43 static bool equiv(const std::shared_ptr<T>& a, const std::shared_ptr<T>& b) {
44 return a->operator==(*b.get());
45 }
46
47 static bool equiv(const T* a, const std::shared_ptr<T>& b) {
48 return a->operator==(*b.get());
49 }
50
51 static bool equiv(const std::shared_ptr<T>& b, const T* a) {
52 return a->operator==(*b.get());
53 }
54
55 static bool equiv(const T* a, const T& b) { return a->operator==(b); }
56
57#if !PTREQUIV_USE_TYPEID
58
59 static bool equiv(const std::shared_ptr<T>& a, const std::shared_ptr<P>& b) {
60 std::shared_ptr<T> b_cast = std::dynamic_pointer_cast<T, P>(b);
61 if (b_cast == 0)
62 return false;
63 else
64 return a->operator==(*b_cast.get());
65 }
66
67 static bool equiv(const T* a, const std::shared_ptr<P>& b) {
68 std::shared_ptr<T> b_cast = std::dynamic_pointer_cast<T, P>(b);
69 if (b_cast == 0)
70 return false;
71 else
72 return a->operator==(*b_cast.get());
73 }
74
75 static bool equiv(const T* a, const std::shared_ptr<DGVertex>& b) {
76 std::shared_ptr<T> b_cast = std::dynamic_pointer_cast<T, DGVertex>(b);
77 if (b_cast == 0)
78 return false;
79 else
80 return a->operator==(*b_cast.get());
81 }
82
83#else
84
85 static bool equiv(const std::shared_ptr<T>& a, const std::shared_ptr<P>& b) {
86 if (a->typeid_ != b->typeid_)
87 return false;
88 else {
89 std::shared_ptr<T> b_cast = std::static_pointer_cast<T, P>(b);
90 return a->operator==(*b_cast.get());
91 }
92 }
93
94 static bool equiv(const T* a, const std::shared_ptr<DGVertex>& b) {
95 if (a->typeid_ != b->typeid_)
96 return false;
97 else {
98#if PTREQUIV_USE_KEY_TO_COMPARE
99#if PTREQUIV_USE_INSTID
100 return a->instid_ == b->instid_;
101#else
102 return a->label() == b->label();
103#endif
104#else
105 std::shared_ptr<T> b_cast = std::static_pointer_cast<T, DGVertex>(b);
106 return a->operator==(*b_cast.get());
107#endif
108 }
109 }
110
111#endif
112};
113
114/*
115 static bool equiv(const std::shared_ptr<parent_type>& b, const
116 std::shared_ptr<T>& a) const { std::shared_ptr<T> b_cast =
117 std::dynamic_pointer_cast<T,parent_type>(b); if (b_cast == 0) return false;
118 else
119 return a->operator==(*b_cast.get())
120 }
121 */
122
123}; // namespace libint2
124
125#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:39
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24