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-2019 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 SourceFiles
35  PtrListDetailI.H
36  PtrListDetail.C
37  PtrListDetailIO.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef PtrListDetail_H
42 #define PtrListDetail_H
43 
44 #include "List.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward declarations
52 class Ostream;
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  //- Construct null
71  inline constexpr PtrListDetail() noexcept;
72 
73  //- Construct with specified size, each element initialized to nullptr
74  inline PtrListDetail(const label len);
75 
76  //- Copy construct (shallow copies addresses)
77  inline PtrListDetail(const PtrListDetail<T>& list);
78 
79  //- Move construct
80  inline PtrListDetail(PtrListDetail<T>&& list);
81 
82  //- Copy or move (reuse) construct as specified
83  inline PtrListDetail(PtrListDetail<T>& list, bool reuse);
84 
85 
86  // Member Functions
87 
88  //- Return the count of non-nullptr entries
89  label count() const;
90 
91  //- Locate the first null entry, -1 if there are not any
92  label findNull() const;
93 
94  //- Delete the allocated entries, but retain the list size.
95  void free();
96 
97  //- Make a copy by cloning each of the list pointers.
98  template<class... Args>
99  PtrListDetail<T> clone(Args&&... args) const;
100 
101  //- Reset size of list.
102  // New entries are initialized to nullptr.
103  inline void resize(const label newLen);
104 
105  //- Override size to be inconsistent with allocated storage.
106  // Use with care
107  inline void setAddressableSize(const label n);
108 
109  //- Write output, optionally silently trimming nullptrs
110  Ostream& write(Ostream& os, const bool trimNull=false) const;
111 
112 
113  // Member Operators
114 
115  //- Copy assignment (shallow copies addresses)
116  inline void operator=(const PtrListDetail<T>& list);
117 
118  //- Move assignment
119  inline void operator=(PtrListDetail<T>&& list);
120 
121 
122  // Housekeeping
123 
124  // Just use resize().
125  void setSize(const label) = delete;
126  void setSize(const label, const T&) = delete;
127  void setSize(const label, const T*) = delete;
128 
129 };
130 
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 
133 } // End namespace Detail
134 } // End namespace Foam
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 #include "PtrListDetailI.H"
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 #ifdef NoRepository
143  #include "PtrListDetail.C"
144  #include "PtrListDetailIO.C"
145 #endif
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 
150 #endif
151 
152 // ************************************************************************* //
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
Construct null.
Definition: PtrListDetailI.H:31
Foam::Detail::PtrListDetail::setAddressableSize
void setAddressableSize(const label n)
Override size to be inconsistent with allocated storage.
Definition: PtrListDetailI.H:78
PtrListDetail.C
PtrListDetailI.H
n
label n
Definition: TABSMDCalcMethod2.H:31
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:70
PtrListDetailIO.C
Foam::Detail::PtrListDetail::operator=
void operator=(const PtrListDetail< T > &list)
Copy assignment (shallow copies addresses)
Definition: PtrListDetailI.H:103
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: HashTable.H:102
Foam::Detail::PtrListDetail::resize
void resize(const label newLen)
Reset size of list.
Definition: PtrListDetailI.H:85
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:99
args
Foam::argList args(argc, argv)
Foam::Detail::PtrListDetail::setSize
void setSize(const label)=delete