Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
solverstack
vite
Commits
658dddcf
Commit
658dddcf
authored
Feb 01, 2009
by
Pascal Noisette
Browse files
codage
parent
7840eff8
Changes
5
Hide whitespace changes
Inline
Side-by-side
parser/src/Definition.cpp
View file @
658dddcf
#include
"ParserDefinitionDecoder"
using
namespace
std
;
int
ParserDefinitionDecoder
::
definitions_number
(){
return
definitions
.
size
();
}
void
ParserDefinitionDecoder
::
store_definition
(
Line
&
line
,
ifstream
&
file
){
//read header of one definition
string
&
tokens
=
line
.
read_token
();
Definition
d
=
Definition
(
token
[
2
]);
Definitions
[
tokens
[
3
]]
=
d
;
//read list of parameters
while
(
line
.
store
(
f
))
{
if
(
line
==
"%EndEventDef"
)
break
;
tokens
=
line
.
read_token
();
if
(
tokens
.
length
()
!=
3
)
//warning();
;
d
.
store
(
token
[
1
],
token
[
2
]);
}
}
Definition
&
ParserDefinitionDecoder
::
get_definition
(
int
i
){
return
Definitions
[
i
];
}
parser/src/Definition.hpp
View file @
658dddcf
...
...
@@ -26,14 +26,29 @@ private:
int
typetoint
(
std
::
string
);
public:
/*!
* \brief : constructor
* \param : string event name
*
*/
Definition
(
String
&
eventname
);
/*!
* \brief : add a field
* \brief : add a field
to definition
* \param : name
* \param : value
*/
store
(
std
::
string
name
,
std
::
string
value
);
void
store
(
std
::
string
name
,
std
::
string
value
);
void
print
()
/*!
* \brief : print() : debug
*
*
*/
void
print
();
}
...
...
parser/src/Line.cpp
View file @
658dddcf
#include
<Line.hpp>
//std::vector<std::string> tokens;
// string buffer;
int
starttoken
(
int
*
cursor
){
while
(
line
[
cursor
]
==
' '
)
cursor
++
;
return
cursor
;
}
int
stopnexttoken
(
int
*
cursor
){
while
(
line
[
cursor
]
!=
' '
||
line
[
cursor
]
!=
'\n'
||
line
[
cursor
]
!=
'\0'
)
cursor
++
;
return
cursor
;
}
void
Line
::
store
(
std
::
ifstream
&
file
){
char
buffer
[
BUFFSIZE
];
file
.
getline
(
buffer
,
BUFFSIZE
);
string
line
=
buffer
;
this
.
store
(
line
);
}
void
Line
::
store
(
std
::
string
s
){
int
cursor
=
0
;
int
start
;
int
stop
;
while
(
cursor
<
line
.
length
())
{
start
=
starttoken
(
&
cursor
);
stop
=
endtoken
(
&
cursor
);
tokens
.
push_back
(
line
.
substr
(
start
,
stop
));
}
}
void
Line
::
tokenize
();
Line
::
Line
();
Line
::
Line
(
Line
&
);
Line
::~
Line
();
bool
Line
::
starts_with
(
std
::
string
&
s
)
{
return
tokens
[
0
].
compare
(
s
)
==
0
;
}
bool
Line
::
operator
==
(
std
::
string
s
)
{
Line
l
;
l
.
store
(
s
);
this
==
l
;
}
bool
Line
::
operator
==
(
Line
)
{
if
(
this
.
length
==
l
.
lentgth
)
{
for
(
int
i
=
0
;
i
<
this
.
length
();
i
++
)
if
(
this
.
item
(
i
)
==
l
.
item
(
i
))
return
false
;
return
true
}
else
return
false
;
}
std
::
string
&
Line
::
item
(
int
i
);
int
Line
::
length
();
parser/src/Line.hpp
View file @
658dddcf
...
...
@@ -3,6 +3,7 @@
#include
<string>
#include
<vector>
#define BUFFSIZE 256
/*! \class Line Line.hpp "../parser/src/Line.hpp"
* Contains the definition of a line.
...
...
@@ -12,7 +13,19 @@ class Line{
private:
std
::
vector
<
std
::
string
>
token
;
std
::
vector
<
std
::
string
>
tokens
;
/*!
* \brief tokenize() divide into tokens
*
*/
void
tokenize
();
public:
/*!
* \brief Constructor
...
...
@@ -26,32 +39,46 @@ public:
* \param : A reference of the line to be copied
*/
Line
(
Line
&
);
/*!
* \brief Destructor
* Destroy the line
*/
~
Line
();
/*!
* \param : the string we want to know if the line starts with it
* \return : true if th
s
line starts with the param, false else
* \return : true if th
e
line starts with the param, false else
*/
bool
starts_with
(
std
::
string
&
);
/*!
* \brief store() read the next line and divide into tokens
*
*/
bool
store
(
std
::
ifstream
&
);
void
store
(
std
::
ifstream
&
);
/*!
* \brief line compare
*
*/
bool
operator
==
(
std
::
string
&
);
/*!
* \brief
next
token i
f exist
* \brief
the ith
token i
n the line
*
*/
std
::
string
operator
[]
();
bool
operator
==
(
std
::
string
&
);
std
::
string
&
item
(
int
i
);
int
length
();
/*!
* \brief number of token
*
*/
int
length
();
};
...
...
parser/src/ParserDefinitionDecoder.cpp
View file @
658dddcf
using
namespace
std
;
int
ParserDefinitionDecoder
::
definitions_number
(){
return
definitions
.
size
();
}
void
ParserDefinitionDecoder
::
store_definition
(
Line
&
line
,
ifstream
&
file
){
//read header of one definition
line
.
store
(
file
);
Definition
d
=
Definition
(
line
.
item
(
2
));
Definitions
[
line
.
item
(
3
)]
=
d
;
//read list of parameters
while
(
line
.
store
(
file
))
{
if
(
line
==
"%EndEventDef"
)
break
;
if
(
line
.
length
()
!=
3
)
//warning();
;
d
.
store
(
line
.
item
(
1
),
line
.
item
(
2
));
}
}
Definition
&
ParserDefinitionDecoder
::
get_definition
(
int
i
){
return
Definitions
[
i
];
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment