HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OTypedScalarProperty.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_OTypedScalarProperty_h
37 #define Alembic_Abc_OTypedScalarProperty_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  // TYPE IDENTIFICATION
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  return ( iMetaData.get( "interpretation" ) ==
74  }
75 
76  //! This will check whether or not a given object (as represented by
77  //! an object header) strictly matches the interpretation of this
78  //! schema object, as well as the data type.
79  static bool matches( const AbcA::PropertyHeader &iHeader,
81  {
82  return ( iHeader.getDataType().getPod() ==
83  TRAITS::dataType().getPod() &&
84  ( iHeader.getDataType().getExtent() ==
85  TRAITS::dataType().getExtent() ||
86  std::string() == getInterpretation() ) ) &&
87  iHeader.isScalar() &&
88  matches( iHeader.getMetaData(), iMatching );
89  }
90 
91  //-*************************************************************************
92  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
93  //-*************************************************************************
94 
95  //! Create a default (empty) TypedScalarProperty
96  //! ...
98 
99  //! Create a new TypedScalarProperty
100  //! as a child of the passed iParent
101  //! Arguments can specify metadata, timesampling, and error handling.
104  const std::string &iName,
105 
106  const Argument &iArg0 = Argument(),
107  const Argument &iArg1 = Argument(),
108  const Argument &iArg2 = Argument(),
109  const Argument &iArg3 = Argument() )
110  {
111  init( iParent, iName, iArg0, iArg1, iArg2, iArg3 );
112  }
113 
114  //! Create a new TypedScalarProperty
115  //! as a child of the passed iParent
116  //! Arguments can specify metadata, timesampling, and error handling.
118  OCompoundProperty iParent,
119  const std::string &iName,
120 
121  const Argument &iArg0 = Argument(),
122  const Argument &iArg1 = Argument(),
123  const Argument &iArg2 = Argument() )
124  {
125  init( iParent.getPtr(), iName, GetErrorHandlerPolicy( iParent ),
126  iArg0, iArg1, iArg2 );
127  }
128 
129  //! Wrap an existing scalar property,
130  //! checking to make sure it matches data type and also
131  //! (if requested) interpretation.
134  const Argument &iArg0 = Argument(),
135  const Argument &iArg1 = Argument() )
136  : OScalarProperty( iProp, GetErrorHandlerPolicy( iProp, iArg0, iArg1 ) )
137  {
139  "OTypedScalarProperty::OTypedScalarProperty()" );
140 
141  const AbcA::PropertyHeader &pheader = iProp->getHeader();
142 
143  ABCA_ASSERT( matches( pheader, GetSchemaInterpMatching( iArg0,iArg1 ) ),
144 
145  "Incorrect match of header datatype: "
146  << pheader.getDataType()
147  << " to expected: "
148  << TRAITS::dataType()
149  << ",\n...or incorrect match of interpretation: "
150  << pheader.getMetaData().get( "interpretation" )
151  << " to expected: "
152  << TRAITS::interpretation() );
153 
155  }
156 
157  // Deprecated in favor of the constructor above
160  WrapExistingFlag iWrapFlag,
161  const Argument &iArg0 = Argument(),
162  const Argument &iArg1 = Argument() )
163  {
164  *this = OTypedScalarProperty( iProp, iArg0, iArg1 );
165  }
166 
167  //-*************************************************************************
168  // SCALAR PROPERTY FEATURES
169  //-*************************************************************************
170 
171  //! Set a sample using a reference to a value-type,
172  //! instead of a void*
173  void set( const value_type &iVal )
174  {
175  OScalarProperty::set( reinterpret_cast<const void *>( &iVal ) );
176  }
177 
178 private:
179 
180  void init( AbcA::CompoundPropertyWriterPtr iParent,
181  const std::string &iName,
182  const Argument &iArg0,
183  const Argument &iArg1,
184  const Argument &iArg2,
185  const Argument &iArg3 )
186  {
187  Arguments args;
188  iArg0.setInto( args );
189  iArg1.setInto( args );
190  iArg2.setInto( args );
191  iArg3.setInto( args );
192 
194 
195  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedScalarProperty::init()" );
196 
197  ABCA_ASSERT( iParent, "NULL CompoundPropertyWriterPtr" );
198 
199  AbcA::MetaData mdata = args.getMetaData();
200  if ( std::string() != getInterpretation() )
201  {
202  mdata.set( "interpretation", getInterpretation() );
203  }
204 
205  AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
206 
207  uint32_t tsIndex = args.getTimeSamplingIndex();
208 
209  // if we specified a valid TimeSamplingPtr, use it to determine the
210  // index otherwise we'll use the index, which defaults to the intrinsic
211  // 0 index
212  if (tsPtr)
213  {
214  tsIndex = iParent->getObject()->getArchive()->addTimeSampling(
215  *tsPtr);
216  }
217 
218  m_property = iParent->createScalarProperty( iName, mdata,
219  TRAITS::dataType(), tsIndex );
220 
222  }
223 
224 };
225 
226 //-*****************************************************************************
227 //-*****************************************************************************
228 //-*****************************************************************************
229 
244 
249 
254 
259 
264 
269 
274 
279 
282 
286 
290 
293 
296 
297 } // End namespace ALEMBIC_VERSION_NS
298 
299 using namespace ALEMBIC_VERSION_NS;
300 
301 } // End namespace Abc
302 } // End namespace Alembic
303 
304 #endif
OTypedScalarProperty< Uint16TPTraits > OUInt16Property
OTypedScalarProperty< V2dTPTraits > OV2dProperty
OTypedScalarProperty< M33dTPTraits > OM33dProperty
OTypedScalarProperty< Box2sTPTraits > OBox2sProperty
OTypedScalarProperty< Uint8TPTraits > OUcharProperty
OTypedScalarProperty< N3fTPTraits > ON3fProperty
OTypedScalarProperty< P2sTPTraits > OP2sProperty
OTypedScalarProperty< P3sTPTraits > OP3sProperty
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
OTypedScalarProperty< QuatdTPTraits > OQuatdProperty
OTypedScalarProperty< V3dTPTraits > OV3dProperty
OTypedScalarProperty< Float32TPTraits > OFloatProperty
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
OTypedScalarProperty< Int32TPTraits > OInt32Property
void setInto(Arguments &iArgs) const
Definition: Argument.h:149
OTypedScalarProperty< Box3dTPTraits > OBox3dProperty
OTypedScalarProperty< P3iTPTraits > OP3iProperty
OTypedScalarProperty< QuatfTPTraits > OQuatfProperty
OTypedScalarProperty< P2fTPTraits > OP2fProperty
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: Argument.h:89
uint64 value_type
Definition: GA_PrimCompat.h:29
OTypedScalarProperty< N2dTPTraits > ON2dProperty
OTypedScalarProperty< Int8TPTraits > OCharProperty
OTypedScalarProperty< WstringTPTraits > OWstringProperty
OTypedScalarProperty< C4hTPTraits > OC4hProperty
OTypedScalarProperty< BooleanTPTraits > OBoolProperty
OTypedScalarProperty(OCompoundProperty iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
OTypedScalarProperty< N2fTPTraits > ON2fProperty
OTypedScalarProperty< M33fTPTraits > OM33fProperty
OTypedScalarProperty< Box2dTPTraits > OBox2dProperty
OTypedScalarProperty< C3hTPTraits > OC3hProperty
OTypedScalarProperty< V3sTPTraits > OV3sProperty
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
OTypedScalarProperty< P3fTPTraits > OP3fProperty
OTypedScalarProperty< StringTPTraits > OStringProperty
OTypedScalarProperty(AbcA::ScalarPropertyWriterPtr iProp, WrapExistingFlag iWrapFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
OTypedScalarProperty< P2iTPTraits > OP2iProperty
OTypedScalarProperty< Box2fTPTraits > OBox2fProperty
OTypedScalarProperty< Float16TPTraits > OHalfProperty
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:83
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
OTypedScalarProperty< P3dTPTraits > OP3dProperty
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:242
OTypedScalarProperty< C4cTPTraits > OC4cProperty
OTypedScalarProperty< V3iTPTraits > OV3iProperty
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:318
OTypedScalarProperty< Box3fTPTraits > OBox3fProperty
Alembic::Util::shared_ptr< ScalarPropertyWriter > ScalarPropertyWriterPtr
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
OTypedScalarProperty< C3fTPTraits > OC3fProperty
OTypedScalarProperty< V2sTPTraits > OV2sProperty
OTypedScalarProperty(AbcA::CompoundPropertyWriterPtr iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
OTypedScalarProperty< N3dTPTraits > ON3dProperty
OTypedScalarProperty< Int64TPTraits > OInt64Property
OTypedScalarProperty< Float64TPTraits > ODoubleProperty
ErrorHandler & getErrorHandler() const
Definition: Base.h:76
OTypedScalarProperty< M44dTPTraits > OM44dProperty
OTypedScalarProperty< Box3sTPTraits > OBox3sProperty
OTypedScalarProperty< V3fTPTraits > OV3fProperty
void set(const std::string &iKey, const std::string &iData)
Definition: MetaData.h:168
OTypedScalarProperty< M44fTPTraits > OM44fProperty
OTypedScalarProperty< C4fTPTraits > OC4fProperty
OTypedScalarProperty< Int16TPTraits > OInt16Property
OTypedScalarProperty< Uint64TPTraits > OUInt64Property
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
**If you just want to fire and args
Definition: thread.h:609
OTypedScalarProperty< V2fTPTraits > OV2fProperty
OTypedScalarProperty< Box2iTPTraits > OBox2iProperty
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:86
OTypedScalarProperty< C3cTPTraits > OC3cProperty
OTypedScalarProperty< P2dTPTraits > OP2dProperty
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
HUSD_API const char * dataType()
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
OTypedScalarProperty< Box3iTPTraits > OBox3iProperty
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88
OTypedScalarProperty< Uint32TPTraits > OUInt32Property
OTypedScalarProperty< V2iTPTraits > OV2iProperty
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr
OTypedScalarProperty(AbcA::ScalarPropertyWriterPtr iProp, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())