PtrListDetail.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2018-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::Detail::PtrListDetail
28 
29 Description
30  A rudimentary list of pointers used for PtrList, UPtrList, etc.
31  This class is considered implementation detail and should not normally
32  be used other than by OpenFOAM container classes.
33 
34  It stores a list of pointers, but makes leaves memory management
35  to the caller or sub-class.
36  The free() method can be used explicitly as required.
37 
38 SourceFiles
39  PtrListDetail.C
40  PtrListDetailI.H
41  PtrListDetailIO.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef PtrListDetail_H
46 #define PtrListDetail_H
47 
48 #include "List.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 namespace Detail
55 {
56 
57 /*---------------------------------------------------------------------------*\
58  Class Detail::PtrListDetail Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class T>
62 class PtrListDetail
63 :
64  public List<T*>
65 {
66 public:
67 
68  // Constructors
69 
70  //- Default construct
71  inline constexpr PtrListDetail() noexcept;
72 
73  //- Construct with specified size, each element initialized to nullptr
74  inline explicit PtrListDetail(const label len);
75 
76  //- Copy a list of pointers.
77  // The caller is responsible for memory management.
78  inline explicit PtrListDetail(const UList<T*>& list);
79 
80  //- Copy construct (shallow copies addresses)
81  inline PtrListDetail(const PtrListDetail<T>& list);
82 
83  //- Move construct
84  inline PtrListDetail(PtrListDetail<T>&& list);
85 
86  //- Copy or move (reuse) construct as specified
87  inline PtrListDetail(PtrListDetail<T>& list, bool reuse);
88 
89 
90  // Member Functions
91 
92  //- Return the count of non-nullptr entries
93  label count() const;
94 
95  //- Locate the first null entry, -1 if there are not any
96  label findNull() const;
97 
98  //- Assign all pointers to nullptr, without deleting.
99  void setNull();
100 
101  //- Delete the allocated entries, but retain the list size.
102  void free();
103 
104  //- Make a copy by cloning each of the list pointers.
105  template<class... Args>
106  PtrListDetail<T> clone(Args&&... args) const;
107 
108  //- Reset size of list.
109  // New entries are initialized to nullptr.
110  inline void resize(const label newLen);
111 
112  //- Set addressed size to be inconsistent with allocated storage.
113  // Use with care
114  inline void setAddressableSize(const label n) noexcept;
115 
116  //- Write output, optionally silently trimming nullptrs
117  Ostream& write(Ostream& os, const bool trimNull=false) const;
118 
119 
120  // Member Operators
121 
122  //- Copy assignment (shallow copies addresses)
123  inline void operator=(const PtrListDetail<T>& list);
124 
125  //- Move assignment
126  inline void operator=(PtrListDetail<T>&& list);
127 
128 
129  // Housekeeping
130 
131  // Just use resize().
132  void setSize(const label) = delete;
133  void setSize(const label, const T&) = delete;
134  void setSize(const label, const T*) = delete;
135 
136  // Too fragile or dangerous
137  void resize_nocopy(const label) = delete;
138 };
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 } // End namespace Detail
143 } // End namespace Foam
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 #include "PtrListDetailI.H"
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #ifdef NoRepository
152  #include "PtrListDetail.C"
153  #include "PtrListDetailIO.C"
154 #endif
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 
159 #endif
160 
161 // ************************************************************************* //
Foam::Detail::PtrListDetail::findNull
label findNull() const
Locate the first null entry, -1 if there are not any.
Definition: PtrListDetail.C:51
Foam::Detail::PtrListDetail::count
label count() const
Return the count of non-nullptr entries.
Definition: PtrListDetail.C:34
List.H
Foam::Detail::PtrListDetail::PtrListDetail
constexpr PtrListDetail() noexcept
Default construct.
Definition: PtrListDetailI.H:31
Foam::Detail::PtrListDetail::setNull
void setNull()
Assign all pointers to nullptr, without deleting.
Definition: PtrListDetail.C:70
PtrListDetail.C
PtrListDetailI.H
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::Detail::PtrListDetail::setAddressableSize
void setAddressableSize(const label n) noexcept
Set addressed size to be inconsistent with allocated storage.
Definition: PtrListDetailI.H:89
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::Detail::PtrListDetail::free
void free()
Delete the allocated entries, but retain the list size.
Definition: PtrListDetail.C:83
PtrListDetailIO.C
Foam::Detail::PtrListDetail::operator=
void operator=(const PtrListDetail< T > &list)
Copy assignment (shallow copies addresses)
Definition: PtrListDetailI.H:116
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Detail::PtrListDetail::write
Ostream & write(Ostream &os, const bool trimNull=false) const
Write output, optionally silently trimming nullptrs.
Definition: PtrListDetailIO.C:36
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::Detail::PtrListDetail::resize
void resize(const label newLen)
Reset size of list.
Definition: PtrListDetailI.H:98
Foam::Detail::PtrListDetail
A rudimentary list of pointers used for PtrList, UPtrList, etc. This class is considered implementati...
Definition: PtrListDetail.H:61
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::List< T * >::clone
autoPtr< List< T * > > clone() const
Clone.
Definition: ListI.H:100
args
Foam::argList args(argc, argv)
Foam::Detail::PtrListDetail::setSize
void setSize(const label)=delete
Foam::Detail::PtrListDetail::resize_nocopy
void resize_nocopy(const label)=delete