openfoam/applications/test/sizeof/Test-sizeof.C
Mark Olesen 33f9ae5080 ENH: improvements to IOstreamOption
* Support default values for format/compress enum lookups.

  - Avoids situations where the preferred default format is not ASCII.
    For example, with dictionary input:

        format binar;

    The typing mistake would previously have caused formatEnum to
    default to ASCII. We can now properly control its behaviour.

        IOstream::formatEnum
        (
            dict.get<word>("format"), IOstream::BINARY
        );

    Allowing us to switch ascii/binary, using BINARY by default even in
    the case of spelling mistakes. The mistakes are flagged, but the
    return value can be non-ASCII.

* The format/compression lookup behave as pass-through if the lookup
  string is empty.

  - Allows the following to work without complaint

      IOstream::formatEnum
      (
          dict.getOrDefault("format", word::null), IOstream::BINARY
      );

  - Or use constructor-like failsafe method

      IOstream::formatEnum("format", dict, IOstream::BINARY);

  - Apply the same behaviour with setting stream format/compression
    from a word.

       is.format("binar");

    will emit a warning, but leave the stream format UNCHANGED

* Rationalize versionNumber construction

  - constexpr constructors where possible.
    Default construct is the "currentVersion"

  - Construct from token to shift the burden to versionNumber.
    Support token as argument to version().

    Now:

        is.version(headerDict.get<token>("version"));

    or failsafe constructor method

        is.version
        (
            IOstreamOption::versionNumber("version", headerDict)
        );

    Before (controlled input):

        is.version
        (
            IOstreamOption::versionNumber
            (
                headerDict.get<float>("version")
            )
        );

    Old, uncontrolled input - has been removed:

        is.version(headerDict.lookup("version"));

* improve consistency, default behaviour for IOstreamOption construct

  - constexpr constructors where possible

  - add copy construct with change of format.

  - construct IOstreamOption from streamFormat is now non-explicit.
    This is a commonly expected result with no ill-effects
2020-02-18 21:51:35 +01:00

146 lines
3.7 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
Description
Test the sizeof various classes.
\*---------------------------------------------------------------------------*/
#include "bool.H"
#include "Switch.H"
#include "string.H"
#include "dictionary.H"
#include "nil.H"
#include "IOstreams.H"
#include "PstreamBuffers.H"
#include "argList.H"
#include "Time.H"
namespace Foam
{
class hasBoolClass
{
public:
bool b_;
hasBoolClass(const bool val=false)
:
b_(false)
{}
};
}
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
cout<<"sizeof\n------\n";
if (true)
{
cout<<"IOstreamOption:" << sizeof(IOstreamOption) << nl;
cout<<"IOstream:" << sizeof(IOstream) << nl;
cout<<"Istream:" << sizeof(Istream) << nl;
cout<<"Ostream:" << sizeof(Ostream) << nl;
cout<<"ISstream:" << sizeof(ISstream) << nl;
cout<<"OSstream:" << sizeof(OSstream) << nl;
cout<<"IPstream:" << sizeof(IPstream) << nl;
cout<<"OPstream:" << sizeof(OPstream) << nl;
}
{
nil x;
cout<<"nil:" << sizeof(x) << nl;
}
#if 0
{
argList x(argc, argv);
cout<<"argList:" << sizeof(x) << nl;
TimePaths y(x);
cout<<"TimePaths:" << sizeof(y) << nl;
}
#endif
{
zero x;
cout<<"zero:" << sizeof(x) << nl;
}
{
bool x(0);
cout<<"bool:" << sizeof(x) << nl;
}
{
hasBoolClass x(true);
cout<<"hasBoolClass:" << sizeof(x) << nl;
}
{
Switch x("n");
cout<<"Switch:" << sizeof(x) << nl;
cout<<"Switch::switchType=" << sizeof(Switch::switchType) << nl;
}
{
scalar x(0);
cout<<"scalar:" << sizeof(x) << nl;
}
{
label x(0);
cout<<"label:" << sizeof(x) << nl;
}
{
cout<<"short:" << sizeof(short) << nl;
cout<<"int:" << sizeof(int) << nl;
cout<<"long:" << sizeof(long) << nl;
cout<<"float:" << sizeof(float) << nl;
cout<<"double:" << sizeof(double) << nl;
}
{
cout<<"string:" << sizeof(Foam::string) << nl;
}
cout<<"IOstream:" << sizeof(Foam::IOstream) << nl;
cout<<"PstreamBuffers:" << sizeof(Foam::PstreamBuffers) << nl;
cout<<"Time:" << sizeof(Foam::Time) << nl;
Info << "---\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //