Mantid
Loading...
Searching...
No Matches
MapSupport.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
19#include "MantidGeometry/DllConfig.h"
20#include "MantidKernel/Logger.h"
21
22namespace {
23Mantid::Kernel::Logger logger("MapSupport");
24}
25namespace MapSupport {
37// Note this needs to be non-constant unary_function return
38template <typename T, typename U> class PFirst {
39public:
41 T operator()(const std::pair<T, U> &A) { return A.first; }
42};
43
52template <typename T, typename U> class PSecond {
53public:
55 U operator()(const std::pair<T, U> &A) { return A.second; }
56};
57
68template <typename KeyPart, typename NumPart> class valEqual {
69private:
70 const NumPart value;
71
72public:
74 valEqual(const NumPart &V) : value(V) {}
75
77 bool operator()(const std::pair<KeyPart, NumPart> &A) const { return A.second == value; }
78};
93template <typename KeyPart, typename PtrPart> class mapClone {
94public:
96 std::pair<KeyPart, PtrPart> operator()(const std::pair<KeyPart, PtrPart> &A) const {
97 return std::pair<KeyPart, PtrPart>(A.first, A.second->clone());
98 }
99};
100
112template <typename KeyPart, typename PtrPart> class mapDelete {
113public:
115 void operator()(std::pair<const KeyPart, PtrPart> &A) {
116 delete A.second;
117 A.second = 0;
118 }
119};
120
131template <typename KeyPart, typename BodyPart> class mapSwap {
132public:
134 std::pair<BodyPart, KeyPart> operator()(const std::pair<KeyPart, BodyPart> &A) const {
135 return std::pair<BodyPart, KeyPart>(A.second, A.first);
136 }
137};
138
149template <typename PartA, typename PartB> class mapWrite {
150public:
152 void operator()(const std::pair<PartA, PartB> &A) const { logger.debug() << A.first << " " << A.second << '\n'; }
153};
154
172template <typename KeyPart, typename NumPart> class sndValue {
173private:
174 const std::map<KeyPart, NumPart> &MRef;
175
176public:
178 sndValue(const std::map<KeyPart, NumPart> &Mr) : MRef(Mr) {}
179
181 NumPart operator()(const KeyPart &Ky) const {
182 typename std::map<KeyPart, NumPart>::const_iterator vc;
183 vc = MRef.find(Ky);
184 return vc->second;
185 }
186};
187} // namespace MapSupport
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
Class to access the first object in index pair.
Definition: MapSupport.h:38
T operator()(const std::pair< T, U > &A)
Functional to the first object.
Definition: MapSupport.h:41
Class to access the second object in index pair.
Definition: MapSupport.h:52
U operator()(const std::pair< T, U > &A)
Functional to the first object.
Definition: MapSupport.h:55
Functor for coping map elements with clone functions.
Definition: MapSupport.h:93
std::pair< KeyPart, PtrPart > operator()(const std::pair< KeyPart, PtrPart > &A) const
clone function to return insert object
Definition: MapSupport.h:96
Functor for deleting the second component of a map.
Definition: MapSupport.h:112
void operator()(std::pair< const KeyPart, PtrPart > &A)
deletion of the map:second ptr
Definition: MapSupport.h:115
Functor for reversing a map.
Definition: MapSupport.h:131
std::pair< BodyPart, KeyPart > operator()(const std::pair< KeyPart, BodyPart > &A) const
Operator()
Definition: MapSupport.h:134
Functor quick write out of a map.
Definition: MapSupport.h:149
void operator()(const std::pair< PartA, PartB > &A) const
Write both the key and object.
Definition: MapSupport.h:152
Functor to get second point in a map.
Definition: MapSupport.h:172
NumPart operator()(const KeyPart &Ky) const
Access via key.
Definition: MapSupport.h:181
sndValue(const std::map< KeyPart, NumPart > &Mr)
Create with Map.
Definition: MapSupport.h:178
const std::map< KeyPart, NumPart > & MRef
Map begin accessd.
Definition: MapSupport.h:174
Functor using second value as equal.
Definition: MapSupport.h:68
const NumPart value
Value to check against map.
Definition: MapSupport.h:70
valEqual(const NumPart &V)
Set Value to check.
Definition: MapSupport.h:74
bool operator()(const std::pair< KeyPart, NumPart > &A) const
Equality operator vs Map second object.
Definition: MapSupport.h:77
Holds stuff for manipulating maps.