mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: define nameOp<>, typeOp<>, sizeOp<> functors (issue #1013)
This commit is contained in:
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -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 * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user