OSchemaObject.h
Go to the documentation of this file.
//-*****************************************************************************
//
// Copyright (c) 2009-2012,
// Sony Pictures Imageworks Inc. and
// Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Sony Pictures Imageworks, nor
// Industrial Light & Magic, nor the names of their contributors may be used
// to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//-*****************************************************************************
#ifndef Alembic_Abc_OSchemaObject_h
#define Alembic_Abc_OSchemaObject_h
#include <Alembic/Abc/Foundation.h>
#include <Alembic/Abc/OObject.h>
#include <Alembic/Abc/OSchema.h>
namespace Alembic {
namespace Abc {
namespace ALEMBIC_VERSION_NS {
//-*****************************************************************************
template <class SCHEMA>
class OSchemaObject : public OObject
{
public:
//-*************************************************************************
// TYPEDEFS AND IDENTIFIERS
//-*************************************************************************
typedef SCHEMA schema_type;
typedef OSchemaObject<SCHEMA> this_type;
static std::string getSchemaObjTitle()
{
return SCHEMA::getSchemaTitle() + std::string( ":" ) +
SCHEMA::getDefaultSchemaName();
}
static const char * getSchemaTitle()
{
return SCHEMA::getSchemaTitle();
}
static bool matches( const AbcA::MetaData &iMetaData,
SchemaInterpMatching iMatching = kStrictMatching )
{
if ( std::string() == getSchemaTitle() || iMatching == kNoMatching )
{ return true; }
if ( iMatching == kStrictMatching )
{
return iMetaData.get( "schemaObjTitle" ) == getSchemaObjTitle();
}
if ( iMatching == kSchemaTitleMatching )
{
return iMetaData.get( "schema" ) == getSchemaTitle();
}
return false;
}
static bool matches( const AbcA::ObjectHeader &iHeader,
SchemaInterpMatching iMatching = kStrictMatching )
{
return matches( iHeader.getMetaData(), iMatching );
}
//-*************************************************************************
// CONSTRUCTION, DESTRUCTION, ASSIGNMENT
//-*************************************************************************
OSchemaObject() {}
OSchemaObject( OObject iParent,
const std::string &iName,
const Argument &iArg0 = Argument(),
const Argument &iArg1 = Argument(),
const Argument &iArg2 = Argument() );
//-*************************************************************************
// ABC BASE MECHANISMS
// These functions are used by Abc to deal with errors, validity,
// and so on.
//-*************************************************************************
SCHEMA &getSchema() { return m_schema; }
const SCHEMA &getSchema() const { return m_schema; }
void reset() { m_schema.reset(); OObject::reset(); }
bool valid() const
{
return ( OObject::valid() && m_schema.valid() );
}
ALEMBIC_OVERRIDE_OPERATOR_BOOL( this_type::valid() );
protected:
SCHEMA m_schema;
};
//-*****************************************************************************
// TEMPLATE AND INLINE FUNCTIONS
//-*****************************************************************************
//-*****************************************************************************
template <class SCHEMA>
OSchemaObject<SCHEMA>::OSchemaObject
(
OObject iParent,
const std::string &iName,
const Argument &iArg0,
const Argument &iArg1,
const Argument &iArg2 )
{
Arguments args( GetErrorHandlerPolicy( iParent ) );
iArg0.setInto( args );
iArg1.setInto( args );
iArg2.setInto( args );
getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
ALEMBIC_ABC_SAFE_CALL_BEGIN(
"OSchemaObject::OSchemaObject( OObject )" );
// Extract the parent.
AbcA::ObjectWriterPtr parent = iParent.getPtr();
ABCA_ASSERT( parent,
"NULL Parent ObjectWriter in OSchemaObject ctor" );
// The object schema title is derived from the schema's title.
// It is never empty (unless sparse)
AbcA::MetaData metaData = args.getMetaData();
SparseFlag sparseFlag = kSparse;
if ( !args.isSparse() )
{
sparseFlag = kFull;
metaData.set( "schema", SCHEMA::getSchemaTitle() );
metaData.set( "schemaObjTitle", getSchemaObjTitle() );
if ( std::string() != SCHEMA::getSchemaBaseType() )
{
metaData.set( "schemaBaseType", SCHEMA::getSchemaBaseType() );
}
}
// Make the object.
AbcA::ObjectHeader ohdr( iName, metaData );
m_object = parent->createChild( ohdr );
AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
uint32_t tsIndex = args.getTimeSamplingIndex();
// if we specified a valid TimeSamplingPtr, use it to determine the index
// otherwise we'll use the index, which defaults to the intrinsic 0 index
if (tsPtr)
{
tsIndex = parent->getArchive()->addTimeSampling(*tsPtr);
}
AbcA::MetaData schemaMetaData;
if ( args.isSparse() && SCHEMA::replaceOnSparse() )
{
schemaMetaData.set( "replace", "1" );
}
// Make the schema.
m_schema = SCHEMA( m_object->getProperties(),
SCHEMA::getDefaultSchemaName(),
this->getErrorHandlerPolicy(),
tsIndex,
schemaMetaData,
sparseFlag );
ALEMBIC_ABC_SAFE_CALL_END_RESET();
}
} // End namespace ALEMBIC_VERSION_NS
using namespace ALEMBIC_VERSION_NS;
} // End namespace Abc
} // End namespace Alembic
#endif
ABCA_ASSERT
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
Foundation.h
ALEMBIC_ABC_SAFE_CALL_BEGIN
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
ALEMBIC_ABC_SAFE_CALL_END_RESET
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
OObject.h
OSchema.h
ALEMBIC_VERSION_NS
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData
Definition: MetaData.h:60
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::get
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::set
void set(const std::string &iKey, const std::string &iData)
Definition: MetaData.h:168
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ObjectHeader
Definition: ObjectHeader.h:52
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ObjectHeader::getMetaData
const MetaData & getMetaData() const
Definition: ObjectHeader.h:93
Alembic::Abc::ALEMBIC_VERSION_NS::Argument
Definition: Argument.h:120
Alembic::Abc::ALEMBIC_VERSION_NS::Argument::setInto
void setInto(Arguments &iArgs) const
Definition: Argument.h:149
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments
Definition: Argument.h:49
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments::getMetaData
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:86
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments::isSparse
bool isSparse() const
Definition: Argument.h:98
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments::getTimeSamplingIndex
uint32_t getTimeSamplingIndex() const
Definition: Argument.h:92
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments::getErrorHandlerPolicy
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:83
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments::getTimeSampling
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: Argument.h:89
Alembic::Abc::ALEMBIC_VERSION_NS::OObject
Definition: OObject.h:54
Alembic::Abc::ALEMBIC_VERSION_NS::OObject::getPtr
AbcA::ObjectWriterPtr getPtr()
Definition: OObject.h:220
Alembic::Abc::ALEMBIC_VERSION_NS::OObject::reset
void reset()
Definition: OObject.h:225
Alembic::Abc::ALEMBIC_VERSION_NS::OObject::valid
bool valid() const
Definition: OObject.h:229
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject
Definition: OSchemaObject.h:54
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::this_type
OSchemaObject< SCHEMA > this_type
Definition: OSchemaObject.h:60
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::reset
void reset()
Definition: OSchemaObject.h:143
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::OSchemaObject
OSchemaObject()
Definition: OSchemaObject.h:118
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::getSchema
const SCHEMA & getSchema() const
Definition: OSchemaObject.h:139
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::getSchemaObjTitle
static std::string getSchemaObjTitle()
Definition: OSchemaObject.h:68
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::matches
static bool matches(const AbcA::ObjectHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition: OSchemaObject.h:105
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::m_schema
SCHEMA m_schema
Definition: OSchemaObject.h:157
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::ALEMBIC_OVERRIDE_OPERATOR_BOOL
ALEMBIC_OVERRIDE_OPERATOR_BOOL(this_type::valid())
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::valid
bool valid() const
Definition: OSchemaObject.h:147
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::matches
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition: OSchemaObject.h:82
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::getSchema
SCHEMA & getSchema()
Definition: OSchemaObject.h:138
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::getSchemaTitle
static const char * getSchemaTitle()
Definition: OSchemaObject.h:74
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::schema_type
SCHEMA schema_type
Definition: OSchemaObject.h:59
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ObjectWriterPtr
Alembic::Util::shared_ptr< ObjectWriter > ObjectWriterPtr
Definition: ForwardDeclarations.h:82
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::TimeSamplingPtr
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
Alembic::Abc::ALEMBIC_VERSION_NS
Definition: ArchiveInfo.h:48
Alembic::Abc::ALEMBIC_VERSION_NS::GetErrorHandlerPolicy
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:242
Alembic::Abc::ALEMBIC_VERSION_NS::SchemaInterpMatching
SchemaInterpMatching
Definition: Foundation.h:77
Alembic::Abc::ALEMBIC_VERSION_NS::kSchemaTitleMatching
@ kSchemaTitleMatching
Definition: Foundation.h:80
Alembic::Abc::ALEMBIC_VERSION_NS::kNoMatching
@ kNoMatching
Definition: Foundation.h:79
Alembic::Abc::ALEMBIC_VERSION_NS::kStrictMatching
@ kStrictMatching
Definition: Foundation.h:78
Alembic::Abc::ALEMBIC_VERSION_NS::SparseFlag
SparseFlag
Definition: Foundation.h:113
Alembic::Abc::ALEMBIC_VERSION_NS::kSparse
@ kSparse
Definition: Foundation.h:115
Alembic::Abc::ALEMBIC_VERSION_NS::kFull
@ kFull
Definition: Foundation.h:114
Alembic
Alembic namespace ...
Definition: ArchiveInfo.h:46