ENH: zero tag for constructing various IO types

- for int64 compilations this disambiguates between '0' as int32 (size)
  or as bool 'false' for local processor validity

  Eg,

     IOList list(io, 0);     <- With label-size 64: is this bool or label?
     IOList list(io, Zero);  <- Size = 0 (int32/int64), not a bool
This commit is contained in:
Mark Olesen
2022-05-11 17:39:18 +02:00
parent 812f4c4f09
commit 5d9456187d
10 changed files with 113 additions and 30 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -51,9 +51,9 @@ void Foam::CompactIOField<T, BaseType>::readFromStream(const bool valid)
else else
{ {
FatalIOErrorInFunction(is) FatalIOErrorInFunction(is)
<< "unexpected class name " << headerClassName() << "Unexpected class name " << headerClassName()
<< " expected " << typeName << " or " << IOField<T>::typeName << " expected " << typeName
<< endl << " or " << IOField<T>::typeName << nl
<< " while reading object " << name() << " while reading object " << name()
<< exit(FatalIOError); << exit(FatalIOError);
} }
@ -104,7 +104,27 @@ template<class T, class BaseType>
Foam::CompactIOField<T, BaseType>::CompactIOField Foam::CompactIOField<T, BaseType>::CompactIOField
( (
const IOobject& io, const IOobject& io,
const label size Foam::zero
)
:
regIOobject(io)
{
if
(
io.readOpt() == IOobject::MUST_READ
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
readFromStream();
}
}
template<class T, class BaseType>
Foam::CompactIOField<T, BaseType>::CompactIOField
(
const IOobject& io,
const label len
) )
: :
regIOobject(io) regIOobject(io)
@ -119,7 +139,7 @@ Foam::CompactIOField<T, BaseType>::CompactIOField
} }
else else
{ {
Field<T>::setSize(size); Field<T>::resize(len);
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -39,18 +39,17 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef CompactIOField_H #ifndef Foam_CompactIOField_H
#define CompactIOField_H #define Foam_CompactIOField_H
#include "IOField.H" #include "IOField.H"
#include "regIOobject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// Forward declarations // Forward Declarations
template<class T, class BaseType> class CompactIOField; template<class T, class BaseType> class CompactIOField;
template<class T, class BaseType> Istream& operator>> template<class T, class BaseType> Istream& operator>>
@ -94,11 +93,14 @@ public:
//- Construct from IOobject //- Construct from IOobject
explicit CompactIOField(const IOobject& io); explicit CompactIOField(const IOobject& io);
//- Construct from IOobject; does local processor require reading? //- Construct from IOobject, with local processor conditional reading
CompactIOField(const IOobject& io, const bool valid); CompactIOField(const IOobject& io, const bool valid);
//- Construct from IOobject and size //- Construct from IOobject and zero size (if not read)
CompactIOField(const IOobject& io, const label size); CompactIOField(const IOobject& io, Foam::zero);
//- Construct from IOobject and size (if not read)
CompactIOField(const IOobject& io, const label len);
//- Construct from IOobject and a List/Field content //- Construct from IOobject and a List/Field content
CompactIOField(const IOobject& io, const UList<T>& content); CompactIOField(const IOobject& io, const UList<T>& content);

View File

@ -103,6 +103,19 @@ Foam::CompactIOList<T, BaseType>::CompactIOList(const IOobject& io)
} }
template<class T, class BaseType>
Foam::CompactIOList<T, BaseType>::CompactIOList
(
const IOobject& io,
Foam::zero
)
:
regIOobject(io)
{
readContents();
}
template<class T, class BaseType> template<class T, class BaseType>
Foam::CompactIOList<T, BaseType>::CompactIOList Foam::CompactIOList<T, BaseType>::CompactIOList
( (

View File

@ -67,7 +67,7 @@ template<class T, class BaseType> Ostream& operator<<
); );
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class CompactIOList Declaration Class CompactIOList Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class T, class BaseType> template<class T, class BaseType>
@ -106,6 +106,9 @@ public:
//- Construct from IOobject //- Construct from IOobject
explicit CompactIOList(const IOobject& io); explicit CompactIOList(const IOobject& io);
//- Construct from IOobject and zero size (if not read)
CompactIOList(const IOobject& io, Foam::zero);
//- Construct from IOobject and default length of CompactIOList //- Construct from IOobject and default length of CompactIOList
CompactIOList(const IOobject& io, const label len); CompactIOList(const IOobject& io, const label len);
@ -115,9 +118,9 @@ public:
//- Construct by transferring the List content //- Construct by transferring the List content
CompactIOList(const IOobject& io, List<T>&& content); CompactIOList(const IOobject& io, List<T>&& content);
// Destructor
virtual ~CompactIOList() = default; //- Destructor
virtual ~CompactIOList() = default;
// Member Functions // Member Functions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd. Copyright (C) 2016-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -43,7 +43,19 @@ Foam::GlobalIOList<Type>::GlobalIOList(const IOobject& io)
template<class Type> template<class Type>
Foam::GlobalIOList<Type>::GlobalIOList(const IOobject& io, const label size) Foam::GlobalIOList<Type>::GlobalIOList(const IOobject& io, Foam::zero)
:
regIOobject(io)
{
// Check for MUST_READ_IF_MODIFIED
warnNoRereading<GlobalIOList<Type>>();
readHeaderOk(IOstream::BINARY, typeName);
}
template<class Type>
Foam::GlobalIOList<Type>::GlobalIOList(const IOobject& io, const label len)
: :
regIOobject(io) regIOobject(io)
{ {
@ -52,7 +64,7 @@ Foam::GlobalIOList<Type>::GlobalIOList(const IOobject& io, const label size)
if (!readHeaderOk(IOstream::BINARY, typeName)) if (!readHeaderOk(IOstream::BINARY, typeName))
{ {
List<Type>::setSize(size); List<Type>::resize(len);
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015-2017 OpenFOAM Foundation Copyright (C) 2015-2017 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -69,8 +69,11 @@ public:
//- Construct from IOobject //- Construct from IOobject
explicit GlobalIOList(const IOobject& io); explicit GlobalIOList(const IOobject& io);
//- Construct from IOobject //- Construct from IOobject and zero size (if not read)
GlobalIOList(const IOobject& io, const label size); GlobalIOList(const IOobject& io, Foam::zero);
//- Construct from IOobject and list size (if not read)
GlobalIOList(const IOobject& io, const label len);
//- Construct from IOobject and a List //- Construct from IOobject and a List
GlobalIOList(const IOobject& io, const UList<Type>& content); GlobalIOList(const IOobject& io, const UList<Type>& content);

View File

@ -102,6 +102,18 @@ Foam::IOField<Type>::IOField(const IOobject& io, const bool valid)
} }
template<class Type>
Foam::IOField<Type>::IOField(const IOobject& io, Foam::zero)
:
regIOobject(io)
{
// Check for MUST_READ_IF_MODIFIED
warnNoRereading<IOField<Type>>();
readContents();
}
template<class Type> template<class Type>
Foam::IOField<Type>::IOField(const IOobject& io, const label len) Foam::IOField<Type>::IOField(const IOobject& io, const label len)
: :

View File

@ -79,13 +79,16 @@ public:
//- Construct from IOobject //- Construct from IOobject
explicit IOField(const IOobject& io); explicit IOField(const IOobject& io);
//- Construct from IOobject; does local processor require reading? //- Construct from IOobject, with local processor conditional reading
IOField(const IOobject& io, const bool valid); IOField(const IOobject& io, const bool valid);
//- Construct from IOobject and size (does not set values) //- Construct from IOobject and zero size (if not read)
IOField(const IOobject& io, const label size); IOField(const IOobject& io, Foam::zero);
//- Construct from IOobject and a List/Field content //- Construct from IOobject and field size (if not read)
IOField(const IOobject& io, const label len);
//- Construct from IOobject and copy of List/Field content
IOField(const IOobject& io, const UList<Type>& content); IOField(const IOobject& io, const UList<Type>& content);
//- Construct by transferring the Field content //- Construct by transferring the Field content

View File

@ -65,6 +65,18 @@ Foam::IOList<T>::IOList(const IOobject& io)
} }
template<class T>
Foam::IOList<T>::IOList(const IOobject& io, Foam::zero)
:
regIOobject(io)
{
// Check for MUST_READ_IF_MODIFIED
warnNoRereading<IOList<T>>();
readContents();
}
template<class T> template<class T>
Foam::IOList<T>::IOList(const IOobject& io, const label len) Foam::IOList<T>::IOList(const IOobject& io, const label len)
: :

View File

@ -79,13 +79,16 @@ public:
//- Construct from IOobject //- Construct from IOobject
explicit IOList(const IOobject& io); explicit IOList(const IOobject& io);
//- Construct from IOobject and size of IOList //- Construct from IOobject and zero size (if not read)
IOList(const IOobject& io, Foam::zero);
//- Construct from IOobject and list size (if not read)
IOList(const IOobject& io, const label len); IOList(const IOobject& io, const label len);
//- Construct from IOobject and a copy of UList content //- Construct from IOobject and a copy of content
IOList(const IOobject& io, const UList<T>& content); IOList(const IOobject& io, const UList<T>& content);
//- Construct by transferring the List content //- Construct by transferring the content
IOList(const IOobject& io, List<T>&& content); IOList(const IOobject& io, List<T>&& content);