ENH: add tmp/refPtr support for setting cref/ref from pointer

- makes it easier to use for local or alternative storage.
  Eg,

  ```
      tmp<volScalarField> tfld;

      tfld.cref(obj.cfindObject<volScalarField>("name"));

      if (!tfld)
      {
          tfld = volScalarField::New("name", ...);
      }
  ```
This commit is contained in:
Mark Olesen
2021-06-08 13:51:49 +02:00
parent e2c8b0b13f
commit 6120e13d29
6 changed files with 71 additions and 7 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -224,12 +224,20 @@ public:
//- Clear existing and transfer ownership.
inline void reset(tmp<T>&& other) noexcept;
//- Delete managed temporary object and set to (const) reference
//- Clear existing and set (const) reference
inline void cref(const T& obj) noexcept;
//- Delete managed temporary object and set to (non-const) reference
//- Clear existing and set (const) reference to pointer content.
// A null pointer is permitted (treated as a managed pointer).
inline void cref(const T* p) noexcept;
//- Clear existing and set to (non-const) reference
inline void ref(T& obj) noexcept;
//- Clear existing and set (non-const) reference to pointer content.
// A null pointer is permitted (treated as a managed pointer).
inline void ref(T* p) noexcept;
//- Swaps the managed object with other.
inline void swap(tmp<T>& other) noexcept;