Commit d41d5022 authored by GUYOT DOMINIQUE's avatar GUYOT DOMINIQUE
Browse files

Add getters and setters, get_index_size, get_next_index.

parent a4fa78ff
......@@ -24,17 +24,18 @@ using namespace::std;
struct Parser{
vector<string_view> chunks;
vector<string_view> atomics;
vector<int> states;
size_t index;
size_t index_size;
Parser(string input_file, string sentinel) : index(0){
Parser(string input_file, string sentinel) : index(0), index_size(0){
struct stat sfd;
int fd;
char* mmfile;
size_t size;
size_t pos = 0;
size_t chunk_size;
size_t atomic_size;
fd = open(input_file.c_str(), O_RDONLY);
fstat(fd,&sfd);
......@@ -43,25 +44,52 @@ struct Parser{
close(fd);
string_view mapview(mmfile,size);
string_view chunk;
string_view atomic;
while(pos < mapview.size()){
pos = mapview.find(sentinel, pos);
chunk_size = mapview.find(sentinel, pos + sentinel.size()) - pos;
chunk = mapview.substr(pos, chunk_size);
atomic_size = mapview.find(sentinel, pos + sentinel.size()) - pos;
atomic = mapview.substr(pos, atomic_size);
states.push_back(TODO);
chunks.push_back(chunk);
pos += chunk_size;
atomics.push_back(atomic);
pos += atomic_size;
index_size++;
}
chunks.shrink_to_fit();
atomics.shrink_to_fit();
states.shrink_to_fit();
}
}
~Parser(){
//munmap(mmfile, size);
}
string_view get_chunk(size_t i){
return(chunks[i]);
//get next index of state state
size_t get_next_index(int state){
size_t i;
for(i = index; i < index_size; i++){
if (states[i] == state) return(i);
}
return(i);
}
//get index_size
size_t get_index_size(){
return(index_size);
}
//get the atomic of index i
string_view get_atomic(size_t i){
return(atomics[i]);
}
//get state of index i
int get_state(size_t i){
return(states[i]);
}
//set state of index i to state
void set_state(size_t i, int state){
states[i] = state;
}
};
......@@ -69,10 +97,15 @@ struct Parser{
/*
int main(int argc, char** argv){
Parser* P = new Parser(string(argv[1]), string(">"));
cout << P->get_chunk(0);
size_t i;
P->set_state(0,DONE);
i = P->get_next_index(TODO);
cout << P->get_index_size() << endl;
if (i < P->get_index_size())
cout << P->get_atomic(i);
delete(P);
}
*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment