-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneral.h
More file actions
113 lines (100 loc) · 4.16 KB
/
Copy pathgeneral.h
File metadata and controls
113 lines (100 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef __STR_H__
#define __STR_H__
#include <string.h>
#endif
#ifndef __VEC_H__
#define __VEC_H__
#include <vector>
#endif
#ifndef __IOS_H__
#define __IOS_H__
#include <iostream>
#endif
#include <stdlib.h>
namespace general{
using namespace std;
//!Exception for Input/Output
class ExceptionIO{
std::string mess;
public:
//! Empty constructors
ExceptionIO() {mess="";};
//! constructor takes in input a message
ExceptionIO(std::string mess) {this->mess=mess;};
//! \name Get of methods use to access at the data structures
//@{
//!it returns message
std::string get(void) {return mess;};
//@}
};
class Parser{
protected:
//it redefines the << operator
std::string delims;
vector <std::string> token;
public:
//! Empty constructors
Parser() {delims="";};
//! constructor takes the list of delimiters plus the string that must be parsed
Parser(const std::string& delims, const std::string& buffer);
//! constructor takes the list of delimiters plus the string (char*) that must be parsed
Parser(const std::string& delims, char* buffer);
//! \name Set of methods use to update the data structures
//@{
//it uses to parse a new string with new delimiters
void update(const std::string& delims, const std::string& buffer);
//it uses to parse a new string(char*) with new delimiters
void update(const std::string& delims, char* buffer);
//it updates the string token in position ith with a input string.
void set(const int&,std::string);
//@}
//! \name Get of methods use to access at the data structures
//@{
//it returns the index of the occurrence of the string test in token vector the otherwise -1
int find(const std::string& test);
//it returns the index of the occurrence of the string test or the string test2 in token vector otherwise -1. Observe that it returns the first index that satisfies the condition.
int findD(const std::string& test,const std::string& test2);
//it returns the index of the occurrence of the string test in token vector the otherwise -1. Observe it tests on string with the same size.
int findS(const std::string& test);
//it returns the token in position i
std::string get(int i);
//it returns the number of tokens
unsigned int size(void) {return token.size();};
//it returns a new string obtained removing all the dilimiter char
std::string get_string(void);
//it returns a new string obtained removing all the delimiter chars and splitting all the block with a new delimitator passed as paramiter
std::string get_string(char delim);
//@}
friend ostream& operator<<(ostream& out,class Parser& data);
};
//This class uses delimiters as a unique string this is different by the normal use (e.i. strtok)
//Es. string=pippi delim=po the algorithm does not split the string
class ParserB:Parser
{
public:
//! Empty constructors
ParserB() {Parser();};
//! constructor takes the list of delimiters plus the string that must be parsed
ParserB(const std::string& delims, const std::string& buffer);
//! \name Set of methods use to update the data structures
//@{
//it uses to parse a new string with new delimiters
void update(const std::string& delims, const std::string& buffer);
//@}
//! \name Get of methods use to access at the data structures
//@{
//it returns the index of the occurrence of the string test in token vector the otherwise -1
int find(const std::string& test){return Parser::find(test);};
//it returns the index of the occurrence of the string test or the string test2 in token vector otherwise -1. Observe that it returns the first index that satisfies the condition.
int findD(const std::string& test,const std::string& test2){return Parser::findD(test,test2);};
//it returns the index of the occurrence of the string test in token vector the otherwise -1. Observe it tests on string with the same size.
int findS(const std::string& test){return Parser::findS(test);};
//it returns the token in position i
std::string get(int i){return Parser::get(i);};
//it returns the number of tokens
unsigned int size(void) {return Parser::size();};
//it returns a new string obtained removing all the dilimiter char
std::string get_string(void){ return Parser::get_string();};
//@}
};
}