yinspire 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +24 -0
- data/bench/pq/Makefile +5 -0
- data/bench/pq/bench.cc +321 -0
- data/bench/pq/bench.rb +125 -0
- data/bench/pq/bench_binaryheap.h +46 -0
- data/bench/pq/bench_calendarqueue.h +58 -0
- data/bench/pq/bench_pairingheap.h +61 -0
- data/bench/pq/bench_stlpq.h +46 -0
- data/bench/pq/benchmark.h +225 -0
- data/bench/pq/distribution.h +93 -0
- data/bench/pq/make.rb +24 -0
- data/bin/yinspire +186 -0
- data/examples/nets/gereon2005.c.json +93723 -0
- data/examples/nets/gereon2005.yin +232650 -0
- data/examples/nets/skorpion.graphml +396 -0
- data/examples/nets/spiketrains_angle_180.txt +8 -0
- data/lib/Algorithms/Array.h +52 -0
- data/lib/Algorithms/BinaryHeap.h +265 -0
- data/lib/Algorithms/CalendarQueue.h +257 -0
- data/lib/Algorithms/IndexedBinaryHeap.h +90 -0
- data/lib/Algorithms/PairingHeap.h +169 -0
- data/lib/Allocators/ChunkedFreelistAllocator.h +96 -0
- data/lib/Allocators/MemoryAllocator.h +45 -0
- data/lib/Allocators/RubyMemoryAllocator.h +37 -0
- data/lib/Yinspire.rb +69 -0
- data/lib/Yinspire/All.rb +10 -0
- data/lib/Yinspire/Core/NeuralEntity.rb +133 -0
- data/lib/Yinspire/Core/Neuron.rb +162 -0
- data/lib/Yinspire/Core/Scheduling/NeuralEntity.rb +123 -0
- data/lib/Yinspire/Core/Scheduling/Simulator.rb +94 -0
- data/lib/Yinspire/Core/Simulator.rb +36 -0
- data/lib/Yinspire/Core/StimuliMixin.rb +103 -0
- data/lib/Yinspire/Core/Stimulus.rb +25 -0
- data/lib/Yinspire/Core/Synapse.rb +64 -0
- data/lib/Yinspire/Dumpers/Dumper.rb +19 -0
- data/lib/Yinspire/Dumpers/Dumper_Dot.rb +28 -0
- data/lib/Yinspire/Loaders/GraphML.rb +84 -0
- data/lib/Yinspire/Loaders/Loader.rb +31 -0
- data/lib/Yinspire/Loaders/Loader_GraphML.rb +97 -0
- data/lib/Yinspire/Loaders/Loader_JSON.rb +181 -0
- data/lib/Yinspire/Loaders/Loader_Spike.rb +42 -0
- data/lib/Yinspire/Loaders/Loader_Yin.rb +62 -0
- data/lib/Yinspire/Loaders/YinScanner.rb +247 -0
- data/lib/Yinspire/Models/Neuron_Base.rb +38 -0
- data/lib/Yinspire/Models/Neuron_Input.rb +12 -0
- data/lib/Yinspire/Models/Neuron_InputOutput.rb +39 -0
- data/lib/Yinspire/Models/Neuron_Output.rb +15 -0
- data/lib/Yinspire/Models/Neuron_SRM01.rb +50 -0
- data/lib/Yinspire/Models/Neuron_SRM02.rb +64 -0
- data/lib/Yinspire/Models/Synapse_Hebb.rb +67 -0
- data/pure_cpp/Makefile +22 -0
- data/pure_cpp/README +2 -0
- data/pure_cpp/src/algo/binary_heap.h +277 -0
- data/pure_cpp/src/algo/indexed_binary_heap.h +90 -0
- data/pure_cpp/src/json/json.cc +542 -0
- data/pure_cpp/src/json/json.h +182 -0
- data/pure_cpp/src/json/json_parser.cc +685 -0
- data/pure_cpp/src/json/json_parser.h +15 -0
- data/pure_cpp/src/json/json_parser.rl +213 -0
- data/pure_cpp/src/main.cc +49 -0
- data/pure_cpp/src/memory_allocator.h +45 -0
- data/pure_cpp/src/neural_entity.cc +208 -0
- data/pure_cpp/src/neural_entity.h +243 -0
- data/pure_cpp/src/neuron.cc +136 -0
- data/pure_cpp/src/neuron.h +70 -0
- data/pure_cpp/src/neuron_srm_01.cc +77 -0
- data/pure_cpp/src/neuron_srm_01.h +36 -0
- data/pure_cpp/src/simulator.cc +151 -0
- data/pure_cpp/src/simulator.h +116 -0
- data/pure_cpp/src/synapse.cc +117 -0
- data/pure_cpp/src/synapse.h +60 -0
- data/pure_cpp/src/types.h +18 -0
- data/run.rb +68 -0
- data/tools/conv_jsonc_to_yin.rb +165 -0
- data/tools/converter.rb +93 -0
- data/tools/json_writer.rb +122 -0
- data/yinspire.gemspec +20 -0
- metadata +156 -0
@@ -0,0 +1,182 @@
|
|
1
|
+
#ifndef __YINSPIRE__JSON__
|
2
|
+
#define __YINSPIRE__JSON__
|
3
|
+
|
4
|
+
#include <ostream>
|
5
|
+
#include <string>
|
6
|
+
|
7
|
+
#define jsonArrayIterator_EACH(ary, i) \
|
8
|
+
jsonValue *i; \
|
9
|
+
for (jsonArrayIterator iter(ary); (i=iter.current()) != NULL; iter.next())
|
10
|
+
|
11
|
+
#define jsonHashIterator_EACH(hash, k, v) \
|
12
|
+
jsonString *k; \
|
13
|
+
jsonValue *v; \
|
14
|
+
for (jsonHashIterator iter(hash); (k=iter.current_key(), v=iter.current_value(), k) != NULL; iter.next())
|
15
|
+
|
16
|
+
struct jsonArrayItem;
|
17
|
+
struct jsonHashItem;
|
18
|
+
|
19
|
+
/*
|
20
|
+
* Forward declarations
|
21
|
+
*/
|
22
|
+
class jsonNull;
|
23
|
+
class jsonTrue;
|
24
|
+
class jsonFalse;
|
25
|
+
class jsonNumber;
|
26
|
+
class jsonString;
|
27
|
+
class jsonArray;
|
28
|
+
class jsonHash;
|
29
|
+
|
30
|
+
class jsonValue {
|
31
|
+
public:
|
32
|
+
jsonValue();
|
33
|
+
virtual ~jsonValue();
|
34
|
+
virtual const char* type();
|
35
|
+
bool is_type(const char* t);
|
36
|
+
void ref_incr();
|
37
|
+
void ref_decr();
|
38
|
+
virtual void output(std::ostream& s) = 0;
|
39
|
+
|
40
|
+
jsonNull* asNull();
|
41
|
+
jsonTrue* asTrue();
|
42
|
+
jsonFalse* asFalse();
|
43
|
+
jsonNumber* asNumber();
|
44
|
+
jsonString* asString();
|
45
|
+
jsonArray* asArray();
|
46
|
+
jsonHash* asHash();
|
47
|
+
|
48
|
+
private:
|
49
|
+
int ref_count;
|
50
|
+
};
|
51
|
+
|
52
|
+
class jsonNull : public jsonValue
|
53
|
+
{
|
54
|
+
public:
|
55
|
+
virtual void output(std::ostream& s);
|
56
|
+
virtual const char* type();
|
57
|
+
};
|
58
|
+
|
59
|
+
class jsonTrue : public jsonValue
|
60
|
+
{
|
61
|
+
public:
|
62
|
+
virtual void output(std::ostream& s);
|
63
|
+
virtual const char* type();
|
64
|
+
};
|
65
|
+
|
66
|
+
class jsonFalse : public jsonValue
|
67
|
+
{
|
68
|
+
public:
|
69
|
+
virtual void output(std::ostream& s);
|
70
|
+
virtual const char* type();
|
71
|
+
};
|
72
|
+
|
73
|
+
class jsonNumber : public jsonValue
|
74
|
+
{
|
75
|
+
public:
|
76
|
+
|
77
|
+
double value;
|
78
|
+
|
79
|
+
public:
|
80
|
+
|
81
|
+
jsonNumber(double value);
|
82
|
+
virtual void output(std::ostream& s);
|
83
|
+
virtual const char* type();
|
84
|
+
};
|
85
|
+
|
86
|
+
class jsonString : public jsonValue
|
87
|
+
{
|
88
|
+
public:
|
89
|
+
|
90
|
+
std::string value;
|
91
|
+
|
92
|
+
public:
|
93
|
+
|
94
|
+
jsonString(std::string& value);
|
95
|
+
jsonString(const char* value);
|
96
|
+
jsonString(const char* _value, int len);
|
97
|
+
|
98
|
+
virtual void output(std::ostream& s);
|
99
|
+
virtual const char* type();
|
100
|
+
};
|
101
|
+
|
102
|
+
class jsonArrayIterator
|
103
|
+
{
|
104
|
+
jsonArray *array;
|
105
|
+
jsonArrayItem *pos;
|
106
|
+
|
107
|
+
public:
|
108
|
+
|
109
|
+
jsonArrayIterator(jsonArray *array);
|
110
|
+
~jsonArrayIterator();
|
111
|
+
|
112
|
+
void next();
|
113
|
+
jsonValue *current();
|
114
|
+
};
|
115
|
+
|
116
|
+
class jsonArray : public jsonValue
|
117
|
+
{
|
118
|
+
public:
|
119
|
+
|
120
|
+
jsonArrayItem* head;
|
121
|
+
jsonArrayItem* tail;
|
122
|
+
|
123
|
+
public:
|
124
|
+
|
125
|
+
jsonArray();
|
126
|
+
virtual ~jsonArray();
|
127
|
+
virtual void output(std::ostream& s);
|
128
|
+
void push(jsonValue* value);
|
129
|
+
//void each(void (*iter)(jsonValue*, void*), void* data);
|
130
|
+
jsonValue *get(int index);
|
131
|
+
virtual const char* type();
|
132
|
+
};
|
133
|
+
|
134
|
+
class jsonHashIterator
|
135
|
+
{
|
136
|
+
jsonHash *hash;
|
137
|
+
jsonHashItem *pos;
|
138
|
+
|
139
|
+
public:
|
140
|
+
|
141
|
+
jsonHashIterator(jsonHash *hash);
|
142
|
+
~jsonHashIterator();
|
143
|
+
|
144
|
+
void next();
|
145
|
+
jsonString *current_key();
|
146
|
+
jsonValue *current_value();
|
147
|
+
};
|
148
|
+
|
149
|
+
|
150
|
+
class jsonHash : public jsonValue
|
151
|
+
{
|
152
|
+
public:
|
153
|
+
|
154
|
+
jsonHashItem* head;
|
155
|
+
jsonHashItem* tail;
|
156
|
+
|
157
|
+
public:
|
158
|
+
|
159
|
+
jsonHash();
|
160
|
+
virtual ~jsonHash();
|
161
|
+
virtual void output(std::ostream& s);
|
162
|
+
//void each(void (*iter)(jsonString*, jsonValue*, void*), void* data);
|
163
|
+
jsonValue* get(const char* key);
|
164
|
+
jsonValue* get(std::string& key);
|
165
|
+
jsonValue* get(jsonString* key);
|
166
|
+
bool has_key(const char* key);
|
167
|
+
bool has_key(std::string& key);
|
168
|
+
bool has_key(jsonString* key);
|
169
|
+
bool get_bool(const char* key, bool default_value);
|
170
|
+
double get_number(const char* key, double default_value);
|
171
|
+
std::string& get_string(const char* key);
|
172
|
+
void set(const char* key, jsonValue* value);
|
173
|
+
void set(const char* key, double value);
|
174
|
+
void set(const char* key, int value);
|
175
|
+
void set(const char* key, bool value);
|
176
|
+
void set(const char* key, const char* value);
|
177
|
+
void set(const char* key, std::string& value);
|
178
|
+
void set(jsonString* key, jsonValue* value);
|
179
|
+
virtual const char* type();
|
180
|
+
};
|
181
|
+
|
182
|
+
#endif
|
@@ -0,0 +1,685 @@
|
|
1
|
+
#line 1 "src/json/json_parser.rl"
|
2
|
+
#line 62 "src/json/json_parser.rl"
|
3
|
+
|
4
|
+
|
5
|
+
#include <vector>
|
6
|
+
#include <math.h>
|
7
|
+
#include <stdlib.h>
|
8
|
+
#include <string.h>
|
9
|
+
#include <iostream>
|
10
|
+
#include "json_parser.h"
|
11
|
+
|
12
|
+
#define PB(x) values.push_back(x)
|
13
|
+
|
14
|
+
inline static jsonString* json_string(char* from, char* to)
|
15
|
+
{
|
16
|
+
return new jsonString(from, to-from);
|
17
|
+
}
|
18
|
+
|
19
|
+
inline static jsonNumber* json_number(char* from, char* to, char* buf, int maxsz)
|
20
|
+
{
|
21
|
+
const int sz = to-from;
|
22
|
+
|
23
|
+
if (sz > maxsz) throw "fatal";
|
24
|
+
|
25
|
+
memcpy(buf, from, sz);
|
26
|
+
buf[sz] = '\000';
|
27
|
+
|
28
|
+
return new jsonNumber(strtod(buf, NULL));
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
#line 33 "src/json/json_parser.cc"
|
33
|
+
static const char _jsonParser_actions[] = {
|
34
|
+
0, 1, 0, 1, 1, 1, 2, 1,
|
35
|
+
3, 1, 4, 1, 5, 1, 6, 1,
|
36
|
+
7, 1, 8, 1, 9, 1, 10, 1,
|
37
|
+
11, 1, 12, 1, 13, 1, 14, 1,
|
38
|
+
15, 1, 16, 1, 17, 2, 0, 13,
|
39
|
+
2, 0, 17, 2, 1, 13, 2, 1,
|
40
|
+
17, 2, 2, 13, 2, 2, 17, 2,
|
41
|
+
4, 13, 2, 4, 17, 2, 5, 13,
|
42
|
+
2, 5, 17, 2, 6, 13, 2, 6,
|
43
|
+
17, 2, 8, 13, 2, 8, 17, 2,
|
44
|
+
13, 15, 2, 14, 7, 2, 14, 9,
|
45
|
+
2, 14, 15, 2, 16, 3, 2, 16,
|
46
|
+
7, 2, 16, 11, 2, 16, 12, 2,
|
47
|
+
16, 17, 3, 0, 13, 15, 3, 1,
|
48
|
+
13, 15, 3, 2, 13, 15, 3, 4,
|
49
|
+
13, 15, 3, 5, 13, 15, 3, 6,
|
50
|
+
13, 15, 3, 8, 13, 15
|
51
|
+
};
|
52
|
+
|
53
|
+
static const short _jsonParser_key_offsets[] = {
|
54
|
+
0, 0, 17, 18, 19, 21, 22, 26,
|
55
|
+
30, 32, 33, 34, 35, 36, 37, 38,
|
56
|
+
39, 43, 44, 45, 46, 47, 48, 49,
|
57
|
+
50, 51, 53, 54, 55, 56, 57, 58,
|
58
|
+
59, 60, 61, 62, 63, 75, 87, 88,
|
59
|
+
93, 98, 99, 101, 118, 119, 125, 131,
|
60
|
+
142, 143, 144, 146, 158, 159, 161, 162,
|
61
|
+
166, 175, 185, 189, 191, 199, 210, 211,
|
62
|
+
212, 213, 214, 215, 216, 217, 223, 227,
|
63
|
+
228, 229, 230, 231, 232, 233, 234, 240,
|
64
|
+
241, 243, 249, 250, 251, 252, 253, 259,
|
65
|
+
260, 261, 262, 268, 269, 270, 271, 277,
|
66
|
+
278, 280, 298, 316, 317, 323, 329, 346,
|
67
|
+
347, 351, 360, 370, 371, 373, 377, 379,
|
68
|
+
387, 398, 399, 400, 401, 402, 403, 404,
|
69
|
+
405, 411, 415, 416, 417, 418, 419, 420,
|
70
|
+
421, 422, 428, 429, 431, 432, 433, 434,
|
71
|
+
435, 441, 442, 443, 444, 450, 451, 452,
|
72
|
+
453, 459, 460, 462, 466, 470, 477, 485,
|
73
|
+
491, 500, 504, 508, 512, 516, 520, 520
|
74
|
+
};
|
75
|
+
|
76
|
+
static const char _jsonParser_trans_keys[] = {
|
77
|
+
32, 34, 39, 43, 45, 47, 48, 73,
|
78
|
+
91, 102, 110, 116, 123, 9, 13, 49,
|
79
|
+
57, 34, 47, 10, 13, 39, 48, 73,
|
80
|
+
49, 57, 43, 45, 48, 57, 48, 57,
|
81
|
+
110, 102, 105, 110, 105, 116, 121, 48,
|
82
|
+
73, 49, 57, 110, 102, 105, 110, 105,
|
83
|
+
116, 121, 47, 10, 13, 97, 108, 115,
|
84
|
+
101, 117, 108, 108, 114, 117, 101, 32,
|
85
|
+
34, 39, 47, 95, 125, 9, 13, 65,
|
86
|
+
90, 97, 122, 32, 34, 39, 47, 95,
|
87
|
+
125, 9, 13, 65, 90, 97, 122, 34,
|
88
|
+
32, 47, 58, 9, 13, 32, 47, 58,
|
89
|
+
9, 13, 47, 10, 13, 32, 34, 39,
|
90
|
+
43, 45, 47, 48, 73, 91, 102, 110,
|
91
|
+
116, 123, 9, 13, 49, 57, 34, 32,
|
92
|
+
44, 47, 125, 9, 13, 32, 44, 47,
|
93
|
+
125, 9, 13, 32, 34, 39, 47, 95,
|
94
|
+
9, 13, 65, 90, 97, 122, 39, 47,
|
95
|
+
10, 13, 32, 47, 58, 95, 9, 13,
|
96
|
+
48, 57, 65, 90, 97, 122, 47, 10,
|
97
|
+
13, 39, 48, 73, 49, 57, 32, 44,
|
98
|
+
46, 47, 69, 101, 125, 9, 13, 32,
|
99
|
+
44, 47, 69, 101, 125, 9, 13, 48,
|
100
|
+
57, 43, 45, 48, 57, 48, 57, 32,
|
101
|
+
44, 47, 125, 9, 13, 48, 57, 32,
|
102
|
+
44, 46, 47, 69, 101, 125, 9, 13,
|
103
|
+
48, 57, 110, 102, 105, 110, 105, 116,
|
104
|
+
121, 32, 44, 47, 125, 9, 13, 48,
|
105
|
+
73, 49, 57, 110, 102, 105, 110, 105,
|
106
|
+
116, 121, 32, 44, 47, 125, 9, 13,
|
107
|
+
47, 10, 13, 32, 44, 47, 125, 9,
|
108
|
+
13, 97, 108, 115, 101, 32, 44, 47,
|
109
|
+
125, 9, 13, 117, 108, 108, 32, 44,
|
110
|
+
47, 125, 9, 13, 114, 117, 101, 32,
|
111
|
+
44, 47, 125, 9, 13, 47, 10, 13,
|
112
|
+
32, 34, 39, 43, 45, 47, 48, 73,
|
113
|
+
91, 93, 102, 110, 116, 123, 9, 13,
|
114
|
+
49, 57, 32, 34, 39, 43, 45, 47,
|
115
|
+
48, 73, 91, 93, 102, 110, 116, 123,
|
116
|
+
9, 13, 49, 57, 34, 32, 44, 47,
|
117
|
+
93, 9, 13, 32, 44, 47, 93, 9,
|
118
|
+
13, 32, 34, 39, 43, 45, 47, 48,
|
119
|
+
73, 91, 102, 110, 116, 123, 9, 13,
|
120
|
+
49, 57, 39, 48, 73, 49, 57, 32,
|
121
|
+
44, 46, 47, 69, 93, 101, 9, 13,
|
122
|
+
32, 44, 47, 69, 93, 101, 9, 13,
|
123
|
+
48, 57, 47, 10, 13, 43, 45, 48,
|
124
|
+
57, 48, 57, 32, 44, 47, 93, 9,
|
125
|
+
13, 48, 57, 32, 44, 46, 47, 69,
|
126
|
+
93, 101, 9, 13, 48, 57, 110, 102,
|
127
|
+
105, 110, 105, 116, 121, 32, 44, 47,
|
128
|
+
93, 9, 13, 48, 73, 49, 57, 110,
|
129
|
+
102, 105, 110, 105, 116, 121, 32, 44,
|
130
|
+
47, 93, 9, 13, 47, 10, 13, 97,
|
131
|
+
108, 115, 101, 32, 44, 47, 93, 9,
|
132
|
+
13, 117, 108, 108, 32, 44, 47, 93,
|
133
|
+
9, 13, 114, 117, 101, 32, 44, 47,
|
134
|
+
93, 9, 13, 47, 10, 13, 32, 47,
|
135
|
+
9, 13, 32, 47, 9, 13, 32, 46,
|
136
|
+
47, 69, 101, 9, 13, 32, 47, 69,
|
137
|
+
101, 9, 13, 48, 57, 32, 47, 9,
|
138
|
+
13, 48, 57, 32, 46, 47, 69, 101,
|
139
|
+
9, 13, 48, 57, 32, 47, 9, 13,
|
140
|
+
32, 47, 9, 13, 32, 47, 9, 13,
|
141
|
+
32, 47, 9, 13, 32, 47, 9, 13,
|
142
|
+
0
|
143
|
+
};
|
144
|
+
|
145
|
+
static const char _jsonParser_single_lengths[] = {
|
146
|
+
0, 13, 1, 1, 2, 1, 2, 2,
|
147
|
+
0, 1, 1, 1, 1, 1, 1, 1,
|
148
|
+
2, 1, 1, 1, 1, 1, 1, 1,
|
149
|
+
1, 2, 1, 1, 1, 1, 1, 1,
|
150
|
+
1, 1, 1, 1, 6, 6, 1, 3,
|
151
|
+
3, 1, 2, 13, 1, 4, 4, 5,
|
152
|
+
1, 1, 2, 4, 1, 2, 1, 2,
|
153
|
+
7, 6, 2, 0, 4, 7, 1, 1,
|
154
|
+
1, 1, 1, 1, 1, 4, 2, 1,
|
155
|
+
1, 1, 1, 1, 1, 1, 4, 1,
|
156
|
+
2, 4, 1, 1, 1, 1, 4, 1,
|
157
|
+
1, 1, 4, 1, 1, 1, 4, 1,
|
158
|
+
2, 14, 14, 1, 4, 4, 13, 1,
|
159
|
+
2, 7, 6, 1, 2, 2, 0, 4,
|
160
|
+
7, 1, 1, 1, 1, 1, 1, 1,
|
161
|
+
4, 2, 1, 1, 1, 1, 1, 1,
|
162
|
+
1, 4, 1, 2, 1, 1, 1, 1,
|
163
|
+
4, 1, 1, 1, 4, 1, 1, 1,
|
164
|
+
4, 1, 2, 2, 2, 5, 4, 2,
|
165
|
+
5, 2, 2, 2, 2, 2, 0, 0
|
166
|
+
};
|
167
|
+
|
168
|
+
static const char _jsonParser_range_lengths[] = {
|
169
|
+
0, 2, 0, 0, 0, 0, 1, 1,
|
170
|
+
1, 0, 0, 0, 0, 0, 0, 0,
|
171
|
+
1, 0, 0, 0, 0, 0, 0, 0,
|
172
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
173
|
+
0, 0, 0, 0, 3, 3, 0, 1,
|
174
|
+
1, 0, 0, 2, 0, 1, 1, 3,
|
175
|
+
0, 0, 0, 4, 0, 0, 0, 1,
|
176
|
+
1, 2, 1, 1, 2, 2, 0, 0,
|
177
|
+
0, 0, 0, 0, 0, 1, 1, 0,
|
178
|
+
0, 0, 0, 0, 0, 0, 1, 0,
|
179
|
+
0, 1, 0, 0, 0, 0, 1, 0,
|
180
|
+
0, 0, 1, 0, 0, 0, 1, 0,
|
181
|
+
0, 2, 2, 0, 1, 1, 2, 0,
|
182
|
+
1, 1, 2, 0, 0, 1, 1, 2,
|
183
|
+
2, 0, 0, 0, 0, 0, 0, 0,
|
184
|
+
1, 1, 0, 0, 0, 0, 0, 0,
|
185
|
+
0, 1, 0, 0, 0, 0, 0, 0,
|
186
|
+
1, 0, 0, 0, 1, 0, 0, 0,
|
187
|
+
1, 0, 0, 1, 1, 1, 2, 2,
|
188
|
+
2, 1, 1, 1, 1, 1, 0, 0
|
189
|
+
};
|
190
|
+
|
191
|
+
static const short _jsonParser_index_offsets[] = {
|
192
|
+
0, 0, 16, 18, 20, 23, 25, 29,
|
193
|
+
33, 35, 37, 39, 41, 43, 45, 47,
|
194
|
+
49, 53, 55, 57, 59, 61, 63, 65,
|
195
|
+
67, 69, 72, 74, 76, 78, 80, 82,
|
196
|
+
84, 86, 88, 90, 92, 102, 112, 114,
|
197
|
+
119, 124, 126, 129, 145, 147, 153, 159,
|
198
|
+
168, 170, 172, 175, 184, 186, 189, 191,
|
199
|
+
195, 204, 213, 217, 219, 226, 236, 238,
|
200
|
+
240, 242, 244, 246, 248, 250, 256, 260,
|
201
|
+
262, 264, 266, 268, 270, 272, 274, 280,
|
202
|
+
282, 285, 291, 293, 295, 297, 299, 305,
|
203
|
+
307, 309, 311, 317, 319, 321, 323, 329,
|
204
|
+
331, 334, 351, 368, 370, 376, 382, 398,
|
205
|
+
400, 404, 413, 422, 424, 427, 431, 433,
|
206
|
+
440, 450, 452, 454, 456, 458, 460, 462,
|
207
|
+
464, 470, 474, 476, 478, 480, 482, 484,
|
208
|
+
486, 488, 494, 496, 499, 501, 503, 505,
|
209
|
+
507, 513, 515, 517, 519, 525, 527, 529,
|
210
|
+
531, 537, 539, 542, 546, 550, 557, 564,
|
211
|
+
569, 577, 581, 585, 589, 593, 597, 598
|
212
|
+
};
|
213
|
+
|
214
|
+
static const unsigned char _jsonParser_trans_targs_wi[] = {
|
215
|
+
1, 2, 5, 6, 16, 24, 149, 9,
|
216
|
+
148, 26, 30, 33, 148, 1, 152, 0,
|
217
|
+
147, 2, 4, 0, 148, 148, 4, 147,
|
218
|
+
5, 149, 9, 152, 0, 8, 8, 151,
|
219
|
+
0, 151, 0, 10, 0, 11, 0, 12,
|
220
|
+
0, 13, 0, 14, 0, 15, 0, 153,
|
221
|
+
0, 149, 17, 152, 0, 18, 0, 19,
|
222
|
+
0, 20, 0, 21, 0, 22, 0, 23,
|
223
|
+
0, 154, 0, 25, 0, 1, 1, 25,
|
224
|
+
27, 0, 28, 0, 29, 0, 155, 0,
|
225
|
+
31, 0, 32, 0, 156, 0, 34, 0,
|
226
|
+
35, 0, 157, 0, 37, 38, 48, 95,
|
227
|
+
51, 158, 37, 51, 51, 0, 37, 38,
|
228
|
+
48, 95, 51, 158, 37, 51, 51, 0,
|
229
|
+
39, 38, 40, 41, 43, 40, 0, 40,
|
230
|
+
41, 43, 40, 0, 42, 0, 40, 40,
|
231
|
+
42, 43, 44, 54, 55, 70, 79, 56,
|
232
|
+
62, 81, 82, 87, 91, 81, 43, 61,
|
233
|
+
0, 45, 44, 46, 47, 52, 158, 46,
|
234
|
+
0, 46, 47, 52, 158, 46, 0, 47,
|
235
|
+
38, 48, 49, 51, 47, 51, 51, 0,
|
236
|
+
39, 48, 50, 0, 47, 47, 50, 40,
|
237
|
+
41, 43, 51, 40, 51, 51, 51, 0,
|
238
|
+
53, 0, 46, 46, 53, 45, 54, 56,
|
239
|
+
62, 61, 0, 46, 47, 57, 52, 58,
|
240
|
+
58, 158, 46, 0, 46, 47, 52, 58,
|
241
|
+
58, 158, 46, 57, 0, 59, 59, 60,
|
242
|
+
0, 60, 0, 46, 47, 52, 158, 46,
|
243
|
+
60, 0, 46, 47, 57, 52, 58, 58,
|
244
|
+
158, 46, 61, 0, 63, 0, 64, 0,
|
245
|
+
65, 0, 66, 0, 67, 0, 68, 0,
|
246
|
+
69, 0, 46, 47, 52, 158, 46, 0,
|
247
|
+
56, 71, 61, 0, 72, 0, 73, 0,
|
248
|
+
74, 0, 75, 0, 76, 0, 77, 0,
|
249
|
+
78, 0, 46, 47, 52, 158, 46, 0,
|
250
|
+
80, 0, 43, 43, 80, 46, 47, 52,
|
251
|
+
158, 46, 0, 83, 0, 84, 0, 85,
|
252
|
+
0, 86, 0, 46, 47, 52, 158, 46,
|
253
|
+
0, 88, 0, 89, 0, 90, 0, 46,
|
254
|
+
47, 52, 158, 46, 0, 92, 0, 93,
|
255
|
+
0, 94, 0, 46, 47, 52, 158, 46,
|
256
|
+
0, 96, 0, 37, 37, 96, 98, 99,
|
257
|
+
103, 104, 121, 145, 105, 113, 101, 159,
|
258
|
+
132, 137, 141, 101, 98, 112, 0, 98,
|
259
|
+
99, 103, 104, 121, 145, 105, 113, 101,
|
260
|
+
159, 132, 137, 141, 101, 98, 112, 0,
|
261
|
+
100, 99, 101, 102, 107, 159, 101, 0,
|
262
|
+
101, 102, 107, 159, 101, 0, 102, 99,
|
263
|
+
103, 104, 121, 130, 105, 113, 101, 132,
|
264
|
+
137, 141, 101, 102, 112, 0, 100, 103,
|
265
|
+
105, 113, 112, 0, 101, 102, 106, 107,
|
266
|
+
109, 159, 109, 101, 0, 101, 102, 107,
|
267
|
+
109, 159, 109, 101, 106, 0, 108, 0,
|
268
|
+
101, 101, 108, 110, 110, 111, 0, 111,
|
269
|
+
0, 101, 102, 107, 159, 101, 111, 0,
|
270
|
+
101, 102, 106, 107, 109, 159, 109, 101,
|
271
|
+
112, 0, 114, 0, 115, 0, 116, 0,
|
272
|
+
117, 0, 118, 0, 119, 0, 120, 0,
|
273
|
+
101, 102, 107, 159, 101, 0, 105, 122,
|
274
|
+
112, 0, 123, 0, 124, 0, 125, 0,
|
275
|
+
126, 0, 127, 0, 128, 0, 129, 0,
|
276
|
+
101, 102, 107, 159, 101, 0, 131, 0,
|
277
|
+
102, 102, 131, 133, 0, 134, 0, 135,
|
278
|
+
0, 136, 0, 101, 102, 107, 159, 101,
|
279
|
+
0, 138, 0, 139, 0, 140, 0, 101,
|
280
|
+
102, 107, 159, 101, 0, 142, 0, 143,
|
281
|
+
0, 144, 0, 101, 102, 107, 159, 101,
|
282
|
+
0, 146, 0, 98, 98, 146, 148, 3,
|
283
|
+
148, 0, 148, 3, 148, 0, 148, 150,
|
284
|
+
3, 7, 7, 148, 0, 148, 3, 7,
|
285
|
+
7, 148, 150, 0, 148, 3, 148, 151,
|
286
|
+
0, 148, 150, 3, 7, 7, 148, 152,
|
287
|
+
0, 148, 3, 148, 0, 148, 3, 148,
|
288
|
+
0, 148, 3, 148, 0, 148, 3, 148,
|
289
|
+
0, 148, 3, 148, 0, 0, 0, 0
|
290
|
+
};
|
291
|
+
|
292
|
+
static const unsigned char _jsonParser_trans_actions_wi[] = {
|
293
|
+
0, 15, 15, 7, 7, 0, 7, 0,
|
294
|
+
25, 0, 0, 0, 23, 0, 7, 0,
|
295
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
296
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
297
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
298
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
299
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
300
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
301
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
302
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
303
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
304
|
+
0, 0, 0, 0, 29, 82, 82, 29,
|
305
|
+
85, 88, 29, 85, 85, 0, 0, 15,
|
306
|
+
15, 0, 19, 31, 0, 19, 19, 0,
|
307
|
+
0, 0, 17, 17, 17, 17, 0, 0,
|
308
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
309
|
+
0, 0, 15, 15, 7, 7, 0, 7,
|
310
|
+
0, 25, 0, 0, 0, 23, 0, 7,
|
311
|
+
0, 0, 0, 73, 73, 73, 130, 73,
|
312
|
+
0, 0, 0, 0, 31, 0, 0, 0,
|
313
|
+
15, 15, 0, 19, 0, 19, 19, 0,
|
314
|
+
0, 0, 0, 0, 0, 0, 0, 21,
|
315
|
+
21, 21, 0, 21, 0, 0, 0, 0,
|
316
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
317
|
+
0, 0, 0, 55, 55, 0, 55, 0,
|
318
|
+
0, 118, 55, 0, 55, 55, 55, 0,
|
319
|
+
0, 118, 55, 0, 0, 0, 0, 0,
|
320
|
+
0, 0, 0, 55, 55, 55, 118, 55,
|
321
|
+
0, 0, 55, 55, 0, 55, 0, 0,
|
322
|
+
118, 55, 0, 0, 0, 0, 0, 0,
|
323
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
324
|
+
0, 0, 61, 61, 61, 122, 61, 0,
|
325
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
326
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
327
|
+
0, 0, 67, 67, 67, 126, 67, 0,
|
328
|
+
0, 0, 0, 0, 0, 27, 27, 27,
|
329
|
+
79, 27, 0, 0, 0, 0, 0, 0,
|
330
|
+
0, 0, 0, 49, 49, 49, 114, 49,
|
331
|
+
0, 0, 0, 0, 0, 0, 0, 37,
|
332
|
+
37, 37, 106, 37, 0, 0, 0, 0,
|
333
|
+
0, 0, 0, 43, 43, 43, 110, 43,
|
334
|
+
0, 0, 0, 0, 0, 0, 33, 94,
|
335
|
+
94, 91, 91, 33, 91, 33, 100, 103,
|
336
|
+
33, 33, 33, 97, 33, 91, 0, 0,
|
337
|
+
15, 15, 7, 7, 0, 7, 0, 25,
|
338
|
+
35, 0, 0, 0, 23, 0, 7, 0,
|
339
|
+
0, 0, 17, 17, 17, 76, 17, 0,
|
340
|
+
0, 0, 0, 35, 0, 0, 0, 15,
|
341
|
+
15, 7, 7, 0, 7, 0, 25, 0,
|
342
|
+
0, 0, 23, 0, 7, 0, 0, 0,
|
343
|
+
0, 0, 0, 0, 9, 9, 0, 9,
|
344
|
+
0, 58, 0, 9, 0, 9, 9, 9,
|
345
|
+
0, 58, 0, 9, 0, 0, 0, 0,
|
346
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
347
|
+
0, 9, 9, 9, 58, 9, 0, 0,
|
348
|
+
9, 9, 0, 9, 0, 58, 0, 9,
|
349
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
350
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
351
|
+
11, 11, 11, 64, 11, 0, 0, 0,
|
352
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
353
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
354
|
+
13, 13, 13, 70, 13, 0, 0, 0,
|
355
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
356
|
+
0, 0, 0, 5, 5, 5, 52, 5,
|
357
|
+
0, 0, 0, 0, 0, 0, 0, 1,
|
358
|
+
1, 1, 40, 1, 0, 0, 0, 0,
|
359
|
+
0, 0, 0, 3, 3, 3, 46, 3,
|
360
|
+
0, 0, 0, 0, 0, 0, 17, 17,
|
361
|
+
17, 0, 0, 0, 0, 0, 9, 0,
|
362
|
+
9, 0, 0, 9, 0, 9, 9, 0,
|
363
|
+
0, 9, 0, 0, 9, 9, 9, 0,
|
364
|
+
0, 9, 0, 9, 0, 0, 9, 0,
|
365
|
+
0, 11, 11, 11, 0, 13, 13, 13,
|
366
|
+
0, 5, 5, 5, 0, 1, 1, 1,
|
367
|
+
0, 3, 3, 3, 0, 0, 0, 0
|
368
|
+
};
|
369
|
+
|
370
|
+
static const int jsonParser_start = 1;
|
371
|
+
static const int jsonParser_first_final = 147;
|
372
|
+
static const int jsonParser_error = 0;
|
373
|
+
|
374
|
+
static const int jsonParser_en_main = 1;
|
375
|
+
static const int jsonParser_en_hash = 36;
|
376
|
+
static const int jsonParser_en_array = 97;
|
377
|
+
|
378
|
+
#line 91 "src/json/json_parser.rl"
|
379
|
+
|
380
|
+
jsonValue* jsonParser::parse(char* content, int size)
|
381
|
+
{
|
382
|
+
int cs;
|
383
|
+
int top;
|
384
|
+
int stack[20];
|
385
|
+
char numbuf[61];
|
386
|
+
const int numbufsz = 60;
|
387
|
+
|
388
|
+
char *ps = content;
|
389
|
+
char *p = ps;
|
390
|
+
char *pe = content + size;
|
391
|
+
|
392
|
+
// user defined
|
393
|
+
char* tstart = NULL;
|
394
|
+
std::vector<jsonValue*> values;
|
395
|
+
std::vector<int> array_i;
|
396
|
+
|
397
|
+
|
398
|
+
#line 399 "src/json/json_parser.cc"
|
399
|
+
{
|
400
|
+
cs = jsonParser_start;
|
401
|
+
top = 0;
|
402
|
+
}
|
403
|
+
#line 110 "src/json/json_parser.rl"
|
404
|
+
|
405
|
+
#line 406 "src/json/json_parser.cc"
|
406
|
+
{
|
407
|
+
int _klen;
|
408
|
+
unsigned int _trans;
|
409
|
+
const char *_acts;
|
410
|
+
unsigned int _nacts;
|
411
|
+
const char *_keys;
|
412
|
+
|
413
|
+
if ( p == pe )
|
414
|
+
goto _out;
|
415
|
+
if ( cs == 0 )
|
416
|
+
goto _out;
|
417
|
+
_resume:
|
418
|
+
_keys = _jsonParser_trans_keys + _jsonParser_key_offsets[cs];
|
419
|
+
_trans = _jsonParser_index_offsets[cs];
|
420
|
+
|
421
|
+
_klen = _jsonParser_single_lengths[cs];
|
422
|
+
if ( _klen > 0 ) {
|
423
|
+
const char *_lower = _keys;
|
424
|
+
const char *_mid;
|
425
|
+
const char *_upper = _keys + _klen - 1;
|
426
|
+
while (1) {
|
427
|
+
if ( _upper < _lower )
|
428
|
+
break;
|
429
|
+
|
430
|
+
_mid = _lower + ((_upper-_lower) >> 1);
|
431
|
+
if ( (*p) < *_mid )
|
432
|
+
_upper = _mid - 1;
|
433
|
+
else if ( (*p) > *_mid )
|
434
|
+
_lower = _mid + 1;
|
435
|
+
else {
|
436
|
+
_trans += (_mid - _keys);
|
437
|
+
goto _match;
|
438
|
+
}
|
439
|
+
}
|
440
|
+
_keys += _klen;
|
441
|
+
_trans += _klen;
|
442
|
+
}
|
443
|
+
|
444
|
+
_klen = _jsonParser_range_lengths[cs];
|
445
|
+
if ( _klen > 0 ) {
|
446
|
+
const char *_lower = _keys;
|
447
|
+
const char *_mid;
|
448
|
+
const char *_upper = _keys + (_klen<<1) - 2;
|
449
|
+
while (1) {
|
450
|
+
if ( _upper < _lower )
|
451
|
+
break;
|
452
|
+
|
453
|
+
_mid = _lower + (((_upper-_lower) >> 1) & ~1);
|
454
|
+
if ( (*p) < _mid[0] )
|
455
|
+
_upper = _mid - 2;
|
456
|
+
else if ( (*p) > _mid[1] )
|
457
|
+
_lower = _mid + 2;
|
458
|
+
else {
|
459
|
+
_trans += ((_mid - _keys)>>1);
|
460
|
+
goto _match;
|
461
|
+
}
|
462
|
+
}
|
463
|
+
_trans += _klen;
|
464
|
+
}
|
465
|
+
|
466
|
+
_match:
|
467
|
+
cs = _jsonParser_trans_targs_wi[_trans];
|
468
|
+
|
469
|
+
if ( _jsonParser_trans_actions_wi[_trans] == 0 )
|
470
|
+
goto _again;
|
471
|
+
|
472
|
+
_acts = _jsonParser_actions + _jsonParser_trans_actions_wi[_trans];
|
473
|
+
_nacts = (unsigned int) *_acts++;
|
474
|
+
while ( _nacts-- > 0 )
|
475
|
+
{
|
476
|
+
switch ( *_acts++ )
|
477
|
+
{
|
478
|
+
case 0:
|
479
|
+
#line 4 "src/json/json_parser.rl"
|
480
|
+
{ PB(new jsonNull()); }
|
481
|
+
break;
|
482
|
+
case 1:
|
483
|
+
#line 6 "src/json/json_parser.rl"
|
484
|
+
{ PB(new jsonTrue()); }
|
485
|
+
break;
|
486
|
+
case 2:
|
487
|
+
#line 8 "src/json/json_parser.rl"
|
488
|
+
{ PB(new jsonFalse()); }
|
489
|
+
break;
|
490
|
+
case 3:
|
491
|
+
#line 11 "src/json/json_parser.rl"
|
492
|
+
{ tstart=p; }
|
493
|
+
break;
|
494
|
+
case 4:
|
495
|
+
#line 11 "src/json/json_parser.rl"
|
496
|
+
{
|
497
|
+
PB(json_number(tstart, p, numbuf, numbufsz));
|
498
|
+
}
|
499
|
+
break;
|
500
|
+
case 5:
|
501
|
+
#line 15 "src/json/json_parser.rl"
|
502
|
+
{ PB(new jsonNumber(INFINITY)); }
|
503
|
+
break;
|
504
|
+
case 6:
|
505
|
+
#line 17 "src/json/json_parser.rl"
|
506
|
+
{ PB(new jsonNumber(-INFINITY)); }
|
507
|
+
break;
|
508
|
+
case 7:
|
509
|
+
#line 19 "src/json/json_parser.rl"
|
510
|
+
{ tstart=p; }
|
511
|
+
break;
|
512
|
+
case 8:
|
513
|
+
#line 19 "src/json/json_parser.rl"
|
514
|
+
{
|
515
|
+
PB(json_string(tstart+1, p-1));
|
516
|
+
}
|
517
|
+
break;
|
518
|
+
case 9:
|
519
|
+
#line 23 "src/json/json_parser.rl"
|
520
|
+
{ tstart=p; }
|
521
|
+
break;
|
522
|
+
case 10:
|
523
|
+
#line 23 "src/json/json_parser.rl"
|
524
|
+
{
|
525
|
+
PB(json_string(tstart, p));
|
526
|
+
}
|
527
|
+
break;
|
528
|
+
case 11:
|
529
|
+
#line 31 "src/json/json_parser.rl"
|
530
|
+
{ {stack[top++] = cs; cs = 36; goto _again;} }
|
531
|
+
break;
|
532
|
+
case 12:
|
533
|
+
#line 32 "src/json/json_parser.rl"
|
534
|
+
{ {stack[top++] = cs; cs = 97; goto _again;} }
|
535
|
+
break;
|
536
|
+
case 13:
|
537
|
+
#line 37 "src/json/json_parser.rl"
|
538
|
+
{
|
539
|
+
if (values.size() < 3) throw "invalid format";
|
540
|
+
jsonValue* v = values.back();
|
541
|
+
values.pop_back();
|
542
|
+
jsonString* k = (jsonString*) values.back();
|
543
|
+
values.pop_back();
|
544
|
+
jsonHash* h = (jsonHash*) values.back();
|
545
|
+
h->set(k, v);
|
546
|
+
}
|
547
|
+
break;
|
548
|
+
case 14:
|
549
|
+
#line 49 "src/json/json_parser.rl"
|
550
|
+
{ PB(new jsonHash());}
|
551
|
+
break;
|
552
|
+
case 15:
|
553
|
+
#line 49 "src/json/json_parser.rl"
|
554
|
+
{ {cs = stack[--top]; goto _again;} }
|
555
|
+
break;
|
556
|
+
case 16:
|
557
|
+
#line 53 "src/json/json_parser.rl"
|
558
|
+
{ array_i.push_back(values.size()); }
|
559
|
+
break;
|
560
|
+
case 17:
|
561
|
+
#line 53 "src/json/json_parser.rl"
|
562
|
+
{
|
563
|
+
jsonArray* a = new jsonArray();
|
564
|
+
for (int i=array_i.back(); i<values.size(); i++) a->push(values[i]);
|
565
|
+
while (values.size() > array_i.back()) values.pop_back();
|
566
|
+
PB(a);
|
567
|
+
array_i.pop_back();
|
568
|
+
{cs = stack[--top]; goto _again;}
|
569
|
+
}
|
570
|
+
break;
|
571
|
+
#line 572 "src/json/json_parser.cc"
|
572
|
+
}
|
573
|
+
}
|
574
|
+
|
575
|
+
_again:
|
576
|
+
if ( cs == 0 )
|
577
|
+
goto _out;
|
578
|
+
if ( ++p != pe )
|
579
|
+
goto _resume;
|
580
|
+
_out: {}
|
581
|
+
}
|
582
|
+
#line 111 "src/json/json_parser.rl"
|
583
|
+
|
584
|
+
if (p != pe)
|
585
|
+
{
|
586
|
+
int err_pos = (int)(p-ps);
|
587
|
+
std::cout << "error at: " << err_pos << std::endl;
|
588
|
+
throw "error occured while parsing";
|
589
|
+
}
|
590
|
+
|
591
|
+
if (values.size() != 1)
|
592
|
+
{
|
593
|
+
throw "error occured while parsing";
|
594
|
+
}
|
595
|
+
|
596
|
+
return values[0];
|
597
|
+
}
|
598
|
+
|
599
|
+
#include <fcntl.h>
|
600
|
+
#include <unistd.h>
|
601
|
+
|
602
|
+
jsonValue* jsonParser::parse_file(const char* filename)
|
603
|
+
{
|
604
|
+
int fh;
|
605
|
+
void *mem;
|
606
|
+
int size;
|
607
|
+
jsonValue* res;
|
608
|
+
|
609
|
+
fh = open(filename, O_RDONLY);
|
610
|
+
if (fh < 0)
|
611
|
+
{
|
612
|
+
throw "cannot open file";
|
613
|
+
}
|
614
|
+
|
615
|
+
size = lseek(fh, 0, SEEK_END);
|
616
|
+
if (size < 0)
|
617
|
+
{
|
618
|
+
throw "error";
|
619
|
+
}
|
620
|
+
lseek(fh, 0, SEEK_SET);
|
621
|
+
|
622
|
+
mem = malloc(size);
|
623
|
+
|
624
|
+
if (mem == NULL)
|
625
|
+
{
|
626
|
+
throw "malloc failed";
|
627
|
+
}
|
628
|
+
|
629
|
+
int c = read(fh, mem, size);
|
630
|
+
|
631
|
+
if (c != size)
|
632
|
+
{
|
633
|
+
throw "couldn't read entire file";
|
634
|
+
}
|
635
|
+
|
636
|
+
res = jsonParser::parse((char*)mem, size);
|
637
|
+
|
638
|
+
free(mem);
|
639
|
+
close(fh);
|
640
|
+
|
641
|
+
return res;
|
642
|
+
}
|
643
|
+
|
644
|
+
#ifdef WITHOUT_MMAP
|
645
|
+
jsonValue* jsonParser::parse_file_mmap(const char* filename)
|
646
|
+
{
|
647
|
+
return parse_file(filename);
|
648
|
+
}
|
649
|
+
#else
|
650
|
+
#include <sys/mman.h>
|
651
|
+
jsonValue* jsonParser::parse_file_mmap(const char* filename)
|
652
|
+
{
|
653
|
+
int fh;
|
654
|
+
void *mem;
|
655
|
+
int size;
|
656
|
+
jsonValue* res;
|
657
|
+
|
658
|
+
fh = open(filename, O_RDONLY);
|
659
|
+
if (fh < 0)
|
660
|
+
{
|
661
|
+
throw "cannot open file";
|
662
|
+
}
|
663
|
+
|
664
|
+
size = lseek(fh, 0, SEEK_END);
|
665
|
+
if (size < 0)
|
666
|
+
{
|
667
|
+
throw "error";
|
668
|
+
}
|
669
|
+
lseek(fh, 0, SEEK_SET);
|
670
|
+
|
671
|
+
mem = mmap(NULL, size, PROT_READ, MAP_SHARED, fh, 0);
|
672
|
+
|
673
|
+
if (mem == MAP_FAILED)
|
674
|
+
{
|
675
|
+
throw "mmap failed";
|
676
|
+
}
|
677
|
+
|
678
|
+
res = jsonParser::parse((char*)mem, size);
|
679
|
+
|
680
|
+
munmap(mem, size);
|
681
|
+
close(fh);
|
682
|
+
|
683
|
+
return res;
|
684
|
+
}
|
685
|
+
#endif
|