Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sdk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Openvibe Group
sdk
Commits
fed9052d
Commit
fed9052d
authored
5 years ago
by
MONSEIGNE Thibaut
Browse files
Options
Downloads
Patches
Plain Diff
Enum Parsing Status
parent
b797fb76
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!152
Reduce Type conversion and modernize enum type (when it's easy)
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
toolkit/src/tools/ovtkMatrix.cpp
+18
-27
18 additions, 27 deletions
toolkit/src/tools/ovtkMatrix.cpp
with
18 additions
and
27 deletions
toolkit/src/tools/ovtkMatrix.cpp
+
18
−
27
View file @
fed9052d
...
@@ -105,15 +105,7 @@ bool Matrix::isContentValid(const IMatrix& src, const bool checkNotANumber, cons
...
@@ -105,15 +105,7 @@ bool Matrix::isContentValid(const IMatrix& src, const bool checkNotANumber, cons
return
true
;
return
true
;
}
}
enum
EStatus
enum
class
EParsingStatus
{
Nothing
,
ParsingHeader
,
ParsingHeaderDimension
,
ParsingHeaderLabel
,
ParsingBuffer
,
ParsingBufferValue
};
{
Status_Nothing
,
Status_ParsingHeader
,
Status_ParsingHeaderDimension
,
Status_ParsingHeaderLabel
,
Status_ParsingBuffer
,
Status_ParsingBufferValue
};
// tokens in the ascii matrix format
// tokens in the ascii matrix format
const
char
CONSTANT_LEFT_SQUARE_BRACKET
=
'['
;
const
char
CONSTANT_LEFT_SQUARE_BRACKET
=
'['
;
...
@@ -135,7 +127,7 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
...
@@ -135,7 +127,7 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
//current string to parse
//current string to parse
std
::
string
what
;
std
::
string
what
;
//current parsing status
//current parsing status
size_t
status
=
Status
_
Nothing
;
EParsingStatus
status
=
EParsing
Status
::
Nothing
;
//current element index (incremented every time a value is stored in matrix)
//current element index (incremented every time a value is stored in matrix)
size_t
curElementIdx
=
0
;
size_t
curElementIdx
=
0
;
//current dimension index
//current dimension index
...
@@ -172,17 +164,17 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
...
@@ -172,17 +164,17 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
switch
(
status
)
switch
(
status
)
{
{
//initial parsing status
//initial parsing status
case
Status
_
Nothing
:
case
EParsing
Status
::
Nothing
:
//comments starting
//comments starting
if
(
*
it
==
CONSTANT_HASHTAG
)
{
it
=
what
.
end
()
-
1
;
}
// ignore rest of line by skipping to last character
if
(
*
it
==
CONSTANT_HASHTAG
)
{
it
=
what
.
end
()
-
1
;
}
// ignore rest of line by skipping to last character
//header starting
//header starting
else
if
(
*
it
==
CONSTANT_LEFT_SQUARE_BRACKET
)
{
status
=
Status
_
ParsingHeader
;
}
// update status
else
if
(
*
it
==
CONSTANT_LEFT_SQUARE_BRACKET
)
{
status
=
EParsing
Status
::
ParsingHeader
;
}
// update status
else
if
(
!
std
::
isspace
(
*
it
,
locale
))
{
return
false
;
}
else
if
(
!
std
::
isspace
(
*
it
,
locale
))
{
return
false
;
}
break
;
break
;
//parse header
//parse header
case
Status
_
ParsingHeader
:
case
EParsing
Status
::
ParsingHeader
:
//comments starting
//comments starting
if
(
*
it
==
CONSTANT_HASHTAG
)
{
it
=
what
.
end
()
-
1
;
}
//ignore rest of line by skipping to last character
if
(
*
it
==
CONSTANT_HASHTAG
)
{
it
=
what
.
end
()
-
1
;
}
//ignore rest of line by skipping to last character
...
@@ -191,7 +183,7 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
...
@@ -191,7 +183,7 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
{
{
dimSize
.
resize
(
dimSize
.
size
()
+
1
);
//increment dimension count
dimSize
.
resize
(
dimSize
.
size
()
+
1
);
//increment dimension count
curDimIdx
++
;
//update current dimension index
curDimIdx
++
;
//update current dimension index
status
=
Status
_
ParsingHeaderDimension
;
//update status
status
=
EParsing
Status
::
ParsingHeaderDimension
;
//update status
}
}
//finished parsing header
//finished parsing header
else
if
(
*
it
==
CONSTANT_RIGHT_SQUARE_BRACKET
)
else
if
(
*
it
==
CONSTANT_RIGHT_SQUARE_BRACKET
)
...
@@ -215,12 +207,12 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
...
@@ -215,12 +207,12 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
//reset current dimension index
//reset current dimension index
curDimIdx
=
size_t
(
-
1
);
curDimIdx
=
size_t
(
-
1
);
//update status
//update status
status
=
Status
_
ParsingBuffer
;
status
=
EParsing
Status
::
ParsingBuffer
;
}
}
else
if
(
!
std
::
isspace
(
*
it
,
locale
))
{
return
false
;
}
else
if
(
!
std
::
isspace
(
*
it
,
locale
))
{
return
false
;
}
break
;
break
;
case
Status
_
ParsingHeaderDimension
:
case
EParsing
Status
::
ParsingHeaderDimension
:
//comments starting
//comments starting
if
(
*
it
==
CONSTANT_HASHTAG
)
{
it
=
what
.
end
()
-
1
;
}
//ignore rest of line by skipping to last character
if
(
*
it
==
CONSTANT_HASHTAG
)
{
it
=
what
.
end
()
-
1
;
}
//ignore rest of line by skipping to last character
...
@@ -230,15 +222,15 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
...
@@ -230,15 +222,15 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
//new element found in current dimension
//new element found in current dimension
dimSize
[
curDimIdx
]
++
;
dimSize
[
curDimIdx
]
++
;
//update status
//update status
status
=
Status
_
ParsingHeaderLabel
;
status
=
EParsing
Status
::
ParsingHeaderLabel
;
}
}
//finished parsing current dimension header
//finished parsing current dimension header
else
if
(
*
it
==
CONSTANT_RIGHT_SQUARE_BRACKET
)
{
status
=
Status
_
ParsingHeader
;
}
//update status
else
if
(
*
it
==
CONSTANT_RIGHT_SQUARE_BRACKET
)
{
status
=
EParsing
Status
::
ParsingHeader
;
}
//update status
else
if
(
!
std
::
isspace
(
*
it
,
locale
))
{
return
false
;
}
else
if
(
!
std
::
isspace
(
*
it
,
locale
))
{
return
false
;
}
break
;
break
;
//look for end of label (first '"' char not preceded by the '\' escape char)
//look for end of label (first '"' char not preceded by the '\' escape char)
case
Status
_
ParsingHeaderLabel
:
case
EParsing
Status
::
ParsingHeaderLabel
:
//found '"' char not preceded by escape char : end of label reached
//found '"' char not preceded by escape char : end of label reached
if
(
*
it
==
CONSTANT_DOUBLE_QUOTE
&&
*
(
it
-
1
)
!=
'\\'
)
if
(
*
it
==
CONSTANT_DOUBLE_QUOTE
&&
*
(
it
-
1
)
!=
'\\'
)
...
@@ -252,13 +244,13 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
...
@@ -252,13 +244,13 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
curString
.
erase
();
curString
.
erase
();
//update status
//update status
status
=
Status
_
ParsingHeaderDimension
;
status
=
EParsing
Status
::
ParsingHeaderDimension
;
}
}
//otherwise, keep parsing current label
//otherwise, keep parsing current label
else
{
curString
.
append
(
1
,
*
it
);
}
else
{
curString
.
append
(
1
,
*
it
);
}
break
;
break
;
case
Status
_
ParsingBuffer
:
case
EParsing
Status
::
ParsingBuffer
:
//comments starting
//comments starting
if
(
*
it
==
CONSTANT_HASHTAG
)
{
it
=
what
.
end
()
-
1
;
}
//ignore rest of line by skipping to last character
if
(
*
it
==
CONSTANT_HASHTAG
)
{
it
=
what
.
end
()
-
1
;
}
//ignore rest of line by skipping to last character
...
@@ -307,14 +299,14 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
...
@@ -307,14 +299,14 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
curString
.
append
(
1
,
*
it
);
curString
.
append
(
1
,
*
it
);
//update status
//update status
status
=
Status
_
ParsingBufferValue
;
status
=
EParsing
Status
::
ParsingBufferValue
;
}
}
else
{
return
false
;
}
else
{
return
false
;
}
}
}
break
;
break
;
//look for end of value (first '"' char not preceded by the '\' escape char)
//look for end of value (first '"' char not preceded by the '\' escape char)
case
Status
_
ParsingBufferValue
:
case
EParsing
Status
::
ParsingBufferValue
:
//values end at first whitespace character or ']' character
//values end at first whitespace character or ']' character
if
(
std
::
isspace
(
*
it
,
locale
)
==
true
||
*
it
==
CONSTANT_RIGHT_SQUARE_BRACKET
)
if
(
std
::
isspace
(
*
it
,
locale
)
==
true
||
*
it
==
CONSTANT_RIGHT_SQUARE_BRACKET
)
...
@@ -322,7 +314,7 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
...
@@ -322,7 +314,7 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
//if dimension closing bracket is found
//if dimension closing bracket is found
if
(
*
it
==
CONSTANT_RIGHT_SQUARE_BRACKET
)
if
(
*
it
==
CONSTANT_RIGHT_SQUARE_BRACKET
)
{
{
//move back iterator by one character so that closing bracket is taken into account in Status
_
ParsingBuffer case
//move back iterator by one character so that closing bracket is taken into account in
EParsing
Status
::
ParsingBuffer case
--
it
;
--
it
;
}
}
...
@@ -341,14 +333,13 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
...
@@ -341,14 +333,13 @@ bool Matrix::fromString(IMatrix& matrix, const CString& str)
//reset current string
//reset current string
curString
.
erase
();
curString
.
erase
();
//update status
//update status
status
=
Status
_
ParsingBuffer
;
status
=
EParsing
Status
::
ParsingBuffer
;
}
}
//otherwise, append current character to current string
//otherwise, append current character to current string
else
{
curString
.
append
(
1
,
*
it
);
}
else
{
curString
.
append
(
1
,
*
it
);
}
break
;
break
;
default
:
default
:
break
;
break
;
}
// switch(status)
}
// switch(status)
//increment iterator
//increment iterator
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment