Alembic: Abc/Argument.h Source File

Alembic 1.8.11

Loading...
Searching...
No Matches
Argument.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_Abc_Argument_h
38#define Alembic_Abc_Argument_h
39
40#include <Alembic/Abc/Foundation.h>
41#include <Alembic/Abc/ErrorHandler.h>
42
43namespace Alembic {
44namespace Abc {
45namespace ALEMBIC_VERSION_NS {
46
47//-*****************************************************************************
48 class Arguments
49{
50public:
51 Arguments( ErrorHandler::Policy iPolicy = ErrorHandler::kThrowPolicy,
52 const AbcA::MetaData &iMetaData = AbcA::MetaData(),
53 AbcA::TimeSamplingPtr iTimeSampling =
54 AbcA::TimeSamplingPtr(),
55 uint32_t iTimeIndex = 0,
56 SchemaInterpMatching iMatch = kNoMatching,
57 SparseFlag iSparse = kFull )
58 : m_errorHandlerPolicy( iPolicy ),
59 m_metaData( iMetaData ),
60 m_timeSampling( iTimeSampling ),
61 m_timeSamplingIndex( iTimeIndex ),
62 m_matching( iMatch ),
63 m_sparse( iSparse ) {}
64
65 void operator()( const uint32_t & iTimeSamplingIndex)
66 { m_timeSamplingIndex = iTimeSamplingIndex; }
67
68 void operator()( const ErrorHandler::Policy &iPolicy )
69 { m_errorHandlerPolicy = iPolicy; }
70
71 void operator()( const AbcA::MetaData &iMetaData )
72 { m_metaData = iMetaData; }
73
74 void operator()( const AbcA::TimeSamplingPtr & iTimeSampling )
75 { m_timeSampling = iTimeSampling; }
76
77 void operator()( const SchemaInterpMatching &iMatching )
78 { m_matching = iMatching; }
79
80 void operator()( const SparseFlag &iSparse )
81 { m_sparse = iSparse; }
82
83 ErrorHandler::Policy getErrorHandlerPolicy() const
84 { return m_errorHandlerPolicy; }
85
86 const AbcA::MetaData &getMetaData() const
87 { return m_metaData; }
88
89 AbcA::TimeSamplingPtr getTimeSampling() const
90 { return m_timeSampling; }
91
92 uint32_t getTimeSamplingIndex() const
93 { return m_timeSamplingIndex; }
94
95 SchemaInterpMatching getSchemaInterpMatching() const
96 { return m_matching; }
97
98 bool isSparse() const
99 { return m_sparse == kSparse; }
100
101private:
102 ErrorHandler::Policy m_errorHandlerPolicy;
103 AbcA::MetaData m_metaData;
104 AbcA::TimeSamplingPtr m_timeSampling;
105 uint32_t m_timeSamplingIndex;
106 SchemaInterpMatching m_matching;
107 SparseFlag m_sparse;
108};
109
110//-*****************************************************************************
111// Right now there are 6 types of arguments that you'd pass into
112// our various classes for construction.
113// ErrorHandlerPolicy - always defaults to QuietNoop
114// MetaData - always defaults to ""
115// matching - schema interpretation matching
116// TimeSampling - always defaults to default uniform
117// TimeSamplingIndex - always defaults to 0
118// Sparse - always defaults to kFull
119 class Argument
120{
121public:
122 Argument() :
123 m_whichVariant( kArgumentNone ) {}
124
125 Argument( ErrorHandler::Policy iPolicy ) :
126 m_whichVariant( kArgumentErrorHandlerPolicy ),
127 m_variant( iPolicy ) {}
128
129 Argument( Alembic::Util::uint32_t iTsIndex ) :
130 m_whichVariant( kArgumentTimeSamplingIndex ),
131 m_variant( iTsIndex ) {}
132
133 Argument( const AbcA::MetaData &iMetaData ) :
134 m_whichVariant( kArgumentMetaData ),
135 m_variant( &iMetaData ) {}
136
137 Argument( const AbcA::TimeSamplingPtr &iTsPtr ) :
138 m_whichVariant( kArgumentTimeSamplingPtr ),
139 m_variant( &iTsPtr ) {}
140
141 Argument( SchemaInterpMatching iMatch ) :
142 m_whichVariant( kArgumentSchemaInterpMatching ),
143 m_variant( iMatch ) {}
144
145 Argument( SparseFlag iSparse ) :
146 m_whichVariant( kArgumentSparse ),
147 m_variant( iSparse ) {}
148
149 void setInto( Arguments &iArgs ) const
150 {
151 switch ( m_whichVariant )
152 {
153 case kArgumentErrorHandlerPolicy:
154 iArgs( m_variant.policy );
155 break;
156
157 case kArgumentTimeSamplingIndex:
158 iArgs( m_variant.timeSamplingIndex );
159 break;
160
161 case kArgumentMetaData:
162 iArgs( *m_variant.metaData );
163 break;
164
165 case kArgumentTimeSamplingPtr:
166 iArgs( *m_variant.timeSamplingPtr );
167 break;
168
169 case kArgumentSchemaInterpMatching:
170 iArgs( m_variant.schemaInterpMatching );
171 break;
172
173 case kArgumentSparse:
174 iArgs( m_variant.sparseFlag );
175 break;
176
177 // no-op
178 case kArgumentNone:
179 break;
180
181 default:
182 // we added something that we forgot to support in the switch
183 assert(false);
184 break;
185 }
186
187
188 }
189
190private:
191
192 const Argument& operator= (const Argument&);
193
194 enum ArgumentWhichFlag
195 {
196 kArgumentNone,
197 kArgumentErrorHandlerPolicy,
198 kArgumentTimeSamplingIndex,
199 kArgumentMetaData,
200 kArgumentTimeSamplingPtr,
201 kArgumentSchemaInterpMatching,
202 kArgumentSparse
203 } const m_whichVariant;
204
205 union ArgumentVariant
206 {
207 ArgumentVariant() : timeSamplingIndex( 0 ) {}
208
209 explicit ArgumentVariant( ErrorHandler::Policy iPolicy ) :
210 policy( iPolicy ) {}
211
212 explicit ArgumentVariant( Alembic::Util::uint32_t iTsIndex ) :
213 timeSamplingIndex( iTsIndex ) {}
214
215 explicit ArgumentVariant( const AbcA::MetaData * iMetaData ) :
216 metaData( iMetaData ) {}
217
218 explicit ArgumentVariant( const AbcA::TimeSamplingPtr * iTsPtr ) :
219 timeSamplingPtr( iTsPtr ) {}
220
221 explicit ArgumentVariant( SchemaInterpMatching iMatch ) :
222 schemaInterpMatching( iMatch ) {}
223
224 explicit ArgumentVariant( SparseFlag iSparse ) :
225 sparseFlag( iSparse ) {}
226
227 ErrorHandler::Policy policy;
228 Alembic::Util::uint32_t timeSamplingIndex;
229 const AbcA::MetaData * metaData;
230 const AbcA::TimeSamplingPtr * timeSamplingPtr;
231 SchemaInterpMatching schemaInterpMatching;
232 SparseFlag sparseFlag;
233 } const m_variant;
234};
235
236
237//-*****************************************************************************
240template <class SOMETHING>
241inline ErrorHandler::Policy GetErrorHandlerPolicy
242( SOMETHING iSomething,
243 const Argument &iArg0,
244 const Argument &iArg1 = Argument(),
245 const Argument &iArg2 = Argument(),
246 const Argument &iArg3 = Argument() )
247{
248 Arguments args( GetErrorHandlerPolicy( iSomething ) );
249 iArg0.setInto( args );
250 iArg1.setInto( args );
251 iArg2.setInto( args );
252 iArg3.setInto( args );
253 return args.getErrorHandlerPolicy();
254}
255
256//-*****************************************************************************
257inline ErrorHandler::Policy GetErrorHandlerPolicyFromArgs
258( const Argument &iArg0,
259 const Argument &iArg1 = Argument(),
260 const Argument &iArg2 = Argument(),
261 const Argument &iArg3 = Argument() )
262{
263 Arguments args;
264 iArg0.setInto( args );
265 iArg1.setInto( args );
266 iArg2.setInto( args );
267 iArg3.setInto( args );
268 return args.getErrorHandlerPolicy();
269}
270
271//-*****************************************************************************
272inline AbcA::MetaData GetMetaData
273( const Argument &iArg0,
274 const Argument &iArg1 = Argument(),
275 const Argument &iArg2 = Argument(),
276 const Argument &iArg3 = Argument() )
277{
278 Arguments args;
279 iArg0.setInto( args );
280 iArg1.setInto( args );
281 iArg2.setInto( args );
282 iArg3.setInto( args );
283 return args.getMetaData();
284}
285
286//-*****************************************************************************
287inline AbcA::TimeSamplingPtr GetTimeSampling
288( const Argument &iArg0,
289 const Argument &iArg1 = Argument(),
290 const Argument &iArg2 = Argument(),
291 const Argument &iArg3 = Argument() )
292{
293 Arguments args;
294 iArg0.setInto( args );
295 iArg1.setInto( args );
296 iArg2.setInto( args );
297 iArg3.setInto( args );
298 return args.getTimeSampling();
299}
300
301//-*****************************************************************************
302inline uint32_t GetTimeSamplingIndex
303( const Argument &iArg0,
304 const Argument &iArg1 = Argument(),
305 const Argument &iArg2 = Argument(),
306 const Argument &iArg3 = Argument() )
307{
308 Arguments args;
309 iArg0.setInto( args );
310 iArg1.setInto( args );
311 iArg2.setInto( args );
312 iArg3.setInto( args );
313 return args.getTimeSamplingIndex();
314}
315
316//-*****************************************************************************
317inline SchemaInterpMatching GetSchemaInterpMatching
318( const Argument &iArg0,
319 const Argument &iArg1 = Argument(),
320 const Argument &iArg2 = Argument(),
321 const Argument &iArg3 = Argument() )
322{
323 Arguments args;
324 iArg0.setInto( args );
325 iArg1.setInto( args );
326 iArg2.setInto( args );
327 iArg3.setInto( args );
328 return args.getSchemaInterpMatching();
329}
330
331//-*****************************************************************************
332inline bool IsSparse
333( const Argument &iArg0,
334 const Argument &iArg1 = Argument(),
335 const Argument &iArg2 = Argument(),
336 const Argument &iArg3 = Argument() )
337{
338 Arguments args;
339 iArg0.setInto( args );
340 iArg1.setInto( args );
341 iArg2.setInto( args );
342 iArg3.setInto( args );
343 return args.isSparse();
344}
345
346} // End namespace ALEMBIC_VERSION_NS
347
348using namespace ALEMBIC_VERSION_NS;
349
350} // End namespace Abc
351} // End namespace Alembic
352
353
354#endif
Alembic::Abc::ALEMBIC_VERSION_NS::Argument
Definition Argument.h:120
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments
Definition Argument.h:49
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39