STYLE: inherit SubField from FieldBase instead of refCount

- at the moment there is no significant difference since FieldBase is
  essentially just a refCount anyhow, but changing the inheritance
  ensures that reinterpret casting from SubField -> Field will
  continue to work if FieldBase is changed in the future.
This commit is contained in:
Mark Olesen
2021-12-09 10:42:31 +01:00
parent efb187e3f7
commit 698ff5eedc
5 changed files with 39 additions and 30 deletions

View File

@ -47,10 +47,10 @@ SourceFiles
#include "tmp.H"
#include "direction.H"
#include "VectorSpace.H"
#include "scalarList.H"
#include "labelList.H"
#include "scalarList.H"
#include "FieldBase.H"
#include "VectorSpace.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -92,11 +92,8 @@ public:
// Static Member Functions
//- Return nullObject reference field
inline static const Field<Type>& null()
{
return NullObjectRef<Field<Type>>();
}
//- Return nullObject reference Field
inline static const Field<Type>& null();
// Constructors

View File

@ -27,7 +27,7 @@ Class
Foam::FieldBase
Description
Template invariant parts for Field
Template invariant parts for Field and SubField
SourceFiles
FieldBase.C
@ -54,17 +54,19 @@ class FieldBase
{
public:
// Static data members
// Static Data Members
//- Typename for Field
static const char* const typeName;
//- Permit read construct from a larger size.
// Mostly required for things like column mesh, for example.
static bool allowConstructFromLargerSize;
// Constructors
//- Construct null, with refCount zero
//- Default construct, refCount zero
constexpr FieldBase() noexcept
:
refCount()

View File

@ -25,6 +25,15 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type>
inline const Foam::Field<Type>& Foam::Field<Type>::null()
{
return NullObjectRef<Field<Type>>();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>

View File

@ -28,11 +28,9 @@ Class
Foam::SubField
Description
SubField is a Field obtained as a section of another Field.
Thus it is itself unallocated so that no storage is allocated or
deallocated during its use. To achieve this behaviour, SubField is
derived from a SubList rather than a List.
SubField is a Field obtained as a section of another Field,
without its own allocation.
SubField is derived from a SubList rather than a List.
SourceFiles
SubFieldI.H
@ -42,17 +40,15 @@ SourceFiles
#ifndef SubField_H
#define SubField_H
#include "SubList.H"
#include "Field.H"
#include "VectorSpace.H"
#include "SubList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declarations
template<class Type> class Field;
// Forward Declarations
template<class Type> class SubField;
/*---------------------------------------------------------------------------*\
@ -62,7 +58,7 @@ template<class Type> class SubField;
template<class Type>
class SubField
:
public refCount,
public FieldBase,
public SubList<Type>
{
public:
@ -71,6 +67,12 @@ public:
typedef typename pTraits<Type>::cmptType cmptType;
// Static Member Functions
//- Return nullObject reference SubField
inline static const SubField<Type>& null();
// Constructors
//- Default construct, zero-sized and nullptr
@ -120,9 +122,6 @@ public:
// Member Functions
//- Return a null SubField
static inline const SubField<Type>& null();
//- Return a component field of the field
inline tmp<Field<cmptType>> component(const direction) const;

View File

@ -26,6 +26,15 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type>
inline const Foam::SubField<Type>& Foam::SubField<Type>::null()
{
return NullObjectRef<SubField<Type>>();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
@ -105,13 +114,6 @@ inline Foam::SubField<Type>::SubField
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
inline const Foam::SubField<Type>& Foam::SubField<Type>::null()
{
return NullObjectRef<SubField<Type>>();
}
template<class Type>
inline Foam::tmp<Foam::Field<typename Foam::SubField<Type>::cmptType>>
Foam::SubField<Type>::component