HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTypedArrayProperty.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_OTypedArrayProperty_h_
37 #define _Alembic_Abc_OTypedArrayProperty_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 
61  //! Return the interpretation expected of this
62  //! property. An empty interpretation matches everything
63  static const char * getInterpretation()
64  {
65  return TRAITS::interpretation();
66  }
67 
68  //! This will check whether or not a given entity (as represented by
69  //! a metadata) strictly matches the interpretation of this
70  //! typed property
71  static bool matches( const AbcA::MetaData &iMetaData,
73  {
74  return ( iMetaData.get( "interpretation" ) ==
76  }
77 
78  //! This will check whether or not a given object (as represented by
79  //! an property header) strictly matches the interpretation of this
80  //! typed property, as well as the data type.
81  static bool matches( const AbcA::PropertyHeader &iHeader,
83  {
84  return ( iHeader.getDataType().getPod() ==
85  TRAITS::dataType().getPod() &&
86  ( iHeader.getDataType().getExtent() ==
87  TRAITS::dataType().getExtent() ||
88  std::string() == getInterpretation() ) ) &&
89  iHeader.isArray() &&
90  matches( iHeader.getMetaData(), iMatching );
91  }
92 
93  //-*************************************************************************
94  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
95  //-*************************************************************************
96 
97  //! Create a default (empty) TypedArrayProperty
98  //! ...
100 
101  //! Create a new TypedArrayProperty
102  //! as a child of the passed COMPOUND_PTR
103  //! Arguments can specify metadata, timesampling, and error handling.
104  template <class COMPOUND_PTR>
106  COMPOUND_PTR iParent,
107  const std::string &iName,
108 
109  const Argument &iArg0 = Argument(),
110  const Argument &iArg1 = Argument(),
111  const Argument &iArg2 = Argument() );
112 
113  //! Wrap an existing property. This will check to make sure
114  //! it can wrap.
117  WrapExistingFlag iWrapFlag,
118  const Argument &iArg0 = Argument(),
119  const Argument &iArg1 = Argument() );
120 
121  //-*************************************************************************
122  // ARRAY PROPERTY FEATURES
123  //-*************************************************************************
124 
125  //! Set a sample using a reference to a typed array sample-type,
126  //! instead of a void* ArraySample
127  void set( const sample_type &iVal )
128  {
129  OArrayProperty::set( iVal );
130  }
131 };
132 
133 //-*****************************************************************************
134 // TEMPLATE AND INLINE FUNCTIONS
135 //-*****************************************************************************
136 
137 //-*****************************************************************************
138 template <class TRAITS>
139 template <class COMPOUND_PTR>
141 (
142  COMPOUND_PTR iParent,
143  const std::string &iName,
144 
145  const Argument &iArg0,
146  const Argument &iArg1,
147  const Argument &iArg2 )
148 {
149  Arguments args( GetErrorHandlerPolicy( iParent ) );
150  iArg0.setInto( args );
151  iArg1.setInto( args );
152  iArg2.setInto( args );
153 
154  getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
155 
156  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedArrayProperty::init()" );
157 
158  // Get actual writer for parent.
160  GetCompoundPropertyWriterPtr( iParent );
161  ABCA_ASSERT( parent, "NULL CompoundPropertyWriterPtr" );
162 
163  // Put interpretation into metadata.
164  AbcA::MetaData mdata = args.getMetaData();
165  if ( std::string() != getInterpretation() )
166  {
167  mdata.set( "interpretation", getInterpretation() );
168  }
169 
170  // Create property.
171  AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
172  uint32_t tsIndex = args.getTimeSamplingIndex();
173 
174  // if we specified a valid TimeSamplingPtr, use it to determine the index
175  // otherwise we'll use the index, which defaults to the intrinsic 0 index
176  if (tsPtr)
177  {
178  tsIndex = parent->getObject()->getArchive()->addTimeSampling(*tsPtr);
179  }
180 
181  m_property = parent->createArrayProperty( iName, mdata,
182  TRAITS::dataType(), tsIndex );
183 
185 }
186 
187 //-*****************************************************************************
188 template<class TRAITS>
191  WrapExistingFlag iFlag,
192  const Argument &iArg0,
193  const Argument &iArg1 )
194  : OArrayProperty( iProperty,
195  iFlag,
196  GetErrorHandlerPolicy( iProperty, iArg0, iArg1 ) )
197 {
199  "OTypedArrayProperty::OTypedArrayProperty()" );
200 
201  const AbcA::PropertyHeader &pheader = iProperty->getHeader();
202 
203  ABCA_ASSERT( matches( pheader, GetSchemaInterpMatching( iArg0, iArg1 ) ),
204 
205  "Incorrect match of header datatype: "
206  << pheader.getDataType()
207  << " to expected: "
208  << TRAITS::dataType()
209  << ",\n...or incorrect match of interpretation: "
210  << pheader.getMetaData().get( "interpretation" )
211  << " to expected: "
212  << TRAITS::interpretation() );
213 
215 }
216 
217 //-*****************************************************************************
218 //-*****************************************************************************
219 //-*****************************************************************************
220 
235 
240 
245 
250 
255 
260 
265 
270 
273 
277 
281 
284 
287 
288 } // End namespace ALEMBIC_VERSION_NS
289 
290 using namespace ALEMBIC_VERSION_NS;
291 
292 } // End namespace Abc
293 } // End namespace Alembic
294 
295 #endif
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:219
OTypedArrayProperty< Box2fTPTraits > OBox2fArrayProperty
OTypedArrayProperty< Int8TPTraits > OCharArrayProperty
OTypedArrayProperty< C3hTPTraits > OC3hArrayProperty
OTypedArrayProperty< V2dTPTraits > OV2dArrayProperty
OTypedArrayProperty< StringTPTraits > OStringArrayProperty
OTypedArrayProperty< Box2iTPTraits > OBox2iArrayProperty
OTypedArrayProperty< P2dTPTraits > OP2dArrayProperty
OTypedArrayProperty< WstringTPTraits > OWstringArrayProperty
OTypedArrayProperty< C3fTPTraits > OC3fArrayProperty
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
OTypedArrayProperty< N3fTPTraits > ON3fArrayProperty
OTypedArrayProperty< Float16TPTraits > OHalfArrayProperty
void setInto(Arguments &iArgs) const
Definition: Argument.h:135
OTypedArrayProperty< P2fTPTraits > OP2fArrayProperty
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
OTypedArrayProperty< P3sTPTraits > OP3sArrayProperty
OTypedArrayProperty< N2fTPTraits > ON2fArrayProperty
OTypedArrayProperty< Float32TPTraits > OFloatArrayProperty
void set(const AbcA::ArraySample &iSample)
OTypedArrayProperty< M44dTPTraits > OM44dArrayProperty
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: Argument.h:84
uint64 value_type
Definition: GA_PrimCompat.h:29
OTypedArrayProperty< V2sTPTraits > OV2sArrayProperty
OTypedArrayProperty< M33dTPTraits > OM33dArrayProperty
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
OTypedArrayProperty< V2fTPTraits > OV2fArrayProperty
OTypedArrayProperty< Float64TPTraits > ODoubleArrayProperty
OTypedArrayProperty< V2iTPTraits > OV2iArrayProperty
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
OTypedArrayProperty< Box3sTPTraits > OBox3sArrayProperty
OTypedArrayProperty< M44fTPTraits > OM44fArrayProperty
OTypedArrayProperty< V3dTPTraits > OV3dArrayProperty
OTypedArrayProperty< P3fTPTraits > OP3fArrayProperty
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:78
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
OTypedArrayProperty< C3cTPTraits > OC3cArrayProperty
Alembic::Util::shared_ptr< ArrayPropertyWriter > ArrayPropertyWriterPtr
OTypedArrayProperty< P2iTPTraits > OP2iArrayProperty
OTypedArrayProperty< Uint8TPTraits > OUcharArrayProperty
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
OTypedArrayProperty< N3dTPTraits > ON3dArrayProperty
OTypedArrayProperty< N2dTPTraits > ON2dArrayProperty
OTypedArrayProperty< P3dTPTraits > OP3dArrayProperty
OTypedArrayProperty< Box3iTPTraits > OBox3iArrayProperty
OTypedArrayProperty< Int16TPTraits > OInt16ArrayProperty
OTypedArrayProperty< Int64TPTraits > OInt64ArrayProperty
OTypedArrayProperty< P3iTPTraits > OP3iArrayProperty
OTypedArrayProperty< BooleanTPTraits > OBoolArrayProperty
void set(const std::string &iKey, const std::string &iData)
Definition: MetaData.h:168
OTypedArrayProperty< C4hTPTraits > OC4hArrayProperty
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:285
OTypedArrayProperty< Int32TPTraits > OInt32ArrayProperty
OTypedArrayProperty< M33fTPTraits > OM33fArrayProperty
OTypedArrayProperty< QuatfTPTraits > OQuatfArrayProperty
OTypedArrayProperty< P2sTPTraits > OP2sArrayProperty
OTypedArrayProperty< Box2sTPTraits > OBox2sArrayProperty
OTypedArrayProperty< Box3fTPTraits > OBox3fArrayProperty
OTypedArrayProperty< Uint64TPTraits > OUInt64ArrayProperty
OTypedArrayProperty< V3sTPTraits > OV3sArrayProperty
OTypedArrayProperty< C4cTPTraits > OC4cArrayProperty
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
OTypedArrayProperty< V3fTPTraits > OV3fArrayProperty
OTypedArrayProperty< Uint32TPTraits > OUInt32ArrayProperty
OTypedArrayProperty< C4fTPTraits > OC4fArrayProperty
AbcA::CompoundPropertyWriterPtr GetCompoundPropertyWriterPtr(AbcA::CompoundPropertyWriterPtr iPtr)
Definition: Foundation.h:164
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:81
OTypedArrayProperty< Box3dTPTraits > OBox3dArrayProperty
OTypedArrayProperty< V3iTPTraits > OV3iArrayProperty
OTypedArrayProperty< Box2dTPTraits > OBox2dArrayProperty
OTypedArrayProperty< QuatdTPTraits > OQuatdArrayProperty
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104
OTypedArrayProperty< Uint16TPTraits > OUInt16ArrayProperty
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr