+ cleaned up directories
[qpalma.git] / ParaParser / ParaParser.h
1 #ifndef __PARAPARSER_H__
2 #define __PARAPARSER_H__
3
4 #include <Python.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/mman.h>
8 #include <sys/stat.h>
9 #include <map>
10 #include <vector>
11 #include <utility>
12 using namespace std;
13
14 struct KeyCmp {
15 //bool operator()( unsigned long s1, unsigned long s2 ) const {
16 bool operator()( int s1, int s2 ) const {
17 return ( s1 < s2 );
18 }
19 };
20
21 enum storage_mode { IN_VECTOR=0, IN_MAP=1 };
22
23 typedef unsigned long map_key_t;
24
25 typedef map<map_key_t,char**,KeyCmp> MAP;
26
27 typedef vector<char**> VECTOR;
28 typedef vector<pair<char*,char*> > PTR_VECTOR;
29
30
31 class ParaParser{
32
33 private:
34 char* format_string;
35 char** field_names;
36 size_t num_columns;
37 char** types_list;
38
39 void *reads_area;
40 off_t reads_filesize;
41
42 storage_mode current_mode;
43
44 MAP *entries;
45 VECTOR *v_entries;
46 PTR_VECTOR *v_ptr_entries;
47
48 public:
49 ParaParser(const char* fmt, char** _fields, int num_entries, storage_mode mode);
50 int parseFile(char* reads_filename);
51 //void create_entry_from_line(const char* current_line, char* format_string);
52 void create_entry_from_line(const char* current_line, char* format_string, char* lineBeginPtr, char* lineEndPtr);
53 PyObject* fetchEntry(map_key_t id);
54 int getSize(storage_mode mode) {
55 if ( current_mode == IN_VECTOR )
56 return v_entries->size();
57
58 if ( current_mode == IN_MAP )
59 return v_entries->size();
60
61 return -1;
62 }
63
64 ~ParaParser();
65 };
66
67
68
69 #endif // __PARAPARSER_H__
70