Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
7473adc8
Commit
7473adc8
authored
Dec 10, 2008
by
Mark Olesen
Browse files
writeKeyword spacing for keyType, misc cosmetics changes
parent
599c1c59
Changes
10
Hide whitespace changes
Inline
Side-by-side
applications/test/dictionary/dictionaryTest.C
View file @
7473adc8
...
...
@@ -41,34 +41,44 @@ using namespace Foam;
int
main
(
int
argc
,
char
*
argv
[])
{
Info
<<
dictionary
(
IFstream
(
"testDict"
)())
<<
endl
;
{
dictionary
dict
(
IFstream
(
"testDict"
)());
Info
<<
"dict: "
<<
dict
<<
nl
<<
"toc: "
<<
dict
.
toc
()
<<
nl
<<
"keys: "
<<
dict
.
keys
()
<<
nl
<<
"patterns: "
<<
dict
.
keys
(
true
)
<<
endl
;
}
IOobject
::
writeDivider
(
Info
);
{
dictionary
dict
(
IFstream
(
"testDictRegex"
)());
dict
.
add
(
keyType
(
"fooba[rz]"
,
true
),
"anything"
);
Info
<<
"dict:"
<<
dict
<<
endl
;
Info
<<
"dict:"
<<
dict
<<
nl
<<
"toc: "
<<
dict
.
toc
()
<<
nl
<<
"keys: "
<<
dict
.
keys
()
<<
nl
<<
"patterns: "
<<
dict
.
keys
(
true
)
<<
endl
;
// Wildcard find.
Info
<<
"Wildcard find
\"
abc
\"
in top directory : "
Info
<<
"Pattern find
\"
abc
\"
in top directory : "
<<
dict
.
lookup
(
"abc"
)
<<
endl
;
Info
<<
"
Wildcard
find
\"
abc
\"
in sub directory : "
Info
<<
"
Pattern
find
\"
abc
\"
in sub directory : "
<<
dict
.
subDict
(
"someDict"
).
lookup
(
"abc"
)
<<
endl
;
Info
<<
"Recursive
wildcard
find
\"
def
\"
in sub directory : "
Info
<<
"Recursive
pattern
find
\"
def
\"
in sub directory : "
<<
dict
.
subDict
(
"someDict"
).
lookup
(
"def"
,
true
)
<<
endl
;
Info
<<
"Recursive
wildcard
find
\"
foo
\"
in sub directory : "
Info
<<
"Recursive
pattern
find
\"
foo
\"
in sub directory : "
<<
dict
.
subDict
(
"someDict"
).
lookup
(
"foo"
,
true
)
<<
endl
;
Info
<<
"Recursive
wildcard
find
\"
fooz
\"
in sub directory : "
Info
<<
"Recursive
pattern
find
\"
fooz
\"
in sub directory : "
<<
dict
.
subDict
(
"someDict"
).
lookup
(
"fooz"
,
true
)
<<
endl
;
Info
<<
"Recursive
wildcard
find
\"
bar
\"
in sub directory : "
Info
<<
"Recursive
pattern
find
\"
bar
\"
in sub directory : "
<<
dict
.
subDict
(
"someDict"
).
lookup
(
"bar"
,
true
)
<<
endl
;
Info
<<
"Recursive
wildcard
find
\"
xxx
\"
in sub directory : "
Info
<<
"Recursive
pattern
find
\"
xxx
\"
in sub directory : "
<<
dict
.
subDict
(
"someDict"
).
lookup
(
"xxx"
,
true
)
<<
endl
;
}
...
...
applications/test/dictionary/testDictRegex
View file @
7473adc8
...
...
@@ -18,8 +18,10 @@ FoamFile
".*" parentValue1;
"[n-z].*" parentValue2;
"f.*" parentValue3;
keyX parentValue4;
keyY parentValue5;
some
Dict
"(.*)
Dict
"
{
foo subdictValue0;
bar $f.*; // should this really match 'foo'?
...
...
@@ -28,7 +30,7 @@ someDict
"a.*c" subdictValue3;
"ab.*" subdictValue2;
"a.*" subdictValue1;
abcd
subdictValue4
;
abcd
\1
;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C
View file @
7473adc8
...
...
@@ -32,22 +32,22 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//
-
Write keyType
Foam
::
Ostream
&
Foam
::
Ostream
::
write
(
const
keyType
&
s
)
// Write keyType
Foam
::
Ostream
&
Foam
::
Ostream
::
write
(
const
keyType
&
kw
)
{
// Write as word
?
if
(
s
.
is
WildCard
())
// Write as word
or string
if
(
kw
.
is
Pattern
())
{
return
write
(
static_cast
<
const
string
&>
(
s
));
return
write
(
static_cast
<
const
string
&>
(
kw
));
}
else
{
return
write
(
static_cast
<
const
word
&>
(
s
));
return
write
(
static_cast
<
const
word
&>
(
kw
));
}
}
//
-
Decreme
m
t the indent level
// Decreme
n
t the indent level
void
Foam
::
Ostream
::
decrIndent
()
{
if
(
indentLevel_
==
0
)
...
...
@@ -62,15 +62,26 @@ void Foam::Ostream::decrIndent()
}
// Write the keyword
to the Ostream
followed by appropriate indentation
Foam
::
Ostream
&
Foam
::
Ostream
::
writeKeyword
(
const
Foam
::
keyType
&
k
eyword
)
// Write the keyword followed by appropriate indentation
Foam
::
Ostream
&
Foam
::
Ostream
::
writeKeyword
(
const
keyType
&
k
w
)
{
indent
();
write
(
k
eyword
);
write
(
k
w
);
label
nSpaces
=
max
(
entryIndentation_
-
label
(
k
eyword
.
size
())
,
1
)
;
label
nSpaces
=
entryIndentation_
-
label
(
k
w
.
size
());
for
(
label
i
=
0
;
i
<
nSpaces
;
i
++
)
// pattern is surrounded by quotes
if
(
kw
.
isPattern
())
{
nSpaces
-=
2
;
}
if
(
nSpaces
<
1
)
{
nSpaces
=
1
;
}
while
(
nSpaces
--
)
{
write
(
char
(
token
::
SPACE
));
}
...
...
src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H
View file @
7473adc8
...
...
@@ -60,12 +60,11 @@ protected:
//- Number of spaces per indent level
static
const
unsigned
short
indentSize_
=
4
;
//- Current indent level
unsigned
short
indentLevel_
;
//- Indentation of the entry from the start of the keyword
static
const
unsigned
short
entryIndentation_
=
16
;
//- Current indent level
unsigned
short
indentLevel_
;
public:
...
...
@@ -148,9 +147,8 @@ public:
//- Decrememt the indent level
void
decrIndent
();
//- Write the keyword to the Ostream followed by
// appropriate indentation
Ostream
&
writeKeyword
(
const
keyType
&
keyword
);
//- Write the keyword followed by an appropriate indentation
Ostream
&
writeKeyword
(
const
keyType
&
);
// Stream state functions
...
...
src/OpenFOAM/db/dictionary/dictionary.C
View file @
7473adc8
...
...
@@ -38,9 +38,9 @@ const Foam::dictionary Foam::dictionary::null;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool
Foam
::
dictionary
::
findIn
Wildcard
s
bool
Foam
::
dictionary
::
findIn
Pattern
s
(
const
bool
wildCard
Match
,
const
bool
pattern
Match
,
const
word
&
Keyword
,
DLList
<
entry
*>::
const_iterator
&
wcLink
,
DLList
<
autoPtr
<
regExp
>
>::
const_iterator
&
reLink
...
...
@@ -50,11 +50,11 @@ bool Foam::dictionary::findInWildcards
{
while
(
wcLink
!=
wildCardEntries_
.
end
())
{
if
(
!
wildCardMatch
&&
wcLink
()
->
keyword
()
==
Keyword
)
{
return
true
;
}
else
if
(
wildCardMatch
&&
reLink
()
->
match
(
Keyword
)
)
if
(
patternMatch
?
reLink
()
->
match
(
Keyword
)
:
wcLink
()
->
keyword
()
==
Keyword
)
{
return
true
;
}
...
...
@@ -68,9 +68,9 @@ bool Foam::dictionary::findInWildcards
}
bool
Foam
::
dictionary
::
findIn
Wildcard
s
bool
Foam
::
dictionary
::
findIn
Pattern
s
(
const
bool
wildCard
Match
,
const
bool
pattern
Match
,
const
word
&
Keyword
,
DLList
<
entry
*>::
iterator
&
wcLink
,
DLList
<
autoPtr
<
regExp
>
>::
iterator
&
reLink
...
...
@@ -80,11 +80,11 @@ bool Foam::dictionary::findInWildcards
{
while
(
wcLink
!=
wildCardEntries_
.
end
())
{
if
(
!
wildCardMatch
&&
wcLink
()
->
keyword
()
==
Keyword
)
{
return
true
;
}
else
if
(
wildCardMatch
&&
reLink
()
->
match
(
Keyword
)
)
if
(
patternMatch
?
reLink
()
->
match
(
Keyword
)
:
wcLink
()
->
keyword
()
==
Keyword
)
{
return
true
;
}
...
...
@@ -125,7 +125,7 @@ Foam::dictionary::dictionary
{
hashedEntries_
.
insert
(
iter
().
keyword
(),
&
iter
());
if
(
iter
().
keyword
().
is
WildCard
())
if
(
iter
().
keyword
().
is
Pattern
())
{
wildCardEntries_
.
insert
(
&
iter
());
wildCardRegexps_
.
insert
...
...
@@ -155,7 +155,7 @@ Foam::dictionary::dictionary
{
hashedEntries_
.
insert
(
iter
().
keyword
(),
&
iter
());
if
(
iter
().
keyword
().
is
WildCard
())
if
(
iter
().
keyword
().
is
Pattern
())
{
wildCardEntries_
.
insert
(
&
iter
());
wildCardRegexps_
.
insert
...
...
@@ -223,8 +223,8 @@ bool Foam::dictionary::found(const word& keyword, bool recursive) const
DLList
<
autoPtr
<
regExp
>
>::
const_iterator
reLink
=
wildCardRegexps_
.
begin
();
// Find in
wildcard
s using regular expressions only
if
(
findIn
Wildcard
s
(
true
,
keyword
,
wcLink
,
reLink
))
// Find in
pattern
s using regular expressions only
if
(
findIn
Pattern
s
(
true
,
keyword
,
wcLink
,
reLink
))
{
return
true
;
}
...
...
@@ -246,22 +246,22 @@ const Foam::entry* Foam::dictionary::lookupEntryPtr
(
const
word
&
keyword
,
bool
recursive
,
bool
wildCard
Match
bool
pattern
Match
)
const
{
HashTable
<
entry
*>::
const_iterator
iter
=
hashedEntries_
.
find
(
keyword
);
if
(
iter
==
hashedEntries_
.
end
())
{
if
(
wildCard
Match
&&
wildCardEntries_
.
size
()
>
0
)
if
(
pattern
Match
&&
wildCardEntries_
.
size
()
>
0
)
{
DLList
<
entry
*>::
const_iterator
wcLink
=
wildCardEntries_
.
begin
();
DLList
<
autoPtr
<
regExp
>
>::
const_iterator
reLink
=
wildCardRegexps_
.
begin
();
// Find in
wildcard
s using regular expressions only
if
(
findIn
Wildcards
(
wildCard
Match
,
keyword
,
wcLink
,
reLink
))
// Find in
pattern
s using regular expressions only
if
(
findIn
Patterns
(
pattern
Match
,
keyword
,
wcLink
,
reLink
))
{
return
wcLink
();
}
...
...
@@ -269,7 +269,7 @@ const Foam::entry* Foam::dictionary::lookupEntryPtr
if
(
recursive
&&
&
parent_
!=
&
dictionary
::
null
)
{
return
parent_
.
lookupEntryPtr
(
keyword
,
recursive
,
wildCard
Match
);
return
parent_
.
lookupEntryPtr
(
keyword
,
recursive
,
pattern
Match
);
}
else
{
...
...
@@ -285,21 +285,22 @@ Foam::entry* Foam::dictionary::lookupEntryPtr
(
const
word
&
keyword
,
bool
recursive
,
bool
wildCard
Match
bool
pattern
Match
)
{
HashTable
<
entry
*>::
iterator
iter
=
hashedEntries_
.
find
(
keyword
);
if
(
iter
==
hashedEntries_
.
end
())
{
if
(
wildCard
Match
&&
wildCardEntries_
.
size
()
>
0
)
if
(
pattern
Match
&&
wildCardEntries_
.
size
()
>
0
)
{
DLList
<
entry
*>::
iterator
wcLink
=
wildCardEntries_
.
begin
();
DLList
<
autoPtr
<
regExp
>
>::
iterator
reLink
=
wildCardRegexps_
.
begin
();
// Find in wildcards using regular expressions only
if
(
findInWildcards
(
wildCardMatch
,
keyword
,
wcLink
,
reLink
))
// Find in patterns using regular expressions only
if
(
findInPatterns
(
patternMatch
,
keyword
,
wcLink
,
reLink
))
{
return
wcLink
();
}
...
...
@@ -311,7 +312,7 @@ Foam::entry* Foam::dictionary::lookupEntryPtr
(
keyword
,
recursive
,
wildCard
Match
pattern
Match
);
}
else
...
...
@@ -328,10 +329,10 @@ const Foam::entry& Foam::dictionary::lookupEntry
(
const
word
&
keyword
,
bool
recursive
,
bool
wildCard
Match
bool
pattern
Match
)
const
{
const
entry
*
entryPtr
=
lookupEntryPtr
(
keyword
,
recursive
,
wildCard
Match
);
const
entry
*
entryPtr
=
lookupEntryPtr
(
keyword
,
recursive
,
pattern
Match
);
if
(
entryPtr
==
NULL
)
{
...
...
@@ -352,16 +353,16 @@ Foam::ITstream& Foam::dictionary::lookup
(
const
word
&
keyword
,
bool
recursive
,
bool
wildCard
Match
bool
pattern
Match
)
const
{
return
lookupEntry
(
keyword
,
recursive
,
wildCard
Match
).
stream
();
return
lookupEntry
(
keyword
,
recursive
,
pattern
Match
).
stream
();
}
bool
Foam
::
dictionary
::
isDict
(
const
word
&
keyword
)
const
{
// Find non-recursive with
wildcard
s
// Find non-recursive with
pattern
s
const
entry
*
entryPtr
=
lookupEntryPtr
(
keyword
,
false
,
true
);
if
(
entryPtr
)
...
...
@@ -430,7 +431,26 @@ Foam::wordList Foam::dictionary::toc() const
{
wordList
keys
(
size
());
label
i
=
0
;
label
nKeys
=
0
;
for
(
IDLList
<
entry
>::
const_iterator
iter
=
begin
();
iter
!=
end
();
++
iter
)
{
keys
[
nKeys
++
]
=
iter
().
keyword
();
}
return
keys
;
}
Foam
::
List
<
Foam
::
keyType
>
Foam
::
dictionary
::
keys
(
bool
patterns
)
const
{
List
<
keyType
>
keys
(
size
());
label
nKeys
=
0
;
for
(
IDLList
<
entry
>::
const_iterator
iter
=
begin
();
...
...
@@ -438,8 +458,12 @@ Foam::wordList Foam::dictionary::toc() const
++
iter
)
{
keys
[
i
++
]
=
iter
().
keyword
();
if
(
iter
().
keyword
().
isPattern
()
?
patterns
:
!
patterns
)
{
keys
[
nKeys
++
]
=
iter
().
keyword
();
}
}
keys
.
setSize
(
nKeys
);
return
keys
;
}
...
...
@@ -473,7 +497,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
{
entryPtr
->
name
()
=
name_
+
"::"
+
entryPtr
->
keyword
();
if
(
entryPtr
->
keyword
().
is
WildCard
())
if
(
entryPtr
->
keyword
().
is
Pattern
())
{
wildCardEntries_
.
insert
(
entryPtr
);
wildCardRegexps_
.
insert
...
...
@@ -502,7 +526,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
entryPtr
->
name
()
=
name_
+
"::"
+
entryPtr
->
keyword
();
IDLList
<
entry
>::
append
(
entryPtr
);
if
(
entryPtr
->
keyword
().
is
WildCard
())
if
(
entryPtr
->
keyword
().
is
Pattern
())
{
wildCardEntries_
.
insert
(
entryPtr
);
wildCardRegexps_
.
insert
...
...
@@ -597,13 +621,12 @@ bool Foam::dictionary::remove(const word& Keyword)
if
(
iter
!=
hashedEntries_
.
end
())
{
// Delete from wildcards first
DLList
<
entry
*>::
iterator
wcLink
=
wildCardEntries_
.
begin
();
// Delete from patterns first
DLList
<
entry
*>::
iterator
wcLink
=
wildCardEntries_
.
begin
();
DLList
<
autoPtr
<
regExp
>
>::
iterator
reLink
=
wildCardRegexps_
.
begin
();
// Find in
wildcards
using exact match only
if
(
findIn
Wildcard
s
(
false
,
Keyword
,
wcLink
,
reLink
))
// Find in
pattern
using exact match only
if
(
findIn
Pattern
s
(
false
,
Keyword
,
wcLink
,
reLink
))
{
wildCardEntries_
.
remove
(
wcLink
);
wildCardRegexps_
.
remove
(
reLink
);
...
...
@@ -643,14 +666,14 @@ bool Foam::dictionary::changeKeyword
return
false
;
}
if
(
iter
()
->
keyword
().
is
WildCard
())
if
(
iter
()
->
keyword
().
is
Pattern
())
{
FatalErrorIn
(
"dictionary::changeKeyword(const word&, const word&, bool)"
)
<<
"Old keyword "
<<
oldKeyword
<<
" is a
wildcard
."
<<
"
Wildcard
replacement not yet implemented."
<<
" is a
pattern
."
<<
"
Pattern
replacement not yet implemented."
<<
exit
(
FatalError
);
}
...
...
@@ -662,16 +685,16 @@ bool Foam::dictionary::changeKeyword
{
if
(
forceOverwrite
)
{
if
(
iter2
()
->
keyword
().
is
WildCard
())
if
(
iter2
()
->
keyword
().
is
Pattern
())
{
// Delete from
wildcard
s first
// Delete from
pattern
s first
DLList
<
entry
*>::
iterator
wcLink
=
wildCardEntries_
.
begin
();
DLList
<
autoPtr
<
regExp
>
>::
iterator
reLink
=
wildCardRegexps_
.
begin
();
// Find in
wildcard
s using exact match only
if
(
findIn
Wildcard
s
(
false
,
iter2
()
->
keyword
(),
wcLink
,
reLink
))
// Find in
pattern
s using exact match only
if
(
findIn
Pattern
s
(
false
,
iter2
()
->
keyword
(),
wcLink
,
reLink
))
{
wildCardEntries_
.
remove
(
wcLink
);
wildCardRegexps_
.
remove
(
reLink
);
...
...
@@ -701,7 +724,7 @@ bool Foam::dictionary::changeKeyword
hashedEntries_
.
erase
(
oldKeyword
);
hashedEntries_
.
insert
(
newKeyword
,
iter
());
if
(
newKeyword
.
is
WildCard
())
if
(
newKeyword
.
is
Pattern
())
{
wildCardEntries_
.
insert
(
iter
());
wildCardRegexps_
.
insert
...
...
src/OpenFOAM/db/dictionary/dictionary.H
View file @
7473adc8
...
...
@@ -27,12 +27,12 @@ Class
Description
A list of keyword definitions, which are a keyword followed by any number
of values (e.g. words and numbers). The keywords can represent
wildcard
s
of values (e.g. words and numbers). The keywords can represent
pattern
s
which are matched using Posix regular expressions. The general order for
searching is
searching is
as follows:
- exact match
-
wildcard
match (in reverse order)
- optional recursion into
sub
dictionaries
-
pattern
match (in reverse order)
- optional recursion into
the enclosing (parent)
dictionaries
The dictionary class is the base class for IOdictionary.
It also serves as a bootstrap dictionary for the objectRegistry data
...
...
@@ -92,29 +92,27 @@ class dictionary
//- Parent dictionary
const
dictionary
&
parent_
;
//-
Wildcard entrie
s
//-
Entries of matching pattern
s
DLList
<
entry
*>
wildCardEntries_
;
//-
Wildcard
precompiled regular expressions
//-
Patterns as
precompiled regular expressions
DLList
<
autoPtr
<
regExp
>
>
wildCardRegexps_
;
// Private Member Functions
//- Search wildcard table either for exact match or for regular
// expression match.
bool
findInWildcards
//- Search patterns table for exact match or regular expression match
bool
findInPatterns
(
const
bool
wildCard
Match
,
const
bool
pattern
Match
,
const
word
&
Keyword
,
DLList
<
entry
*>::
const_iterator
&
wcLink
,
DLList
<
autoPtr
<
regExp
>
>::
const_iterator
&
reLink
)
const
;
//- Search wildcard table either for exact match or for regular
// expression match.
bool
findInWildcards
//- Search patterns table for exact match or regular expression match
bool
findInPatterns
(
const
bool
wildCard
Match
,
const
bool
pattern
Match
,
const
word
&
Keyword
,
DLList
<
entry
*>::
iterator
&
wcLink
,
DLList
<
autoPtr
<
regExp
>
>::
iterator
&
reLink
...
...
@@ -210,83 +208,88 @@ public:
// Search and lookup
//- Search dictionary for given keyword
// If recursive search parent dictionaries
// If recursive
,
search parent dictionaries
bool
found
(
const
word
&
,
bool
recursive
=
false
)
const
;
//- Find and return an entry data stream pointer if present
// otherwise return NULL.
// If recursive search parent dictionaries.
// If
wildCard
Match use
wildcards.
// If recursive
,
search parent dictionaries.
// If
pattern
Match
,
use
regular expressions
const
entry
*
lookupEntryPtr
(
const
word
&
,
bool
recursive
,
bool
wildCard
Match
bool
pattern
Match
)
const
;
//- Find and return an entry data stream pointer for manipulation
// if present otherwise return NULL.
// If recursive search parent dictionaries.
// If
wildCard
Match use
wildcard
s.
// If recursive
,
search parent dictionaries.
// If
pattern
Match
,
use
regular expression
s.
entry
*
lookupEntryPtr
(
const
word
&
,
bool
recursive
,
bool
wildCard
Match
bool
pattern
Match
);
//- Find and return an entry data stream if present otherwise error.
// If recursive search parent dictionaries.
// If
wildCard
Match use
wildcard
s.
// If recursive
,
search parent dictionaries.
// If
pattern
Match
,
use
regular expression
s.
const
entry
&
lookupEntry
(
const
word
&
,
bool
recursive
,
bool
wildCard
Match
bool
pattern
Match
)
const
;
//- Find and return an entry data stream
// If recursive search parent dictionaries
// If recursive, search parent dictionaries.
// If patternMatch, use regular expressions.
ITstream
&
lookup
(
const
word
&
,
bool
recursive
=
false
,
bool
wildCard
Match
=
true
bool
pattern
Match
=
true
)
const
;
//- Find and return a T,
// if not found return the given default value
// If recursive search parent dictionaries
// If recursive, search parent dictionaries.
// If patternMatch, use regular expressions.
template
<
class
T
>
T
lookupOrDefault
(
const
word
&
,
const
T
&
,
bool
recursive
=
false
,
bool
wildCard
Match
=
true
bool
pattern
Match
=
true
)
const
;
//- Find and return a T, if not found return the given
// default value, and add to dictionary.
// If recursive search parent dictionaries
// If recursive, search parent dictionaries.
// If patternMatch, use regular expressions.
template
<
class
T
>
T
lookupOrAddDefault
(
const
word
&
,
const
T
&
,