Test-sizeof.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Test the sizeof various classes.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "bool.H"
30 #include "Switch.H"
31 #include "string.H"
32 #include "dictionary.H"
33 #include "nil.H"
34 #include "IOstreams.H"
35 #include "IStringStream.H"
36 
37 namespace Foam
38 {
40  {
41  public:
42  bool b_;
43 
44  hasBoolClass(const bool val=false)
45  :
46  b_(false)
47  {}
48  };
49 
50 }
51 
52 
53 using namespace Foam;
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 // Main program:
57 
58 int main(int argc, char *argv[])
59 {
60  cout<<"sizeof\n------\n";
61  {
62  nil x;
63  cout<<"nil:" << sizeof(x) << nl;
64  }
65  {
66  bool x(0);
67  cout<<"bool:" << sizeof(x) << nl;
68  }
69  {
70  hasBoolClass x(true);
71  cout<<"hasBoolClass:" << sizeof(x) << nl;
72  }
73 
74  {
75  Switch x("n");
76  cout<<"Switch:" << sizeof(x) << nl;
77  cout<<"Switch::switchType=" << sizeof(Switch::switchType) << nl;
78  }
79 
80  {
81  scalar x(0);
82  cout<<"scalar:" << sizeof(x) << nl;
83  }
84 
85  {
86  label x(0);
87  cout<<"label:" << sizeof(x) << nl;
88  }
89 
90  {
91  cout<<"int:" << sizeof(int) << nl;
92  cout<<"long:" << sizeof(long) << nl;
93  cout<<"float:" << sizeof(float) << nl;
94  cout<<"double:" << sizeof(double) << nl;
95  }
96 
97 
98  Info << "---\nEnd\n" << endl;
99 
100  return 0;
101 }
102 
103 
104 // ************************************************************************* //
main
int main(int argc, char *argv[])
Definition: Test-sizeof.C:58
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::nil
A zero-sized class without any storage. Used, for example, in HashSet.
Definition: nil.H:58
string.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IStringStream.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::hasBoolClass::hasBoolClass
hasBoolClass(const bool val=false)
Definition: Test-sizeof.C:44
Switch.H
bool.H
System bool.
nil.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Switch::switchType
switchType
The various text representations for a switch value.
Definition: Switch.H:88
Foam::hasBoolClass::b_
bool b_
Definition: Test-sizeof.C:42
Foam::hasBoolClass
Definition: Test-sizeof.C:39
dictionary.H
x
x
Definition: LISASMDCalcMethod2.H:52