Alembic: AbcCoreAbstract/ArraySampleKey.h Source File

Alembic 1.8.11

Loading...
Searching...
No Matches
ArraySampleKey.h
1//-*****************************************************************************
2//
3// Copyright (c) 2009-2012,
4// Sony Pictures Imageworks Inc. and
5// Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6//
7// All rights reserved.
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12// * Redistributions of source code must retain the above copyright
13// notice, this list of conditions and the following disclaimer.
14// * Redistributions in binary form must reproduce the above
15// copyright notice, this list of conditions and the following disclaimer
16// in the documentation and/or other materials provided with the
17// distribution.
18// * Neither the name of Sony Pictures Imageworks, nor
19// Industrial Light & Magic, nor the names of their contributors may be used
20// to endorse or promote products derived from this software without specific
21// prior written permission.
22//
23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34//
35//-*****************************************************************************
36
37#ifndef Alembic_AbcCoreAbstract_ArraySampleKey_h
38#define Alembic_AbcCoreAbstract_ArraySampleKey_h
39
40#include <Alembic/AbcCoreAbstract/Foundation.h>
41#include <Alembic/AbcCoreAbstract/DataType.h>
42
43namespace Alembic {
44namespace AbcCoreAbstract {
45namespace ALEMBIC_VERSION_NS {
46
47 struct ArraySampleKey : public Alembic::Util::totally_ordered<ArraySampleKey>
48{
50 uint64_t numBytes;
51
53 PlainOldDataType origPOD;
54
56 PlainOldDataType readPOD;
57
58 Digest digest;
59
60 bool operator==( const ArraySampleKey &iRhs ) const
61 {
62 return ( ( numBytes == iRhs.numBytes ) &&
63 ( origPOD == iRhs.origPOD ) &&
64 ( readPOD == iRhs.readPOD ) &&
65 ( digest == iRhs.digest ) );
66 };
67
68 bool operator<( const ArraySampleKey &iRhs ) const
69 {
70 return ( numBytes < iRhs.numBytes ? true :
71 ( numBytes > iRhs.numBytes ? false :
72
73 ( origPOD < iRhs.origPOD ? true :
74 ( origPOD > iRhs.origPOD ? false :
75
76 ( readPOD < iRhs.readPOD ? true :
77 ( readPOD > iRhs.readPOD ? false :
78
79 ( digest < iRhs.digest ) ) ) ) ) ) );
80 };
81
82};
83
84//-*****************************************************************************
85// Equality operator.
86 struct ArraySampleKeyEqualTo
87{
88 typedef ArraySampleKey first_argument_type;
89 typedef ArraySampleKey second_argument_type;
90 typedef bool result_type;
91
92 bool operator()( ArraySampleKey const &a,
93 ArraySampleKey const &b ) const
94 {
95 return a == b;
96 }
97};
98
99//-*****************************************************************************
100// Hash function
101inline size_t StdHash( ArraySampleKey const &a )
102{
103 // Theoretically, the bits of our hash are uniformly
104 // randomly distributed, so it doesn't matter which of the 128
105 // bits we use to generate the 64 bits that we return as the hash
106 // key. So, I'll just do the simple thing.
107 return *(( const size_t * )&a.digest);
108}
109
110//-*****************************************************************************
111 struct ArraySampleKeyStdHash
112{
113 typedef ArraySampleKey argument_type;
114 typedef size_t result_type;
115
116 size_t operator()( ArraySampleKey const &a ) const
117 {
118 return StdHash( a );
119 }
120};
121
122//-*****************************************************************************
123template <class MAPPED>
124 struct UnorderedMapUtil
125{
126 typedef Alembic::Util::unordered_map<ArraySampleKey,
127 MAPPED,
128 ArraySampleKeyStdHash,
129 ArraySampleKeyEqualTo> umap_type;
130};
131
132} // End namespace ALEMBIC_VERSION_NS
133
134using namespace ALEMBIC_VERSION_NS;
135
136} // End namespace AbcCoreAbstract
137} // End namespace Alembic
138
139#endif
Alembic::Util::ALEMBIC_VERSION_NS::totally_ordered
Definition Foundation.h:120
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySampleKeyEqualTo
Definition ArraySampleKey.h:87
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySampleKey
Definition ArraySampleKey.h:48
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySampleKey::numBytes
uint64_t numBytes
total number of bytes of the sample as originally stored
Definition ArraySampleKey.h:50
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySampleKey::origPOD
PlainOldDataType origPOD
Original POD as stored.
Definition ArraySampleKey.h:53
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySampleKey::readPOD
PlainOldDataType readPOD
POD used at read time.
Definition ArraySampleKey.h:56
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySampleKeyStdHash
Definition ArraySampleKey.h:112
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::UnorderedMapUtil
Definition ArraySampleKey.h:125