Skip to content
  • Henry Weller's avatar
    Completed boundaryField() -> boundaryFieldRef() · a4e2afa4
    Henry Weller authored
    Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1938
    
    Because C++ does not support overloading based on the return-type there
    is a problem defining both const and non-const member functions which
    are resolved based on the const-ness of the object for which they are
    called rather than the intent of the programmer declared via the
    const-ness of the returned type.  The issue for the "boundaryField()"
    member function is that the non-const version increments the
    event-counter and checks the state of the stored old-time fields in case
    the returned value is altered whereas the const version has no
    side-effects and simply returns the reference.  If the the non-const
    function is called within the patch-loop the event-counter may overflow.
    To resolve this it in necessary to avoid calling the non-const form of
    "boundaryField()" if the results is not altered and cache the reference
    outside the patch-loop when mutation of the patch fields is needed.
    
    The most straight forward way of resolving this problem is to name the
    const and non-const forms of the member functions differently e.g. the
    non-const form could be named:
    
        mutableBoundaryField()
        mutBoundaryField()
        nonConstBoundaryField()
        boundaryFieldRef()
    
    Given that in C++ a reference is non-const unless specified as const:
    "T&" vs "const T&" the logical convention would be
    
        boundaryFieldRef()
        boundaryFieldConstRef()
    
    and given that the const form which is more commonly used is it could
    simply be named "boundaryField()" then the logical convention is
    
        GeometricBoundaryField& boundaryFieldRef();
    
        inline const GeometricBoundaryField& boundaryField() const;
    
    This is also consistent with the new "tmp" class for which non-const
    access to the stored object is obtained using the ".ref()" member function.
    
    This new convention for non-const access to the components of
    GeometricField will be applied to "dimensionedInternalField()" and "internalField()" in the
    future, i.e. "dimensionedInternalFieldRef()" and "internalFieldRef()".
    a4e2afa4