-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcpps_map.h
More file actions
154 lines (139 loc) · 3.65 KB
/
cpps_map.h
File metadata and controls
154 lines (139 loc) · 3.65 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef cpps_map_CPPS_HEAD_
#define cpps_map_CPPS_HEAD_
//===================================
//@Author : Johnson
//@QQ : 88481106
//@Email : 88481106@qq.com
//@Date : 2015/11/25 (yy/mm/dd)
//@Module : CPPS_DOMAIN
//@Description : ´´½¨ºìºÚÊ÷½Ó¿Ú
//@website : http://cppscript.org
//==================================
namespace cpps
{
#ifdef _DEBUG
typedef std::unordered_map<cpps_value, cpps_value, cpps_value::hash> cpps_hash_map;
typedef std::unordered_set<cpps_value, cpps_value::hash> cpps_hash_set;
#else
typedef phmap::flat_hash_map<cpps_value, cpps_value, cpps_value::hash> cpps_hash_map;
typedef phmap::flat_hash_set<cpps_value, cpps_value::hash> cpps_hash_set;
#endif
struct object;
struct cpps_map
{
virtual ~cpps_map();
void insert(cpps_value k, cpps_value v);
cpps_value find(cpps_value k);
cpps_value& cpps_find(const cpps_value & k);
void erase(cpps_value k);
void begin();
bool has(cpps_value k);
bool end();
bool empty();
void next();
cpps_value it();
void pop();
cpps_value key();
void clear();
cpps_integer size();
void merge(cpps_value right);
void set(cpps_value key_val, cpps_value value);
void remove_at_map(cpps_map* _right);
cpps_value where(C* c, object o);
cpps_value select(C* c, object o);
cpps_value to_list(C* c);
cpps_value orderby(C* c, object o);
cpps_value& operator [] (cpps_value k)
{
return _map[k];
}
cpps_hash_map& realmap();
private:
cpps_hash_map _map;
cpps_hash_map::iterator _begin;
public:
};
struct cpps_set
{
virtual ~cpps_set();
void constructor(object list);
void insert(cpps_value k);
void erase(cpps_value k);
void begin();
bool has(cpps_value k);
bool end();
bool empty();
void next();
cpps_value it();
void pop();
void clear();
cpps_integer size();
void merge(cpps_value right);
cpps_value where(C* c, object o);
cpps_value select(C* c, object o);
void remove_at_set(cpps_set* _right);
cpps_hash_set& realset();
cpps_value orderby(C* c, object o);
cpps_value to_list(C* c);
private:
cpps_hash_set _set;
cpps_hash_set::iterator _begin;
public:
};
void cpps_regmap(C *c);
struct cpps_pair
{
public:
cpps_pair(){}
cpps_pair(cpps_value __first,cpps_value __second){
_first = __first;
_second = __second;
}
cpps_pair(object __first, object __second);
virtual~cpps_pair(){}
cpps_value first() {
return _first;
}
cpps_value second() {
return _second;
}
void constructor(object __first, object __second);
object getobject(object right);
bool equalfunc(object right);
cpps_value _first;
cpps_value _second;
};
template<>
struct cpps_converter<cpps_hash_map*>
{
static bool match(cpps_value obj)
{
if (obj.tt != CPPS_TCLASSVAR) return false;
if (!obj.is_kindof<cpps_map>()) return false;
return true;
}
static cpps_hash_map* apply(cpps_value obj)
{
cpps_cppsclassvar *clsvar = (cpps_cppsclassvar *)obj.value.domain;
cpps::cpps_map *m = static_cast<cpps::cpps_map*>(clsvar->getclsptr());
return &m->realmap();
}
};
template<>
struct cpps_converter<cpps_hash_set*>
{
static bool match(cpps_value obj)
{
if (obj.tt != CPPS_TCLASSVAR) return false;
if (obj.is_kindof<cpps_set>()) return false;
return true;
}
static cpps_hash_set* apply(cpps_value obj)
{
cpps_cppsclassvar* clsvar = (cpps_cppsclassvar*)obj.value.domain;
cpps::cpps_set* m = static_cast<cpps::cpps_set*>(clsvar->getclsptr());
return &m->realset();
}
};
}
#endif