-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntity.h
More file actions
78 lines (70 loc) · 1.49 KB
/
Entity.h
File metadata and controls
78 lines (70 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef ENTITY_H
#define ENTITY_H
#include "BasicLib.h"
#include <string>
namespace SimpleMUD
{
typedef unsigned int entityid;
class Entity
{
public:
Entity() :m_name("UNDEFINED"), m_id(0) {}
std::string& Name() { return m_name; }
entityid& ID() { return m_id; }
std::string CompName() { return BasicLib::LowerCase(m_name); }
bool FullMatch(const std::string& p_name) { return BasicLib::LowerCase(m_name) == BasicLib::LowerCase(p_name); }
bool Match(const std::string& p_name)
{
if (p_name.size() == 0)
return true;
std::string name = CompName();
std::string search = BasicLib::LowerCase(p_name);
size_t pos = name.find(search);
while (pos != std::string::npos)
{
if (pos == 0 || m_name[pos - 1] == ' ')
{
return true;
}
pos = name.find(search, pos + 1);
}
return false;
}
protected:
std::string m_name;
entityid m_id;
};
struct matchentityfull
{
std::string m_str;
matchentityfull(const std::string& p_str)
:m_str(p_str)
{
}
bool operator()(Entity& p_entity)
{
return p_entity.FullMatch(m_str);
}
bool operator()(Entity* p_entity)
{
return p_entity != nullptr && p_entity->FullMatch(m_str);
}
};
struct matchentity
{
std::string m_str;
matchentity(const std::string& p_str)
:m_str(p_str)
{
}
bool operator()(Entity& p_entity)
{
return p_entity.Match(m_str);
}
bool operator()(Entity* p_entity)
{
return p_entity != nullptr && p_entity->Match(m_str);
}
};
}
#endif // !ENTITY_H