Alembic: AbcCoreAbstract/ScalarSample.h Source File

Alembic 1.8.11

Loading...
Searching...
No Matches
ScalarSample.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_ScalarSample_h
38#define Alembic_AbcCoreAbstract_ScalarSample_h
39
40#include <Alembic/Util/Export.h>
41#include <Alembic/AbcCoreAbstract/Foundation.h>
42#include <Alembic/AbcCoreAbstract/DataType.h>
43
44namespace Alembic {
45namespace AbcCoreAbstract {
46namespace ALEMBIC_VERSION_NS {
47
48//-*****************************************************************************
62 class ALEMBIC_EXPORT ScalarSample
63 : public Alembic::Util::totally_ordered<ScalarSample>
64{
65public:
66 //-*************************************************************************
67 // Data
68 //-*************************************************************************
69 class Data
70 {
71 public:
72 virtual ~Data() {}
73
74 virtual void setToDefault() = 0;
75 virtual void copyFrom( const void *iData ) = 0;
76 virtual bool equalTo( const void *iData ) const = 0;
77 virtual bool equalEpsilon( const void *iData,
78 double iEpsilon ) const = 0;
79 virtual bool lessThan( const void *iData ) const = 0;
80 virtual const void *getData() const = 0;
81 };
82
86 explicit ScalarSample( const DataType &iDataType );
87
92 void copyFrom( const void *iData )
93 {
94 m_data->copyFrom( iData );
95 }
96
97 //-*************************************************************************
98 // Data Access
99 //-*************************************************************************
100
103 const DataType &getDataType() const { return m_dataType; }
104
107 const void *getData() const { return m_data->getData(); }
108
109 //-*************************************************************************
110 // Comparison and Equality
111 //-*************************************************************************
112
116 bool operator==( const void *iRhs ) const
117 {
118 return m_data->equalTo( iRhs );
119 }
120
123 bool operator==( const ScalarSample &iRhs ) const
124 {
125 return ( iRhs.getDataType() == m_dataType ) &&
126 m_data->equalTo( iRhs.getData() );
127 }
128
132 bool equalWithRelAbsError( const void *iRhs,
133 double iRelAbsError ) const
134 {
135 return m_data->equalEpsilon( iRhs, iRelAbsError );
136 }
137
140 bool equalWithRelAbsError( const ScalarSample &iRhs,
141 double iRelAbsError ) const
142 {
143 return ( iRhs.getDataType() == m_dataType ) &&
144 m_data->equalEpsilon( iRhs.getData(), iRelAbsError );
145 }
146
149 bool operator<( const void *iRhs ) const
150 {
151 return m_data->lessThan( iRhs );
152 }
153
156 bool operator<( const ScalarSample &iRhs ) const
157 {
158 if ( m_dataType < iRhs.getDataType() )
159 {
160 return true;
161 }
162 else if ( m_dataType > iRhs.getDataType() )
163 {
164 return false;
165 }
166 else
167 {
168 return m_data->lessThan( iRhs.getData() );
169 }
170 }
171
172 //-*************************************************************************
173 // Useful functions
174 //-*************************************************************************
175
178 void setToDefault()
179 {
180 m_data->setToDefault();
181 }
182
183private:
184 DataType m_dataType;
185 Alembic::Util::unique_ptr<Data> m_data;
186};
187
188} // End namespace ALEMBIC_VERSION_NS
189
190using namespace ALEMBIC_VERSION_NS;
191
192} // End namespace AbcCoreAbstract
193} // End namespace Alembic
194
195#endif
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::DataType
Definition DataType.h:52
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::Data
Definition ScalarSample.h:70
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::operator==
bool operator==(const ScalarSample &iRhs) const
Definition ScalarSample.h:123
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::copyFrom
void copyFrom(const void *iData)
Definition ScalarSample.h:92
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::equalWithRelAbsError
bool equalWithRelAbsError(const void *iRhs, double iRelAbsError) const
Definition ScalarSample.h:132
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::getData
const void * getData() const
Definition ScalarSample.h:107
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::operator==
bool operator==(const void *iRhs) const
Definition ScalarSample.h:116
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::equalWithRelAbsError
bool equalWithRelAbsError(const ScalarSample &iRhs, double iRelAbsError) const
Definition ScalarSample.h:140
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::operator<
bool operator<(const void *iRhs) const
Definition ScalarSample.h:149
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::ScalarSample
ScalarSample(const DataType &iDataType)
Definition ScalarSample.cpp:159
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::setToDefault
void setToDefault()
Definition ScalarSample.h:178
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::operator<
bool operator<(const ScalarSample &iRhs) const
Definition ScalarSample.h:156
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ScalarSample::getDataType
const DataType & getDataType() const
Definition ScalarSample.h:103
Alembic::Util::ALEMBIC_VERSION_NS::totally_ordered
Definition Foundation.h:120
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39