AGX Dynamics 2.41.3.0
Loading...
Searching...
No Matches
SymmetricPair.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
24namespace 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 */
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Definition: SymmetricPair.h:32
bool contains(const T &a) const
Definition: SymmetricPair.h:37
SymmetricPair(const T &a, const T &b)
Definition: SymmetricPair.h:35
UInt32 hash() const
Definition: SymmetricPair.h:59
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
UInt32 hash(const T &key)
Definition: HashFunction.h:65
uint32_t UInt32
Definition: Integer.h:32
bool operator!=(T val, InvalidIndexStruct)
Definition: agx.h:222
std::ostream & operator<<(std::ostream &os, const agx::AddedMassInteraction::Matrix6x6 &m)
bool operator==(T val, InvalidIndexStruct)
Definition: agx.h:213
STL namespace.
void swap(agx::Name &lhs, agx::Name &rhs)
Definition: Name.h:323