Commit Graph

45 Commits

Author SHA1 Message Date
Mark Olesen
732c8b3330 STYLE: more explicit method name PtrList::count() -> count_nonnull()
STYLE: use two-parameter shallowCopy
2024-02-13 12:30:13 +01:00
Mark Olesen
03ca52b036 ENH: PtrList, PtrDynList, HashPtrTable try_emplace() method
- naming like std::map::try_emplace(), it behaves like emplace_set()
  if there is no element at the given location otherwise a no-op

ENH: reuse existing HashPtrTable 'slot' when setting pointers

- avoids extra HashTable operations
2023-08-18 13:55:32 +02:00
Mark Olesen
63258d0b33 ENH: refine PtrList emplace method, add emplace for autoPtr/refPtr...
* resize_null() methods for PtrList variants
  - for cases where an existing PtrList needs a specific size and
    but not retain any existing entries.

    Eg,
        ptrs.resize_null(100);

    vs.   ptrs.free();     ptr.resize(100);
    or    ptr.resize(100); ptrs.free();

* remove stored pointer before emplacing PtrList elements
  - may reduce memory peaks

* STYLE: static_cast of (nullptr) instead of reinterpret_cast of (0)

* COMP: implement emplace_set() for PtrDynList
  - previously missing, which meant it would have leaked through to the
    underlying PtrList definition

* emplace methods for autoPtr, refPtr, tmp
  - applies reset() with forwarding arguments.
    For example,

        tmp<GeoField> tfld = ...;

    later...

        tfld.emplace(io, mesh);

    vs.
        tfld.reset(new GeoField(io, mesh));
    or
        tfld.reset(tmp<GeoField>::New(io, mesh));

    The emplace() obviously has reduced typing, but also allows the
    existing stored pointer to be deleted *before* creating its
    replacement (reduces memory peaks).
2023-07-27 16:52:03 +02:00
Mark Olesen
a581a8cb8d ENH: disallow implicit cast of autoPtr to non-const pointer
- permitting a cast to a non-const pointer adds uncertainty of
  ownership.

- adjust PtrDynList transfer. Remove the unused 'PtrDynList::remove()'
  method, which is better handled with pop().
2023-05-17 11:46:57 +02:00
Mark Olesen
9729617ae3 ENH: PtrList iterate over non-null entries (#2702)
- the iterator/const_iterator now skip any nullptr entries,
  which enables the following code to work even if the PtrList
  contains nullptr:

  for (const auto& intf : interfaces)
  {
      // Do something
      ...
  }

- this is a change in behaviour compared to OpenFOAM-v2212 and earlier,
  but is non-breaking:
  * Lists without null entries will traverse exactly as before.
  * Lists with null entries will now traverse correctly without
    provoking a FatalError.
2023-02-27 20:03:02 +01:00
Mark Olesen
afee861af9 DEFEATURE: remove PtrList random access iterators (#2702)
- random access was unused.
  Retaining it would impede reimplementing iterators to only iterate
  across non-null items.
2023-02-27 20:03:02 +01:00
Mark Olesen
1dbb54c391 ENH: refine definition of PtrList emplace() and HashPtrTable emplace_set()
- like emplace_back(), return a reference to the new element
2023-02-10 19:43:43 +01:00
Mark Olesen
7c60c80edd ENH: new/revised emplace_back() [for DynamicList/List/PtrDynList/PtrList]
- returns reference as per C++17 std::vector

STYLE: drop unused, redundant DynamicField remove() method
2023-01-27 09:50:45 +01:00
Mark Olesen
c7e6ae30bf ENH: add front(), back() methods to List containers
- traditionally used first(), last() methods,
  but front(), back() are well-known from std::vector etc
  which makes the access more familiar.

- support push_back() method for containers that already had append().
  This increases name familiar and can help when porting between
  different C++ code bases.

- support pop_back() method for List containers.
  This is similar to std::vector
2022-11-24 12:21:01 +00:00
Mark Olesen
f3ba6c6da0 ENH: linked-lists accept more familiar STL method names
- ie, front(), back(), push_front(), push_back(), pop_front()

ENH: add CircularBuffer flattening operator() and list() method

- useful if assigning content to a List etc

BUG: CircularBuffer find() did not return logical index
2022-11-24 12:21:01 +00:00
Mark Olesen
87f3866f20 ENH: support move append lists for PtrList and UPtrList 2022-05-17 17:35:51 +02:00
Mark Olesen
d68902f4a7 ENH: relocate Foam::sort from PtrListOps to UPtrList.H
- can sort directly without ListOps or other intermediates
  (eg labelList order).

- PtrListOps::less/greater wrappers -> UPtrList::less/greater
2022-05-10 10:04:27 +02:00
Mark Olesen
ab065cd5d3 BUG: avoid memory slicing in LList (#2300)
ENH: reduce code effort for clearing linked-lists

ENH: adjust linked-list method name

- complement linked-list append() method with prepend() method
  instead of 'insert', which is not very descriptive
2022-01-31 20:08:52 +01:00
Mark Olesen
872c9d370b ENH: support emplace methods and std::unique_ptr for PtrList-derivatives
- emplace methods
  Eg,
      m.internalCoeffs().emplace(patchi, fc.size(), Zero);
  vs.
      m.internalCoeffs().set(patchi, new Field<Type>(fc.size(), Zero));

- handle insert/append of refPtr wherever tmp was already supported

COMP: incorrect variable names in PtrListOpsTemplates.C
2020-07-28 08:40:43 +02:00
Andrew Heather
fdf8d10ab4 Merge commit 'e9219558d7' into develop-v1906 2019-12-05 11:47:19 +00:00
OpenFOAM bot
e9219558d7 GIT: Header file updates 2019-10-31 14:48:44 +00:00
Mark Olesen
3c07a1bb6f ENH: Foam::name() of memory address
- returns the memory address formatted in hexadecimal, which can be
  useful for detailed information
2019-08-12 10:46:29 +02:00
Mark Olesen
59da4cf56d STYLE: use uintptr_t cast instead of long when reporting addresses 2019-04-29 08:15:48 +02:00
Mark Olesen
9149b3579a ENH: PtrList and PtrListOps improvements
- PtrDynList support for move append list:
  can be used to concatenate pointer lists into a single one

- include resize in PtrDynList squeezeNull as being a natural
  combination

- support sorting operations for pointer lists (PtrListOps)
2019-03-13 10:53:28 +01:00
Mark Olesen
7795adfcb4 ENH: additional PtrList constructor and memory management method
- PtrList::release() method.

  Similar to autoPtr and unique_ptr and clearer in purpose than
  using set(i,nullptr)

- Construct from List of pointers, taking ownership.

  Useful when upgrading code. Eg,

     List<polyPatch*> oldList = ...;
     PtrList<polyPatch> newList(oldList);
     ...

BUG: incorrect resizing method names (PtrDynList) in previously unused code
2019-02-22 15:55:17 +01:00
OpenFOAM bot
154029ddd0 BOT: Cleaned up header files 2019-02-06 12:28:23 +00:00
Mark Olesen
73e89f9332 ENH: add UPtrList method to squeeze out (remove) null pointers
- moves any nullptr to the end of the list where they can be
  eliminated in a second step with resize()
2019-01-21 09:51:02 +01:00
Mark Olesen
1883a872a1 STYLE: adds comments in empty Make/options files
- easier when making modifications

STYLE: spelling in topoSetSource comments
2018-11-13 15:21:13 +01:00
Mark Olesen
2cd2732fed ENH: avoid change when setting UPtrList twice (issue #1035)
UPtrList::set(const label i, T* ptr);

No-op if the new pointer value is identical to the current content.
This avoid memory management issues.
2018-10-09 08:27:50 +02:00
Mark Olesen
5d008f7a18 ENH: improvements for PtrList, UPtrList and new PtrDynList container
- improve internal handling to permit deriving resizable containers
  (eg, PtrDynList).

- include '->' iterator dereferencing

- Only append/set non-const autoPtr references. This doesn't break
  existing code, but makes the intention more transparent.
2018-03-22 01:13:38 +01:00
Mark Olesen
3d608bf06a ENH: remove reliance on the Xfer class (issue #639)
This class is largely a pre-C++11 holdover. It is now possible to
simply use move construct/assignment directly.

In a few rare cases (eg, polyMesh::resetPrimitives) it has been
replaced by an autoPtr.
2018-03-05 13:28:53 +01:00
Mark Olesen
57291e8692 STYLE: use autoPtr::New and tmp::New for simple return types 2018-02-26 14:00:30 +01:00
Mark Olesen
2f32b586b5 ENH: PtrList, UPtrList cleanup
- rationalize iterators, reduce code duplication,
  improve assignment behaviour, moveable construct and assignment.
2018-01-09 13:15:50 +01:00
Mark Olesen
cc5f30f25e ENH: several improvements for linked-lists
- support move construct/assignment for linked-lists themselves
  and when moving into a 'normal' list

- better consistency with begin/end signatures and the various
  iterators.

- for indirect linked-lists, provide iterator access to the underlying
  data element address:   iter.get()  vs  &(iter())

- add standard '->' indirection for iterators (as per normal STL
  definitions)
2017-11-27 14:11:25 +01:00
laurence
259d030fed ENH: Update tests for PtrList and sort 2013-09-25 10:11:36 +01:00
Henry
c2dd153a14 Copyright transfered to the OpenFOAM Foundation 2011-08-14 12:17:30 +01:00
mattijs
7faf1a5205 COMP: app/test: make test apps compile 2011-03-23 16:18:06 +00:00
andy
eaef8d482b STYLE: Updated 1991 start copyright year to 2004 2011-01-14 16:08:00 +00:00
andy
099cc39e2e Revert "STYLE: 2011 copyright date."
This reverts commit b18f6cc1ce.
2011-01-05 18:24:29 +00:00
graham
b18f6cc1ce STYLE: 2011 copyright date. 2011-01-05 11:14:26 +00:00
Mark Olesen
499d48cfdb STYLE: uniform 'Test-' prefix for all applications/test
- easier to clean, avoid confusion with 'real' applications, etc.
2010-11-23 16:26:04 +01:00
graham
012494fdb5 STYLE: Fixing code style requirements for all apps.
Exception: applyWallFunctionBoundaryConditions.C cannot split #include
directives.
2010-07-27 15:27:05 +01:00
Mark Olesen
42807ddd7e STYLE: fix worst spacing violations for 'os <<' constructions
- accept some violations of the coding guidelines though
- perhaps adding a style exception would be simpler.
2010-04-13 17:45:49 +02:00
Mark Olesen
d29c438657 STYLE: use url for FSF license instead of postal address, switch to GPL v3 2010-03-29 14:07:56 +02:00
Mark Olesen
fa93ce8cd7 coding style adherence
- markup codingStyleGuide.org examples so they actually indent correctly

- use 'Info<<' as per codingStyleGuide instead of 'Info <<'
2009-11-27 15:39:14 +01:00
henry
35c9d7bbd5 Corrected test applications. 2009-11-20 12:40:19 +00:00
Mark Olesen
19503c93e1 rename xfer<T> class to Xfer<T>
- The capitalization is consistent with most other template classes, but
  more importantly frees up xfer() for use as method name without needing
  special treatment to avoid ambiguities.

  It seems reasonable to have different names for transfer(...) and xfer()
  methods, since the transfer is occuring in different directions.
  The xfer() method can thus replace the recently introduced zero-parameter
  transfer() methods.
  Other name candidates (eg, yield, release, etc.) were deemed too abstract.
2009-01-05 12:30:19 +01:00
Mark Olesen
cf488912bb added xfer<...> transfer() method to various containers
- this should provide a slightly more naturally means to using transfer
  constructors, for example
          labelList list2(list1.transfer());
      vs. labelList list2(xferMove(list1));

- returns a plain list where appropriate (eg, DynamicList, SortableList)
  for example
          labelList list2(dynList1.transfer());
      vs. labelList list2(xferMoveTo<labelList>(dynList1));
2009-01-02 15:54:51 +01:00
Mark Olesen
28b200bcd9 update copyrights for 2009 2008-12-31 19:01:56 +01:00
Mark Olesen
79e9a90c0e reworked functionObjectList to use PtrList
- This was originally plan 'B', but it is actually probably more efficient
  than using PtrDictionary anyhow.
- straightened out the return value logic, but it wasn't being used anywhere
  anyhow.
- new 'updated_' data member avoids inadvertent execution in the read()
  method when execution is turned off.
2008-12-19 09:29:58 +01:00