Alembic Version 1.1
ArraySampleKey.h
Go to the documentation of this file.
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
42
43namespace Alembic {
44namespace AbcCoreAbstract {
45namespace ALEMBIC_VERSION_NS {
46
47struct ArraySampleKey : public Alembic::Util::totally_ordered<ArraySampleKey>
48{
50 uint64_t numBytes;
51
54
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.
87{
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//-*****************************************************************************
112{
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>
125{
126 typedef Alembic::Util::unordered_map<ArraySampleKey,
127 MAPPED,
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
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105
size_t StdHash(ArraySampleKey const &a)
Alembic namespace ...
Definition: ArchiveInfo.h:46
bool operator()(ArraySampleKey const &a, ArraySampleKey const &b) const
uint64_t numBytes
total number of bytes of the sample as originally stored
PlainOldDataType origPOD
Original POD as stored.
bool operator==(const ArraySampleKey &iRhs) const
bool operator<(const ArraySampleKey &iRhs) const
Alembic::Util::unordered_map< ArraySampleKey, MAPPED, ArraySampleKeyStdHash, ArraySampleKeyEqualTo > umap_type