char.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Primitive
28  char
29 
30 Description
31  A character and a pointer to a character string.
32 
33 SourceFiles
34  char.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_primitives_char_H
39 #define Foam_primitives_char_H
40 
41 #include "pTraits.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 //- Read single character
51 char readChar(Istream& is);
52 
53 //- Read single character
54 Istream& operator>>(Istream& is, char& c);
55 
56 //- Write single character
57 Ostream& operator<<(Ostream& os, const char c);
58 
59 //- Write a nul-terminated C-string
60 Ostream& operator<<(Ostream& os, const char* str);
61 
62 //- Test for whitespace (C-locale)
63 inline bool isspace(char c) noexcept
64 {
65  return
66  (
67  c == ' ' // (0x20) space (SPC)
68  || c == '\t' // (0x09) horizontal tab (TAB)
69  || c == '\n' // (0x0a) newline (LF)
70  || c == '\v' // (0x0b) vertical tab (VT)
71  || c == '\f' // (0x0c) feed (FF)
72  || c == '\r' // (0x0d) carriage return (CR)
73  );
74 }
75 
76 
77 /*---------------------------------------------------------------------------*\
78  Specialization pTraits<char>
79 \*---------------------------------------------------------------------------*/
80 
81 //- Template specialisation for pTraits<char>
82 template<>
83 class pTraits<char>
84 {
85  char p_;
86 
87 public:
88 
89  // Static Data Members
90 
91  static const char* const typeName;
92 
93 
94  // Constructors
95 
96  //- Copy construct from primitive
97  explicit pTraits(char val) noexcept
98  :
99  p_(val)
100  {}
101 
102  //- Read construct from Istream
103  explicit pTraits(Istream& is);
104 
105 
106  // Member Functions
108  //- Return the value
109  operator char() const noexcept { return p_; }
110 
111  //- Access the value
112  operator char&() noexcept { return p_; }
113 };
114 
115 
116 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117 
118 } // End namespace Foam
119 
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 
122 #endif
124 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
pTraits(const Base &obj)
Copy construct from base class.
Definition: pTraits.H:86
Istream & operator>>(Istream &, directionInfo &)
char readChar(Istream &is)
Read single character.
Definition: char.C:40
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
const dimensionedScalar c
Speed of light in a vacuum.
bool isspace(char c) noexcept
Test for whitespace (C-locale)
Definition: char.H:69
Namespace for OpenFOAM.