HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTypedScalarProperty.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 #ifndef _Alembic_Abc_OTypedScalarProperty_h_
37 #define _Alembic_Abc_OTypedScalarProperty_h_
38 
39 #include <Alembic/Abc/Foundation.h>
42 
43 namespace Alembic {
44 namespace Abc {
45 namespace ALEMBIC_VERSION_NS {
46 
47 //-*****************************************************************************
48 template <class TRAITS>
50 {
51 public:
52  //-*************************************************************************
53  // TYPE IDENTIFICATION
54  //-*************************************************************************
55  typedef TRAITS traits_type;
57  typedef typename TRAITS::value_type value_type;
58 
59  //! Return the interpretation expected of this
60  //! property. An empty interpretation matches everything
61  static const char * getInterpretation()
62  {
63  return TRAITS::interpretation();
64  }
65 
66  //! This will check whether or not a given entity (as represented by
67  //! a metadata) strictly matches the interpretation of this
68  //! schema object
69  static bool matches( const AbcA::MetaData &iMetaData,
71  {
72  return ( iMetaData.get( "interpretation" ) ==
74  }
75 
76  //! This will check whether or not a given object (as represented by
77  //! an object header) strictly matches the interpretation of this
78  //! schema object, as well as the data type.
79  static bool matches( const AbcA::PropertyHeader &iHeader,
81  {
82  return ( iHeader.getDataType().getPod() ==
83  TRAITS::dataType().getPod() &&
84  ( iHeader.getDataType().getExtent() ==
85  TRAITS::dataType().getExtent() ||
86  std::string() == getInterpretation() ) ) &&
87  iHeader.isScalar() &&
88  matches( iHeader.getMetaData(), iMatching );
89  }
90 
91  //-*************************************************************************
92  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
93  //-*************************************************************************
94 
95  //! Create a default (empty) TypedScalarProperty
96  //! ...
98 
99  //! Create a new TypedScalarProperty
100  //! as a child of the passed COMPOUND_PTR
101  //! Arguments can specify metadata, timesampling, and error handling.
102  template <class COMPOUND_PTR>
104  COMPOUND_PTR iParent,
105  const std::string &iName,
106 
107  const Argument &iArg0 = Argument(),
108  const Argument &iArg1 = Argument(),
109  const Argument &iArg2 = Argument() );
110 
111  //! Wrap an existing scalar property,
112  //! checking to make sure it matches data type and also
113  //! (if requested) interpretation.
116  WrapExistingFlag iWrapFlag,
117  const Argument &iArg0 = Argument(),
118  const Argument &iArg1 = Argument() );
119 
120  //-*************************************************************************
121  // SCALAR PROPERTY FEATURES
122  //-*************************************************************************
123 
124  //! Set a sample using a reference to a value-type,
125  //! instead of a void*
126  void set( const value_type &iVal )
127  {
128  OScalarProperty::set( reinterpret_cast<const void *>( &iVal ) );
129  }
130 };
131 
132 //-*****************************************************************************
133 // TEMPLATE AND INLINE FUNCTIONS
134 //-*****************************************************************************
135 
136 //-*****************************************************************************
137 template <class TRAITS>
138 template <class COMPOUND_PTR>
140  COMPOUND_PTR iParent,
141  const std::string &iName,
142 
143  const Argument &iArg0,
144  const Argument &iArg1,
145  const Argument &iArg2 )
146 {
147  Arguments args( GetErrorHandlerPolicy( iParent ) );
148  iArg0.setInto( args );
149  iArg1.setInto( args );
150  iArg2.setInto( args );
151 
152  getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
153 
154  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedScalarProperty::init()" );
155 
157  GetCompoundPropertyWriterPtr( iParent );
158 
159  ABCA_ASSERT( parent, "NULL CompoundPropertyWriterPtr" );
160 
161  AbcA::MetaData mdata = args.getMetaData();
162  if ( std::string() != getInterpretation() )
163  {
164  mdata.set( "interpretation", getInterpretation() );
165  }
166 
167  AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
168 
169  uint32_t tsIndex = args.getTimeSamplingIndex();
170 
171  // if we specified a valid TimeSamplingPtr, use it to determine the index
172  // otherwise we'll use the index, which defaults to the intrinsic 0 index
173  if (tsPtr)
174  {
175  tsIndex = parent->getObject()->getArchive()->addTimeSampling(*tsPtr);
176  }
177 
178  m_property = parent->createScalarProperty( iName, mdata,
179  TRAITS::dataType(), tsIndex );
180 
182 }
183 
184 //-*****************************************************************************
185 template<class TRAITS>
188  WrapExistingFlag iFlag,
189  const Argument &iArg0,
190  const Argument &iArg1 )
191  : OScalarProperty( iProperty,
192  iFlag,
193  GetErrorHandlerPolicy( iProperty, iArg0, iArg1 ) )
194 {
196  "ITypedScalarProperty::ITypedScalarProperty()" );
197 
198  const AbcA::PropertyHeader &pheader = iProperty->getHeader();
199 
200  ABCA_ASSERT( matches( pheader, GetSchemaInterpMatching( iArg0, iArg1 ) ),
201 
202  "Incorrect match of header datatype: "
203  << pheader.getDataType()
204  << " to expected: "
205  << TRAITS::dataType()
206  << ",\n...or incorrect match of interpretation: "
207  << pheader.getMetaData().get( "interpretation" )
208  << " to expected: "
209  << TRAITS::interpretation() );
210 
212 }
213 
214 //-*****************************************************************************
215 //-*****************************************************************************
216 //-*****************************************************************************
217 
232 
237 
242 
247 
252 
257 
262 
267 
270 
274 
278 
281 
284 
285 } // End namespace ALEMBIC_VERSION_NS
286 
287 using namespace ALEMBIC_VERSION_NS;
288 
289 } // End namespace Abc
290 } // End namespace Alembic
291 
292 #endif
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:219
OTypedScalarProperty< Uint16TPTraits > OUInt16Property
OTypedScalarProperty< V2dTPTraits > OV2dProperty
OTypedScalarProperty< M33dTPTraits > OM33dProperty
OTypedScalarProperty< Box2sTPTraits > OBox2sProperty
OTypedScalarProperty< Uint8TPTraits > OUcharProperty
OTypedScalarProperty< N3fTPTraits > ON3fProperty
OTypedScalarProperty< P2sTPTraits > OP2sProperty
OTypedScalarProperty< P3sTPTraits > OP3sProperty
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
OTypedScalarProperty< QuatdTPTraits > OQuatdProperty
OTypedScalarProperty< V3dTPTraits > OV3dProperty
OTypedScalarProperty< Float32TPTraits > OFloatProperty
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
OTypedScalarProperty< Int32TPTraits > OInt32Property
void setInto(Arguments &iArgs) const
Definition: Argument.h:135
OTypedScalarProperty< Box3dTPTraits > OBox3dProperty
OTypedScalarProperty< P3iTPTraits > OP3iProperty
OTypedScalarProperty< QuatfTPTraits > OQuatfProperty
OTypedScalarProperty< P2fTPTraits > OP2fProperty
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: Argument.h:84
uint64 value_type
Definition: GA_PrimCompat.h:29
OTypedScalarProperty< N2dTPTraits > ON2dProperty
OTypedScalarProperty< Int8TPTraits > OCharProperty
OTypedScalarProperty< WstringTPTraits > OWstringProperty
OTypedScalarProperty< C4hTPTraits > OC4hProperty
OTypedScalarProperty< BooleanTPTraits > OBoolProperty
OTypedScalarProperty< N2fTPTraits > ON2fProperty
OTypedScalarProperty< M33fTPTraits > OM33fProperty
OTypedScalarProperty< Box2dTPTraits > OBox2dProperty
OTypedScalarProperty< C3hTPTraits > OC3hProperty
OTypedScalarProperty< V3sTPTraits > OV3sProperty
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
OTypedScalarProperty< P3fTPTraits > OP3fProperty
OTypedScalarProperty< StringTPTraits > OStringProperty
OTypedScalarProperty< P2iTPTraits > OP2iProperty
OTypedScalarProperty< Box2fTPTraits > OBox2fProperty
OTypedScalarProperty< Float16TPTraits > OHalfProperty
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:78
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
OTypedScalarProperty< P3dTPTraits > OP3dProperty
OTypedScalarProperty< C4cTPTraits > OC4cProperty
OTypedScalarProperty< V3iTPTraits > OV3iProperty
OTypedScalarProperty< Box3fTPTraits > OBox3fProperty
Alembic::Util::shared_ptr< ScalarPropertyWriter > ScalarPropertyWriterPtr
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
OTypedScalarProperty< C3fTPTraits > OC3fProperty
OTypedScalarProperty< V2sTPTraits > OV2sProperty
OTypedScalarProperty< N3dTPTraits > ON3dProperty
OTypedScalarProperty< Int64TPTraits > OInt64Property
OTypedScalarProperty< Float64TPTraits > ODoubleProperty
OTypedScalarProperty< M44dTPTraits > OM44dProperty
OTypedScalarProperty< Box3sTPTraits > OBox3sProperty
OTypedScalarProperty< V3fTPTraits > OV3fProperty
void set(const std::string &iKey, const std::string &iData)
Definition: MetaData.h:168
OTypedScalarProperty< M44fTPTraits > OM44fProperty
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:285
OTypedScalarProperty< C4fTPTraits > OC4fProperty
OTypedScalarProperty< Int16TPTraits > OInt16Property
OTypedScalarProperty< Uint64TPTraits > OUInt64Property
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
OTypedScalarProperty< V2fTPTraits > OV2fProperty
OTypedScalarProperty< Box2iTPTraits > OBox2iProperty
AbcA::CompoundPropertyWriterPtr GetCompoundPropertyWriterPtr(AbcA::CompoundPropertyWriterPtr iPtr)
Definition: Foundation.h:164
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:81
OTypedScalarProperty< C3cTPTraits > OC3cProperty
OTypedScalarProperty< P2dTPTraits > OP2dProperty
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
OTypedScalarProperty< Box3iTPTraits > OBox3iProperty
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104
OTypedScalarProperty< Uint32TPTraits > OUInt32Property
OTypedScalarProperty< V2iTPTraits > OV2iProperty
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr