Cortex  10.0.0-a4
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
IECore::Object Class Referenceabstract

#include <Object.h>

+ Inheritance diagram for IECore::Object:

Classes

class  AbstractTypeDescription
 
class  CopyContext
 
class  LoadContext
 The class provided to the load() method implemented by subclasses. More...
 
class  MemoryAccumulator
 
class  SaveContext
 The class provided to the save() method implemented by subclasses. More...
 
class  TypeDescription
 

Public Types

typedef ObjectPtr(* CreatorFn) (void *data)
 
- Public Types inherited from IECore::RunTimeTyped
typedef RefCounted BaseClass
 A typedef for the class this class derives from. All RunTimeTyped classes define this typedef.
 
- Public Types inherited from IECore::RefCounted
typedef size_t RefCount
 

Public Member Functions

 IE_CORE_DECLARERUNTIMETYPED (Object, RunTimeTyped)
 
Object interface

The following functions define the interface to which all Object subclasses must adhere. Note that the IE_CORE_DECLAREOBJECT macro is provided to simplify the declaration of these functions for your own derived classes. Note also that there is additional protected interface which you must implement - this too is declared (but not implemented) by the IE_CORE_DECLAREOBJECT macro.

ObjectPtr copy () const
 
void copyFrom (const Object *other)
 
void save (IndexedIOPtr ioInterface, const IndexedIO::EntryID &name) const
 
virtual bool isEqualTo (const Object *other) const =0
 
virtual bool isNotEqualTo (const Object *other) const
 
bool operator== (const Object &other) const
 Calls isEqualTo() for people who prefer to use the operator syntax.
 
bool operator!= (const Object &other) const
 Calls isNotEqualTo() for people who prefer to use the operator syntax.
 
size_t memoryUsage () const
 Returns the number of bytes this instance occupies in memory.
 
MurmurHash hash () const
 
virtual void hash (MurmurHash &h) const =0
 
- Public Member Functions inherited from IECore::RunTimeTyped
 IE_CORE_DECLAREMEMBERPTR (RunTimeTyped)
 
virtual TypeId typeId () const
 
virtual const char * typeName () const
 
virtual bool isInstanceOf (TypeId typeId) const
 
virtual bool isInstanceOf (const char *typeName) const
 
- Public Member Functions inherited from IECore::RefCounted
 IE_CORE_DECLAREMEMBERPTR (RefCounted)
 
void addRef () const
 Add a reference to the current object.
 
void removeRef () const
 Remove a reference from the current object.
 
RefCount refCount () const
 Returns the current reference count.
 

Static Public Member Functions

static void registerType (TypeId typeId, const std::string &typeName, CreatorFn creator, void *data=nullptr)
 Register a new Object-derived type with the system. The specified void* data is passed into the creator function.
 
Object factory

The following static functions provide the ability to create an Object of a given type or typeId, as well as providing conversions between type names and TypeIds.

static bool isType (TypeId typeId)
 Returns true if typeId is a valid registered Object type.
 
static bool isType (const std::string &typeName)
 Returns true if typeName is a valid registered Object type.
 
static bool isAbstractType (TypeId typeId)
 
static bool isAbstractType (const std::string &typeName)
 As above but taking a type name.
 
static ObjectPtr create (TypeId typeId)
 
static ObjectPtr create (const std::string &typeName)
 
static ObjectPtr load (ConstIndexedIOPtr ioInterface, const IndexedIO::EntryID &name)
 
- Static Public Member Functions inherited from IECore::RunTimeTyped
static TypeId staticTypeId ()
 Returns the TypeId for this class, without needing an instance.
 
static const char * staticTypeName ()
 Returns the type name for this class, without needing an instance.
 
static TypeId baseTypeId ()
 
static const char * baseTypeName ()
 
static bool inheritsFrom (TypeId typeId)
 Returns true if this class inherits from the specified type.
 
static bool inheritsFrom (const char *typeName)
 Returns true if this class inherits from the specified type.
 
static bool inheritsFrom (TypeId type, TypeId baseType)
 Returns true if type inherits from baseType.
 
static bool inheritsFrom (const char *typeName, const char *baseTypeName)
 Returns true if typeName inherits from baseTypeName.
 
static TypeId baseTypeId (TypeId typeId)
 Returns the base type of the given type, or InvalidTypeId if no such base exists.
 
static const std::vector< TypeId > & baseTypeIds (TypeId typeId)
 
static const std::set< TypeId > & derivedTypeIds (TypeId typeId)
 
static TypeId typeIdFromTypeName (const char *typeName)
 
static const char * typeNameFromTypeId (TypeId typeId)
 
static void registerType (TypeId derivedTypeId, const char *derivedTypeName, TypeId baseTypeId)
 Allows external modules to register their own type ids.
 

Protected Member Functions

virtual void copyFrom (const Object *other, CopyContext *context)=0
 
 IE_CORE_DECLAREPTR (LoadContext)
 
virtual void save (SaveContext *context) const =0
 
virtual void load (LoadContextPtr context)=0
 
virtual void memoryUsage (MemoryAccumulator &accumulator) const =0
 

Additional Inherited Members

- Protected Types inherited from IECore::RunTimeTyped
typedef std::map< TypeId, TypeIdBaseTypeRegistryMap
 
typedef std::map< TypeId, std::vector< TypeId > > BaseTypesRegistryMap
 
typedef std::map< TypeId, std::set< TypeId > > DerivedTypesRegistryMap
 
typedef tbb::spin_rw_mutex Mutex
 
typedef std::map< TypeId, std::string > TypeIdsToTypeNamesMap
 
typedef std::map< std::string, TypeIdTypeNamesToTypeIdsMap
 
- Static Protected Member Functions inherited from IECore::RunTimeTyped
static BaseTypeRegistryMap & baseTypeRegistry ()
 
static DerivedTypesRegistryMap & derivedTypesRegistry ()
 
static BaseTypesRegistryMap & completeBaseTypesRegistry ()
 
static DerivedTypesRegistryMap & completeDerivedTypesRegistry ()
 
static void derivedTypeIdsWalk (TypeId typeId, std::set< TypeId > &)
 
static TypeIdsToTypeNamesMap & typeIdsToTypeNames ()
 
static TypeNamesToTypeIdsMap & typeNamesToTypeIds ()
 
- Static Protected Attributes inherited from IECore::RunTimeTyped
static Mutex g_baseTypeIdsMutex
 
static Mutex g_derivedTypeIdsMutex
 

Detailed Description

A base class defining copying and streaming.

Todo:
rename virtual functions that match non-virtual functions so that pointers to derived classes still provide access the non-virtual ones: example hash(), memoryUsage(), save().

Member Function Documentation

ObjectPtr IECore::Object::copy ( ) const

Returns a deep copy of this object. In subclasses an identical function is provided which returns a pointer to the subclass rather than to this base class.

void IECore::Object::copyFrom ( const Object other)

Copies from another object. Throws an IECore::InvalidArgumentException if other is not an instance of this object.

virtual void IECore::Object::copyFrom ( const Object other,
CopyContext context 
)
protectedpure virtual

Must be implemented in all subclasses to make a deep copy of all member data, after calling BaseClass::copyFrom() to allow the base class to do the same. When making copies of held member data derived from Object, you /must/ use the context object provided, rather than calling copy() or copyFrom() yourself.

Implemented in IECore::TypedData< T >, IECore::TypedData< std::vector< T > >, and IECore::GeometricTypedData< T >.

static ObjectPtr IECore::Object::create ( TypeId  typeId)
static

Creates an instance of an object of the specified type. Throws an Exception if typeId is not a valid type.

static ObjectPtr IECore::Object::create ( const std::string &  typeName)
static

Creates an instance of an object of the specified type. Throws an Exception if typeName is not a valid type.

MurmurHash IECore::Object::hash ( ) const

Returns a hash computed from all the member data of this object. This convenience function simply creates a MurmurHash object, appends to it using the virtual function below and then returns it.

virtual void IECore::Object::hash ( MurmurHash h) const
pure virtual

Must be implemented by subclasses to append all member data into the given hash. Implementations must first call the base class implementation before appending their own data.

Implemented in IECore::GeometricTypedData< T >, IECore::TypedData< T >, and IECore::TypedData< std::vector< T > >.

static bool IECore::Object::isAbstractType ( TypeId  typeId)
static

Returns true if typeId is a valid registered abstract Object type - one which cannot be instantiated with create().

virtual bool IECore::Object::isEqualTo ( const Object other) const
pure virtual

Returns true if this object is equal to the other. Should be reimplemented appropriately in derived classes, first calling your base class isEqualTo() and returning false straight away if that returns false. The Object level implementation checks that the types are identical, so you can safely perform a boost::static_pointer_cast<YourClass>( other ) if your base class isEqualTo() doesn't return false.

Implemented in IECore::GeometricTypedData< T >, IECore::TypedData< T >, and IECore::TypedData< std::vector< T > >.

virtual bool IECore::Object::isNotEqualTo ( const Object other) const
virtual

Returns true if this object is not equal to the other. A default implementation for this returns the negation of isEqualTo(), but you may wish to override it if you can provide a faster implementation for a specific subclass.

static ObjectPtr IECore::Object::load ( ConstIndexedIOPtr  ioInterface,
const IndexedIO::EntryID name 
)
static

Loads an object previously saved with the given name in the current directory of ioInterface.

Referenced by IECore.ParameterParser::registerTypeWithRepr().

virtual void IECore::Object::load ( LoadContextPtr  context)
protectedpure virtual

Must be implemented in all derived classes. Implementations should first call the parent class load() method, then call context->container() before loading their member data from that container. context is a smart pointer to a reference counted object to allow you to keep the context and perform lazy loading at a later date - although this is not yet used by any of the core types. A call to context->container() will throw an Exception if the corresponding save() method did not create a container.

Implemented in IECore::TypedData< T >, and IECore::TypedData< std::vector< T > >.

virtual void IECore::Object::memoryUsage ( MemoryAccumulator accumulator) const
protectedpure virtual

Must be implemented in all derived classes to specify the amount of memory they are using. An implementation must add it's memory usage to the accumulator before calling memoryUsage() on its base class.

Implemented in IECore::TypedData< T >, IECore::TypedData< std::vector< T > >, and IECore::GeometricTypedData< T >.

void IECore::Object::save ( IndexedIOPtr  ioInterface,
const IndexedIO::EntryID name 
) const

Saves the object in the current directory of ioInterface, in a subdirectory with the specified name.

virtual void IECore::Object::save ( SaveContext context) const
protectedpure virtual

Must be implemented in all derived classes. Implementations should first call the parent class save() method, then call context->container() before filling the returned container with their member data. Classes with no member data may omit the call to container(), resulting in smaller file sizes.

Implemented in IECore::TypedData< T >, IECore::TypedData< std::vector< T > >, and IECore::GeometricTypedData< T >.


The documentation for this class was generated from the following file: