HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ITypedScalarProperty.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_ITypedScalarProperty_h_
37 #define _Alembic_Abc_ITypedScalarProperty_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  // TYPEDEFS AND IDENTIFIERS
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  if ( iMatching == kStrictMatching )
73  {
74  return ( iMetaData.get( "interpretation" ) ==
76  }
77  return true;
78  }
79 
80  //! This will check whether or not a given object (as represented by
81  //! an object header) strictly matches the interpretation of this
82  //! schema object
83  static bool matches( const AbcA::PropertyHeader &iHeader,
85  {
86  return ( iHeader.getDataType().getPod() ==
87  TRAITS::dataType().getPod() &&
88  ( iHeader.getDataType().getExtent() ==
89  TRAITS::dataType().getExtent() ||
90  std::string() == getInterpretation() ) ) &&
91  iHeader.isScalar() &&
92  matches( iHeader.getMetaData(), iMatching );
93  }
94 
95  //-*************************************************************************
96  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
97  //-*************************************************************************
98 
99  //! Default constructor
100  //! ...
102 
103  //! This templated, explicit function creates a new
104  //! typed scalar property reader.
105  //! The first argument is any Abc (or AbcCoreAbstract) object
106  //! which can intrusively be converted to a CompoundPropertyReaderPtr
107  //! to use as a parent, from which the error handler policy for
108  //! inheritance is also derived. The remaining optional arguments
109  //! can be used to override the ErrorHandlerPolicy, to specify
110  //! schema matching policy, and that's it.
111  template <class COMPOUND_PTR>
112  ITypedScalarProperty( COMPOUND_PTR iParent,
113  const std::string &iName,
114 
115  const Argument &iArg0 = Argument(),
116  const Argument &iArg1 = Argument() );
117 
118  //! Explicitly wrap an existing property
119  //! It will check the data type and also verify the schema,
120  //! if requested.
122  WrapExistingFlag iWrapFlag,
123  const Argument &iArg0 = Argument(),
124  const Argument &iArg1 = Argument() );
125 
126 
127  //-*************************************************************************
128  // SCALAR PROPERTY FEATURES
129  //-*************************************************************************
130 
131  //! Get the typed sample.
132  //! ...
133  void get( value_type &iVal,
134  const ISampleSelector &iSS = ISampleSelector() ) const
135  {
136  IScalarProperty::get( reinterpret_cast<void*>( &iVal ), iSS );
137  }
138 
139  //! Return the typed sample by value.
140  //! ...
142  {
143  value_type ret;
144  get( ret, iSS );
145  return ret;
146  }
147 };
148 
149 //-*****************************************************************************
150 // TEMPLATE AND INLINE FUNCTIONS
151 //-*****************************************************************************
152 
153 //-*****************************************************************************
154 template <class TRAITS>
155 template <class COMPOUND_PTR>
157 (
158  COMPOUND_PTR iParent,
159  const std::string &iName,
160  const Argument &iArg0,
161  const Argument &iArg1 )
162 {
163  Arguments args( GetErrorHandlerPolicy( iParent ) );
164  iArg0.setInto( args );
165  iArg1.setInto( args );
166 
167  getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
168 
170  "ITypedScalarProperty::ITypedScalarProperty()" );
171 
173  GetCompoundPropertyReaderPtr( iParent );
174  ABCA_ASSERT( parent != NULL,
175  "NULL CompoundPropertyReader passed into "
176  << "ITypedScalarProperty ctor" );
177 
178  const AbcA::PropertyHeader *pheader =
179  parent->getPropertyHeader( iName );
180  ABCA_ASSERT( pheader != NULL,
181  "Nonexistent scalar property: " << iName );
182 
183  ABCA_ASSERT( matches( *pheader, args.getSchemaInterpMatching() ),
184 
185  "Incorrect match of header datatype: "
186  << pheader->getDataType()
187  << " to expected: "
188  << TRAITS::dataType()
189  << ",\n...or incorrect match of interpretation: "
190  << pheader->getMetaData().get( "interpretation" )
191  << " to expected: "
192  << TRAITS::interpretation() );
193 
194  m_property = parent->getScalarProperty( iName );
195 
197 }
198 
199 //-*****************************************************************************
200 template <class TRAITS>
203  WrapExistingFlag iFlag,
204  const Argument &iArg0,
205  const Argument &iArg1 )
206  : IScalarProperty( iProperty,
207  iFlag,
208  GetErrorHandlerPolicy( iProperty, iArg0, iArg1 ) )
209 {
211  "ITypedScalarProperty::ITypedScalarProperty()" );
212 
213  const AbcA::PropertyHeader &pheader = iProperty->getHeader();
214 
215  ABCA_ASSERT( matches( pheader, GetSchemaInterpMatching( iArg0, iArg1 ) ),
216 
217  "Incorrect match of header datatype: "
218  << pheader.getDataType()
219  << " to expected: "
220  << TRAITS::dataType()
221  << ",\n...or incorrect match of interpretation: "
222  << pheader.getMetaData().get( "interpretation" )
223  << " to expected: "
224  << TRAITS::interpretation() );
225 
227 }
228 
229 
230 //-*****************************************************************************
231 //-*****************************************************************************
232 //-*****************************************************************************
233 
248 
253 
258 
263 
268 
273 
278 
283 
286 
290 
294 
297 
300 
301 } // End namespace ALEMBIC_VERSION_NS
302 
303 using namespace ALEMBIC_VERSION_NS;
304 
305 } // End namespace Abc
306 } // End namespace Alembic
307 
308 #endif
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:219
ITypedScalarProperty< Float32TPTraits > IFloatProperty
value_type getValue(const ISampleSelector &iSS=ISampleSelector()) const
ITypedScalarProperty< Box3iTPTraits > IBox3iProperty
ITypedScalarProperty< P2dTPTraits > IP2dProperty
ITypedScalarProperty< C3cTPTraits > IC3cProperty
ITypedScalarProperty< Uint64TPTraits > IUInt64Property
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
SchemaInterpMatching getSchemaInterpMatching() const
Definition: Argument.h:90
ITypedScalarProperty< P3sTPTraits > IP3sProperty
void setInto(Arguments &iArgs) const
Definition: Argument.h:135
ITypedScalarProperty< N2fTPTraits > IN2fProperty
ITypedScalarProperty< Box2sTPTraits > IBox2sProperty
ITypedScalarProperty< P3dTPTraits > IP3dProperty
ITypedScalarProperty< QuatfTPTraits > IQuatfProperty
ITypedScalarProperty< QuatdTPTraits > IQuatdProperty
ITypedScalarProperty< N3fTPTraits > IN3fProperty
ITypedScalarProperty< V3iTPTraits > IV3iProperty
ITypedScalarProperty< Box3sTPTraits > IBox3sProperty
uint64 value_type
Definition: GA_PrimCompat.h:29
ITypedScalarProperty< V3fTPTraits > IV3fProperty
ITypedScalarProperty< Box2iTPTraits > IBox2iProperty
ITypedScalarProperty< P2fTPTraits > IP2fProperty
ITypedScalarProperty< V2dTPTraits > IV2dProperty
ITypedScalarProperty< C3hTPTraits > IC3hProperty
ITypedScalarProperty< V2fTPTraits > IV2fProperty
ITypedScalarProperty< V2iTPTraits > IV2iProperty
ITypedScalarProperty< M33dTPTraits > IM33dProperty
ITypedScalarProperty< Int16TPTraits > IInt16Property
ITypedScalarProperty< M44dTPTraits > IM44dProperty
ITypedScalarProperty< Box3fTPTraits > IBox3fProperty
ITypedScalarProperty< Box2fTPTraits > IBox2fProperty
ITypedScalarProperty< P2iTPTraits > IP2iProperty
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
ITypedScalarProperty< Float64TPTraits > IDoubleProperty
ITypedScalarProperty< Uint8TPTraits > IUcharProperty
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:78
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
ITypedScalarProperty< StringTPTraits > IStringProperty
ITypedScalarProperty< N3dTPTraits > IN3dProperty
ITypedScalarProperty< C4fTPTraits > IC4fProperty
ITypedScalarProperty< N2dTPTraits > IN2dProperty
ITypedScalarProperty< P3iTPTraits > IP3iProperty
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
ITypedScalarProperty< Uint32TPTraits > IUInt32Property
ITypedScalarProperty< Int8TPTraits > ICharProperty
ITypedScalarProperty< V3dTPTraits > IV3dProperty
ITypedScalarProperty< Int64TPTraits > IInt64Property
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
ITypedScalarProperty< WstringTPTraits > IWstringProperty
AbcA::CompoundPropertyReaderPtr GetCompoundPropertyReaderPtr(AbcA::CompoundPropertyReaderPtr iPtr)
Definition: Foundation.h:171
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:285
ITypedScalarProperty< M33fTPTraits > IM33fProperty
ITypedScalarProperty< Int32TPTraits > IInt32Property
ITypedScalarProperty< C4hTPTraits > IC4hProperty
ITypedScalarProperty< Uint16TPTraits > IUInt16Property
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
ITypedScalarProperty< Box2dTPTraits > IBox2dProperty
void get(void *oSample, const ISampleSelector &iSS=ISampleSelector()) const
ITypedScalarProperty< P2sTPTraits > IP2sProperty
ITypedScalarProperty< C4cTPTraits > IC4cProperty
ITypedScalarProperty< V3sTPTraits > IV3sProperty
ITypedScalarProperty< M44fTPTraits > IM44fProperty
ITypedScalarProperty< C3fTPTraits > IC3fProperty
ITypedScalarProperty< BooleanTPTraits > IBoolProperty
ITypedScalarProperty< V2sTPTraits > IV2sProperty
Alembic::Util::shared_ptr< ScalarPropertyReader > ScalarPropertyReaderPtr
ITypedScalarProperty< P3fTPTraits > IP3fProperty
ITypedScalarProperty< Box3dTPTraits > IBox3dProperty
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104
ITypedScalarProperty< Float16TPTraits > IHalfProperty