1. 30 Jul, 2020 1 commit
    • Mark Olesen's avatar
      BUG: inconsistent check in non-const '->' dereference (tmp, refPtr) · 23ea498c
      Mark Olesen authored
      - old code just checked for pointer vs non-pointer.
        Should actually treat CREF and REF types differently
        Overseen in commit be058bec. Only affects develop branch
      
      ENH: improved naming consistency in tmp, refPtr
      
      - also use long-form to check for pointer type instead of the isTmp()
        method. Makes differences between PTR, CREF, REF easier to spot.
      
      STYLE: typeName() for tmp, refPtr is static
      23ea498c
  2. 21 Jul, 2020 1 commit
    • Mark Olesen's avatar
      ENH: support writable reference for tmp (#1775) · be058bec
      Mark Olesen authored
      - improves flexibility. Can tag a tmp as allowing non-const access to
        the reference and skip additional const_cast in following code. For
        example,
      
            tmp<volScalarField> tfld(nullptr);
            auto* ptr = getObjectPtr<volScalarField>("field");
            if (ptr)
            {
                tfld.ref(*ptr);
            }
            else
            {
                tfld.reset(volScalarField::New(...));
            }
            auto& fld = tfld.ref();
      
      ENH: renamed tmpNrc to refPtr
      
      - the name 'refPtr' (reference|pointer) should be easier to remember
        than tmpNrc (tmp, but non-ref-counted).
      
      - provide tmpNrc typedef and header for code compatibility
      
      NOTE
      
      - in some places refPtr and tmp can be used instead of a
        std::reference_wrapper for handling external references.
      
        Unlike std::reference_wrapper, it can be default constructed
        (holding nothing), whereas reference_wrapper may need a dummy
        reference. However, the lifetime extension of references _may_ be
        better with reference_wrapper.
      be058bec
  3. 16 Jul, 2020 3 commits
  4. 19 Nov, 2019 1 commit
    • Mark Olesen's avatar
      ENH: add move reset and move assignment for tmp, tmpNrc · 83d6aa42
      Mark Olesen authored
      - improves similarity to autoPtr. Simplifies coding.
      
        Example,
      
          tmp<volScalarField> tfield;
      
          // sometime later...
      
          tfield.reset
          (
              volScalarField::New("myfield", mesh, dimensionedScalar(Zero))
          );
      
      - as per tmp, disallow tmpNrc assignment from literal nullptr
      
      - as per autoPtr, allow explicit test as bool (same as valid).
      83d6aa42
  5. 31 Oct, 2019 1 commit
  6. 05 Nov, 2019 1 commit
  7. 11 Feb, 2019 1 commit
  8. 06 Feb, 2019 1 commit
  9. 20 Dec, 2018 1 commit
    • Mark Olesen's avatar
      ENH: add get() accessor to tmp classes · 08335beb
      Mark Olesen authored
      - similar to autoPtr and unique_ptr. Returns the pointer value without
        any checks. This provides a simple way for use to use either
        an autoPtr or a tmp for local memory management without accidentally
        stealing the pointer.
      
        Eg,
      
           volVectorField* ptr;
           tmp<volVectorField> tempField;
      
           if (someField.valid())
           {
               ptr = someField.get();
           }
           else
           {
               tempField.reset(new volVectorField(....));
               ptr = tmpField.get();
           }
      
           const volVectorField& withField = *ptr;
      
      STYLE: make more tmp methods noexcept
      08335beb
  10. 26 Feb, 2018 1 commit
    • Mark Olesen's avatar
      ENH: cleanup tmp class (issue #639) · 52b36f84
      Mark Olesen authored
      Improve alignment of its behaviour with std::shared_ptr
      
        - element_type typedef
        - swap, reset methods
      
      * additional reference access methods:
      
      cref()
          returns a const reference, synonymous with operator().
          This provides a more verbose alternative to using the '()' operator
          when that is desired.
      
              Mnemonic: a const form of 'ref()'
      
      constCast()
          returns a non-const reference, regardless if the underlying object
          itself is a managed pointer or a const object.
          This is similar to ref(), but more permissive.
      
              Mnemonic: const_cast<>
      
          Using the constCast() method greatly reduces the amount of typing
          and reading. And since the data type is already defined via the tmp
          template parameter, the type deduction is automatically known.
      
          Previously,
      
              const tmp<volScalarField>& tfld;
      
              const_cast<volScalarField&>(tfld()).rename("name");
              volScalarField& fld = const_cast<volScalarField&>(tfld());
      
          Now,
      
              tfld.constCast().rename("name");
              auto& fld = tfld.constCast();
      
      --
      
      BUG: attempts to move tmp value that may still be shared.
      
      - old code simply checked isTmp() to decide if the contents could be
        transfered. However, this means that the content of a shared tmp
        would be removed, leaving other instances without content.
      
      * movable() method checks that for a non-null temporary that is
        unique (not shared).
      52b36f84
  11. 26 Jan, 2018 1 commit
    • Mark Olesen's avatar
      ENH: minor cleanup of the Xfer class · 25339a5b
      Mark Olesen authored
      - simplify structure, removed unused constuctors.
      
      - transfer from base objects via '=' assignment removed as being too
        non-transparent
      
      - add New factory method with perfect forwarding.
      25339a5b
  12. 22 Nov, 2017 2 commits
  13. 14 Jul, 2017 2 commits
  14. 13 Jul, 2017 1 commit
  15. 03 Dec, 2016 1 commit
  16. 23 May, 2016 1 commit
  17. 21 May, 2016 1 commit
  18. 22 Mar, 2016 1 commit
  19. 27 Feb, 2016 1 commit
    • Henry Weller's avatar
      tmp: Limit the number of references to a temporary object to 2 · 0830ace9
      Henry Weller authored
      which reduces the number of potential problems with the reuse of
      temporary objects.
      
      In order to avoid unnecessary creation of tmp's referring to temporary
      objects the assignment operator now transfers ownership of the object
      and resets the argument.
      0830ace9
  20. 26 Feb, 2016 1 commit
    • Henry Weller's avatar
      OpenFOAM: Updated all libraries, solvers and utilities to use the new const-safe tmp · cd852be3
      Henry Weller authored
      The deprecated non-const tmp functionality is now on the compiler switch
      NON_CONST_TMP which can be enabled by adding -DNON_CONST_TMP to EXE_INC
      in the Make/options file.  However, it is recommended to upgrade all
      code to the new safer tmp by using the '.ref()' member function rather
      than the non-const '()' dereference operator when non-const access to
      the temporary object is required.
      
      Please report any problems on Mantis.
      
      Henry G. Weller
      CFD Direct.
      cd852be3
  21. 25 Feb, 2016 2 commits
  22. 24 Feb, 2016 1 commit
    • Henry Weller's avatar
      tmp: Improved reference count checks to provide better error diagnostics · c02bf70e
      Henry Weller authored
      in case of tmp misuse.
      
      Simplified tmp reuse pattern in field algebra to use tmp copy and
      assignment rather than the complex delayed call to 'ptr()'.
      
      Removed support for unused non-const 'REF' storage of non-tmp objects due to C++
      limitation in constructor overloading: if both tmp(T&) and tmp(const T&)
      constructors are provided resolution is ambiguous.
      
      The turbulence libraries have been upgraded and '-DCONST_TMP' option
      specified in the 'options' file to switch to the new 'tmp' behavior.
      c02bf70e
  23. 22 Feb, 2016 1 commit
    • Henry Weller's avatar
      tmp: Updated to store and preserve the const-ness of the reference to a constant object · 15b7e87d
      Henry Weller authored
      This change requires that the de-reference operator '()' returns a
      const-reference to the object stored irrespective of the const-ness of
      object stored and the new member function 'ref()' is provided to return
      an non-const reference to stored object which throws a fatal error if the
      stored object is const.
      
      In order to smooth the transition to this new safer 'tmp' the now
      deprecated and unsafe non-const de-reference operator '()' is still
      provided by default but may be switched-off with the compilation switch
      'CONST_TMP'.
      
      The main OpenFOAM library has already been upgraded and '-DCONST_TMP'
      option specified in the 'options' file to switch to the new 'tmp'
      behavior.  The rest of OpenFOAM-dev will be upgraded over the following
      few weeks.
      
      Henry G. Weller
      CFD Direct
      15b7e87d
  24. 20 Feb, 2016 1 commit
    • Henry Weller's avatar
      Boundary conditions: Added extrapolatedCalculatedFvPatchField · 99a10ece
      Henry Weller authored
      To be used instead of zeroGradientFvPatchField for temporary fields for
      which zero-gradient extrapolation is use to evaluate the boundary field
      but avoiding fields derived from temporary field using field algebra
      inheriting the zeroGradient boundary condition by the reuse of the
      temporary field storage.
      
      zeroGradientFvPatchField should not be used as the default patch field
      for any temporary fields and should be avoided for non-temporary fields
      except where it is clearly appropriate;
      extrapolatedCalculatedFvPatchField and calculatedFvPatchField are
      generally more suitable defaults depending on the manner in which the
      boundary values are specified or evaluated.
      
      The entire OpenFOAM-dev code-base has been updated following the above
      recommendations.
      
      Henry G. Weller
      CFD Direct
      99a10ece
  25. 12 Feb, 2016 1 commit
  26. 08 Nov, 2015 1 commit
  27. 21 May, 2013 1 commit
  28. 11 Oct, 2012 2 commits
  29. 14 Aug, 2011 1 commit
  30. 19 Jan, 2011 1 commit
  31. 14 Jan, 2011 1 commit
  32. 07 Jan, 2011 1 commit
  33. 05 Jan, 2011 2 commits