FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
FiberTypeMap.hpp
1#ifndef FIBERTYPEMAP_HPP
2#define FIBERTYPEMAP_HPP "Created 20.06.2020 12:20:27 by werner"
3
4#include "FiberTypeBase.hpp"
5
6#include <memcore/RefPtr.hpp>
7#include <map>
8#include <ranges>
9
10#include "FieldAPI.h"
11
12namespace Fiber
13{
14
18template <class TypeProperty>
19struct FiberTypeMap : std::map<FiberTypeIndex, MemCore::RefPtr<TypeProperty>>
20{
22
23 bool insert(const MemCore::RefPtr<FiberTypeBase>&Index,
25 {
26 if (!Index) return false;
27
28 (*this)[ Index->getFiberTypeIndex() ] = Property;
29 return true;
30 }
31
33 find(const FiberTypeIndex&FTI) const
34 {
35 auto f = base_t::find(FTI);
36 if (f == this->end())
37 return nullptr;
38
39 return f->second;
40 }
41
43 find(const MemCore::RefPtr<FiberTypeBase>&FTB) const
44 {
45 if (!FTB)
46 return nullptr;
47
48 return find(FTB->getFiberTypeIndex());
49 }
50
51
52static FiberTypeMap&theMap()
53 {
54 static FiberTypeMap myMap;
55 return myMap;
56 }
57
58static bool remember(const MemCore::RefPtr<FiberTypeBase>&Index,
60 {
61 return theMap().insert( Index, Property );
62 }
63
66 {
67 return theMap().find(FTB);
68 }
69};
70
71
75template <class TypeProperty>
76struct FiberTypeMultiMap : std::multimap<FiberTypeIndex, MemCore::RefPtr<TypeProperty>>
77{
79
80 bool insert(const MemCore::RefPtr<FiberTypeBase>&Index,
82 {
83 if (!Index) return false;
84
85 (*this).emplace( Index->getFiberTypeIndex(), Property);
86 return true;
87 }
88
89 template <typename I>
90 struct iter_pair : std::pair<I, I>
91 {
92 using std::pair<I, I>::pair;
93
94 I begin() { return this->first; }
95 I end() { return this->second; }
96 };
97
98
99// iter_pair<typename base_t::const_iterator>
100 auto find(const FiberTypeIndex&FTI) const
101 {
102 return base_t::equal_range(FTI);
103 }
104
105
106 auto find(const MemCore::RefPtr<FiberTypeBase>&FTB) const
107 {
108 if (!FTB)
109 return nullptr;
110
111 return find(FTB->getFiberTypeIndex());
112 }
113
114
115static FiberTypeMultiMap&theMap()
116 {
117 static FiberTypeMultiMap myMap;
118 return myMap;
119 }
120
121static bool remember(const MemCore::RefPtr<FiberTypeBase>&Index,
122 const MemCore::RefPtr<TypeProperty>&Property)
123 {
124 return theMap().insert( Index, Property );
125 }
126
128 get(const FiberTypeIndex&FTI)
129 {
130 auto [a,b] = theMap().find(FTI);
131#if 1
132 for(auto r = a; r !=b; r++ )
133#else
134 for(auto r : std::ranges::iota_view(a,b) )
135#endif
136 {
137 if (r->second)
138 return r->second;
139 }
140 return nullptr;
141 }
142
144 get(const MemCore::RefPtr<FiberTypeBase>&FTB)
145 {
146 auto R = theMap().find(FTB);
147 for(auto r : R)
148 {
149 if (r.second)
150 return r.second;
151 }
152 return nullptr;
153 }
154};
155
156
157} /* namespace Fiber */
158
159#endif /* FIBERTYPEMAP_HPP */
constexpr pair()
iterator emplace(_Args &&... __args)
std::pair< iterator, iterator > equal_range(const key_type &__x)
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
STL namespace.
Definition FiberTypeIndex.hpp:12
https://stackoverflow.com/questions/17614172/c-template-singletons-in-a-dll
Definition FiberTypeMap.hpp:20
Definition FiberTypeMap.hpp:91
https://stackoverflow.com/questions/17614172/c-template-singletons-in-a-dll
Definition FiberTypeMap.hpp:77