Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
4f1e4aa5
Commit
4f1e4aa5
authored
Nov 12, 2017
by
Mark Olesen
Browse files
ENH: add token type for stream flags (ASCII/BINARY)
parent
5281dd48
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C
View file @
4f1e4aa5
...
...
@@ -191,6 +191,13 @@ bool Foam::UOPstream::write(const token& tok)
switch
(
tok
.
type
())
{
case
token
:
:
tokenType
::
FLAG
:
{
// silently consume the flag
return
true
;
}
case
token
:
:
tokenType
::
VERBATIMSTRING
:
{
writeToBuffer
(
char
(
token
::
tokenType
::
VERBATIMSTRING
));
...
...
src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C
View file @
4f1e4aa5
...
...
@@ -36,6 +36,12 @@ bool Foam::OSstream::write(const token& tok)
switch
(
tok
.
type
())
{
case
token
:
:
tokenType
::
FLAG
:
{
// silently consume the flag
return
true
;
}
case
token
:
:
tokenType
::
VERBATIMSTRING
:
{
write
(
char
(
token
::
HASH
));
...
...
src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C
View file @
4f1e4aa5
...
...
@@ -71,6 +71,12 @@ bool Foam::prefixOSstream::write(const token& tok)
switch
(
tok
.
type
())
{
case
token
:
:
tokenType
::
FLAG
:
{
// silently consume the flag
return
true
;
}
case
token
:
:
tokenType
::
VERBATIMSTRING
:
{
write
(
char
(
token
::
HASH
));
...
...
src/OpenFOAM/db/IOstreams/token/token.H
View file @
4f1e4aa5
...
...
@@ -79,6 +79,7 @@ public:
UNDEFINED
,
//!< An undefined token-type
// Fundamental types
FLAG
,
//!< stream flag (1-byte bitmask)
PUNCTUATION
,
//!< single character punctuation
LABEL
,
//!< label (integer) type
FLOAT_SCALAR
,
//!< float (single-precision) type
...
...
@@ -97,6 +98,15 @@ public:
};
//- Stream or output control flags (1-byte width)
enum
flagType
{
NO_FLAG
=
0
,
//!< No flags
ASCII
=
1
,
//!< ASCII-mode stream
BINARY
=
2
,
//!< BINARY-mode stream
};
//- Standard punctuation tokens (a character)
enum
punctuationToken
{
...
...
@@ -137,16 +147,6 @@ public:
bool
empty_
;
// Private Member Functions
//- Disallow default bitwise copy construct
compound
(
const
compound
&
)
=
delete
;
//- Disallow default bitwise assignment
void
operator
=
(
const
compound
&
)
=
delete
;
public:
//- Runtime type information
...
...
@@ -171,6 +171,9 @@ public:
empty_
(
false
)
{}
//- No default copy construct
compound
(
const
compound
&
)
=
delete
;
// Selectors
...
...
@@ -202,9 +205,13 @@ public:
virtual
void
write
(
Ostream
&
os
)
const
=
0
;
// IOstream Operators
// Operators
//- No default assign operator
compound
&
operator
=
(
const
compound
&
)
=
delete
;
friend
Ostream
&
operator
<<
(
Ostream
&
,
const
compound
&
);
//- Output operator
friend
Ostream
&
operator
<<
(
Ostream
&
os
,
const
compound
&
ct
);
};
...
...
@@ -250,6 +257,7 @@ private:
int64_t
int64Val
;
int32_t
int32Val
;
int
flagVal
;
// bitmask - stored as int, not enum
punctuationToken
punctuationVal
;
label
labelVal
;
floatScalar
floatVal
;
...
...
@@ -350,7 +358,12 @@ public:
inline
~
token
();
// Static member functions
// Static Member Functions
//- Create a token with stream flags, no sanity check
//
// \param bitmask the flags to set
inline
static
token
flag
(
int
bitmask
);
//- True if the character is a punctuation separator (eg, in ISstream).
// Since it could also start a number, SUBTRACT is not included as
...
...
@@ -395,6 +408,9 @@ public:
//- True if token is ERROR
inline
bool
error
()
const
;
//- True if token is FLAG
inline
bool
isFlag
()
const
;
//- True if token is PUNCTUATION
inline
bool
isPunctuation
()
const
;
...
...
@@ -431,6 +447,10 @@ public:
// Access
//- Return flag bitmask
// Report FatalIOError and return NO_FLAG if token is not FLAG
inline
int
flagToken
()
const
;
//- Return punctuation character.
// Report FatalIOError and return \b \\0 if token is not PUNCTUATION
inline
punctuationToken
pToken
()
const
;
...
...
src/OpenFOAM/db/IOstreams/token/tokenI.H
View file @
4f1e4aa5
...
...
@@ -25,6 +25,48 @@ License
#include <algorithm>
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
inline
Foam
::
token
Foam
::
token
::
flag
(
int
bitmask
)
{
token
tok
;
tok
.
type_
=
tokenType
::
FLAG
;
tok
.
data_
.
flagVal
=
bitmask
;
return
tok
;
}
inline
bool
Foam
::
token
::
isseparator
(
int
c
)
{
switch
(
c
)
{
case
token
:
:
END_STATEMENT
:
case
token
:
:
BEGIN_LIST
:
case
token
:
:
END_LIST
:
case
token
:
:
BEGIN_SQR
:
case
token
:
:
END_SQR
:
case
token
:
:
BEGIN_BLOCK
:
case
token
:
:
END_BLOCK
:
case
token
:
:
COLON
:
case
token
:
:
COMMA
:
case
token
:
:
ASSIGN
:
case
token
:
:
ADD
:
// Excluded token::SUBTRACT since it could start a number
case
token
:
:
MULTIPLY
:
case
token
:
:
DIVIDE
:
{
return
true
;
}
default:
break
;
}
return
false
;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
inline
void
Foam
::
token
::
setUndefined
()
...
...
@@ -322,51 +364,39 @@ inline bool Foam::token::error() const
}
inline
bool
Foam
::
token
::
is
Punctuation
()
const
inline
bool
Foam
::
token
::
is
Flag
()
const
{
return
(
type_
==
tokenType
::
PUNCTUATION
);
return
(
type_
==
tokenType
::
FLAG
);
}
inline
Foam
::
token
::
punctuationToken
Foam
::
token
::
p
Token
()
const
inline
int
Foam
::
token
::
flag
Token
()
const
{
if
(
type_
==
tokenType
::
PUNCTUATION
)
if
(
type_
==
tokenType
::
FLAG
)
{
return
data_
.
punctuation
Val
;
return
data_
.
flag
Val
;
}
parseError
(
"
punctuation character
"
);
return
N
ULL_TOKEN
;
parseError
(
"
flag bitmask
"
);
return
N
O_FLAG
;
}
inline
bool
Foam
::
token
::
is
separator
(
int
c
)
inline
bool
Foam
::
token
::
is
Punctuation
()
const
{
switch
(
c
)
{
case
token
:
:
END_STATEMENT
:
case
token
:
:
BEGIN_LIST
:
case
token
:
:
END_LIST
:
case
token
:
:
BEGIN_SQR
:
case
token
:
:
END_SQR
:
case
token
:
:
BEGIN_BLOCK
:
case
token
:
:
END_BLOCK
:
case
token
:
:
COLON
:
case
token
:
:
COMMA
:
case
token
:
:
ASSIGN
:
case
token
:
:
ADD
:
// Excluded token::SUBTRACT since it could start a number
case
token
:
:
MULTIPLY
:
case
token
:
:
DIVIDE
:
{
return
true
;
}
return
(
type_
==
tokenType
::
PUNCTUATION
);
}
default:
break
;
inline
Foam
::
token
::
punctuationToken
Foam
::
token
::
pToken
()
const
{
if
(
type_
==
tokenType
::
PUNCTUATION
)
{
return
data_
.
punctuationVal
;
}
return
false
;
parseError
(
"punctuation character"
);
return
punctuationToken
::
NULL_TOKEN
;
}
...
...
@@ -712,6 +742,9 @@ inline bool Foam::token::operator==(const token& tok) const
case
tokenType
:
:
UNDEFINED
:
return
true
;
case
tokenType
:
:
FLAG
:
return
data_
.
flagVal
==
tok
.
data_
.
flagVal
;
case
tokenType
:
:
PUNCTUATION
:
return
data_
.
punctuationVal
==
tok
.
data_
.
punctuationVal
;
...
...
src/OpenFOAM/db/IOstreams/token/tokenIO.C
View file @
4f1e4aa5
...
...
@@ -43,6 +43,10 @@ static OS& printTokenInfo(OS& os, const token& tok)
os
<<
"undefined token"
;
break
;
case
token
:
:
tokenType
::
FLAG
:
os
<<
"flag '"
<<
int
(
tok
.
flagToken
())
<<
'\''
;
break
;
case
token
:
:
tokenType
::
PUNCTUATION
:
os
<<
"punctuation '"
<<
tok
.
pToken
()
<<
'\''
;
break
;
...
...
@@ -117,6 +121,7 @@ Foam::word Foam::token::name() const
switch
(
type_
)
{
case
token
:
:
tokenType
::
UNDEFINED
:
return
"undefined"
;
case
token
:
:
tokenType
::
FLAG
:
return
"flag"
;
case
token
:
:
tokenType
::
PUNCTUATION
:
return
"punctuation"
;
case
token
:
:
tokenType
::
LABEL
:
return
"label"
;
case
token
:
:
tokenType
::
FLOAT_SCALAR
:
return
"float"
;
...
...
@@ -155,6 +160,10 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const token& tok)
<<
"Undefined token"
<<
endl
;
break
;
case
token
:
:
tokenType
::
FLAG
:
// Swallow the flag
break
;
case
token
:
:
tokenType
::
PUNCTUATION
:
os
<<
tok
.
data_
.
punctuationVal
;
break
;
...
...
Write
Preview
Markdown
is supported
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