evecache 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,110 @@
1
+ // libevecache - EVE Cache File Reader Library
2
+ // Copyright (C) 2009-2010 StackFoundry LLC and Yann Ramin
3
+ //
4
+ // This library is free software; you can redistribute it and/or
5
+ // modify it under the terms of the GNU General Public
6
+ // License as published by the Free Software Foundation; either
7
+ // version 2 of the License, or (at your option) any later version.
8
+ //
9
+ // This library is distributed in the hope that it will be useful,
10
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ // General Public License for more details.
13
+ //
14
+ // You should have received a copy of the GNU General Public
15
+ // License along with this library; if not, write to the Free Software
16
+ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+ //
18
+ // http://dev.eve-central.com/libevecache/
19
+ // http://gitorious.org/libevecache
20
+
21
+ #ifndef _EC_READER_H_
22
+ #define _EC_READER_H_
23
+
24
+ #include <string>
25
+ #include <vector>
26
+ #include "evecache/config.hpp"
27
+
28
+ namespace EveCache {
29
+
30
+ class CacheFile_Iterator;
31
+
32
+ class EVECACHE_API CacheFile {
33
+ public:
34
+
35
+ #ifdef WIN32
36
+ CacheFile(const std::wstring &filename);
37
+ #else
38
+ CacheFile(const std::string &filename);
39
+ #endif
40
+ CacheFile(const CacheFile&);
41
+ CacheFile(std::vector<unsigned char> &buf);
42
+ ~CacheFile();
43
+ bool readFile();
44
+ int getLength() const;
45
+ CacheFile_Iterator end() const;
46
+ CacheFile_Iterator begin() const;
47
+
48
+ unsigned char byteAt(int) const;
49
+ void peekAt(unsigned char* data, int at, int len) const;
50
+
51
+ private:
52
+ unsigned char* contents;
53
+ int length;
54
+ bool valid;
55
+ std::string filename;
56
+ std::wstring wfilename;
57
+ };
58
+
59
+ class EVECACHE_API CacheFile_Iterator { // This does not adhere to the iterator protocol, yet
60
+ public:
61
+ CacheFile_Iterator(CacheFile const*, int position, int valid_length);
62
+ CacheFile_Iterator(const CacheFile_Iterator&);
63
+ ~CacheFile_Iterator();
64
+
65
+ CacheFile_Iterator& operator=(const CacheFile_Iterator& other);
66
+ bool operator==(const CacheFile_Iterator& rhs) const;
67
+ bool operator!=(const CacheFile_Iterator& rhs) const;
68
+
69
+ bool atEnd() const;
70
+ int position() const;
71
+ int limit() const;
72
+ //CacheFile_Iterator operator+(CacheFile_Iterator& lhs, const int len) const;
73
+ CacheFile_Iterator& operator+=(int len);
74
+
75
+
76
+ int peekShort() const;
77
+ int peekInt() const;
78
+ unsigned char peekChar() const;
79
+ float peekFloat() const;
80
+ double peekDouble() const;
81
+ std::string peekString(int len) const;
82
+
83
+
84
+
85
+ int readShort();
86
+ int readInt();
87
+ unsigned char readChar();
88
+ float readFloat();
89
+ double readDouble();
90
+ std::string readString(int len);
91
+ long long readLongLong();
92
+
93
+ void seek(int pos);
94
+ bool advance(int len);
95
+ void setLimit(int limit);
96
+
97
+
98
+
99
+
100
+ private:
101
+ CacheFile const *cacheFile;
102
+ int lastPeek;
103
+ int pos;
104
+ int _limit;
105
+
106
+ };
107
+ };
108
+
109
+
110
+ #endif
@@ -0,0 +1,46 @@
1
+ // libevecache - EVE Cache File Reader Library
2
+ // Copyright (C) 2009-2010 StackFoundry LLC and Yann Ramin
3
+ //
4
+ // This program is free software: you can redistribute it and/or modify
5
+ // it under the terms of the GNU General Public License as published by
6
+ // the Free Software Foundation, either version 3 of the License, or
7
+ // (at your option) any later version.
8
+ //
9
+ // This program is distributed in the hope that it will be useful,
10
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ // GNU General Public License for more details.
13
+ //
14
+ // You should have received a copy of the GNU General Public License
15
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ //
17
+ // http://dev.eve-central.com/libevecache/
18
+ // http://gitorious.org/libevecache
19
+
20
+ #include "evecache/exceptions.hpp"
21
+
22
+ namespace EveCache {
23
+ EndOfFileException::EndOfFileException()
24
+ {
25
+ }
26
+
27
+ EndOfFileException::operator std::string () const
28
+ {
29
+ return std::string("End of file");
30
+ }
31
+
32
+ ParseException::ParseException(const std::string &m) : message(m)
33
+ {
34
+ }
35
+
36
+ ParseException::ParseException(const char*m)
37
+ {
38
+ message = std::string(m);
39
+ }
40
+
41
+ ParseException::operator std::string () const
42
+ {
43
+ return message;
44
+ }
45
+
46
+ };
@@ -0,0 +1,8 @@
1
+ require 'mkmf'
2
+
3
+ # swig -c++ -ruby -o evecache.cxx libevecache.i
4
+ # unless File.exists?("evecache.cxx")
5
+ # require 'FileUtils'
6
+ # FileUtils.mv("libevecache_wrap.cxx","evecache.cxx")
7
+ # end
8
+ create_makefile('evecache')
@@ -0,0 +1,431 @@
1
+ %module evecache
2
+
3
+ %{
4
+ #define SWIG_FILE_WITH_INIT
5
+ #include <vector>
6
+ #include <string>
7
+ #include "evecache/reader.hpp"
8
+ #include "evecache/parser.hpp"
9
+ #include "evecache/market.hpp"
10
+ %}
11
+
12
+ %include "std_string.i"
13
+ %include "std_vector.i"
14
+
15
+
16
+ namespace EveCache {
17
+
18
+ typedef enum {
19
+ EStreamStart = 0x7e,
20
+ ETuple = 0x14, // a tuple of N objects
21
+ ETuple2 = 0x15, // a tuple of N objects, variant 2
22
+ E2Tuple = 0x2c, // a tuple of 2 objects
23
+ E1Tuple = 0x25, // a tuple of 1 objects
24
+ E1Tuple2 = 0x27, // a tuple of 1 objects, variant 2
25
+ E0Tuple = 0x24, // a tuple of 0 objects
26
+ E0Tuple2 = 0x26,
27
+ EMarker = 0x11, // A one byte identifier code
28
+ EIdent = 0x13, // an identifier string
29
+ EString = 0x2, // Another type of string, also ids
30
+ EString2 = 0x2e, // stringtastic
31
+ EString3 = 0xf, // really? another? single character string
32
+ EString4 = 0x10,
33
+ EUnicodeString = 0x12,
34
+ EUnicodeString2 = 0x29,
35
+ EEmptyString = 0x28, // empty
36
+ EInteger = 0x04, // 4 byte, little endian?
37
+ EReal = 0x0a, // floating point, 64 bits, assume matches machine double type
38
+ E0Real = 0x0b,
39
+ E0Integer = 0x08, // int == 0
40
+ ENeg1Integer = 0x07, // int == -1
41
+ E1Integer = 0x09, // int == 1
42
+ EBoolTrue = 0x1f,
43
+ EBoolFalse = 0x20,
44
+ EByte = 0x6, // i think
45
+ ESizedInt = 0x2f, // when you can't decide ahead of time how long to make the integer...
46
+ EShort = 0x05, // 2 byte
47
+ EDict = 0x16, // N objects, consisting of key object and value object
48
+ EObject = 0x17, // Object type ?
49
+ ENone = 0x01, // Python None type
50
+ ESubstream = 0x2b, // substream - len bytes followed by 0x7e
51
+ ELongLong = 0x3, // 64 bit value?
52
+ ECompressedRow = 0x2a, // the datatype from hell, a RLEish compressed row
53
+ EObject22 = 0x22, // a database header field of some variety
54
+ EObject23 = 0x23, // another datatype containing ECompressedRows/DBRows
55
+ ESharedObj = 0x1b, // shared object reference
56
+ } EStreamCode;
57
+
58
+
59
+ class CacheFile_Iterator;
60
+
61
+ /***********************************************************************/
62
+
63
+ class SNode {
64
+ public:
65
+ SNode(EStreamCode t);
66
+ SNode(const SNode&);
67
+ virtual ~SNode();
68
+ virtual std::string repl() const;
69
+ virtual EStreamCode type() const;
70
+ virtual void setType(EStreamCode t);
71
+ virtual void addMember(SNode* node);
72
+ virtual const std::vector<SNode*>& members() const;
73
+ virtual SNode* clone() const;
74
+ };
75
+
76
+ /***********************************************************************/
77
+
78
+ class SStreamNode : public SNode {
79
+ public:
80
+ SStreamNode();
81
+ SStreamNode(EStreamCode t);
82
+ SStreamNode(const SStreamNode &rhs);
83
+ virtual ~SStreamNode() { }
84
+ virtual std::string repl() const;
85
+ virtual SStreamNode* clone() const;
86
+ protected:
87
+
88
+ };
89
+
90
+ /***********************************************************************/
91
+
92
+ class SDBHeader : public SNode {
93
+ public:
94
+ SDBHeader();
95
+ virtual std::string repl() const;
96
+ virtual SDBHeader* clone() const;
97
+ };
98
+
99
+
100
+ /***********************************************************************/
101
+
102
+ class STuple : public SNode {
103
+ public:
104
+ STuple(unsigned int len);
105
+ STuple(const STuple &rhs);
106
+ virtual ~STuple();
107
+ virtual unsigned int givenLength() const;
108
+ virtual void addMember(SNode* node);
109
+ virtual std::string repl() const;
110
+ virtual STuple* clone() const;
111
+ protected:
112
+ unsigned int _givenLength;
113
+ };
114
+
115
+ /***********************************************************************/
116
+
117
+ class SDict : public SNode {
118
+ public:
119
+ SDict(unsigned int len);
120
+ SDict(const SDict &);
121
+ virtual ~SDict();
122
+ virtual unsigned int givenLength() const;
123
+ virtual void addMember(SNode* node);
124
+ virtual std::string repl() const;
125
+ virtual SDict* clone() const;
126
+ virtual SNode* getByName(const std::string& target) const;
127
+ protected:
128
+ unsigned int _givenLength;
129
+ };
130
+
131
+
132
+ /***********************************************************************/
133
+
134
+ class SNone : public SNode {
135
+ public:
136
+ SNone();
137
+ virtual std::string repl() const;
138
+ virtual SNone* clone() const;
139
+ };
140
+
141
+
142
+ /***********************************************************************/
143
+
144
+ class SMarker : public SNode {
145
+ public:
146
+ SMarker(unsigned char id);
147
+ virtual unsigned char id() const;
148
+ virtual std::string string() const;
149
+ virtual std::string repl() const;
150
+ virtual SMarker* clone() const;
151
+ protected:
152
+ unsigned char _id;
153
+ };
154
+
155
+ /***********************************************************************/
156
+
157
+ class SIdent : public SNode {
158
+ public:
159
+ SIdent(const std::string& m);
160
+ virtual std::string name() const;
161
+ virtual std::string repl() const;
162
+ virtual SIdent* clone() const;
163
+ protected:
164
+ std::string _name;
165
+ };
166
+
167
+ /***********************************************************************/
168
+
169
+ class SString : public SNode {
170
+ public:
171
+ SString(const std::string& m);
172
+ virtual std::string string() const;
173
+ virtual std::string repl() const;
174
+ virtual SString* clone() const;
175
+ protected:
176
+ std::string _name;
177
+ };
178
+
179
+ /***********************************************************************/
180
+
181
+ class SInt : public SNode {
182
+ public:
183
+ SInt(int val);
184
+ virtual int value() const;
185
+ virtual std::string repl() const;
186
+ virtual SInt* clone() const;
187
+ };
188
+
189
+ /***********************************************************************/
190
+
191
+ class SReal : public SNode {
192
+ public:
193
+ SReal(double val);
194
+ virtual double value() const;
195
+ virtual std::string repl() const;
196
+ virtual SReal* clone() const;
197
+ };
198
+
199
+
200
+ /***********************************************************************/
201
+
202
+ class SLongLong : public SNode {
203
+ public:
204
+ SLongLong(long long val);
205
+ virtual long long value() const;
206
+ virtual std::string repl() const;
207
+ virtual SLongLong* clone() const;
208
+ };
209
+
210
+ /***********************************************************************/
211
+
212
+ class SObject : public SNode {
213
+ public:
214
+ SObject();
215
+ virtual std::string name() const;
216
+ virtual std::string repl() const;
217
+ virtual SObject* clone() const;
218
+ private:
219
+ };
220
+
221
+
222
+ /***********************************************************************/
223
+
224
+ class SSubstream : public SNode {
225
+ public:
226
+ SSubstream(int len);
227
+ virtual std::string repl() const;
228
+ virtual SSubstream* clone() const;
229
+ };
230
+
231
+ /***********************************************************************/
232
+
233
+ class SDBRow : public SNode {
234
+ public:
235
+ SDBRow(int magic, const std::vector<unsigned char>& data);
236
+ bool isLast() const;
237
+ void setLast(bool l);
238
+ virtual std::string repl() const;
239
+ virtual SDBRow* clone() const;
240
+ };
241
+
242
+ /***********************************************************************/
243
+
244
+ class SDBRecords : public SNode {
245
+ public:
246
+ SDBRecords();
247
+ virtual std::string repl() const;
248
+ virtual SDBRecords* clone() const;
249
+ };
250
+
251
+ /***********************************************************************/
252
+
253
+ class Parser {
254
+ public:
255
+ Parser(CacheFile_Iterator *iter);
256
+ ~Parser();
257
+ void parse();
258
+ std::vector<SNode*> streams() const;
259
+ protected:
260
+ SNode* parseone();
261
+ void parse(SNode* node, int limit);
262
+ SNode* getDBRow();
263
+ int getLen();
264
+ unsigned int shareInit();
265
+ void shareAdd(SNode* obj);
266
+ SNode* shareGet(unsigned int id);
267
+ void shareSkip();
268
+ };
269
+
270
+
271
+ /**
272
+ * Domain object for a market order
273
+ */
274
+ class MarketOrder {
275
+ public:
276
+
277
+ MarketOrder() {}
278
+
279
+ /**
280
+ * Utility
281
+ */
282
+
283
+ /**
284
+ * Return this item as a standard CSV file export line
285
+ */
286
+ std::string toCsv() const;
287
+
288
+ /**
289
+ * Data setters
290
+ */
291
+
292
+ void setPrice(unsigned long long v) { _price = v; }
293
+ void setVolRemaining(double v) { _volRemaining = v; }
294
+ void setRange(unsigned int v) { _range = v; }
295
+ void setOrderID(unsigned long long v) { _orderID = v; }
296
+ void setVolEntered(unsigned int v) { _volEntered = v; }
297
+ void setMinVolume(unsigned int v) { _minVolume = v; }
298
+ void setBid(bool b) { _bid = b; }
299
+ void setIssued(unsigned long long v) { _issued = v; }
300
+ void setDuration(unsigned int v) { _duration = v; }
301
+ void setStationID(unsigned int v) { _stationID = v; }
302
+ void setRegionID(unsigned int v) { _regionID = v; }
303
+ void setSolarSystemID(unsigned int v) { _solarSystemID = v; }
304
+ void setJumps(unsigned int v) { _jumps = v; }
305
+ void setType(unsigned int v) { _type = v; }
306
+
307
+ /**
308
+ * Data accessors
309
+ */
310
+ unsigned long long price() const { return _price; }
311
+ double volRemaining() const { return _volRemaining; }
312
+ unsigned int range() const { return _range; }
313
+ unsigned long long orderID() const { return _orderID; }
314
+ unsigned int volEntered() const { return _volEntered; }
315
+ unsigned int minVolume() const { return _minVolume; }
316
+ bool isBid() const { return _bid; }
317
+ unsigned long long issued() const { return _issued; }
318
+ unsigned int duration() const { return _duration; }
319
+ unsigned int stationID() const { return _stationID; }
320
+ unsigned int regionID() const { return _regionID; }
321
+ unsigned int solarSystemID() const { return _solarSystemID; }
322
+ unsigned int jumps() const { return _jumps; }
323
+ unsigned int type() const { return _type; }
324
+
325
+ };
326
+
327
+
328
+ class MarketList {
329
+ public:
330
+ MarketList(int type, int region);
331
+ MarketList();
332
+ MarketList(const MarketList &rhs) {
333
+ _type = rhs._type;
334
+ _region = rhs._region;
335
+ _sellOrders = rhs._sellOrders;
336
+ _buyOrders = rhs._buyOrders;
337
+ }
338
+
339
+
340
+ void setType(int v) { _type = v; }
341
+ void setRegion(int r) { _region = r; }
342
+ void setTimestamp(unsigned long t) { _ts = t; }
343
+
344
+ int type() const { return _type; }
345
+ int region() const { return _region; }
346
+ unsigned long timestamp() const { return _ts; }
347
+
348
+ std::vector<MarketOrder> getSellOrders() const { return _sellOrders; }
349
+ std::vector<MarketOrder> getBuyOrders() const { return _buyOrders; }
350
+
351
+ void addOrder(MarketOrder& order);
352
+
353
+ };
354
+
355
+
356
+ class MarketParser {
357
+ public:
358
+ MarketParser(const SNode *stream);
359
+ ~MarketParser();
360
+ MarketList getList() const;
361
+ void parse();
362
+ bool valid() const;
363
+ MarketParser(const char* fileName);
364
+ MarketParser(const std::string fileName);
365
+
366
+ };
367
+
368
+
369
+ class CacheFile {
370
+ public:
371
+ CacheFile(const std::string &filename);
372
+ CacheFile(const CacheFile&);
373
+ CacheFile(std::vector<unsigned char> &buf);
374
+ ~CacheFile();
375
+ bool readFile();
376
+ int getLength() const;
377
+ CacheFile_Iterator end() const;
378
+ CacheFile_Iterator begin() const;
379
+
380
+ unsigned char byteAt(int) const;
381
+ void peekAt(unsigned char* data, int at, int len) const;
382
+
383
+ };
384
+
385
+ class CacheFile_Iterator { // This does not adhere to the iterator protocol, yet
386
+ public:
387
+ CacheFile_Iterator(CacheFile const*, int position, int valid_length);
388
+ CacheFile_Iterator(const CacheFile_Iterator&);
389
+ ~CacheFile_Iterator();
390
+
391
+ CacheFile_Iterator& operator=(const CacheFile_Iterator& other);
392
+ bool operator==(const CacheFile_Iterator& rhs) const;
393
+ bool operator!=(const CacheFile_Iterator& rhs) const;
394
+
395
+ bool atEnd() const;
396
+ int position() const;
397
+ int limit() const;
398
+ //CacheFile_Iterator operator+(CacheFile_Iterator& lhs, const int len) const;
399
+ CacheFile_Iterator& operator+=(int len);
400
+
401
+
402
+ int peekShort() const;
403
+ int peekInt() const;
404
+ unsigned char peekChar() const;
405
+ float peekFloat() const;
406
+ double peekDouble() const;
407
+ std::string peekString(int len) const;
408
+
409
+
410
+
411
+ int readShort();
412
+ int readInt();
413
+ unsigned char readChar();
414
+ float readFloat();
415
+ double readDouble();
416
+ std::string readString(int len);
417
+ long long readLongLong();
418
+
419
+ void seek(int pos);
420
+ bool advance(int len);
421
+ void setLimit(int limit);
422
+
423
+ };
424
+
425
+ }
426
+
427
+
428
+ namespace std {
429
+ %template (MarketOrderVector) vector<EveCache::MarketOrder>;
430
+ %template (UnsignedCharVector) vector<unsigned char>;
431
+ }