votca 2024.2-dev
Loading...
Searching...
No Matches
triplelist.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2019 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#ifndef VOTCA_CSG_TRIPLELIST_H
19#define VOTCA_CSG_TRIPLELIST_H
20
21// Standard includes
22#include <map>
23#include <vector>
24
25namespace votca {
26namespace csg {
27
28template <typename element_type, typename triple_type>
30 public:
31 TripleList() = default;
32 virtual ~TripleList() { Cleanup(); }
33
34 void AddTriple(triple_type *t);
35
36 using iterator = typename std::vector<triple_type *>::iterator;
37
38 iterator begin() { return triples_.begin(); }
39 iterator end() { return triples_.end(); }
40 typename std::vector<triple_type *>::size_type size() {
41 return triples_.size();
42 }
43 triple_type *front() { return triples_.front(); }
44 triple_type *back() { return triples_.back(); }
45 bool empty() { return triples_.empty(); }
46
47 void Cleanup();
48
49 triple_type *FindTriple(element_type e1, element_type e2, element_type e3);
50
51 using element_t = element_type;
52 using triple_t = triple_type;
53
54 private:
55 std::vector<triple_type *> triples_;
56
57 std::map<element_type,
58 std::map<element_type, std::map<element_type, triple_type *>>>
60};
61
62template <typename element_type, typename triple_type>
64 //(*t)[i] gives access to ith element of tuple object (i=0,1,2).
65 // only consider the permutations of elements (1,2) of the tuple object ->
66 // tuple objects of the form (*,1,2) and (*,2,1) are considered to be the same
67 triple_map_[std::get<0>(*t)][std::get<1>(*t)][std::get<2>(*t)] = t;
68 triple_map_[std::get<0>(*t)][std::get<2>(*t)][std::get<1>(*t)] = t;
70 triples_.push_back(t);
71}
72
73template <typename element_type, typename triple_type>
75 for (iterator iter = triples_.begin(); iter != triples_.end(); ++iter) {
76 delete *iter;
77 }
78 triples_.clear();
79 triple_map_.clear();
80}
81
82template <typename element_type, typename triple_type>
84 element_type e1, element_type e2, element_type e3) {
85 typename std::map<
86 element_type,
87 std::map<element_type, std::map<element_type, triple_type *>>>::iterator
88 iter1;
89 iter1 = triple_map_.find(e1);
90 if (iter1 == triple_map_.end()) {
91 return nullptr;
92 }
93
94 typename std::map<element_type,
95 std::map<element_type, triple_type *>>::iterator iter2;
96 iter2 = iter1->second.find(e2);
97 if (iter2 == iter1->second.end()) {
98 return nullptr;
99 }
100
101 typename std::map<element_type, triple_type *>::iterator iter3;
102 iter3 = iter2->second.find(e3);
103 if (iter3 == iter2->second.end()) {
104 return nullptr;
105 }
106
107 return iter3->second;
108}
109
110} // namespace csg
111} // namespace votca
112
113#endif /* VOTCA_CSG_TRIPLELIST_H */
void AddTriple(triple_type *t)
Definition triplelist.h:63
typename std::vector< triple_type * >::iterator iterator
Definition triplelist.h:36
triple_type * back()
Definition triplelist.h:44
element_type element_t
Definition triplelist.h:51
std::vector< triple_type * >::size_type size()
Definition triplelist.h:40
triple_type * FindTriple(element_type e1, element_type e2, element_type e3)
Definition triplelist.h:83
triple_type * front()
Definition triplelist.h:43
std::vector< triple_type * > triples_
Definition triplelist.h:55
std::map< element_type, std::map< element_type, std::map< element_type, triple_type * > > > triple_map_
Definition triplelist.h:59
base class for all analysis tools
Definition basebead.h:33