ENH: add get() retrieval of a pointer from PtrLists, HashPtrTable
- naming similarity with autoPtr, unique_ptr and other containers. For UPtrList derivatives, this is equivalent to the existing operator(). The read-only variant is also equivalent to the single-parameter 'set(label)' method. With PtrList<T> list(...) : const T* ptr = list.get(10); if (ptr) { ptr->method(); } vs. if (list.set(10)) { list[10].method(); } For HashPtrTable there is only a read-only variant which is equivalent to testing for existence and for value. With HashPtrTable<T> hash(...) : const T* ptr = list.get("key"); if (ptr) { ptr->method(); } vs. if (list.found("key")) { // Fails on null pointer!! list["key"].method(); } Use of get() is largely a matter of taste or local coding requirements
Showing
- applications/test/HashPtrTable/Test-HashPtrTable.C 18 additions, 0 deletionsapplications/test/HashPtrTable/Test-HashPtrTable.C
- src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H 7 additions, 0 deletions...penFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H
- src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableI.H 12 additions, 0 deletions...enFOAM/containers/HashTables/HashPtrTable/HashPtrTableI.H
- src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H 5 additions, 1 deletionsrc/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H
- src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H 1 addition, 1 deletionsrc/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H
- src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H 2 additions, 2 deletionssrc/OpenFOAM/containers/PtrLists/PtrList/PtrList.H
- src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H 10 additions, 2 deletionssrc/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H
- src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H 14 additions, 0 deletionssrc/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H
Please register or sign in to comment