*
*/
-void ParaParser::create_entry_from_line(const char* current_line, char* format_string) {
+void ParaParser::create_entry_from_line(const char* current_line, char* format_string, char* lineBeginPtr, char* lineEndPtr) {
//printf("current line is %s",current_line);
// create an array of void ptrs
if ( current_mode == IN_VECTOR ) {
//printf("size is %zd\n",v_entries->size());
v_entries->push_back(current_entries);
+ v_ptr_entries->push_back(make_pair(lineBeginPtr,lineEndPtr));
//printf("size is %zd\n",v_entries->size());
}
}
off_t reads_filesize = reads_stat.st_size;
- //printf("Reads file is of size %lu bytes\n",(unsigned long) reads_filesize);
+ printf("Reads file is of size %lu bytes\n",(unsigned long) reads_filesize);
if ( current_mode == IN_VECTOR )
v_entries = new VECTOR();
}
close(reads_fid);
- //printf("Successfully mapped %lu bytes of reads file into memory\n",(unsigned long)reads_filesize);
+ printf("Successfully mapped %lu bytes of reads file into memory\n",(unsigned long)reads_filesize);
char* lineBeginPtr = (char*) reads_area;
char* lineEndPtr = (char*) reads_area;
int readCtr = 0;
int status = 0;
+ printf("Starting to parse file...\n");
+
while(1) {
if (strcmp(current_line,"") == 0)
break;
- create_entry_from_line(current_line,format_string);
+ create_entry_from_line(current_line,format_string,lineBeginPtr,lineEndPtr);
if (status != 0 )
printf("Error while parsing line (status=%d).",status);
readCtr += 1;
}
+ printf("Successfully parsed file !\n");
+
// unmap parsed file
status = munmap(reads_area,reads_filesize);
if(status != 0)
char** current_entry;
+ char* lineBeginPtr = 0;
+ char* lineEndPtr = 0;
+
if ( current_mode == IN_VECTOR ) {
//printf("IN_VECTOR mode\n");
if (id >= v_entries->size())
//printf("size %d\n",v_entries->size());
current_entry = (*v_entries)[id];
+ pair<char*,char*> ptr_pair = (*v_ptr_entries)[id];
+ lineBeginPtr = ptr_pair.first;
+ lineEndPtr = ptr_pair.second;
}
if ( current_mode == IN_MAP ) {
*/
//printf("end of fetchEntry\n");
+ PyObject *return_value = PyTuple_New(2);
+ PyTuple_SetItem(return_value,0,line_dict);
+
+ char* current_line = (char*) malloc(sizeof(char)*512);
+ memset(current_line,0,512);
+ unsigned long line_size = lineEndPtr - lineBeginPtr;
+ strncpy(current_line,lineBeginPtr,line_size);
+
+ PyObject *original_line = PyString_FromString(current_line);
+ PyTuple_SetItem(return_value,1,original_line);
+
return line_dict;
}
#include <Python.h>
#include <map>
#include <vector>
+#include <utility>
using namespace std;
struct KeyCmp {
typedef map<map_key_t,char**,KeyCmp> MAP;
typedef vector<char**> VECTOR;
+typedef vector<pair<char*,char*> > PTR_VECTOR;
class ParaParser{
MAP *entries;
VECTOR *v_entries;
+ PTR_VECTOR *v_ptr_entries;
public:
ParaParser(const char* fmt, char** _fields, int num_entries, storage_mode mode);
int parseFile(char* reads_filename);
- void create_entry_from_line(const char* current_line, char* format_string);
+ //void create_entry_from_line(const char* current_line, char* format_string);
+ void create_entry_from_line(const char* current_line, char* format_string, char* lineBeginPtr, char* lineEndPtr);
PyObject* fetchEntry(map_key_t id);
+ int getSize(storage_mode mode) {
+ if ( current_mode == IN_VECTOR )
+ return v_entries->size();
+
+ if ( current_mode == IN_MAP )
+ return v_entries->size();
+ }
~ParaParser(){}
};
+
+
#endif // __PARAPARSER_H__