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> 40 #include <Alembic/Abc/IScalarProperty.h> 41 #include <Alembic/Abc/TypedPropertyTraits.h> 42 43 namespace Alembic { 44 namespace Abc { 45 namespace ALEMBIC_VERSION_NS { 46 47 //-***************************************************************************** 48 template <class TRAITS> 49 class ITypedScalarProperty : public IScalarProperty 50 { 51 public: 52 //-************************************************************************* 53 // TYPEDEFS AND IDENTIFIERS 54 //-************************************************************************* 55 typedef TRAITS traits_type; 56 typedef ITypedScalarProperty<TRAITS> this_type; 57 typedef typename TRAITS::value_type value_type; 58 59 //! Return the interpretation expected of this 60 //! property. An empty interpretation matches everything getInterpretation()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, 70 SchemaInterpMatching iMatching = kStrictMatching ) 71 { 72 if ( iMatching == kStrictMatching ) 73 { 74 return ( iMetaData.get( "interpretation" ) == 75 getInterpretation() ); 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, 84 SchemaInterpMatching iMatching = kStrictMatching ) 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 //! ... ITypedScalarProperty()100 ITypedScalarProperty() {} 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. 107 ITypedScalarProperty( const ICompoundProperty & iParent, 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 117 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() ); 118 119 ALEMBIC_ABC_SAFE_CALL_BEGIN( 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 145 ALEMBIC_ABC_SAFE_CALL_END_RESET(); 146 } 147 148 149 //! Explicitly wrap an existing property 150 //! It will check the data type and also verify the schema, 151 //! if requested. 152 ITypedScalarProperty( AbcA::ScalarPropertyReaderPtr iProperty, 153 const Argument &iArg0 = Argument(), 154 const Argument &iArg1 = Argument() ) 155 { 156 157 ALEMBIC_ABC_SAFE_CALL_BEGIN( 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 175 ALEMBIC_ABC_SAFE_CALL_END_RESET(); 176 } 177 178 179 //! Deprecated in favor of the constructor above 180 ITypedScalarProperty( AbcA::ScalarPropertyReaderPtr iProp, 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 //! ... 202 value_type getValue( const ISampleSelector &iSS = ISampleSelector() ) const 203 { 204 value_type ret; 205 get( ret, iSS ); 206 return ret; 207 } 208 }; 209 210 //-***************************************************************************** 211 //-***************************************************************************** 212 //-***************************************************************************** 213 214 typedef ITypedScalarProperty<BooleanTPTraits> IBoolProperty; 215 typedef ITypedScalarProperty<Uint8TPTraits> IUcharProperty; 216 typedef ITypedScalarProperty<Int8TPTraits> ICharProperty; 217 typedef ITypedScalarProperty<Uint16TPTraits> IUInt16Property; 218 typedef ITypedScalarProperty<Int16TPTraits> IInt16Property; 219 typedef ITypedScalarProperty<Uint32TPTraits> IUInt32Property; 220 typedef ITypedScalarProperty<Int32TPTraits> IInt32Property; 221 typedef ITypedScalarProperty<Uint64TPTraits> IUInt64Property; 222 typedef ITypedScalarProperty<Int64TPTraits> IInt64Property; 223 typedef ITypedScalarProperty<Float16TPTraits> IHalfProperty; 224 typedef ITypedScalarProperty<Float32TPTraits> IFloatProperty; 225 typedef ITypedScalarProperty<Float64TPTraits> IDoubleProperty; 226 typedef ITypedScalarProperty<StringTPTraits> IStringProperty; 227 typedef ITypedScalarProperty<WstringTPTraits> IWstringProperty; 228 229 typedef ITypedScalarProperty<V2sTPTraits> IV2sProperty; 230 typedef ITypedScalarProperty<V2iTPTraits> IV2iProperty; 231 typedef ITypedScalarProperty<V2fTPTraits> IV2fProperty; 232 typedef ITypedScalarProperty<V2dTPTraits> IV2dProperty; 233 234 typedef ITypedScalarProperty<V3sTPTraits> IV3sProperty; 235 typedef ITypedScalarProperty<V3iTPTraits> IV3iProperty; 236 typedef ITypedScalarProperty<V3fTPTraits> IV3fProperty; 237 typedef ITypedScalarProperty<V3dTPTraits> IV3dProperty; 238 239 typedef ITypedScalarProperty<P2sTPTraits> IP2sProperty; 240 typedef ITypedScalarProperty<P2iTPTraits> IP2iProperty; 241 typedef ITypedScalarProperty<P2fTPTraits> IP2fProperty; 242 typedef ITypedScalarProperty<P2dTPTraits> IP2dProperty; 243 244 typedef ITypedScalarProperty<P3sTPTraits> IP3sProperty; 245 typedef ITypedScalarProperty<P3iTPTraits> IP3iProperty; 246 typedef ITypedScalarProperty<P3fTPTraits> IP3fProperty; 247 typedef ITypedScalarProperty<P3dTPTraits> IP3dProperty; 248 249 typedef ITypedScalarProperty<Box2sTPTraits> IBox2sProperty; 250 typedef ITypedScalarProperty<Box2iTPTraits> IBox2iProperty; 251 typedef ITypedScalarProperty<Box2fTPTraits> IBox2fProperty; 252 typedef ITypedScalarProperty<Box2dTPTraits> IBox2dProperty; 253 254 typedef ITypedScalarProperty<Box3sTPTraits> IBox3sProperty; 255 typedef ITypedScalarProperty<Box3iTPTraits> IBox3iProperty; 256 typedef ITypedScalarProperty<Box3fTPTraits> IBox3fProperty; 257 typedef ITypedScalarProperty<Box3dTPTraits> IBox3dProperty; 258 259 typedef ITypedScalarProperty<M33fTPTraits> IM33fProperty; 260 typedef ITypedScalarProperty<M33dTPTraits> IM33dProperty; 261 typedef ITypedScalarProperty<M44fTPTraits> IM44fProperty; 262 typedef ITypedScalarProperty<M44dTPTraits> IM44dProperty; 263 264 typedef ITypedScalarProperty<QuatfTPTraits> IQuatfProperty; 265 typedef ITypedScalarProperty<QuatdTPTraits> IQuatdProperty; 266 267 typedef ITypedScalarProperty<C3hTPTraits> IC3hProperty; 268 typedef ITypedScalarProperty<C3fTPTraits> IC3fProperty; 269 typedef ITypedScalarProperty<C3cTPTraits> IC3cProperty; 270 271 typedef ITypedScalarProperty<C4hTPTraits> IC4hProperty; 272 typedef ITypedScalarProperty<C4fTPTraits> IC4fProperty; 273 typedef ITypedScalarProperty<C4cTPTraits> IC4cProperty; 274 275 typedef ITypedScalarProperty<N2fTPTraits> IN2fProperty; 276 typedef ITypedScalarProperty<N2dTPTraits> IN2dProperty; 277 278 typedef ITypedScalarProperty<N3fTPTraits> IN3fProperty; 279 typedef ITypedScalarProperty<N3dTPTraits> IN3dProperty; 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 289