HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ITypedScalarProperty.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_ITypedScalarProperty_h
37 #define Alembic_Abc_ITypedScalarProperty_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  // TYPEDEFS AND IDENTIFIERS
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  if ( iMatching == kStrictMatching )
73  {
74  return ( iMetaData.get( "interpretation" ) ==
76  }
77  return true;
78  }
79 
80  //! This will check whether or not a given object (as represented by
81  //! an object header) strictly matches the interpretation of this
82  //! schema object
83  static bool matches( const AbcA::PropertyHeader &iHeader,
85  {
86  return (
87  iHeader.getDataType().getPod() == TRAITS::dataType().getPod() &&
88  iHeader.getDataType().getExtent() ==
89  TRAITS::dataType().getExtent() &&
90  iHeader.isScalar() &&
91  matches( iHeader.getMetaData(), iMatching ) );
92  }
93 
94  //-*************************************************************************
95  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
96  //-*************************************************************************
97 
98  //! Default constructor
99  //! ...
101 
102  //! This constructor creates a new typed scalar property reader.
103  //! The first argument is the ICompoundProperty parent, from which the
104  //! error handler policy for inheritance is also derived. The remaining
105  //! optional arguments can be used to override the ErrorHandlerPolicy,
106  //! to specify schema matching policy, and that's it.
108  const std::string &iName,
109 
110  const Argument &iArg0 = Argument(),
111  const Argument &iArg1 = Argument() )
112  {
113  Arguments args( GetErrorHandlerPolicy( iParent ) );
114  iArg0.setInto( args );
115  iArg1.setInto( args );
116 
118 
120  "ITypedScalarProperty::ITypedScalarProperty()" );
121 
122  AbcA::CompoundPropertyReaderPtr parent = iParent.getPtr();
123 
124  ABCA_ASSERT( parent != NULL,
125  "NULL CompoundPropertyReader passed into "
126  << "ITypedScalarProperty ctor" );
127 
128  const AbcA::PropertyHeader *pheader =
129  parent->getPropertyHeader( iName );
130  ABCA_ASSERT( pheader != NULL,
131  "Nonexistent scalar property: " << iName );
132 
133  ABCA_ASSERT( matches( *pheader, args.getSchemaInterpMatching() ),
134  "Incorrect match of header datatype: "
135  << pheader->getDataType()
136  << " to expected: "
137  << TRAITS::dataType()
138  << ",\n...or incorrect match of interpretation: "
139  << pheader->getMetaData().get( "interpretation" )
140  << " to expected: "
141  << TRAITS::interpretation() );
142 
143  m_property = parent->getScalarProperty( iName );
144 
146  }
147 
148 
149  //! Explicitly wrap an existing property
150  //! It will check the data type and also verify the schema,
151  //! if requested.
153  const Argument &iArg0 = Argument(),
154  const Argument &iArg1 = Argument() )
155  {
156 
158  "ITypedScalarProperty::ITypedScalarProperty()" );
159 
160  const AbcA::PropertyHeader &pheader = iProperty->getHeader();
161 
162  ABCA_ASSERT( matches( pheader,
163  GetSchemaInterpMatching( iArg0, iArg1 ) ),
164  "Incorrect match of header datatype: "
165  << pheader.getDataType()
166  << " to expected: "
167  << TRAITS::dataType()
168  << ",\n...or incorrect match of interpretation: "
169  << pheader.getMetaData().get( "interpretation" )
170  << " to expected: "
171  << TRAITS::interpretation() );
172 
173  m_property = iProperty;
174 
176  }
177 
178 
179  //! Deprecated in favor of the constructor above
181  WrapExistingFlag iWrapFlag,
182  const Argument &iArg0 = Argument(),
183  const Argument &iArg1 = Argument() )
184  {
185  *this = ITypedScalarProperty( iProp, iArg0, iArg1 );
186  }
187 
188  //-*************************************************************************
189  // SCALAR PROPERTY FEATURES
190  //-*************************************************************************
191 
192  //! Get the typed sample.
193  //! ...
194  void get( value_type &iVal,
195  const ISampleSelector &iSS = ISampleSelector() ) const
196  {
197  IScalarProperty::get( reinterpret_cast<void*>( &iVal ), iSS );
198  }
199 
200  //! Return the typed sample by value.
201  //! ...
203  {
204  value_type ret;
205  get( ret, iSS );
206  return ret;
207  }
208 };
209 
210 //-*****************************************************************************
211 //-*****************************************************************************
212 //-*****************************************************************************
213 
228 
233 
238 
243 
248 
253 
258 
263 
266 
270 
274 
277 
280 
281 } // End namespace ALEMBIC_VERSION_NS
282 
283 using namespace ALEMBIC_VERSION_NS;
284 
285 } // End namespace Abc
286 } // End namespace Alembic
287 
288 #endif
ITypedScalarProperty< Float32TPTraits > IFloatProperty
value_type getValue(const ISampleSelector &iSS=ISampleSelector()) const
ITypedScalarProperty< Box3iTPTraits > IBox3iProperty
ITypedScalarProperty< P2dTPTraits > IP2dProperty
ITypedScalarProperty< C3cTPTraits > IC3cProperty
ITypedScalarProperty< Uint64TPTraits > IUInt64Property
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
SchemaInterpMatching getSchemaInterpMatching() const
Definition: Argument.h:95
ITypedScalarProperty< P3sTPTraits > IP3sProperty
ITypedScalarProperty< N2fTPTraits > IN2fProperty
ITypedScalarProperty< Box2sTPTraits > IBox2sProperty
ITypedScalarProperty< P3dTPTraits > IP3dProperty
ITypedScalarProperty< QuatfTPTraits > IQuatfProperty
ITypedScalarProperty< QuatdTPTraits > IQuatdProperty
ITypedScalarProperty< N3fTPTraits > IN3fProperty
ITypedScalarProperty< V3iTPTraits > IV3iProperty
ITypedScalarProperty< Box3sTPTraits > IBox3sProperty
uint64 value_type
Definition: GA_PrimCompat.h:29
ITypedScalarProperty< V3fTPTraits > IV3fProperty
ITypedScalarProperty< Box2iTPTraits > IBox2iProperty
ITypedScalarProperty< P2fTPTraits > IP2fProperty
ITypedScalarProperty< V2dTPTraits > IV2dProperty
ITypedScalarProperty(AbcA::ScalarPropertyReaderPtr iProp, WrapExistingFlag iWrapFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Deprecated in favor of the constructor above.
ITypedScalarProperty< C3hTPTraits > IC3hProperty
ITypedScalarProperty< V2fTPTraits > IV2fProperty
ITypedScalarProperty< V2iTPTraits > IV2iProperty
ITypedScalarProperty< M33dTPTraits > IM33dProperty
ITypedScalarProperty< Int16TPTraits > IInt16Property
ITypedScalarProperty< M44dTPTraits > IM44dProperty
ITypedScalarProperty< Box3fTPTraits > IBox3fProperty
ITypedScalarProperty< Box2fTPTraits > IBox2fProperty
ITypedScalarProperty< P2iTPTraits > IP2iProperty
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
ITypedScalarProperty< Float64TPTraits > IDoubleProperty
ITypedScalarProperty< Uint8TPTraits > IUcharProperty
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:83
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
ITypedScalarProperty< StringTPTraits > IStringProperty
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:242
ITypedScalarProperty< N3dTPTraits > IN3dProperty
ITypedScalarProperty< C4fTPTraits > IC4fProperty
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:318
ITypedScalarProperty< N2dTPTraits > IN2dProperty
ITypedScalarProperty< P3iTPTraits > IP3iProperty
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
ErrorHandler & getErrorHandler() const
Definition: Base.h:76
ITypedScalarProperty< Uint32TPTraits > IUInt32Property
ITypedScalarProperty< Int8TPTraits > ICharProperty
ITypedScalarProperty< V3dTPTraits > IV3dProperty
ITypedScalarProperty< Int64TPTraits > IInt64Property
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
ITypedScalarProperty(const ICompoundProperty &iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
ITypedScalarProperty< WstringTPTraits > IWstringProperty
ITypedScalarProperty< M33fTPTraits > IM33fProperty
ITypedScalarProperty< Int32TPTraits > IInt32Property
ITypedScalarProperty< C4hTPTraits > IC4hProperty
ITypedScalarProperty< Uint16TPTraits > IUInt16Property
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
**If you just want to fire and args
Definition: thread.h:609
ITypedScalarProperty< Box2dTPTraits > IBox2dProperty
void get(void *oSample, const ISampleSelector &iSS=ISampleSelector()) const
ITypedScalarProperty< P2sTPTraits > IP2sProperty
ITypedScalarProperty< C4cTPTraits > IC4cProperty
ITypedScalarProperty< V3sTPTraits > IV3sProperty
ITypedScalarProperty< M44fTPTraits > IM44fProperty
ITypedScalarProperty< C3fTPTraits > IC3fProperty
ITypedScalarProperty(AbcA::ScalarPropertyReaderPtr iProperty, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
ITypedScalarProperty< BooleanTPTraits > IBoolProperty
ITypedScalarProperty< V2sTPTraits > IV2sProperty
Alembic::Util::shared_ptr< ScalarPropertyReader > ScalarPropertyReaderPtr
ITypedScalarProperty< P3fTPTraits > IP3fProperty
ITypedScalarProperty< Box3dTPTraits > IBox3dProperty
HUSD_API const char * dataType()
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88
ITypedScalarProperty< Float16TPTraits > IHalfProperty