AGX Dynamics  2.38.0.2
SymmetricPair.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_SYMMETRICPAIR_H
18 #define AGX_SYMMETRICPAIR_H
19 
20 #include <utility>
21 #include <agx/macros.h>
22 #include <agx/hash.h>
23 
24 namespace agx
25 {
26 
30  template<typename T>
31  class SymmetricPair : public std::pair<T, T>
32  {
33  public:
34  SymmetricPair() : std::pair<T, T>() {}
35  SymmetricPair(const T& a, const T& b) : std::pair<T, T>(a, b) {}
36 
37  AGX_FORCE_INLINE bool contains (const T& a ) const
38  {
39  return ( a == this->first || a == this->second );
40  }
41 
42  // Hash function
43  UInt32 hash() const;
44  };
45 
46  template<typename T>
48  {
49  return (a.first == b.first && a.second == b.second) || (a.first == b.second && a.second == b.first);
50  }
51 
52  template<typename T>
54  {
55  return !(a == b);
56  }
57 
58  template<typename T>
60  {
61  UInt32 h1 = agx::hash(this->first);
62  UInt32 h2 = agx::hash(this->second);
63 
64  if (h1 > h2 )
65  std::swap(h1, h2);
66 
67  return agx::hash( h1, h2 );
68  }
69 
70  template<typename T>
71  std::ostream& operator << ( std::ostream& output, const SymmetricPair<T>& pair)
72  {
73  output << pair.first << " : " << pair.second;
74  return output;
75  }
76 }
77 
78 #endif /* AGX_SYMMETRICPAIR_H */
agx::SymmetricPair
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Definition: SymmetricPair.h:31
agx::operator<<
std::ostream & operator<<(std::ostream &os, const agx::AddedMassInteraction::Matrix6x6 &m)
Definition: AddedMassInteraction.h:441
macros.h
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agx::SymmetricPair::hash
UInt32 hash() const
Definition: SymmetricPair.h:59
agx::SymmetricPair::SymmetricPair
SymmetricPair(const T &a, const T &b)
Definition: SymmetricPair.h:35
agx::operator!=
bool operator!=(T val, InvalidIndexStruct)
Definition: agx.h:207
agx::hash
AGXCORE_EXPORT UInt32 hash(const T &key)
Definition: HashFunction.h:65
agx::SymmetricPair::contains
bool contains(const T &a) const
Definition: SymmetricPair.h:37
agx::SymmetricPair::SymmetricPair
SymmetricPair()
Definition: SymmetricPair.h:34
agx::operator==
bool operator==(T val, InvalidIndexStruct)
Definition: agx.h:201
hash.h
agx::UInt32
uint32_t UInt32
Definition: Integer.h:32
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58