Gorgon Game Engine
Folder Class Reference

This is basic folder resource, it contains other resources. More...

Inheritance diagram for Folder:
[legend]

Public Member Functions

 Folder ()
 Default constructor. More...
 
 Folder (File &file)
 Constructs a folder over a specific file, it does not add the folder to the tree of the file though. More...
 
 Folder (std::weak_ptr< File > file)
 
virtual ~Folder ()
 Destructor. More...
 
virtual GID::Type GetGID () const override
 01010000h, (System, Folder) More...
 
bool IsLoaded () const
 Returns whether this resource is loaded. More...
 
bool Load (bool shallow=false)
 Loads this resource if it is not loaded yet. More...
 
virtual void Prepare () override
 Prepares children to be used. More...
 
- Public Member Functions inherited from Base
 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 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 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...
 

Static Public Member Functions

static FolderLoadResource (std::weak_ptr< File > file, std::shared_ptr< Reader > data, unsigned long size)
 

Protected Member Functions

bool load (std::shared_ptr< Reader > data, unsigned long size, bool first, bool shallow, bool load)
 This is the actual load function. More...
 
void save (Writer &writer) const override
 
- Protected Member Functions inherited from Base
virtual ~Base ()
 Destructor, Always children gets destroyed first. More...
 
void destroychildren ()
 Destroys the children of this resource. More...
 
void setparenttonullptr (Base &base)
 Sets the parent of an object to nullptr, provides access. More...
 

Protected Attributes

unsigned long entrypoint
 Entry point of this resource within the physical file. More...
 
std::weak_ptr< Filefile
 The file object that is used to load this folder. More...
 
bool fullyloaded
 Whether the contents of this folder is fully loaded. More...
 
std::map< std::string, Base * > namedlist
 A map to bind items to their names. More...
 
std::shared_ptr< Readerreader
 This is the reader used to read this folder. Might be empty if the folder is loaded completely. More...
 
bool reallyloadnames
 Names will only be loaded if the variable is set. More...
 
- Protected Attributes inherited from Base
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...
 

Collection related

These functions allows modification of folder's children

void Add (Base &resource)
 Adds a the given resource to this folder. More...
 
void Add (Base *resource)
 Adds a the given resource to this folder. More...
 
void Insert (Base &resource, long before)
 Inserts a the given resource to this folder before the given index. More...
 
void Insert (Base *resource, long before)
 Inserts a the given resource to this folder before the given index. More...
 
void MoveBefore (long index, long before)
 Moves the given item to the given position. More...
 
void MoveBefore (Base &item, long before)
 Moves the given item to the given position. More...
 
void Remove (Base &resource)
 Removes the given item. More...
 
void Delete (Base &resource)
 Deletes the given item properly, minding any links. More...
 
int GetCount () const
 Returns the number of items contained. More...
 
BaseGetItem (int Index) const
 Returns an item with the given index. More...
 
BaseGetItemPtr (int Index) const
 Returns an item with the given index. More...
 
Baseoperator[] (int Index) const
 Returns an item with the given index. More...
 
bool Exists (int index) const
 Checks whether an item in the given index is present. More...
 
bool Exists (const std::string &name) const
 Checks whether an item with the given name is present. More...
 

Typecasting access

These functions allow access to children by casting them to the requested type

template<typename T_ >
T_ & Get (int index) const
 Returns the item at the given index performing dynamic_cast to the given type. More...
 
template<typename T_ >
T_ & Get (const std::string &name) const
 Returns the item at the given index performing dynamic_cast to the given type. More...
 
template<typename T_ >
T_ * GetPtr (int index)
 Returns the item at the given index performing dynamic_cast to the given type. More...
 
template<typename T_ >
T_ * GetPtr (const std::string &name) const
 Returns the item at the given index performing dynamic_cast to the given type. More...
 

Additional Inherited Members

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

Detailed Description

This is basic folder resource, it contains other resources.

Constructor & Destructor Documentation

◆ Folder() [1/3]

Folder ( )

Default constructor.

◆ Folder() [2/3]

Folder ( File file)

Constructs a folder over a specific file, it does not add the folder to the tree of the file though.

◆ Folder() [3/3]

Folder ( std::weak_ptr< File file)

References Folder::file.

◆ ~Folder()

virtual ~Folder ( )
virtual

Destructor.

Member Function Documentation

◆ Add() [1/2]

void Add ( Base resource)

Adds a the given resource to this folder.

References Base::children.

◆ Add() [2/2]

void Add ( Base resource)

Adds a the given resource to this folder.

References Base::children.

◆ Delete()

void Delete ( Base resource)

Deletes the given item properly, minding any links.

References Base::children, Base::DeleteResource(), Base::GetParentPtr(), and Base::setparenttonullptr().

◆ Exists() [1/2]

bool Exists ( const std::string &  name) const

Checks whether an item with the given name is present.

References Base::name, and Folder::namedlist.

◆ Exists() [2/2]

bool Exists ( int  index) const

Checks whether an item in the given index is present.

References Base::children.

◆ Get() [1/2]

T_& Get ( const std::string &  name) const

Returns the item at the given index performing dynamic_cast to the given type.

This function propagates bad_cast exception from dynamic_cast, does not perform range check

Exceptions
std::runtime_errorif the given name is not found

References Base::name, and Folder::namedlist.

◆ Get() [2/2]

T_& Get ( int  index) const

Returns the item at the given index performing dynamic_cast to the given type.

This function propagates bad_cast exception from dynamic_cast, does not perform range check

References Base::children.

◆ GetCount()

int GetCount ( ) const

Returns the number of items contained.

References Base::children.

◆ GetGID()

virtual GID::Type GetGID ( ) const
overridevirtual

01010000h, (System, Folder)

Implements Base.

References Gorgon::Resource::GID::Folder.

◆ GetItem()

Base& GetItem ( int  Index) const

Returns an item with the given index.

References Base::children.

◆ GetItemPtr()

Base& GetItemPtr ( int  Index) const

Returns an item with the given index.

References Base::children.

◆ GetPtr() [1/2]

T_* GetPtr ( const std::string &  name) const

Returns the item at the given index performing dynamic_cast to the given type.

This function returns nullptr if object cannot be casted to the given type.

Exceptions
std::runtime_errorif the given name is not found

References Base::name, and Folder::namedlist.

◆ GetPtr() [2/2]

T_* GetPtr ( int  index)

Returns the item at the given index performing dynamic_cast to the given type.

This function returns nullptr if object cannot be casted to the given type.

References Base::children.

◆ Insert() [1/2]

void Insert ( Base resource,
long  before 
)

Inserts a the given resource to this folder before the given index.

References Base::children.

◆ Insert() [2/2]

void Insert ( Base resource,
long  before 
)

Inserts a the given resource to this folder before the given index.

References Base::children.

◆ IsLoaded()

bool IsLoaded ( ) const

Returns whether this resource is loaded.

References Folder::fullyloaded.

◆ Load()

bool Load ( bool  shallow = false)

Loads this resource if it is not loaded yet.

Parameters
shallowonly loads immediate children of this resource

References Base::begin(), Folder::entrypoint, Folder::file, Folder::fullyloaded, Folder::load(), Folder::reader, and Base::Resolve().

◆ load()

bool load ( std::shared_ptr< Reader data,
unsigned long  size,
bool  first,
bool  shallow,
bool  load 
)
protected

◆ LoadResource()

Folder * LoadResource ( std::weak_ptr< File file,
std::shared_ptr< Reader data,
unsigned long  size 
)
static

References Folder::Folder(), and Folder::file.

◆ MoveBefore() [1/2]

void MoveBefore ( Base item,
long  before 
)

Moves the given item to the given position.

It is possible to specify GetCount() as before to move the item to the end.

References Base::children.

◆ MoveBefore() [2/2]

void MoveBefore ( long  index,
long  before 
)

Moves the given item to the given position.

It is possible to specify GetCount() as before to move the item to the end.

References Base::children.

◆ operator[]()

Base& operator[] ( int  Index) const

Returns an item with the given index.

References Base::children.

◆ Prepare()

void Prepare ( )
overridevirtual

Prepares children to be used.

Reimplemented from Base.

References Base::children, Folder::namedlist, Base::Prepare(), and Folder::reallyloadnames.

◆ Remove()

void Remove ( Base resource)

Removes the given item.

References Base::children.

◆ save()

Member Data Documentation

◆ entrypoint

unsigned long entrypoint
protected

Entry point of this resource within the physical file.

This value is stored for late loading purposes

◆ file

std::weak_ptr<File> file
protected

The file object that is used to load this folder.

If this folder is partially loaded this file would be used to load its contents

◆ fullyloaded

bool fullyloaded
protected

Whether the contents of this folder is fully loaded.

◆ namedlist

std::map<std::string, Base*> namedlist
protected

A map to bind items to their names.

◆ reader

std::shared_ptr<Reader> reader
protected

This is the reader used to read this folder. Might be empty if the folder is loaded completely.

◆ reallyloadnames

bool reallyloadnames
protected

Names will only be loaded if the variable is set.


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