CSEngine
Loading...
Searching...
No Matches
CSE::SContainerHash< T > Class Template Reference
Inheritance diagram for CSE::SContainerHash< T >:
CSE::SIContainer< std::unordered_map< std::string, T >, T, std::string >

Public Member Functions

void Register (T object) override
 
void Remove (T object) override
 
bool HasHash (const std::string &hash) const
 
Get (std::string index) const override
 
std::unordered_map< std::string, T > GetAll () const override
 
std::string GetID (T object) const override
 
int GetSize () const override
 
void ChangeHash (const std::string &srcHash, const std::string &dstHash)
 

Protected Attributes

std::unordered_map< std::string, T > m_objects
 
int m_size = 0
 

Detailed Description

template<class T>
class CSE::SContainerHash< T >

Definition at line 11 of file SContainerHash.h.

Member Function Documentation

◆ ChangeHash()

template<class T >
void CSE::SContainerHash< T >::ChangeHash ( const std::string &  srcHash,
const std::string &  dstHash 
)
inline

Definition at line 59 of file SContainerHash.h.

59 {
60 T object = m_objects.at(srcHash);
61 if(object == nullptr) return;
62 m_objects.erase(srcHash);
63 const auto& prevSize = m_objects.size();
64 m_objects.insert(std::pair<std::string, T>(dstHash, object));
65 //if(prevSize - m_objects.size() == 0) throw -1;
66 }

◆ Get()

template<class T >
T CSE::SContainerHash< T >::Get ( std::string  index) const
inlineoverridevirtual

Implements CSE::SIContainer< std::unordered_map< std::string, T >, T, std::string >.

Definition at line 43 of file SContainerHash.h.

43 {
44 return m_objects.at(index);
45 }

◆ GetAll()

template<class T >
std::unordered_map< std::string, T > CSE::SContainerHash< T >::GetAll ( ) const
inlineoverridevirtual

Implements CSE::SIContainer< std::unordered_map< std::string, T >, T, std::string >.

Definition at line 47 of file SContainerHash.h.

47 {
48 return m_objects;
49 }

◆ GetID()

template<class T >
std::string CSE::SContainerHash< T >::GetID ( object) const
inlineoverridevirtual

Implements CSE::SIContainer< std::unordered_map< std::string, T >, T, std::string >.

Definition at line 51 of file SContainerHash.h.

51 {
52 return object->GetHash();
53 }

◆ GetSize()

template<class T >
int CSE::SContainerHash< T >::GetSize ( ) const
inlineoverridevirtual

Implements CSE::SIContainer< std::unordered_map< std::string, T >, T, std::string >.

Definition at line 55 of file SContainerHash.h.

55 {
56 return m_size;
57 }

◆ HasHash()

template<class T >
bool CSE::SContainerHash< T >::HasHash ( const std::string &  hash) const
inline

Definition at line 39 of file SContainerHash.h.

39 {
40 return m_objects.count(hash) > 0;
41 }

◆ Register()

template<class T >
void CSE::SContainerHash< T >::Register ( object)
inlineoverridevirtual

Implements CSE::SIContainer< std::unordered_map< std::string, T >, T, std::string >.

Definition at line 17 of file SContainerHash.h.

17 {
18 std::string hash = object->GetHash();
19 if (m_objects.count(hash) > 0) {
20 throw -1;
21 return;
22 }
23 m_objects.insert(std::pair<std::string, T>(hash, object));
24 ++m_size;
25 }

◆ Remove()

template<class T >
void CSE::SContainerHash< T >::Remove ( object)
inlineoverridevirtual

Implements CSE::SIContainer< std::unordered_map< std::string, T >, T, std::string >.

Definition at line 27 of file SContainerHash.h.

27 {
28 std::string hash = object->GetHash();
29 if (m_objects.count(hash) <= 0) return;
30 for (auto it = m_objects.begin(); it != m_objects.end(); ++it) {
31 if (it->second == object) {
32 m_objects.erase(it);
33 --m_size;
34 break;
35 }
36 }
37 }

Member Data Documentation

◆ m_objects

template<class T >
std::unordered_map<std::string, T> CSE::SContainerHash< T >::m_objects
protected

Definition at line 69 of file SContainerHash.h.

◆ m_size

template<class T >
int CSE::SContainerHash< T >::m_size = 0
protected

Definition at line 70 of file SContainerHash.h.


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