HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  : m_errorHandlerPolicy( iPolicy ),
58  m_metaData( iMetaData ),
59  m_timeSampling( iTimeSampling ),
60  m_timeSamplingIndex( iTimeIndex ),
61  m_matching( iMatch ){}
62 
63  void operator()( const uint32_t & iTimeSamplingIndex)
64  { m_timeSamplingIndex = iTimeSamplingIndex; }
65 
66  void operator()( const ErrorHandler::Policy &iPolicy )
67  { m_errorHandlerPolicy = iPolicy; }
68 
69  void operator()( const AbcA::MetaData &iMetaData )
70  { m_metaData = iMetaData; }
71 
72  void operator()( const AbcA::TimeSamplingPtr & iTimeSampling )
73  { m_timeSampling = iTimeSampling; }
74 
75  void operator()( const SchemaInterpMatching &iMatching )
76  { m_matching = iMatching; }
77 
79  { return m_errorHandlerPolicy; }
80 
81  const AbcA::MetaData &getMetaData() const
82  { return m_metaData; }
83 
85  { return m_timeSampling; }
86 
87  uint32_t getTimeSamplingIndex() const
88  { return m_timeSamplingIndex; }
89 
91  { return m_matching; }
92 
93 private:
94  ErrorHandler::Policy m_errorHandlerPolicy;
95  AbcA::MetaData m_metaData;
96  AbcA::TimeSamplingPtr m_timeSampling;
97  uint32_t m_timeSamplingIndex;
98  SchemaInterpMatching m_matching;
99 };
100 
101 //-*****************************************************************************
102 // Right now there are 4 types of arguments that you'd pass into
103 // our various classes for construction.
104 // ErrorHandlerPolicy - always defaults to QuietNoop
105 // MetaData - always defaults to ""
106 // matching - schema interpretation matching
107 // TimeSampling - always defaults to default uniform
108 // TimeSamplingIndex - always defaults to 0
109 class Argument
110 {
111 public:
113  m_whichVariant( kArgumentNone ) {}
114 
116  m_whichVariant( kArgumentErrorHandlerPolicy ),
117  m_variant( iPolicy ) {}
118 
119  Argument( Alembic::Util::uint32_t iTsIndex ) :
120  m_whichVariant( kArgumentTimeSamplingIndex ),
121  m_variant( iTsIndex ) {}
122 
123  Argument( const AbcA::MetaData &iMetaData ) :
124  m_whichVariant( kArgumentMetaData ),
125  m_variant( &iMetaData ) {}
126 
127  Argument( const AbcA::TimeSamplingPtr &iTsPtr ) :
128  m_whichVariant( kArgumentTimeSamplingPtr ),
129  m_variant( &iTsPtr ) {}
130 
132  m_whichVariant( kArgumentSchemaInterpMatching ),
133  m_variant( iMatch ) {}
134 
135  void setInto( Arguments &iArgs ) const
136  {
137  switch ( m_whichVariant )
138  {
139  case kArgumentErrorHandlerPolicy:
140  iArgs( m_variant.policy );
141  break;
142 
143  case kArgumentTimeSamplingIndex:
144  iArgs( m_variant.timeSamplingIndex );
145  break;
146 
147  case kArgumentMetaData:
148  iArgs( *m_variant.metaData );
149  break;
150 
151  case kArgumentTimeSamplingPtr:
152  iArgs( *m_variant.timeSamplingPtr );
153  break;
154 
155  case kArgumentSchemaInterpMatching:
156  iArgs( m_variant.schemaInterpMatching );
157  break;
158 
159  // no-op
160  case kArgumentNone:
161  break;
162 
163  default:
164  // we added something that we forgot to support in the switch
165  assert(false);
166  break;
167  }
168 
169 
170  }
171 
172 private:
173 
174  const Argument& operator= (const Argument&);
175 
176  enum ArgumentWhichFlag
177  {
178  kArgumentNone,
179  kArgumentErrorHandlerPolicy,
180  kArgumentTimeSamplingIndex,
181  kArgumentMetaData,
182  kArgumentTimeSamplingPtr,
183  kArgumentSchemaInterpMatching
184  } const m_whichVariant;
185 
186  union ArgumentVariant
187  {
188  ArgumentVariant() : timeSamplingIndex( 0 ) {}
189 
190  explicit ArgumentVariant( ErrorHandler::Policy iPolicy ) :
191  policy( iPolicy ) {}
192 
193  explicit ArgumentVariant( Alembic::Util::uint32_t iTsIndex ) :
194  timeSamplingIndex( iTsIndex ) {}
195 
196  explicit ArgumentVariant( const AbcA::MetaData * iMetaData ) :
197  metaData( iMetaData ) {}
198 
199  explicit ArgumentVariant( const AbcA::TimeSamplingPtr * iTsPtr ) :
200  timeSamplingPtr( iTsPtr ) {}
201 
202  explicit ArgumentVariant( SchemaInterpMatching iMatch ) :
203  schemaInterpMatching( iMatch ) {}
204 
206  Alembic::Util::uint32_t timeSamplingIndex;
207  const AbcA::MetaData * metaData;
208  const AbcA::TimeSamplingPtr * timeSamplingPtr;
209  SchemaInterpMatching schemaInterpMatching;
210  } const m_variant;
211 };
212 
213 
214 //-*****************************************************************************
215 //! This is for when you need to get the error handler policy out inside
216 //! a constructor header.
217 template <class SOMETHING>
219 ( SOMETHING iSomething,
220  const Argument &iArg0,
221  const Argument &iArg1 = Argument(),
222  const Argument &iArg2 = Argument() )
223 {
224  Arguments args( GetErrorHandlerPolicy( iSomething ) );
225  iArg0.setInto( args );
226  iArg1.setInto( args );
227  iArg2.setInto( args );
228  return args.getErrorHandlerPolicy();
229 }
230 
231 //-*****************************************************************************
233 ( const Argument &iArg0,
234  const Argument &iArg1 = Argument(),
235  const Argument &iArg2 = Argument() )
236 {
237  Arguments args;
238  iArg0.setInto( args );
239  iArg1.setInto( args );
240  iArg2.setInto( args );
241  return args.getErrorHandlerPolicy();
242 }
243 
244 //-*****************************************************************************
246 ( const Argument &iArg0,
247  const Argument &iArg1 = Argument(),
248  const Argument &iArg2 = Argument() )
249 {
250  Arguments args;
251  iArg0.setInto( args );
252  iArg1.setInto( args );
253  iArg2.setInto( args );
254  return args.getMetaData();
255 }
256 
257 //-*****************************************************************************
259 ( const Argument &iArg0,
260  const Argument &iArg1 = Argument(),
261  const Argument &iArg2 = Argument() )
262 {
263  Arguments args;
264  iArg0.setInto( args );
265  iArg1.setInto( args );
266  iArg2.setInto( args );
267  return args.getTimeSampling();
268 }
269 
270 //-*****************************************************************************
271 inline uint32_t GetTimeSamplingIndex
272 ( const Argument &iArg0,
273  const Argument &iArg1 = Argument(),
274  const Argument &iArg2 = Argument() )
275 {
276  Arguments args;
277  iArg0.setInto( args );
278  iArg1.setInto( args );
279  iArg2.setInto( args );
280  return args.getTimeSamplingIndex();
281 }
282 
283 //-*****************************************************************************
285 ( const Argument &iArg0,
286  const Argument &iArg1 = Argument(),
287  const Argument &iArg2 = Argument() )
288 {
289  Arguments args;
290  iArg0.setInto( args );
291  iArg1.setInto( args );
292  iArg2.setInto( args );
293  return args.getSchemaInterpMatching();
294 }
295 
296 } // End namespace ALEMBIC_VERSION_NS
297 
298 using namespace ALEMBIC_VERSION_NS;
299 
300 } // End namespace Abc
301 } // End namespace Alembic
302 
303 
304 #endif
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:219
void operator()(const uint32_t &iTimeSamplingIndex)
Definition: Argument.h:63
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
Arguments(ErrorHandler::Policy iPolicy=ErrorHandler::kThrowPolicy, const AbcA::MetaData &iMetaData=AbcA::MetaData(), AbcA::TimeSamplingPtr iTimeSampling=AbcA::TimeSamplingPtr(), uint32_t iTimeIndex=0, SchemaInterpMatching iMatch=kNoMatching)
Definition: Argument.h:51
void operator()(const SchemaInterpMatching &iMatching)
Definition: Argument.h:75
SchemaInterpMatching getSchemaInterpMatching() const
Definition: Argument.h:90
void setInto(Arguments &iArgs) const
Definition: Argument.h:135
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: Argument.h:84
void operator()(const ErrorHandler::Policy &iPolicy)
Definition: Argument.h:66
Argument(ErrorHandler::Policy iPolicy)
Definition: Argument.h:115
Argument(const AbcA::MetaData &iMetaData)
Definition: Argument.h:123
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:78
ErrorHandler::Policy GetErrorHandlerPolicyFromArgs(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:233
void operator()(const AbcA::TimeSamplingPtr &iTimeSampling)
Definition: Argument.h:72
Argument(SchemaInterpMatching iMatch)
Definition: Argument.h:131
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:285
AbcA::TimeSamplingPtr GetTimeSampling(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:259
AbcA::MetaData GetMetaData(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:246
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:81
Argument(Alembic::Util::uint32_t iTsIndex)
Definition: Argument.h:119
uint32_t GetTimeSamplingIndex(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:272
Argument(const AbcA::TimeSamplingPtr &iTsPtr)
Definition: Argument.h:127
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104
void operator()(const AbcA::MetaData &iMetaData)
Definition: Argument.h:69