Norbert's Game Engine v200
Loading...
Searching...
No Matches
eMap< T > Class Template Reference

#include <Map.hpp>

Inheritance diagram for eMap< T >:
eBase

Public Member Functions

void Push (T vl, eString id="")
 Push an item to the collection.
 
void Pop (eString id)
 Pop an item from the collection.
 
void Pop (uint id)
 Pop an item from the collection by number index.
 
void Popa ()
 Clear the collection.
 
T & Get (eString id)
 Returns item from collection.
 
T & Get (uint id)
 Returns item from collection.
 
std::vector< std::pair< eString, T > > & Geta ()
 Returns collection.
 
T & operator[] (eString id)
 
T & operator[] (uint id)
 
uint64 Size ()
 Returns collection size.
 
eString & IdAt (uint i)
 Returns item name from number index.
 
bool Find (eString name)
 Returns true if item with such a name exists!
 
- Public Member Functions inherited from eBase
template<typename T >
T * Cast (eBase *obj)
 Cast class to base.
 

Detailed Description

template<typename T>
class eMap< T >

Map container for objects

Definition at line 15 of file Map.hpp.

Member Function Documentation

◆ Find()

template<typename T >
bool eMap< T >::Find ( eString name)
inline

Returns true if item with such a name exists!

Definition at line 129 of file Map.hpp.

130 {
131 for (auto& it : mItems)
132 {
133 if (it.first == name)
134 return true;
135 }
136 return false;
137 }

◆ Get() [1/2]

template<typename T >
T & eMap< T >::Get ( eString id)
inline

Returns item from collection.

Definition at line 71 of file Map.hpp.

72 {
73 for (auto& it : mItems)
74 {
75 if (it.first == id)
76 return it.second;
77 }
78 eConsole::PrintLog("WARNING::eMap::Get", "Item '" + id.GetStrg() + "' could not be found!");
79
80 T dvl;
81 return dvl;
82 }
static void PrintLog(eString head, eString msg)
Print a log.
Definition Console.cpp:22

◆ Get() [2/2]

template<typename T >
T & eMap< T >::Get ( uint id)
inline

Returns item from collection.

Definition at line 85 of file Map.hpp.

86 {
87 if (id > mItems.size() || id < 0)
88 {
89 eConsole::PrintLog("ERROR::eMap::Get", "Invalid id '" + std::to_string(id) + "'!");
91 }
92 return mItems[id].second;
93 }
static void WriteToDisk()
Write the console text to a crash file called 'CRASH.log'.
Definition Console.cpp:40

◆ Geta()

template<typename T >
std::vector< std::pair< eString, T > > & eMap< T >::Geta ( )
inline

Returns collection.

Definition at line 96 of file Map.hpp.

97 {
98 return mItems;
99 }

◆ IdAt()

template<typename T >
eString & eMap< T >::IdAt ( uint i)
inline

Returns item name from number index.

Definition at line 118 of file Map.hpp.

119 {
120 if (i > mItems.size() || i < 0)
121 {
122 eConsole::PrintLog("ERROR::eMap::IdAt", "Invalid id '" + std::to_string(i) + "'!");
124 }
125 return mItems[i].first;
126 }

◆ operator[]() [1/2]

template<typename T >
T & eMap< T >::operator[] ( eString id)
inline

Definition at line 101 of file Map.hpp.

102 {
103 return Get(id);
104 }
T & Get(eString id)
Returns item from collection.
Definition Map.hpp:71

◆ operator[]() [2/2]

template<typename T >
T & eMap< T >::operator[] ( uint id)
inline

Definition at line 106 of file Map.hpp.

107 {
108 return Get(id);
109 }

◆ Pop() [1/2]

template<typename T >
void eMap< T >::Pop ( eString id)
inline

Pop an item from the collection.

Definition at line 39 of file Map.hpp.

40 {
41 for (uint i = 0; i < mItems.size(); i++)
42 {
43 auto& it = mItems[i];
44 if (it.first == id)
45 {
46 mItems.erase(mItems.begin() + i);
47 return;
48 }
49 }
50 eConsole::PrintLog("WARNING::eMap::Pop", "Item '" + id.GetStrg() + "' could not be found!");
51 }

◆ Pop() [2/2]

template<typename T >
void eMap< T >::Pop ( uint id)
inline

Pop an item from the collection by number index.

Definition at line 54 of file Map.hpp.

55 {
56 if (id > mItems.size() || id < 0)
57 {
58 eConsole::PrintLog("WARNING::eMap::Pop", "Invalid id '" + std::to_string(id) + "'!");
59 return;
60 }
61 mItems.erase(mItems.size() + id);
62 }

◆ Popa()

template<typename T >
void eMap< T >::Popa ( )
inline

Clear the collection.

Definition at line 65 of file Map.hpp.

66 {
67 mItems.clear();
68 }

◆ Push()

template<typename T >
void eMap< T >::Push ( T vl,
eString id = "" )
inline

Push an item to the collection.

Definition at line 19 of file Map.hpp.

20 {
21 eString newId = std::to_string(mItems.size() + 1);
22 if (!id.IsEmpty())
23 {
24 newId = id;
25 for (auto& it : mItems)
26 {
27 if (it.first == newId)
28 {
29 eConsole::PrintLog("WARNING::eMap::Push", "Item '" + newId.GetStrg() + "' already exists!");
30 return;
31 }
32 }
33 }
34
35 mItems.push_back(std::make_pair(newId, vl));
36 }
const strg & GetStrg() const
Return text as std::string.
Definition String.cpp:70

◆ Size()

template<typename T >
uint64 eMap< T >::Size ( )
inline

Returns collection size.

Definition at line 112 of file Map.hpp.

113 {
114 return mItems.size();
115 }

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