HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 constructor creates a new typed array property reader.
107  //! The first argument is the ICompoundProperty parent, from which the
108  //! error handler policy for inheritance is also derived. The remaining
109  //! optional arguments can be used to override the ErrorHandlerPolicy,
110  //! to specify schema matching policy, and that's it.
112  const std::string &iName,
113  const Argument &iArg0 = Argument(),
114  const Argument &iArg1 = Argument() )
115  {
116  Arguments args( GetErrorHandlerPolicy( iParent ) );
117  iArg0.setInto( args );
118  iArg1.setInto( args );
119 
121 
123  "ITypedArrayProperty::ITypedArrayProperty()" );
124 
125  AbcA::CompoundPropertyReaderPtr parent = iParent.getPtr();
126  ABCA_ASSERT( parent != NULL,
127  "NULL CompoundPropertyReader passed into "
128  << "ITypedArrayProperty ctor" );
129 
130  const AbcA::PropertyHeader *pheader =
131  parent->getPropertyHeader( iName );
132  ABCA_ASSERT( pheader != NULL,
133  "Nonexistent array property: " << iName );
134 
135  ABCA_ASSERT( matches( *pheader, args.getSchemaInterpMatching() ),
136  "Incorrect match of header datatype: "
137  << pheader->getDataType()
138  << " to expected: "
139  << TRAITS::dataType()
140  << ",\n...or incorrect match of interpretation: "
141  << pheader->getMetaData().get( "interpretation" )
142  << " to expected: "
143  << TRAITS::interpretation() );
144 
145  m_property = parent->getArrayProperty( iName );
146 
148  }
149 
150  //! Explicitly wrap an existing property
151  //! It will check the data type and also verify the schema,
152  //! if requested.
154  const Argument &iArg0 = Argument(),
155  const Argument &iArg1 = Argument() )
156  {
158  "ITypedArrayProperty::ITypedArrayProperty()" );
159 
160  const AbcA::PropertyHeader &pheader = iProperty->getHeader();
161 
162  ABCA_ASSERT( matches( pheader,GetSchemaInterpMatching( iArg0, iArg1 ) ),
163  "Incorrect match of header datatype: "
164  << pheader.getDataType()
165  << " to expected: "
166  << TRAITS::dataType()
167  << ",\n...or incorrect match of interpretation: "
168  << pheader.getMetaData().get( "interpretation" )
169  << " to expected: "
170  << TRAITS::interpretation() );
171 
172  m_property = iProperty;
173 
175  }
176 
177  // Deprecated in favor of the constructor above
179  WrapExistingFlag iWrapFlag,
180  const Argument &iArg0 = Argument(),
181  const Argument &iArg1 = Argument() )
182  {
183  *this = ITypedArrayProperty( iProp, iArg0, iArg1 );
184  }
185 
186  //-*************************************************************************
187  // ARRAY PROPERTY FEATURES
188  //-*************************************************************************
189 
190  //! Get the typed sample.
191  //! ...
192  void get( sample_ptr_type& iVal,
193  const ISampleSelector &iSS = ISampleSelector() ) const
194  {
196  IArrayProperty::get( ptr, iSS );
197  iVal = Alembic::Util::static_pointer_cast<sample_type,
199  }
200 
201  //! Return the typed sample by value.
202  //! ...
204  {
205  sample_ptr_type ret;
206  get( ret, iSS );
207  return ret;
208  }
209 };
210 
211 //-*****************************************************************************
212 //-*****************************************************************************
213 //-*****************************************************************************
214 
229 
234 
239 
244 
249 
254 
259 
264 
267 
271 
275 
278 
281 
282 
283 } // End namespace ALEMBIC_VERSION_NS
284 
285 using namespace ALEMBIC_VERSION_NS;
286 
287 } // End namespace Abc
288 } // End namespace Alembic
289 
290 #endif
ITypedArrayProperty< N3dTPTraits > IN3dArrayProperty
ITypedArrayProperty< P2dTPTraits > IP2dArrayProperty
ITypedArrayProperty< V2sTPTraits > IV2sArrayProperty
ITypedArrayProperty< N3fTPTraits > IN3fArrayProperty
ITypedArrayProperty(const ICompoundProperty &iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
ITypedArrayProperty< P3dTPTraits > IP3dArrayProperty
ITypedArrayProperty(AbcA::ArrayPropertyReaderPtr iProperty, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
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:95
ITypedArrayProperty< Uint32TPTraits > IUInt32ArrayProperty
ITypedArrayProperty< Int16TPTraits > IInt16ArrayProperty
ITypedArrayProperty< P3sTPTraits > IP3sArrayProperty
ITypedArrayProperty< Uint16TPTraits > IUInt16ArrayProperty
ITypedArrayProperty< P2fTPTraits > IP2fArrayProperty
ITypedArrayProperty(AbcA::ArrayPropertyReaderPtr iProp, WrapExistingFlag iWrapFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
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:83
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:242
ITypedArrayProperty< C4hTPTraits > IC4hArrayProperty
sample_ptr_type getValue(const ISampleSelector &iSS=ISampleSelector()) const
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:318
ITypedArrayProperty< Uint8TPTraits > IUcharArrayProperty
ITypedArrayProperty< StringTPTraits > IStringArrayProperty
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
ITypedArrayProperty< M44dTPTraits > IM44dArrayProperty
ITypedArrayProperty< Box3dTPTraits > IBox3dArrayProperty
ErrorHandler & getErrorHandler() const
Definition: Base.h:76
ITypedArrayProperty< QuatfTPTraits > IQuatfArrayProperty
ITypedArrayProperty< P2iTPTraits > IP2iArrayProperty
ITypedArrayProperty< Box3fTPTraits > IBox3fArrayProperty
ITypedArrayProperty< M33dTPTraits > IM33dArrayProperty
ITypedArrayProperty< V3sTPTraits > IV3sArrayProperty
ITypedArrayProperty< Box2dTPTraits > IBox2dArrayProperty
ITypedArrayProperty< Box2sTPTraits > IBox2sArrayProperty
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:105
ITypedArrayProperty< P2sTPTraits > IP2sArrayProperty