Gorgon Game Engine
Base Class Referenceabstract

This class is the base for all Gorgon Resources. More...

Inheritance diagram for Base:
[legend]

Public Member Functions

 Base ()
 Default constructor. More...
 
const Containers::Collection< Base >::ConstIterator begin () const
 Allows easy iteration through range based fors. More...
 
const Containers::Collection< Base >::ConstIterator cbegin () const
 Beginning of children. More...
 
const Containers::Collection< Base >::ConstIterator cend () const
 End of children. More...
 
bool DeleteResource ()
 Safely deletes the resource. More...
 
virtual void Discard ()
 This function shall discard any transitional data which is not vital after Prepare function is issued. More...
 
const Containers::Collection< Base >::ConstIterator end () const
 Allows easy iteration through range based fors. More...
 
virtual GID::Type GetGID () const =0
 This function shall return Gorgon ID of this resource. More...
 
virtual SGuid GetGuid () const
 Returns the guid of the object. More...
 
const std::string & GetName () const
 Returns the name of this object. More...
 
BaseGetParent () const
 Returns the parent. If no parent set, this function throws std::runtime_error. More...
 
BaseGetParentPtr () const
 Returns the pointer to the parent. This function may return nullptr. More...
 
const BaseGetRoot () const
 Returns the root of this resource. More...
 
bool HasParent () const
 Returns whether this object has a parent. More...
 
virtual bool IsEqual (const SGuid &guid) const
 This function tests whether this object has the given SGuid. More...
 
virtual void Prepare ()
 This function shall prepare this resource to be used after resource is loaded. More...
 
virtual void Resolve (File &file)
 This function shall resolve links or similar constructs. More...
 
void Save (Writer &writer)
 Saves this object into the given writer. The writer should be open prior to this call. More...
 
virtual void SetGuid (SGuid guid)
 Changes the guid of the object. More...
 
virtual void SetName (const std::string &name)
 Sets the name of the object. More...
 

Public Attributes

const Containers::Collection< Base > & Children
 The children this object have. More...
 
unsigned long refcount
 INTERNAL, Reference count, used in linking mechanism. More...
 

Protected Member Functions

virtual ~Base ()
 Destructor, Always children gets destroyed first. More...
 
void destroychildren ()
 Destroys the children of this resource. More...
 
virtual void save (Writer &writer) const =0
 
void setparenttonullptr (Base &base)
 Sets the parent of an object to nullptr, provides access. More...
 

Protected Attributes

Containers::Collection< Basechildren
 Child objects that this resource object have. More...
 
SGuid guid
 SGuid to identify this resource object. More...
 
std::string name
 Name of this resource object, may not be loaded. More...
 
Baseparent
 Immediate parent of this resource. More...
 
const Baseroot
 Root of this resource. More...
 

Detailed Description

This class is the base for all Gorgon Resources.

Warning
This class is rather heavy and should not be used for small objects that are planned to be created a lot of.

Constructor & Destructor Documentation

◆ Base()

Base ( )

Default constructor.

◆ ~Base()

~Base ( )
protectedvirtual

Destructor, Always children gets destroyed first.

References Base::destroychildren().

Member Function Documentation

◆ begin()

const Containers::Collection<Base>::ConstIterator begin ( ) const

Allows easy iteration through range based fors.

References Base::Children.

◆ cbegin()

const Containers::Collection<Base>::ConstIterator cbegin ( ) const

Beginning of children.

References Base::Children.

◆ cend()

const Containers::Collection<Base>::ConstIterator cend ( ) const

End of children.

References Base::Children.

◆ DeleteResource()

bool DeleteResource ( )

Safely deletes the resource.

If the resource is being used more a single place, this method will not delete the resource, instead it will decrement the reference count and returns false.

References Base::refcount.

◆ destroychildren()

void destroychildren ( )
protected

Destroys the children of this resource.

References Base::children.

◆ Discard()

void Discard ( )
virtual

This function shall discard any transitional data which is not vital after Prepare function is issued.

This data can be image pixel buffer sound data buffer. Default behavior is to pass the request to children

Reimplemented in Image, and Font.

◆ end()

const Containers::Collection<Base>::ConstIterator end ( ) const

Allows easy iteration through range based fors.

References Base::Children.

◆ GetGID()

virtual GID::Type GetGID ( ) const
pure virtual

This function shall return Gorgon ID of this resource.

Implemented in TintedObject, StackedObject, Sound, ScalableObject, Rectangle, Pointer, Null, MaskedObject, Line, Image, Font, Folder, Data, Blob, and Animation.

◆ GetGuid()

virtual SGuid GetGuid ( ) const
virtual

Returns the guid of the object.

References Base::guid.

◆ GetName()

const std::string& GetName ( ) const

Returns the name of this object.

Warning
The object names are loaded only upon request

References Base::name.

◆ GetParent()

Base& GetParent ( ) const

Returns the parent. If no parent set, this function throws std::runtime_error.

References Base::parent.

◆ GetParentPtr()

Base* GetParentPtr ( ) const

Returns the pointer to the parent. This function may return nullptr.

References Base::parent.

◆ GetRoot()

const Base& GetRoot ( ) const

Returns the root of this resource.

Root of a resource is always exists, in case of no parent, the root is the object itself. Note that this value is cached and maintained. In rare cases, it will be recalculated.

References Base::parent, and Base::root.

◆ HasParent()

bool HasParent ( ) const

Returns whether this object has a parent.

References Base::parent.

◆ IsEqual()

virtual bool IsEqual ( const SGuid guid) const
virtual

This function tests whether this object has the given SGuid.

References Base::guid.

◆ Prepare()

void Prepare ( )
virtual

This function shall prepare this resource to be used after resource is loaded.

Default behavior is to pass the request to children

Reimplemented in Pointer, Image, Font, and Folder.

◆ Resolve()

void Resolve ( File file)
virtual

This function shall resolve links or similar constructs.

This function is intended to be called after a file is loaded. It has no meaning for in memory constructed resource trees. Default behavior is to pass the request to children.

References Base::children, and Base::Resolve().

◆ Save()

void Save ( Writer writer)

Saves this object into the given writer. The writer should be open prior to this call.

References ASSERT, Base::guid, SGuid::IsEmpty(), Writer::IsGood(), SGuid::New(), and Base::save().

◆ save()

virtual void save ( Writer writer) const
protectedpure virtual

◆ SetGuid()

virtual void SetGuid ( SGuid  guid)
virtual

Changes the guid of the object.

References Base::guid.

◆ SetName()

virtual void SetName ( const std::string &  name)
virtual

Sets the name of the object.

References Base::name.

◆ setparenttonullptr()

void setparenttonullptr ( Base base)
protected

Sets the parent of an object to nullptr, provides access.

References Base::parent, and Base::root.

Member Data Documentation

◆ Children

const Containers::Collection<Base>& Children

The children this object have.

The elements in const collections are modifiable, therefore, its possible to modify properties of the children. However, children should be added to the object using member methods as some objects do not allow children, or allow children that are of specific type.

◆ children

Containers::Collection<Base> children
protected

Child objects that this resource object have.

Some of child objects can be private, therefore, this is not guaranteed to be complete

◆ guid

SGuid guid
protected

SGuid to identify this resource object.

◆ name

std::string name
protected

Name of this resource object, may not be loaded.

◆ parent

Base* parent
protected

Immediate parent of this resource.

◆ refcount

unsigned long refcount

INTERNAL, Reference count, used in linking mechanism.

Warning
Never change or rely on this value unless you know the internal mechanics of linking system. Any uninformed changes may cause leaks or worse, double deletion and crash of the program.

◆ root

const Base* root
mutableprotected

Root of this resource.


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