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