Skip to content
GitLab
Menu
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
12c903bb
Commit
12c903bb
authored
Sep 19, 2018
by
Mark OLESEN
Browse files
ENH: define nameOp<>, typeOp<>, sizeOp<> functors (issue
#1013
)
parent
47519b2e
Changes
15
Hide whitespace changes
Inline
Side-by-side
applications/test/fileName/Test-fileName.C
View file @
12c903bb
...
...
@@ -617,6 +617,7 @@ int main(int argc, char *argv[])
fileName
pathName
(
wrdList
);
Info
<<
"pathName = "
<<
pathName
<<
nl
<<
"nameOp = "
<<
nameOp
<
fileName
>
()(
pathName
)
<<
nl
<<
"pathName.name() = >"
<<
pathName
.
name
()
<<
"<
\n
"
<<
"pathName.path() = "
<<
pathName
.
path
()
<<
nl
<<
"pathName.ext() = >"
<<
pathName
.
ext
()
<<
"<
\n
"
...
...
applications/test/string/Test-string.C
View file @
12c903bb
...
...
@@ -271,32 +271,31 @@ int main(int argc, char *argv[])
Info
<<
"hash: = "
<<
word
::
printf
(
"0x%012X"
,
string
::
hash
()(
s2
))
<<
endl
;
//
t
est formatting on int
//
T
est formatting on int
{
label
val
=
25
;
Info
<<
"val: "
<<
val
<<
"
\n
"
;
Info
<<
"int "
<<
val
<<
" as word >"
<<
Foam
::
name
(
val
)
<<
"< or "
<<
word
::
printf
(
"formatted >%08d<"
,
val
)
<<
"
\n
"
;
Info
<<
"int "
<<
val
<<
" nameOp='"
<<
nameOp
<
label
>
()(
val
)
<<
"', name='"
<<
Foam
::
name
(
val
)
<<
"' or "
<<
word
::
printf
(
"formatted '%08d'"
,
val
)
<<
"
\n
"
;
}
//
t
est formatting on scalar
//
T
est formatting on scalar
{
scalar
val
=
3
.
1415926535897931
;
Info
<<
"scalar "
<<
val
<<
" as word >"
<<
Foam
::
name
(
val
)
<<
"< or "
<<
word
::
printf
(
"formatted >%.9f<"
,
val
)
<<
"
\n
"
;
Info
<<
"scalar "
<<
val
<<
" nameOp='"
<<
nameOp
<
scalar
>
()(
val
)
<<
"', name='"
<<
Foam
::
name
(
val
)
<<
"' or "
<<
word
::
printf
(
"formatted '%.9f'"
,
val
)
<<
"
\n
"
;
}
//
t
est formatting on uint
//
T
est formatting on uint
{
uint64_t
val
=
25000000ul
;
Info
<<
"val: "
<<
val
<<
"
\n
"
;
Info
<<
"uint64 "
<<
val
<<
" as word >"
<<
Foam
::
name
(
val
)
<<
"< or "
<<
word
::
printf
(
"formatted >%08d<"
,
val
)
<<
"
\n
"
;
Info
<<
"uint64 "
<<
val
<<
" nameOp='"
<<
nameOp
<
uint64_t
>
()(
val
)
<<
"', name='"
<<
Foam
::
name
(
val
)
<<
"' or "
<<
word
::
printf
(
"formatted '%08d'"
,
val
)
<<
"
\n
"
;
}
// test startsWith, endsWith methods
...
...
applications/utilities/miscellaneous/foamRestoreFields/foamRestoreFields.C
View file @
12c903bb
...
...
@@ -87,12 +87,12 @@ static const Enum<restoreMethod> methodEndings
// Files in given directory at time instant
wordList
getFiles
(
const
fileName
&
dir
,
const
word
&
instance
)
inline
wordList
getFiles
(
const
fileName
&
dir
,
const
word
&
instance
)
{
return
ListOps
::
create
<
word
>
(
Foam
::
readDir
(
dir
/
instance
,
fileName
::
FILE
),
[](
const
fileName
&
f
){
return
f
.
name
();
}
nameOp
<
fileName
>
()
);
}
...
...
src/OpenFOAM/containers/Lists/UList/UList.H
View file @
12c903bb
...
...
@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017
-2018
OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -612,6 +612,17 @@ struct Hash<UList<T>>
};
//- Extract size (as label) from an object, typically using its size() method.
template
<
class
T
>
struct
sizeOp
{
inline
label
operator
()(
const
T
&
obj
)
const
{
return
obj
.
size
();
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
}
// End namespace Foam
...
...
src/OpenFOAM/primitives/Scalar/Scalar.H
View file @
12c903bb
...
...
@@ -105,10 +105,22 @@ public:
// * * * * * * * * * * * * * * * IO/Conversion * * * * * * * * * * * * * * * //
//-
Return a
word representation of a
Scalar
.
//-
A
word representation of a
floating-point value
.
// Uses stringstream instead of std::to_string for more consistent formatting.
word
name
(
const
Scalar
val
);
//- A word representation of a floating-point value.
template
<
>
struct
nameOp
<
Scalar
>
{
inline
word
operator
()(
const
Scalar
val
)
const
{
return
Foam
::
name
(
val
);
}
};
//- Parse entire buffer as a float/double, skipping leading/trailing whitespace.
// \return Parsed value or FatalIOError on any problem
Scalar
ScalarRead
(
const
char
*
buf
);
...
...
src/OpenFOAM/primitives/VectorSpace/VectorSpace.H
View file @
12c903bb
...
...
@@ -216,9 +216,9 @@ public:
// * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * * //
//-
Return a string
representation of a VectorSpace
//-
A word
representation of a VectorSpace
template
<
class
Form
,
class
Cmpt
,
direction
Ncmpts
>
word
name
(
const
VectorSpace
<
Form
,
Cmpt
,
Ncmpts
>&
);
word
name
(
const
VectorSpace
<
Form
,
Cmpt
,
Ncmpts
>&
vs
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...
...
src/OpenFOAM/primitives/ints/int16/int16.H
View file @
12c903bb
...
...
@@ -48,13 +48,22 @@ class Ostream;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//-
Return a
word representation of
an
int16
//-
A
word representation of int16
value
inline
word
name
(
const
int16_t
val
)
{
// No stripping required
return
word
(
std
::
to_string
(
int
(
val
)),
false
);
return
word
(
std
::
to_string
(
int
(
val
)),
false
);
// Needs no stripping
}
//- A word representation of int16 value
template
<
>
struct
nameOp
<
int16_t
>
{
inline
word
operator
()(
const
int16_t
val
)
const
{
return
word
(
std
::
to_string
(
int
(
val
)),
false
);
// Needs no stripping
}
};
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
...
...
src/OpenFOAM/primitives/ints/int32/int32.H
View file @
12c903bb
...
...
@@ -54,14 +54,24 @@ class Ostream;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//-
Return a
word representation of
an
int32
//-
A
word representation of int32
value
inline
word
name
(
const
int32_t
val
)
{
// No stripping required
return
word
(
std
::
to_string
(
val
),
false
);
return
word
(
std
::
to_string
(
val
),
false
);
// Needs no stripping
}
//- A word representation of int32 value
template
<
>
struct
nameOp
<
int32_t
>
{
inline
word
operator
()(
const
int32_t
val
)
const
{
return
word
(
std
::
to_string
(
val
),
false
);
// Needs no stripping
}
};
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
//- Read int32_t from stream
...
...
src/OpenFOAM/primitives/ints/int64/int64.H
View file @
12c903bb
...
...
@@ -55,14 +55,24 @@ class Ostream;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//-
Return a
word representation of
an
int64
//-
A
word representation of int64
value
inline
word
name
(
const
int64_t
val
)
{
// No stripping required
return
word
(
std
::
to_string
(
val
),
false
);
return
word
(
std
::
to_string
(
val
),
false
);
// Needs no stripping
}
//- A word representation of int64 value
template
<
>
struct
nameOp
<
int64_t
>
{
inline
word
operator
()(
const
int64_t
val
)
const
{
return
word
(
std
::
to_string
(
val
),
false
);
// Needs no stripping
}
};
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
//- Read int64_t from stream
...
...
src/OpenFOAM/primitives/ints/uint16/uint16.H
View file @
12c903bb
...
...
@@ -48,14 +48,24 @@ class Ostream;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//-
Return a
word representation of
a
uint16
//-
A
word representation of uint16
value
inline
word
name
(
const
uint16_t
val
)
{
// No stripping required
return
word
(
std
::
to_string
(
int
(
val
)),
false
);
return
word
(
std
::
to_string
(
int
(
val
)),
false
);
// Needs no stripping
}
//- A word representation of uint16 value
template
<
>
struct
nameOp
<
uint16_t
>
{
inline
word
operator
()(
const
uint16_t
val
)
const
{
return
word
(
std
::
to_string
(
int
(
val
)),
false
);
// Needs no stripping
}
};
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Istream
&
operator
>>
(
Istream
&
is
,
uint16_t
&
val
);
...
...
src/OpenFOAM/primitives/ints/uint32/uint32.H
View file @
12c903bb
...
...
@@ -54,13 +54,22 @@ class Ostream;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//-
Return a
word representation of
a
uint32
//-
A
word representation of uint32
value
inline
word
name
(
const
uint32_t
val
)
{
// No stripping required
return
word
(
std
::
to_string
(
val
),
false
);
return
word
(
std
::
to_string
(
val
),
false
);
// Needs no stripping
}
//- A word representation of uint32 value
template
<
>
struct
nameOp
<
uint32_t
>
{
inline
word
operator
()(
const
uint32_t
val
)
const
{
return
word
(
std
::
to_string
(
val
),
false
);
// Needs no stripping
}
};
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
...
...
src/OpenFOAM/primitives/ints/uint64/uint64.H
View file @
12c903bb
...
...
@@ -54,14 +54,24 @@ class Ostream;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//-
Return a
word representation of
a
uint64
//-
A
word representation of uint64
value
inline
word
name
(
const
uint64_t
val
)
{
// No stripping required
return
word
(
std
::
to_string
(
val
),
false
);
return
word
(
std
::
to_string
(
val
),
false
);
// Needs no stripping
}
//- A word representation of uint64 value
template
<
>
struct
nameOp
<
uint64_t
>
{
inline
word
operator
()(
const
uint64_t
val
)
const
{
return
word
(
std
::
to_string
(
val
),
false
);
// Needs no stripping
}
};
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
//- Read uint64_t from stream.
...
...
src/OpenFOAM/primitives/strings/fileName/fileName.C
View file @
12c903bb
...
...
@@ -589,7 +589,7 @@ Foam::fileName Foam::operator/(const string& a, const string& b)
Foam
::
fileName
Foam
::
search
(
const
word
&
file
,
const
fileName
&
directory
)
{
// Search the current directory for the file
fileNameList
files
(
fileHandler
().
readDir
(
directory
));
fileNameList
files
(
fileHandler
().
readDir
(
directory
,
fileName
::
FILE
));
for
(
const
fileName
&
item
:
files
)
{
if
(
item
==
file
)
...
...
src/OpenFOAM/primitives/strings/fileName/fileName.H
View file @
12c903bb
...
...
@@ -52,11 +52,11 @@ SourceFiles
namespace
Foam
{
// Forward declarations
template
<
class
T
>
class
List
;
template
<
class
T
>
class
UList
;
typedef
List
<
word
>
wordList
;
// Forward declaration of friend functions and operators
class
wordRe
;
class
fileName
;
...
...
src/OpenFOAM/primitives/strings/word/word.H
View file @
12c903bb
...
...
@@ -47,7 +47,7 @@ SourceFiles
namespace
Foam
{
// Forward declaration
of friend functions and operator
s
// Forward declarations
class
word
;
Istream
&
operator
>>
(
Istream
&
is
,
word
&
w
);
Ostream
&
operator
<<
(
Ostream
&
os
,
const
word
&
w
);
...
...
@@ -218,13 +218,37 @@ public:
};
//
Global Operators
//
* * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
//- Join words as camelCase, capitalizing the first letter of b.
// No effect if either argument is empty.
word
operator
&
(
const
word
&
a
,
const
word
&
b
);
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
//- Extract name (as a word) from an object, typically using its name() method.
template
<
class
T
>
struct
nameOp
{
inline
word
operator
()(
const
T
&
obj
)
const
{
return
obj
.
name
();
}
};
//- Extract type (as a word) from an object, typically using its type() method.
template
<
class
T
>
struct
typeOp
{
inline
word
operator
()(
const
T
&
obj
)
const
{
return
obj
.
type
();
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
}
// End namespace Foam
...
...
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