BlankMat 0.1.0
Free open-source 3D texture creation application
Loading...
Searching...
No Matches
IContainer< T > Class Template Referenceabstract

Container class for storing key value pairs. Should not be instantiated directly, but should be overridden by a class that implements additional functionality. (If not overriden, this class is functionally equivalent to an unordered map, just use that instead) More...

Inheritance diagram for IContainer< T >:
Collaboration diagram for IContainer< T >:

Public Member Functions

void Read (const std::string &scope, std::ifstream &file, bool clear) override
 Reads this container from the file.
 
void Write (std::ofstream &file) override
 Writes this container to the file.
 
void Clear () override
 Clears the container of all items, deleting them.
 
void ClearData ()
 Clears the data of the container without deleting it. Only use this if pointers to the data exist elsewhere.
 
unsigned int WriteCount () override
 Returns the number of items that will be written from the container.
 
unsigned int Count ()
 Returns the number of elements in the container.
 
bool Empty ()
 Returns whether the container is empty or not.
 
virtual std::string GetUniqueName (const std::string &name)
 Returns a unique name, incrementing the existing name until it is unique.
 
virtual bool Select (const std::string &name)
 Selects the given item. Does nothing if the item is not part of the container.
 
virtual bool IsDeleteable (T *item)
 Returns whether the given item is deletable (ie. not a default element or internal)
 
virtual bool Select (T *item)
 Selects the given item. Does nothing if the item is not part of the container.
 
virtual void Deselect ()
 Deselects the currently selected item.
 
virtual const std::string GetSelectedName ()
 Returns the currently selected item.
 
virtual T * GetSelectedItem ()
 Returns the currently selected item.
 
virtual T * Add (const std::string &name, T *item, bool replace, bool select=false)
 Adds the given item to the container, or if it already exists, updates the item to the given one.
 
virtual bool TryDelete (T *item)
 Attempts to delete the given item. Does nothing if the item is not deleteable or is null.
 
virtual bool Remove (const std::string &name)
 Removes the given item from the container.
 
virtual bool Remove (T *item)
 Removes the given item from the container.
 
virtual T * GetItem (const std::string &name)
 Returns the item with the given key, or nullptr if not found.
 
virtual const std::string GetKey (T *item)
 Returns the key of the item given, or an empty string if not found.
 
virtual bool Contains (const std::string &name)
 Returns whether the container contains an item with the given name.
 
virtual bool Rename (const std::string &name, const std::string &newName)
 Renames the given item to the new name, or the new name with appended numbers.
 
virtual const std::unordered_map< std::string, T * > & Data ()
 Returns a reference to the data stored in the container.
 
 ~IContainer ()
 Clears all of the container, deleting its elements.
 

Protected Member Functions

virtual bool SkipItem (T *item)
 Returns whether the item should be skipped or not.
 
virtual void RenameItem (T *item, const std::string &name)=0
 Renames the given item to the given name.
 
virtual const std::pair< std::string, T * > ReadItem (const std::string &scope, std::ifstream &file)=0
 Reads the next item from the input file stream.
 
virtual void WriteItem (const std::string &key, T *item, std::ofstream &file)=0
 Writes the given item into the output file stream.
 

Protected Attributes

std::unordered_map< std::string, T * > mData
 Data of the container.
 
std::string mCurSelectedName
 Currently selected item's name.
 
T * mCurSelectedItem
 Currently selected item.
 

Detailed Description

template<typename T>
class IContainer< T >

Container class for storing key value pairs. Should not be instantiated directly, but should be overridden by a class that implements additional functionality. (If not overriden, this class is functionally equivalent to an unordered map, just use that instead)

Template Parameters
TType of item to store

Constructor & Destructor Documentation

◆ ~IContainer()

template<typename T >
IContainer< T >::~IContainer ( )
inline

Clears all of the container, deleting its elements.

Member Function Documentation

◆ Add()

template<typename T >
virtual T * IContainer< T >::Add ( const std::string &  name,
T *  item,
bool  replace,
bool  select = false 
)
inlinevirtual

Adds the given item to the container, or if it already exists, updates the item to the given one.

Parameters
nameName of the item
itemThe item to store
replaceWhether to replace duplicate items (true) or rename the incoming item (false)
selectWhether to select the item after adding it
Returns
The element stored in the container

◆ Clear()

template<typename T >
void IContainer< T >::Clear ( )
inlineoverridevirtual

Clears the container of all items, deleting them.

Implements IWritable.

◆ ClearData()

template<typename T >
void IContainer< T >::ClearData ( )
inline

Clears the data of the container without deleting it. Only use this if pointers to the data exist elsewhere.

◆ Contains()

template<typename T >
virtual bool IContainer< T >::Contains ( const std::string &  name)
inlinevirtual

Returns whether the container contains an item with the given name.

Parameters
nameName of the item
Returns
Whether the item exists

◆ Count()

template<typename T >
unsigned int IContainer< T >::Count ( )
inline

Returns the number of elements in the container.

Returns
Number of elements in the container

◆ Data()

template<typename T >
virtual const std::unordered_map< std::string, T * > & IContainer< T >::Data ( )
inlinevirtual

Returns a reference to the data stored in the container.

Returns
Data of the container

◆ Deselect()

template<typename T >
virtual void IContainer< T >::Deselect ( )
inlinevirtual

Deselects the currently selected item.

◆ Empty()

template<typename T >
bool IContainer< T >::Empty ( )
inline

Returns whether the container is empty or not.

Returns

◆ GetItem()

template<typename T >
virtual T * IContainer< T >::GetItem ( const std::string &  name)
inlinevirtual

Returns the item with the given key, or nullptr if not found.

Parameters
nameName of item to find
Returns
Item

◆ GetKey()

template<typename T >
virtual const std::string IContainer< T >::GetKey ( T *  item)
inlinevirtual

Returns the key of the item given, or an empty string if not found.

Parameters
itemItem to search for
Returns
Name of item

◆ GetSelectedItem()

template<typename T >
virtual T * IContainer< T >::GetSelectedItem ( )
inlinevirtual

Returns the currently selected item.

Returns
Selected item

◆ GetSelectedName()

template<typename T >
virtual const std::string IContainer< T >::GetSelectedName ( )
inlinevirtual

Returns the currently selected item.

Returns
Selected item

◆ GetUniqueName()

template<typename T >
virtual std::string IContainer< T >::GetUniqueName ( const std::string &  name)
inlinevirtual

Returns a unique name, incrementing the existing name until it is unique.

Parameters
nameStarting name
scopeNamespace of the item
Returns
New unique name

◆ IsDeleteable()

template<typename T >
virtual bool IContainer< T >::IsDeleteable ( T *  item)
inlinevirtual

Returns whether the given item is deletable (ie. not a default element or internal)

Parameters
nameItem to consider
Returns
Whether the item can be deleted safely

Reimplemented in CameraContainer, LightContainer, MaterialContainer, and TextureContainer.

◆ Read()

template<typename T >
void IContainer< T >::Read ( const std::string &  scope,
std::ifstream &  file,
bool  clear 
)
inlineoverridevirtual

Reads this container from the file.

Parameters
scopeScope to read in
fileFile to read from
clearWhether to overwrite the contents of the item

Implements IWritable.

◆ ReadItem()

template<typename T >
virtual const std::pair< std::string, T * > IContainer< T >::ReadItem ( const std::string &  scope,
std::ifstream &  file 
)
protectedpure virtual

Reads the next item from the input file stream.

Parameters
scopeScope to read item in
fileFile to read
Returns
Newly constructed item from file

Implemented in CameraContainer, EntityContainer, LightContainer, MaterialContainer, MeshContainer, ShaderContainer, and TextureContainer.

◆ Remove() [1/2]

template<typename T >
virtual bool IContainer< T >::Remove ( const std::string &  name)
inlinevirtual

Removes the given item from the container.

Parameters
nameName of item to remove
Returns
Whether the item was removed or not

◆ Remove() [2/2]

template<typename T >
virtual bool IContainer< T >::Remove ( T *  item)
inlinevirtual

Removes the given item from the container.

Parameters
itemItem to remove
Returns
Whether the item was removed or not

◆ Rename()

template<typename T >
virtual bool IContainer< T >::Rename ( const std::string &  name,
const std::string &  newName 
)
inlinevirtual

Renames the given item to the new name, or the new name with appended numbers.

Parameters
nameName of the item to rename
newNameName to rename to
Returns
Whether the item was renamed

◆ RenameItem()

template<typename T >
virtual void IContainer< T >::RenameItem ( T *  item,
const std::string &  name 
)
protectedpure virtual

Renames the given item to the given name.

Parameters
itemItem to rename

Implemented in CameraContainer, EntityContainer, LightContainer, MaterialContainer, MeshContainer, ShaderContainer, and TextureContainer.

◆ Select() [1/2]

template<typename T >
virtual bool IContainer< T >::Select ( const std::string &  name)
inlinevirtual

Selects the given item. Does nothing if the item is not part of the container.

Parameters
nameName of item to select
Returns
Whether the item was selected or not

◆ Select() [2/2]

template<typename T >
virtual bool IContainer< T >::Select ( T *  item)
inlinevirtual

Selects the given item. Does nothing if the item is not part of the container.

Parameters
itemItem to select
Returns
Whether the item was selected or not

◆ SkipItem()

template<typename T >
virtual bool IContainer< T >::SkipItem ( T *  item)
inlineprotectedvirtual

Returns whether the item should be skipped or not.

Parameters
itemItem to consider
Returns
Whether the item should be skipped

Reimplemented in MaterialContainer, and TextureContainer.

◆ TryDelete()

template<typename T >
virtual bool IContainer< T >::TryDelete ( T *  item)
inlinevirtual

Attempts to delete the given item. Does nothing if the item is not deleteable or is null.

Parameters
itemItem to try to delete
Returns
Whether the item was deleted or not

◆ Write()

template<typename T >
void IContainer< T >::Write ( std::ofstream &  file)
inlineoverridevirtual

Writes this container to the file.

Parameters
fileFile to output to

Implements IWritable.

◆ WriteCount()

template<typename T >
unsigned int IContainer< T >::WriteCount ( )
inlineoverridevirtual

Returns the number of items that will be written from the container.

Returns
Number of writable items

Implements IWritable.

◆ WriteItem()

template<typename T >
virtual void IContainer< T >::WriteItem ( const std::string &  key,
T *  item,
std::ofstream &  file 
)
protectedpure virtual

Writes the given item into the output file stream.

Parameters
keyKey of item
itemItem to write
fileFile to write to

Implemented in CameraContainer, EntityContainer, LightContainer, MaterialContainer, MeshContainer, ShaderContainer, and TextureContainer.

Member Data Documentation

◆ mCurSelectedItem

template<typename T >
T* IContainer< T >::mCurSelectedItem
protected

Currently selected item.

◆ mCurSelectedName

template<typename T >
std::string IContainer< T >::mCurSelectedName
protected

Currently selected item's name.

◆ mData

template<typename T >
std::unordered_map<std::string, T*> IContainer< T >::mData
protected

Data of the container.