FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

wordI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <cctype>
00027 
00028 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 inline void Foam::word::stripInvalid()
00033 {
00034     // skip stripping unless debug is active to avoid
00035     // costly operations
00036     if (debug && string::stripInvalid<word>(*this))
00037     {
00038         std::cerr
00039             << "word::stripInvalid() called for word "
00040             << this->c_str() << std::endl;
00041 
00042         if (debug > 1)
00043         {
00044             std::cerr
00045                 << "    For debug level (= " << debug
00046                 << ") > 1 this is considered fatal" << std::endl;
00047             std::abort();
00048         }
00049     }
00050 }
00051 
00052 
00053 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00054 
00055 inline Foam::word::word(const word& w)
00056 :
00057     string(w)
00058 {}
00059 
00060 
00061 inline Foam::word::word()
00062 :
00063     string()
00064 {}
00065 
00066 
00067 inline Foam::word::word(const string& s, const bool doStripInvalid)
00068 :
00069     string(s)
00070 {
00071     if (doStripInvalid)
00072     {
00073         stripInvalid();
00074     }
00075 }
00076 
00077 
00078 inline Foam::word::word(const std::string& s, const bool doStripInvalid)
00079 :
00080     string(s)
00081 {
00082     if (doStripInvalid)
00083     {
00084         stripInvalid();
00085     }
00086 }
00087 
00088 
00089 inline Foam::word::word(const char* s, const bool doStripInvalid)
00090 :
00091     string(s)
00092 {
00093     if (doStripInvalid)
00094     {
00095         stripInvalid();
00096     }
00097 }
00098 
00099 inline Foam::word::word
00100 (
00101     const char* s,
00102     const size_type n,
00103     const bool doStripInvalid
00104 )
00105 :
00106     string(s, n)
00107 {
00108     if (doStripInvalid)
00109     {
00110         stripInvalid();
00111     }
00112 }
00113 
00114 
00115 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00116 
00117 inline bool Foam::word::valid(char c)
00118 {
00119     return
00120     (
00121         !isspace(c)
00122      && c != '"'   // string quote
00123      && c != '\''  // string quote
00124      && c != '/'   // path separator
00125      && c != ';'   // end statement
00126      && c != '{'   // beg subdict
00127      && c != '}'   // end subdict
00128     );
00129 }
00130 
00131 
00132 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00133 
00134 inline const Foam::word& Foam::word::operator=(const word& q)
00135 {
00136     string::operator=(q);
00137     return *this;
00138 }
00139 
00140 
00141 inline const Foam::word& Foam::word::operator=(const string& q)
00142 {
00143     string::operator=(q);
00144     stripInvalid();
00145     return *this;
00146 }
00147 
00148 
00149 inline const Foam::word& Foam::word::operator=(const std::string& q)
00150 {
00151     string::operator=(q);
00152     stripInvalid();
00153     return *this;
00154 }
00155 
00156 
00157 inline const Foam::word& Foam::word::operator=(const char* q)
00158 {
00159     string::operator=(q);
00160     stripInvalid();
00161     return *this;
00162 }
00163 
00164 
00165 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00166 
00167 inline Foam::word Foam::operator&(const word& a, const word& b)
00168 {
00169     if (b.size())
00170     {
00171         string ub = b;
00172         ub.string::operator[](0) = char(toupper(ub.string::operator[](0)));
00173 
00174         return a + ub;
00175     }
00176     else
00177     {
00178         return a;
00179     }
00180 }
00181 
00182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00183 
00184 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines