-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings.cpp
80 lines (69 loc) · 1.45 KB
/
strings.cpp
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
78
79
80
#pragma warning (disable:4786)
#include <map>
#include <string>
using namespace std;
typedef map<string, int, less<string> > MapStringInt;
#include "strings.h"
struct Private_Data
{
MapStringInt theMap;
MapStringInt::iterator pos;
};
#define THE_MAP ( (*((Private_Data*)data)).theMap)
#define THE_POS ( (*((Private_Data*)data)).pos)
StringFinder::StringFinder()
{
data = new Private_Data;
}
StringFinder::~StringFinder()
{
delete (Private_Data*)data;
}
void StringFinder::clear()
{
THE_MAP.clear();
}
void StringFinder::add(const char* str, int num)
{
if (!str || !*str) { return; }
typedef MapStringInt::value_type Entry;
THE_MAP.insert(Entry(str, num));
}
void StringFinder::erase(const char* str)
{
MapStringInt::iterator foundPos = THE_MAP.find(std::string(str));
if (foundPos != THE_MAP.end())
{
THE_MAP.erase(foundPos);
}
}
bool StringFinder::find(const char* str)
{
if (!str || !*str) { return false; }
MapStringInt::iterator foundPos = THE_MAP.find(std::string(str));
if (foundPos == THE_MAP.end())
{
return false;
}
else
{
num = (*foundPos).second;
return true;
}
}
void StringFinder::it_start()
{
THE_POS = THE_MAP.begin();
num = THE_POS->second;
str = THE_POS->first.c_str();
}
bool StringFinder::it_running()
{
return (THE_POS != THE_MAP.end());
}
void StringFinder::it_next()
{
++THE_POS;
num = THE_POS->second;
str = THE_POS->first.c_str();
}