HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
102  //! Create a new TypedArrayProperty
103  //! as a child of the passed iParent
104  //! Arguments can specify metadata, timesampling, and error handling.
107  const std::string &iName,
108 
109  const Argument &iArg0 = Argument(),
110  const Argument &iArg1 = Argument(),
111  const Argument &iArg2 = Argument(),
112  const Argument &iArg3 = Argument() )
113  {
114  init( iParent, iName, iArg0, iArg1, iArg2, iArg3 );
115  }
116 
117  //! Create a new TypedArrayProperty
118  //! as a child of the passed iParent
119  //! Arguments can specify metadata, timesampling, and error handling.
121  OCompoundProperty iParent,
122  const std::string &iName,
123 
124  const Argument &iArg0 = Argument(),
125  const Argument &iArg1 = Argument(),
126  const Argument &iArg2 = Argument() )
127  {
128  init( iParent.getPtr(), iName, GetErrorHandlerPolicy( iParent ),
129  iArg0, iArg1, iArg2 );
130  }
131 
132  //! Wrap an existing property. This will check to make sure
133  //! it can wrap.
136  const Argument &iArg0 = Argument(),
137  const Argument &iArg1 = Argument() )
138  : OArrayProperty( iProp,
139  GetErrorHandlerPolicy( iProp, iArg0, iArg1 ) )
140  {
141  init( iProp, iArg0, iArg1 );
142  }
143 
144 
145  // Deprecated in favor of constructor above
148  WrapExistingFlag iWrapFlag,
149  const Argument &iArg0 = Argument(),
150  const Argument &iArg1 = Argument() )
151  : OArrayProperty( iProp,
152  GetErrorHandlerPolicy( iProp, iArg0, iArg1 ) )
153  {
154  init( iProp, iArg0, iArg1 );
155  }
156 
157  //-*************************************************************************
158  // ARRAY PROPERTY FEATURES
159  //-*************************************************************************
160 
161  //! Set a sample using a reference to a typed array sample-type,
162  //! instead of a void* ArraySample
163  void set( const sample_type &iVal )
164  {
165  OArrayProperty::set( iVal );
166  }
167 
168 private:
169 
170  void init( AbcA::CompoundPropertyWriterPtr iParent,
171  const std::string &iName,
172 
173  const Argument &iArg0,
174  const Argument &iArg1,
175  const Argument &iArg2,
176  const Argument &iArg3 )
177  {
178  Arguments args;
179  iArg0.setInto( args );
180  iArg1.setInto( args );
181  iArg2.setInto( args );
182  iArg3.setInto( args );
183 
185 
186  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedArrayProperty::init()" );
187 
188  // Get actual writer for parent.
189  ABCA_ASSERT( iParent, "NULL CompoundPropertyWriterPtr" );
190 
191  // Put interpretation into metadata.
192  AbcA::MetaData mdata = args.getMetaData();
193  if ( std::string() != getInterpretation() )
194  {
195  mdata.set( "interpretation", getInterpretation() );
196  }
197 
198  // Create property.
199  AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
200  uint32_t tsIndex = args.getTimeSamplingIndex();
201 
202  // if we specified a valid TimeSamplingPtr, use it to determine the
203  // index otherwise we'll use the index, which defaults to the intrinsic
204  // 0 index
205  if (tsPtr)
206  {
207  tsIndex = iParent->getObject()->getArchive()->addTimeSampling(
208  *tsPtr);
209  }
210 
211  m_property = iParent->createArrayProperty( iName, mdata,
212  TRAITS::dataType(), tsIndex );
213 
215  }
216 
217  void init( AbcA::ArrayPropertyWriterPtr iProp,
218  const Argument &iArg0, const Argument &iArg1 )
219  {
221  "OTypedArrayProperty::init( ArrayPtr )" );
222 
223  const AbcA::PropertyHeader &pheader = iProp->getHeader();
224 
225  ABCA_ASSERT( matches( pheader, GetSchemaInterpMatching( iArg0,iArg1 ) ),
226  "Incorrect match of header datatype: "
227  << pheader.getDataType()
228  << " to expected: "
229  << TRAITS::dataType()
230  << ",\n...or incorrect match of interpretation: "
231  << pheader.getMetaData().get( "interpretation" )
232  << " to expected: "
233  << TRAITS::interpretation() );
234 
236  }
237 };
238 
239 //-*****************************************************************************
240 //-*****************************************************************************
241 //-*****************************************************************************
242 
257 
262 
267 
272 
277 
282 
287 
292 
295 
299 
303 
306 
309 
310 } // End namespace ALEMBIC_VERSION_NS
311 
312 using namespace ALEMBIC_VERSION_NS;
313 
314 } // End namespace Abc
315 } // End namespace Alembic
316 
317 #endif
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:814
OTypedArrayProperty< N3fTPTraits > ON3fArrayProperty
OTypedArrayProperty< Float16TPTraits > OHalfArrayProperty
void setInto(Arguments &iArgs) const
Definition: Argument.h:149
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:89
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: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
OTypedArrayProperty< C3cTPTraits > OC3cArrayProperty
Alembic::Util::shared_ptr< ArrayPropertyWriter > ArrayPropertyWriterPtr
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:318
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
ErrorHandler & getErrorHandler() const
Definition: Base.h:76
OTypedArrayProperty(AbcA::ArrayPropertyWriterPtr iProp, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
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
OTypedArrayProperty(AbcA::CompoundPropertyWriterPtr iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
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(AbcA::ArrayPropertyWriterPtr iProp, WrapExistingFlag iWrapFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
**If you just want to fire and args
Definition: thread.h:609
OTypedArrayProperty< V3fTPTraits > OV3fArrayProperty
OTypedArrayProperty< Uint32TPTraits > OUInt32ArrayProperty
OTypedArrayProperty< C4fTPTraits > OC4fArrayProperty
OTypedArrayProperty(OCompoundProperty iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:86
OTypedArrayProperty< Box3dTPTraits > OBox3dArrayProperty
OTypedArrayProperty< V3iTPTraits > OV3iArrayProperty
OTypedArrayProperty< Box2dTPTraits > OBox2dArrayProperty
HUSD_API const char * dataType()
OTypedArrayProperty< QuatdTPTraits > OQuatdArrayProperty
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88
OTypedArrayProperty< Uint16TPTraits > OUInt16ArrayProperty
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr