forked from zrax/pycdc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyc_sequence.h
108 lines (78 loc) · 2.47 KB
/
pyc_sequence.h
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
#ifndef _PYC_SEQUENCE_H
#define _PYC_SEQUENCE_H
#include "pyc_object.h"
#include <vector>
#include <list>
#include <set>
class PycSequence : public PycObject {
public:
PycSequence(int type) : PycObject(type), m_size(0) { }
int size() const { return m_size; }
virtual PycRef<PycObject> get(int idx) const = 0;
protected:
int m_size;
};
class PycTuple : public PycSequence {
public:
typedef std::vector<PycRef<PycObject> > value_t;
PycTuple(int type = TYPE_TUPLE) : PycSequence(type) { }
bool isEqual(PycRef<PycObject> obj) const;
void load(class PycData* stream, class PycModule* mod);
const value_t& values() const { return m_values; }
PycRef<PycObject> get(int idx) const { return m_values[idx]; }
private:
value_t m_values;
};
class PycList : public PycSequence {
public:
typedef std::list<PycRef<PycObject> > value_t;
PycList(int type = TYPE_LIST) : PycSequence(type) { }
bool isEqual(PycRef<PycObject> obj) const;
void load(class PycData* stream, class PycModule* mod);
const value_t& values() const { return m_values; }
PycRef<PycObject> get(int idx) const
{
value_t::const_iterator it = m_values.begin();
for (int i=0; i<idx; i++) ++it;
return *it;
}
private:
value_t m_values;
};
class PycDict : public PycSequence {
public:
typedef std::list<PycRef<PycObject> > key_t;
typedef std::list<PycRef<PycObject> > value_t;
PycDict(int type = TYPE_DICT) : PycSequence(type) { }
bool isEqual(PycRef<PycObject> obj) const;
void load(class PycData* stream, class PycModule* mod);
PycRef<PycObject> get(PycRef<PycObject> key) const;
const key_t& keys() const { return m_keys; }
const value_t& values() const { return m_values; }
PycRef<PycObject> get(int idx) const
{
value_t::const_iterator it = m_values.begin();
for (int i=0; i<idx; i++) ++it;
return *it;
}
private:
key_t m_keys;
value_t m_values;
};
class PycSet : public PycSequence {
public:
typedef std::set<PycRef<PycObject> > value_t;
PycSet(int type = TYPE_SET) : PycSequence(type) { }
bool isEqual(PycRef<PycObject> obj) const;
void load(class PycData* stream, class PycModule* mod);
const value_t& values() const { return m_values; }
PycRef<PycObject> get(int idx) const
{
value_t::const_iterator it = m_values.begin();
for (int i=0; i<idx; i++) ++it;
return *it;
}
private:
value_t m_values;
};
#endif