QuantityConversionKey.h
1 /**************************************************************************************
2 Copyright 2015 Applied Research Associates, Inc.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 this file except in compliance with the License. You may obtain a copy of the License
5 at:
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software distributed under
8 the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9 CONDITIONS OF ANY KIND, either express or implied. See the License for the
10 specific language governing permissions and limitations under the License.
11 **************************************************************************************/
12 
13 //----------------------------------------------------------------------------
19 //----------------------------------------------------------------------------
20 
21 #pragma once
22 
23 #include <biogears/exports.h>
24 namespace biogears{
25 class CUnitDimension;
26 class CQuantityConversionKey;
27 
29 public:
30  // Construct from two Quantity Type IDs
31  // This is called by the code that parses the initialization file and
32  // creates the hash map entry
33  CQuantityConversionKey(int fromId, int toID);
34 
35  // Construct from two UnitDimension pointers
37  : m_CUDfromDim(fromDim)
38  , m_CUDtoDim(toDim)
39  {
40  // Do nothing
41  }
42 
43  // override less-than operator to facilitate default hash comparison function
44  bool operator<(const CQuantityConversionKey& rhs) const;
45 
46  // For the sake of completeness only, implement the other relational operators
47  bool operator>(const CQuantityConversionKey& rhs) const
48  {
49  return rhs < *this;
50  }
51 
52  bool operator<=(const CQuantityConversionKey& rhs) const
53  {
54  return !(*this > rhs);
55  }
56 
57  bool operator>=(const CQuantityConversionKey& rhs) const
58  {
59  return !(*this < rhs);
60  }
61 
62  bool operator==(const CQuantityConversionKey& rhs) const;
63 
64  bool operator!=(const CQuantityConversionKey& rhs) const
65  {
66  return !(*this == rhs);
67  }
68 
69  // Compute a hash value from an array of the two hash values of the From and
70  // To Dimension objects
71  size_t hash_value() const;
72 
73 private:
74  // Regardless of how we're constructed, these two CUnitDimension pointers
75  // are "owned" by other objects. In the case of the one physically stored in
76  // the hash table, the pointers are owned by the QuantityTypeDescriptor objects
77  // referenced by name in the initializaiton file. In the case of one constructed
78  // in the course of hash table lookup, it's owned by the compound unit objects
79  // involved in the type conversion.
82 };
83 
84 // Overload non_member hash_value on CQuantityConversionKey so that the
85 // templated hash_compare used by hash_map can call it.
86 inline size_t hash_value(const CQuantityConversionKey& ref)
87 {
88  return ref.hash_value();
89 }
90 } //namespace biogears
91 
92 namespace std {
93 template <>
94 struct hash<biogears::CQuantityConversionKey> {
96  {
97  return ref.hash_value();
98  }
99 };
100 }//namespace std
Definition: QuantityConversionKey.h:28
size_t hash_value(const CQuantityConversionKey &ref)
Definition: QuantityConversionKey.h:86
bool operator>=(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.h:57
CQuantityConversionKey(const CUnitDimension *fromDim, const CUnitDimension *toDim)
Definition: QuantityConversionKey.h:36
STL namespace.
const CUnitDimension * m_CUDfromDim
Definition: QuantityConversionKey.h:80
const CUnitDimension * m_CUDtoDim
Definition: QuantityConversionKey.h:81
size_t hash_value() const
Definition: QuantityConversionKey.cpp:39
bool operator<(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.cpp:48
bool operator<=(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.h:52
bool operator!=(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.h:64
bool operator==(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.cpp:62
Definition: UnitDimension.h:35
size_t operator()(const biogears::CQuantityConversionKey &ref) const
Definition: QuantityConversionKey.h:95
CQuantityConversionKey(int fromId, int toID)
Definition: QuantityConversionKey.cpp:25
Definition: SEElectricalCircuit.h:18
bool operator>(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.h:47