HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ITypedArrayProperty.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_ITypedArrayProperty_h_
37 #define _Alembic_Abc_ITypedArrayProperty_h_
38 
39 #include <Alembic/Abc/Foundation.h>
43 
44 namespace Alembic {
45 namespace Abc {
46 namespace ALEMBIC_VERSION_NS {
47 
48 //-*****************************************************************************
49 template <class TRAITS>
51 {
52 public:
53  //-*************************************************************************
54  // TYPEDEFS AND IDENTIFIERS
55  //-*************************************************************************
56  typedef TRAITS traits_type;
58  typedef typename TRAITS::value_type value_type;
60  typedef shared_ptr<sample_type> sample_ptr_type;
61 
62  //! Return the interpretation expected of this
63  //! property. An empty interpretation matches everything
64  static const char * getInterpretation()
65  {
66  return TRAITS::interpretation();
67  }
68 
69  //! This will check whether or not a given entity (as represented by
70  //! a metadata) strictly matches the interpretation of this
71  //! schema object
72  static bool matches( const AbcA::MetaData &iMetaData,
74  {
75  if ( iMatching == kStrictMatching )
76  {
77  return ( iMetaData.get( "interpretation" ) ==
79  }
80  return true;
81  }
82 
83  //! This will check whether or not a given object (as represented by
84  //! an object header) strictly matches the interpretation of this
85  //! schema object
86  static bool matches( const AbcA::PropertyHeader &iHeader,
88  {
89  return ( iHeader.getDataType().getPod() ==
90  TRAITS::dataType().getPod() &&
91  ( iHeader.getDataType().getExtent() ==
92  TRAITS::dataType().getExtent() ||
93  std::string() == getInterpretation() ) ) &&
94  iHeader.isArray() &&
95  matches( iHeader.getMetaData(), iMatching );
96  }
97 
98  //-*************************************************************************
99  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
100  //-*************************************************************************
101 
102  //! Default constructor
103  //! ...
105 
106  //! This templated, explicit function creates a new
107  //! typed array property reader.
108  //! The first argument is any Abc (or AbcCoreAbstract) object
109  //! which can intrusively be converted to a CompoundPropertyReaderPtr
110  //! to use as a parent, from which the error handler policy for
111  //! inheritance is also derived. The remaining optional arguments
112  //! can be used to override the ErrorHandlerPolicy, to specify
113  //! schema matching policy, and that's it.
114  template <class COMPOUND_PTR>
115  ITypedArrayProperty( COMPOUND_PTR iParent,
116  const std::string &iName,
117 
118  const Argument &iArg0 = Argument(),
119  const Argument &iArg1 = Argument() );
120 
121  //! Explicitly wrap an existing property
122  //! It will check the data type and also verify the schema,
123  //! if requested.
125  WrapExistingFlag iWrapFlag,
126  const Argument &iArg0 = Argument(),
127  const Argument &iArg1 = Argument() );
128 
129 
130  //-*************************************************************************
131  // ARRAY PROPERTY FEATURES
132  //-*************************************************************************
133 
134  //! Get the typed sample.
135  //! ...
136  void get( sample_ptr_type& iVal,
137  const ISampleSelector &iSS = ISampleSelector() ) const
138  {
140  IArrayProperty::get( ptr, iSS );
141  iVal = Alembic::Util::static_pointer_cast<sample_type,
143  }
144 
145  //! Return the typed sample by value.
146  //! ...
148  {
149  sample_ptr_type ret;
150  get( ret, iSS );
151  return ret;
152  }
153 };
154 
155 //-*****************************************************************************
156 // TEMPLATE AND INLINE FUNCTIONS
157 //-*****************************************************************************
158 
159 //-*****************************************************************************
160 template <class TRAITS>
161 template <class COMPOUND_PTR>
163 (
164  COMPOUND_PTR iParent,
165  const std::string &iName,
166  const Argument &iArg0,
167  const Argument &iArg1 )
168 {
169  Arguments args( GetErrorHandlerPolicy( iParent ) );
170  iArg0.setInto( args );
171  iArg1.setInto( args );
172 
173  getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
174 
176  "ITypedArrayProperty::ITypedArrayProperty()" );
177 
179  GetCompoundPropertyReaderPtr( iParent );
180  ABCA_ASSERT( parent != NULL,
181  "NULL CompoundPropertyReader passed into "
182  << "ITypedArrayProperty ctor" );
183 
184  const AbcA::PropertyHeader *pheader =
185  parent->getPropertyHeader( iName );
186  ABCA_ASSERT( pheader != NULL,
187  "Nonexistent array property: " << iName );
188 
189  ABCA_ASSERT( matches( *pheader, args.getSchemaInterpMatching() ),
190 
191  "Incorrect match of header datatype: "
192  << pheader->getDataType()
193  << " to expected: "
194  << TRAITS::dataType()
195  << ",\n...or incorrect match of interpretation: "
196  << pheader->getMetaData().get( "interpretation" )
197  << " to expected: "
198  << TRAITS::interpretation() );
199 
200  m_property = parent->getArrayProperty( iName );
201 
203 }
204 
205 //-*****************************************************************************
206 template <class TRAITS>
209  WrapExistingFlag iFlag,
210  const Argument &iArg0,
211  const Argument &iArg1 )
212  : IArrayProperty( iProperty,
213  iFlag,
214  GetErrorHandlerPolicy( iProperty, iArg0, iArg1 ) )
215 {
217  "ITypedArrayProperty::ITypedArrayProperty()" );
218 
219  const AbcA::PropertyHeader &pheader = iProperty->getHeader();
220 
221  ABCA_ASSERT( matches( pheader, GetSchemaInterpMatching( iArg0, iArg1 ) ),
222 
223  "Incorrect match of header datatype: "
224  << pheader.getDataType()
225  << " to expected: "
226  << TRAITS::dataType()
227  << ",\n...or incorrect match of interpretation: "
228  << pheader.getMetaData().get( "interpretation" )
229  << " to expected: "
230  << TRAITS::interpretation() );
231 
233 }
234 
235 //-*****************************************************************************
236 //-*****************************************************************************
237 //-*****************************************************************************
238 
253 
258 
263 
268 
273 
278 
283 
288 
291 
295 
299 
302 
305 
306 
307 } // End namespace ALEMBIC_VERSION_NS
308 
309 using namespace ALEMBIC_VERSION_NS;
310 
311 } // End namespace Abc
312 } // End namespace Alembic
313 
314 #endif
ITypedArrayProperty< N3dTPTraits > IN3dArrayProperty
ITypedArrayProperty< P2dTPTraits > IP2dArrayProperty
ITypedArrayProperty< V2sTPTraits > IV2sArrayProperty
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:219
ITypedArrayProperty< N3fTPTraits > IN3fArrayProperty
ITypedArrayProperty< P3dTPTraits > IP3dArrayProperty
ITypedArrayProperty< C4fTPTraits > IC4fArrayProperty
ITypedArrayProperty< V3dTPTraits > IV3dArrayProperty
ITypedArrayProperty< Int64TPTraits > IInt64ArrayProperty
ITypedArrayProperty< C3cTPTraits > IC3cArrayProperty
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
ITypedArrayProperty< Int8TPTraits > ICharArrayProperty
ITypedArrayProperty< V2fTPTraits > IV2fArrayProperty
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
png_voidp ptr
Definition: png.h:2145
ITypedArrayProperty< WstringTPTraits > IWstringArrayProperty
ITypedArrayProperty< Uint64TPTraits > IUInt64ArrayProperty
ITypedArrayProperty< Int32TPTraits > IInt32ArrayProperty
ITypedArrayProperty< Float64TPTraits > IDoubleArrayProperty
SchemaInterpMatching getSchemaInterpMatching() const
Definition: Argument.h:90
ITypedArrayProperty< Uint32TPTraits > IUInt32ArrayProperty
void setInto(Arguments &iArgs) const
Definition: Argument.h:135
ITypedArrayProperty< Int16TPTraits > IInt16ArrayProperty
ITypedArrayProperty< P3sTPTraits > IP3sArrayProperty
ITypedArrayProperty< Uint16TPTraits > IUInt16ArrayProperty
ITypedArrayProperty< P2fTPTraits > IP2fArrayProperty
ITypedArrayProperty< Box2fTPTraits > IBox2fArrayProperty
ITypedArrayProperty< N2dTPTraits > IN2dArrayProperty
Alembic::Util::shared_ptr< ArrayPropertyReader > ArrayPropertyReaderPtr
ITypedArrayProperty< V2dTPTraits > IV2dArrayProperty
uint64 value_type
Definition: GA_PrimCompat.h:29
ITypedArrayProperty< QuatdTPTraits > IQuatdArrayProperty
ITypedArrayProperty< BooleanTPTraits > IBoolArrayProperty
Alembic::Util::shared_ptr< ArraySample > ArraySamplePtr
Definition: ArraySample.h:138
ITypedArrayProperty< Box2iTPTraits > IBox2iArrayProperty
ITypedArrayProperty< P3fTPTraits > IP3fArrayProperty
ITypedArrayProperty< C4cTPTraits > IC4cArrayProperty
ITypedArrayProperty< P3iTPTraits > IP3iArrayProperty
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
void get(AbcA::ArraySamplePtr &oSample, const ISampleSelector &iSS=ISampleSelector()) const
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:78
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
ITypedArrayProperty< C4hTPTraits > IC4hArrayProperty
sample_ptr_type getValue(const ISampleSelector &iSS=ISampleSelector()) const
ITypedArrayProperty< Uint8TPTraits > IUcharArrayProperty
ITypedArrayProperty< StringTPTraits > IStringArrayProperty
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
ITypedArrayProperty< M44dTPTraits > IM44dArrayProperty
ITypedArrayProperty< Box3dTPTraits > IBox3dArrayProperty
ITypedArrayProperty< QuatfTPTraits > IQuatfArrayProperty
ITypedArrayProperty< P2iTPTraits > IP2iArrayProperty
ITypedArrayProperty< Box3fTPTraits > IBox3fArrayProperty
ITypedArrayProperty< M33dTPTraits > IM33dArrayProperty
ITypedArrayProperty< V3sTPTraits > IV3sArrayProperty
ITypedArrayProperty< Box2dTPTraits > IBox2dArrayProperty
ITypedArrayProperty< Box2sTPTraits > IBox2sArrayProperty
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
ITypedArrayProperty< Float16TPTraits > IHalfArrayProperty
ITypedArrayProperty< Float32TPTraits > IFloatArrayProperty
ITypedArrayProperty< V3iTPTraits > IV3iArrayProperty
ITypedArrayProperty< V2iTPTraits > IV2iArrayProperty
ITypedArrayProperty< Box3sTPTraits > IBox3sArrayProperty
ITypedArrayProperty< C3fTPTraits > IC3fArrayProperty
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
ITypedArrayProperty< M44fTPTraits > IM44fArrayProperty
ITypedArrayProperty< V3fTPTraits > IV3fArrayProperty
ITypedArrayProperty< M33fTPTraits > IM33fArrayProperty
ITypedArrayProperty< N2fTPTraits > IN2fArrayProperty
ITypedArrayProperty< C3hTPTraits > IC3hArrayProperty
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
ITypedArrayProperty< Box3iTPTraits > IBox3iArrayProperty
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104
ITypedArrayProperty< P2sTPTraits > IP2sArrayProperty