QuantityConversionKey.h
1/* Distributed under the Apache License, Version 2.0.
2 See accompanying NOTICE file for details.*/
3
4//----------------------------------------------------------------------------
10//----------------------------------------------------------------------------
11
12#pragma once
13
15{
16public:
17 // Construct from two Quantity Type IDs
18 // This is called by the code that parses the initialization file and
19 // creates the hash map entry
20 CQuantityConversionKey(int fromId, int toID);
21
22 // Construct from two UnitDimension pointers
24 :m_CUDfromDim(fromDim), m_CUDtoDim(toDim)
25 {
26 // Do nothing
27 }
28
29 // override less-than operator to facilitate default hash comparison function
30 bool operator< (const CQuantityConversionKey &rhs) const;
31
32 // For the sake of completeness only, implement the other relational operators
33 bool operator>(const CQuantityConversionKey &rhs) const
34 {
35 return rhs < *this;
36 }
37
38 bool operator <=(const CQuantityConversionKey &rhs) const
39 {
40 return !(*this > rhs);
41 }
42
43 bool operator >=(const CQuantityConversionKey &rhs) const
44 {
45 return !(*this < rhs);
46 }
47
48 bool operator ==(const CQuantityConversionKey &rhs) const;
49
50 bool operator !=(const CQuantityConversionKey &rhs) const
51 {
52 return ! (*this == rhs);
53 }
54
55
56 // Compute a hash value from an array of the two hash values of the From and
57 // To Dimension objects
58 size_t hash_value() const;
59
60private:
61 // Regardless of how we're constructed, these two CUnitDimension pointers
62 // are "owned" by other objects. In the case of the one physically stored in
63 // the hash table, the pointers are owned by the QuantityTypeDescriptor objects
64 // referenced by name in the initializaiton file. In the case of one constructed
65 // in the course of hash table lookup, it's owned by the compound unit objects
66 // involved in the type conversion.
69};
70
71// Overload non_member hash_value on CQuantityConversionKey so that the
72// templated hash_compare used by hash_map can call it.
73inline size_t hash_value(const CQuantityConversionKey &ref)
74{
75 return ref.hash_value();
76}
77
78namespace std
79{
80 template<>
82 {
83 size_t operator()(const CQuantityConversionKey& ref) const
84 {
85 return ref.hash_value();
86 }
87 };
88}
89
90
Definition: QuantityConversionKey.h:15
CQuantityConversionKey(int fromId, int toID)
Definition: QuantityConversionKey.cpp:12
bool operator<=(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.h:38
bool operator==(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.cpp:51
CQuantityConversionKey(const CUnitDimension *fromDim, const CUnitDimension *toDim)
Definition: QuantityConversionKey.h:23
bool operator>=(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.h:43
const CUnitDimension * m_CUDfromDim
Definition: QuantityConversionKey.h:67
bool operator<(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.cpp:36
const CUnitDimension * m_CUDtoDim
Definition: QuantityConversionKey.h:68
bool operator>(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.h:33
size_t hash_value() const
Definition: QuantityConversionKey.cpp:27
bool operator!=(const CQuantityConversionKey &rhs) const
Definition: QuantityConversionKey.h:50
Definition: UnitDimension.h:22
STL namespace.
size_t operator()(const CQuantityConversionKey &ref) const
Definition: QuantityConversionKey.h:83

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.