-
Notifications
You must be signed in to change notification settings - Fork 259
/
tools.cpp
114 lines (95 loc) · 2.56 KB
/
tools.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) 2014-2017 Coin Sciences Ltd
// MultiChain code distributed under the GPLv3 license, see COPYING file.
#include "multichain/multichain.h"
#include <iosfwd>
#include <string>
#include <map>
using namespace std;
void mc_MapStringIndex::Init()
{
Destroy();
mapObject=new std::map<string, int>;
}
void mc_MapStringIndex::Destroy()
{
if(mapObject)
{
delete (std::map<string, int>*)mapObject;
}
}
void mc_MapStringIndex::Clear()
{
Init();
}
void mc_MapStringIndex::Add(const char* key, int value)
{
((std::map<string, int>*)mapObject)->insert(std::pair<string, int>(string(key), value));
}
void mc_MapStringIndex::Add(const unsigned char* key, int size, int value)
{
((std::map<string, int>*)mapObject)->insert(std::pair<string, int>(string(key,key+size), value));
}
void mc_MapStringIndex::Remove(const char* key,int size)
{
((std::map<string, int>*)mapObject)->erase(string(key,key+size));
}
int mc_MapStringIndex::Get(const char* key)
{
std::map<string, int>::iterator it;
int value=-1;
it=((std::map<string, int>*)mapObject)->find(string(key));
if (it != ((std::map<string, int>*)mapObject)->end())
{
value=it->second;
}
return value;
}
int mc_MapStringIndex::Get(const unsigned char* key,int size)
{
std::map<string, int>::iterator it;
int value=-1;
it=((std::map<string, int>*)mapObject)->find(string(key,key+size));
if (it != ((std::map<string, int>*)mapObject)->end())
{
value=it->second;
}
return value;
}
void mc_MapStringIndex::Set(const unsigned char* key,int size, int value)
{
std::map<string, int>::iterator it;
it=((std::map<string, int>*)mapObject)->find(string(key,key+size));
if (it != ((std::map<string, int>*)mapObject)->end())
{
it->second=value;
}
}
void mc_MapStringString::Init()
{
mapObject=new std::map<string, string>;
}
void mc_MapStringString::Destroy()
{
if(mapObject)
{
delete (std::map<string, string>*)mapObject;
}
}
void mc_MapStringString::Add(const char* key, const char* value)
{
((std::map<string, string>*)mapObject)->insert(std::pair<string, string>(string(key), value));
}
const char* mc_MapStringString::Get(const char* key)
{
std::map<string, string>::iterator it;
it=((std::map<string, string>*)mapObject)->find(string(key));
if (it != ((std::map<string, string>*)mapObject)->end())
{
return it->second.c_str();
}
return NULL;
}
int mc_MapStringString::GetCount()
{
return ((std::map<string, string>*)mapObject)->size();
}