HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Argument.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_Abc_Argument_h
38 #define Alembic_Abc_Argument_h
39 
40 #include <Alembic/Abc/Foundation.h>
42 
43 namespace Alembic {
44 namespace Abc {
45 namespace ALEMBIC_VERSION_NS {
46 
47 //-*****************************************************************************
48 class Arguments
49 {
50 public:
52  const AbcA::MetaData &iMetaData = AbcA::MetaData(),
53  AbcA::TimeSamplingPtr iTimeSampling =
55  uint32_t iTimeIndex = 0,
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 
84  { return m_errorHandlerPolicy; }
85 
86  const AbcA::MetaData &getMetaData() const
87  { return m_metaData; }
88 
90  { return m_timeSampling; }
91 
92  uint32_t getTimeSamplingIndex() const
93  { return m_timeSamplingIndex; }
94 
96  { return m_matching; }
97 
98  bool isSparse() const
99  { return m_sparse == kSparse; }
100 
101 private:
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 {
121 public:
123  m_whichVariant( kArgumentNone ) {}
124 
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 
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 
190 private:
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 
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 //-*****************************************************************************
238 //! This is for when you need to get the error handler policy out inside
239 //! a constructor header.
240 template <class SOMETHING>
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 //-*****************************************************************************
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 //-*****************************************************************************
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 //-*****************************************************************************
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 //-*****************************************************************************
302 inline 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 //-*****************************************************************************
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 //-*****************************************************************************
332 inline 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 
348 using namespace ALEMBIC_VERSION_NS;
349 
350 } // End namespace Abc
351 } // End namespace Alembic
352 
353 
354 #endif
Arguments(ErrorHandler::Policy iPolicy=ErrorHandler::kThrowPolicy, const AbcA::MetaData &iMetaData=AbcA::MetaData(), AbcA::TimeSamplingPtr iTimeSampling=AbcA::TimeSamplingPtr(), uint32_t iTimeIndex=0, SchemaInterpMatching iMatch=kNoMatching, SparseFlag iSparse=kFull)
Definition: Argument.h:51
void operator()(const uint32_t &iTimeSamplingIndex)
Definition: Argument.h:65
hboost::math::policies::policy< hboost::math::policies::domain_error< hboost::math::policies::ignore_error >, hboost::math::policies::pole_error< hboost::math::policies::ignore_error >, hboost::math::policies::overflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::underflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::denorm_error< hboost::math::policies::ignore_error >, hboost::math::policies::rounding_error< hboost::math::policies::ignore_error >, hboost::math::policies::evaluation_error< hboost::math::policies::ignore_error >, hboost::math::policies::indeterminate_result_error< hboost::math::policies::ignore_error > > policy
Definition: SYS_MathCbrt.h:35
void operator()(const SchemaInterpMatching &iMatching)
Definition: Argument.h:77
SchemaInterpMatching getSchemaInterpMatching() const
Definition: Argument.h:95
void setInto(Arguments &iArgs) const
Definition: Argument.h:149
AbcA::MetaData GetMetaData(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:273
ErrorHandler::Policy GetErrorHandlerPolicyFromArgs(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:258
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: Argument.h:89
void operator()(const ErrorHandler::Policy &iPolicy)
Definition: Argument.h:68
Argument(ErrorHandler::Policy iPolicy)
Definition: Argument.h:125
Argument(const AbcA::MetaData &iMetaData)
Definition: Argument.h:133
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:83
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:242
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:318
bool IsSparse(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:333
void operator()(const SparseFlag &iSparse)
Definition: Argument.h:80
AbcA::TimeSamplingPtr GetTimeSampling(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:288
void operator()(const AbcA::TimeSamplingPtr &iTimeSampling)
Definition: Argument.h:74
Argument(SchemaInterpMatching iMatch)
Definition: Argument.h:141
**If you just want to fire and args
Definition: thread.h:609
uint32_t GetTimeSamplingIndex(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:303
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:86
Argument(Alembic::Util::uint32_t iTsIndex)
Definition: Argument.h:129
Argument(const AbcA::TimeSamplingPtr &iTsPtr)
Definition: Argument.h:137
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88
void operator()(const AbcA::MetaData &iMetaData)
Definition: Argument.h:71