Commit 480a3c6e authored by mattijs's avatar mattijs
Browse files

wildcards in dictionaries

parent bac9f1e1
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::keyType
Description
A class for handling keywords in dictionaries.
A keyType is the keyword of a dictionary. It differs from word in that
it accepts wildcards.
SourceFiles
keyType.C
keyTypeIO.C
\*---------------------------------------------------------------------------*/
#ifndef keyType_H
#define keyType_H
#include "word.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class Istream;
class Ostream;
/*---------------------------------------------------------------------------*\
Class keyType Declaration
\*---------------------------------------------------------------------------*/
class keyType
:
public word
{
// Private member data
bool isWildCard_;
// Private Member Functions
//- Disallow assignments where we cannot determine string/word type
void operator=(const std::string&);
public:
// Constructors
//- Construct null
inline keyType();
//- Construct as copy
inline keyType(const keyType& s);
//- Construct as copy of word
inline keyType(const word& s);
//- Construct as copy of string. Expect it to be regular expression.
inline keyType(const string& s);
//- Construct as copy of character array
inline keyType(const char* s);
//- Construct as copy of std::string
inline keyType(const std::string& s, const bool isWildCard);
//- Construct from Istream
keyType(Istream& is);
// Member functions
//- Is this character valid for a keyType
inline static bool valid(char c);
//- Is the type a wildcard?
inline bool isWildCard() const;
// Member operators
// Assignment
inline void operator=(const keyType& s);
//- Assign from regular expression.
inline void operator=(const string& s);
inline void operator=(const word& s);
inline void operator=(const char*);
// IOstream operators
friend Istream& operator>>(Istream& is, keyType& w);
friend Ostream& operator<<(Ostream& os, const keyType& w);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "keyTypeI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct null
inline Foam::keyType::keyType()
:
word(),
isWildCard_(false)
{}
//- Construct as copy
inline Foam::keyType::keyType(const keyType& s)
:
word(s, false),
isWildCard_(s.isWildCard())
{}
//- Construct as copy of word
inline Foam::keyType::keyType(const word& s)
:
word(s, false),
isWildCard_(false)
{}
//- Construct as copy of string. Expect it to be regular expression
inline Foam::keyType::keyType(const string& s)
:
word(s, false),
isWildCard_(true)
{}
//- Construct as copy of character array
inline Foam::keyType::keyType(const char* s)
:
word(s, false),
isWildCard_(false)
{}
//- Construct as copy of std::string
inline Foam::keyType::keyType
(
const std::string& s,
const bool isWildCard
)
:
word(s, false),
isWildCard_(isWildCard)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::keyType::valid(char c)
{
return c != '"';
}
bool Foam::keyType::isWildCard() const
{
return isWildCard_;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline void Foam::keyType::operator=(const keyType& s)
{
// Bypass checking
string::operator=(s);
isWildCard_ = s.isWildCard();
}
inline void Foam::keyType::operator=(const word& s)
{
word::operator=(s);
isWildCard_ = false;
}
inline void Foam::keyType::operator=(const string& s)
{
// Bypass checking
string::operator=(s);
isWildCard_ = true;
}
inline void Foam::keyType::operator=(const char* s)
{
// Bypass checking
string::operator=(s);
isWildCard_ = false;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Istream constructor and IOstream operators for word.
\*---------------------------------------------------------------------------*/
#include "keyType.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::keyType::keyType(Istream& is)
:
word()
{
is >> *this;
}
Foam::Istream& Foam::operator>>(Istream& is, keyType& w)
{
token t(is);
if (!t.good())
{
is.setBad();
return is;
}
if (t.isWord())
{
w = t.wordToken();
}
else if (t.isString())
{
// Assign from string. Sets regular expression.
w = t.stringToken();
}
else
{
is.setBad();
FatalIOErrorIn("operator>>(Istream&, keyType&)", is)
<< "wrong token type - expected word or string found "
<< t.info()
<< exit(FatalIOError);
return is;
}
// Check state of IOstream
is.check("Istream& operator>>(Istream&, keyType&)");
return is;
}
Foam::Ostream& Foam::operator<<(Ostream& os, const keyType& w)
{
os.write(w);
os.check("Ostream& operator<<(Ostream&, const keyType&)");
return os;
}
// ************************************************************************* //
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment