Skip to content

Commit 0746e8c

Browse files
ImathHash.h : Added file to allow using Imath types with unordered_map
1 parent 7712732 commit 0746e8c

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

include/IECore/ImathHash.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2023, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IE_CORE_IMATHHASH_H
36+
#define IE_CORE_IMATHHASH_H
37+
38+
IECORE_PUSH_DEFAULT_VISIBILITY
39+
#include "OpenEXR/half.h"
40+
#include "OpenEXR/ImathBox.h"
41+
#include "OpenEXR/ImathColor.h"
42+
#include "OpenEXR/ImathMatrix.h"
43+
#include "OpenEXR/ImathQuat.h"
44+
#include "OpenEXR/ImathVec.h"
45+
IECORE_POP_DEFAULT_VISIBILITY
46+
47+
namespace IECore
48+
{
49+
50+
namespace Detail
51+
{
52+
53+
template <typename T>
54+
struct PodHash
55+
{
56+
size_t operator()( const T &x ) const
57+
{
58+
return std::hash<std::string_view>()( std::string_view( (char*)&x, sizeof( T ) ) );
59+
}
60+
};
61+
62+
} // namespace Detail
63+
64+
} // namespace IECore
65+
66+
namespace std
67+
{
68+
69+
template <> struct hash<half> : public IECore::Detail::PodHash<half> { };
70+
template <> struct hash<Imath::V2f> : public IECore::Detail::PodHash<Imath::V2f> { };
71+
template <> struct hash<Imath::V2i> : public IECore::Detail::PodHash<Imath::V2i> { };
72+
template <> struct hash<Imath::V2d> : public IECore::Detail::PodHash<Imath::V2d> { };
73+
template <> struct hash<Imath::V3f> : public IECore::Detail::PodHash<Imath::V3f> { };
74+
template <> struct hash<Imath::V3i> : public IECore::Detail::PodHash<Imath::V3i> { };
75+
template <> struct hash<Imath::V3d> : public IECore::Detail::PodHash<Imath::V3d> { };
76+
template <> struct hash<Imath::Color3f> : public IECore::Detail::PodHash<Imath::Color3f> { };
77+
template <> struct hash<Imath::Color4f> : public IECore::Detail::PodHash<Imath::Color4f> { };
78+
template <> struct hash<Imath::Quatf> : public IECore::Detail::PodHash<Imath::Quatf> { };
79+
template <> struct hash<Imath::Quatd> : public IECore::Detail::PodHash<Imath::Quatd> { };
80+
template <> struct hash<Imath::M33f> : public IECore::Detail::PodHash<Imath::M33f> { };
81+
template <> struct hash<Imath::M33d> : public IECore::Detail::PodHash<Imath::M33d> { };
82+
template <> struct hash<Imath::M44f> : public IECore::Detail::PodHash<Imath::M44f> { };
83+
template <> struct hash<Imath::M44d> : public IECore::Detail::PodHash<Imath::M44d> { };
84+
template <> struct hash<Imath::Box2i> : public IECore::Detail::PodHash<Imath::Box2i> { };
85+
template <> struct hash<Imath::Box3i> : public IECore::Detail::PodHash<Imath::Box3i> { };
86+
template <> struct hash<Imath::Box2f> : public IECore::Detail::PodHash<Imath::Box2f> { };
87+
template <> struct hash<Imath::Box3f> : public IECore::Detail::PodHash<Imath::Box3f> { };
88+
template <> struct hash<Imath::Box2d> : public IECore::Detail::PodHash<Imath::Box2d> { };
89+
template <> struct hash<Imath::Box3d> : public IECore::Detail::PodHash<Imath::Box3d> { };
90+
91+
} // namespace std
92+
93+
#endif // IE_CORE_IMATHHASH_H

0 commit comments

Comments
 (0)