mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-12-28 03:37:59 +00:00
Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop
This commit is contained in:
@ -47,8 +47,8 @@ int main(int argc, char *argv[])
|
||||
Info<< "cll1:" << cll1 << endl;
|
||||
|
||||
// Resize and assign row by row
|
||||
labelList row0(2, 0);
|
||||
labelList row1(3, 1);
|
||||
labelList row0(2, label(0));
|
||||
labelList row1(3, label(1));
|
||||
|
||||
labelList rowSizes(2);
|
||||
rowSizes[0] = row0.size();
|
||||
@ -140,8 +140,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
{
|
||||
faceList fcs(2);
|
||||
fcs[0] = face(labelList(1, 111));
|
||||
fcs[1] = face(labelList(2, 222));
|
||||
fcs[0] = face(labelList(1, label(111)));
|
||||
fcs[1] = face(labelList(2, label(222)));
|
||||
|
||||
CompactListList<label, face> compactFcs(fcs);
|
||||
Info<< "comactFcs:" << compactFcs << endl;
|
||||
|
||||
@ -28,20 +28,39 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
|
||||
#include "IOstreams.H"
|
||||
#include "DLList.H"
|
||||
#include "List.H"
|
||||
#include "FlatOutput.H"
|
||||
#include "ListOps.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class T>
|
||||
void printAddress(const UList<T>& list)
|
||||
{
|
||||
Info<< "list addr: " << long(&list)
|
||||
<< " data addr: " << long(list.cdata()) << nl;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void printAddresses(const DLList<List<T>>& sll)
|
||||
{
|
||||
for (const auto& elem : sll)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
DLList<scalar> myList;
|
||||
|
||||
Info<< "DLList<scalar>" << nl;
|
||||
DLList<scalar> myList{2.1, 3.4};
|
||||
myList = {2.1, 3.4, 4.3};
|
||||
|
||||
for (int i = 0; i<10; i++)
|
||||
{
|
||||
@ -51,58 +70,165 @@ int main(int argc, char *argv[])
|
||||
myList.append(100.3);
|
||||
myList.append(500.3);
|
||||
|
||||
forAllConstIters(myList, iter)
|
||||
Info<< "DLList<scalar>" << nl;
|
||||
Info<< nl << "flat-output: " << flatOutput(myList) << nl;
|
||||
|
||||
Info<< nl << "range-for:" << nl;
|
||||
for (const auto& val : myList)
|
||||
{
|
||||
Info<< "element:" << *iter << endl;
|
||||
Info<< " " << val << nl;
|
||||
}
|
||||
|
||||
Info<< nl << "And again using the same STL iterator: " << nl << endl;
|
||||
Info<< nl << "const_iterator:" << nl;
|
||||
|
||||
forAllConstIters(myList, iter)
|
||||
{
|
||||
Info<< " " << *iter << endl;
|
||||
}
|
||||
|
||||
// Test bi-directional movement
|
||||
{
|
||||
const label n2 = myList.size()/2;
|
||||
|
||||
Info<< nl << "test movement through " << flatOutput(myList) << nl;
|
||||
|
||||
DLList<scalar>::const_iterator citer = myList.begin();
|
||||
|
||||
for (label i=0; i<n2; ++i)
|
||||
{
|
||||
Info<< " forward " << i << " " << *citer << nl;
|
||||
++citer;
|
||||
}
|
||||
|
||||
for (label i=0; i<n2; ++i)
|
||||
{
|
||||
Info<< " backward " << i << " " << *citer << nl;
|
||||
--citer;
|
||||
}
|
||||
|
||||
// Verify - does not compile since it uses a delete method (good!)
|
||||
DLList<scalar>::iterator iter = myList.begin();
|
||||
++iter;
|
||||
++iter;
|
||||
++iter;
|
||||
|
||||
Info<<" now with " << *iter << nl;
|
||||
myList.remove(iter);
|
||||
Info<<" after remove " << *iter << nl;
|
||||
++iter;
|
||||
Info<<" after incr " << *iter << nl;
|
||||
--iter;
|
||||
--iter;
|
||||
|
||||
Info<<" after 2x decr " << *iter << nl;
|
||||
}
|
||||
|
||||
Info<< nl << "const_reverse_iterator:" << nl;
|
||||
|
||||
forAllConstReverseIters(myList, iter)
|
||||
{
|
||||
Info<< " " << *iter << endl;
|
||||
}
|
||||
|
||||
|
||||
Info<< nl << "Remove elements:" << nl;
|
||||
|
||||
forAllIters(myList, iter)
|
||||
{
|
||||
Info<< "Removing " << myList.remove(iter) << endl;
|
||||
Info<< " remove " << *iter;
|
||||
myList.remove(iter);
|
||||
|
||||
Info<< " => " << flatOutput(myList) << nl;
|
||||
}
|
||||
|
||||
myList.append(500.3);
|
||||
myList.append(200.3);
|
||||
myList.append(100.3);
|
||||
|
||||
Info<< nl << "Using range-based for: " << nl << endl;
|
||||
for (auto val : myList)
|
||||
Info<< nl << "Testing swapUp and swapDown:" << nl;
|
||||
Info<< " => " << flatOutput(myList) << nl;
|
||||
|
||||
{
|
||||
Info<< "element:" << val << endl;
|
||||
myList.swapUp(myList.DLListBase::first());
|
||||
myList.swapUp(myList.DLListBase::last());
|
||||
|
||||
Info<< nl << "swapUp => " << flatOutput(myList) << nl;
|
||||
}
|
||||
|
||||
Info<< nl << "Testing swapUp and swapDown: " << endl;
|
||||
|
||||
Info<< nl << "swapUp" << endl;
|
||||
|
||||
myList.swapUp(myList.DLListBase::first());
|
||||
myList.swapUp(myList.DLListBase::last());
|
||||
|
||||
for (auto val : myList)
|
||||
{
|
||||
Info<< "element:" << val << endl;
|
||||
myList.swapDown(myList.DLListBase::first());
|
||||
myList.swapDown(myList.DLListBase::last());
|
||||
|
||||
Info<< nl << "swapDown => " << flatOutput(myList) << nl;
|
||||
}
|
||||
|
||||
Info<< nl << "swapDown" << endl;
|
||||
|
||||
myList.swapDown(myList.DLListBase::first());
|
||||
myList.swapDown(myList.DLListBase::last());
|
||||
|
||||
for (auto val : myList)
|
||||
{
|
||||
Info<< "element:" << val << endl;
|
||||
}
|
||||
|
||||
Info<< nl << "Testing transfer: " << nl << nl
|
||||
<< "original: " << myList << endl;
|
||||
Info<< nl << "Transfer: " << nl;
|
||||
Info<< "original: " << flatOutput(myList) << endl;
|
||||
|
||||
DLList<scalar> newList;
|
||||
newList.transfer(myList);
|
||||
|
||||
Info<< nl << "source: " << myList << nl
|
||||
<< nl << "target: " << newList << endl;
|
||||
Info<< nl
|
||||
<< "source: " << flatOutput(myList) << nl
|
||||
<< "target: " << flatOutput(newList) << nl;
|
||||
|
||||
|
||||
Info<< nl << "Move Construct: " << nl;
|
||||
|
||||
DLList<scalar> list2(std::move(newList));
|
||||
|
||||
Info<< nl
|
||||
<< "in : " << flatOutput(newList) << nl
|
||||
<< "out: " << flatOutput(list2) << nl;
|
||||
|
||||
// Move back
|
||||
Info<< nl << "Move Assignment: " << nl;
|
||||
|
||||
newList = std::move(list2);
|
||||
|
||||
Info<< nl
|
||||
<< "in : " << flatOutput(newList) << nl
|
||||
<< "out: " << flatOutput(list2) << nl;
|
||||
|
||||
// Try delete data recovery
|
||||
{
|
||||
DLList<List<label>> labList;
|
||||
|
||||
for (int i = 0; i<5; i++)
|
||||
{
|
||||
labList.append(identity(6));
|
||||
}
|
||||
|
||||
Info<< nl
|
||||
<< "DLList<labelList> : " << labList << nl;
|
||||
|
||||
printAddresses(labList);
|
||||
|
||||
auto elem = labList.removeHead();
|
||||
|
||||
Info<< " removed head" << nl;
|
||||
printAddress(elem);
|
||||
|
||||
elem = labList.removeHead();
|
||||
|
||||
Info<< " removed head" << nl;
|
||||
printAddress(elem);
|
||||
|
||||
List<label> content1 = identity(10);
|
||||
|
||||
Info<< nl
|
||||
<< " move append ";
|
||||
printAddress(content1);
|
||||
|
||||
labList.append(std::move(content1));
|
||||
|
||||
Info<< " content " << flatOutput(content1) << nl
|
||||
<< " list" << labList << nl;
|
||||
|
||||
printAddresses(labList);
|
||||
// labList.append(content1);
|
||||
}
|
||||
|
||||
Info<< nl << "Done." << endl;
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ Application
|
||||
Test-FixedList
|
||||
|
||||
Description
|
||||
Simple tests and examples of use of FixedList
|
||||
Simple tests and examples for FixedList
|
||||
|
||||
See also
|
||||
Foam::FixedList
|
||||
@ -42,47 +42,72 @@ See also
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class T, unsigned Size>
|
||||
Ostream& printInfo(const FixedList<List<T>, Size>& list)
|
||||
{
|
||||
Info<< list << " addresses:";
|
||||
for (unsigned i = 0; i < Size; ++i)
|
||||
{
|
||||
Info<< " " << long(list[i].cdata());
|
||||
}
|
||||
Info<< nl;
|
||||
return Info;
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
Ostream& printInfo
|
||||
(
|
||||
const FixedList<List<T>, Size>& list1,
|
||||
const FixedList<List<T>, Size>& list2
|
||||
)
|
||||
{
|
||||
Info<< "llist1:"; printInfo(list1);
|
||||
Info<< "llist2:"; printInfo(list2);
|
||||
return Info;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList args(argc, argv);
|
||||
argList::addBoolOption("assign");
|
||||
argList::addBoolOption("iter");
|
||||
argList::addBoolOption("swap");
|
||||
argList::addBoolOption("default", "reinstate default tests");
|
||||
argList::addNote("runs default tests or specified ones only");
|
||||
|
||||
if (false)
|
||||
#include "setRootCase.H"
|
||||
|
||||
// Run default tests, unless only specific tests are requested
|
||||
const bool defaultTests =
|
||||
args.found("default") || args.options().empty();
|
||||
|
||||
|
||||
if (defaultTests || args.found("iter"))
|
||||
{
|
||||
FixedList<string, 1> ident;
|
||||
Info<< nl
|
||||
<< "Test iterators" << nl;
|
||||
|
||||
auto iter = ident.begin();
|
||||
|
||||
Info << iter->size() << endl;
|
||||
|
||||
auto riter = ident.rbegin();
|
||||
Info << riter->size() << endl;
|
||||
|
||||
auto iter2 = ident.rbegin();
|
||||
|
||||
iter2 = iter;
|
||||
}
|
||||
|
||||
{
|
||||
FixedList<label, 15> ident;
|
||||
std::iota(ident.begin(), ident.end(), 0);
|
||||
|
||||
// auto iter = ident.begin();
|
||||
//
|
||||
// iter += 5;
|
||||
// Info << *iter << "< " << endl;
|
||||
// Info << *iter << "< " << nl;
|
||||
// iter -= 2;
|
||||
// Info << *iter << "< " << endl;
|
||||
// Info << *iter << "< " << nl;
|
||||
|
||||
// Don't yet bother with making reverse iterators random access
|
||||
// auto riter = ident.crbegin();
|
||||
|
||||
// riter += 5;
|
||||
// Info << *riter << "< " << endl;
|
||||
// Info << *riter << "< " << nl;
|
||||
// riter += 2;
|
||||
// Info << *riter << "< " << endl;
|
||||
// Info << *riter << "< " << nl;
|
||||
|
||||
Info<<"Ident:";
|
||||
forAllConstIters(ident, iter)
|
||||
@ -106,65 +131,121 @@ int main(int argc, char *argv[])
|
||||
Info<< nl;
|
||||
}
|
||||
|
||||
if (defaultTests || args.found("swap"))
|
||||
{
|
||||
FixedList<label, 4> list1{1, 2, 3, 4};
|
||||
Info<< nl
|
||||
<< "Test swap" << nl;
|
||||
|
||||
FixedList<label, 4> list1{2, 3, 4, 5};
|
||||
|
||||
Info<< "list1:" << list1
|
||||
<< " hash:" << FixedList<label, 4>::Hash<>()(list1) << endl;
|
||||
<< " hash:" << FixedList<label, 4>::Hash<>()(list1) << nl;
|
||||
|
||||
label a[4] = {0, 1, 2, 3};
|
||||
FixedList<label, 4> list2(a);
|
||||
|
||||
Info<< "list2:" << list2
|
||||
<< " hash:" << FixedList<label, 4>::Hash<>()(list2) << endl;
|
||||
<< " hash:" << FixedList<label, 4>::Hash<>()(list2) << nl;
|
||||
|
||||
// Using FixedList for content too
|
||||
{
|
||||
List<FixedList<label, 4>> twolists{list1, list2};
|
||||
Info<<"List of FixedList: " << flatOutput(twolists) << endl;
|
||||
Info<<"List of FixedList: " << flatOutput(twolists) << nl;
|
||||
sort(twolists);
|
||||
// outer-sort only
|
||||
Info<<"sorted FixedList : " << flatOutput(twolists) << endl;
|
||||
Info<<"sorted FixedList : " << flatOutput(twolists) << nl;
|
||||
}
|
||||
|
||||
Info<< "====" << nl
|
||||
<< "Test swap" << nl;
|
||||
|
||||
Info<< "list1: " << list1 << nl
|
||||
<< "list2: " << list2 << endl;
|
||||
<< "list2: " << list2 << nl;
|
||||
|
||||
// Addresses don't change with swap
|
||||
Info<< "mem: " << long(list1.data()) << " " << long(list2.data()) << nl;
|
||||
|
||||
list1.swap(list2);
|
||||
Info<< "The swap() method" << endl;
|
||||
Info<< "The swap() method" << nl;
|
||||
Info<< "list1: " << list1 << nl
|
||||
<< "list2: " << list2 << endl;
|
||||
<< "list2: " << list2 << nl;
|
||||
|
||||
Info<< "mem: " << long(list1.data()) << " " << long(list2.data()) << nl;
|
||||
|
||||
Swap(list1, list2);
|
||||
Info<< "The Swap() function" << endl;
|
||||
Info<< "The Swap() function" << nl;
|
||||
Info<< "list1: " << list1 << nl
|
||||
<< "list2: " << list2 << endl;
|
||||
<< "list2: " << list2 << nl;
|
||||
|
||||
Info<< "mem: " << long(list1.data()) << " " << long(list2.data()) << nl;
|
||||
|
||||
Info<< "====" << nl;
|
||||
|
||||
|
||||
Info<< nl
|
||||
<< "Test of swap with other container content" << nl;
|
||||
|
||||
FixedList<labelList, 4> llist1;
|
||||
FixedList<labelList, 4> llist2;
|
||||
|
||||
{
|
||||
label i = 1;
|
||||
for (auto& item : llist1)
|
||||
{
|
||||
item = identity(1 + 1.5*i);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
Info<< nl
|
||||
<< "initial lists" << nl;
|
||||
printInfo(llist1, llist2);
|
||||
|
||||
llist2.transfer(llist1);
|
||||
Info<< nl
|
||||
<< "After transfer" << nl;
|
||||
printInfo(llist1, llist2);
|
||||
|
||||
llist2.swap(llist1);
|
||||
Info<< nl
|
||||
<< "After swap" << nl;
|
||||
printInfo(llist1, llist2);
|
||||
|
||||
llist2 = llist1;
|
||||
Info<< nl
|
||||
<< "After copy assignment" << nl;
|
||||
printInfo(llist1, llist2);
|
||||
|
||||
llist2 = std::move(llist1);
|
||||
Info<< nl
|
||||
<< "After move assignment" << nl;
|
||||
printInfo(llist1, llist2);
|
||||
}
|
||||
|
||||
Info<< nl
|
||||
<< "Test construct and assignment" << nl;
|
||||
|
||||
|
||||
List<label> list3{0, 1, 2, 3};
|
||||
FixedList<label, 4> list4(list3.begin(), list3.end());
|
||||
Info<< "list3: " << list3 << nl
|
||||
<< "list4: " << list4 << endl;
|
||||
<< "list4: " << list4 << nl;
|
||||
|
||||
list4 = {1, 2, 3, 5};
|
||||
Info<< "list4: " << list4 << nl;
|
||||
|
||||
FixedList<label, 5> list5{0, 1, 2, 3, 4};
|
||||
Info<< "list5: " << list5 << endl;
|
||||
Info<< "list5: " << list5 << nl;
|
||||
|
||||
List<FixedList<label, 2>> list6{{0, 1}, {2, 3}};
|
||||
Info<< "list6: " << list6 << endl;
|
||||
Info<< "list6: " << list6 << nl;
|
||||
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
if (Pstream::myProcNo() != Pstream::masterNo())
|
||||
{
|
||||
Serr<< "slave sending to master "
|
||||
<< Pstream::masterNo() << endl;
|
||||
<< Pstream::masterNo() << nl;
|
||||
|
||||
OPstream toMaster
|
||||
(
|
||||
|
||||
@ -98,11 +98,12 @@ int main()
|
||||
}
|
||||
|
||||
|
||||
HashTable<scalar> table2(table1);
|
||||
HashTable<scalar> table3(std::move(table1));
|
||||
HashTable<scalar> table2(table1); // Copy
|
||||
HashTable<scalar> table3(std::move(table1)); // Move
|
||||
|
||||
Info<< "\ncopy table1 -> table2" << nl
|
||||
<< "transfer table1 -> table3 via the xfer() method" << nl;
|
||||
Info<< nl
|
||||
<< "copy table1 -> table2" << nl
|
||||
<< "move table1 -> table3" << nl;
|
||||
|
||||
Info<< "\ntable1" << table1 << nl
|
||||
<< "\ntable2" << table2 << nl
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,9 +28,12 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
|
||||
#include "IOstreams.H"
|
||||
#include "ISLList.H"
|
||||
#include "List.H"
|
||||
#include "FlatOutput.H"
|
||||
#include "ListOps.H"
|
||||
#include "OSspecific.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -66,7 +69,7 @@ public:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ISLList<Scalar> myList;
|
||||
ISLList<Scalar> myList(new Scalar(0));
|
||||
|
||||
for (int i = 0; i<10; i++)
|
||||
{
|
||||
@ -76,31 +79,74 @@ int main(int argc, char *argv[])
|
||||
myList.append(new Scalar(100.3));
|
||||
myList.append(new Scalar(500.3));
|
||||
|
||||
Info<< nl << "And again using STL iterator: " << nl << endl;
|
||||
Info<< "ISLList<scalar>" << myList << nl;
|
||||
Info<< nl << "flat-output: " << flatOutput(myList) << nl;
|
||||
|
||||
forAllIters(myList, iter)
|
||||
Info<< nl << "range-for:" << nl;
|
||||
for (const auto& val : myList)
|
||||
{
|
||||
Info<< "element:" << *iter << endl;
|
||||
Info<< " " << val << nl;
|
||||
// Info<<" is " << typeid(val).name() << endl;
|
||||
}
|
||||
|
||||
Info<< nl << "And again using STL const_iterator: " << nl << endl;
|
||||
Info<< nl << "const_iterator:" << nl;
|
||||
|
||||
const ISLList<Scalar>& const_myList = myList;
|
||||
|
||||
forAllConstIters(const_myList, iter)
|
||||
{
|
||||
Info<< "element:" << *iter << endl;
|
||||
Info<< " " << *iter << endl;
|
||||
}
|
||||
|
||||
{
|
||||
Info<< nl << "Remove element:" << nl;
|
||||
|
||||
Scalar *iter = myList.removeHead();
|
||||
|
||||
Info<< " remove " << *iter;
|
||||
Info<< " => " << flatOutput(myList) << nl;
|
||||
|
||||
delete iter;
|
||||
}
|
||||
|
||||
|
||||
Info<< nl << "Testing transfer: " << nl << endl;
|
||||
Info<< "original: " << myList << endl;
|
||||
Info<< nl << "Transfer: " << nl;
|
||||
Info<< "original: " << flatOutput(myList) << endl;
|
||||
|
||||
ISLList<Scalar> newList;
|
||||
newList.transfer(myList);
|
||||
|
||||
Info<< nl << "source: " << myList << nl
|
||||
<< nl << "target: " << newList << endl;
|
||||
Info<< nl
|
||||
<< "source: " << flatOutput(myList) << nl
|
||||
<< "target: " << flatOutput(newList) << endl;
|
||||
|
||||
myList.swap(newList);
|
||||
|
||||
Info<< nl << "swap: " << nl;
|
||||
Info<< nl
|
||||
<< "source: " << flatOutput(myList) << nl
|
||||
<< "target: " << flatOutput(newList) << endl;
|
||||
|
||||
myList.swap(newList);
|
||||
|
||||
Info<< nl << "Move Construct: " << nl;
|
||||
|
||||
ISLList<Scalar> list2(std::move(newList));
|
||||
|
||||
Info<< nl
|
||||
<< "in : " << flatOutput(newList) << nl
|
||||
<< "out: " << flatOutput(list2) << nl;
|
||||
|
||||
// Move back
|
||||
Info<< nl << "Move Assignment: " << nl;
|
||||
|
||||
newList = std::move(list2);
|
||||
|
||||
Info<< nl << "move assign: " << nl;
|
||||
Info<< nl
|
||||
<< "source: " << flatOutput(list2) << nl
|
||||
<< "target: " << flatOutput(newList) << endl;
|
||||
|
||||
|
||||
Info<< nl << "Bye." << endl;
|
||||
return 0;
|
||||
|
||||
3
applications/test/List3/Make/files
Normal file
3
applications/test/List3/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-List3.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-List3
|
||||
155
applications/test/List3/Test-List3.C
Normal file
155
applications/test/List3/Test-List3.C
Normal file
@ -0,0 +1,155 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-List3
|
||||
|
||||
Description
|
||||
Test list construction
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "FixedList.H"
|
||||
#include "labelList.H"
|
||||
#include "vectorList.H"
|
||||
#include "ListOps.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "cpuTime.H"
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class T>
|
||||
void printAddress(const UList<T>& list)
|
||||
{
|
||||
Info<< "list addr: " << long(&list)
|
||||
<< " data addr: " << long(list.cdata()) << nl;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void printAddress(const SLList<T>& list)
|
||||
{
|
||||
Info<< "list addr: " << long(&list)
|
||||
<< " data addr: ???" << nl;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void printAddresses(const List<List<T>>& list)
|
||||
{
|
||||
for (const auto& elem : list)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void printAddresses(const SLList<List<T>>& list)
|
||||
{
|
||||
for (const auto& elem : list)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::addBoolOption("labelListList");
|
||||
|
||||
argList args(argc, argv, false);
|
||||
|
||||
if (args.options().empty())
|
||||
{
|
||||
Info<< nl << "Specify an option! " << nl << endl;
|
||||
}
|
||||
|
||||
if (args.optionFound("labelListList"))
|
||||
{
|
||||
for (label argi=1; argi < args.size(); ++argi)
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
IFstream is(args[argi]);
|
||||
|
||||
Info<< nl << nl
|
||||
<< "read from " << is.name() << nl << endl;
|
||||
|
||||
SLList<List<label>> sll(is);
|
||||
Info<< "read " << sll.size() << " entries" << nl;
|
||||
|
||||
Info<< "sll" << nl;
|
||||
for (const auto& elem : sll)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
|
||||
|
||||
// List<List<label>> list(std::move(sll));
|
||||
List<List<label>> list;
|
||||
Info<< "move to List" << nl;
|
||||
list = std::move(sll);
|
||||
|
||||
Info<< "sll" << nl;
|
||||
for (const auto& elem : sll)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
Info<< "list" << nl;
|
||||
printAddresses(list);
|
||||
}
|
||||
|
||||
if (true)
|
||||
{
|
||||
IFstream is(args[argi]);
|
||||
|
||||
Info<< nl << nl
|
||||
<< "read from " << is.name() << nl << endl;
|
||||
|
||||
List<List<label>> list(is);
|
||||
|
||||
Info<< "list" << nl;
|
||||
for (const auto& elem : list)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Info<< nl << "Done" << nl << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
8
applications/test/List3/list1
Normal file
8
applications/test/List3/list1
Normal file
@ -0,0 +1,8 @@
|
||||
// List of labelList
|
||||
|
||||
(
|
||||
(1 2 3 4)
|
||||
(5 6 7 8)
|
||||
(15 16 17 18)
|
||||
)
|
||||
|
||||
@ -144,18 +144,18 @@ int main(int argc, char *argv[])
|
||||
Info<< "\ntest Istream constructor\n";
|
||||
|
||||
list4.printInfo(Info, true);
|
||||
Info<< list4 << " indices: " << list4.used()() << nl;
|
||||
Info<< list4 << " indices: " << list4.used() << nl;
|
||||
|
||||
Info<< "\nassign from labelList\n";
|
||||
list4 = labelList{0, 1, 2, 3, 12, 13, 14, 19, 20, 21};
|
||||
|
||||
list4.printInfo(Info, true);
|
||||
Info<< list4 << " indices: " << list4.used()() << nl;
|
||||
Info<< list4 << " indices: " << list4.used() << nl;
|
||||
|
||||
// Not yet:
|
||||
// PackedBoolList list5{0, 1, 2, 3, 12, 13, 14, 19, 20, 21};
|
||||
// list5.printInfo(Info, true);
|
||||
// Info<< list5 << " indices: " << list5.used()() << nl;
|
||||
// Info<< list5 << " indices: " << list5.used() << nl;
|
||||
|
||||
Info<< "\nassign from indices\n";
|
||||
list4.read
|
||||
@ -168,7 +168,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
list4.printInfo(Info, true);
|
||||
Info<< list4 << " indices: " << list4.used()() << nl;
|
||||
Info<< list4 << " indices: " << list4.used() << nl;
|
||||
|
||||
boolList bools(list4.size());
|
||||
forAll(list4, i)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -21,10 +21,8 @@ License
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
|
||||
Description
|
||||
|
||||
Test behaviour of UPtrList, PtrList
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
@ -32,6 +30,8 @@ Description
|
||||
#include "scalar.H"
|
||||
#include "IOstreams.H"
|
||||
#include "PtrList.H"
|
||||
#include "DLPtrList.H"
|
||||
#include "SLPtrList.H"
|
||||
#include "plane.H"
|
||||
#include "DynamicList.H"
|
||||
|
||||
@ -80,6 +80,36 @@ int main(int argc, char *argv[])
|
||||
PtrList<Scalar> list2(15);
|
||||
PtrList<Scalar> listApp;
|
||||
|
||||
{
|
||||
DLPtrList<Scalar> llist1;
|
||||
llist1.insert(new Scalar(100));
|
||||
llist1.insert(new Scalar(200));
|
||||
llist1.insert(new Scalar(300));
|
||||
|
||||
DLPtrList<Scalar>::const_iterator citer = llist1.begin();
|
||||
|
||||
Info<< *citer << endl;
|
||||
Info<< typeid(*citer).name() << endl;
|
||||
|
||||
++citer;
|
||||
++citer;
|
||||
|
||||
--citer;
|
||||
|
||||
Info<< typeid(llist1.begin()).name() << endl;
|
||||
|
||||
forAllIters(llist1, it)
|
||||
{
|
||||
Info<< typeid(*it).name() << nl
|
||||
<< "reversed: " << *it << endl;
|
||||
}
|
||||
for (const auto& it : llist1)
|
||||
{
|
||||
Info<< typeid(it).name() << nl
|
||||
<< "for-: " << it << endl;
|
||||
}
|
||||
}
|
||||
|
||||
forAll(list1, i)
|
||||
{
|
||||
list1.set(i, new Scalar(1.3*i));
|
||||
@ -95,9 +125,10 @@ int main(int argc, char *argv[])
|
||||
listApp.append(new Scalar(1.3*i));
|
||||
}
|
||||
|
||||
Info<<"list1: " << list1 << endl;
|
||||
Info<<"list2: " << list2 << endl;
|
||||
Info<<"listApp: " << listApp << endl;
|
||||
Info<< nl
|
||||
<<"list1: " << list1 << nl
|
||||
<<"list2: " << list2 << nl
|
||||
<<"list-appended: " << listApp << endl;
|
||||
|
||||
Info<<"indirectly delete some items via set(.., 0) :" << endl;
|
||||
for (label i = 0; i < 3; i++)
|
||||
@ -108,8 +139,8 @@ int main(int argc, char *argv[])
|
||||
Info<<"transfer list2 -> list1:" << endl;
|
||||
list1.transfer(list2);
|
||||
|
||||
Info<<"list1: " << list1 << endl;
|
||||
Info<<"list2: " << list2 << endl;
|
||||
Info<<"list1: " << list1 << nl
|
||||
<<"list2: " << list2 << endl;
|
||||
|
||||
Info<<"indirectly delete some items via setSize :" << endl;
|
||||
list1.setSize(4);
|
||||
@ -119,16 +150,71 @@ int main(int argc, char *argv[])
|
||||
PtrList<Scalar> list3(list1.xfer());
|
||||
Info<< "Transferred via the xfer() method" << endl;
|
||||
|
||||
Info<<"list1: " << list1 << endl;
|
||||
Info<<"list2: " << list2 << endl;
|
||||
Info<<"list3: " << list3 << endl;
|
||||
Info<<"list1: " << list1 << nl
|
||||
<<"list2: " << list2 << nl
|
||||
<<"list3: " << list3 << endl;
|
||||
|
||||
|
||||
Info<<"Move construct:" << endl;
|
||||
|
||||
PtrList<Scalar> list4(std::move(list3));
|
||||
|
||||
Info<<"list3: " << list3 << nl
|
||||
<<"list4: " << list4 << endl;
|
||||
|
||||
Info<<"Move assign:" << endl;
|
||||
list3 = std::move(list4);
|
||||
|
||||
Info<<"list3: " << list3 << nl
|
||||
<<"list4: " << list4 << endl;
|
||||
|
||||
|
||||
Info<<"UPtrList from PtrList" << nl;
|
||||
|
||||
UPtrList<Scalar> ulist1(list3);
|
||||
|
||||
Info<<"ulist1: " << ulist1 << nl;
|
||||
|
||||
Info<<"Move construct:" << endl;
|
||||
|
||||
UPtrList<Scalar> ulist2(std::move(ulist1));
|
||||
|
||||
Info<<"ulist1: " << ulist1 << nl
|
||||
<<"ulist2: " << ulist2 << nl;
|
||||
|
||||
Info<<"Copy assign:" << endl;
|
||||
ulist1 = ulist2;
|
||||
|
||||
Info<<"ulist1: " << ulist1 << nl
|
||||
<<"ulist2: " << ulist2 << nl;
|
||||
|
||||
Info<<"Move assign:" << endl;
|
||||
ulist1 = std::move(ulist2);
|
||||
|
||||
Info<<"ulist1: " << ulist1 << nl
|
||||
<<"ulist2: " << ulist2 << nl;
|
||||
|
||||
// Test iterator random access
|
||||
{
|
||||
auto iter1 = ulist1.begin();
|
||||
auto iter2 = iter1 + 3;
|
||||
|
||||
Info<<"begin:" << *iter1 << " (+3):" << *iter2 << nl;
|
||||
Info<< "diff= " << (iter1 - iter2) << nl;
|
||||
Info<< "iter[2]=" << iter1[2] << nl;
|
||||
Info<< "iter1 < iter2 : " << (iter1 < iter2) << nl;
|
||||
Info<< "iter1 >= iter2 : " << (iter1 >= iter2) << nl;
|
||||
}
|
||||
|
||||
PtrList<plane> planes;
|
||||
planes.append(new plane(vector::one, vector::one));
|
||||
planes.append(new plane(vector(1,2,3), vector::one));
|
||||
|
||||
forAll(planes, p)
|
||||
Info<< "plane " << planes[p] << endl;
|
||||
Info<< nl << "appended values" << nl;
|
||||
for (const plane& p : planes)
|
||||
{
|
||||
Info<< " plane " << p << endl;
|
||||
}
|
||||
|
||||
Info<< nl << "Done." << endl;
|
||||
return 0;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,12 +28,32 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
|
||||
#include "IOstreams.H"
|
||||
#include "SLList.H"
|
||||
#include "List.H"
|
||||
#include "FlatOutput.H"
|
||||
#include "ListOps.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class T>
|
||||
void printAddress(const UList<T>& list)
|
||||
{
|
||||
Info<< "list addr: " << long(&list)
|
||||
<< " data addr: " << long(list.cdata()) << nl;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void printAddresses(const SLList<List<T>>& sll)
|
||||
{
|
||||
for (const auto& elem : sll)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
@ -50,34 +70,34 @@ int main(int argc, char *argv[])
|
||||
myList.append(100.3);
|
||||
myList.append(500.3);
|
||||
|
||||
Info<< nl << "And again using STL iterator: " << nl << endl;
|
||||
Info<< "SLList<scalar>" << myList << nl;
|
||||
Info<< nl << "flat-output: " << flatOutput(myList) << nl;
|
||||
|
||||
Info<< nl << "range-for:" << nl;
|
||||
for (const auto& val : myList)
|
||||
{
|
||||
Info<< "element:" << val << endl;
|
||||
Info<< " " << val << nl;
|
||||
}
|
||||
|
||||
Info<< nl << "And again using STL const_iterator: " << nl << endl;
|
||||
Info<< nl << "const_iterator:" << nl;
|
||||
|
||||
const SLList<scalar>& const_myList = myList;
|
||||
|
||||
forAllConstIters(const_myList, iter)
|
||||
{
|
||||
Info<< "element:" << *iter << endl;
|
||||
Info<< " " << *iter << endl;
|
||||
}
|
||||
|
||||
Info<< nl << "Remove elements:" << nl;
|
||||
|
||||
forAllIters(myList, iter)
|
||||
{
|
||||
Info<< "Removing element:" << *iter << endl;
|
||||
Info<< " remove " << *iter;
|
||||
myList.remove(iter);
|
||||
}
|
||||
|
||||
for (const auto& val : const_myList)
|
||||
{
|
||||
Info<< "element:" << val << endl;
|
||||
Info<< " => " << flatOutput(myList) << nl;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i<10; i++)
|
||||
{
|
||||
myList.append(1.3*i);
|
||||
@ -86,15 +106,72 @@ int main(int argc, char *argv[])
|
||||
myList.append(100.3);
|
||||
myList.append(500.3);
|
||||
|
||||
Info<< nl << "Testing transfer: " << nl << endl;
|
||||
Info<< "original: " << myList << endl;
|
||||
Info<< nl << "Transfer: " << nl;
|
||||
Info<< "original: " << flatOutput(myList) << endl;
|
||||
|
||||
SLList<scalar> newList;
|
||||
newList.transfer(myList);
|
||||
|
||||
Info<< nl << "source: " << myList << nl
|
||||
<< nl << "target: " << newList << endl;
|
||||
Info<< nl
|
||||
<< "source: " << flatOutput(myList) << nl
|
||||
<< "target: " << flatOutput(newList) << nl;
|
||||
|
||||
Info<< nl << "Move Construct: " << nl;
|
||||
|
||||
SLList<scalar> list2(std::move(newList));
|
||||
|
||||
Info<< nl
|
||||
<< "in : " << flatOutput(newList) << nl
|
||||
<< "out: " << flatOutput(list2) << nl;
|
||||
|
||||
// Move back
|
||||
Info<< nl << "Move Assignment: " << nl;
|
||||
|
||||
newList = std::move(list2);
|
||||
|
||||
Info<< nl
|
||||
<< "in : " << flatOutput(newList) << nl
|
||||
<< "out: " << flatOutput(list2) << nl;
|
||||
|
||||
|
||||
// Try delete data recovery
|
||||
{
|
||||
SLList<List<label>> labList;
|
||||
|
||||
for (int i = 0; i<5; i++)
|
||||
{
|
||||
labList.append(identity(6));
|
||||
}
|
||||
|
||||
Info<< nl
|
||||
<< "SLList<labelList> : " << labList << nl;
|
||||
|
||||
printAddresses(labList);
|
||||
|
||||
auto elem = labList.removeHead();
|
||||
|
||||
Info<< " removed head" << nl;
|
||||
printAddress(elem);
|
||||
|
||||
elem = labList.removeHead();
|
||||
|
||||
Info<< " removed head" << nl;
|
||||
printAddress(elem);
|
||||
|
||||
List<label> content1 = identity(10);
|
||||
|
||||
Info<< nl
|
||||
<< " move append ";
|
||||
printAddress(content1);
|
||||
|
||||
labList.append(std::move(content1));
|
||||
|
||||
Info<< " content " << flatOutput(content1) << nl
|
||||
<< " list" << labList << nl;
|
||||
|
||||
printAddresses(labList);
|
||||
// labList.append(content1);
|
||||
}
|
||||
|
||||
Info<< nl << "Done." << endl;
|
||||
return 0;
|
||||
|
||||
3
applications/test/UList/Make/files
Normal file
3
applications/test/UList/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-UList.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-UList
|
||||
0
applications/test/UList/Make/options
Normal file
0
applications/test/UList/Make/options
Normal file
119
applications/test/UList/Test-UList.C
Normal file
119
applications/test/UList/Test-UList.C
Normal file
@ -0,0 +1,119 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-UList
|
||||
|
||||
Description
|
||||
Simple tests for UList constructors
|
||||
|
||||
See also
|
||||
Foam::List
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
#include "IOstreams.H"
|
||||
#include "StringStream.H"
|
||||
|
||||
#include "labelList.H"
|
||||
#include "ListOps.H"
|
||||
#include "SubList.H"
|
||||
#include "FlatOutput.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class ListType>
|
||||
void print(const ListType& list)
|
||||
{
|
||||
Info << flatOutput(list) << " data addr: " << long(list.cdata()) << nl;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
List<label> source = identity(7);
|
||||
List<label> other = identity(7);
|
||||
|
||||
// Text for reading as a SLList"
|
||||
string inputSLList("(10 20 30 40 50 60 70)");
|
||||
|
||||
// Text for reading as a SLList"
|
||||
string inputCompound("List<label> (-1 -2 -3 -4 -5 -6 -7)");
|
||||
|
||||
reverse(other);
|
||||
|
||||
UList<label> ulist(source.data(), source.size());
|
||||
|
||||
Info<<"source: "; print(source);
|
||||
Info<<"other: "; print(other);
|
||||
Info<<"UList: "; print(ulist);
|
||||
|
||||
{
|
||||
Info<<"shallow copy" << nl;
|
||||
ulist.shallowCopy(other);
|
||||
|
||||
Info<<"source: "; print(source);
|
||||
Info<<"other: "; print(other);
|
||||
Info<<"UList: "; print(ulist);
|
||||
}
|
||||
|
||||
{
|
||||
Info<<"deep copy" << nl;
|
||||
ulist.deepCopy(source);
|
||||
|
||||
Info<<"source: "; print(source);
|
||||
Info<<"other: "; print(other);
|
||||
Info<<"UList: "; print(ulist);
|
||||
}
|
||||
|
||||
{
|
||||
Info<<"Read from " << inputSLList << nl;
|
||||
|
||||
IStringStream is(inputSLList);
|
||||
is >> ulist;
|
||||
|
||||
// Info<<"source: "; print(source);
|
||||
// Info<<"other: "; print(other);
|
||||
Info<<"UList: "; print(ulist);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
Info<<"Read from " << inputCompound << nl;
|
||||
|
||||
IStringStream is(inputCompound);
|
||||
is >> ulist;
|
||||
|
||||
// Info<<"source: "; print(source);
|
||||
// Info<<"other: "; print(other);
|
||||
Info<<"UList: "; print(ulist);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -194,6 +194,7 @@ int main(int argc, char *argv[])
|
||||
argList::addBoolOption("ext", "test handing of file extensions");
|
||||
argList::addBoolOption("construct", "test constructors");
|
||||
argList::addBoolOption("relative", "test relative operations");
|
||||
argList::addBoolOption("system", "test filesystem operations");
|
||||
argList::addBoolOption("default", "reinstate default tests");
|
||||
argList::addNote("runs default tests or specified ones only");
|
||||
|
||||
@ -485,72 +486,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
if (!defaultTests)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
DynamicList<word> wrdList
|
||||
{
|
||||
"hello",
|
||||
"hello1",
|
||||
"hello2",
|
||||
"hello3",
|
||||
"hello4.hmm"
|
||||
};
|
||||
|
||||
fileName pathName(wrdList);
|
||||
|
||||
Info<< "pathName = " << pathName << nl
|
||||
<< "pathName.name() = >" << pathName.name() << "<\n"
|
||||
<< "pathName.path() = " << pathName.path() << nl
|
||||
<< "pathName.ext() = >" << pathName.ext() << "<\n"
|
||||
<< "pathName.name(true) = >" << pathName.name(true) << "<\n";
|
||||
|
||||
Info<< "pathName.components() = " << pathName.components() << nl
|
||||
<< "pathName.component(2) = " << pathName.component(2) << nl
|
||||
<< endl;
|
||||
|
||||
// try with different combination
|
||||
// The final one should emit warnings
|
||||
for (label start = 0; start <= wrdList.size(); ++start)
|
||||
{
|
||||
fileName instance, local;
|
||||
word name;
|
||||
|
||||
fileName path(SubList<word>(wrdList, wrdList.size()-start, start));
|
||||
fileName path2 = "."/path;
|
||||
|
||||
IOobject::fileNameComponents
|
||||
(
|
||||
path,
|
||||
instance,
|
||||
local,
|
||||
name
|
||||
);
|
||||
|
||||
Info<< "IOobject::fileNameComponents for " << path << nl
|
||||
<< " instance = " << instance << nl
|
||||
<< " local = " << local << nl
|
||||
<< " name = " << name << endl;
|
||||
|
||||
IOobject::fileNameComponents
|
||||
(
|
||||
path2,
|
||||
instance,
|
||||
local,
|
||||
name
|
||||
);
|
||||
|
||||
Info<< "IOobject::fileNameComponents for " << path2 << nl
|
||||
<< " instance = " << instance << nl
|
||||
<< " local = " << local << nl
|
||||
<< " name = " << name << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Test some copying and deletion
|
||||
if (args.found("system"))
|
||||
{
|
||||
const fileName dirA("dirA");
|
||||
const fileName lnA("lnA");
|
||||
@ -663,6 +600,71 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
if (!defaultTests)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
DynamicList<word> wrdList
|
||||
{
|
||||
"hello",
|
||||
"hello1",
|
||||
"hello2",
|
||||
"hello3",
|
||||
"hello4.hmm"
|
||||
};
|
||||
|
||||
fileName pathName(wrdList);
|
||||
|
||||
Info<< "pathName = " << pathName << nl
|
||||
<< "pathName.name() = >" << pathName.name() << "<\n"
|
||||
<< "pathName.path() = " << pathName.path() << nl
|
||||
<< "pathName.ext() = >" << pathName.ext() << "<\n"
|
||||
<< "pathName.name(true) = >" << pathName.name(true) << "<\n";
|
||||
|
||||
Info<< "pathName.components() = " << pathName.components() << nl
|
||||
<< "pathName.component(2) = " << pathName.component(2) << nl
|
||||
<< endl;
|
||||
|
||||
// try with different combination
|
||||
// The final one should emit warnings
|
||||
for (label start = 0; start <= wrdList.size(); ++start)
|
||||
{
|
||||
fileName instance, local;
|
||||
word name;
|
||||
|
||||
fileName path(SubList<word>(wrdList, wrdList.size()-start, start));
|
||||
fileName path2 = "."/path;
|
||||
|
||||
IOobject::fileNameComponents
|
||||
(
|
||||
path,
|
||||
instance,
|
||||
local,
|
||||
name
|
||||
);
|
||||
|
||||
Info<< "IOobject::fileNameComponents for " << path << nl
|
||||
<< " instance = " << instance << nl
|
||||
<< " local = " << local << nl
|
||||
<< " name = " << name << endl;
|
||||
|
||||
IOobject::fileNameComponents
|
||||
(
|
||||
path2,
|
||||
instance,
|
||||
local,
|
||||
name
|
||||
);
|
||||
|
||||
Info<< "IOobject::fileNameComponents for " << path2 << nl
|
||||
<< " instance = " << instance << nl
|
||||
<< " local = " << local << nl
|
||||
<< " name = " << name << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// test findEtcFile
|
||||
Info<< "\n\nfindEtcFile tests:" << nl
|
||||
<< " controlDict => " << findEtcFile("controlDict") << nl
|
||||
|
||||
@ -46,6 +46,9 @@ void printCleaning(fileName& pathName)
|
||||
<< " name() = " << pathName.name() << nl
|
||||
<< " joined = " << pathName.path()/pathName.name() << nl << nl;
|
||||
|
||||
Info<< "components = " << flatOutput(pathName.components()) << nl;
|
||||
Info<< "component 2 = " << pathName.component(2) << nl;
|
||||
|
||||
pathName.clean();
|
||||
|
||||
Info<< "cleaned = " << pathName << nl
|
||||
|
||||
3
applications/test/hashedWordList/Make/files
Normal file
3
applications/test/hashedWordList/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-hashedWordList.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-hashedWordList
|
||||
2
applications/test/hashedWordList/Make/options
Normal file
2
applications/test/hashedWordList/Make/options
Normal file
@ -0,0 +1,2 @@
|
||||
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */
|
||||
/* EXE_LIBS = -lfiniteVolume */
|
||||
181
applications/test/hashedWordList/Test-hashedWordList.C
Normal file
181
applications/test/hashedWordList/Test-hashedWordList.C
Normal file
@ -0,0 +1,181 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "IOstreams.H"
|
||||
#include "ITstream.H"
|
||||
#include "FlatOutput.H"
|
||||
#include "hashedWordList.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
Ostream& printInfo(const hashedWordList& list, bool withAddr=false)
|
||||
{
|
||||
Info<< flatOutput(list) << nl << list.lookup() << nl;
|
||||
if (withAddr)
|
||||
{
|
||||
Info<< "addr=" << long(list.cdata()) << nl;
|
||||
}
|
||||
|
||||
return Info;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Info<< "Test hashedWordList" << nl;
|
||||
|
||||
hashedWordList list1
|
||||
{
|
||||
"this",
|
||||
"is",
|
||||
"a",
|
||||
"list",
|
||||
"of",
|
||||
"words",
|
||||
};
|
||||
|
||||
Info<<nl << "From initializer_list" << nl;
|
||||
printInfo(list1, true);
|
||||
|
||||
list1.sort();
|
||||
|
||||
Info<<nl << "sorted" << nl;
|
||||
printInfo(list1, true);
|
||||
|
||||
// Copy construct
|
||||
hashedWordList list2(list1);
|
||||
|
||||
Info<<nl << "Copy construct" << nl;
|
||||
Info<<"list1: ";
|
||||
printInfo(list1, true);
|
||||
Info<<"list2: ";
|
||||
printInfo(list2, true);
|
||||
|
||||
// Move construct
|
||||
hashedWordList list3(std::move(list1));
|
||||
|
||||
Info<<nl << "Move construct" << nl;
|
||||
Info<<"list1: ";
|
||||
printInfo(list1, true);
|
||||
Info<<"list3: ";
|
||||
printInfo(list3, true);
|
||||
|
||||
// Move assign
|
||||
list1 = std::move(list3);
|
||||
|
||||
Info<<nl << "Move assign" << nl;
|
||||
Info<<"list1: ";
|
||||
printInfo(list1, true);
|
||||
Info<<"list3: ";
|
||||
printInfo(list3, true);
|
||||
|
||||
list1.swap(list3);
|
||||
Info<<nl << "Swap" << nl;
|
||||
Info<<"list1: ";
|
||||
printInfo(list1, true);
|
||||
Info<<"list3: ";
|
||||
printInfo(list3, true);
|
||||
|
||||
wordList wlist1
|
||||
{
|
||||
"plain", "list", "with", "some", "with", "list", "duplicates"
|
||||
};
|
||||
|
||||
|
||||
// Copy construct unique
|
||||
hashedWordList list4(wlist1, true);
|
||||
|
||||
Info<<nl << "Copy construct unique" << nl;
|
||||
Info<<"words: " << flatOutput(wlist1) << nl;
|
||||
Info<<"list4: ";
|
||||
printInfo(list4, false);
|
||||
|
||||
// Move construct unique
|
||||
hashedWordList list5(std::move(wlist1), true);
|
||||
|
||||
Info<<nl << "Move construct unique" << nl;
|
||||
Info<<"words: " << flatOutput(wlist1) << nl;
|
||||
Info<<"list5: ";
|
||||
printInfo(list5, false);
|
||||
|
||||
// Move back. Leaves lookup() with some rubbish, but clean that later
|
||||
wlist1 = std::move(list5);
|
||||
|
||||
Info<<nl << "Move to wordList" << nl;
|
||||
Info<<"words: " << flatOutput(wlist1) << nl;
|
||||
Info<<"list5: ";
|
||||
printInfo(list5, false);
|
||||
|
||||
// Move back. Leaves lookup() with some rubbish, but clean that later
|
||||
list5 = std::move(wlist1);
|
||||
|
||||
Info<<nl << "Moved from wordList" << nl;
|
||||
Info<<"words: " << flatOutput(wlist1) << nl;
|
||||
Info<<"list5: ";
|
||||
printInfo(list5, false);
|
||||
|
||||
|
||||
// Test access:
|
||||
|
||||
Info<<nl << "Access" << nl;
|
||||
Info<<"list: " << flatOutput(list5) << nl;
|
||||
|
||||
for (const auto str : { "some", "list", "of", "words" })
|
||||
{
|
||||
Info<<"index of " << str << " = " << list5[str] << nl;
|
||||
}
|
||||
|
||||
// Stream construct
|
||||
{
|
||||
ITstream input
|
||||
(
|
||||
"input",
|
||||
"(plain list with some with list duplicates)"
|
||||
);
|
||||
|
||||
hashedWordList list6(input);
|
||||
|
||||
Info<<nl << "Construct from stream" << nl;
|
||||
Info<<"list: " << flatOutput(list6) << nl;
|
||||
|
||||
input.rewind();
|
||||
|
||||
input >> list4;
|
||||
Info<<nl << "re-read from stream" << nl;
|
||||
Info<<"list: " << flatOutput(list4) << nl;
|
||||
}
|
||||
|
||||
|
||||
Info<< "\nEnd\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,3 +0,0 @@
|
||||
Test-xferList.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-xferList
|
||||
3
applications/test/xfer1/Make/files
Normal file
3
applications/test/xfer1/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-xfer1.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-xfer1
|
||||
0
applications/test/xfer1/Make/options
Normal file
0
applications/test/xfer1/Make/options
Normal file
@ -39,61 +39,83 @@ Description
|
||||
using namespace Foam;
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
List<label> lstA(10);
|
||||
List<label> lstC
|
||||
labelList lstA(10);
|
||||
labelList lstC
|
||||
{
|
||||
1, 2, 3, 4
|
||||
};
|
||||
|
||||
forAll(lstA, i)
|
||||
{
|
||||
lstA[i] = i;
|
||||
lstA[i] = 5 - i;
|
||||
}
|
||||
|
||||
Info<< "lstA: " << lstA << endl;
|
||||
Info<< "lstC: " << lstC << endl;
|
||||
Info<< "lstA: " << lstA << nl
|
||||
<< "lstC: " << lstC << nl;
|
||||
|
||||
Xfer<List<label>> xA = xferMove(lstA);
|
||||
Xfer<List<label>> xB;
|
||||
Xfer<labelList> xA = xferMove(lstA);
|
||||
Xfer<labelList> xB;
|
||||
|
||||
List<label> lstB( xA );
|
||||
labelList lstB( xA );
|
||||
|
||||
Info<< "xA: " << xA() << endl;
|
||||
Info<< "xB: " << xB() << endl;
|
||||
Info<< "lstA: " << lstA << endl;
|
||||
Info<< "lstB: " << lstB << endl;
|
||||
Info<< "lstC: " << lstC << endl;
|
||||
Info<< "xA: " << xA() << nl
|
||||
<< "xB: " << xB() << nl
|
||||
<< "lstA: " << lstA << nl
|
||||
<< "lstB: " << lstB << nl
|
||||
<< "lstC: " << lstC << nl;
|
||||
|
||||
xA = lstB;
|
||||
// Now illegal: xA = lstB;
|
||||
|
||||
Info<< "xA: " << xA() << endl;
|
||||
Info<< "xB: " << xB() << endl;
|
||||
Info<< "lstA: " << lstA << endl;
|
||||
Info<< "lstB: " << lstB << endl;
|
||||
Info<< "lstC: " << lstC << endl;
|
||||
xA->transfer(lstB);
|
||||
|
||||
Info<< "xA: " << xA() << nl
|
||||
<< "xB: " << xB() << nl
|
||||
<< "lstA: " << lstA << nl
|
||||
<< "lstB: " << lstB << nl
|
||||
<< "lstC: " << lstC << nl;
|
||||
|
||||
xB = xA;
|
||||
|
||||
List<label> lstD(xferCopy(lstC));
|
||||
List<label> lstE(xferMove(lstC));
|
||||
// Construct with forwarding. For this example, truly ugly.
|
||||
Xfer<labelList> xFwdA =
|
||||
Xfer<labelList>::New
|
||||
(
|
||||
std::initializer_list<label>
|
||||
{
|
||||
1, 2, 10, 20, 15, 24, 200
|
||||
}
|
||||
);
|
||||
|
||||
Xfer<labelList> xFwdB = Xfer<labelList>::New(label(8), 123);
|
||||
Xfer<labelList> xFwdC = Xfer<labelList>::New();
|
||||
|
||||
Info<< nl
|
||||
<< "Constructed with forwarding: " << nl
|
||||
<< *xFwdA << nl
|
||||
<< *xFwdB << nl
|
||||
<< *xFwdC << nl
|
||||
<< nl;
|
||||
|
||||
|
||||
labelList lstD(xferCopy(lstC));
|
||||
labelList lstE(xferMove(lstC));
|
||||
|
||||
// this must be empty
|
||||
List<label> lstF = xferCopy(lstC);
|
||||
labelList lstF = xferCopy(lstC);
|
||||
|
||||
Info<< "xA: " << xA() << endl;
|
||||
Info<< "xB: " << xB() << endl;
|
||||
Info<< "lstA: " << lstA << endl;
|
||||
Info<< "lstB: " << lstB << endl;
|
||||
Info<< "lstC: " << lstC << endl;
|
||||
Info<< "lstD: " << lstD << endl;
|
||||
Info<< "lstE: " << lstE << endl;
|
||||
Info<< "lstF: " << lstF << endl;
|
||||
Info<< "xA: " << xA() << nl
|
||||
<< "xB: " << xB() << nl
|
||||
<< "lstA: " << lstA << nl
|
||||
<< "lstB: " << lstB << nl
|
||||
<< "lstC: " << lstC << nl
|
||||
<< "lstD: " << lstD << nl
|
||||
<< "lstE: " << lstE << nl
|
||||
<< "lstF: " << lstF << nl;
|
||||
|
||||
Info<< "xB[" << xB->size() << "]\n";
|
||||
|
||||
@ -102,7 +124,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< "xB[" << xB->size() << "]\n";
|
||||
|
||||
DynamicList<label> dl(10);
|
||||
DynamicList<label> dl;
|
||||
for (label i = 0; i < 5; ++i)
|
||||
{
|
||||
dl.append(i);
|
||||
@ -111,9 +133,9 @@ int main(int argc, char *argv[])
|
||||
face f1(dl);
|
||||
face f2(xferCopy<labelList>(dl));
|
||||
|
||||
Info<< "dl[" << dl.size() << "/" << dl.capacity() << "] " << dl << endl;
|
||||
Info<< "f1: " << f1 << endl;
|
||||
Info<< "f2: " << f2 << endl;
|
||||
Info<< "dl[" << dl.size() << "/" << dl.capacity() << "] " << dl << nl;
|
||||
Info<< "f1: " << f1 << nl;
|
||||
Info<< "f2: " << f2 << nl;
|
||||
|
||||
// add some more labels
|
||||
for (label i = 5; i < 8; ++i)
|
||||
@ -123,18 +145,18 @@ int main(int argc, char *argv[])
|
||||
|
||||
// note: xfer() method returns a plain labelList
|
||||
face f3(dl.xfer());
|
||||
Info<< "dl[" << dl.size() << "/" << dl.capacity() << "] " << dl << endl;
|
||||
Info<< "f3: " << f3 << endl;
|
||||
Info<< "dl[" << dl.size() << "/" << dl.capacity() << "] " << dl << nl;
|
||||
Info<< "f3: " << f3 << nl;
|
||||
|
||||
Info<<"\nflip faces:" << endl;
|
||||
Info<<"\nflip faces:" << nl;
|
||||
f1.flip();
|
||||
f3.flip();
|
||||
Info<< "f1: " << f1 << endl;
|
||||
Info<< "f3: " << f3 << endl;
|
||||
Info<< "f1: " << f1 << nl;
|
||||
Info<< "f3: " << f3 << nl;
|
||||
|
||||
|
||||
{
|
||||
Info<<"\nTest xfer with fields:" << endl;
|
||||
Info<<"\nTest xfer with fields:" << nl;
|
||||
List<point> list1
|
||||
{
|
||||
{ 0, 1, 2 },
|
||||
@ -180,7 +202,6 @@ int main(int argc, char *argv[])
|
||||
<<"xfer copy construct from Field (as Field): " << nl
|
||||
<<"input (field) = " << field4 << nl
|
||||
<<"output (dyn-field) = " << dyfield1 << nl;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -41,7 +41,6 @@ SeeAlso
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
#include "volFields.H"
|
||||
#include "CompactListList.H"
|
||||
#include "unitConversion.H"
|
||||
#include "pairPatchAgglomeration.H"
|
||||
#include "labelListIOList.H"
|
||||
|
||||
@ -70,11 +70,11 @@ class HashPtrTable
|
||||
|
||||
//- Read from Istream using given Istream constructor class
|
||||
template<class INew>
|
||||
void read(Istream& is, const INew& inewt);
|
||||
void read(Istream& is, const INew& inew);
|
||||
|
||||
//- Read from dictionary using given dictionary constructor class
|
||||
template<class INew>
|
||||
void read(const dictionary& dict, const INew& inewt);
|
||||
void read(const dictionary& dict, const INew& inew);
|
||||
|
||||
|
||||
public:
|
||||
@ -99,7 +99,7 @@ public:
|
||||
|
||||
//- Construct from Istream using given Istream constructor class
|
||||
template<class INew>
|
||||
HashPtrTable(Istream& is, const INew& inewt);
|
||||
HashPtrTable(Istream& is, const INew& inew);
|
||||
|
||||
//- Construct from Istream using default Istream constructor class
|
||||
HashPtrTable(Istream& is);
|
||||
|
||||
@ -33,7 +33,7 @@ License
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
template<class INew>
|
||||
void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt)
|
||||
void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inew)
|
||||
{
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
@ -47,25 +47,25 @@ void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt)
|
||||
|
||||
if (firstToken.isLabel())
|
||||
{
|
||||
const label s = firstToken.labelToken();
|
||||
const label len = firstToken.labelToken();
|
||||
|
||||
// Read beginning of contents
|
||||
const char delimiter = is.readBeginList("HashPtrTable");
|
||||
|
||||
if (s)
|
||||
if (len)
|
||||
{
|
||||
if (2*s > this->capacity())
|
||||
if (2*len > this->capacity())
|
||||
{
|
||||
this->resize(2*s);
|
||||
this->resize(2*len);
|
||||
}
|
||||
|
||||
if (delimiter == token::BEGIN_LIST)
|
||||
{
|
||||
for (label i=0; i<s; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
Key key;
|
||||
is >> key;
|
||||
this->insert(key, inewt(key, is).ptr());
|
||||
this->insert(key, inew(key, is).ptr());
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
@ -110,7 +110,7 @@ void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt)
|
||||
is.putBack(lastToken);
|
||||
Key key;
|
||||
is >> key;
|
||||
this->insert(key, inewt(key, is).ptr());
|
||||
this->insert(key, inew(key, is).ptr());
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
@ -140,14 +140,14 @@ template<class INew>
|
||||
void Foam::HashPtrTable<T, Key, Hash>::read
|
||||
(
|
||||
const dictionary& dict,
|
||||
const INew& inewt
|
||||
const INew& inew
|
||||
)
|
||||
{
|
||||
forAllConstIter(dictionary, dict, iter)
|
||||
{
|
||||
const word& k = iter().keyword();
|
||||
|
||||
this->insert(k, inewt(dict.subDict(k)).ptr());
|
||||
this->insert(k, inew(dict.subDict(k)).ptr());
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,9 +170,9 @@ void Foam::HashPtrTable<T, Key, Hash>::write(Ostream& os) const
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
template<class INew>
|
||||
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(Istream& is, const INew& inewt)
|
||||
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(Istream& is, const INew& inew)
|
||||
{
|
||||
this->read(is, inewt);
|
||||
this->read(is, inew);
|
||||
}
|
||||
|
||||
|
||||
@ -209,12 +209,12 @@ Foam::Ostream& Foam::operator<<
|
||||
const HashPtrTable<T, Key, Hash>& tbl
|
||||
)
|
||||
{
|
||||
const label sz = tbl.size();
|
||||
const label len = tbl.size();
|
||||
|
||||
if (sz)
|
||||
if (len)
|
||||
{
|
||||
// Size and start list delimiter
|
||||
os << nl << sz << nl << token::BEGIN_LIST << nl;
|
||||
os << nl << len << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
// Contents
|
||||
for (auto iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
|
||||
@ -233,7 +233,7 @@ Foam::Ostream& Foam::operator<<
|
||||
else
|
||||
{
|
||||
// Empty hash table
|
||||
os << sz << token::BEGIN_LIST << token::END_LIST;
|
||||
os << len << token::BEGIN_LIST << token::END_LIST;
|
||||
}
|
||||
|
||||
os.check(FUNCTION_NAME);
|
||||
|
||||
@ -170,28 +170,27 @@ inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
|
||||
|
||||
|
||||
template<class Key, class Hash>
|
||||
void Foam::HashSet<Key, Hash>::operator=(const UList<Key>& lst)
|
||||
void Foam::HashSet<Key, Hash>::operator=(const UList<Key>& rhs)
|
||||
{
|
||||
assignMultiple(lst.begin(), lst.end(), 2*lst.size());
|
||||
assignMultiple(rhs.begin(), rhs.end(), 2*rhs.size());
|
||||
}
|
||||
|
||||
|
||||
template<class Key, class Hash>
|
||||
template<unsigned Size>
|
||||
void Foam::HashSet<Key, Hash>::operator=(const FixedList<Key, Size>& lst)
|
||||
void Foam::HashSet<Key, Hash>::operator=(const FixedList<Key, Size>& rhs)
|
||||
{
|
||||
assignMultiple(lst.begin(), lst.end(), 2*lst.size());
|
||||
assignMultiple(rhs.begin(), rhs.end(), 2*rhs.size());
|
||||
}
|
||||
|
||||
|
||||
template<class Key, class Hash>
|
||||
void Foam::HashSet<Key, Hash>::operator=(std::initializer_list<Key> lst)
|
||||
void Foam::HashSet<Key, Hash>::operator=(std::initializer_list<Key> rhs)
|
||||
{
|
||||
assignMultiple(lst.begin(), lst.end(), 2*lst.size());
|
||||
assignMultiple(rhs.begin(), rhs.end(), 2*rhs.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Key, class Hash>
|
||||
bool Foam::HashSet<Key, Hash>::operator==(const HashSet<Key, Hash>& rhs) const
|
||||
{
|
||||
@ -283,24 +282,10 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const HashSet<Key, Hash>& tbl)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Key, class Hash>
|
||||
inline void Foam::Swap
|
||||
(
|
||||
HashSet<Key, Hash>& a,
|
||||
HashSet<Key, Hash>& b
|
||||
)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * */
|
||||
|
||||
template<class Key, class Hash>
|
||||
Foam::HashSet<Key, Hash>
|
||||
Foam::operator|
|
||||
Foam::HashSet<Key, Hash> Foam::operator|
|
||||
(
|
||||
const HashSet<Key, Hash>& hash1,
|
||||
const HashSet<Key, Hash>& hash2
|
||||
@ -313,8 +298,7 @@ Foam::operator|
|
||||
|
||||
|
||||
template<class Key, class Hash>
|
||||
Foam::HashSet<Key, Hash>
|
||||
Foam::operator&
|
||||
Foam::HashSet<Key, Hash> Foam::operator&
|
||||
(
|
||||
const HashSet<Key, Hash>& hash1,
|
||||
const HashSet<Key, Hash>& hash2
|
||||
@ -327,8 +311,7 @@ Foam::operator&
|
||||
|
||||
|
||||
template<class Key, class Hash>
|
||||
Foam::HashSet<Key, Hash>
|
||||
Foam::operator^
|
||||
Foam::HashSet<Key, Hash> Foam::operator^
|
||||
(
|
||||
const HashSet<Key, Hash>& hash1,
|
||||
const HashSet<Key, Hash>& hash2
|
||||
|
||||
@ -334,10 +334,10 @@ public:
|
||||
|
||||
//- Assignment from a FixedList of keys
|
||||
template<unsigned Size>
|
||||
void operator=(const FixedList<Key, Size>& lst);
|
||||
void operator=(const FixedList<Key, Size>& rhs);
|
||||
|
||||
//- Assignment from an initializer list of keys
|
||||
void operator=(std::initializer_list<Key> lst);
|
||||
void operator=(std::initializer_list<Key> rhs);
|
||||
|
||||
|
||||
// Logical and set operations
|
||||
@ -372,17 +372,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// Global Functions
|
||||
|
||||
// Exchange contents of HashSets - see HashSet::swap().
|
||||
template<class Key, class Hash>
|
||||
inline void Swap
|
||||
(
|
||||
HashSet<Key, Hash>& a,
|
||||
HashSet<Key, Hash>& b
|
||||
);
|
||||
|
||||
|
||||
// Global Operators
|
||||
|
||||
//- Combine entries from HashSets
|
||||
|
||||
@ -100,11 +100,16 @@ Foam::HashTable<T, Key, Hash>::HashTable(const HashTable<T, Key, Hash>& ht)
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::HashTable<T, Key, Hash>::HashTable(HashTable<T, Key, Hash>&& ht)
|
||||
Foam::HashTable<T, Key, Hash>::HashTable(HashTable<T, Key, Hash>&& rhs)
|
||||
:
|
||||
HashTable<T, Key, Hash>(0)
|
||||
HashTableCore(),
|
||||
size_(rhs.size_),
|
||||
capacity_(rhs.capacity_),
|
||||
table_(rhs.table_)
|
||||
{
|
||||
transfer(ht);
|
||||
rhs.size_ = 0;
|
||||
rhs.capacity_ = 0;
|
||||
rhs.table_ = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -116,9 +121,9 @@ Foam::HashTable<T, Key, Hash>::HashTable
|
||||
:
|
||||
HashTable<T, Key, Hash>(2*lst.size())
|
||||
{
|
||||
for (const auto& pair : lst)
|
||||
for (const auto& keyval : lst)
|
||||
{
|
||||
insert(pair.first, pair.second);
|
||||
insert(keyval.first, keyval.second);
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,25 +146,25 @@ Foam::HashTable<T, Key, Hash>::~HashTable()
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::List<Key> Foam::HashTable<T, Key, Hash>::toc() const
|
||||
{
|
||||
List<Key> keyLst(size_);
|
||||
List<Key> list(size_);
|
||||
label count = 0;
|
||||
|
||||
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
||||
{
|
||||
keyLst[count++] = iter.key();
|
||||
list[count++] = iter.key();
|
||||
}
|
||||
|
||||
return keyLst;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::List<Key> Foam::HashTable<T, Key, Hash>::sortedToc() const
|
||||
{
|
||||
List<Key> keyLst(this->toc());
|
||||
Foam::sort(keyLst);
|
||||
List<Key> list(this->toc());
|
||||
Foam::sort(list);
|
||||
|
||||
return keyLst;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@ -170,10 +175,10 @@ Foam::List<Key> Foam::HashTable<T, Key, Hash>::sortedToc
|
||||
const Compare& comp
|
||||
) const
|
||||
{
|
||||
List<Key> keyLst(this->toc());
|
||||
Foam::sort(keyLst, comp);
|
||||
List<Key> list(this->toc());
|
||||
Foam::sort(list, comp);
|
||||
|
||||
return keyLst;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@ -185,21 +190,21 @@ Foam::List<Key> Foam::HashTable<T, Key, Hash>::tocKeys
|
||||
const bool invert
|
||||
) const
|
||||
{
|
||||
List<Key> keyLst(size_);
|
||||
List<Key> list(size_);
|
||||
label count = 0;
|
||||
|
||||
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
||||
{
|
||||
if ((pred(iter.key()) ? !invert : invert))
|
||||
{
|
||||
keyLst[count++] = iter.key();
|
||||
list[count++] = iter.key();
|
||||
}
|
||||
}
|
||||
|
||||
keyLst.setSize(count);
|
||||
Foam::sort(keyLst);
|
||||
list.setSize(count);
|
||||
Foam::sort(list);
|
||||
|
||||
return keyLst;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@ -211,21 +216,21 @@ Foam::List<Key> Foam::HashTable<T, Key, Hash>::tocValues
|
||||
const bool invert
|
||||
) const
|
||||
{
|
||||
List<Key> keyLst(size_);
|
||||
List<Key> list(size_);
|
||||
label count = 0;
|
||||
|
||||
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
||||
{
|
||||
if ((pred(iter.object()) ? !invert : invert))
|
||||
{
|
||||
keyLst[count++] = iter.key();
|
||||
list[count++] = iter.key();
|
||||
}
|
||||
}
|
||||
|
||||
keyLst.setSize(count);
|
||||
Foam::sort(keyLst);
|
||||
list.setSize(count);
|
||||
Foam::sort(list);
|
||||
|
||||
return keyLst;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@ -237,21 +242,21 @@ Foam::List<Key> Foam::HashTable<T, Key, Hash>::tocEntries
|
||||
const bool invert
|
||||
) const
|
||||
{
|
||||
List<Key> keyLst(size_);
|
||||
List<Key> list(size_);
|
||||
label count = 0;
|
||||
|
||||
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
||||
{
|
||||
if ((pred(iter.key(), iter.object()) ? !invert : invert))
|
||||
{
|
||||
keyLst[count++] = iter.key();
|
||||
list[count++] = iter.key();
|
||||
}
|
||||
}
|
||||
|
||||
keyLst.setSize(count);
|
||||
Foam::sort(keyLst);
|
||||
list.setSize(count);
|
||||
Foam::sort(list);
|
||||
|
||||
return keyLst;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@ -647,33 +652,19 @@ void Foam::HashTable<T, Key, Hash>::clearStorage()
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
void Foam::HashTable<T, Key, Hash>::swap(HashTable<T, Key, Hash>& ht)
|
||||
void Foam::HashTable<T, Key, Hash>::swap(HashTable<T, Key, Hash>& rhs)
|
||||
{
|
||||
Foam::Swap(size_, ht.size_);
|
||||
Foam::Swap(capacity_, ht.capacity_);
|
||||
Foam::Swap(table_, ht.table_);
|
||||
Foam::Swap(size_, rhs.size_);
|
||||
Foam::Swap(capacity_, rhs.capacity_);
|
||||
Foam::Swap(table_, rhs.table_);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
void Foam::HashTable<T, Key, Hash>::transfer(HashTable<T, Key, Hash>& ht)
|
||||
void Foam::HashTable<T, Key, Hash>::transfer(HashTable<T, Key, Hash>& rhs)
|
||||
{
|
||||
// As per destructor
|
||||
if (table_)
|
||||
{
|
||||
clear();
|
||||
delete[] table_;
|
||||
}
|
||||
|
||||
size_ = ht.size_;
|
||||
ht.size_ = 0;
|
||||
|
||||
capacity_ = ht.capacity_;
|
||||
ht.capacity_ = 0;
|
||||
|
||||
table_ = ht.table_;
|
||||
ht.table_ = nullptr;
|
||||
|
||||
clear();
|
||||
swap(rhs);
|
||||
}
|
||||
|
||||
|
||||
@ -794,22 +785,22 @@ void Foam::HashTable<T, Key, Hash>::operator=
|
||||
template<class T, class Key, class Hash>
|
||||
void Foam::HashTable<T, Key, Hash>::operator=
|
||||
(
|
||||
std::initializer_list<std::pair<Key, T>> lst
|
||||
std::initializer_list<std::pair<Key, T>> rhs
|
||||
)
|
||||
{
|
||||
// Could be zero-sized from a previous transfer()
|
||||
if (!capacity_)
|
||||
{
|
||||
resize(2*lst.size());
|
||||
resize(2*rhs.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
for (const auto& pair : lst)
|
||||
for (const auto& keyval : rhs)
|
||||
{
|
||||
insert(pair.first, pair.second);
|
||||
insert(keyval.first, keyval.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -336,11 +336,11 @@ public:
|
||||
//- Construct from Istream with default table capacity
|
||||
HashTable(Istream& is, const label size = 128);
|
||||
|
||||
//- Construct as copy
|
||||
//- Copy construct
|
||||
HashTable(const this_type& ht);
|
||||
|
||||
//- Move construct
|
||||
HashTable(this_type&& ht);
|
||||
HashTable(this_type&& rhs);
|
||||
|
||||
//- Construct from an initializer list
|
||||
HashTable(std::initializer_list<std::pair<Key, T>> lst);
|
||||
@ -591,12 +591,11 @@ public:
|
||||
// Equivalent to clear() followed by resize(0)
|
||||
void clearStorage();
|
||||
|
||||
//- Swap contents of the argument table into this table
|
||||
void swap(HashTable<T, Key, Hash>& ht);
|
||||
//- Swap contents into this table
|
||||
void swap(HashTable<T, Key, Hash>& rhs);
|
||||
|
||||
//- Transfer the contents of the argument table into this table
|
||||
// and annul the argument table.
|
||||
void transfer(HashTable<T, Key, Hash>& ht);
|
||||
//- Transfer contents into this table.
|
||||
void transfer(HashTable<T, Key, Hash>& rhs);
|
||||
|
||||
|
||||
// Member Operators
|
||||
@ -615,11 +614,11 @@ public:
|
||||
//- Return existing entry or insert a new entry.
|
||||
inline T& operator()(const Key& key, const T& deflt);
|
||||
|
||||
//- Assignment
|
||||
//- Copy assignment
|
||||
void operator=(const HashTable<T, Key, Hash>& rhs);
|
||||
|
||||
//- Assignment from an initializer list
|
||||
void operator=(std::initializer_list<std::pair<Key, T>> lst);
|
||||
//- Copy assignment from an initializer list
|
||||
void operator=(std::initializer_list<std::pair<Key, T>> rhs);
|
||||
|
||||
//- Move assign
|
||||
void operator=(HashTable<T, Key, Hash>&& rhs);
|
||||
@ -973,17 +972,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// Global Functions
|
||||
|
||||
// Exchange contents of hash tables - see HashTable::swap().
|
||||
template<class T, class Key, class Hash>
|
||||
inline void Swap
|
||||
(
|
||||
HashTable<T, Key, Hash>& a,
|
||||
HashTable<T, Key, Hash>& b
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -218,17 +218,4 @@ inline T& Foam::HashTable<T, Key, Hash>::operator()
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
inline void Foam::Swap
|
||||
(
|
||||
HashTable<T, Key, Hash>& a,
|
||||
HashTable<T, Key, Hash>& b
|
||||
)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -160,21 +160,21 @@ Foam::Istream& Foam::operator>>
|
||||
|
||||
if (firstToken.isLabel())
|
||||
{
|
||||
const label s = firstToken.labelToken();
|
||||
const label len = firstToken.labelToken();
|
||||
|
||||
// Read beginning of contents
|
||||
const char delimiter = is.readBeginList("HashTable");
|
||||
|
||||
if (s)
|
||||
if (len)
|
||||
{
|
||||
if (2*s > L.capacity_)
|
||||
if (2*len > L.capacity_)
|
||||
{
|
||||
L.resize(2*s);
|
||||
L.resize(2*len);
|
||||
}
|
||||
|
||||
if (delimiter == token::BEGIN_LIST)
|
||||
{
|
||||
for (label i=0; i<s; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
Key key;
|
||||
is >> key;
|
||||
@ -258,12 +258,12 @@ Foam::Ostream& Foam::operator<<
|
||||
const HashTable<T, Key, Hash>& tbl
|
||||
)
|
||||
{
|
||||
const label sz = tbl.size();
|
||||
const label len = tbl.size();
|
||||
|
||||
if (sz)
|
||||
if (len)
|
||||
{
|
||||
// Size and start list delimiter
|
||||
os << nl << sz << nl << token::BEGIN_LIST << nl;
|
||||
os << nl << len << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
// Contents
|
||||
for (auto iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
|
||||
@ -276,7 +276,7 @@ Foam::Ostream& Foam::operator<<
|
||||
else
|
||||
{
|
||||
// Empty hash table
|
||||
os << sz << token::BEGIN_LIST << token::END_LIST;
|
||||
os << len << token::BEGIN_LIST << token::END_LIST;
|
||||
}
|
||||
|
||||
os.check(FUNCTION_NAME);
|
||||
|
||||
@ -71,14 +71,14 @@ public:
|
||||
//- Add labels to a list of values
|
||||
inline static List<Keyed<T>> createList
|
||||
(
|
||||
const List<T>&,
|
||||
const UList<T>& lst,
|
||||
const label key=0
|
||||
);
|
||||
|
||||
//- Add labels to a list of values
|
||||
inline static List<Keyed<T>> createList
|
||||
(
|
||||
const List<T>&,
|
||||
const UList<T>& lst,
|
||||
const labelUList& keys
|
||||
);
|
||||
|
||||
@ -88,14 +88,14 @@ public:
|
||||
//- Construct null
|
||||
inline Keyed();
|
||||
|
||||
//- Construct as a copy of item, with a key
|
||||
//- Copy construct item, with a key
|
||||
inline Keyed(const T& item, const label key=0);
|
||||
|
||||
//- Construct by transferring the item, with a key
|
||||
inline Keyed(const Xfer<T>& item, const label key=0);
|
||||
//- Move construct item, with a key
|
||||
inline Keyed(T&& item, const label key=0);
|
||||
|
||||
//- Construct from Istream
|
||||
inline Keyed(Istream&);
|
||||
inline Keyed(Istream& is);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
@ -25,8 +25,6 @@ License
|
||||
|
||||
#include "IOstreams.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
@ -45,9 +43,9 @@ inline Foam::Keyed<T>::Keyed(const T& item, const label key)
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::Keyed<T>::Keyed(const Xfer<T>& item, const label key)
|
||||
inline Foam::Keyed<T>::Keyed(T&& item, const label key)
|
||||
:
|
||||
T(item),
|
||||
T(std::move(item)),
|
||||
key_(key)
|
||||
{}
|
||||
|
||||
@ -76,7 +74,7 @@ inline Foam::label& Foam::Keyed<T>::key()
|
||||
|
||||
template<class T>
|
||||
inline Foam::List<Foam::Keyed<T>>
|
||||
Foam::Keyed<T>::createList(const List<T>& lst, const label key)
|
||||
Foam::Keyed<T>::createList(const UList<T>& lst, const label key)
|
||||
{
|
||||
List<Keyed<T>> newList(lst.size());
|
||||
|
||||
@ -90,7 +88,7 @@ Foam::Keyed<T>::createList(const List<T>& lst, const label key)
|
||||
|
||||
template<class T>
|
||||
inline Foam::List<Foam::Keyed<T>>
|
||||
Foam::Keyed<T>::createList(const List<T>& lst, const labelUList& keys)
|
||||
Foam::Keyed<T>::createList(const UList<T>& lst, const labelUList& keys)
|
||||
{
|
||||
if (lst.size() != keys.size())
|
||||
{
|
||||
@ -141,6 +139,5 @@ inline Foam::Ostream& Foam::operator<<(Ostream& os, const Keyed<T>& item)
|
||||
return os;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -32,18 +32,22 @@ Foam::ILList<LListBase, T>::ILList(const ILList<LListBase, T>& lst)
|
||||
:
|
||||
UILList<LListBase, T>()
|
||||
{
|
||||
for
|
||||
(
|
||||
typename UILList<LListBase, T>::const_iterator iter = lst.begin();
|
||||
iter != lst.end();
|
||||
++iter
|
||||
)
|
||||
for (const auto& item : lst)
|
||||
{
|
||||
this->append(iter().clone().ptr());
|
||||
this->append(item.clone().ptr());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class LListBase, class T>
|
||||
Foam::ILList<LListBase, T>::ILList(ILList<LListBase, T>&& lst)
|
||||
:
|
||||
UILList<LListBase, T>()
|
||||
{
|
||||
LListBase::transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
template<class LListBase, class T>
|
||||
template<class CloneArg>
|
||||
Foam::ILList<LListBase, T>::ILList
|
||||
@ -54,14 +58,9 @@ Foam::ILList<LListBase, T>::ILList
|
||||
:
|
||||
UILList<LListBase, T>()
|
||||
{
|
||||
for
|
||||
(
|
||||
typename UILList<LListBase, T>::const_iterator iter = lst.begin();
|
||||
iter != lst.end();
|
||||
++iter
|
||||
)
|
||||
for (const auto& item :lst)
|
||||
{
|
||||
this->append(iter().clone(cloneArg).ptr());
|
||||
this->append(item.clone(cloneArg).ptr());
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,39 +79,38 @@ Foam::ILList<LListBase, T>::~ILList()
|
||||
template<class LListBase, class T>
|
||||
bool Foam::ILList<LListBase, T>::eraseHead()
|
||||
{
|
||||
T* tPtr;
|
||||
if ((tPtr = this->removeHead()))
|
||||
T* p = this->removeHead();
|
||||
|
||||
if (p)
|
||||
{
|
||||
delete tPtr;
|
||||
delete p;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class LListBase, class T>
|
||||
bool Foam::ILList<LListBase, T>::erase(T* p)
|
||||
bool Foam::ILList<LListBase, T>::erase(T* item)
|
||||
{
|
||||
T* tPtr;
|
||||
if ((tPtr = remove(p)))
|
||||
T* p = remove(item);
|
||||
|
||||
if (p)
|
||||
{
|
||||
delete tPtr;
|
||||
delete p;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class LListBase, class T>
|
||||
void Foam::ILList<LListBase, T>::clear()
|
||||
{
|
||||
label oldSize = this->size();
|
||||
for (label i=0; i<oldSize; ++i)
|
||||
const label len = this->size();
|
||||
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
eraseHead();
|
||||
}
|
||||
@ -136,20 +134,19 @@ void Foam::ILList<LListBase, T>::operator=(const ILList<LListBase, T>& lst)
|
||||
{
|
||||
this->clear();
|
||||
|
||||
for
|
||||
(
|
||||
typename UILList<LListBase, T>::const_iterator iter = lst.begin();
|
||||
iter != lst.end();
|
||||
++iter
|
||||
)
|
||||
for (const auto& item : lst)
|
||||
{
|
||||
this->append(iter().clone().ptr());
|
||||
this->append(item.clone().ptr());
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
|
||||
#include "ILListIO.C"
|
||||
template<class LListBase, class T>
|
||||
void Foam::ILList<LListBase, T>::operator=(ILList<LListBase, T>&& lst)
|
||||
{
|
||||
clear();
|
||||
LListBase::transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -43,17 +43,16 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
template<class LListBase, class T> class ILList;
|
||||
|
||||
template<class LListBase, class T> Istream& operator>>
|
||||
(
|
||||
Istream&,
|
||||
ILList<LListBase, T>&
|
||||
Istream& is,
|
||||
ILList<LListBase, T>& lst
|
||||
);
|
||||
|
||||
|
||||
@ -70,7 +69,7 @@ class ILList
|
||||
|
||||
//- Read from Istream using given Istream constructor class
|
||||
template<class INew>
|
||||
void read(Istream&, const INew&);
|
||||
void read(Istream& is, const INew& inew);
|
||||
|
||||
|
||||
public:
|
||||
@ -78,28 +77,30 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Null construct
|
||||
ILList()
|
||||
{}
|
||||
ILList() = default;
|
||||
|
||||
//- Construct given initial T
|
||||
ILList(T* a)
|
||||
//- Construct and insert the initial T item pointer
|
||||
explicit ILList(T* item)
|
||||
:
|
||||
UILList<LListBase, T>(a)
|
||||
UILList<LListBase, T>(item)
|
||||
{}
|
||||
|
||||
//- Construct from Istream
|
||||
ILList(Istream&);
|
||||
ILList(Istream& is);
|
||||
|
||||
//- Construct as copy
|
||||
ILList(const ILList<LListBase, T>&);
|
||||
//- Copy construct using the 'clone()' method for each element
|
||||
ILList(const ILList<LListBase, T>& lst);
|
||||
|
||||
//- Copy constructor with additional argument for clone
|
||||
//- Move construct
|
||||
ILList(ILList<LListBase, T>&& lst);
|
||||
|
||||
//- Copy constructor with additional argument for clone 'clone()'
|
||||
template<class CloneArg>
|
||||
ILList(const ILList<LListBase, T>& lst, const CloneArg& cloneArg);
|
||||
|
||||
//- Construct from Istream using given Istream constructor class
|
||||
template<class INew>
|
||||
ILList(Istream&, const INew&);
|
||||
ILList(Istream& is, const INew& inew);
|
||||
|
||||
|
||||
//- Destructor
|
||||
@ -108,35 +109,36 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Edit
|
||||
//- Remove the head element specified from the list and delete it
|
||||
bool eraseHead();
|
||||
|
||||
//- Remove the head element specified from the list and delete it
|
||||
bool eraseHead();
|
||||
//- Remove the specified element from the list and delete it
|
||||
bool erase(T* item);
|
||||
|
||||
//- Remove the specified element from the list and delete it
|
||||
bool erase(T* p);
|
||||
//- Clear the contents of the list
|
||||
void clear();
|
||||
|
||||
//- Clear the contents of the list
|
||||
void clear();
|
||||
|
||||
//- Transfer the contents of the argument into this List
|
||||
// and annul the argument list.
|
||||
void transfer(ILList<LListBase, T>&);
|
||||
//- Transfer the contents of the argument into this List
|
||||
//- and annul the argument list.
|
||||
void transfer(ILList<LListBase, T>& lst);
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
//- Assignment operator
|
||||
void operator=(const ILList<LListBase, T>&);
|
||||
//- Copy assignment using the 'clone()' method for each element
|
||||
void operator=(const ILList<LListBase, T>& lst);
|
||||
|
||||
//- Move assignment
|
||||
void operator=(ILList<LListBase, T>&& lst);
|
||||
|
||||
|
||||
// Istream operator
|
||||
|
||||
//- Read List from Istream, discarding contents of existing List.
|
||||
//- Read from Istream, discarding existing contents.
|
||||
friend Istream& operator>> <LListBase, T>
|
||||
(
|
||||
Istream&,
|
||||
ILList<LListBase, T>&
|
||||
Istream& is,
|
||||
ILList<LListBase, T>& lst
|
||||
);
|
||||
};
|
||||
|
||||
@ -149,6 +151,7 @@ public:
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "ILList.C"
|
||||
#include "ILListIO.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -31,59 +31,49 @@ License
|
||||
|
||||
template<class LListBase, class T>
|
||||
template<class INew>
|
||||
void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
|
||||
void Foam::ILList<LListBase, T>::read(Istream& is, const INew& inew)
|
||||
{
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
token firstToken(is);
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"operator>>(Istream&, ILList<LListBase, T>&) : reading first token"
|
||||
);
|
||||
is.fatalCheck("ILList::readList : reading first token");
|
||||
|
||||
if (firstToken.isLabel())
|
||||
{
|
||||
const label s = firstToken.labelToken();
|
||||
const label len = firstToken.labelToken();
|
||||
|
||||
// Read beginning of contents
|
||||
const char delimiter = is.readBeginList("ILList<LListBase, T>");
|
||||
const char delimiter = is.readBeginList("ILList");
|
||||
|
||||
if (s)
|
||||
if (len)
|
||||
{
|
||||
if (delimiter == token::BEGIN_LIST)
|
||||
{
|
||||
for (label i=0; i<s; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
this->append(iNew(is).ptr());
|
||||
T* p = inew(is).ptr();
|
||||
this->append(p);
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"operator>>(Istream&, ILList<LListBase, T>&) : "
|
||||
"reading entry"
|
||||
);
|
||||
is.fatalCheck("ILList::readList : reading entry");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
T* tPtr = iNew(is).ptr();
|
||||
this->append(tPtr);
|
||||
T* p = inew(is).ptr();
|
||||
this->append(p);
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"operator>>(Istream&, ILList<LListBase, T>&) : "
|
||||
"reading entry"
|
||||
);
|
||||
is.fatalCheck("ILList::readList : reading entry");
|
||||
|
||||
for (label i=1; i<s; ++i)
|
||||
for (label i=1; i<len; ++i)
|
||||
{
|
||||
this->append(new T(*tPtr));
|
||||
this->append(new T(*p)); // Copy construct
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read end of contents
|
||||
is.readEndList("ILList<LListBase, T>");
|
||||
is.readEndList("ILList");
|
||||
}
|
||||
else if (firstToken.isPunctuation())
|
||||
{
|
||||
@ -108,7 +98,9 @@ void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
|
||||
)
|
||||
{
|
||||
is.putBack(lastToken);
|
||||
this->append(iNew(is).ptr());
|
||||
|
||||
T* p = inew(is).ptr();
|
||||
this->append(p);
|
||||
|
||||
is >> lastToken;
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
@ -128,9 +120,9 @@ void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
|
||||
|
||||
template<class LListBase, class T>
|
||||
template<class INew>
|
||||
Foam::ILList<LListBase, T>::ILList(Istream& is, const INew& iNew)
|
||||
Foam::ILList<LListBase, T>::ILList(Istream& is, const INew& inew)
|
||||
{
|
||||
this->read(is, iNew);
|
||||
this->read(is, inew);
|
||||
}
|
||||
|
||||
|
||||
@ -144,10 +136,10 @@ Foam::ILList<LListBase, T>::ILList(Istream& is)
|
||||
// * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
|
||||
|
||||
template<class LListBase, class T>
|
||||
Foam::Istream& Foam::operator>>(Istream& is, ILList<LListBase, T>& L)
|
||||
Foam::Istream& Foam::operator>>(Istream& is, ILList<LListBase, T>& lst)
|
||||
{
|
||||
L.clear();
|
||||
L.read(is, INew<T>());
|
||||
lst.clear();
|
||||
lst.read(is, INew<T>());
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
@ -39,6 +39,15 @@ Foam::LList<LListBase, T>::LList(const LList<LListBase, T>& lst)
|
||||
}
|
||||
|
||||
|
||||
template<class LListBase, class T>
|
||||
Foam::LList<LListBase, T>::LList(LList<LListBase, T>&& lst)
|
||||
:
|
||||
LListBase()
|
||||
{
|
||||
LListBase::transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
template<class LListBase, class T>
|
||||
Foam::LList<LListBase, T>::LList(std::initializer_list<T> lst)
|
||||
:
|
||||
@ -51,6 +60,8 @@ Foam::LList<LListBase, T>::LList(std::initializer_list<T> lst)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class LListBase, class T>
|
||||
Foam::LList<LListBase, T>::~LList()
|
||||
{
|
||||
@ -63,8 +74,8 @@ Foam::LList<LListBase, T>::~LList()
|
||||
template<class LListBase, class T>
|
||||
void Foam::LList<LListBase, T>::clear()
|
||||
{
|
||||
label oldSize = this->size();
|
||||
for (label i=0; i<oldSize; ++i)
|
||||
const label len = this->size();
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
this->removeHead();
|
||||
}
|
||||
@ -95,6 +106,15 @@ void Foam::LList<LListBase, T>::operator=(const LList<LListBase, T>& lst)
|
||||
}
|
||||
|
||||
|
||||
template<class LListBase, class T>
|
||||
void Foam::LList<LListBase, T>::operator=(LList<LListBase, T>&& lst)
|
||||
{
|
||||
this->clear();
|
||||
|
||||
LListBase::transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
template<class LListBase, class T>
|
||||
void Foam::LList<LListBase, T>::operator=(std::initializer_list<T> lst)
|
||||
{
|
||||
@ -107,8 +127,4 @@ void Foam::LList<LListBase, T>::operator=(std::initializer_list<T> lst)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
|
||||
#include "LListIO.C"
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -44,25 +44,25 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
template<class LListBase, class T> class LList;
|
||||
|
||||
template<class LListBase, class T>
|
||||
Istream& operator>>
|
||||
(
|
||||
Istream&,
|
||||
LList<LListBase, T>&
|
||||
Istream& is,
|
||||
LList<LListBase, T>& lst
|
||||
);
|
||||
|
||||
template<class LListBase, class T>
|
||||
Ostream& operator<<
|
||||
(
|
||||
Ostream&,
|
||||
const LList<LListBase, T>&
|
||||
Ostream& os,
|
||||
const LList<LListBase, T>& lst
|
||||
);
|
||||
|
||||
|
||||
@ -75,19 +75,42 @@ class LList
|
||||
:
|
||||
public LListBase
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// STL type definitions
|
||||
|
||||
//- Type of values stored.
|
||||
typedef T value_type;
|
||||
|
||||
//- Pointer for value_type
|
||||
typedef T* pointer;
|
||||
|
||||
//- Const pointer for value_type
|
||||
typedef const T* const_pointer;
|
||||
|
||||
//- Reference for value_type
|
||||
typedef T& reference;
|
||||
|
||||
//- Const reference for value_type
|
||||
typedef const T& const_reference;
|
||||
|
||||
//- The type that can represent the container size
|
||||
typedef label size_type;
|
||||
|
||||
//- The difference between iterator objects
|
||||
typedef label difference_type;
|
||||
|
||||
|
||||
// Forward declaration of STL iterators
|
||||
|
||||
class iterator;
|
||||
friend class iterator;
|
||||
|
||||
class const_iterator;
|
||||
friend class const_iterator;
|
||||
|
||||
using base_iterator = typename LListBase::iterator;
|
||||
using const_base_iterator = typename LListBase::const_iterator;
|
||||
|
||||
|
||||
//- Link structure
|
||||
//- The storage of T with linked nodes
|
||||
struct link
|
||||
:
|
||||
public LListBase::link
|
||||
@ -95,34 +118,73 @@ public:
|
||||
//- Stored object
|
||||
T obj_;
|
||||
|
||||
//- Construct given object
|
||||
link(T a)
|
||||
//- Copy construct from given object
|
||||
link(const T& obj)
|
||||
:
|
||||
obj_(a)
|
||||
obj_(obj)
|
||||
{}
|
||||
|
||||
//- Move construct from given object
|
||||
link(T&& obj)
|
||||
:
|
||||
obj_(std::move(obj))
|
||||
{}
|
||||
|
||||
|
||||
//- Dereference LListBase::link to obtain address of stored object
|
||||
static constexpr T* ptr(typename LListBase::link* node)
|
||||
{
|
||||
return &(static_cast<link*>(node)->obj_);
|
||||
}
|
||||
|
||||
//- Dereference LListBase::link to obtain address of stored object
|
||||
static constexpr const T* ptr(const typename LListBase::link* node)
|
||||
{
|
||||
return &(static_cast<const link*>(node)->obj_);
|
||||
}
|
||||
|
||||
//- Dereference LListBase::link to obtain the stored object
|
||||
static constexpr T& ref(typename LListBase::link* node)
|
||||
{
|
||||
return static_cast<link*>(node)->obj_;
|
||||
}
|
||||
|
||||
//- Dereference LListBase::link to obtain the stored object
|
||||
static constexpr const T& ref(const typename LListBase::link* node)
|
||||
{
|
||||
return static_cast<const link*>(node)->obj_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Null construct
|
||||
LList()
|
||||
{}
|
||||
LList() = default;
|
||||
|
||||
//- Construct given initial T
|
||||
explicit LList(T a)
|
||||
:
|
||||
LListBase(new link(a))
|
||||
{}
|
||||
//- Construct and copy insert the initial T item
|
||||
explicit LList(const T& item)
|
||||
{
|
||||
this->insert(item);
|
||||
}
|
||||
|
||||
//- Construct and move insert the initial T item
|
||||
explicit LList(T&& item)
|
||||
{
|
||||
this->insert(std::move(item));
|
||||
}
|
||||
|
||||
//- Construct from Istream
|
||||
explicit LList(Istream&);
|
||||
explicit LList(Istream& is);
|
||||
|
||||
//- Construct as copy
|
||||
LList(const LList<LListBase, T>&);
|
||||
//- Copy construct
|
||||
LList(const LList<LListBase, T>& lst);
|
||||
|
||||
//- Construct from an initializer list
|
||||
LList(std::initializer_list<T>);
|
||||
//- Move construct
|
||||
LList(LList<LListBase, T>&& lst);
|
||||
|
||||
//- Copy construct from an initializer list
|
||||
LList(std::initializer_list<T> lst);
|
||||
|
||||
|
||||
//- Destructor
|
||||
@ -131,240 +193,375 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
//- The first entry in the list
|
||||
reference first()
|
||||
{
|
||||
return link::ref(LListBase::first());
|
||||
}
|
||||
|
||||
//- Return the first entry added
|
||||
T& first()
|
||||
{
|
||||
return static_cast<link*>(LListBase::first())->obj_;
|
||||
}
|
||||
//- The first entry in the list (const access)
|
||||
const_reference first() const
|
||||
{
|
||||
return link::ref(LListBase::first());
|
||||
}
|
||||
|
||||
//- Return const access to the first entry added
|
||||
const T& first() const
|
||||
{
|
||||
return static_cast<const link*>(LListBase::first())->obj_;
|
||||
}
|
||||
//- The last entry in the list
|
||||
reference last()
|
||||
{
|
||||
return link::ref(LListBase::last());
|
||||
}
|
||||
|
||||
//- Return the last entry added
|
||||
T& last()
|
||||
{
|
||||
return static_cast<link*>(LListBase::last())->obj_;
|
||||
}
|
||||
|
||||
//- Return const access to the last entry added
|
||||
const T& last() const
|
||||
{
|
||||
return static_cast<const link*>(LListBase::last())->obj_;
|
||||
}
|
||||
//- The last entry in the list (const access)
|
||||
const_reference last() const
|
||||
{
|
||||
return link::ref(LListBase::last());
|
||||
}
|
||||
|
||||
|
||||
// Edit
|
||||
//- Add copy at head of list
|
||||
void insert(const T& item)
|
||||
{
|
||||
LListBase::insert(new link(item));
|
||||
}
|
||||
|
||||
//- Add at head of list
|
||||
void insert(const T& a)
|
||||
{
|
||||
LListBase::insert(new link(a));
|
||||
}
|
||||
//- Move construct at head of list
|
||||
void insert(T&& item)
|
||||
{
|
||||
LListBase::insert(new link(std::move(item)));
|
||||
}
|
||||
|
||||
//- Add at tail of list
|
||||
void append(const T& a)
|
||||
{
|
||||
LListBase::append(new link(a));
|
||||
}
|
||||
|
||||
//- Remove and return head
|
||||
T removeHead()
|
||||
{
|
||||
link* elmtPtr = static_cast<link*>(LListBase::removeHead());
|
||||
T data = elmtPtr->obj_;
|
||||
delete elmtPtr;
|
||||
return data;
|
||||
}
|
||||
//- Add copy at tail of list
|
||||
void append(const T& item)
|
||||
{
|
||||
LListBase::append(new link(item));
|
||||
}
|
||||
|
||||
//- Remove and return element
|
||||
T remove(link* l)
|
||||
{
|
||||
link* elmtPtr = static_cast<link*>(LListBase::remove(l));
|
||||
T data = elmtPtr->obj_;
|
||||
delete elmtPtr;
|
||||
return data;
|
||||
}
|
||||
//- Move construct at tail of list
|
||||
void append(T&& item)
|
||||
{
|
||||
LListBase::append(new link(std::move(item)));
|
||||
}
|
||||
|
||||
//- Remove and return element specified by iterator
|
||||
T remove(iterator& it)
|
||||
{
|
||||
link* elmtPtr = static_cast<link*>(LListBase::remove(it));
|
||||
T data = elmtPtr->obj_;
|
||||
delete elmtPtr;
|
||||
return data;
|
||||
}
|
||||
|
||||
//- Delete contents of list
|
||||
void clear();
|
||||
//- Remove and return head
|
||||
T removeHead()
|
||||
{
|
||||
auto p = LListBase::removeHead();
|
||||
T obj(std::move(link::ref(p)));
|
||||
delete p;
|
||||
return obj;
|
||||
}
|
||||
|
||||
//- Transfer the contents of the argument into this List
|
||||
// and annul the argument list.
|
||||
void transfer(LList<LListBase, T>&);
|
||||
//- Remove and return element
|
||||
T remove(link* item)
|
||||
{
|
||||
auto p = LListBase::remove(item);
|
||||
T obj(std::move(link::ref(p)));
|
||||
delete p;
|
||||
return obj;
|
||||
}
|
||||
|
||||
//- Remove and return element specified by iterator
|
||||
T remove(iterator& iter)
|
||||
{
|
||||
auto p = LListBase::remove(iter);
|
||||
T obj(std::move(link::ref(p)));
|
||||
delete p;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
//- Delete contents of list
|
||||
void clear();
|
||||
|
||||
//- Transfer the contents of the argument into this List
|
||||
// and annul the argument list.
|
||||
void transfer(LList<LListBase, T>& lst);
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
//- Assignment operator
|
||||
void operator=(const LList<LListBase, T>&);
|
||||
//- Copy assignment
|
||||
void operator=(const LList<LListBase, T>& lst);
|
||||
|
||||
//- Assignment to an initializer list
|
||||
void operator=(std::initializer_list<T>);
|
||||
//- Move assignment
|
||||
void operator=(LList<LListBase, T>&& lst);
|
||||
|
||||
|
||||
// STL type definitions
|
||||
|
||||
//- Type of values the LList contains.
|
||||
typedef T value_type;
|
||||
|
||||
//- Type that can be used for storing into value_type
|
||||
// objects.
|
||||
typedef T& reference;
|
||||
|
||||
//- Type that can be used for storing into constant
|
||||
// LList::value_type objects.
|
||||
typedef const T& const_reference;
|
||||
|
||||
//- The type that can represent the size of a LList.
|
||||
typedef label size_type;
|
||||
|
||||
|
||||
// STL iterator
|
||||
|
||||
typedef typename LListBase::iterator LListBase_iterator;
|
||||
|
||||
//- An STL-conforming iterator
|
||||
class iterator
|
||||
:
|
||||
public LListBase_iterator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from base iterator
|
||||
iterator(LListBase_iterator baseIter)
|
||||
:
|
||||
LListBase_iterator(baseIter)
|
||||
{}
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
T& operator*() const
|
||||
{
|
||||
return
|
||||
static_cast<link&>
|
||||
(LListBase_iterator::operator*()).obj_;
|
||||
}
|
||||
|
||||
T& operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
|
||||
iterator& operator++()
|
||||
{
|
||||
LListBase_iterator::operator++();
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
inline iterator begin()
|
||||
{
|
||||
return LListBase::begin();
|
||||
}
|
||||
|
||||
inline const iterator& end()
|
||||
{
|
||||
return static_cast<const iterator&>(LListBase::end());
|
||||
}
|
||||
|
||||
|
||||
// STL const_iterator
|
||||
|
||||
typedef typename LListBase::const_iterator LListBase_const_iterator;
|
||||
|
||||
//- An STL-conforming const_iterator
|
||||
class const_iterator
|
||||
:
|
||||
public LListBase_const_iterator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from base const_iterator
|
||||
const_iterator(LListBase_const_iterator baseIter)
|
||||
:
|
||||
LListBase_const_iterator(baseIter)
|
||||
{}
|
||||
|
||||
|
||||
//- Construct from base iterator
|
||||
const_iterator(LListBase_iterator baseIter)
|
||||
:
|
||||
LListBase_const_iterator(baseIter)
|
||||
{}
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
const T& operator*() const
|
||||
{
|
||||
return
|
||||
static_cast<const link&>
|
||||
(LListBase_const_iterator::operator*()).obj_;
|
||||
}
|
||||
|
||||
const T& operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
|
||||
const_iterator& operator++()
|
||||
{
|
||||
LListBase_const_iterator::operator++();
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
inline const_iterator cbegin() const
|
||||
{
|
||||
return LListBase::cbegin();
|
||||
}
|
||||
|
||||
inline const const_iterator& cend() const
|
||||
{
|
||||
return static_cast<const const_iterator&>(LListBase::cend());
|
||||
}
|
||||
|
||||
inline const_iterator begin() const
|
||||
{
|
||||
return LListBase::begin();
|
||||
}
|
||||
|
||||
inline const const_iterator& end() const
|
||||
{
|
||||
return static_cast<const const_iterator&>(LListBase::end());
|
||||
}
|
||||
//- Copy assignment from an initializer list
|
||||
void operator=(std::initializer_list<T> lst);
|
||||
|
||||
|
||||
// IOstream operators
|
||||
|
||||
//- Write LList with line-breaks when its length exceeds
|
||||
//- shortListLen.
|
||||
// Using '0' suppresses line-breaks entirely.
|
||||
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
|
||||
|
||||
//- Read list from Istream
|
||||
friend Istream& operator>> <LListBase, T>
|
||||
(
|
||||
Istream&,
|
||||
LList<LListBase, T>&
|
||||
LList<LListBase, T>& lst
|
||||
);
|
||||
|
||||
//- Write LList to Ostream with line breaks,
|
||||
//- as per writeList() with shortListLen=-1
|
||||
friend Ostream& operator<< <LListBase, T>
|
||||
(
|
||||
Ostream&,
|
||||
const LList<LListBase, T>&
|
||||
Ostream& os,
|
||||
const LList<LListBase, T>& lst
|
||||
);
|
||||
|
||||
|
||||
// STL iterator
|
||||
|
||||
//- An STL-conforming iterator
|
||||
class iterator
|
||||
:
|
||||
public base_iterator
|
||||
{
|
||||
public:
|
||||
|
||||
//- Construct from base iterator
|
||||
iterator(base_iterator iter)
|
||||
:
|
||||
base_iterator(iter)
|
||||
{}
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
return link::ref(this->get_node());
|
||||
}
|
||||
|
||||
pointer operator->() const
|
||||
{
|
||||
return link::ptr(this->get_node());
|
||||
}
|
||||
|
||||
reference operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
|
||||
iterator& operator++()
|
||||
{
|
||||
this->next();
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator& operator--()
|
||||
{
|
||||
this->prev(); // May not be implemented
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// STL const_iterator
|
||||
|
||||
//- An STL-conforming const_iterator
|
||||
class const_iterator
|
||||
:
|
||||
public const_base_iterator
|
||||
{
|
||||
public:
|
||||
|
||||
//- Construct from base iterator
|
||||
const_iterator(const_base_iterator iter)
|
||||
:
|
||||
const_base_iterator(iter)
|
||||
{}
|
||||
|
||||
//- Construct from base iterator
|
||||
const_iterator(base_iterator iter)
|
||||
:
|
||||
const_base_iterator(iter)
|
||||
{}
|
||||
|
||||
const_reference operator*() const
|
||||
{
|
||||
return link::ref(this->get_node());
|
||||
}
|
||||
|
||||
const_pointer operator->() const
|
||||
{
|
||||
return link::ptr(this->get_node());
|
||||
}
|
||||
|
||||
const_reference operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
|
||||
const_iterator& operator++()
|
||||
{
|
||||
this->next();
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_iterator& operator--()
|
||||
{
|
||||
this->prev(); // May not be implemented
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// STL reverse_iterator
|
||||
|
||||
//- A reverse_iterator, for LListBase classes that support
|
||||
//- reverse iteration
|
||||
class reverse_iterator
|
||||
:
|
||||
public base_iterator
|
||||
{
|
||||
public:
|
||||
|
||||
//- Construct from base iterator
|
||||
reverse_iterator(base_iterator iter)
|
||||
:
|
||||
base_iterator(iter)
|
||||
{}
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
return link::ref(this->get_node());
|
||||
}
|
||||
|
||||
pointer operator->() const
|
||||
{
|
||||
return link::ptr(this->get_node());
|
||||
}
|
||||
|
||||
reverse_iterator& operator++()
|
||||
{
|
||||
this->prev(); // Only if base iterator is bidirectional
|
||||
return *this;
|
||||
}
|
||||
|
||||
reverse_iterator& operator--()
|
||||
{
|
||||
this->next();
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// STL const_reverse_iterator
|
||||
|
||||
//- A const_reverse_iterator, for LListBase classes that support
|
||||
//- reverse iteration
|
||||
class const_reverse_iterator
|
||||
:
|
||||
public const_base_iterator
|
||||
{
|
||||
public:
|
||||
|
||||
//- Construct from base iterator
|
||||
const_reverse_iterator(const_base_iterator iter)
|
||||
:
|
||||
const_base_iterator(iter)
|
||||
{}
|
||||
|
||||
const_reference operator*() const
|
||||
{
|
||||
return link::ref(this->get_node());
|
||||
}
|
||||
|
||||
const_pointer operator->() const
|
||||
{
|
||||
return link::ptr(this->get_node());
|
||||
}
|
||||
|
||||
const_reverse_iterator& operator++()
|
||||
{
|
||||
this->prev(); // Only if base iterator is bidirectional
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_reverse_iterator& operator--()
|
||||
{
|
||||
this->next();
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//- Iterator to first item in list with non-const access
|
||||
inline iterator begin()
|
||||
{
|
||||
return LListBase::template iterator_first<base_iterator>();
|
||||
}
|
||||
|
||||
//- Iterator to first item in list with const access
|
||||
inline const_iterator cbegin() const
|
||||
{
|
||||
return LListBase::template iterator_first<const_base_iterator>();
|
||||
}
|
||||
|
||||
//- Iterator to last item in list with non-const access
|
||||
inline reverse_iterator rbegin()
|
||||
{
|
||||
return LListBase::template iterator_last<base_iterator>();
|
||||
}
|
||||
|
||||
//- Iterator to last item in list with const access
|
||||
inline const_reverse_iterator crbegin() const
|
||||
{
|
||||
return LListBase::template iterator_last<const_base_iterator>();
|
||||
}
|
||||
|
||||
//- Iterator to first item in list with const access
|
||||
inline const_iterator begin() const
|
||||
{
|
||||
return LListBase::cbegin();
|
||||
}
|
||||
|
||||
//- Iterator to last item in list with const access
|
||||
inline const_reverse_iterator rbegin() const
|
||||
{
|
||||
return crbegin();
|
||||
}
|
||||
|
||||
|
||||
//- End of list for forward iterators
|
||||
inline const iterator& end()
|
||||
{
|
||||
return LListBase::template iterator_end<iterator>();
|
||||
}
|
||||
|
||||
//- End of list for forward iterators
|
||||
inline const const_iterator& cend() const
|
||||
{
|
||||
return LListBase::template iterator_end<const_iterator>();
|
||||
}
|
||||
|
||||
//- End of list for reverse iterators
|
||||
inline const reverse_iterator& rend()
|
||||
{
|
||||
return LListBase::template iterator_rend<reverse_iterator>();
|
||||
}
|
||||
|
||||
//- End of list for reverse iterators
|
||||
inline const const_reverse_iterator& crend() const
|
||||
{
|
||||
return LListBase::template iterator_rend<const_reverse_iterator>();
|
||||
}
|
||||
|
||||
//- End of list for forward iterators
|
||||
inline const const_iterator& end() const
|
||||
{
|
||||
return cend();
|
||||
}
|
||||
|
||||
//- End of list for reverse iterators
|
||||
inline const const_reverse_iterator& rend() const
|
||||
{
|
||||
return crend();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -376,6 +573,7 @@ public:
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "LList.C"
|
||||
#include "LListIO.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -36,39 +36,36 @@ Foam::LList<LListBase, T>::LList(Istream& is)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
template<class LListBase, class T>
|
||||
Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
|
||||
Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& lst)
|
||||
{
|
||||
// Anull list
|
||||
L.clear();
|
||||
lst.clear();
|
||||
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
token firstToken(is);
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
" operator>>(Istream&, LList<LListBase, T>&) : reading first token"
|
||||
);
|
||||
is.fatalCheck("LList::readList : reading first token");
|
||||
|
||||
if (firstToken.isLabel())
|
||||
{
|
||||
const label s = firstToken.labelToken();
|
||||
const label len = firstToken.labelToken();
|
||||
|
||||
// Read beginning of contents
|
||||
const char delimiter = is.readBeginList("LList<LListBase, T>");
|
||||
const char delimiter = is.readBeginList("LList");
|
||||
|
||||
if (s)
|
||||
if (len)
|
||||
{
|
||||
if (delimiter == token::BEGIN_LIST)
|
||||
{
|
||||
for (label i=0; i<s; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
T element;
|
||||
is >> element;
|
||||
L.append(element);
|
||||
lst.append(element);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -76,9 +73,9 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
|
||||
T element;
|
||||
is >> element;
|
||||
|
||||
for (label i=0; i<s; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
L.append(element);
|
||||
lst.append(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -109,9 +106,10 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
|
||||
)
|
||||
{
|
||||
is.putBack(lastToken);
|
||||
|
||||
T element;
|
||||
is >> element;
|
||||
L.append(element);
|
||||
lst.append(element);
|
||||
|
||||
is >> lastToken;
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
@ -125,36 +123,66 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
// Check state of IOstream
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
||||
|
||||
template<class LListBase, class T>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const LList<LListBase, T>& lst)
|
||||
Foam::Ostream& Foam::LList<LListBase, T>::writeList
|
||||
(
|
||||
Ostream& os,
|
||||
const label shortListLen
|
||||
) const
|
||||
{
|
||||
// Write size
|
||||
os << nl << lst.size();
|
||||
const label len = this->size();
|
||||
|
||||
// Write beginning of contents
|
||||
os << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
// Write contents
|
||||
for (const T& val : lst)
|
||||
if
|
||||
(
|
||||
len <= 1 || !shortListLen
|
||||
|| (len <= shortListLen)
|
||||
)
|
||||
{
|
||||
os << val << nl;
|
||||
}
|
||||
// Size and start delimiter
|
||||
os << len << token::BEGIN_LIST;
|
||||
|
||||
// Write end of contents
|
||||
os << token::END_LIST;
|
||||
// Contents
|
||||
bool space = false;
|
||||
for (const T& val : *this)
|
||||
{
|
||||
if (space) os << token::SPACE;
|
||||
os << val;
|
||||
space = true;
|
||||
}
|
||||
|
||||
// End delimiter
|
||||
os << token::END_LIST;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Size and start delimiter
|
||||
os << nl << len << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
// Contents
|
||||
for (const T& val : *this)
|
||||
{
|
||||
os << val << nl;
|
||||
}
|
||||
|
||||
// End delimiter
|
||||
os << token::END_LIST;
|
||||
}
|
||||
|
||||
os.check(FUNCTION_NAME);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
template<class LListBase, class T>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const LList<LListBase, T>& lst)
|
||||
{
|
||||
return lst.writeList(os, -1); // always with line breaks
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -32,13 +32,22 @@ Foam::LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& lst)
|
||||
:
|
||||
LList<LListBase, T*>()
|
||||
{
|
||||
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
|
||||
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
|
||||
{
|
||||
this->append(iter().clone().ptr());
|
||||
this->append((*iter).clone().ptr());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class LListBase, class T>
|
||||
Foam::LPtrList<LListBase, T>::LPtrList(LPtrList<LListBase, T>&& lst)
|
||||
:
|
||||
LList<LListBase, T*>()
|
||||
{
|
||||
LList<LListBase, T*>::transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class LListBase, class T>
|
||||
@ -53,24 +62,23 @@ Foam::LPtrList<LListBase, T>::~LPtrList()
|
||||
template<class LListBase, class T>
|
||||
bool Foam::LPtrList<LListBase, T>::eraseHead()
|
||||
{
|
||||
T* tPtr;
|
||||
if ((tPtr = this->removeHead()))
|
||||
T* p = this->removeHead();
|
||||
|
||||
if (p)
|
||||
{
|
||||
delete tPtr;
|
||||
delete p;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class LListBase, class T>
|
||||
void Foam::LPtrList<LListBase, T>::clear()
|
||||
{
|
||||
const label oldSize = this->size();
|
||||
for (label i=0; i<oldSize; ++i)
|
||||
const label len = this->size();
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
eraseHead();
|
||||
}
|
||||
@ -94,16 +102,18 @@ void Foam::LPtrList<LListBase, T>::operator=(const LPtrList<LListBase, T>& lst)
|
||||
{
|
||||
clear();
|
||||
|
||||
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
|
||||
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
|
||||
{
|
||||
this->append(iter().clone().ptr());
|
||||
this->append((*iter).clone().ptr());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
|
||||
#include "LPtrListIO.C"
|
||||
template<class LListBase, class T>
|
||||
void Foam::LPtrList<LListBase, T>::operator=(LPtrList<LListBase, T>&& lst)
|
||||
{
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -43,22 +43,22 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
// Forward declarations
|
||||
|
||||
template<class LListBase, class T> class LPtrList;
|
||||
|
||||
template<class LListBase, class T>
|
||||
Istream& operator>>
|
||||
(
|
||||
Istream&,
|
||||
LPtrList<LListBase, T>&
|
||||
Istream& is,
|
||||
LPtrList<LListBase, T>& lst
|
||||
);
|
||||
|
||||
template<class LListBase, class T>
|
||||
Ostream& operator<<
|
||||
(
|
||||
Ostream&,
|
||||
const LPtrList<LListBase, T>&
|
||||
Ostream& os,
|
||||
const LPtrList<LListBase, T>& lst
|
||||
);
|
||||
|
||||
|
||||
@ -71,45 +71,67 @@ class LPtrList
|
||||
:
|
||||
public LList<LListBase, T*>
|
||||
{
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Read from Istream using given Istream constructor class
|
||||
template<class INew>
|
||||
void read(Istream&, const INew&);
|
||||
void read(Istream& is, const INew& inew);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// STL type definitions
|
||||
|
||||
//- Pointer for LPtrList::value_type objects.
|
||||
typedef T* pointer;
|
||||
|
||||
//- Const pointer for LPtrList::value_type objects.
|
||||
typedef const T* const_pointer;
|
||||
|
||||
//- Reference for LPtrList::value_type objects.
|
||||
typedef T& reference;
|
||||
|
||||
//- Const reference for LPtrList::value_type objects.
|
||||
typedef const T& const_reference;
|
||||
|
||||
|
||||
// Forward declaration of STL iterators
|
||||
|
||||
class iterator;
|
||||
friend class iterator;
|
||||
|
||||
class const_iterator;
|
||||
friend class const_iterator;
|
||||
|
||||
using base_iterator = typename LListBase::iterator;
|
||||
using const_base_iterator = typename LListBase::const_iterator;
|
||||
|
||||
//- The parent list storage
|
||||
typedef LList<LListBase, T*> parent_type;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Null construct
|
||||
LPtrList()
|
||||
{}
|
||||
LPtrList() = default;
|
||||
|
||||
//- Construct given initial T
|
||||
LPtrList(T* a)
|
||||
:
|
||||
LList<LListBase, T*>(a)
|
||||
{}
|
||||
//- Construct and insert the initial T item
|
||||
explicit LPtrList(T* item)
|
||||
{
|
||||
this->insert(item);
|
||||
}
|
||||
|
||||
//- Copy construct by using 'clone()' for each element
|
||||
LPtrList(const LPtrList& lst);
|
||||
|
||||
//- Move construct
|
||||
LPtrList(LPtrList&& lst);
|
||||
|
||||
//- Construct from Istream using given Istream constructor class
|
||||
template<class INew>
|
||||
LPtrList(Istream&, const INew&);
|
||||
LPtrList(Istream& is, const INew& inew);
|
||||
|
||||
//- Construct from Istream using default Istream constructor class
|
||||
LPtrList(Istream&);
|
||||
|
||||
//- Construct as copy
|
||||
LPtrList(const LPtrList&);
|
||||
LPtrList(Istream& is);
|
||||
|
||||
|
||||
//- Destructor
|
||||
@ -118,147 +140,292 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
//- The first entry in the list
|
||||
T& first()
|
||||
{
|
||||
return *(parent_type::first());
|
||||
}
|
||||
|
||||
//- Return the first entry added
|
||||
T& first()
|
||||
{
|
||||
return *LList<LListBase, T*>::first();
|
||||
}
|
||||
//- The first entry in the list (const access)
|
||||
const T& first() const
|
||||
{
|
||||
return *(parent_type::first());
|
||||
}
|
||||
|
||||
//- Return const access to the first entry added
|
||||
const T& first() const
|
||||
{
|
||||
return *LList<LListBase, T*>::first();
|
||||
}
|
||||
//- The last entry in the list
|
||||
T& last()
|
||||
{
|
||||
return *(parent_type::last());
|
||||
}
|
||||
|
||||
//- Return the last entry added
|
||||
T& last()
|
||||
{
|
||||
return *LList<LListBase, T*>::last();
|
||||
}
|
||||
|
||||
//- Return const access to the last entry added
|
||||
const T& last() const
|
||||
{
|
||||
return *LList<LListBase, T*>::last();
|
||||
}
|
||||
//- The last entry in the list (const access)
|
||||
const T& last() const
|
||||
{
|
||||
return *(parent_type::last());
|
||||
}
|
||||
|
||||
|
||||
// Edit
|
||||
//- Remove the head element from the list and delete the pointer
|
||||
bool eraseHead();
|
||||
|
||||
//- Remove the head element from the list and delete the pointer
|
||||
bool eraseHead();
|
||||
//- Clear the contents of the list
|
||||
void clear();
|
||||
|
||||
//- Clear the contents of the list
|
||||
void clear();
|
||||
|
||||
//- Transfer the contents of the argument into this List
|
||||
// and annul the argument list.
|
||||
void transfer(LPtrList<LListBase, T>&);
|
||||
//- Transfer the contents of the argument into this List
|
||||
//- and annul the argument list.
|
||||
void transfer(LPtrList<LListBase, T>& lst);
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
//- Assign copy
|
||||
void operator=(const LPtrList<LListBase, T>&);
|
||||
//- Copy assign by using 'clone()' for each element
|
||||
void operator=(const LPtrList<LListBase, T>& lst);
|
||||
|
||||
|
||||
// STL type definitions
|
||||
|
||||
//- Type that can be used for storing into LPtrList::value_type
|
||||
// objects.
|
||||
typedef T& reference;
|
||||
|
||||
//- Type that can be used for storing into constant
|
||||
// LPtrList::value_type objects.
|
||||
typedef T& const_reference;
|
||||
//- Move assign
|
||||
void operator=(LPtrList<LListBase, T>&& lst);
|
||||
|
||||
|
||||
// STL iterator
|
||||
|
||||
typedef typename LListBase::iterator LListBase_iterator;
|
||||
|
||||
//- An STL-conforming iterator
|
||||
class iterator
|
||||
:
|
||||
public LList<LListBase, T*>::iterator
|
||||
public parent_type::iterator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from base iterator
|
||||
iterator(LListBase_iterator baseIter)
|
||||
iterator(base_iterator iter)
|
||||
:
|
||||
LList<LListBase, T*>::iterator(baseIter)
|
||||
parent_type::iterator(iter)
|
||||
{}
|
||||
|
||||
//- Return the address of the object being referenced
|
||||
pointer get() const
|
||||
{
|
||||
return parent_type::iterator::operator*();
|
||||
}
|
||||
|
||||
// Member operators
|
||||
reference operator*() const
|
||||
{
|
||||
return *(this->get());
|
||||
}
|
||||
|
||||
T& operator*() const
|
||||
{
|
||||
return *(LList<LListBase, T*>::iterator::operator*());
|
||||
}
|
||||
pointer operator->() const
|
||||
{
|
||||
return this->get();
|
||||
}
|
||||
|
||||
T& operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
reference operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// STL const_iterator
|
||||
|
||||
typedef typename LListBase::const_iterator LListBase_const_iterator;
|
||||
|
||||
//- An STL-conforming const_iterator
|
||||
class const_iterator
|
||||
:
|
||||
public LList<LListBase, T*>::const_iterator
|
||||
public parent_type::const_iterator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from base const_iterator
|
||||
const_iterator(LListBase_const_iterator baseIter)
|
||||
const_iterator(const_base_iterator iter)
|
||||
:
|
||||
LList<LListBase, T*>::const_iterator(baseIter)
|
||||
parent_type::const_iterator(iter)
|
||||
{}
|
||||
|
||||
//- Construct from base iterator
|
||||
const_iterator(LListBase_iterator baseIter)
|
||||
const_iterator(base_iterator iter)
|
||||
:
|
||||
LList<LListBase, T*>::const_iterator(baseIter)
|
||||
parent_type::const_iterator(iter)
|
||||
{}
|
||||
|
||||
//- Return the address of the object being referenced
|
||||
const_pointer get() const
|
||||
{
|
||||
return parent_type::const_iterator::operator*();
|
||||
}
|
||||
|
||||
// Member operators
|
||||
const_reference operator*() const
|
||||
{
|
||||
return *(this->get());
|
||||
}
|
||||
|
||||
const T& operator*() const
|
||||
{
|
||||
return *(LList<LListBase, T*>::const_iterator::operator*());
|
||||
}
|
||||
const_pointer operator->() const
|
||||
{
|
||||
return this->get();
|
||||
}
|
||||
|
||||
const T& operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
const_reference operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// STL reverse_iterator
|
||||
|
||||
//- A reverse_iterator, for base classes that support
|
||||
//- reverse iteration
|
||||
class reverse_iterator
|
||||
:
|
||||
public parent_type::reverse_iterator
|
||||
{
|
||||
public:
|
||||
|
||||
reverse_iterator(base_iterator iter)
|
||||
:
|
||||
parent_type::reverse_iterator(iter)
|
||||
{}
|
||||
|
||||
//- Return the address of the object being referenced
|
||||
pointer get() const
|
||||
{
|
||||
return parent_type::reverse_iterator::operator*();
|
||||
}
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
return *(this->get());
|
||||
}
|
||||
|
||||
pointer operator->() const
|
||||
{
|
||||
return this->get();
|
||||
}
|
||||
|
||||
reference operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// STL const_reverse_iterator
|
||||
|
||||
//- A const_reverse_iterator, for base classes that support
|
||||
//- reverse iteration
|
||||
class const_reverse_iterator
|
||||
:
|
||||
public parent_type::const_reverse_iterator
|
||||
{
|
||||
public:
|
||||
|
||||
const_reverse_iterator(const_base_iterator iter)
|
||||
:
|
||||
parent_type::const_reverse_iterator(iter)
|
||||
{}
|
||||
|
||||
//- Return the address of the object being referenced
|
||||
const_pointer get() const
|
||||
{
|
||||
return parent_type::const_reverse_iterator::operator*();
|
||||
}
|
||||
|
||||
const_reference operator*() const
|
||||
{
|
||||
return *(this->get());
|
||||
}
|
||||
|
||||
const_pointer operator->() const
|
||||
{
|
||||
return this->get();
|
||||
}
|
||||
|
||||
const_reference operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//- Iterator to first item in list with non-const access
|
||||
inline iterator begin()
|
||||
{
|
||||
return LListBase::template iterator_first<base_iterator>();
|
||||
}
|
||||
|
||||
//- Iterator to first item in list with const access
|
||||
inline const_iterator cbegin() const
|
||||
{
|
||||
return LListBase::template iterator_first<const_base_iterator>();
|
||||
}
|
||||
|
||||
//- Iterator to last item in list with non-const access
|
||||
inline reverse_iterator rbegin()
|
||||
{
|
||||
return LListBase::template iterator_last<base_iterator>();
|
||||
}
|
||||
|
||||
//- Iterator to last item in list with const access
|
||||
inline const_reverse_iterator crbegin() const
|
||||
{
|
||||
return LListBase::template iterator_last<const_base_iterator>();
|
||||
}
|
||||
|
||||
//- Iterator to first item in list with const access
|
||||
inline const_iterator begin() const
|
||||
{
|
||||
return LListBase::cbegin();
|
||||
}
|
||||
|
||||
//- Iterator to last item in list with const access
|
||||
inline const_reverse_iterator rbegin() const
|
||||
{
|
||||
return crbegin();
|
||||
}
|
||||
|
||||
|
||||
//- End of list for forward iterators
|
||||
inline const iterator& end()
|
||||
{
|
||||
return LListBase::template iterator_end<iterator>();
|
||||
}
|
||||
|
||||
//- End of list for forward iterators
|
||||
inline const const_iterator& cend() const
|
||||
{
|
||||
return LListBase::template iterator_end<const_iterator>();
|
||||
}
|
||||
|
||||
//- End of list for reverse iterators
|
||||
inline const reverse_iterator& rend()
|
||||
{
|
||||
return LListBase::template iterator_rend<reverse_iterator>();
|
||||
}
|
||||
|
||||
//- End of list for reverse iterators
|
||||
inline const const_reverse_iterator& crend() const
|
||||
{
|
||||
return LListBase::template iterator_rend<const_reverse_iterator>();
|
||||
}
|
||||
|
||||
//- End of list for forward iterators
|
||||
inline const const_iterator& end() const
|
||||
{
|
||||
return cend();
|
||||
}
|
||||
|
||||
//- End of list for reverse iterators
|
||||
inline const const_reverse_iterator& rend() const
|
||||
{
|
||||
return crend();
|
||||
}
|
||||
|
||||
|
||||
// IOstream operators
|
||||
|
||||
friend Istream& operator>> <LListBase, T>
|
||||
(
|
||||
Istream&,
|
||||
LPtrList<LListBase, T>&
|
||||
Istream& is,
|
||||
LPtrList<LListBase, T>& lst
|
||||
);
|
||||
|
||||
friend Ostream& operator<< <LListBase, T>
|
||||
(
|
||||
Ostream&,
|
||||
const LPtrList<LListBase, T>&
|
||||
Ostream& os,
|
||||
const LPtrList<LListBase, T>& lst
|
||||
);
|
||||
};
|
||||
|
||||
@ -271,6 +438,7 @@ public:
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "LPtrList.C"
|
||||
#include "LPtrListIO.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -32,60 +32,49 @@ License
|
||||
|
||||
template<class LListBase, class T>
|
||||
template<class INew>
|
||||
void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
|
||||
void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& inew)
|
||||
{
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
token firstToken(is);
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"LPtrList<LListBase, T>::read(Istream&, const INew&) : "
|
||||
"reading first token"
|
||||
);
|
||||
is.fatalCheck("LPtrList::readList : reading first token");
|
||||
|
||||
if (firstToken.isLabel())
|
||||
{
|
||||
const label s = firstToken.labelToken();
|
||||
const label len = firstToken.labelToken();
|
||||
|
||||
// Read beginning of contents
|
||||
const char delimiter = is.readBeginList("LPtrList<LListBase, T>");
|
||||
const char delimiter = is.readBeginList("LPtrList");
|
||||
|
||||
if (s)
|
||||
if (len)
|
||||
{
|
||||
if (delimiter == token::BEGIN_LIST)
|
||||
{
|
||||
for (label i=0; i<s; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
this->append(iNew(is).ptr());
|
||||
T* p = inew(is).ptr();
|
||||
this->append(p);
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"LPtrList<LListBase, T>::read(Istream&, const INew&) : "
|
||||
"reading entry"
|
||||
);
|
||||
is.fatalCheck("LPtrList::readList : reading entry");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
T* tPtr = iNew(is).ptr();
|
||||
this->append(tPtr);
|
||||
T* p = inew(is).ptr();
|
||||
this->append(p);
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"LPtrList<LListBase, T>::read(Istream&, const INew&) : "
|
||||
"reading entry"
|
||||
);
|
||||
is.fatalCheck("LPtrList::readList : reading entry");
|
||||
|
||||
for (label i=1; i<s; ++i)
|
||||
for (label i=1; i<len; ++i)
|
||||
{
|
||||
this->append(tPtr->clone().ptr());
|
||||
this->append(p->clone().ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read end of contents
|
||||
is.readEndList("LPtrList<LListBase, T>");
|
||||
is.readEndList("LPtrList");
|
||||
}
|
||||
else if (firstToken.isPunctuation())
|
||||
{
|
||||
@ -110,7 +99,7 @@ void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
|
||||
)
|
||||
{
|
||||
is.putBack(lastToken);
|
||||
this->append(iNew(is).ptr());
|
||||
this->append(inew(is).ptr());
|
||||
|
||||
is >> lastToken;
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
@ -134,9 +123,9 @@ void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
|
||||
|
||||
template<class LListBase, class T>
|
||||
template<class INew>
|
||||
Foam::LPtrList<LListBase, T>::LPtrList(Istream& is, const INew& iNew)
|
||||
Foam::LPtrList<LListBase, T>::LPtrList(Istream& is, const INew& inew)
|
||||
{
|
||||
this->read(is, iNew);
|
||||
this->read(is, inew);
|
||||
}
|
||||
|
||||
|
||||
@ -164,24 +153,16 @@ Foam::Istream& Foam::operator>>(Istream& is, LPtrList<LListBase, T>& L)
|
||||
template<class LListBase, class T>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const LPtrList<LListBase, T>& lst)
|
||||
{
|
||||
// Write size
|
||||
os << nl << lst.size();
|
||||
// Size and start delimiter
|
||||
os << nl << lst.size() << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
// Write beginning of contents
|
||||
os << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
// Write contents
|
||||
for
|
||||
(
|
||||
typename LPtrList<LListBase, T>::const_iterator iter = lst.begin();
|
||||
iter != lst.end();
|
||||
++iter
|
||||
)
|
||||
// Contents
|
||||
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
|
||||
{
|
||||
os << iter() << nl;
|
||||
os << *iter << nl;
|
||||
}
|
||||
|
||||
// Write end of contents
|
||||
// End delimiter
|
||||
os << token::END_LIST;
|
||||
|
||||
os.check(FUNCTION_NAME);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -30,9 +30,9 @@ License
|
||||
template<class LListBase, class T>
|
||||
Foam::UILList<LListBase, T>::UILList(const UILList<LListBase, T>& lst)
|
||||
{
|
||||
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
|
||||
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
|
||||
{
|
||||
this->append(&iter());
|
||||
this->append(&(*iter));
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,13 +40,13 @@ Foam::UILList<LListBase, T>::UILList(const UILList<LListBase, T>& lst)
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class LListBase, class T>
|
||||
void Foam::UILList<LListBase, T>::operator=(const UILList<LListBase, T>& rhs)
|
||||
void Foam::UILList<LListBase, T>::operator=(const UILList<LListBase, T>& lst)
|
||||
{
|
||||
LListBase::clear();
|
||||
|
||||
for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter)
|
||||
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
|
||||
{
|
||||
this->append(&iter());
|
||||
this->append(&(*iter));
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,22 +57,22 @@ bool Foam::UILList<LListBase, T>::operator==
|
||||
const UILList<LListBase, T>& rhs
|
||||
) const
|
||||
{
|
||||
bool equal = (this->size() == rhs.size());
|
||||
if (!equal)
|
||||
if (this->size() != rhs.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const_iterator iter1 = this->begin();
|
||||
const_iterator iter2 = rhs.begin();
|
||||
auto iter2 = rhs.cbegin();
|
||||
|
||||
for (; iter1 != this->end(); ++iter1, ++iter2)
|
||||
for (auto iter1 = this->cbegin(); iter1 != this->cend(); ++iter1, ++iter2)
|
||||
{
|
||||
equal = (iter1() == iter2());
|
||||
if (!equal) break;
|
||||
if (!(*iter1 == *iter2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return equal;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -86,9 +86,4 @@ bool Foam::UILList<LListBase, T>::operator!=
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
|
||||
#include "UILListIO.C"
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -44,18 +44,17 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
|
||||
class Ostream;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
template<class LListBase, class T>
|
||||
class UILList;
|
||||
template<class LListBase, class T> class UILList;
|
||||
|
||||
template<class LListBase, class T>
|
||||
Ostream& operator<<
|
||||
(
|
||||
Ostream&,
|
||||
const UILList<LListBase, T>&
|
||||
Ostream& os,
|
||||
const UILList<LListBase, T>& lst
|
||||
);
|
||||
|
||||
|
||||
@ -68,308 +67,385 @@ class UILList
|
||||
:
|
||||
public LListBase
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// STL type definitions
|
||||
|
||||
//- Type of values stored
|
||||
typedef T value_type;
|
||||
|
||||
//- Pointer for value_type
|
||||
typedef T* pointer;
|
||||
|
||||
//- Const pointer for value_type
|
||||
typedef const T* const_pointer;
|
||||
|
||||
//- Reference for value_type
|
||||
typedef T& reference;
|
||||
|
||||
//- Const reference for value_type
|
||||
typedef const T& const_reference;
|
||||
|
||||
//- The type that can represent the container size
|
||||
typedef label size_type;
|
||||
|
||||
//- The difference between iterator objects
|
||||
typedef label difference_type;
|
||||
|
||||
|
||||
// Forward declaration of STL iterators
|
||||
|
||||
class iterator;
|
||||
friend class iterator;
|
||||
|
||||
class const_iterator;
|
||||
friend class const_iterator;
|
||||
|
||||
class const_reverse_iterator;
|
||||
friend class const_reverse_iterator;
|
||||
using base_iterator = typename LListBase::iterator;
|
||||
using const_base_iterator = typename LListBase::const_iterator;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Null construct
|
||||
UILList()
|
||||
{}
|
||||
UILList() = default;
|
||||
|
||||
//- Construct given initial T
|
||||
UILList(T* a)
|
||||
:
|
||||
LListBase(a)
|
||||
{}
|
||||
//- Construct and insert the initial T item
|
||||
explicit UILList(T* item)
|
||||
{
|
||||
this->insert(item);
|
||||
}
|
||||
|
||||
//- Construct as copy
|
||||
UILList(const UILList<LListBase, T>&);
|
||||
UILList(const UILList<LListBase, T>& lst);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
//- The first entry in the list
|
||||
T* first()
|
||||
{
|
||||
return static_cast<T*>(LListBase::first());
|
||||
}
|
||||
|
||||
//- Return the first entry
|
||||
T* first()
|
||||
{
|
||||
return static_cast<T*>(LListBase::first());
|
||||
}
|
||||
//- The first entry in the list (const access)
|
||||
const T* first() const
|
||||
{
|
||||
return static_cast<const T*>(LListBase::first());
|
||||
}
|
||||
|
||||
//- Return the first entry
|
||||
const T* first() const
|
||||
{
|
||||
return static_cast<const T*>(LListBase::first());
|
||||
}
|
||||
//- The last entry in the list
|
||||
T* last()
|
||||
{
|
||||
return static_cast<T*>(LListBase::last());
|
||||
}
|
||||
|
||||
//- Return the last entry
|
||||
T* last()
|
||||
{
|
||||
return static_cast<T*>(LListBase::last());
|
||||
}
|
||||
|
||||
//- Return the last entry
|
||||
const T* last() const
|
||||
{
|
||||
return static_cast<const T*>(LListBase::last());
|
||||
}
|
||||
//- The last entry in the list (const access)
|
||||
const T* last() const
|
||||
{
|
||||
return static_cast<const T*>(LListBase::last());
|
||||
}
|
||||
|
||||
|
||||
// Edit
|
||||
//- Remove and return head
|
||||
T* removeHead()
|
||||
{
|
||||
return static_cast<T*>(LListBase::removeHead());
|
||||
}
|
||||
|
||||
//- Remove and return head
|
||||
T* removeHead()
|
||||
{
|
||||
return static_cast<T*>(LListBase::removeHead());
|
||||
}
|
||||
//- Remove and return element
|
||||
T* remove(T* item)
|
||||
{
|
||||
return static_cast<T*>(LListBase::remove(item));
|
||||
}
|
||||
|
||||
//- Remove and return element
|
||||
T* remove(T* p)
|
||||
{
|
||||
return static_cast<T*>(LListBase::remove(p));
|
||||
}
|
||||
|
||||
//- Remove and return specified by iterator
|
||||
T* remove(iterator& it)
|
||||
{
|
||||
return static_cast<T*>(LListBase::remove(it));
|
||||
}
|
||||
//- Remove and return item specified by iterator
|
||||
T* remove(iterator& iter)
|
||||
{
|
||||
return static_cast<T*>(LListBase::remove(iter));
|
||||
}
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
void operator=(const UILList<LListBase, T>&);
|
||||
//- Copy assignment
|
||||
void operator=(const UILList<LListBase, T>& lst);
|
||||
|
||||
//- Equality. True both lists are element-wise equal
|
||||
// (using value_type::operator==). Takes linear time.
|
||||
bool operator==(const UILList<LListBase, T>& lst) const;
|
||||
|
||||
//- The opposite of the equality operation. Takes linear time.
|
||||
bool operator!=(const UILList<LListBase, T>& lst) const;
|
||||
|
||||
|
||||
// STL type definitions
|
||||
// IOstream operators
|
||||
|
||||
//- Type of values the DLList contains.
|
||||
typedef T value_type;
|
||||
//- Write UILList with line-breaks when its length exceeds
|
||||
//- shortListLen.
|
||||
// Using '0' suppresses line-breaks entirely.
|
||||
Ostream& writeList(Ostream& os, const label shortListLen=0) const;
|
||||
|
||||
//- Type that can be used for storing into DLList::value_type
|
||||
// objects.
|
||||
typedef T& reference;
|
||||
|
||||
//- Type that can be used for storing into constant
|
||||
// DLList::value_type objects.
|
||||
typedef const T& const_reference;
|
||||
|
||||
//- The type that can represent the size of a DLList.
|
||||
typedef label size_type;
|
||||
//- Write UILList to Ostream with line breaks,
|
||||
//- as per writeList() with shortListLen=-1
|
||||
friend Ostream& operator<< <LListBase, T>
|
||||
(
|
||||
Ostream& os,
|
||||
const UILList<LListBase, T>& lst
|
||||
);
|
||||
|
||||
|
||||
// STL iterator
|
||||
|
||||
typedef typename LListBase::iterator LListBase_iterator;
|
||||
|
||||
//- An STL-conforming iterator
|
||||
//- A non-const iterator
|
||||
class iterator
|
||||
:
|
||||
public LListBase_iterator
|
||||
public base_iterator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from base iterator
|
||||
iterator(LListBase_iterator baseIter)
|
||||
iterator(base_iterator iter)
|
||||
:
|
||||
LListBase_iterator(baseIter)
|
||||
base_iterator(iter)
|
||||
{}
|
||||
|
||||
//- Return the address of the object being referenced
|
||||
pointer get() const
|
||||
{
|
||||
return static_cast<T*>(base_iterator::get_node());
|
||||
}
|
||||
|
||||
// Member operators
|
||||
reference operator*() const
|
||||
{
|
||||
return *(this->get());
|
||||
}
|
||||
|
||||
T& operator*() const
|
||||
{
|
||||
return static_cast<T&>(LListBase_iterator::operator*());
|
||||
}
|
||||
pointer operator->() const
|
||||
{
|
||||
return this->get();
|
||||
}
|
||||
|
||||
T& operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
reference operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
|
||||
iterator& operator++()
|
||||
{
|
||||
LListBase_iterator::operator++();
|
||||
return *this;
|
||||
}
|
||||
iterator& operator++()
|
||||
{
|
||||
this->next();
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
inline iterator begin()
|
||||
{
|
||||
return LListBase::begin();
|
||||
}
|
||||
|
||||
inline const iterator& end()
|
||||
{
|
||||
return static_cast<const iterator&>(LListBase::end());
|
||||
}
|
||||
|
||||
|
||||
// STL const_iterator
|
||||
|
||||
typedef typename LListBase::const_iterator LListBase_const_iterator;
|
||||
|
||||
//- An STL-conforming const_iterator
|
||||
//- A const_iterator
|
||||
class const_iterator
|
||||
:
|
||||
public LListBase_const_iterator
|
||||
public const_base_iterator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from base const_iterator
|
||||
const_iterator(LListBase_const_iterator baseIter)
|
||||
const_iterator(const_base_iterator iter)
|
||||
:
|
||||
LListBase_const_iterator(baseIter)
|
||||
const_base_iterator(iter)
|
||||
{}
|
||||
|
||||
//- Construct from base iterator
|
||||
const_iterator(LListBase_iterator baseIter)
|
||||
const_iterator(base_iterator iter)
|
||||
:
|
||||
LListBase_const_iterator(baseIter)
|
||||
const_base_iterator(iter)
|
||||
{}
|
||||
|
||||
//- Return the address of the object being referenced
|
||||
const_pointer get() const
|
||||
{
|
||||
return static_cast<const T*>(const_base_iterator::get_node());
|
||||
}
|
||||
|
||||
// Member operators
|
||||
const_reference operator*() const
|
||||
{
|
||||
return *(this->get());
|
||||
}
|
||||
|
||||
const T& operator*() const
|
||||
{
|
||||
return
|
||||
static_cast<const T&>
|
||||
(LListBase_const_iterator::operator*());
|
||||
}
|
||||
const_pointer operator->() const
|
||||
{
|
||||
return this->get();
|
||||
}
|
||||
|
||||
const T& operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
const_reference operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
|
||||
const_iterator& operator++()
|
||||
{
|
||||
LListBase_const_iterator::operator++();
|
||||
return *this;
|
||||
}
|
||||
const_iterator& operator++()
|
||||
{
|
||||
this->next();
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
inline const_iterator cbegin() const
|
||||
{
|
||||
return LListBase::cbegin();
|
||||
}
|
||||
|
||||
inline const const_iterator& cend() const
|
||||
{
|
||||
return static_cast<const const_iterator&>(LListBase::cend());
|
||||
}
|
||||
// STL reverse_iterator
|
||||
|
||||
inline const_iterator begin() const
|
||||
//- A reverse_iterator, for LListBase classes that support
|
||||
//- reverse iteration
|
||||
class reverse_iterator
|
||||
:
|
||||
public base_iterator
|
||||
{
|
||||
return LListBase::begin();
|
||||
}
|
||||
public:
|
||||
|
||||
inline const const_iterator& end() const
|
||||
{
|
||||
return static_cast<const const_iterator&>(LListBase::end());
|
||||
}
|
||||
reverse_iterator(base_iterator iter)
|
||||
:
|
||||
base_iterator(iter)
|
||||
{}
|
||||
|
||||
//- Return the address of the object being referenced
|
||||
pointer get() const
|
||||
{
|
||||
return static_cast<T*>(base_iterator::get_node());
|
||||
}
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
return *(this->get());
|
||||
}
|
||||
|
||||
pointer operator->() const
|
||||
{
|
||||
return this->get();
|
||||
}
|
||||
|
||||
reference operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
|
||||
reverse_iterator& operator++()
|
||||
{
|
||||
this->prev(); // Only if base iterator is bidirectional
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// STL const_reverse_iterator
|
||||
|
||||
//- An STL-conforming const_reverse_iterator
|
||||
//- A const_reverse_iterator, for LListBase classes that support
|
||||
//- reverse iteration
|
||||
class const_reverse_iterator
|
||||
:
|
||||
public LListBase::const_reverse_iterator
|
||||
public const_base_iterator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from base const_reverse_iterator
|
||||
const_reverse_iterator
|
||||
(
|
||||
typename LListBase::const_reverse_iterator baseIter
|
||||
)
|
||||
const_reverse_iterator(const_base_iterator iter)
|
||||
:
|
||||
LListBase::const_reverse_iterator(baseIter)
|
||||
const_base_iterator(iter)
|
||||
{}
|
||||
|
||||
//- Return the address of the object being referenced
|
||||
const_pointer get() const
|
||||
{
|
||||
return static_cast<const T*>(const_base_iterator::get_node());
|
||||
}
|
||||
|
||||
// Member operators
|
||||
const_reference operator*() const
|
||||
{
|
||||
return *(this->get());
|
||||
}
|
||||
|
||||
const T& operator*() const
|
||||
{
|
||||
return
|
||||
static_cast<const T&>
|
||||
(LListBase::const_reverse_iterator::operator*());
|
||||
}
|
||||
const_pointer operator->() const
|
||||
{
|
||||
return this->get();
|
||||
}
|
||||
|
||||
const T& operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
const_reference operator()() const
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
|
||||
const_reverse_iterator& operator++()
|
||||
{
|
||||
LListBase::const_reverse_iterator::operator++();
|
||||
return *this;
|
||||
}
|
||||
const_reverse_iterator& operator++()
|
||||
{
|
||||
this->prev(); // Only if base iterator is bidirectional
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//- Iterator to first item in list with non-const access
|
||||
inline iterator begin()
|
||||
{
|
||||
return LListBase::template iterator_first<base_iterator>();
|
||||
}
|
||||
|
||||
//- Iterator to first item in list with const access
|
||||
inline const_iterator cbegin() const
|
||||
{
|
||||
return LListBase::template iterator_first<const_base_iterator>();
|
||||
}
|
||||
|
||||
//- Iterator to last item in list with non-const access
|
||||
inline reverse_iterator rbegin()
|
||||
{
|
||||
return LListBase::template iterator_last<base_iterator>();
|
||||
}
|
||||
|
||||
//- Iterator to last item in list with const access
|
||||
inline const_reverse_iterator crbegin() const
|
||||
{
|
||||
return LListBase::crbegin();
|
||||
return LListBase::template iterator_last<const_base_iterator>();
|
||||
}
|
||||
|
||||
inline const const_reverse_iterator& crend() const
|
||||
//- Iterator to first item in list with const access
|
||||
inline const_iterator begin() const
|
||||
{
|
||||
return
|
||||
static_cast<const const_reverse_iterator&>(LListBase::crend());
|
||||
return LListBase::cbegin();
|
||||
}
|
||||
|
||||
|
||||
//- Iterator to last item in list with const access
|
||||
inline const_reverse_iterator rbegin() const
|
||||
{
|
||||
return LListBase::rbegin();
|
||||
return crbegin();
|
||||
}
|
||||
|
||||
|
||||
//- End of list for forward iterators
|
||||
inline const iterator& end()
|
||||
{
|
||||
return LListBase::template iterator_end<iterator>();
|
||||
}
|
||||
|
||||
//- End of list for forward iterators
|
||||
inline const const_iterator& cend() const
|
||||
{
|
||||
return LListBase::template iterator_end<const_iterator>();
|
||||
}
|
||||
|
||||
//- End of list for reverse iterators
|
||||
inline const reverse_iterator& rend()
|
||||
{
|
||||
return LListBase::template iterator_rend<reverse_iterator>();
|
||||
}
|
||||
|
||||
//- End of list for reverse iterators
|
||||
inline const const_reverse_iterator& crend() const
|
||||
{
|
||||
return LListBase::template iterator_rend<const_reverse_iterator>();
|
||||
}
|
||||
|
||||
//- End of list for forward iterators
|
||||
inline const const_iterator& end() const
|
||||
{
|
||||
return cend();
|
||||
}
|
||||
|
||||
//- End of list for reverse iterators
|
||||
inline const const_reverse_iterator& rend() const
|
||||
{
|
||||
return
|
||||
static_cast<const const_reverse_iterator&>(LListBase::rend());
|
||||
return crend();
|
||||
}
|
||||
|
||||
|
||||
// STL member operators
|
||||
|
||||
//- Equality operation on ULists of the same type.
|
||||
// Returns true when the ULists are element-wise equal
|
||||
// (using UList::value_type::operator==). Takes linear time.
|
||||
bool operator==(const UILList<LListBase, T>&) const;
|
||||
|
||||
//- The opposite of the equality operation. Takes linear time.
|
||||
bool operator!=(const UILList<LListBase, T>&) const;
|
||||
|
||||
|
||||
// Ostream operator
|
||||
|
||||
friend Ostream& operator<< <LListBase, T>
|
||||
(
|
||||
Ostream&,
|
||||
const UILList<LListBase, T>&
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@ -381,6 +457,7 @@ public:
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "UILList.C"
|
||||
#include "UILListIO.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -30,30 +30,61 @@ License
|
||||
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
||||
|
||||
template<class LListBase, class T>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const UILList<LListBase, T>& lst)
|
||||
Foam::Ostream& Foam::UILList<LListBase, T>::writeList
|
||||
(
|
||||
Ostream& os,
|
||||
const label shortListLen
|
||||
) const
|
||||
{
|
||||
// Write size
|
||||
os << nl << lst.size();
|
||||
const label len = this->size();
|
||||
|
||||
// Write beginning of contents
|
||||
os << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
// Write contents
|
||||
for
|
||||
if
|
||||
(
|
||||
typename UILList<LListBase, T>::const_iterator iter = lst.begin();
|
||||
iter != lst.end();
|
||||
++iter
|
||||
len <= 1 || !shortListLen
|
||||
|| (len <= shortListLen)
|
||||
)
|
||||
{
|
||||
os << iter() << nl;
|
||||
}
|
||||
// Size and start delimiter
|
||||
os << len << token::BEGIN_LIST;
|
||||
|
||||
// Write end of contents
|
||||
os << token::END_LIST;
|
||||
// Contents
|
||||
bool space = false;
|
||||
for (const T& val : *this)
|
||||
{
|
||||
if (space) os << token::SPACE;
|
||||
space = true;
|
||||
os << val;
|
||||
}
|
||||
|
||||
// End delimiter
|
||||
os << token::END_LIST;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Size and start delimiter
|
||||
os << nl << len << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
// Contents
|
||||
for (const T& val : *this)
|
||||
{
|
||||
os << val << nl;
|
||||
}
|
||||
|
||||
// End delimiter
|
||||
os << token::END_LIST;
|
||||
}
|
||||
|
||||
os.check(FUNCTION_NAME);
|
||||
return os;
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<class LListBase, class T>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const UILList<LListBase, T>& lst)
|
||||
{
|
||||
return lst.writeList(os, -1);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -23,158 +23,142 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
|
||||
#include "DLListBase.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
Foam::DLListBase::iterator Foam::DLListBase::endIter_
|
||||
(
|
||||
const_cast<DLListBase&>(static_cast<const DLListBase&>(DLListBase()))
|
||||
);
|
||||
|
||||
Foam::DLListBase::const_iterator Foam::DLListBase::endConstIter_
|
||||
(
|
||||
static_cast<const DLListBase&>(DLListBase()),
|
||||
reinterpret_cast<const link*>(0)
|
||||
);
|
||||
|
||||
Foam::DLListBase::const_reverse_iterator Foam::DLListBase::endConstRevIter_
|
||||
(
|
||||
static_cast<const DLListBase&>(DLListBase()),
|
||||
reinterpret_cast<const link*>(0)
|
||||
);
|
||||
|
||||
#include "error.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::DLListBase::insert(DLListBase::link* a)
|
||||
void Foam::DLListBase::insert(DLListBase::link* item)
|
||||
{
|
||||
nElmts_++;
|
||||
if (!item)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
++size_;
|
||||
|
||||
if (!first_)
|
||||
{
|
||||
a->prev_ = a;
|
||||
a->next_ = a;
|
||||
first_ = last_ = a;
|
||||
item->prev_ = item;
|
||||
item->next_ = item;
|
||||
first_ = last_ = item;
|
||||
}
|
||||
else
|
||||
{
|
||||
a->prev_ = a;
|
||||
a->next_ = first_;
|
||||
first_->prev_ = a;
|
||||
first_ = a;
|
||||
item->prev_ = item;
|
||||
item->next_ = first_;
|
||||
first_->prev_ = item;
|
||||
first_ = item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::DLListBase::append(DLListBase::link* a)
|
||||
void Foam::DLListBase::append(DLListBase::link* item)
|
||||
{
|
||||
nElmts_++;
|
||||
if (!item)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
++size_;
|
||||
|
||||
if (!first_)
|
||||
{
|
||||
a->prev_ = a;
|
||||
a->next_ = a;
|
||||
first_ = last_ = a;
|
||||
item->prev_ = item;
|
||||
item->next_ = item;
|
||||
first_ = last_ = item;
|
||||
}
|
||||
else
|
||||
{
|
||||
last_->next_ = a;
|
||||
a->prev_ = last_;
|
||||
a->next_ = a;
|
||||
last_ = a;
|
||||
last_->next_ = item;
|
||||
item->prev_ = last_;
|
||||
item->next_ = item;
|
||||
last_ = item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::DLListBase::swapUp(DLListBase::link* a)
|
||||
{
|
||||
if (first_ != a)
|
||||
{
|
||||
link* ap = a->prev_;
|
||||
|
||||
if (ap == first_)
|
||||
{
|
||||
first_ = a;
|
||||
ap->prev_ = a;
|
||||
}
|
||||
else
|
||||
{
|
||||
ap->prev_->next_ = a;
|
||||
}
|
||||
|
||||
if (a == last_)
|
||||
{
|
||||
last_ = ap;
|
||||
a->next_ = ap;
|
||||
}
|
||||
else
|
||||
{
|
||||
a->next_->prev_ = ap;
|
||||
}
|
||||
|
||||
a->prev_ = ap->prev_;
|
||||
ap->prev_ = a;
|
||||
|
||||
ap->next_ = a->next_;
|
||||
a->next_ = ap;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (first_ == a)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DLListBase::link *ap = a->prev_;
|
||||
|
||||
if (ap == first_)
|
||||
{
|
||||
first_ = a;
|
||||
ap->prev_ = a;
|
||||
}
|
||||
else
|
||||
{
|
||||
ap->prev_->next_ = a;
|
||||
}
|
||||
|
||||
if (a == last_)
|
||||
{
|
||||
last_ = ap;
|
||||
a->next_ = ap;
|
||||
}
|
||||
else
|
||||
{
|
||||
a->next_->prev_ = ap;
|
||||
}
|
||||
|
||||
a->prev_ = ap->prev_;
|
||||
ap->prev_ = a;
|
||||
|
||||
ap->next_ = a->next_;
|
||||
a->next_ = ap;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::DLListBase::swapDown(DLListBase::link* a)
|
||||
{
|
||||
if (last_ != a)
|
||||
{
|
||||
link* an = a->next_;
|
||||
|
||||
if (a == first_)
|
||||
{
|
||||
first_ = an;
|
||||
a->prev_ = an;
|
||||
}
|
||||
else
|
||||
{
|
||||
a->prev_->next_ = an;
|
||||
}
|
||||
|
||||
if (an == last_)
|
||||
{
|
||||
last_ = a;
|
||||
an->next_ = a;
|
||||
}
|
||||
else
|
||||
{
|
||||
an->next_->prev_ = a;
|
||||
}
|
||||
|
||||
an->prev_ = a->prev_;
|
||||
a->prev_ = an;
|
||||
|
||||
a->next_ = an->next_;
|
||||
an->next_ = a;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (last_ == a)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DLListBase::link *an = a->next_;
|
||||
|
||||
if (a == first_)
|
||||
{
|
||||
first_ = an;
|
||||
a->prev_ = an;
|
||||
}
|
||||
else
|
||||
{
|
||||
a->prev_->next_ = an;
|
||||
}
|
||||
|
||||
if (an == last_)
|
||||
{
|
||||
last_ = a;
|
||||
an->next_ = a;
|
||||
}
|
||||
else
|
||||
{
|
||||
an->next_->prev_ = a;
|
||||
}
|
||||
|
||||
an->prev_ = a->prev_;
|
||||
a->prev_ = an;
|
||||
|
||||
a->next_ = an->next_;
|
||||
an->next_ = a;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Foam::DLListBase::link* Foam::DLListBase::removeHead()
|
||||
{
|
||||
nElmts_--;
|
||||
--size_;
|
||||
|
||||
if (!first_)
|
||||
{
|
||||
@ -183,44 +167,44 @@ Foam::DLListBase::link* Foam::DLListBase::removeHead()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
DLListBase::link* f = first_;
|
||||
first_ = f->next_;
|
||||
DLListBase::link *ret = first_;
|
||||
first_ = first_->next_;
|
||||
|
||||
if (!first_)
|
||||
{
|
||||
last_ = nullptr;
|
||||
}
|
||||
|
||||
f->deregister();
|
||||
return f;
|
||||
ret->deregister();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Foam::DLListBase::link* Foam::DLListBase::remove(DLListBase::link* l)
|
||||
Foam::DLListBase::link* Foam::DLListBase::remove(DLListBase::link* item)
|
||||
{
|
||||
nElmts_--;
|
||||
--size_;
|
||||
|
||||
link* ret = l;
|
||||
DLListBase::link *ret = item;
|
||||
|
||||
if (l == first_ && first_ == last_)
|
||||
if (item == first_ && first_ == last_)
|
||||
{
|
||||
first_ = nullptr;
|
||||
last_ = nullptr;
|
||||
}
|
||||
else if (l == first_)
|
||||
else if (item == first_)
|
||||
{
|
||||
first_ = first_->next_;
|
||||
first_->prev_ = first_;
|
||||
}
|
||||
else if (l == last_)
|
||||
else if (item == last_)
|
||||
{
|
||||
last_ = last_->prev_;
|
||||
last_->next_ = last_;
|
||||
}
|
||||
else
|
||||
{
|
||||
l->next_->prev_ = l->prev_;
|
||||
l->prev_->next_ = l->next_;
|
||||
item->next_->prev_ = item->prev_;
|
||||
item->prev_->next_ = item->next_;
|
||||
}
|
||||
|
||||
ret->deregister();
|
||||
@ -234,7 +218,7 @@ Foam::DLListBase::link* Foam::DLListBase::replace
|
||||
DLListBase::link* newLink
|
||||
)
|
||||
{
|
||||
link* ret = oldLink;
|
||||
DLListBase::link *ret = oldLink;
|
||||
|
||||
newLink->prev_ = oldLink->prev_;
|
||||
newLink->next_ = oldLink->next_;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,6 +27,13 @@ Class
|
||||
Description
|
||||
Base for doubly-linked lists.
|
||||
|
||||
The iterators associated with the list only have a core functionality
|
||||
for navigation, with additional functionality to be added by inheriting
|
||||
classes. The node iterators always have a node-pointer as the
|
||||
first member data, which allows reinterpret_cast from anything else with
|
||||
a nullptr as its first data member.
|
||||
The nullObject is such an item (with a nullptr data member).
|
||||
|
||||
SourceFiles
|
||||
DLListBaseI.H
|
||||
DLListBase.C
|
||||
@ -36,9 +43,9 @@ SourceFiles
|
||||
#ifndef DLListBase_H
|
||||
#define DLListBase_H
|
||||
|
||||
#include "bool.H"
|
||||
#include "label.H"
|
||||
#include "uLabel.H"
|
||||
#include <utility>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -51,35 +58,40 @@ namespace Foam
|
||||
|
||||
class DLListBase
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Link structure
|
||||
//- The structure for a doubly-linked storage node
|
||||
struct link
|
||||
{
|
||||
//- Pointer to prev entry in list
|
||||
link* prev_ = nullptr;
|
||||
|
||||
//- Pointer to next entry in list
|
||||
link *prev_, *next_;
|
||||
link* next_ = nullptr;
|
||||
|
||||
//- Null construct
|
||||
inline link();
|
||||
link() = default;
|
||||
|
||||
//- Check if the link is registered with the DLListBase
|
||||
//- Check if the node is registered with the list
|
||||
inline bool registered() const;
|
||||
|
||||
//- Deregister the link after removal
|
||||
//- Deregister the node after removal
|
||||
inline void deregister();
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
// Private Member Data
|
||||
|
||||
//- first_ points to first element and last_ points to last element.
|
||||
link *first_, *last_;
|
||||
//- Pointer to first element
|
||||
link *first_ = nullptr;
|
||||
|
||||
//- Number of elements in in list
|
||||
label nElmts_;
|
||||
//- Pointer to last element
|
||||
link *last_ = nullptr;
|
||||
|
||||
//- Number of elements in the list
|
||||
label size_ = 0;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
@ -91,9 +103,34 @@ private:
|
||||
void operator=(const DLListBase&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Factory method to return an iterator end
|
||||
// Simply reinterprets a NullObject as a DLListBase iterator.
|
||||
template<class IteratorType>
|
||||
inline static const IteratorType& iterator_end();
|
||||
|
||||
//- Factory method to return an iterator reverse end
|
||||
// Simply reinterprets a NullObject as a DLListBase iterator.
|
||||
template<class IteratorType>
|
||||
inline static const IteratorType& iterator_rend();
|
||||
|
||||
//- Return iterator to first item or end-iterator if list is empty
|
||||
// Removes constness which the caller promises to manage.
|
||||
template<class IteratorType>
|
||||
inline IteratorType iterator_first() const;
|
||||
|
||||
//- Return iterator to last item or end-iterator if list is empty
|
||||
// Removes constness which the caller promises to manage.
|
||||
template<class IteratorType>
|
||||
inline IteratorType iterator_last() const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Forward declaration of STL iterators
|
||||
// Forward declaration of iterators
|
||||
|
||||
class iterator;
|
||||
friend class iterator;
|
||||
@ -101,213 +138,185 @@ public:
|
||||
class const_iterator;
|
||||
friend class const_iterator;
|
||||
|
||||
class const_reverse_iterator;
|
||||
friend class const_reverse_iterator;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Null construct
|
||||
inline DLListBase();
|
||||
|
||||
//- Construct given initial entry
|
||||
inline DLListBase(link*);
|
||||
DLListBase() = default;
|
||||
|
||||
|
||||
//- Destructor
|
||||
~DLListBase();
|
||||
~DLListBase() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
//- Return number of elements in list
|
||||
inline label size() const;
|
||||
|
||||
//- Return number of elements in list
|
||||
inline label size() const;
|
||||
//- Return true if the list is empty
|
||||
inline bool empty() const;
|
||||
|
||||
//- Return true if the list is empty
|
||||
inline bool empty() const;
|
||||
//- Return first entry
|
||||
inline link* first();
|
||||
|
||||
//- Return first entry
|
||||
inline link* first();
|
||||
//- Return const access to first entry
|
||||
inline const link* first() const;
|
||||
|
||||
//- Return const access to first entry
|
||||
inline const link* first() const;
|
||||
//- Return last entry
|
||||
inline link* last();
|
||||
|
||||
//- Return last entry
|
||||
inline link* last();
|
||||
|
||||
//- Return const access to last entry
|
||||
inline const link* last() const;
|
||||
//- Return const access to last entry
|
||||
inline const link* last() const;
|
||||
|
||||
|
||||
// Edit
|
||||
//- Add at head of list
|
||||
void insert(link* item);
|
||||
|
||||
//- Add at head of list
|
||||
void insert(link*);
|
||||
//- Add at tail of list
|
||||
void append(link* item);
|
||||
|
||||
//- Add at tail of list
|
||||
void append(link*);
|
||||
//- Swap this element with the one above unless it is at the top
|
||||
bool swapUp(link* item);
|
||||
|
||||
//- Swap this element with the one above unless it is at the top
|
||||
bool swapUp(link*);
|
||||
//- Swap this element with the one below unless it is at the bottom
|
||||
bool swapDown(link* item);
|
||||
|
||||
//- Swap this element with the one below unless it is at the bottom
|
||||
bool swapDown(link*);
|
||||
//- Remove and return head
|
||||
link* removeHead();
|
||||
|
||||
//- Remove and return head
|
||||
link* removeHead();
|
||||
//- Remove and return element
|
||||
link* remove(link* item);
|
||||
|
||||
//- Remove and return element
|
||||
link* remove(link*);
|
||||
// Remove and return element specified by iterator
|
||||
inline link* remove(iterator& iter);
|
||||
|
||||
// Remove and return element specified by iterator
|
||||
inline link* remove(iterator&);
|
||||
//- Replace oldLink with newLink and return element
|
||||
link* replace(link* oldLink, link* newLink);
|
||||
|
||||
//- Replace oldLink with newLink and return element
|
||||
link* replace(link* oldLink, link* newLink);
|
||||
//- Replace oldIter with newItem and return element
|
||||
inline link* replace(iterator& oldIter, link* newitem);
|
||||
|
||||
//- Replace oldIter with newLink and return element
|
||||
inline link* replace(iterator& oldIter, link* newLink);
|
||||
//- Clear the list
|
||||
inline void clear();
|
||||
|
||||
//- Clear the list
|
||||
inline void clear();
|
||||
//- Swap the contents of the list
|
||||
inline void swap(DLListBase& lst);
|
||||
|
||||
//- Transfer the contents of the argument into this List
|
||||
// and annul the argument list.
|
||||
inline void transfer(DLListBase&);
|
||||
//- Transfer the contents of the argument into this list
|
||||
//- and annul the argument list.
|
||||
inline void transfer(DLListBase& lst);
|
||||
|
||||
// STL iterator
|
||||
|
||||
//- An STL-conforming iterator
|
||||
// iterator
|
||||
|
||||
//- A primitive non-const node iterator.
|
||||
// Needs to be extended by inheriting classes.
|
||||
class iterator
|
||||
{
|
||||
friend class DLListBase;
|
||||
friend class const_iterator;
|
||||
|
||||
//- Reference to the list this is an iterator for
|
||||
DLListBase& curList_;
|
||||
//- The selected node.
|
||||
// MUST be the first member for easy comparison between iterators
|
||||
// and for reinterpret_cast from nullObject
|
||||
link* node_;
|
||||
|
||||
//- Current element
|
||||
link* curElmt_;
|
||||
//- The list being iterated on
|
||||
DLListBase* list_;
|
||||
|
||||
//- Copy of the link
|
||||
link curLink_;
|
||||
|
||||
//- Construct for a given SLListBase with nullptr element and link.
|
||||
// Only used to create endIter
|
||||
inline iterator(DLListBase&);
|
||||
//- Copy of the node prev/next pointers (to use after removal)
|
||||
link copy_;
|
||||
|
||||
public:
|
||||
|
||||
//- Construct for a given DLListBase and link
|
||||
inline iterator(DLListBase&, link*);
|
||||
//- Construct for a node on a list
|
||||
inline iterator(DLListBase* list, link* item);
|
||||
|
||||
//- Currently pointing at a valid entry
|
||||
//- The storage node
|
||||
inline link* get_node() const;
|
||||
|
||||
//- Pointing at a valid storage node
|
||||
inline bool found() const;
|
||||
|
||||
//- Move backward through list
|
||||
inline void prev();
|
||||
|
||||
//- Move forward through list
|
||||
inline void next();
|
||||
|
||||
inline void operator=(const iterator& iter);
|
||||
|
||||
inline bool operator==(const iterator& iter) const;
|
||||
inline bool operator!=(const iterator& iter) const;
|
||||
|
||||
inline link& operator*() const;
|
||||
|
||||
inline iterator& operator++();
|
||||
inline iterator operator++(int);
|
||||
inline bool operator==(const iterator&) const;
|
||||
inline bool operator!=(const iterator&) const;
|
||||
};
|
||||
|
||||
inline iterator begin();
|
||||
inline const iterator& end();
|
||||
|
||||
// const_iterator
|
||||
|
||||
// STL const_iterator
|
||||
|
||||
//- An STL-conforming const_iterator
|
||||
//- A primitive const node iterator (bidirectional).
|
||||
// Must normally be extended by inheriting classes.
|
||||
// Since this iterator works bidirectionally, it can be used as the
|
||||
// basis for a derived const_reverse_iterator
|
||||
class const_iterator
|
||||
{
|
||||
//- Reference to the list this is an iterator for
|
||||
const DLListBase& curList_;
|
||||
//- The selected node.
|
||||
// MUST be the first member for easy comparison between iterators
|
||||
// and for reinterpret_cast from nullObject
|
||||
const link* node_;
|
||||
|
||||
//- Current element
|
||||
const link* curElmt_;
|
||||
//- The list being iterated on (as pointer for bitwise copy)
|
||||
const DLListBase* list_;
|
||||
|
||||
public:
|
||||
|
||||
//- Construct for a given DLListBase and link
|
||||
inline const_iterator(const DLListBase&, const link*);
|
||||
//- Construct for a node on a list
|
||||
inline const_iterator(const DLListBase* list, const link* item);
|
||||
|
||||
//- Construct from a non-const iterator
|
||||
//- Copy construct from a non-const iterator
|
||||
inline const_iterator(const DLListBase::iterator& iter);
|
||||
|
||||
//- Currently pointing at a valid entry
|
||||
//- Copy construct
|
||||
const_iterator(const const_iterator&) = default;
|
||||
|
||||
//- The storage node
|
||||
inline const link* get_node() const;
|
||||
|
||||
//- Pointing at a valid storage node
|
||||
inline bool found() const;
|
||||
|
||||
inline void operator=(const const_iterator& iter);
|
||||
//- Move backward through list
|
||||
inline void prev();
|
||||
|
||||
inline bool operator==(const const_iterator& iter) const;
|
||||
inline bool operator!=(const const_iterator& iter) const;
|
||||
//- Move forward through list
|
||||
inline void next();
|
||||
|
||||
inline const link& operator*() const;
|
||||
const_iterator& operator=(const const_iterator&) = default;
|
||||
|
||||
inline const_iterator& operator++();
|
||||
inline const_iterator operator++(int);
|
||||
inline bool operator==(const const_iterator&) const;
|
||||
inline bool operator!=(const const_iterator&) const;
|
||||
};
|
||||
|
||||
|
||||
//- Iterator to first item in list with non-const access
|
||||
inline iterator begin();
|
||||
|
||||
//- Iterator to first item in list with const access
|
||||
inline const_iterator cbegin() const;
|
||||
|
||||
//- Iterator to last item in list with const access
|
||||
// Note that this is not a const_reverse_iterator, this is the
|
||||
// responsibilty of any derived classes.
|
||||
inline const_iterator crbegin() const;
|
||||
|
||||
//- End of list for iterators
|
||||
inline const iterator& end();
|
||||
|
||||
//- End of list for iterators
|
||||
inline const const_iterator& cend() const;
|
||||
|
||||
inline const_iterator begin() const;
|
||||
inline const const_iterator& end() const;
|
||||
|
||||
|
||||
// STL const_reverse_iterator
|
||||
|
||||
//- An STL-conforming const_reverse_iterator
|
||||
class const_reverse_iterator
|
||||
{
|
||||
//- Reference to the list this is an reverse_iterator for
|
||||
const DLListBase& curList_;
|
||||
|
||||
//- Current element
|
||||
const link* curElmt_;
|
||||
|
||||
public:
|
||||
|
||||
//- Construct for a given DLListBase and link
|
||||
inline const_reverse_iterator(const DLListBase& lst, const link*);
|
||||
|
||||
//- Currently pointing at a valid entry
|
||||
inline bool found() const;
|
||||
|
||||
inline void operator=(const const_reverse_iterator& iter);
|
||||
|
||||
inline bool operator==(const const_reverse_iterator& iter) const;
|
||||
inline bool operator!=(const const_reverse_iterator& iter) const;
|
||||
|
||||
inline const link& operator*() const;
|
||||
|
||||
inline const_reverse_iterator& operator++();
|
||||
inline const_reverse_iterator operator++(int);
|
||||
};
|
||||
|
||||
inline const_reverse_iterator crbegin() const;
|
||||
inline const const_reverse_iterator& crend() const;
|
||||
|
||||
inline const_reverse_iterator rbegin() const;
|
||||
inline const const_reverse_iterator& rend() const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
//- Iterator returned by end()
|
||||
static iterator endIter_;
|
||||
|
||||
//- const_iterator returned by end()
|
||||
static const_iterator endConstIter_;
|
||||
|
||||
//- const_reverse_iterator returned by end()
|
||||
static const_reverse_iterator endConstRevIter_;
|
||||
//- End of list for reverse iterators
|
||||
inline const const_iterator& crend() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -24,39 +24,74 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "nullObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
inline Foam::DLListBase::link::link()
|
||||
:
|
||||
prev_(nullptr),
|
||||
next_(nullptr)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::DLListBase::DLListBase()
|
||||
:
|
||||
first_(nullptr),
|
||||
last_(nullptr),
|
||||
nElmts_(0)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::DLListBase::DLListBase(link* a)
|
||||
:
|
||||
first_(a),
|
||||
last_(a),
|
||||
nElmts_(1)
|
||||
template<class IteratorType>
|
||||
inline const IteratorType& Foam::DLListBase::iterator_end()
|
||||
{
|
||||
a->prev_ = a;
|
||||
a->next_ = a;
|
||||
return *reinterpret_cast<const IteratorType*>(nullObjectPtr);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
template<class IteratorType>
|
||||
inline const IteratorType& Foam::DLListBase::iterator_rend()
|
||||
{
|
||||
return *reinterpret_cast<const IteratorType*>(nullObjectPtr);
|
||||
}
|
||||
|
||||
inline Foam::DLListBase::~DLListBase()
|
||||
{}
|
||||
|
||||
template<class IteratorType>
|
||||
inline IteratorType Foam::DLListBase::iterator_first() const
|
||||
{
|
||||
DLListBase* list = const_cast<DLListBase*>(this);
|
||||
|
||||
if (size())
|
||||
{
|
||||
return IteratorType(list, const_cast<DLListBase::link*>(first_));
|
||||
}
|
||||
|
||||
// Return an end iterator
|
||||
return IteratorType(list, nullptr);
|
||||
}
|
||||
|
||||
|
||||
template<class IteratorType>
|
||||
inline IteratorType Foam::DLListBase::iterator_last() const
|
||||
{
|
||||
DLListBase* list = const_cast<DLListBase*>(this);
|
||||
|
||||
if (size())
|
||||
{
|
||||
return IteratorType(list, const_cast<DLListBase::link*>(last_));
|
||||
}
|
||||
|
||||
// Return an end iterator
|
||||
return IteratorType(list, nullptr);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Iterator ends * * * * * * * * * * * * * * * //
|
||||
|
||||
inline const Foam::DLListBase::iterator& Foam::DLListBase::end()
|
||||
{
|
||||
return iterator_end<DLListBase::iterator>();
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::DLListBase::const_iterator&
|
||||
Foam::DLListBase::cend() const
|
||||
{
|
||||
return iterator_end<DLListBase::const_iterator>();
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::DLListBase::const_iterator&
|
||||
Foam::DLListBase::crend() const
|
||||
{
|
||||
return iterator_rend<DLListBase::const_iterator>();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
@ -69,27 +104,26 @@ inline bool Foam::DLListBase::link::registered() const
|
||||
|
||||
inline void Foam::DLListBase::link::deregister()
|
||||
{
|
||||
prev_ = nullptr;
|
||||
next_ = nullptr;
|
||||
prev_ = next_ = nullptr;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::DLListBase::size() const
|
||||
{
|
||||
return nElmts_;
|
||||
return size_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::DLListBase::empty() const
|
||||
{
|
||||
return !nElmts_;
|
||||
return !size_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::link*
|
||||
Foam::DLListBase::first()
|
||||
{
|
||||
if (!nElmts_)
|
||||
if (!size_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "list is empty"
|
||||
@ -102,7 +136,7 @@ Foam::DLListBase::first()
|
||||
inline const Foam::DLListBase::link*
|
||||
Foam::DLListBase::first() const
|
||||
{
|
||||
if (!nElmts_)
|
||||
if (!size_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "list is empty"
|
||||
@ -115,7 +149,7 @@ Foam::DLListBase::first() const
|
||||
inline Foam::DLListBase::link*
|
||||
Foam::DLListBase::last()
|
||||
{
|
||||
if (!nElmts_)
|
||||
if (!size_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "list is empty"
|
||||
@ -128,7 +162,7 @@ Foam::DLListBase::last()
|
||||
inline const Foam::DLListBase::link*
|
||||
Foam::DLListBase::last() const
|
||||
{
|
||||
if (!nElmts_)
|
||||
if (!size_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "list is empty"
|
||||
@ -142,15 +176,23 @@ inline void Foam::DLListBase::clear()
|
||||
{
|
||||
first_ = nullptr;
|
||||
last_ = nullptr;
|
||||
nElmts_ = 0;
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::DLListBase::swap(DLListBase& lst)
|
||||
{
|
||||
std::swap(first_, lst.first_);
|
||||
std::swap(last_, lst.last_);
|
||||
std::swap(size_, lst.size_);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::DLListBase::transfer(DLListBase& lst)
|
||||
{
|
||||
first_ = lst.first_;
|
||||
last_ = lst.last_;
|
||||
nElmts_ = lst.nElmts_;
|
||||
first_ = lst.first_;
|
||||
last_ = lst.last_;
|
||||
size_ = lst.size_;
|
||||
|
||||
lst.clear();
|
||||
}
|
||||
@ -159,10 +201,10 @@ inline void Foam::DLListBase::transfer(DLListBase& lst)
|
||||
inline Foam::DLListBase::link*
|
||||
Foam::DLListBase::remove
|
||||
(
|
||||
DLListBase::iterator& it
|
||||
DLListBase::iterator& iter
|
||||
)
|
||||
{
|
||||
return remove(it.curElmt_);
|
||||
return remove(iter.node_);
|
||||
}
|
||||
|
||||
|
||||
@ -170,88 +212,100 @@ inline Foam::DLListBase::link*
|
||||
Foam::DLListBase::replace
|
||||
(
|
||||
DLListBase::iterator& oldIter,
|
||||
DLListBase::link* newLink
|
||||
DLListBase::link* newItem
|
||||
)
|
||||
{
|
||||
return replace(oldIter.curElmt_, newLink);
|
||||
return replace(oldIter.node_, newItem);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::DLListBase::iterator::iterator(DLListBase& s, link* elmt)
|
||||
inline Foam::DLListBase::iterator::iterator
|
||||
(
|
||||
DLListBase* list,
|
||||
DLListBase::link* item
|
||||
)
|
||||
:
|
||||
curList_(s),
|
||||
curElmt_(elmt),
|
||||
curLink_(*curElmt_)
|
||||
{}
|
||||
node_(item),
|
||||
list_(list),
|
||||
copy_()
|
||||
{
|
||||
if (node_ != nullptr)
|
||||
{
|
||||
copy_ = *node_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::iterator::iterator(DLListBase& s)
|
||||
:
|
||||
curList_(s),
|
||||
curElmt_(nullptr),
|
||||
curLink_()
|
||||
{}
|
||||
inline Foam::DLListBase::link*
|
||||
Foam::DLListBase::iterator::get_node() const
|
||||
{
|
||||
return node_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::DLListBase::iterator::found() const
|
||||
{
|
||||
return (curElmt_ != nullptr);
|
||||
return (node_ != nullptr);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::DLListBase::iterator::prev()
|
||||
{
|
||||
if (list_)
|
||||
{
|
||||
// Check if the node_ is the first element (points to itself)
|
||||
// or if the list is empty because last element was removed
|
||||
if (node_ == copy_.prev_ || list_->first_ == nullptr)
|
||||
{
|
||||
node_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
node_ = copy_.prev_;
|
||||
copy_ = *node_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::DLListBase::iterator::next()
|
||||
{
|
||||
if (list_)
|
||||
{
|
||||
// Check if the node_ is the last element (points to itself)
|
||||
// or if the list is empty because last element was removed
|
||||
if (node_ == copy_.next_ || list_->last_ == nullptr)
|
||||
{
|
||||
node_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
node_ = copy_.next_;
|
||||
copy_ = *node_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::DLListBase::iterator::operator=(const iterator& iter)
|
||||
{
|
||||
curElmt_ = iter.curElmt_;
|
||||
curLink_ = iter.curLink_;
|
||||
node_ = iter.node_;
|
||||
list_ = iter.list_;
|
||||
copy_ = iter.copy_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::DLListBase::iterator::operator==(const iterator& iter) const
|
||||
{
|
||||
return curElmt_ == iter.curElmt_;
|
||||
return node_ == iter.node_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::DLListBase::iterator::operator!=(const iterator& iter) const
|
||||
{
|
||||
return curElmt_ != iter.curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::link&
|
||||
Foam::DLListBase::iterator::operator*() const
|
||||
{
|
||||
return *curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::iterator&
|
||||
Foam::DLListBase::iterator::operator++()
|
||||
{
|
||||
// Check if the curElmt_ is the last element (if it points to itself)
|
||||
// or if the list is empty because the last element may have been removed
|
||||
if (curLink_.next_ == curElmt_ || curList_.last_ == nullptr)
|
||||
{
|
||||
curElmt_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
curElmt_ = curLink_.next_;
|
||||
curLink_ = *curElmt_;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::iterator
|
||||
Foam::DLListBase::iterator::operator++(int)
|
||||
{
|
||||
iterator tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
return node_ != iter.node_;
|
||||
}
|
||||
|
||||
|
||||
@ -260,18 +314,10 @@ Foam::DLListBase::begin()
|
||||
{
|
||||
if (size())
|
||||
{
|
||||
return iterator(*this, first());
|
||||
return iterator_first<iterator>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return endIter_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::DLListBase::iterator& Foam::DLListBase::end()
|
||||
{
|
||||
return endIter_;
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
@ -279,12 +325,12 @@ inline const Foam::DLListBase::iterator& Foam::DLListBase::end()
|
||||
|
||||
inline Foam::DLListBase::const_iterator::const_iterator
|
||||
(
|
||||
const DLListBase& s,
|
||||
const link* elmt
|
||||
const DLListBase* list,
|
||||
const DLListBase::link* item
|
||||
)
|
||||
:
|
||||
curList_(s),
|
||||
curElmt_(elmt)
|
||||
node_(item),
|
||||
list_(list)
|
||||
{}
|
||||
|
||||
|
||||
@ -293,23 +339,53 @@ inline Foam::DLListBase::const_iterator::const_iterator
|
||||
const DLListBase::iterator& iter
|
||||
)
|
||||
:
|
||||
curList_(iter.curList_),
|
||||
curElmt_(iter.curElmt_)
|
||||
node_(iter.node_),
|
||||
list_(iter.list_)
|
||||
{}
|
||||
|
||||
|
||||
inline const Foam::DLListBase::link*
|
||||
Foam::DLListBase::const_iterator::get_node() const
|
||||
{
|
||||
return node_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::DLListBase::const_iterator::found() const
|
||||
{
|
||||
return (curElmt_ != nullptr);
|
||||
return (node_ != nullptr);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::DLListBase::const_iterator::operator=
|
||||
(
|
||||
const const_iterator& iter
|
||||
)
|
||||
inline void Foam::DLListBase::const_iterator::prev()
|
||||
{
|
||||
curElmt_ = iter.curElmt_;
|
||||
if (list_ && node_)
|
||||
{
|
||||
if (node_ == list_->first_)
|
||||
{
|
||||
node_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
node_ = node_->prev_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::DLListBase::const_iterator::next()
|
||||
{
|
||||
if (list_ && node_)
|
||||
{
|
||||
if (node_ == list_->last_)
|
||||
{
|
||||
node_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
node_ = node_->next_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -318,7 +394,7 @@ inline bool Foam::DLListBase::const_iterator::operator==
|
||||
const const_iterator& iter
|
||||
) const
|
||||
{
|
||||
return curElmt_ == iter.curElmt_;
|
||||
return node_ == iter.node_;
|
||||
}
|
||||
|
||||
|
||||
@ -327,39 +403,7 @@ inline bool Foam::DLListBase::const_iterator::operator!=
|
||||
const const_iterator& iter
|
||||
) const
|
||||
{
|
||||
return curElmt_ != iter.curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::DLListBase::link&
|
||||
Foam::DLListBase::const_iterator::operator*() const
|
||||
{
|
||||
return *curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::const_iterator&
|
||||
Foam::DLListBase::const_iterator::operator++()
|
||||
{
|
||||
if (curElmt_ == curList_.last_)
|
||||
{
|
||||
curElmt_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
curElmt_ = curElmt_->next_;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::const_iterator
|
||||
Foam::DLListBase::const_iterator::operator++(int)
|
||||
{
|
||||
const_iterator tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
return node_ != iter.node_;
|
||||
}
|
||||
|
||||
|
||||
@ -368,146 +412,22 @@ Foam::DLListBase::cbegin() const
|
||||
{
|
||||
if (size())
|
||||
{
|
||||
return const_iterator(*this, first());
|
||||
return iterator_first<const_iterator>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return endConstIter_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::DLListBase::const_iterator&
|
||||
Foam::DLListBase::cend() const
|
||||
{
|
||||
return endConstIter_;
|
||||
return cend();
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::const_iterator
|
||||
Foam::DLListBase::begin() const
|
||||
{
|
||||
return this->cbegin();
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::DLListBase::const_iterator&
|
||||
Foam::DLListBase::end() const
|
||||
{
|
||||
return endConstIter_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * STL const_reverse_iterator * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::DLListBase::const_reverse_iterator::const_reverse_iterator
|
||||
(
|
||||
const DLListBase& lst,
|
||||
const link* elmt
|
||||
)
|
||||
:
|
||||
curList_(lst),
|
||||
curElmt_(elmt)
|
||||
{}
|
||||
|
||||
|
||||
inline bool Foam::DLListBase::const_reverse_iterator::found() const
|
||||
{
|
||||
return (curElmt_ != nullptr);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::DLListBase::const_reverse_iterator::operator=
|
||||
(
|
||||
const const_reverse_iterator& iter
|
||||
)
|
||||
{
|
||||
curElmt_ = iter.curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::DLListBase::const_reverse_iterator::operator==
|
||||
(
|
||||
const const_reverse_iterator& iter
|
||||
) const
|
||||
{
|
||||
return curElmt_ == iter.curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::DLListBase::const_reverse_iterator::operator!=
|
||||
(
|
||||
const const_reverse_iterator& iter
|
||||
) const
|
||||
{
|
||||
return curElmt_ != iter.curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::DLListBase::link&
|
||||
Foam::DLListBase::const_reverse_iterator::operator*() const
|
||||
{
|
||||
return *curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::const_reverse_iterator&
|
||||
Foam::DLListBase::const_reverse_iterator::operator++()
|
||||
{
|
||||
if (curElmt_ == curList_.first_)
|
||||
{
|
||||
curElmt_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
curElmt_ = curElmt_->prev_;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::const_reverse_iterator
|
||||
Foam::DLListBase::const_reverse_iterator::operator++(int)
|
||||
{
|
||||
const_reverse_iterator tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::const_reverse_iterator
|
||||
Foam::DLListBase::crbegin() const
|
||||
{
|
||||
if (size())
|
||||
{
|
||||
return const_reverse_iterator(*this, this->last());
|
||||
return iterator_last<const_iterator>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return endConstRevIter_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::DLListBase::const_reverse_iterator&
|
||||
Foam::DLListBase::crend() const
|
||||
{
|
||||
return endConstRevIter_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::DLListBase::const_reverse_iterator
|
||||
Foam::DLListBase::rbegin() const
|
||||
{
|
||||
return this->crbegin();
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::DLListBase::const_reverse_iterator&
|
||||
Foam::DLListBase::rend() const
|
||||
{
|
||||
return endConstRevIter_;
|
||||
return crend();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -23,61 +23,57 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "SLListBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::SLListBase::iterator Foam::SLListBase::endIter_
|
||||
(
|
||||
const_cast<SLListBase&>(static_cast<const SLListBase&>(SLListBase()))
|
||||
);
|
||||
|
||||
Foam::SLListBase::const_iterator Foam::SLListBase::endConstIter_
|
||||
(
|
||||
static_cast<const SLListBase&>(SLListBase()),
|
||||
reinterpret_cast<const link*>(0)
|
||||
);
|
||||
|
||||
#include "error.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::SLListBase::insert(SLListBase::link* a)
|
||||
void Foam::SLListBase::insert(SLListBase::link* item)
|
||||
{
|
||||
nElmts_++;
|
||||
if (!item)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
++size_;
|
||||
|
||||
if (last_)
|
||||
{
|
||||
a->next_ = last_->next_;
|
||||
item->next_ = last_->next_;
|
||||
}
|
||||
else
|
||||
{
|
||||
last_ = a;
|
||||
last_ = item;
|
||||
}
|
||||
|
||||
last_->next_ = a;
|
||||
last_->next_ = item;
|
||||
}
|
||||
|
||||
|
||||
void Foam::SLListBase::append(SLListBase::link* a)
|
||||
void Foam::SLListBase::append(SLListBase::link* item)
|
||||
{
|
||||
nElmts_++;
|
||||
if (!item)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
++size_;
|
||||
|
||||
if (last_)
|
||||
{
|
||||
a->next_ = last_->next_;
|
||||
last_ = last_->next_ = a;
|
||||
item->next_ = last_->next_;
|
||||
last_ = last_->next_ = item;
|
||||
}
|
||||
else
|
||||
{
|
||||
last_ = a->next_ = a;
|
||||
last_ = item->next_ = item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::SLListBase::link* Foam::SLListBase::removeHead()
|
||||
{
|
||||
nElmts_--;
|
||||
--size_;
|
||||
|
||||
if (last_ == nullptr)
|
||||
{
|
||||
@ -86,39 +82,39 @@ Foam::SLListBase::link* Foam::SLListBase::removeHead()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
SLListBase::link* f = last_->next_;
|
||||
SLListBase::link *ret = last_->next_;
|
||||
|
||||
if (f == last_)
|
||||
if (ret == last_)
|
||||
{
|
||||
last_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
last_->next_ = f->next_;
|
||||
last_->next_ = ret->next_;
|
||||
}
|
||||
|
||||
return f;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Foam::SLListBase::link* Foam::SLListBase::remove(SLListBase::link* it)
|
||||
Foam::SLListBase::link* Foam::SLListBase::remove(SLListBase::link* item)
|
||||
{
|
||||
SLListBase::iterator iter = begin();
|
||||
SLListBase::link *prev = &(*iter);
|
||||
SLListBase::link *prev = iter.get_node();
|
||||
|
||||
if (it == prev)
|
||||
if (item == prev)
|
||||
{
|
||||
return removeHead();
|
||||
}
|
||||
|
||||
nElmts_--;
|
||||
|
||||
for (++iter; iter != end(); ++iter)
|
||||
for (iter.next(); iter != end(); iter.next())
|
||||
{
|
||||
SLListBase::link *p = &(*iter);
|
||||
SLListBase::link *p = iter.get_node();
|
||||
|
||||
if (p == it)
|
||||
if (p == item)
|
||||
{
|
||||
--size_;
|
||||
|
||||
prev->next_ = p->next_;
|
||||
|
||||
if (p == last_)
|
||||
@ -126,12 +122,13 @@ Foam::SLListBase::link* Foam::SLListBase::remove(SLListBase::link* it)
|
||||
last_ = prev;
|
||||
}
|
||||
|
||||
return it;
|
||||
return item;
|
||||
}
|
||||
|
||||
prev = p;
|
||||
}
|
||||
|
||||
// Did not remove
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,6 +27,13 @@ Class
|
||||
Description
|
||||
Base for singly-linked lists.
|
||||
|
||||
The iterators associated with the list only have a core functionality
|
||||
for navigation, with additional functionality to be added by inheriting
|
||||
classes. The node iterators always have a node-pointer as the
|
||||
first member data, which allows reinterpret_cast from anything else with
|
||||
a nullptr as its first data member.
|
||||
The nullObject is such an item (with a nullptr data member).
|
||||
|
||||
SourceFiles
|
||||
SLListBaseI.H
|
||||
SLListBase.C
|
||||
@ -36,9 +43,9 @@ SourceFiles
|
||||
#ifndef SLListBase_H
|
||||
#define SLListBase_H
|
||||
|
||||
#include "bool.H"
|
||||
#include "label.H"
|
||||
#include "uLabel.H"
|
||||
#include <utility>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -51,33 +58,30 @@ namespace Foam
|
||||
|
||||
class SLListBase
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Link structure
|
||||
//- The structure for a singly-linked storage node
|
||||
struct link
|
||||
{
|
||||
//- Pointer to next entry in list
|
||||
link* next_;
|
||||
link* next_ = nullptr;
|
||||
|
||||
//- Null construct
|
||||
inline link();
|
||||
|
||||
//- Construct given pointer to another link
|
||||
inline link(link* p);
|
||||
link() = default;
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
// Private Member Data
|
||||
|
||||
//- last_ points to last element
|
||||
//- A pointer to the last element.
|
||||
// last_->next_ points to first element, i.e. circular storage
|
||||
link* last_;
|
||||
link* last_ = nullptr;
|
||||
|
||||
//- Number of elements in the list
|
||||
label size_ = 0;
|
||||
|
||||
//- Number of elements in in list
|
||||
label nElmts_;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
@ -88,9 +92,33 @@ private:
|
||||
void operator=(const SLListBase&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Factory method to return an iterator end
|
||||
// Simply reinterprets a NullObject as a SLListBase iterator.
|
||||
template<class IteratorType>
|
||||
inline static const IteratorType& iterator_end();
|
||||
|
||||
//- Factory method to return an iterator rend
|
||||
// Deleted for SLListBase
|
||||
template<class IteratorType>
|
||||
static const IteratorType& iterator_rend() = delete;
|
||||
|
||||
//- Return iterator to first item or end-iterator if list is empty
|
||||
// Removes constness which the caller promises to manage.
|
||||
template<class IteratorType>
|
||||
inline IteratorType iterator_first() const;
|
||||
|
||||
//- Return iterator to last item or end-iterator if list is empty
|
||||
// Removes constness which the caller promises to manage.
|
||||
template<class IteratorType>
|
||||
inline IteratorType iterator_last() const;
|
||||
|
||||
public:
|
||||
|
||||
// Forward declaration of STL iterators
|
||||
// Forward declaration of iterators
|
||||
|
||||
class iterator;
|
||||
friend class iterator;
|
||||
@ -102,154 +130,166 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Null construct
|
||||
inline SLListBase();
|
||||
|
||||
//- Construct given initial entry
|
||||
inline SLListBase(link*);
|
||||
SLListBase() = default;
|
||||
|
||||
|
||||
//- Destructor
|
||||
~SLListBase();
|
||||
~SLListBase() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
//- Return number of elements in list
|
||||
inline label size() const;
|
||||
|
||||
//- Return number of elements in list
|
||||
inline label size() const;
|
||||
//- Return true if the list is empty
|
||||
inline bool empty() const;
|
||||
|
||||
//- Return true if the list is empty
|
||||
inline bool empty() const;
|
||||
//- Return first entry
|
||||
inline link* first();
|
||||
|
||||
//- Return first entry
|
||||
inline link* first();
|
||||
//- Return const access to first entry
|
||||
inline const link* first() const;
|
||||
|
||||
//- Return const access to first entry
|
||||
inline const link* first() const;
|
||||
//- Return last entry
|
||||
inline link* last();
|
||||
|
||||
//- Return last entry
|
||||
inline link* last();
|
||||
|
||||
//- Return const access to last entry
|
||||
inline const link* last() const;
|
||||
//- Return const access to last entry
|
||||
inline const link* last() const;
|
||||
|
||||
|
||||
// Edit
|
||||
//- Add at head of list
|
||||
void insert(link* item);
|
||||
|
||||
//- Add at head of list
|
||||
void insert(link*);
|
||||
//- Add at tail of list
|
||||
void append(link* item);
|
||||
|
||||
//- Add at tail of list
|
||||
void append(link*);
|
||||
//- Remove and return head
|
||||
link* removeHead();
|
||||
|
||||
//- Remove and return head
|
||||
link* removeHead();
|
||||
// Remove and return element
|
||||
link* remove(link* item);
|
||||
|
||||
// Remove and return element
|
||||
link* remove(link*);
|
||||
// Remove and return element specified by iterator
|
||||
inline link* remove(iterator& iter);
|
||||
|
||||
// Remove and return element specified by iterator
|
||||
inline link* remove(iterator&);
|
||||
//- Clear the list
|
||||
inline void clear();
|
||||
|
||||
//- Clear the list
|
||||
inline void clear();
|
||||
//- Swap the contents of list
|
||||
inline void swap(SLListBase& lst);
|
||||
|
||||
//- Transfer the contents of the argument into this List
|
||||
// and annul the argument list.
|
||||
inline void transfer(SLListBase&);
|
||||
//- Transfer the contents of the argument into this list
|
||||
//- and annul the argument list.
|
||||
inline void transfer(SLListBase& lst);
|
||||
|
||||
// STL iterator
|
||||
|
||||
//- An STL-conforming iterator
|
||||
// iterator
|
||||
|
||||
//- A primitive non-const node iterator.
|
||||
// Must normally be extended by inheriting classes.
|
||||
class iterator
|
||||
{
|
||||
friend class SLListBase;
|
||||
friend class const_iterator;
|
||||
|
||||
//- Reference to the list this is an iterator for
|
||||
SLListBase& curList_;
|
||||
//- The selected node.
|
||||
// MUST be the first member for easy comparison between iterators
|
||||
// and for reinterpret_cast from nullObject
|
||||
link* node_;
|
||||
|
||||
//- Current element
|
||||
link* curElmt_;
|
||||
//- The list being iterated on (as pointer for bitwise copy)
|
||||
SLListBase* list_;
|
||||
|
||||
//- Copy of the link
|
||||
link curLink_;
|
||||
|
||||
//- Construct for a given SLListBase with nullptr element and link.
|
||||
// Only used to create endIter
|
||||
inline iterator(SLListBase&);
|
||||
//- Copy of the node next pointer (to use after removal)
|
||||
link copy_;
|
||||
|
||||
public:
|
||||
|
||||
//- Construct for a given SLListBase and link
|
||||
inline iterator(SLListBase&, link*);
|
||||
//- Construct for a node on the list
|
||||
inline iterator(SLListBase* list, link* item);
|
||||
|
||||
//- Currently pointing at a valid entry
|
||||
//- The storage node
|
||||
inline link* get_node() const;
|
||||
|
||||
//- Pointing at a valid storage node
|
||||
inline bool found() const;
|
||||
|
||||
//- Cannot move backward through list
|
||||
inline void prev() = delete;
|
||||
|
||||
//- Move forward through list
|
||||
inline void next();
|
||||
|
||||
inline void operator=(const iterator& iter);
|
||||
|
||||
inline bool operator==(const iterator& iter) const;
|
||||
inline bool operator!=(const iterator& iter) const;
|
||||
|
||||
inline link& operator*() const;
|
||||
|
||||
inline iterator& operator++();
|
||||
inline iterator operator++(int);
|
||||
};
|
||||
|
||||
inline iterator begin();
|
||||
inline const iterator& end();
|
||||
|
||||
|
||||
// STL const_iterator
|
||||
|
||||
//- An STL-conforming const_iterator
|
||||
//- A primitive const node iterator.
|
||||
// Must normally be extended by inheriting classes.
|
||||
class const_iterator
|
||||
{
|
||||
//- Reference to the list this is an iterator for
|
||||
const SLListBase& curList_;
|
||||
//- The selected node.
|
||||
// MUST be the first member for easy comparison between iterators
|
||||
// and for reinterpret_cast from nullObject
|
||||
const link* node_;
|
||||
|
||||
//- Current element
|
||||
const link* curElmt_;
|
||||
//- The list being iterated on (as pointer for bitwise copy)
|
||||
const SLListBase* list_;
|
||||
|
||||
public:
|
||||
|
||||
//- Construct for a given SLListBase and link
|
||||
inline const_iterator(const SLListBase&, const link*);
|
||||
//- Construct for a node on the list
|
||||
inline const_iterator(const SLListBase* list, const link* item);
|
||||
|
||||
//- Construct from a non-const iterator
|
||||
inline const_iterator(const SLListBase::iterator& iter);
|
||||
|
||||
//- Currently pointing at a valid entry
|
||||
//- Copy construct
|
||||
const_iterator(const const_iterator&) = default;
|
||||
|
||||
//- The storage node
|
||||
inline const link* get_node() const;
|
||||
|
||||
//- Pointing at a valid storage node
|
||||
inline bool found() const;
|
||||
|
||||
inline void operator=(const const_iterator& iter);
|
||||
//- Cannot move backward through list
|
||||
inline void prev() = delete;
|
||||
|
||||
//- Move forward through list
|
||||
inline void next();
|
||||
|
||||
const_iterator& operator=(const const_iterator&) = default;
|
||||
|
||||
inline bool operator==(const const_iterator& iter) const;
|
||||
inline bool operator!=(const const_iterator& iter) const;
|
||||
|
||||
inline const link& operator*() const;
|
||||
|
||||
inline const_iterator& operator++();
|
||||
inline const_iterator operator++(int);
|
||||
};
|
||||
|
||||
|
||||
//- Iterator to first item in list with non-const access
|
||||
inline iterator begin();
|
||||
|
||||
//- Iterator to first item in list with const access
|
||||
inline const_iterator cbegin() const;
|
||||
|
||||
//- No reverse iteration
|
||||
const_iterator crbegin() const = delete;
|
||||
|
||||
//- End of list for iterators
|
||||
inline const iterator& end();
|
||||
|
||||
//- End of list for iterators
|
||||
inline const const_iterator& cend() const;
|
||||
|
||||
inline const_iterator begin() const;
|
||||
inline const const_iterator& end() const;
|
||||
//- No reverse iteration
|
||||
const const_iterator& crend() const = delete;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
//- Iterator returned by end()
|
||||
static iterator endIter_;
|
||||
|
||||
//- const_iterator returned by end()
|
||||
static const_iterator endConstIter_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -24,65 +24,65 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "nullObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
inline Foam::SLListBase::link::link()
|
||||
:
|
||||
next_(nullptr)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::SLListBase::link::link(link* p)
|
||||
:
|
||||
next_(p)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::SLListBase::SLListBase()
|
||||
:
|
||||
last_(nullptr),
|
||||
nElmts_(0)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::SLListBase::SLListBase(link* a)
|
||||
:
|
||||
last_(a),
|
||||
nElmts_(0)
|
||||
template<class IteratorType>
|
||||
inline const IteratorType& Foam::SLListBase::iterator_end()
|
||||
{
|
||||
if (a) // protect against nullptr
|
||||
{
|
||||
a->next_ = a;
|
||||
nElmts_ = 1;
|
||||
}
|
||||
return *reinterpret_cast<const IteratorType*>(nullObjectPtr);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
template<class IteratorType>
|
||||
inline IteratorType Foam::SLListBase::iterator_first() const
|
||||
{
|
||||
SLListBase* list = const_cast<SLListBase*>(this);
|
||||
|
||||
inline Foam::SLListBase::~SLListBase()
|
||||
{}
|
||||
if (size())
|
||||
{
|
||||
return IteratorType(list, const_cast<SLListBase::link*>(last_->next_));
|
||||
}
|
||||
|
||||
// Return an end iterator
|
||||
return IteratorType(list, nullptr);
|
||||
}
|
||||
|
||||
|
||||
template<class IteratorType>
|
||||
inline IteratorType Foam::SLListBase::iterator_last() const
|
||||
{
|
||||
SLListBase* list = const_cast<SLListBase*>(this);
|
||||
|
||||
if (size())
|
||||
{
|
||||
return IteratorType(list, const_cast<SLListBase::link*>(last_));
|
||||
}
|
||||
|
||||
// Return an end iterator
|
||||
return IteratorType(list, nullptr);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::label Foam::SLListBase::size() const
|
||||
{
|
||||
return nElmts_;
|
||||
return size_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::SLListBase::empty() const
|
||||
{
|
||||
return !nElmts_;
|
||||
return !size_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::SLListBase::link*
|
||||
Foam::SLListBase::first()
|
||||
{
|
||||
if (!nElmts_)
|
||||
if (!size_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "list is empty"
|
||||
@ -95,7 +95,7 @@ Foam::SLListBase::first()
|
||||
inline const Foam::SLListBase::link*
|
||||
Foam::SLListBase::first() const
|
||||
{
|
||||
if (!nElmts_)
|
||||
if (!size_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "list is empty"
|
||||
@ -108,7 +108,7 @@ Foam::SLListBase::first() const
|
||||
inline Foam::SLListBase::link*
|
||||
Foam::SLListBase::last()
|
||||
{
|
||||
if (!nElmts_)
|
||||
if (!size_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "list is empty"
|
||||
@ -121,7 +121,7 @@ Foam::SLListBase::last()
|
||||
inline const Foam::SLListBase::link*
|
||||
Foam::SLListBase::last() const
|
||||
{
|
||||
if (!nElmts_)
|
||||
if (!size_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "list is empty"
|
||||
@ -134,14 +134,21 @@ Foam::SLListBase::last() const
|
||||
inline void Foam::SLListBase::clear()
|
||||
{
|
||||
last_ = nullptr;
|
||||
nElmts_ = 0;
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::SLListBase::swap(SLListBase& lst)
|
||||
{
|
||||
std::swap(last_, lst.last_);
|
||||
std::swap(size_, lst.size_);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::SLListBase::transfer(SLListBase& lst)
|
||||
{
|
||||
last_ = lst.last_;
|
||||
nElmts_ = lst.nElmts_;
|
||||
last_ = lst.last_;
|
||||
size_ = lst.size_;
|
||||
|
||||
lst.clear();
|
||||
}
|
||||
@ -149,84 +156,79 @@ inline void Foam::SLListBase::transfer(SLListBase& lst)
|
||||
|
||||
inline Foam::SLListBase::link* Foam::SLListBase::remove
|
||||
(
|
||||
SLListBase::iterator& it
|
||||
SLListBase::iterator& iter
|
||||
)
|
||||
{
|
||||
return remove(it.curElmt_);
|
||||
return remove(iter.node_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::SLListBase::iterator::iterator(SLListBase& s, link* elmt)
|
||||
inline Foam::SLListBase::iterator::iterator
|
||||
(
|
||||
SLListBase* list,
|
||||
SLListBase::link* item
|
||||
)
|
||||
:
|
||||
curList_(s),
|
||||
curElmt_(elmt),
|
||||
curLink_(*curElmt_)
|
||||
{}
|
||||
node_(item),
|
||||
list_(list),
|
||||
copy_()
|
||||
{
|
||||
if (node_ != nullptr)
|
||||
{
|
||||
copy_ = *node_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::SLListBase::iterator::iterator(SLListBase& s)
|
||||
:
|
||||
curList_(s),
|
||||
curElmt_(nullptr),
|
||||
curLink_()
|
||||
{}
|
||||
inline Foam::SLListBase::link*
|
||||
Foam::SLListBase::iterator::get_node() const
|
||||
{
|
||||
return node_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::SLListBase::iterator::found() const
|
||||
{
|
||||
return (curElmt_ != nullptr);
|
||||
return (node_ != nullptr);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::SLListBase::iterator::next()
|
||||
{
|
||||
if (list_)
|
||||
{
|
||||
if (node_ == list_->last_ || list_->last_ == nullptr)
|
||||
{
|
||||
node_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
node_ = copy_.next_;
|
||||
copy_ = *node_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::SLListBase::iterator::operator=(const iterator& iter)
|
||||
{
|
||||
curElmt_ = iter.curElmt_;
|
||||
curLink_ = iter.curLink_;
|
||||
node_ = iter.node_;
|
||||
list_ = iter.list_;
|
||||
copy_ = iter.copy_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::SLListBase::iterator::operator==(const iterator& iter) const
|
||||
{
|
||||
return curElmt_ == iter.curElmt_;
|
||||
return node_ == iter.node_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::SLListBase::iterator::operator!=(const iterator& iter) const
|
||||
{
|
||||
return curElmt_ != iter.curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::SLListBase::link& Foam::SLListBase::iterator::operator*() const
|
||||
{
|
||||
return *curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::SLListBase::iterator& Foam::SLListBase::iterator::operator++()
|
||||
{
|
||||
if (curElmt_ == curList_.last_ || curList_.last_ == nullptr)
|
||||
{
|
||||
curElmt_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
curElmt_ = curLink_.next_;
|
||||
curLink_ = *curElmt_;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::SLListBase::iterator
|
||||
Foam::SLListBase::iterator::operator++(int)
|
||||
{
|
||||
iterator tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
return node_ != iter.node_;
|
||||
}
|
||||
|
||||
|
||||
@ -235,19 +237,24 @@ Foam::SLListBase::begin()
|
||||
{
|
||||
if (size())
|
||||
{
|
||||
return iterator(*this, first());
|
||||
}
|
||||
else
|
||||
{
|
||||
return endIter_;
|
||||
return iterator_first<iterator>();
|
||||
}
|
||||
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::SLListBase::iterator&
|
||||
Foam::SLListBase::end()
|
||||
{
|
||||
return endIter_;
|
||||
return iterator_end<SLListBase::iterator>();
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::SLListBase::const_iterator&
|
||||
Foam::SLListBase::cend() const
|
||||
{
|
||||
return iterator_end<SLListBase::const_iterator>();
|
||||
}
|
||||
|
||||
|
||||
@ -255,12 +262,12 @@ Foam::SLListBase::end()
|
||||
|
||||
inline Foam::SLListBase::const_iterator::const_iterator
|
||||
(
|
||||
const SLListBase& s,
|
||||
const link* elmt
|
||||
const SLListBase* list,
|
||||
const SLListBase::link* item
|
||||
)
|
||||
:
|
||||
curList_(s),
|
||||
curElmt_(elmt)
|
||||
node_(item),
|
||||
list_(list)
|
||||
{}
|
||||
|
||||
|
||||
@ -269,23 +276,37 @@ inline Foam::SLListBase::const_iterator::const_iterator
|
||||
const SLListBase::iterator& iter
|
||||
)
|
||||
:
|
||||
curList_(iter.curList_),
|
||||
curElmt_(iter.curElmt_)
|
||||
node_(iter.node_),
|
||||
list_(iter.list_)
|
||||
{}
|
||||
|
||||
|
||||
inline const Foam::SLListBase::link*
|
||||
Foam::SLListBase::const_iterator::get_node() const
|
||||
{
|
||||
return node_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::SLListBase::const_iterator::found() const
|
||||
{
|
||||
return (curElmt_ != nullptr);
|
||||
return (node_ != nullptr);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::SLListBase::const_iterator::operator=
|
||||
(
|
||||
const const_iterator& iter
|
||||
)
|
||||
inline void Foam::SLListBase::const_iterator::next()
|
||||
{
|
||||
curElmt_ = iter.curElmt_;
|
||||
if (list_)
|
||||
{
|
||||
if (node_ == list_->last_)
|
||||
{
|
||||
node_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
node_ = node_->next_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -294,7 +315,7 @@ inline bool Foam::SLListBase::const_iterator::operator==
|
||||
const const_iterator& iter
|
||||
) const
|
||||
{
|
||||
return curElmt_ == iter.curElmt_;
|
||||
return node_ == iter.node_;
|
||||
}
|
||||
|
||||
|
||||
@ -303,39 +324,7 @@ inline bool Foam::SLListBase::const_iterator::operator!=
|
||||
const const_iterator& iter
|
||||
) const
|
||||
{
|
||||
return curElmt_ != iter.curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::SLListBase::link&
|
||||
Foam::SLListBase::const_iterator::operator*() const
|
||||
{
|
||||
return *curElmt_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::SLListBase::const_iterator&
|
||||
Foam::SLListBase::const_iterator::operator++()
|
||||
{
|
||||
if (curElmt_ == curList_.last_)
|
||||
{
|
||||
curElmt_ = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
curElmt_ = curElmt_->next_;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::SLListBase::const_iterator
|
||||
Foam::SLListBase::const_iterator::operator++(int)
|
||||
{
|
||||
const_iterator tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
return node_ != iter.node_;
|
||||
}
|
||||
|
||||
|
||||
@ -344,33 +333,10 @@ Foam::SLListBase::cbegin() const
|
||||
{
|
||||
if (size())
|
||||
{
|
||||
return const_iterator(*this, first());
|
||||
return iterator_first<const_iterator>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return endConstIter_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::SLListBase::const_iterator&
|
||||
Foam::SLListBase::cend() const
|
||||
{
|
||||
return endConstIter_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::SLListBase::const_iterator
|
||||
Foam::SLListBase::begin() const
|
||||
{
|
||||
return this->cbegin();
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::SLListBase::const_iterator&
|
||||
Foam::SLListBase::end() const
|
||||
{
|
||||
return endConstIter_;
|
||||
return cend();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,10 +27,7 @@ Class
|
||||
Description
|
||||
A FIFO stack based on a singly-linked list.
|
||||
|
||||
Operations are push(), pop(), top(), bottom() and empty().
|
||||
|
||||
SourceFiles
|
||||
FIFOStack.C
|
||||
Stack operations are push(), pop(), top(), bottom().
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -53,7 +50,6 @@ class FIFOStack
|
||||
:
|
||||
public SLList<T>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
@ -64,34 +60,35 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
//- Return a copy of the top element
|
||||
T top() const
|
||||
{
|
||||
return this->last();
|
||||
}
|
||||
|
||||
//- Return a copy of the top element
|
||||
T top() const
|
||||
{
|
||||
return this->last();
|
||||
}
|
||||
//- Return a copy of the bottom element
|
||||
T bottom() const
|
||||
{
|
||||
return this->first();
|
||||
}
|
||||
|
||||
//- Return a copy of the bottom element
|
||||
T bottom() const
|
||||
{
|
||||
return this->first();
|
||||
}
|
||||
//- Push an element onto the back of the stack
|
||||
void push(const T& element)
|
||||
{
|
||||
this->append(element);
|
||||
}
|
||||
|
||||
//- Move an element onto the back of the stack
|
||||
void push(T&& element)
|
||||
{
|
||||
this->append(std::move(element));
|
||||
}
|
||||
|
||||
// Edit
|
||||
|
||||
//- Push an element onto the stack
|
||||
void push(const T& a)
|
||||
{
|
||||
this->append(a);
|
||||
}
|
||||
|
||||
//- Pop the bottom element off the stack
|
||||
T pop()
|
||||
{
|
||||
return this->removeHead();
|
||||
}
|
||||
//- Pop the bottom element off the stack
|
||||
T pop()
|
||||
{
|
||||
return this->removeHead();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,10 +27,7 @@ Class
|
||||
Description
|
||||
A LIFO stack based on a singly-linked list.
|
||||
|
||||
Operations are push(), pop(), top(), bottom() and empty().
|
||||
|
||||
SourceFiles
|
||||
LIFOStack.C
|
||||
Stack operations are push(), pop(), top(), bottom().
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -53,7 +50,6 @@ class LIFOStack
|
||||
:
|
||||
public SLList<T>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
@ -64,34 +60,35 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
//- Return a copy of the top element
|
||||
T top() const
|
||||
{
|
||||
return this->first();
|
||||
}
|
||||
|
||||
//- Return a copy of the top element
|
||||
T top() const
|
||||
{
|
||||
return this->first();
|
||||
}
|
||||
//- Return a copy of the bottom element
|
||||
T bottom() const
|
||||
{
|
||||
return this->last();
|
||||
}
|
||||
|
||||
//- Return a copy of the bottom element
|
||||
T bottom() const
|
||||
{
|
||||
return this->last();
|
||||
}
|
||||
//- Push an element onto the front of the stack
|
||||
void push(const T& element)
|
||||
{
|
||||
this->insert(element);
|
||||
}
|
||||
|
||||
//- Move an element onto the front of the stack
|
||||
void push(T&& element)
|
||||
{
|
||||
this->insert(std::move(element));
|
||||
}
|
||||
|
||||
// Edit
|
||||
|
||||
//- Push an element onto the stack
|
||||
void push(const T& a)
|
||||
{
|
||||
this->insert(a);
|
||||
}
|
||||
|
||||
//- Pop the top element off the stack
|
||||
T pop()
|
||||
{
|
||||
return this->removeHead();
|
||||
}
|
||||
//- Pop the top element off the stack
|
||||
T pop()
|
||||
{
|
||||
return this->removeHead();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -32,18 +32,10 @@ Description
|
||||
#ifndef SLList_H
|
||||
#define SLList_H
|
||||
|
||||
#include "LList.H"
|
||||
#include "SLListBase.H"
|
||||
#include "LList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
template<class T>
|
||||
using SLList = LList<SLListBase, T>;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
#include "SLListFwd.H"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
52
src/OpenFOAM/containers/LinkedLists/user/SLListFwd.H
Normal file
52
src/OpenFOAM/containers/LinkedLists/user/SLListFwd.H
Normal file
@ -0,0 +1,52 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
InClass
|
||||
Foam::SLList
|
||||
|
||||
Description
|
||||
Forward declarations for SLList
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef SLListFwd_H
|
||||
#define SLListFwd_H
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
// Forward declarations
|
||||
class SLListBase;
|
||||
template<class LListBase, class T> class LList;
|
||||
|
||||
// Alias
|
||||
template<class T>
|
||||
using SLList = LList<SLListBase, T>;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -32,18 +32,9 @@ Description
|
||||
#ifndef SLPtrList_H
|
||||
#define SLPtrList_H
|
||||
|
||||
#include "LPtrList.H"
|
||||
#include "SLListBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
template<class T>
|
||||
using SLPtrList = LPtrList<SLListBase, T>;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
#include "LPtrList.H"
|
||||
#include "SLPtrListFwd.H"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
52
src/OpenFOAM/containers/LinkedLists/user/SLPtrListFwd.H
Normal file
52
src/OpenFOAM/containers/LinkedLists/user/SLPtrListFwd.H
Normal file
@ -0,0 +1,52 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
InClass
|
||||
Foam::SLPtrList
|
||||
|
||||
Description
|
||||
Forward declarations for SLPtrList
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef SLPtrListFwd_H
|
||||
#define SLPtrListFwd_H
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
// Forward declarations
|
||||
class SLListBase;
|
||||
template<class LListBase, class T> class LPtrList;
|
||||
|
||||
// Alias
|
||||
template<class T>
|
||||
using SLPtrList = LPtrList<SLListBase, T>;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -81,7 +81,7 @@ template<class T, class Container>
|
||||
Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
const labelUList& rowSizes,
|
||||
const T& t
|
||||
const T& val
|
||||
)
|
||||
:
|
||||
size_(rowSizes.size()),
|
||||
@ -95,7 +95,7 @@ Foam::CompactListList<T, Container>::CompactListList
|
||||
offsets_[i+1] = sumSize;
|
||||
}
|
||||
|
||||
m_.setSize(sumSize, t);
|
||||
m_.setSize(sumSize, val);
|
||||
}
|
||||
|
||||
|
||||
@ -109,19 +109,6 @@ Foam::CompactListList<T, Container>::CompactListList
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
CompactListList<T, Container>& lst,
|
||||
bool reuse
|
||||
)
|
||||
:
|
||||
size_(lst.size()),
|
||||
offsets_(lst.offsets_, reuse),
|
||||
m_(lst.m_, reuse)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Container>
|
||||
@ -219,14 +206,26 @@ void Foam::CompactListList<T, Container>::clear()
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
void Foam::CompactListList<T, Container>::transfer
|
||||
void Foam::CompactListList<T, Container>::swap
|
||||
(
|
||||
CompactListList<T, Container>& a
|
||||
CompactListList<T, Container>& lst
|
||||
)
|
||||
{
|
||||
size_ = a.size_;
|
||||
offsets_.transfer(a.offsets_);
|
||||
m_.transfer(a.m_);
|
||||
Foam::Swap(size_, lst.size_);
|
||||
offsets_.swap(lst.offsets_);
|
||||
m_.swap(lst.m_);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
void Foam::CompactListList<T, Container>::transfer
|
||||
(
|
||||
CompactListList<T, Container>& lst
|
||||
)
|
||||
{
|
||||
size_ = lst.size_;
|
||||
offsets_.transfer(lst.offsets_);
|
||||
m_.transfer(lst.m_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -119,11 +119,17 @@ public:
|
||||
//- Construct given list of row-sizes
|
||||
CompactListList(const labelUList& rowSizes, const T&);
|
||||
|
||||
//- Copy construct
|
||||
inline CompactListList(const CompactListList<T, Container>& lst);
|
||||
|
||||
//- Move construct
|
||||
inline CompactListList(CompactListList<T, Container>&& lst);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
explicit CompactListList(const Xfer<CompactListList<T, Container>>&);
|
||||
|
||||
//- Construct as copy or re-use as specified.
|
||||
CompactListList(CompactListList<T, Container>&, bool reuse);
|
||||
inline CompactListList(CompactListList<T, Container>& lst, bool reuse);
|
||||
|
||||
//- Construct from Istream.
|
||||
CompactListList(Istream&);
|
||||
@ -189,13 +195,17 @@ public:
|
||||
//- Return sizes (to be used e.g. for construction)
|
||||
labelList sizes() const;
|
||||
|
||||
//- Swap contents
|
||||
void swap(CompactListList<T, Container>& lst);
|
||||
|
||||
//- Transfer the contents of the argument CompactListList
|
||||
// into this CompactListList and annul the argument list.
|
||||
void transfer(CompactListList<T, Container>&);
|
||||
void transfer(CompactListList<T, Container>& lst);
|
||||
|
||||
//- Transfer the contents to the Xfer container
|
||||
inline Xfer<CompactListList<T, Container>> xfer();
|
||||
|
||||
|
||||
// Other
|
||||
|
||||
//- Return index into m
|
||||
@ -226,7 +236,13 @@ public:
|
||||
List<Container> operator()() const;
|
||||
|
||||
//- Assignment of all entries to the given value
|
||||
inline void operator=(const T&);
|
||||
inline void operator=(const T& val);
|
||||
|
||||
//- Copy assignment
|
||||
inline void operator=(const CompactListList<T, Container>& lst);
|
||||
|
||||
//- Move assignment
|
||||
inline void operator=(CompactListList<T, Container>&& lst);
|
||||
|
||||
|
||||
// Istream operator
|
||||
|
||||
@ -53,12 +53,47 @@ inline Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
const label mRows,
|
||||
const label nData,
|
||||
const T& t
|
||||
const T& val
|
||||
)
|
||||
:
|
||||
size_(mRows),
|
||||
offsets_(mRows+1, 0),
|
||||
m_(nData, t)
|
||||
m_(nData, val)
|
||||
{}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
const CompactListList<T, Container>& lst
|
||||
)
|
||||
:
|
||||
size_(lst.size()),
|
||||
offsets_(lst.offsets_),
|
||||
m_(lst.m_)
|
||||
{}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
CompactListList<T, Container>&& lst
|
||||
)
|
||||
{
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
CompactListList<T, Container>& lst,
|
||||
bool reuse
|
||||
)
|
||||
:
|
||||
size_(lst.size()),
|
||||
offsets_(lst.offsets_, reuse),
|
||||
m_(lst.m_, reuse)
|
||||
{}
|
||||
|
||||
|
||||
@ -220,7 +255,7 @@ inline Foam::UList<T> Foam::CompactListList<T, Container>::operator[]
|
||||
const label i
|
||||
)
|
||||
{
|
||||
label start = offsets_[i];
|
||||
const label start = offsets_[i];
|
||||
return UList<T>(m_.begin() + start, offsets_[i+1] - start);
|
||||
}
|
||||
|
||||
@ -232,7 +267,7 @@ Foam::CompactListList<T, Container>::operator[]
|
||||
const label i
|
||||
) const
|
||||
{
|
||||
label start = offsets_[i];
|
||||
const label start = offsets_[i];
|
||||
return UList<T>
|
||||
(
|
||||
const_cast<T*>(m_.begin() + start),
|
||||
@ -264,9 +299,31 @@ inline const T& Foam::CompactListList<T, Container>::operator()
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline void Foam::CompactListList<T, Container>::operator=(const T& t)
|
||||
inline void Foam::CompactListList<T, Container>::operator=(const T& val)
|
||||
{
|
||||
m_ = t;
|
||||
m_ = val;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline void Foam::CompactListList<T, Container>::operator=
|
||||
(
|
||||
const CompactListList<T, Container>& lst
|
||||
)
|
||||
{
|
||||
size_ = lst.size_;
|
||||
offsets_ = lst.offsets_,
|
||||
m_ = lst.m_;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline void Foam::CompactListList<T, Container>::operator=
|
||||
(
|
||||
CompactListList<T, Container>&& lst
|
||||
)
|
||||
{
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -418,11 +418,7 @@ inline void Foam::DynamicList<T, SizeMin>::swap
|
||||
const label oldSize2 = lst.expandStorage();
|
||||
|
||||
// Swap storage
|
||||
Foam::Swap
|
||||
(
|
||||
static_cast<UList<T>&>(cur),
|
||||
static_cast<UList<T>&>(lst)
|
||||
);
|
||||
UList<T>::swap(lst);
|
||||
|
||||
// Match capacity to the underlying allocated list size
|
||||
cur.setCapacity(cur.size());
|
||||
|
||||
@ -52,13 +52,6 @@ Foam::label Foam::FixedList<T, Size>::find
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
void Foam::FixedList<T, Size>::swap(FixedList<T, Size>& lst)
|
||||
{
|
||||
Foam::Swap(v_, lst.v_);
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
void Foam::FixedList<T, Size>::moveFirst(const label i)
|
||||
{
|
||||
@ -112,72 +105,74 @@ void Foam::FixedList<T, Size>::swapLast(const label i)
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, unsigned Size>
|
||||
bool Foam::FixedList<T, Size>::operator==(const FixedList<T, Size>& a) const
|
||||
bool Foam::FixedList<T, Size>::operator==(const FixedList<T, Size>& list) const
|
||||
{
|
||||
bool equal = true;
|
||||
|
||||
List_CONST_ACCESS(T, (*this), vp);
|
||||
List_CONST_ACCESS(T, (a), ap);
|
||||
List_CONST_ACCESS(T, *this, lhs);
|
||||
List_CONST_ACCESS(T, (list), rhs);
|
||||
|
||||
// List sizes are identical by definition (template parameter)
|
||||
for (unsigned i = 0; i < Size; ++i)
|
||||
{
|
||||
equal = (vp[i] == ap[i]);
|
||||
if (!equal) break;
|
||||
}
|
||||
|
||||
return equal;
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
bool Foam::FixedList<T, Size>::operator!=(const FixedList<T, Size>& a) const
|
||||
{
|
||||
return !operator==(a);
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
bool Foam::FixedList<T, Size>::operator<(const FixedList<T, Size>& a) const
|
||||
{
|
||||
List_CONST_ACCESS(T, *this, ptr1);
|
||||
List_CONST_ACCESS(T, a, ptr2);
|
||||
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
if (ptr1[i] < ptr2[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (ptr1[i] > ptr2[i])
|
||||
if (!(lhs[i] == rhs[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Contents look to be identical.
|
||||
// The sizes are identical by definition (template parameter)
|
||||
// Contents appear to be identical.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
bool Foam::FixedList<T, Size>::operator<(const FixedList<T, Size>& list) const
|
||||
{
|
||||
List_CONST_ACCESS(T, *this, lhs);
|
||||
List_CONST_ACCESS(T, (list), rhs);
|
||||
|
||||
// List sizes are identical by definition (template parameter)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
if (lhs[i] < rhs[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (rhs[i] < lhs[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Contents appear to be identical.
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
bool Foam::FixedList<T, Size>::operator>(const FixedList<T, Size>& a) const
|
||||
bool Foam::FixedList<T, Size>::operator!=(const FixedList<T, Size>& list) const
|
||||
{
|
||||
return a.operator<(*this);
|
||||
return !operator==(list);
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
bool Foam::FixedList<T, Size>::operator<=(const FixedList<T, Size>& a) const
|
||||
bool Foam::FixedList<T, Size>::operator>(const FixedList<T, Size>& list) const
|
||||
{
|
||||
return !operator>(a);
|
||||
return list.operator<(*this);
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
bool Foam::FixedList<T, Size>::operator>=(const FixedList<T, Size>& a) const
|
||||
bool Foam::FixedList<T, Size>::operator<=(const FixedList<T, Size>& list) const
|
||||
{
|
||||
return !operator<(a);
|
||||
return !list.operator<(*this);
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
bool Foam::FixedList<T, Size>::operator>=(const FixedList<T, Size>& list) const
|
||||
{
|
||||
return !operator<(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -43,16 +43,18 @@ SourceFiles
|
||||
#include "Hash.H"
|
||||
#include "autoPtr.H"
|
||||
#include "Swap.H"
|
||||
#include "SLListFwd.H"
|
||||
|
||||
#include <type_traits>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
// Forward declarations
|
||||
|
||||
template<class T, unsigned Size> class FixedList;
|
||||
|
||||
@ -64,10 +66,6 @@ Ostream& operator<<(Ostream&, const FixedList<T, Size>&);
|
||||
|
||||
template<class T> class UList;
|
||||
|
||||
class SLListBase;
|
||||
template<class LListBase, class T> class LList;
|
||||
template<class T>
|
||||
using SLList = LList<SLListBase, T>;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class FixedList Declaration
|
||||
@ -98,6 +96,42 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
// STL type definitions
|
||||
|
||||
//- The value type the FixedList contains
|
||||
typedef T value_type;
|
||||
|
||||
//- The pointer type for non-const access to value_type items
|
||||
typedef T* pointer;
|
||||
|
||||
//- The pointer type for const access to value_type items
|
||||
typedef const T* const_pointer;
|
||||
|
||||
//- The type used for storing into value_type objects
|
||||
typedef T& reference;
|
||||
|
||||
//- The type used for reading from constant value_type objects.
|
||||
typedef const T& const_reference;
|
||||
|
||||
//- Random access iterator for traversing FixedList
|
||||
typedef T* iterator;
|
||||
|
||||
//- Random access iterator for traversing FixedList
|
||||
typedef const T* const_iterator;
|
||||
|
||||
//- The type to represent the size of a FixedList
|
||||
typedef label size_type;
|
||||
|
||||
//- The difference between iterator objects
|
||||
typedef label difference_type;
|
||||
|
||||
//- Reverse iterator (non-const access)
|
||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
|
||||
//- Reverse iterator (const access)
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
|
||||
//- Hashing function class.
|
||||
// Use Hasher directly for contiguous data. Otherwise hash incrementally.
|
||||
template<class HashT=Hash<T>>
|
||||
@ -105,7 +139,7 @@ public:
|
||||
{
|
||||
inline unsigned operator()
|
||||
(
|
||||
const FixedList<T, Size>&,
|
||||
const FixedList<T, Size>& lst,
|
||||
unsigned seed = 0
|
||||
) const;
|
||||
};
|
||||
@ -120,7 +154,7 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Null constructor
|
||||
inline FixedList();
|
||||
inline FixedList() = default;
|
||||
|
||||
//- Construct from value
|
||||
explicit inline FixedList(const T& val);
|
||||
@ -131,7 +165,8 @@ public:
|
||||
//- Copy constructor
|
||||
inline FixedList(const FixedList<T, Size>& lst);
|
||||
|
||||
//- Move constructor
|
||||
//- Move construct by using move assignment for the individual
|
||||
//- list elements
|
||||
inline FixedList(FixedList<T, Size>&& lst);
|
||||
|
||||
//- Construct given begin/end iterators
|
||||
@ -230,11 +265,11 @@ public:
|
||||
|
||||
//- Dummy resize function
|
||||
// needed to make FixedList consistent with List
|
||||
inline void resize(const label s);
|
||||
inline void resize(const label n);
|
||||
|
||||
//- Dummy setSize function
|
||||
// needed to make FixedList consistent with List
|
||||
inline void setSize(const label s);
|
||||
inline void setSize(const label n);
|
||||
|
||||
//- Move element to the first position.
|
||||
void moveFirst(const label i);
|
||||
@ -248,9 +283,9 @@ public:
|
||||
//- Swap element with the last element.
|
||||
void swapLast(const label i);
|
||||
|
||||
//- Copy (not transfer) the argument contents
|
||||
// needed to make FixedList consistent with List
|
||||
void transfer(const FixedList<T, Size>& lst);
|
||||
//- Transfer by swapping using a move assignment for the content
|
||||
//- of the individual list elements
|
||||
inline void transfer(FixedList<T, Size>& lst);
|
||||
|
||||
|
||||
// Member operators
|
||||
@ -283,29 +318,7 @@ public:
|
||||
inline void operator=(FixedList<T, Size>&& lst);
|
||||
|
||||
|
||||
// STL type definitions
|
||||
|
||||
//- Type of values the FixedList contains
|
||||
typedef T value_type;
|
||||
|
||||
//- The type used for storing into value_type objects
|
||||
typedef T& reference;
|
||||
|
||||
//- The type used for reading from constant value_type objects.
|
||||
typedef const T& const_reference;
|
||||
|
||||
//- The type that can represent the difference between any two
|
||||
//- FixedList iterator objects
|
||||
typedef label difference_type;
|
||||
|
||||
//- The type that can represent the size of a FixedList
|
||||
typedef label size_type;
|
||||
|
||||
|
||||
// STL iterator
|
||||
|
||||
//- Random access iterator for traversing FixedList
|
||||
typedef T* iterator;
|
||||
// Random access iterator (non-const)
|
||||
|
||||
//- Return an iterator to begin traversing the FixedList
|
||||
inline iterator begin();
|
||||
@ -314,10 +327,7 @@ public:
|
||||
inline iterator end();
|
||||
|
||||
|
||||
// STL const_iterator
|
||||
|
||||
//- Random access iterator for traversing FixedList
|
||||
typedef const T* const_iterator;
|
||||
// Random access iterator (const)
|
||||
|
||||
//- Return const_iterator to begin traversing the constant FixedList
|
||||
inline const_iterator cbegin() const;
|
||||
@ -332,86 +342,7 @@ public:
|
||||
inline const_iterator end() const;
|
||||
|
||||
|
||||
// Reverse iterators
|
||||
|
||||
//- Generic const/non-const reverse iterator
|
||||
template<bool Const>
|
||||
class reverse_iterator_base
|
||||
{
|
||||
public:
|
||||
//- The const/non-const type for entries
|
||||
typedef typename std::conditional
|
||||
<Const, const T, T>::type value_type;
|
||||
|
||||
//- A pointer to a const/non-const entry
|
||||
typedef value_type* pointer;
|
||||
|
||||
//- A reference to a const/non-const entry
|
||||
typedef value_type& reference;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
//- The element pointer
|
||||
pointer ptr_;
|
||||
|
||||
public:
|
||||
|
||||
//- Construct null or from list element pointer
|
||||
inline reverse_iterator_base(pointer ptr = nullptr)
|
||||
:
|
||||
ptr_(ptr)
|
||||
{}
|
||||
|
||||
//- Copy construct
|
||||
inline reverse_iterator_base(const reverse_iterator_base& iter)
|
||||
:
|
||||
ptr_(iter.ptr_)
|
||||
{}
|
||||
|
||||
|
||||
//- Reverse increment
|
||||
inline void operator++()
|
||||
{
|
||||
--ptr_;
|
||||
}
|
||||
|
||||
//- Reverse increment
|
||||
inline reverse_iterator_base operator++(int)
|
||||
{
|
||||
reverse_iterator_base old(*this);
|
||||
--ptr_;
|
||||
return old;
|
||||
}
|
||||
|
||||
//- Dereference iterator
|
||||
reference operator*() const
|
||||
{
|
||||
return *ptr_;
|
||||
}
|
||||
|
||||
//- Dereference iterator
|
||||
pointer operator->() const
|
||||
{
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
//- Equality
|
||||
bool operator==(const reverse_iterator_base& iter) const
|
||||
{
|
||||
return ptr_ == iter.ptr_;
|
||||
}
|
||||
|
||||
//- inequality
|
||||
bool operator!=(const reverse_iterator_base& iter) const
|
||||
{
|
||||
return ptr_ != iter.ptr_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//- STL reverse_iterator
|
||||
typedef reverse_iterator_base<false> reverse_iterator;
|
||||
// Reverse iterator (non-const)
|
||||
|
||||
//- Return reverse_iterator to begin reverse traversing the FixedList
|
||||
inline reverse_iterator rbegin();
|
||||
@ -420,8 +351,7 @@ public:
|
||||
inline reverse_iterator rend();
|
||||
|
||||
|
||||
//- STL const reverse iterator
|
||||
typedef reverse_iterator_base<true> const_reverse_iterator;
|
||||
// Reverse iterator (const)
|
||||
|
||||
//- Return const_reverse_iterator to begin reverse traversing FixedList
|
||||
inline const_reverse_iterator crbegin() const;
|
||||
@ -447,31 +377,31 @@ public:
|
||||
//- Always false since zero-sized FixedList is compile-time disabled.
|
||||
inline bool empty() const;
|
||||
|
||||
//- Swap content with another FixedList of the same type.
|
||||
void swap(FixedList<T, Size>& lst);
|
||||
//- Swap lists by swapping the content of the individual list elements
|
||||
inline void swap(FixedList<T, Size>& lst);
|
||||
|
||||
|
||||
// STL member operators
|
||||
|
||||
//- Equality operation on FixedLists of the same type.
|
||||
// Returns true when the FixedLists are element-wise equal
|
||||
// (using FixedList::value_type::operator==). Takes linear time
|
||||
bool operator==(const FixedList<T, Size>& a) const;
|
||||
// (using FixedList::value_type::operator==). Takes linear time
|
||||
bool operator==(const FixedList<T, Size>& list) const;
|
||||
|
||||
//- The opposite of the equality operation. Takes linear time
|
||||
bool operator!=(const FixedList<T, Size>& a) const;
|
||||
bool operator!=(const FixedList<T, Size>& list) const;
|
||||
|
||||
//- Compare two FixedLists lexicographically. Takes linear time
|
||||
bool operator<(const FixedList<T, Size>& a) const;
|
||||
bool operator<(const FixedList<T, Size>& list) const;
|
||||
|
||||
//- Compare two FixedLists lexicographically. Takes linear time
|
||||
bool operator>(const FixedList<T, Size>& a) const;
|
||||
bool operator>(const FixedList<T, Size>& list) const;
|
||||
|
||||
//- Return true if !(a > b). Takes linear time
|
||||
bool operator<=(const FixedList<T, Size>& a) const;
|
||||
bool operator<=(const FixedList<T, Size>& list) const;
|
||||
|
||||
//- Return true if !(a < b). Takes linear time
|
||||
bool operator>=(const FixedList<T, Size>& a) const;
|
||||
bool operator>=(const FixedList<T, Size>& list) const;
|
||||
|
||||
|
||||
// Writing
|
||||
@ -487,27 +417,28 @@ public:
|
||||
|
||||
// IOstream operators
|
||||
|
||||
//- Read List from Istream, discarding contents of existing List
|
||||
//- Read from Istream, discarding contents of existing List
|
||||
friend Istream& operator>> <T, Size>
|
||||
(
|
||||
Istream& is,
|
||||
FixedList<T, Size>& L
|
||||
FixedList<T, Size>& lst
|
||||
);
|
||||
|
||||
//- Write List to Ostream, as per writeList() with shortListLen=10
|
||||
//- Write to Ostream, as per writeList() with shortListLen=10
|
||||
friend Ostream& operator<< <T, Size>
|
||||
(
|
||||
Ostream& os,
|
||||
const FixedList<T, Size>& L
|
||||
const FixedList<T, Size>& lst
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// Global Functions
|
||||
|
||||
// Exchange contents of lists - see FixedList::swap().
|
||||
//- Swap FixedList contents - see FixedList::swap().
|
||||
// Internally this actually swaps the individual list elements
|
||||
template<class T, unsigned Size>
|
||||
inline void Swap(FixedList<T,Size>& a, FixedList<T,Size>& b);
|
||||
inline void Swap(FixedList<T,Size>& lhs, FixedList<T,Size>& rhs);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -32,11 +32,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, unsigned Size>
|
||||
inline Foam::FixedList<T, Size>::FixedList()
|
||||
{}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
inline Foam::FixedList<T, Size>::FixedList(const T& val)
|
||||
{
|
||||
@ -62,7 +57,7 @@ inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst)
|
||||
{
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = lst[i];
|
||||
v_[i] = lst.v_[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,9 +65,6 @@ inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst)
|
||||
template<class T, unsigned Size>
|
||||
inline Foam::FixedList<T, Size>::FixedList(FixedList<T, Size>&& lst)
|
||||
{
|
||||
// No significant speedup observed for copy assignment on simple types,
|
||||
// use move assignment for generality with more complex types
|
||||
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = std::move(lst.v_[i]);
|
||||
@ -82,7 +74,7 @@ inline Foam::FixedList<T, Size>::FixedList(FixedList<T, Size>&& lst)
|
||||
|
||||
template<class T, unsigned Size>
|
||||
template<class InputIterator>
|
||||
Foam::FixedList<T, Size>::FixedList
|
||||
inline Foam::FixedList<T, Size>::FixedList
|
||||
(
|
||||
InputIterator begIter,
|
||||
InputIterator endIter
|
||||
@ -130,7 +122,7 @@ inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
|
||||
{
|
||||
checkSize(lst.size());
|
||||
|
||||
typename SLList<T>::const_iterator iter = lst.begin();
|
||||
auto iter = lst.begin();
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = *iter;
|
||||
@ -246,28 +238,38 @@ inline bool Foam::FixedList<T, Size>::found
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
inline void Foam::FixedList<T, Size>::resize(const label s)
|
||||
inline void Foam::FixedList<T, Size>::resize(const label n)
|
||||
{
|
||||
#ifdef FULLDEBUG
|
||||
checkSize(s);
|
||||
checkSize(n);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T, unsigned Size>
|
||||
inline void Foam::FixedList<T, Size>::setSize(const label s)
|
||||
inline void Foam::FixedList<T, Size>::setSize(const label n)
|
||||
{
|
||||
#ifdef FULLDEBUG
|
||||
checkSize(s);
|
||||
checkSize(n);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst)
|
||||
inline void Foam::FixedList<T, Size>::swap(FixedList<T, Size>& lst)
|
||||
{
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = lst[i];
|
||||
Foam::Swap(v_[i], lst.v_[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
inline void Foam::FixedList<T, Size>::transfer(FixedList<T, Size>& lst)
|
||||
{
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
v_[i] = std::move(lst[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,7 +446,7 @@ template<class T, unsigned Size>
|
||||
inline typename Foam::FixedList<T, Size>::iterator
|
||||
Foam::FixedList<T, Size>::end()
|
||||
{
|
||||
return &v_[Size];
|
||||
return (v_ + Size);
|
||||
}
|
||||
|
||||
|
||||
@ -452,7 +454,7 @@ template<class T, unsigned Size>
|
||||
inline typename Foam::FixedList<T, Size>::const_iterator
|
||||
Foam::FixedList<T, Size>::end() const
|
||||
{
|
||||
return &v_[Size];
|
||||
return (v_ + Size);
|
||||
}
|
||||
|
||||
|
||||
@ -460,7 +462,7 @@ template<class T, unsigned Size>
|
||||
inline typename Foam::FixedList<T, Size>::const_iterator
|
||||
Foam::FixedList<T, Size>::cend() const
|
||||
{
|
||||
return &v_[Size];
|
||||
return (v_ + Size);
|
||||
}
|
||||
|
||||
|
||||
@ -468,7 +470,7 @@ template<class T, unsigned Size>
|
||||
inline typename Foam::FixedList<T, Size>::reverse_iterator
|
||||
Foam::FixedList<T, Size>::rbegin()
|
||||
{
|
||||
return reverse_iterator(&v_[Size-1]);
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
|
||||
|
||||
@ -476,7 +478,7 @@ template<class T, unsigned Size>
|
||||
inline typename Foam::FixedList<T, Size>::const_reverse_iterator
|
||||
Foam::FixedList<T, Size>::rbegin() const
|
||||
{
|
||||
return const_reverse_iterator(&v_[Size-1]);
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
|
||||
|
||||
@ -484,7 +486,7 @@ template<class T, unsigned Size>
|
||||
inline typename Foam::FixedList<T, Size>::const_reverse_iterator
|
||||
Foam::FixedList<T, Size>::crbegin() const
|
||||
{
|
||||
return const_reverse_iterator(&v_[Size-1]);
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
|
||||
|
||||
@ -492,7 +494,7 @@ template<class T, unsigned Size>
|
||||
inline typename Foam::FixedList<T, Size>::reverse_iterator
|
||||
Foam::FixedList<T, Size>::rend()
|
||||
{
|
||||
return reverse_iterator(&v_[-1]);
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
|
||||
|
||||
@ -500,7 +502,7 @@ template<class T, unsigned Size>
|
||||
inline typename Foam::FixedList<T, Size>::const_reverse_iterator
|
||||
Foam::FixedList<T, Size>::rend() const
|
||||
{
|
||||
return const_reverse_iterator(&v_[-1]);
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
|
||||
@ -508,7 +510,7 @@ template<class T, unsigned Size>
|
||||
inline typename Foam::FixedList<T, Size>::const_reverse_iterator
|
||||
Foam::FixedList<T, Size>::crend() const
|
||||
{
|
||||
return const_reverse_iterator(&v_[-1]);
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
|
||||
@ -562,9 +564,9 @@ inline unsigned Foam::FixedList<T, Size>::Hash<HashT>::operator()
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, unsigned Size>
|
||||
void Foam::Swap(FixedList<T, Size>& a, FixedList<T, Size>& b)
|
||||
inline void Foam::Swap(FixedList<T, Size>& lhs, FixedList<T, Size>& rhs)
|
||||
{
|
||||
a.swap(b);
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -67,7 +67,7 @@ Foam::Ostream& Foam::FixedList<T, Size>::writeList
|
||||
const label shortListLen
|
||||
) const
|
||||
{
|
||||
const FixedList<T, Size>& L = *this;
|
||||
const FixedList<T, Size>& lst = *this;
|
||||
|
||||
// Write list contents depending on data format
|
||||
if (os.format() == IOstream::ASCII || !contiguous<T>())
|
||||
@ -76,9 +76,9 @@ Foam::Ostream& Foam::FixedList<T, Size>::writeList
|
||||
bool uniform = (Size > 1 && contiguous<T>());
|
||||
if (uniform)
|
||||
{
|
||||
forAll(L, i)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
if (L[i] != L[0])
|
||||
if (lst[i] != lst[0])
|
||||
{
|
||||
uniform = false;
|
||||
break;
|
||||
@ -92,7 +92,7 @@ Foam::Ostream& Foam::FixedList<T, Size>::writeList
|
||||
os << Size << token::BEGIN_BLOCK;
|
||||
|
||||
// Contents
|
||||
os << L[0];
|
||||
os << lst[0];
|
||||
|
||||
// End delimiter
|
||||
os << token::END_BLOCK;
|
||||
@ -107,10 +107,10 @@ Foam::Ostream& Foam::FixedList<T, Size>::writeList
|
||||
os << token::BEGIN_LIST;
|
||||
|
||||
// Contents
|
||||
forAll(L, i)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
if (i) os << token::SPACE;
|
||||
os << L[i];
|
||||
os << lst[i];
|
||||
}
|
||||
|
||||
// End delimiter
|
||||
@ -122,9 +122,9 @@ Foam::Ostream& Foam::FixedList<T, Size>::writeList
|
||||
os << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
// Contents
|
||||
forAll(L, i)
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
os << L[i] << nl;
|
||||
os << lst[i] << nl;
|
||||
}
|
||||
|
||||
// End delimiter
|
||||
@ -133,10 +133,10 @@ Foam::Ostream& Foam::FixedList<T, Size>::writeList
|
||||
}
|
||||
else
|
||||
{
|
||||
// Contents are binary and contiguous
|
||||
// Binary, contiguous
|
||||
|
||||
// write(...) includes surrounding start/end delimiters
|
||||
os.write(reinterpret_cast<const char*>(L.cdata()), Size*sizeof(T));
|
||||
os.write(reinterpret_cast<const char*>(lst.cdata()), Size*sizeof(T));
|
||||
}
|
||||
|
||||
os.check(FUNCTION_NAME);
|
||||
@ -154,7 +154,7 @@ Foam::FixedList<T, Size>::FixedList(Istream& is)
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
|
||||
Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& lst)
|
||||
{
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
@ -169,17 +169,17 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
|
||||
|
||||
if (firstToken.isCompound())
|
||||
{
|
||||
L = dynamicCast<token::Compound<List<T>>>
|
||||
lst = dynamicCast<token::Compound<List<T>>>
|
||||
(
|
||||
firstToken.transferCompoundToken(is)
|
||||
);
|
||||
}
|
||||
else if (firstToken.isLabel())
|
||||
{
|
||||
label s = firstToken.labelToken();
|
||||
const label len = firstToken.labelToken();
|
||||
|
||||
// Set list length to that read
|
||||
L.checkSize(s);
|
||||
// List lengths must match
|
||||
lst.checkSize(len);
|
||||
}
|
||||
else if (!firstToken.isPunctuation())
|
||||
{
|
||||
@ -202,7 +202,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
|
||||
{
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
is >> L[i];
|
||||
is >> lst[i];
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
@ -224,7 +224,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
|
||||
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
L[i] = element;
|
||||
lst[i] = element; // Copy the value
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,9 +233,9 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
|
||||
}
|
||||
else
|
||||
{
|
||||
// contents are binary and contiguous
|
||||
// Binary and contiguous
|
||||
|
||||
is.read(reinterpret_cast<char*>(L.data()), Size*sizeof(T));
|
||||
is.read(reinterpret_cast<char*>(lst.data()), Size*sizeof(T));
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
@ -249,9 +249,9 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
|
||||
|
||||
|
||||
template<class T, unsigned Size>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& L)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& lst)
|
||||
{
|
||||
return L.writeList(os, 10);
|
||||
return lst.writeList(os, 10);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -373,6 +373,15 @@ Foam::List<T>::List(SortableList<T>&& lst)
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::List<T>::List(SLList<T>&& lst)
|
||||
:
|
||||
UList<T>(nullptr, 0)
|
||||
{
|
||||
operator=(std::move(lst));
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
@ -530,9 +539,11 @@ void Foam::List<T>::operator=(const List<T>& lst)
|
||||
template<class T>
|
||||
void Foam::List<T>::operator=(const SLList<T>& lst)
|
||||
{
|
||||
reAlloc(lst.size());
|
||||
const label len = lst.size();
|
||||
|
||||
if (this->size_)
|
||||
reAlloc(len);
|
||||
|
||||
if (len)
|
||||
{
|
||||
label i = 0;
|
||||
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
|
||||
@ -631,6 +642,22 @@ void Foam::List<T>::operator=(SortableList<T>&& lst)
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::List<T>::operator=(SLList<T>&& lst)
|
||||
{
|
||||
const label len = lst.size();
|
||||
|
||||
reAlloc(len);
|
||||
|
||||
for (label i = 0; i < len; ++i)
|
||||
{
|
||||
this->operator[](i) = std::move(lst.removeHead());
|
||||
}
|
||||
|
||||
lst.clear();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
|
||||
|
||||
#include "ListIO.C"
|
||||
|
||||
@ -43,6 +43,8 @@ SourceFiles
|
||||
#include "UList.H"
|
||||
#include "autoPtr.H"
|
||||
#include "Xfer.H"
|
||||
#include "SLListFwd.H"
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -57,15 +59,9 @@ class Ostream;
|
||||
|
||||
template<class T> class List;
|
||||
template<class T, unsigned Size> class FixedList;
|
||||
template<class T> class PtrList;
|
||||
|
||||
class SLListBase;
|
||||
template<class LListBase, class T> class LList;
|
||||
template<class T>
|
||||
using SLList = LList<SLListBase, T>;
|
||||
|
||||
template<class T, int SizeMin> class DynamicList;
|
||||
|
||||
template<class T> class PtrList;
|
||||
template<class T> class SortableList;
|
||||
template<class T> class IndirectList;
|
||||
template<class T> class UIndirectList;
|
||||
@ -73,6 +69,7 @@ template<class T> class BiIndirectList;
|
||||
|
||||
template<class T> Istream& operator>>(Istream& is, List<T>& L);
|
||||
|
||||
// Commonly required list types
|
||||
typedef List<char> charList;
|
||||
|
||||
|
||||
@ -217,6 +214,9 @@ public:
|
||||
//- Move construct from SortableList
|
||||
List(SortableList<T>&& lst);
|
||||
|
||||
//- Move construct from SLList
|
||||
List(SLList<T>&& lst);
|
||||
|
||||
//- Construct from Istream
|
||||
List(Istream& is);
|
||||
|
||||
@ -326,6 +326,9 @@ public:
|
||||
//- Move assignment. Takes constant time.
|
||||
void operator=(SortableList<T>&& lst);
|
||||
|
||||
//- Move assignment. Takes constant time
|
||||
void operator=(SLList<T>&& lst);
|
||||
|
||||
|
||||
// Istream operator
|
||||
|
||||
|
||||
@ -41,10 +41,10 @@ Foam::List<T>::List(Istream& is)
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
|
||||
Foam::Istream& Foam::operator>>(Istream& is, List<T>& lst)
|
||||
{
|
||||
// Anull list
|
||||
L.setSize(0);
|
||||
lst.setSize(0);
|
||||
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
@ -52,22 +52,28 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
|
||||
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
// Compound: simply transfer contents
|
||||
if (firstToken.isCompound())
|
||||
{
|
||||
L.transfer
|
||||
lst.transfer
|
||||
(
|
||||
dynamicCast<token::Compound<List<T>>>
|
||||
(
|
||||
firstToken.transferCompoundToken(is)
|
||||
)
|
||||
);
|
||||
|
||||
return is;
|
||||
}
|
||||
else if (firstToken.isLabel())
|
||||
|
||||
|
||||
// Label: could be int(..), int{...} or just a plain '0'
|
||||
if (firstToken.isLabel())
|
||||
{
|
||||
const label sz = firstToken.labelToken();
|
||||
const label len = firstToken.labelToken();
|
||||
|
||||
// Set list length to that read
|
||||
L.setSize(sz);
|
||||
lst.setSize(len);
|
||||
|
||||
// Read list contents depending on data format
|
||||
|
||||
@ -76,13 +82,13 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
|
||||
// Read beginning of contents
|
||||
const char delimiter = is.readBeginList("List");
|
||||
|
||||
if (sz)
|
||||
if (len)
|
||||
{
|
||||
if (delimiter == token::BEGIN_LIST)
|
||||
{
|
||||
for (label i=0; i<sz; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
is >> L[i];
|
||||
is >> lst[i];
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
@ -103,9 +109,9 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
|
||||
"reading the single entry"
|
||||
);
|
||||
|
||||
for (label i=0; i<sz; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
L[i] = element;
|
||||
lst[i] = element; // Copy the value
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -113,22 +119,24 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
|
||||
// Read end of contents
|
||||
is.readEndList("List");
|
||||
}
|
||||
else
|
||||
else if (len)
|
||||
{
|
||||
// Contents are binary and contiguous
|
||||
// Non-empty, binary, contiguous
|
||||
|
||||
if (sz)
|
||||
{
|
||||
is.read(reinterpret_cast<char*>(L.data()), sz*sizeof(T));
|
||||
is.read(reinterpret_cast<char*>(lst.data()), len*sizeof(T));
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"operator>>(Istream&, List<T>&) : reading the binary block"
|
||||
);
|
||||
}
|
||||
is.fatalCheck
|
||||
(
|
||||
"operator>>(Istream&, List<T>&) : reading the binary block"
|
||||
);
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
else if (firstToken.isPunctuation())
|
||||
|
||||
|
||||
// "(...)" : read as SLList and transfer contents
|
||||
if (firstToken.isPunctuation())
|
||||
{
|
||||
if (firstToken.pToken() != token::BEGIN_LIST)
|
||||
{
|
||||
@ -138,23 +146,22 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
// Putback the opening bracket
|
||||
is.putBack(firstToken);
|
||||
is.putBack(firstToken); // Putback the opening bracket
|
||||
|
||||
// Read as a singly-linked list
|
||||
SLList<T> sll(is);
|
||||
SLList<T> sll(is); // Read as singly-linked list
|
||||
|
||||
// Convert the singly-linked list to this list
|
||||
L = sll;
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorInFunction(is)
|
||||
<< "incorrect first token, expected <int> or '(', found "
|
||||
<< firstToken.info()
|
||||
<< exit(FatalIOError);
|
||||
// Reallocate and move assign list elements
|
||||
lst = std::move(sll);
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
FatalIOErrorInFunction(is)
|
||||
<< "incorrect first token, expected <int> or '(', found "
|
||||
<< firstToken.info()
|
||||
<< exit(FatalIOError);
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
@ -265,26 +265,28 @@ Foam::label Foam::PackedBoolList::subset(const labelUIndList& indices)
|
||||
}
|
||||
|
||||
|
||||
Foam::Xfer<Foam::labelList> Foam::PackedBoolList::used() const
|
||||
Foam::labelList Foam::PackedBoolList::used() const
|
||||
{
|
||||
labelList lst(this->count());
|
||||
// Number of used (set) entries
|
||||
const label cnt = this->count();
|
||||
|
||||
if (lst.size())
|
||||
labelList lst(cnt);
|
||||
|
||||
if (cnt)
|
||||
{
|
||||
label nElem = 0;
|
||||
// The length of the input list
|
||||
const label len = this->size();
|
||||
|
||||
forAll(*this, elemI)
|
||||
for (label i=0, usedi=0; (i < len && usedi < cnt); ++i)
|
||||
{
|
||||
if (get(elemI))
|
||||
if (get(i))
|
||||
{
|
||||
lst[nElem++] = elemI;
|
||||
lst[usedi++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
lst.setSize(nElem);
|
||||
}
|
||||
|
||||
return lst.xfer();
|
||||
return lst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -91,7 +91,7 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
inline PackedBoolList();
|
||||
PackedBoolList() = default;
|
||||
|
||||
//- Construct from Istream
|
||||
PackedBoolList(Istream& is);
|
||||
@ -102,17 +102,17 @@ public:
|
||||
//- Construct with given size and value for all elements
|
||||
inline PackedBoolList(const label size, const bool val);
|
||||
|
||||
//- Copy constructor
|
||||
//- Copy construct
|
||||
inline PackedBoolList(const PackedBoolList& lst);
|
||||
|
||||
//- Copy constructor
|
||||
//- Copy construct
|
||||
explicit inline PackedBoolList(const PackedList<1>& lst);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
inline PackedBoolList(const Xfer<PackedBoolList>& lst);
|
||||
//- Move construct
|
||||
inline PackedBoolList(PackedBoolList&& lst);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
inline PackedBoolList(const Xfer<PackedList<1>>& lst);
|
||||
//- Move construct
|
||||
inline PackedBoolList(PackedList<1>&& lst);
|
||||
|
||||
//- Construct with given size and list of labels to set as true.
|
||||
inline PackedBoolList(const label size, const labelUList& indices);
|
||||
@ -137,7 +137,7 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
// Access
|
||||
|
||||
using PackedList<1>::set;
|
||||
using PackedList<1>::unset;
|
||||
@ -175,12 +175,11 @@ public:
|
||||
// Return number of elements subsetted.
|
||||
label subset(const labelUIndList& indices);
|
||||
|
||||
|
||||
//- Return indices of the used (true) elements as a list of labels
|
||||
Xfer<labelList> used() const;
|
||||
labelList used() const;
|
||||
|
||||
|
||||
// Edit
|
||||
// Edit
|
||||
|
||||
//- Transfer the contents of the argument list into this list
|
||||
//- and annul the argument list.
|
||||
@ -190,21 +189,24 @@ public:
|
||||
//- and annul the argument list.
|
||||
inline void transfer(PackedList<1>& lst);
|
||||
|
||||
//- Transfer contents to the Xfer container
|
||||
inline Xfer<PackedBoolList> xfer();
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Assignment of all entries to the given value.
|
||||
inline void operator=(const bool val);
|
||||
|
||||
//- Assignment operator.
|
||||
//- Copy assignment
|
||||
inline void operator=(const PackedBoolList& lst);
|
||||
|
||||
//- Assignment operator.
|
||||
//- Copy assignment
|
||||
inline void operator=(const PackedList<1>& lst);
|
||||
|
||||
//- Move assignment
|
||||
inline void operator=(PackedBoolList&& lst);
|
||||
|
||||
//- Move assignment
|
||||
inline void operator=(PackedList<1>&& lst);
|
||||
|
||||
//- Assignment operator.
|
||||
void operator=(const UList<bool>& lst);
|
||||
|
||||
|
||||
@ -25,12 +25,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::PackedBoolList::PackedBoolList()
|
||||
:
|
||||
PackedList<1>()
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::PackedBoolList::PackedBoolList(const label size)
|
||||
:
|
||||
PackedList<1>(size)
|
||||
@ -59,18 +53,20 @@ inline Foam::PackedBoolList::PackedBoolList(const PackedList<1>& lst)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::PackedBoolList::PackedBoolList(const Xfer<PackedBoolList>& lst)
|
||||
inline Foam::PackedBoolList::PackedBoolList(PackedBoolList&& lst)
|
||||
:
|
||||
PackedList<1>()
|
||||
{
|
||||
transfer(lst());
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::PackedBoolList::PackedBoolList(const Xfer<PackedList<1>>& lst)
|
||||
inline Foam::PackedBoolList::PackedBoolList(PackedList<1>&& lst)
|
||||
:
|
||||
PackedList<1>(lst)
|
||||
{}
|
||||
PackedList<1>()
|
||||
{
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::PackedBoolList::PackedBoolList(const UList<bool>& lst)
|
||||
@ -147,12 +143,6 @@ inline void Foam::PackedBoolList::transfer(PackedList<1>& lst)
|
||||
}
|
||||
|
||||
|
||||
inline Foam::Xfer<Foam::PackedBoolList> Foam::PackedBoolList::xfer()
|
||||
{
|
||||
return xferMove(*this);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
inline void Foam::PackedBoolList::operator=(const bool val)
|
||||
@ -173,6 +163,18 @@ inline void Foam::PackedBoolList::operator=(const PackedList<1>& lst)
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::PackedBoolList::operator=(PackedBoolList&& lst)
|
||||
{
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::PackedBoolList::operator=(PackedList<1>&& lst)
|
||||
{
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::PackedBoolList::operator=(const labelUList& indices)
|
||||
{
|
||||
clear();
|
||||
|
||||
@ -141,16 +141,16 @@ void Foam::PackedList<nBits>::flip()
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
Foam::Xfer<Foam::labelList> Foam::PackedList<nBits>::values() const
|
||||
Foam::labelList Foam::PackedList<nBits>::values() const
|
||||
{
|
||||
labelList elems(size_);
|
||||
|
||||
forAll(*this, i)
|
||||
for (label i=0; i < size_; ++i)
|
||||
{
|
||||
elems[i] = get(i);
|
||||
}
|
||||
|
||||
return elems.xfer();
|
||||
return elems;
|
||||
}
|
||||
|
||||
|
||||
@ -271,34 +271,34 @@ Foam::Istream& Foam::PackedList<nBits>::read(Istream& is)
|
||||
token firstTok(is);
|
||||
is.fatalCheck
|
||||
(
|
||||
"PackedList<nBits>::read(Istream&) : "
|
||||
"PackedList::read(Istream&) : "
|
||||
"reading first token"
|
||||
);
|
||||
|
||||
if (firstTok.isLabel())
|
||||
{
|
||||
const label sz = firstTok.labelToken();
|
||||
const label len = firstTok.labelToken();
|
||||
|
||||
// Set list length to that read
|
||||
lst.resize(sz);
|
||||
lst.resize(len);
|
||||
|
||||
// Read list contents depending on data format
|
||||
if (is.format() == IOstream::ASCII)
|
||||
{
|
||||
// Read beginning of contents
|
||||
const char delimiter = is.readBeginList("PackedList<nBits>");
|
||||
const char delimiter = is.readBeginList("PackedList");
|
||||
|
||||
if (sz)
|
||||
if (len)
|
||||
{
|
||||
if (delimiter == token::BEGIN_LIST)
|
||||
{
|
||||
for (label i=0; i<sz; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
lst[i] = lst.readValue(is);
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"PackedList<nBits>::read(Istream&) : "
|
||||
"PackedList::read(Istream&) : "
|
||||
"reading entry"
|
||||
);
|
||||
}
|
||||
@ -310,7 +310,7 @@ Foam::Istream& Foam::PackedList<nBits>::read(Istream& is)
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"PackedList<nBits>::read(Istream&) : "
|
||||
"PackedList::read(Istream&) : "
|
||||
"reading the single entry"
|
||||
);
|
||||
}
|
||||
@ -324,11 +324,11 @@ Foam::Istream& Foam::PackedList<nBits>::read(Istream& is)
|
||||
}
|
||||
|
||||
// Read end of contents
|
||||
is.readEndList("PackedList<nBits>");
|
||||
is.readEndList("PackedList");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sz)
|
||||
if (len)
|
||||
{
|
||||
is.read
|
||||
(
|
||||
@ -338,7 +338,7 @@ Foam::Istream& Foam::PackedList<nBits>::read(Istream& is)
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"PackedList<nBits>::read(Istream&) : "
|
||||
"PackedList::read(Istream&) : "
|
||||
"reading the binary block"
|
||||
);
|
||||
}
|
||||
@ -413,13 +413,13 @@ Foam::Ostream& Foam::PackedList<nBits>::writeList
|
||||
{
|
||||
const bool indexedOutput = (shortListLen < 0);
|
||||
const PackedList<nBits>& lst = *this;
|
||||
const label sz = lst.size();
|
||||
const label len = lst.size();
|
||||
|
||||
// Write list contents depending on data format
|
||||
if (os.format() == IOstream::ASCII)
|
||||
{
|
||||
// Can the contents be considered 'uniform' (ie, identical)?
|
||||
bool uniform = (sz > 1 && !indexedOutput);
|
||||
bool uniform = (len > 1 && !indexedOutput);
|
||||
if (uniform)
|
||||
{
|
||||
forAll(lst, i)
|
||||
@ -435,7 +435,7 @@ Foam::Ostream& Foam::PackedList<nBits>::writeList
|
||||
if (uniform)
|
||||
{
|
||||
// uniform values:
|
||||
os << sz << token::BEGIN_BLOCK << lst[0] << token::END_BLOCK;
|
||||
os << len << token::BEGIN_BLOCK << lst[0] << token::END_BLOCK;
|
||||
}
|
||||
else if (indexedOutput)
|
||||
{
|
||||
@ -457,10 +457,10 @@ Foam::Ostream& Foam::PackedList<nBits>::writeList
|
||||
|
||||
os << token::END_BLOCK << nl;
|
||||
}
|
||||
else if (!shortListLen || sz <= shortListLen)
|
||||
else if (!shortListLen || len <= shortListLen)
|
||||
{
|
||||
// Shorter list, or line-breaks suppressed
|
||||
os << sz << token::BEGIN_LIST;
|
||||
os << len << token::BEGIN_LIST;
|
||||
forAll(lst, i)
|
||||
{
|
||||
if (i) os << token::SPACE;
|
||||
@ -471,7 +471,7 @@ Foam::Ostream& Foam::PackedList<nBits>::writeList
|
||||
else
|
||||
{
|
||||
// Longer list
|
||||
os << nl << sz << nl << token::BEGIN_LIST << nl;
|
||||
os << nl << len << nl << token::BEGIN_LIST << nl;
|
||||
forAll(lst, i)
|
||||
{
|
||||
os << lst[i] << nl;
|
||||
@ -482,9 +482,9 @@ Foam::Ostream& Foam::PackedList<nBits>::writeList
|
||||
else
|
||||
{
|
||||
// Contents are binary and contiguous
|
||||
os << nl << sz << nl;
|
||||
os << nl << len << nl;
|
||||
|
||||
if (sz)
|
||||
if (len)
|
||||
{
|
||||
// write(...) includes surrounding start/end delimiters
|
||||
os.write
|
||||
@ -522,6 +522,13 @@ void Foam::PackedList<nBits>::operator=(const PackedList<nBits>& lst)
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
void Foam::PackedList<nBits>::operator=(PackedList<nBits>&& lst)
|
||||
{
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
void Foam::PackedList<nBits>::operator=(const labelUList& lst)
|
||||
{
|
||||
|
||||
@ -235,11 +235,11 @@ public:
|
||||
//- Construct from Istream
|
||||
inline PackedList(Istream& is);
|
||||
|
||||
//- Copy constructor
|
||||
//- Copy construct
|
||||
inline PackedList(const PackedList<nBits>& lst);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
inline PackedList(const Xfer<PackedList<nBits>>& lst);
|
||||
//- Move construct
|
||||
inline PackedList(PackedList<nBits>&& lst);
|
||||
|
||||
//- Construct from a list of labels
|
||||
explicit inline PackedList(const labelUList& lst);
|
||||
@ -297,7 +297,7 @@ public:
|
||||
unsigned int count() const;
|
||||
|
||||
//- Return the values as a list of labels
|
||||
Xfer<labelList> values() const;
|
||||
labelList values() const;
|
||||
|
||||
//- Print bit patterns, optionally output unused elements
|
||||
//
|
||||
@ -356,9 +356,6 @@ public:
|
||||
// and annul the argument list.
|
||||
inline void transfer(PackedList<nBits>& lst);
|
||||
|
||||
//- Transfer contents to the Xfer container
|
||||
inline Xfer<PackedList<nBits>> xfer();
|
||||
|
||||
|
||||
// IO
|
||||
|
||||
@ -407,9 +404,12 @@ public:
|
||||
//- Assignment of all entries to the given value. Takes linear time.
|
||||
inline void operator=(const unsigned int val);
|
||||
|
||||
//- Assignment operator.
|
||||
//- Copy assignment.
|
||||
void operator=(const PackedList<nBits>& lst);
|
||||
|
||||
//- Move assignment.
|
||||
void operator=(PackedList<nBits>&& lst);
|
||||
|
||||
//- Assignment operator.
|
||||
void operator=(const labelUList& lst);
|
||||
|
||||
|
||||
@ -223,9 +223,13 @@ inline Foam::PackedList<nBits>::PackedList(const PackedList<nBits>& lst)
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline Foam::PackedList<nBits>::PackedList(const Xfer<PackedList<nBits>>& lst)
|
||||
inline Foam::PackedList<nBits>::PackedList(PackedList<nBits>&& lst)
|
||||
:
|
||||
PackedListCore(),
|
||||
StorageList(),
|
||||
size_(0)
|
||||
{
|
||||
transfer(lst());
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
@ -956,13 +960,6 @@ inline void Foam::PackedList<nBits>::transfer(PackedList<nBits>& lst)
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline Foam::Xfer<Foam::PackedList<nBits>> Foam::PackedList<nBits>::xfer()
|
||||
{
|
||||
return xferMove(*this);
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline unsigned int Foam::PackedList<nBits>::get(const label i) const
|
||||
{
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -29,40 +29,30 @@ License
|
||||
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Foam::PtrList<T>::PtrList()
|
||||
Foam::PtrList<T>::PtrList(const PtrList<T>& lst)
|
||||
:
|
||||
UPtrList<T>()
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::PtrList<T>::PtrList(const label s)
|
||||
:
|
||||
UPtrList<T>(s)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::PtrList<T>::PtrList(const PtrList<T>& a)
|
||||
:
|
||||
UPtrList<T>(a.size())
|
||||
UPtrList<T>(lst.size())
|
||||
{
|
||||
forAll(*this, i)
|
||||
const label len = this->size();
|
||||
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
this->ptrs_[i] = (a[i]).clone().ptr();
|
||||
this->ptrs_[i] = (lst[i]).clone().ptr();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
template<class CloneArg>
|
||||
Foam::PtrList<T>::PtrList(const PtrList<T>& a, const CloneArg& cloneArg)
|
||||
Foam::PtrList<T>::PtrList(const PtrList<T>& lst, const CloneArg& cloneArg)
|
||||
:
|
||||
UPtrList<T>(a.size())
|
||||
UPtrList<T>(lst.size())
|
||||
{
|
||||
forAll(*this, i)
|
||||
const label len = this->size();
|
||||
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
this->ptrs_[i] = (a[i]).clone(cloneArg).ptr();
|
||||
this->ptrs_[i] = (lst[i]).clone(cloneArg).ptr();
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,36 +65,33 @@ Foam::PtrList<T>::PtrList(const Xfer<PtrList<T>>& lst)
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::PtrList<T>::PtrList(PtrList<T>& a, bool reuse)
|
||||
Foam::PtrList<T>::PtrList(PtrList<T>& lst, bool reuse)
|
||||
:
|
||||
UPtrList<T>(a, reuse)
|
||||
UPtrList<T>(lst, reuse)
|
||||
{
|
||||
if (!reuse)
|
||||
{
|
||||
forAll(*this, i)
|
||||
const label len = this->size();
|
||||
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
this->ptrs_[i] = (a[i]).clone().ptr();
|
||||
this->ptrs_[i] = (lst[i]).clone().ptr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::PtrList<T>::PtrList(const SLPtrList<T>& sll)
|
||||
Foam::PtrList<T>::PtrList(const SLPtrList<T>& lst)
|
||||
:
|
||||
UPtrList<T>(sll.size())
|
||||
UPtrList<T>(lst.size())
|
||||
{
|
||||
if (sll.size())
|
||||
if (lst.size())
|
||||
{
|
||||
label i = 0;
|
||||
for
|
||||
(
|
||||
typename SLPtrList<T>::const_iterator iter = sll.begin();
|
||||
iter != sll.end();
|
||||
++iter
|
||||
)
|
||||
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
|
||||
{
|
||||
this->ptrs_[i++] = (iter()).clone().ptr();
|
||||
this->ptrs_[i++] = (*iter).clone().ptr();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -115,7 +102,10 @@ Foam::PtrList<T>::PtrList(const SLPtrList<T>& sll)
|
||||
template<class T>
|
||||
Foam::PtrList<T>::~PtrList()
|
||||
{
|
||||
forAll(*this, i)
|
||||
const label len = this->size();
|
||||
|
||||
// Free old pointers
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
if (this->ptrs_[i])
|
||||
{
|
||||
@ -127,53 +117,12 @@ Foam::PtrList<T>::~PtrList()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
void Foam::PtrList<T>::setSize(const label newSize)
|
||||
{
|
||||
if (newSize < 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "bad set size " << newSize
|
||||
<< " for type " << typeid(T).name()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
label oldSize = this->size();
|
||||
|
||||
if (newSize == 0)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
else if (newSize < oldSize)
|
||||
{
|
||||
label i;
|
||||
for (i=newSize; i<oldSize; i++)
|
||||
{
|
||||
if (this->ptrs_[i])
|
||||
{
|
||||
delete this->ptrs_[i];
|
||||
}
|
||||
}
|
||||
|
||||
this->ptrs_.setSize(newSize);
|
||||
}
|
||||
else // newSize > oldSize
|
||||
{
|
||||
this->ptrs_.setSize(newSize);
|
||||
|
||||
label i;
|
||||
for (i=oldSize; i<newSize; i++)
|
||||
{
|
||||
this->ptrs_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::PtrList<T>::clear()
|
||||
{
|
||||
forAll(*this, i)
|
||||
const label len = this->size();
|
||||
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
if (this->ptrs_[i])
|
||||
{
|
||||
@ -181,109 +130,82 @@ void Foam::PtrList<T>::clear()
|
||||
}
|
||||
}
|
||||
|
||||
this->ptrs_.clear();
|
||||
UPtrList<T>::clear();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::PtrList<T>::transfer(PtrList<T>& a)
|
||||
void Foam::PtrList<T>::setSize(const label newLen)
|
||||
{
|
||||
clear();
|
||||
this->ptrs_.transfer(a.ptrs_);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::PtrList<T>::reorder(const labelUList& oldToNew)
|
||||
{
|
||||
if (oldToNew.size() != this->size())
|
||||
if (newLen <= 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Size of map (" << oldToNew.size()
|
||||
<< ") not equal to list size (" << this->size()
|
||||
<< ") for type " << typeid(T).name()
|
||||
<< abort(FatalError);
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
List<T*> newPtrs_(this->ptrs_.size(), reinterpret_cast<T*>(0));
|
||||
|
||||
forAll(*this, i)
|
||||
const label oldLen = this->size();
|
||||
if (newLen < oldLen)
|
||||
{
|
||||
label newI = oldToNew[i];
|
||||
|
||||
if (newI < 0 || newI >= this->size())
|
||||
// Truncate - free old pointers
|
||||
for (label i=newLen; i<oldLen; ++i)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Illegal index " << newI << nl
|
||||
<< "Valid indices are 0.." << this->size()-1
|
||||
<< " for type " << typeid(T).name()
|
||||
<< abort(FatalError);
|
||||
if (this->ptrs_[i])
|
||||
{
|
||||
delete this->ptrs_[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (newPtrs_[newI])
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "reorder map is not unique; element " << newI
|
||||
<< " already set for type " << typeid(T).name()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
newPtrs_[newI] = this->ptrs_[i];
|
||||
this->ptrs_.setSize(newLen);
|
||||
}
|
||||
|
||||
forAll(newPtrs_, i)
|
||||
else if (newLen > oldLen)
|
||||
{
|
||||
if (!newPtrs_[i])
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Element " << i << " not set after reordering with type "
|
||||
<< typeid(T).name() << nl << abort(FatalError);
|
||||
}
|
||||
// Extend - new elements initialized to nullptr
|
||||
this->ptrs_.setSize(newLen, reinterpret_cast<T*>(0));
|
||||
}
|
||||
|
||||
this->ptrs_.transfer(newPtrs_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
void Foam::PtrList<T>::operator=(const PtrList<T>& a)
|
||||
void Foam::PtrList<T>::operator=(const PtrList<T>& lst)
|
||||
{
|
||||
if (this == &a)
|
||||
if (this == &lst)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "attempted assignment to self for type " << typeid(T).name()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
if (this->size() == 0)
|
||||
{
|
||||
setSize(a.size());
|
||||
const label oldLen = this->size();
|
||||
const label newLen = lst.size();
|
||||
|
||||
forAll(*this, i)
|
||||
{
|
||||
this->ptrs_[i] = (a[i]).clone().ptr();
|
||||
}
|
||||
}
|
||||
else if (a.size() == this->size())
|
||||
// Truncate (frees old pointers) or extend the length
|
||||
setSize(newLen);
|
||||
|
||||
if (newLen < oldLen)
|
||||
{
|
||||
forAll(*this, i)
|
||||
// Copy values for existing entries
|
||||
for (label i=0; i<newLen; ++i)
|
||||
{
|
||||
(*this)[i] = a[i];
|
||||
(*this)[i] = lst[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "bad size: " << a.size()
|
||||
<< " for type " << typeid(T).name()
|
||||
<< abort(FatalError);
|
||||
// Copy values for existing entries
|
||||
for (label i=0; i<oldLen; ++i)
|
||||
{
|
||||
(*this)[i] = lst[i];
|
||||
}
|
||||
|
||||
// Clone pointers for new entries
|
||||
for (label i=oldLen; i<newLen; ++i)
|
||||
{
|
||||
this->ptrs_[i] = (lst[i]).clone().ptr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "PtrListIO.C"
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -25,11 +25,12 @@ Class
|
||||
Foam::PtrList
|
||||
|
||||
Description
|
||||
A templated 1D list of pointers to objects of type \<T\>, where the
|
||||
size of the array is known and used for subscript bounds checking, etc.
|
||||
A list of pointers to objects of type \<T\>, with allocation/deallocation
|
||||
management of the pointers.
|
||||
The operator[] returns a reference to the object, not the pointer.
|
||||
|
||||
The element operator [] returns a reference to the object rather than a
|
||||
pointer.
|
||||
See Also
|
||||
Foam::PtrList
|
||||
|
||||
SourceFiles
|
||||
PtrListI.H
|
||||
@ -42,27 +43,20 @@ SourceFiles
|
||||
#define PtrList_H
|
||||
|
||||
#include "UPtrList.H"
|
||||
#include "SLPtrListFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
// Forward declarations
|
||||
|
||||
template<class T> class autoPtr;
|
||||
template<class T> class tmp;
|
||||
|
||||
class SLListBase;
|
||||
template<class LListBase, class T> class LPtrList;
|
||||
template<class T>
|
||||
using SLPtrList = LPtrList<SLListBase, T>;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
template<class T> class PtrList;
|
||||
|
||||
template<class T>
|
||||
Istream& operator>>(Istream&, PtrList<T>&);
|
||||
template<class T> Istream& operator>>(Istream& is, PtrList<T>& lst);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
@ -81,103 +75,106 @@ protected:
|
||||
|
||||
//- Read from Istream using given Istream constructor class
|
||||
template<class INew>
|
||||
void read(Istream&, const INew& inewt);
|
||||
void read(Istream& is, const INew& inew);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Null Constructor
|
||||
PtrList();
|
||||
//- Construct null
|
||||
PtrList() = default;
|
||||
|
||||
//- Construct with size specified
|
||||
explicit PtrList(const label);
|
||||
//- Construct with specified size, each element initialized to nullptr
|
||||
explicit inline PtrList(const label nElem);
|
||||
|
||||
//- Copy constructor
|
||||
PtrList(const PtrList<T>&);
|
||||
//- Copy construct using 'clone()' method on each element
|
||||
PtrList(const PtrList<T>& lst);
|
||||
|
||||
//- Copy constructor with additional argument for clone
|
||||
//- Move construct
|
||||
inline PtrList(PtrList<T>&& lst);
|
||||
|
||||
//- Copy construct with additional argument for 'clone()'
|
||||
template<class CloneArg>
|
||||
PtrList(const PtrList<T>&, const CloneArg&);
|
||||
PtrList(const PtrList<T>& lst, const CloneArg& cloneArg);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
PtrList(const Xfer<PtrList<T>>&);
|
||||
PtrList(const Xfer<PtrList<T>>& lst);
|
||||
|
||||
//- Construct as copy or re-use as specified
|
||||
PtrList(PtrList<T>&, bool reuse);
|
||||
PtrList(PtrList<T>& lst, bool reuse);
|
||||
|
||||
//- Construct as copy of SLPtrList<T>
|
||||
explicit PtrList(const SLPtrList<T>&);
|
||||
explicit PtrList(const SLPtrList<T>& lst);
|
||||
|
||||
//- Construct from Istream using given Istream constructor class
|
||||
template<class INew>
|
||||
PtrList(Istream&, const INew&);
|
||||
PtrList(Istream& is, const INew& inew);
|
||||
|
||||
//- Construct from Istream using default Istream constructor class
|
||||
PtrList(Istream&);
|
||||
PtrList(Istream& is);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~PtrList();
|
||||
|
||||
|
||||
// Member functions
|
||||
// Member Functions
|
||||
|
||||
// Edit
|
||||
//- Clear the PtrList. Set size to zero and delete allocated entries
|
||||
void clear();
|
||||
|
||||
//- Reset size of PtrList. If extending the PtrList, new entries are
|
||||
// set to nullptr. If truncating the PtrList, removed entries are
|
||||
// deleted
|
||||
void setSize(const label);
|
||||
//- Reset size of PtrList.
|
||||
// New entries are initialized to nullptr, removed entries are deleted
|
||||
void setSize(const label newLen);
|
||||
|
||||
//- Alias for setSize(const label)
|
||||
inline void resize(const label);
|
||||
//- Reset size of PtrList.
|
||||
// New entries are initialized to nullptr, removed entries are deleted
|
||||
inline void resize(const label newLen);
|
||||
|
||||
//- Clear the PtrList, i.e. set size to zero deleting all the
|
||||
// allocated entries
|
||||
void clear();
|
||||
//- Append an element at the end of the list
|
||||
using UPtrList<T>::append;
|
||||
|
||||
//- Append an element at the end of the list
|
||||
inline void append(T*);
|
||||
inline void append(const autoPtr<T>&);
|
||||
inline void append(const tmp<T>&);
|
||||
//- Append an element at the end of the list
|
||||
inline void append(const autoPtr<T>& aptr);
|
||||
|
||||
//- Transfer the contents of the argument PtrList into this PtrList
|
||||
// and annul the argument list
|
||||
void transfer(PtrList<T>&);
|
||||
//- Append an element at the end of the list
|
||||
inline void append(const tmp<T>& tptr);
|
||||
|
||||
//- Transfer contents to the Xfer container
|
||||
inline Xfer<PtrList<T>> xfer();
|
||||
//- Transfer into this list and annul the argument list
|
||||
inline void transfer(PtrList<T>& lst);
|
||||
|
||||
//- Is element set
|
||||
inline bool set(const label) const;
|
||||
//- Transfer contents to the Xfer container
|
||||
inline Xfer<PtrList<T>> xfer();
|
||||
|
||||
//- Set element to given T* and return old element (can be nullptr)
|
||||
inline autoPtr<T> set(const label, T*);
|
||||
//- Return true if element is set (ie, not a nullptr)
|
||||
inline bool set(const label i) const;
|
||||
|
||||
//- Set element to given autoPtr<T> and return old element
|
||||
inline autoPtr<T> set(const label, const autoPtr<T>&);
|
||||
//- Set element to given pointer and return old element (can be null)
|
||||
inline autoPtr<T> set(const label i, T* ptr);
|
||||
|
||||
//- Set element to given tmp<T> and return old element
|
||||
inline autoPtr<T> set(const label, const tmp<T>&);
|
||||
//- Set element to given autoPtr and return old element
|
||||
inline autoPtr<T> set(const label i, const autoPtr<T>& aptr);
|
||||
|
||||
//- Reorders elements. Ordering does not have to be done in
|
||||
// ascending or descending order. Reordering has to be unique.
|
||||
// (is shuffle)
|
||||
void reorder(const labelUList&);
|
||||
//- Set element to given tmp and return old element
|
||||
inline autoPtr<T> set(const label i, const tmp<T>& tptr);
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
//- Assignment
|
||||
void operator=(const PtrList<T>&);
|
||||
//- Copy assignment.
|
||||
// For existing list entries, values are copied from the list.
|
||||
// For new list entries, pointers are cloned from the list.
|
||||
void operator=(const PtrList<T>& lst);
|
||||
|
||||
//- Move assignment
|
||||
inline void operator=(PtrList<T>&& lst);
|
||||
|
||||
|
||||
// IOstream operator
|
||||
|
||||
//- Read PtrList from Istream, discarding contents of existing PtrList
|
||||
friend Istream& operator>> <T>(Istream&, PtrList<T>&);
|
||||
friend Istream& operator>> <T>(Istream& is, PtrList<T>& lst);
|
||||
};
|
||||
|
||||
|
||||
@ -193,6 +190,7 @@ public:
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "PtrList.C"
|
||||
#include "PtrListIO.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -26,38 +26,42 @@ License
|
||||
#include "autoPtr.H"
|
||||
#include "tmp.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline Foam::PtrList<T>::PtrList(const label nElem)
|
||||
:
|
||||
UPtrList<T>(nElem)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::PtrList<T>::PtrList(PtrList<T>&& lst)
|
||||
:
|
||||
UPtrList<T>(std::move(lst))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline void Foam::PtrList<T>::resize(const label newSize)
|
||||
inline void Foam::PtrList<T>::resize(const label newLen)
|
||||
{
|
||||
this->setSize(newSize);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::PtrList<T>::append(T* ptr)
|
||||
{
|
||||
label sz = this->size();
|
||||
this->setSize(sz+1);
|
||||
this->ptrs_[sz] = ptr;
|
||||
this->setSize(newLen);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::PtrList<T>::append(const autoPtr<T>& aptr)
|
||||
{
|
||||
return append(const_cast<autoPtr<T>&>(aptr).ptr());
|
||||
return UPtrList<T>::append(const_cast<autoPtr<T>&>(aptr).ptr());
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::PtrList<T>::append
|
||||
(
|
||||
const tmp<T>& t
|
||||
)
|
||||
inline void Foam::PtrList<T>::append(const tmp<T>& tptr)
|
||||
{
|
||||
return append(const_cast<tmp<T>&>(t).ptr());
|
||||
return UPtrList<T>::append(const_cast<tmp<T>&>(tptr).ptr());
|
||||
}
|
||||
|
||||
|
||||
@ -92,10 +96,18 @@ template<class T>
|
||||
inline Foam::autoPtr<T> Foam::PtrList<T>::set
|
||||
(
|
||||
const label i,
|
||||
const tmp<T>& t
|
||||
const tmp<T>& tptr
|
||||
)
|
||||
{
|
||||
return set(i, const_cast<tmp<T>&>(t).ptr());
|
||||
return set(i, const_cast<tmp<T>&>(tptr).ptr());
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::PtrList<T>::transfer(PtrList<T>& lst)
|
||||
{
|
||||
this->clear();
|
||||
UPtrList<T>::swap(lst);
|
||||
}
|
||||
|
||||
|
||||
@ -106,4 +118,14 @@ inline Foam::Xfer<Foam::PtrList<T>> Foam::PtrList<T>::xfer()
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline void Foam::PtrList<T>::operator=(PtrList<T>&& lst)
|
||||
{
|
||||
this->clear();
|
||||
this->swap(lst);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -33,7 +33,7 @@ License
|
||||
|
||||
template<class T>
|
||||
template<class INew>
|
||||
void Foam::PtrList<T>::read(Istream& is, const INew& inewt)
|
||||
void Foam::PtrList<T>::read(Istream& is, const INew& inew)
|
||||
{
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
@ -41,58 +41,66 @@ void Foam::PtrList<T>::read(Istream& is, const INew& inewt)
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"PtrList<T>::read(Istream&, const INew&) : "
|
||||
"PtrList::read(Istream&) : "
|
||||
"reading first token"
|
||||
);
|
||||
|
||||
|
||||
// Label: could be int(..), int{...} or just a plain '0'
|
||||
if (firstToken.isLabel())
|
||||
{
|
||||
// Read size of list
|
||||
const label sz = firstToken.labelToken();
|
||||
const label len = firstToken.labelToken();
|
||||
|
||||
// Set list length to that read
|
||||
setSize(sz);
|
||||
setSize(len);
|
||||
|
||||
// Read beginning of contents
|
||||
const char delimiter = is.readBeginList("PtrList");
|
||||
|
||||
if (sz)
|
||||
if (len)
|
||||
{
|
||||
if (delimiter == token::BEGIN_LIST)
|
||||
{
|
||||
for (label i=0; i<sz; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
set(i, inewt(is));
|
||||
T* p = inew(is).ptr();
|
||||
set(i, p);
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"PtrList<T>::read(Istream&, const INew&) : "
|
||||
"PtrList::read(Istream&) : "
|
||||
"reading entry"
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
T* tPtr = inewt(is).ptr();
|
||||
set(0, tPtr);
|
||||
T* p = inew(is).ptr();
|
||||
set(0, p);
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"PtrList<T>::read(Istream&, const INew&) : "
|
||||
"PtrList::read(Istream&) : "
|
||||
"reading the single entry"
|
||||
);
|
||||
|
||||
for (label i=1; i<sz; ++i)
|
||||
for (label i=1; i<len; ++i)
|
||||
{
|
||||
set(i, tPtr->clone());
|
||||
set(i, p->clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read end of contents
|
||||
is.readEndList("PtrList");
|
||||
|
||||
return;
|
||||
}
|
||||
else if (firstToken.isPunctuation())
|
||||
|
||||
|
||||
// "(...)" : read as SLList and transfer contents
|
||||
if (firstToken.isPunctuation())
|
||||
{
|
||||
if (firstToken.pToken() != token::BEGIN_LIST)
|
||||
{
|
||||
@ -125,32 +133,28 @@ void Foam::PtrList<T>::read(Istream& is, const INew& inewt)
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
sllPtrs.append(inewt(is).ptr());
|
||||
sllPtrs.append(inew(is).ptr());
|
||||
is >> lastToken;
|
||||
}
|
||||
|
||||
setSize(sllPtrs.size());
|
||||
|
||||
// A list of pointers - can simply copy
|
||||
label i = 0;
|
||||
for
|
||||
(
|
||||
typename SLList<T*>::iterator iter = sllPtrs.begin();
|
||||
iter != sllPtrs.end();
|
||||
++iter
|
||||
)
|
||||
for (T* ptr : sllPtrs)
|
||||
{
|
||||
set(i++, iter());
|
||||
set(i++, ptr);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorInFunction
|
||||
(
|
||||
is
|
||||
) << "incorrect first token, expected <int> or '(', found "
|
||||
<< firstToken.info()
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
FatalIOErrorInFunction
|
||||
(
|
||||
is
|
||||
) << "incorrect first token, expected <int> or '(', found "
|
||||
<< firstToken.info()
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
|
||||
@ -158,9 +162,9 @@ void Foam::PtrList<T>::read(Istream& is, const INew& inewt)
|
||||
|
||||
template<class T>
|
||||
template<class INew>
|
||||
Foam::PtrList<T>::PtrList(Istream& is, const INew& inewt)
|
||||
Foam::PtrList<T>::PtrList(Istream& is, const INew& inew)
|
||||
{
|
||||
read(is, inewt);
|
||||
read(is, inew);
|
||||
}
|
||||
|
||||
|
||||
@ -174,10 +178,10 @@ Foam::PtrList<T>::PtrList(Istream& is)
|
||||
// * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Foam::Istream& Foam::operator>>(Istream& is, PtrList<T>& L)
|
||||
Foam::Istream& Foam::operator>>(Istream& is, PtrList<T>& lst)
|
||||
{
|
||||
L.clear();
|
||||
L.read(is, INew<T>());
|
||||
lst.clear();
|
||||
lst.read(is, INew<T>());
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
@ -39,16 +39,16 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
|
||||
{
|
||||
const UIndirectList<T>& L = *this;
|
||||
|
||||
const label sz = L.size();
|
||||
const label len = L.size();
|
||||
|
||||
// Write list contents depending on data format
|
||||
if (os.format() == IOstream::ASCII || !contiguous<T>())
|
||||
{
|
||||
// Can the contents be considered 'uniform' (ie, identical)?
|
||||
bool uniform = (sz > 1 && contiguous<T>());
|
||||
bool uniform = (len > 1 && contiguous<T>());
|
||||
if (uniform)
|
||||
{
|
||||
for (label i=1; i < sz; ++i)
|
||||
for (label i=1; i < len; ++i)
|
||||
{
|
||||
if (L[i] != L[0])
|
||||
{
|
||||
@ -61,7 +61,7 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
|
||||
if (uniform)
|
||||
{
|
||||
// Size and start delimiter
|
||||
os << sz << token::BEGIN_BLOCK;
|
||||
os << len << token::BEGIN_BLOCK;
|
||||
|
||||
// Contents
|
||||
os << L[0];
|
||||
@ -71,15 +71,15 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
|
||||
}
|
||||
else if
|
||||
(
|
||||
sz <= 1 || !shortListLen
|
||||
|| (sz <= shortListLen && contiguous<T>())
|
||||
len <= 1 || !shortListLen
|
||||
|| (len <= shortListLen && contiguous<T>())
|
||||
)
|
||||
{
|
||||
// Size and start delimiter
|
||||
os << sz << token::BEGIN_LIST;
|
||||
os << len << token::BEGIN_LIST;
|
||||
|
||||
// Contents
|
||||
for (label i=0; i < sz; ++i)
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
if (i) os << token::SPACE;
|
||||
os << L[i];
|
||||
@ -91,10 +91,10 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
|
||||
else
|
||||
{
|
||||
// Size and start delimiter
|
||||
os << nl << sz << nl << token::BEGIN_LIST << nl;
|
||||
os << nl << len << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
// Contents
|
||||
for (label i=0; i < sz; ++i)
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
os << L[i] << nl;
|
||||
}
|
||||
@ -106,16 +106,16 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
|
||||
else
|
||||
{
|
||||
// Contents are binary and contiguous
|
||||
os << nl << sz << nl;
|
||||
os << nl << len << nl;
|
||||
|
||||
if (sz)
|
||||
if (len)
|
||||
{
|
||||
// The TOTAL number of bytes to be written.
|
||||
// - possibly add start delimiter
|
||||
os.beginRaw(sz*sizeof(T));
|
||||
os.beginRaw(len*sizeof(T));
|
||||
|
||||
// Contents
|
||||
for (label i=0; i < sz; ++i)
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
os.writeRaw
|
||||
(
|
||||
|
||||
@ -63,9 +63,9 @@ Foam::labelRange Foam::UList<T>::validateRange
|
||||
auto iter = start_size.begin();
|
||||
|
||||
const label beg = *(iter++);
|
||||
const label sz = *iter;
|
||||
const label len = *iter;
|
||||
|
||||
return this->validateRange(labelRange(beg, sz));
|
||||
return this->validateRange(labelRange(beg, len));
|
||||
}
|
||||
|
||||
|
||||
@ -122,31 +122,32 @@ void Foam::UList<T>::swapLast(const label i)
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::UList<T>::deepCopy(const UList<T>& a)
|
||||
void Foam::UList<T>::deepCopy(const UList<T>& list)
|
||||
{
|
||||
if (a.size_ != this->size_)
|
||||
const label len = this->size_;
|
||||
|
||||
if (len != list.size_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "ULists have different sizes: "
|
||||
<< this->size_ << " " << a.size_
|
||||
<< len << " " << list.size_
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
if (this->size_)
|
||||
else if (len)
|
||||
{
|
||||
#ifdef USEMEMCPY
|
||||
if (contiguous<T>())
|
||||
{
|
||||
memcpy(this->v_, a.v_, this->byteSize());
|
||||
memcpy(this->v_, list.v_, this->byteSize());
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
List_ACCESS(T, (*this), vp);
|
||||
List_CONST_ACCESS(T, a, ap);
|
||||
List_FOR_ALL((*this), i)
|
||||
List_ACCESS(T, (*this), lhs);
|
||||
List_CONST_ACCESS(T, list, rhs);
|
||||
for (label i = 0; i < len; ++i)
|
||||
{
|
||||
vp[i] = ap[i];
|
||||
lhs[i] = rhs[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -228,8 +229,7 @@ std::streamsize Foam::UList<T>::byteSize() const
|
||||
if (!contiguous<T>())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Cannot return the binary size of a list of "
|
||||
"non-primitive elements"
|
||||
<< "Cannot return binary size of a list with non-primitive elements"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
@ -317,20 +317,22 @@ void Foam::shuffle(UList<T>& a)
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
bool Foam::UList<T>::operator==(const UList<T>& a) const
|
||||
bool Foam::UList<T>::operator==(const UList<T>& list) const
|
||||
{
|
||||
bool equal = (this->size_ == a.size_);
|
||||
if (!equal)
|
||||
const label len = this->size_;
|
||||
if (len != list.size_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
List_CONST_ACCESS(T, (*this), vp);
|
||||
List_CONST_ACCESS(T, (a), ap);
|
||||
bool equal = false;
|
||||
|
||||
List_FOR_ALL((*this), i)
|
||||
List_CONST_ACCESS(T, (*this), lhs);
|
||||
List_CONST_ACCESS(T, (list), rhs);
|
||||
|
||||
for (label i = 0; i < len; ++i)
|
||||
{
|
||||
equal = (vp[i] == ap[i]);
|
||||
equal = (lhs[i] == rhs[i]);
|
||||
if (!equal) break;
|
||||
}
|
||||
|
||||
@ -339,55 +341,55 @@ bool Foam::UList<T>::operator==(const UList<T>& a) const
|
||||
|
||||
|
||||
template<class T>
|
||||
bool Foam::UList<T>::operator!=(const UList<T>& a) const
|
||||
bool Foam::UList<T>::operator!=(const UList<T>& list) const
|
||||
{
|
||||
return !operator==(a);
|
||||
return !operator==(list);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
bool Foam::UList<T>::operator<(const UList<T>& a) const
|
||||
bool Foam::UList<T>::operator<(const UList<T>& list) const
|
||||
{
|
||||
for
|
||||
(
|
||||
const_iterator vi = begin(), ai = a.begin();
|
||||
vi < end() && ai < a.end();
|
||||
++vi, ++ai
|
||||
const_iterator lhs = begin(), rhs = list.begin();
|
||||
lhs < end() && rhs < list.end();
|
||||
++lhs, ++rhs
|
||||
)
|
||||
{
|
||||
if (*vi < *ai)
|
||||
if (*lhs < *rhs)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (*vi > *ai)
|
||||
else if (*rhs < *lhs)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Contents look to be identical, or lists have different sizes
|
||||
return (this->size_ < a.size_);
|
||||
return (this->size_ < list.size_);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
bool Foam::UList<T>::operator>(const UList<T>& a) const
|
||||
bool Foam::UList<T>::operator>(const UList<T>& list) const
|
||||
{
|
||||
return a.operator<(*this);
|
||||
return list.operator<(*this);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
bool Foam::UList<T>::operator<=(const UList<T>& a) const
|
||||
bool Foam::UList<T>::operator<=(const UList<T>& list) const
|
||||
{
|
||||
return !operator>(a);
|
||||
return !list.operator<(*this);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
bool Foam::UList<T>::operator>=(const UList<T>& a) const
|
||||
bool Foam::UList<T>::operator>=(const UList<T>& list) const
|
||||
{
|
||||
return !operator<(a);
|
||||
return !operator<(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -51,6 +51,8 @@ SourceFiles
|
||||
#include "Swap.H"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -61,8 +63,6 @@ namespace Foam
|
||||
class labelRange;
|
||||
template<class T> class List;
|
||||
template<class T> class SubList;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
template<class T> class UList;
|
||||
template<class T> Ostream& operator<<(Ostream&, const UList<T>&);
|
||||
template<class T> Istream& operator>>(Istream&, UList<T>&);
|
||||
@ -97,7 +97,7 @@ class UList
|
||||
// for the default assignment to be either. The solution is to
|
||||
// disallow default assignment and provide separate 'shallowCopy' and
|
||||
// 'deepCopy' member functions
|
||||
void operator=(const UList<T>&) = delete;
|
||||
UList<T>& operator=(const UList<T>&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
@ -124,6 +124,42 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
// STL type definitions
|
||||
|
||||
//- The value type the list contains
|
||||
typedef T value_type;
|
||||
|
||||
//- The pointer type for non-const access to value_type items
|
||||
typedef T* pointer;
|
||||
|
||||
//- The pointer type for const access to value_type items
|
||||
typedef const T* const_pointer;
|
||||
|
||||
//- The type used for storing into value_type objects
|
||||
typedef T& reference;
|
||||
|
||||
//- The type used for reading from constant value_type objects.
|
||||
typedef const T& const_reference;
|
||||
|
||||
//- Random access iterator for traversing a UList
|
||||
typedef T* iterator;
|
||||
|
||||
//- Random access iterator for traversing a UList
|
||||
typedef const T* const_iterator;
|
||||
|
||||
//- The type to represent the size of a UList
|
||||
typedef label size_type;
|
||||
|
||||
//- The difference between iterator objects
|
||||
typedef label difference_type;
|
||||
|
||||
//- Reverse iterator (non-const access)
|
||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
|
||||
//- Reverse iterator (const access)
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
|
||||
// Related types
|
||||
|
||||
//- Declare friendship with the List class
|
||||
@ -135,7 +171,7 @@ public:
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Return a null UList
|
||||
//- Return a UList reference to a nullObject
|
||||
inline static const UList<T>& null();
|
||||
|
||||
|
||||
@ -169,7 +205,7 @@ public:
|
||||
|
||||
bool operator()(const label a, const label b) const
|
||||
{
|
||||
return values[a] > values[b];
|
||||
return values[b] < values[a];
|
||||
}
|
||||
};
|
||||
|
||||
@ -288,10 +324,10 @@ public:
|
||||
// Copy
|
||||
|
||||
//- Copy the pointer held by the given UList
|
||||
inline void shallowCopy(const UList<T>& a);
|
||||
inline void shallowCopy(const UList<T>& list);
|
||||
|
||||
//- Copy elements of the given UList
|
||||
void deepCopy(const UList<T>& a);
|
||||
void deepCopy(const UList<T>& list);
|
||||
|
||||
|
||||
// Member operators
|
||||
@ -337,29 +373,7 @@ public:
|
||||
void operator=(const zero);
|
||||
|
||||
|
||||
// STL type definitions
|
||||
|
||||
//- Type of values the UList contains
|
||||
typedef T value_type;
|
||||
|
||||
//- The type used for storing into value_type objects
|
||||
typedef T& reference;
|
||||
|
||||
//- The type used for reading from constant value_type objects.
|
||||
typedef const T& const_reference;
|
||||
|
||||
//- The type that can represent the difference between any two
|
||||
//- UList iterator objects
|
||||
typedef label difference_type;
|
||||
|
||||
//- The type that can represent the size of a UList
|
||||
typedef label size_type;
|
||||
|
||||
|
||||
// STL iterator
|
||||
|
||||
//- Random access iterator for traversing UList
|
||||
typedef T* iterator;
|
||||
// Random access iterator (non-const)
|
||||
|
||||
//- Return an iterator to begin traversing the UList
|
||||
inline iterator begin();
|
||||
@ -368,10 +382,7 @@ public:
|
||||
inline iterator end();
|
||||
|
||||
|
||||
// STL const_iterator
|
||||
|
||||
//- Random access iterator for traversing UList
|
||||
typedef const T* const_iterator;
|
||||
// Random access iterator (const)
|
||||
|
||||
//- Return const_iterator to begin traversing the constant UList
|
||||
inline const_iterator cbegin() const;
|
||||
@ -385,94 +396,8 @@ public:
|
||||
//- Return const_iterator to end traversing the constant UList
|
||||
inline const_iterator end() const;
|
||||
|
||||
// Reverse iterators
|
||||
|
||||
//- Generic const/non-const reverse iterator
|
||||
template<bool Const>
|
||||
class reverse_iterator_base
|
||||
{
|
||||
public:
|
||||
//- The const/non-const type for entries
|
||||
typedef typename std::conditional
|
||||
<Const, const T, T>::type value_type;
|
||||
|
||||
//- A pointer to a const/non-const entry
|
||||
typedef value_type* pointer;
|
||||
|
||||
//- A reference to a const/non-const entry
|
||||
typedef value_type& reference;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
//- The element pointer
|
||||
pointer ptr_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Construct null or from list element pointer
|
||||
inline reverse_iterator_base(pointer ptr = nullptr)
|
||||
:
|
||||
ptr_(ptr)
|
||||
{}
|
||||
|
||||
|
||||
//- Copy construct
|
||||
inline reverse_iterator_base(const reverse_iterator_base& iter)
|
||||
:
|
||||
ptr_(iter.ptr_)
|
||||
{}
|
||||
|
||||
|
||||
//- Reverse increment
|
||||
inline void operator++()
|
||||
{
|
||||
--ptr_;
|
||||
}
|
||||
|
||||
//- Reverse increment
|
||||
inline reverse_iterator_base operator++(int)
|
||||
{
|
||||
reverse_iterator_base old(*this);
|
||||
--ptr_;
|
||||
return old;
|
||||
}
|
||||
|
||||
//- Reverse increase
|
||||
inline void operator+=(int n)
|
||||
{
|
||||
ptr_ -= n;
|
||||
}
|
||||
|
||||
//- Dereference iterator
|
||||
reference operator*() const
|
||||
{
|
||||
return *ptr_;
|
||||
}
|
||||
|
||||
//- Dereference iterator
|
||||
pointer operator->() const
|
||||
{
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
//- Equality
|
||||
bool operator==(const reverse_iterator_base& iter) const
|
||||
{
|
||||
return ptr_ == iter.ptr_;
|
||||
}
|
||||
|
||||
//- inequality
|
||||
bool operator!=(const reverse_iterator_base& iter) const
|
||||
{
|
||||
return ptr_ != iter.ptr_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//- STL reverse_iterator
|
||||
typedef reverse_iterator_base<false> reverse_iterator;
|
||||
// Reverse iterators (non-const)
|
||||
|
||||
//- Return reverse_iterator to begin reverse traversing the UList
|
||||
inline reverse_iterator rbegin();
|
||||
@ -481,8 +406,7 @@ public:
|
||||
inline reverse_iterator rend();
|
||||
|
||||
|
||||
//- STL const reverse iterator
|
||||
typedef reverse_iterator_base<true> const_reverse_iterator;
|
||||
// Reverse iterators (const)
|
||||
|
||||
//- Return const_reverse_iterator to begin reverse traversing the UList
|
||||
inline const_reverse_iterator crbegin() const;
|
||||
@ -523,7 +447,7 @@ public:
|
||||
bool operator!=(const UList<T>& a) const;
|
||||
|
||||
//- Compare two ULists lexicographically. Takes linear time
|
||||
bool operator<(const UList<T>& a) const;
|
||||
bool operator<(const UList<T>& list) const;
|
||||
|
||||
//- Compare two ULists lexicographically. Takes linear time
|
||||
bool operator>(const UList<T>& a) const;
|
||||
|
||||
@ -188,10 +188,10 @@ inline bool Foam::UList<T>::found(const T& val, const label start) const
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::UList<T>::shallowCopy(const UList<T>& a)
|
||||
inline void Foam::UList<T>::shallowCopy(const UList<T>& list)
|
||||
{
|
||||
size_ = a.size_;
|
||||
v_ = a.v_;
|
||||
size_ = list.size_;
|
||||
v_ = list.v_;
|
||||
}
|
||||
|
||||
|
||||
@ -217,10 +217,8 @@ namespace Foam
|
||||
{
|
||||
return v_[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
return Foam::pTraits<bool>::zero;
|
||||
}
|
||||
|
||||
return Foam::pTraits<bool>::zero;
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,63 +266,63 @@ template<class T>
|
||||
inline typename Foam::UList<T>::iterator
|
||||
Foam::UList<T>::end()
|
||||
{
|
||||
return &v_[size_];
|
||||
return (v_ + size_);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UList<T>::const_iterator
|
||||
Foam::UList<T>::end() const
|
||||
{
|
||||
return &v_[size_];
|
||||
return (v_ + size_);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UList<T>::const_iterator
|
||||
Foam::UList<T>::cend() const
|
||||
{
|
||||
return &v_[size_];
|
||||
return (v_ + size_);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UList<T>::reverse_iterator
|
||||
Foam::UList<T>::rbegin()
|
||||
{
|
||||
return reverse_iterator(&v_[size_-1]);
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UList<T>::const_reverse_iterator
|
||||
Foam::UList<T>::rbegin() const
|
||||
{
|
||||
return const_reverse_iterator(&v_[size_-1]);
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UList<T>::const_reverse_iterator
|
||||
Foam::UList<T>::crbegin() const
|
||||
{
|
||||
return const_reverse_iterator(&v_[size_-1]);
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UList<T>::reverse_iterator
|
||||
Foam::UList<T>::rend()
|
||||
{
|
||||
return reverse_iterator(&v_[-1]);
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UList<T>::const_reverse_iterator
|
||||
Foam::UList<T>::rend() const
|
||||
{
|
||||
return const_reverse_iterator(&v_[-1]);
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UList<T>::const_reverse_iterator
|
||||
Foam::UList<T>::crend() const
|
||||
{
|
||||
return const_reverse_iterator(&v_[-1]);
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -76,16 +76,16 @@ Foam::Ostream& Foam::UList<T>::writeList
|
||||
{
|
||||
const UList<T>& L = *this;
|
||||
|
||||
const label sz = L.size();
|
||||
const label len = L.size();
|
||||
|
||||
// Write list contents depending on data format
|
||||
if (os.format() == IOstream::ASCII || !contiguous<T>())
|
||||
{
|
||||
// Can the contents be considered 'uniform' (ie, identical)?
|
||||
bool uniform = (sz > 1 && contiguous<T>());
|
||||
bool uniform = (len > 1 && contiguous<T>());
|
||||
if (uniform)
|
||||
{
|
||||
for (label i=1; i < sz; ++i)
|
||||
for (label i=1; i < len; ++i)
|
||||
{
|
||||
if (L[i] != L[0])
|
||||
{
|
||||
@ -98,7 +98,7 @@ Foam::Ostream& Foam::UList<T>::writeList
|
||||
if (uniform)
|
||||
{
|
||||
// Size and start delimiter
|
||||
os << sz << token::BEGIN_BLOCK;
|
||||
os << len << token::BEGIN_BLOCK;
|
||||
|
||||
// Contents
|
||||
os << L[0];
|
||||
@ -108,15 +108,15 @@ Foam::Ostream& Foam::UList<T>::writeList
|
||||
}
|
||||
else if
|
||||
(
|
||||
sz <= 1 || !shortListLen
|
||||
|| (sz <= shortListLen && contiguous<T>())
|
||||
len <= 1 || !shortListLen
|
||||
|| (len <= shortListLen && contiguous<T>())
|
||||
)
|
||||
{
|
||||
// Size and start delimiter
|
||||
os << sz << token::BEGIN_LIST;
|
||||
os << len << token::BEGIN_LIST;
|
||||
|
||||
// Contents
|
||||
for (label i=0; i < sz; ++i)
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
if (i) os << token::SPACE;
|
||||
os << L[i];
|
||||
@ -128,10 +128,10 @@ Foam::Ostream& Foam::UList<T>::writeList
|
||||
else
|
||||
{
|
||||
// Size and start delimiter
|
||||
os << nl << sz << nl << token::BEGIN_LIST << nl;
|
||||
os << nl << len << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
// Contents
|
||||
for (label i=0; i < sz; ++i)
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
os << L[i] << nl;
|
||||
}
|
||||
@ -143,9 +143,9 @@ Foam::Ostream& Foam::UList<T>::writeList
|
||||
else
|
||||
{
|
||||
// Contents are binary and contiguous
|
||||
os << nl << sz << nl;
|
||||
os << nl << len << nl;
|
||||
|
||||
if (sz)
|
||||
if (len)
|
||||
{
|
||||
// write(...) includes surrounding start/end delimiters
|
||||
os.write
|
||||
@ -171,14 +171,18 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const UList<T>& lst)
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L)
|
||||
Foam::Istream& Foam::operator>>(Istream& is, UList<T>& lst)
|
||||
{
|
||||
// The target list length - must match with sizes read
|
||||
const label len = lst.size();
|
||||
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
token firstToken(is);
|
||||
|
||||
is.fatalCheck("operator>>(Istream&, UList<T>&) : reading first token");
|
||||
|
||||
// Compound: simply transfer contents
|
||||
if (firstToken.isCompound())
|
||||
{
|
||||
List<T> elems;
|
||||
@ -189,31 +193,38 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L)
|
||||
firstToken.transferCompoundToken(is)
|
||||
)
|
||||
);
|
||||
// Check list length
|
||||
const label sz = elems.size();
|
||||
|
||||
if (sz != L.size())
|
||||
const label inputLen = elems.size();
|
||||
|
||||
// List lengths must match
|
||||
if (inputLen != len)
|
||||
{
|
||||
FatalIOErrorInFunction(is)
|
||||
<< "incorrect length for UList. Read " << sz
|
||||
<< " expected " << L.size()
|
||||
<< "incorrect length for UList. Read "
|
||||
<< inputLen << " expected " << len
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
for (label i=0; i<sz; ++i)
|
||||
{
|
||||
L[i] = elems[i];
|
||||
}
|
||||
}
|
||||
else if (firstToken.isLabel())
|
||||
{
|
||||
const label sz = firstToken.labelToken();
|
||||
|
||||
// Set list length to that read
|
||||
if (sz != L.size())
|
||||
for (label i = 0; i < len; ++i)
|
||||
{
|
||||
lst[i] = std::move(elems[i]);
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
// Label: could be int(..), int{...} or just a plain '0'
|
||||
if (firstToken.isLabel())
|
||||
{
|
||||
const label inputLen = firstToken.labelToken();
|
||||
|
||||
// List lengths must match
|
||||
if (inputLen != len)
|
||||
{
|
||||
FatalIOErrorInFunction(is)
|
||||
<< "incorrect length for UList. Read " << sz
|
||||
<< " expected " << L.size()
|
||||
<< "incorrect length for UList. Read "
|
||||
<< inputLen << " expected " << len
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
@ -224,13 +235,13 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L)
|
||||
// Read beginning of contents
|
||||
const char delimiter = is.readBeginList("List");
|
||||
|
||||
if (sz)
|
||||
if (len)
|
||||
{
|
||||
if (delimiter == token::BEGIN_LIST)
|
||||
{
|
||||
for (label i=0; i<sz; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
is >> L[i];
|
||||
is >> lst[i];
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
@ -251,9 +262,9 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L)
|
||||
"reading the single entry"
|
||||
);
|
||||
|
||||
for (label i=0; i<sz; ++i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
L[i] = element;
|
||||
lst[i] = element; // Copy the value
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -261,22 +272,24 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L)
|
||||
// Read end of contents
|
||||
is.readEndList("List");
|
||||
}
|
||||
else
|
||||
else if (len)
|
||||
{
|
||||
// contents are binary and contiguous
|
||||
// Non-empty, binary, contiguous
|
||||
|
||||
if (sz)
|
||||
{
|
||||
is.read(reinterpret_cast<char*>(L.data()), sz*sizeof(T));
|
||||
is.read(reinterpret_cast<char*>(lst.data()), len*sizeof(T));
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
"operator>>(Istream&, UList<T>&) : reading the binary block"
|
||||
);
|
||||
}
|
||||
is.fatalCheck
|
||||
(
|
||||
"operator>>(Istream&, UList<T>&) : reading the binary block"
|
||||
);
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
else if (firstToken.isPunctuation())
|
||||
|
||||
|
||||
// "(...)" : read as SLList and transfer contents
|
||||
if (firstToken.isPunctuation())
|
||||
{
|
||||
if (firstToken.pToken() != token::BEGIN_LIST)
|
||||
{
|
||||
@ -286,40 +299,33 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L)
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
// Putback the opening bracket
|
||||
is.putBack(firstToken);
|
||||
is.putBack(firstToken); // Putback the opening bracket
|
||||
|
||||
// Now read as a singly-linked list
|
||||
SLList<T> sll(is);
|
||||
SLList<T> sll(is); // Read as singly-linked list
|
||||
|
||||
if (sll.size() != L.size())
|
||||
// List lengths must match
|
||||
if (sll.size() != len)
|
||||
{
|
||||
FatalIOErrorInFunction(is)
|
||||
<< "incorrect length for UList. Read " << sll.size()
|
||||
<< " expected " << L.size()
|
||||
<< "incorrect length for UList. Read "
|
||||
<< sll.size() << " expected " << len
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
// Convert the singly-linked list to this list
|
||||
label i = 0;
|
||||
for
|
||||
(
|
||||
typename SLList<T>::const_iterator iter = sll.begin();
|
||||
iter != sll.end();
|
||||
++iter, ++i
|
||||
)
|
||||
// Move assign each list element
|
||||
for (label i = 0; i < len; ++i)
|
||||
{
|
||||
L[i] = iter();
|
||||
lst[i] = std::move(sll.removeHead());
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorInFunction(is)
|
||||
<< "incorrect first token, expected <int> or '(', found "
|
||||
<< firstToken.info()
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
|
||||
FatalIOErrorInFunction(is)
|
||||
<< "incorrect first token, expected <int> or '(', found "
|
||||
<< firstToken.info()
|
||||
<< exit(FatalIOError);
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,137 +27,66 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Foam::UPtrList<T>::UPtrList()
|
||||
:
|
||||
ptrs_()
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::UPtrList<T>::UPtrList(const label s)
|
||||
:
|
||||
ptrs_(s, reinterpret_cast<T*>(0))
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::UPtrList<T>::UPtrList(UList<T>& lst)
|
||||
:
|
||||
ptrs_(lst.size())
|
||||
{
|
||||
forAll(lst, i)
|
||||
const label len = lst.size();
|
||||
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
ptrs_[i] = &lst[i];
|
||||
ptrs_[i] = &(lst[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::UPtrList<T>::UPtrList(PtrList<T>& lst)
|
||||
:
|
||||
ptrs_(lst.size())
|
||||
{
|
||||
forAll(lst, i)
|
||||
{
|
||||
ptrs_[i] = &lst[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::UPtrList<T>::UPtrList(const Xfer<UPtrList<T>>& lst)
|
||||
{
|
||||
transfer(lst());
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::UPtrList<T>::UPtrList(UPtrList<T>& a, bool reuse)
|
||||
:
|
||||
ptrs_(a.ptrs_, reuse)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
void Foam::UPtrList<T>::setSize(const label newSize)
|
||||
{
|
||||
label oldSize = size();
|
||||
|
||||
if (newSize <= 0)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
else if (newSize < oldSize)
|
||||
{
|
||||
ptrs_.setSize(newSize);
|
||||
}
|
||||
else if (newSize > oldSize)
|
||||
{
|
||||
ptrs_.setSize(newSize);
|
||||
|
||||
// set new elements to nullptr
|
||||
for (label i=oldSize; i<newSize; i++)
|
||||
{
|
||||
ptrs_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::UPtrList<T>::clear()
|
||||
{
|
||||
ptrs_.clear();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::UPtrList<T>::transfer(UPtrList<T>& a)
|
||||
{
|
||||
ptrs_.transfer(a.ptrs_);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::UPtrList<T>::reorder(const labelUList& oldToNew)
|
||||
{
|
||||
if (oldToNew.size() != size())
|
||||
const label len = this->size();
|
||||
|
||||
if (oldToNew.size() != len)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Size of map (" << oldToNew.size()
|
||||
<< ") not equal to list size (" << size()
|
||||
<< ")." << abort(FatalError);
|
||||
<< ") not equal to list size (" << len
|
||||
<< ") for type " << typeid(T).name() << nl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
List<T*> newPtrs_(ptrs_.size(), reinterpret_cast<T*>(0));
|
||||
// New list of pointers
|
||||
List<T*> ptrLst(len, reinterpret_cast<T*>(0));
|
||||
|
||||
forAll(*this, i)
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
label newI = oldToNew[i];
|
||||
const label idx = oldToNew[i];
|
||||
|
||||
if (newI < 0 || newI >= size())
|
||||
if (idx < 0 || idx >= len)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Illegal index " << newI << nl
|
||||
<< "Valid indices are 0.." << size()-1
|
||||
<< "Illegal index " << idx << nl
|
||||
<< "Valid indices are 0.." << len-1
|
||||
<< " for type " << typeid(T).name() << nl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
if (newPtrs_[newI])
|
||||
if (ptrLst[idx])
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "reorder map is not unique; element " << newI
|
||||
<< " already set." << abort(FatalError);
|
||||
<< "reorder map is not unique; element " << idx
|
||||
<< " already set for type " << typeid(T).name()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
newPtrs_[newI] = ptrs_[i];
|
||||
ptrLst[idx] = ptrs_[i];
|
||||
}
|
||||
|
||||
forAll(newPtrs_, i)
|
||||
// Verify that all pointers were set
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
if (!newPtrs_[i])
|
||||
if (!ptrLst[i])
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Element " << i << " not set after reordering." << nl
|
||||
@ -165,12 +94,8 @@ void Foam::UPtrList<T>::reorder(const labelUList& oldToNew)
|
||||
}
|
||||
}
|
||||
|
||||
ptrs_.transfer(newPtrs_);
|
||||
ptrs_.swap(ptrLst);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "UPtrListIO.C"
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -25,14 +25,15 @@ Class
|
||||
Foam::UPtrList
|
||||
|
||||
Description
|
||||
A templated 1D list of pointers to objects of type \<T\>, where the
|
||||
size of the array is known and used for subscript bounds checking, etc.
|
||||
A list of pointers to objects of type \<T\>, without allocation/deallocation
|
||||
management of the pointers - this is to be done elsewhere.
|
||||
The operator[] returns a reference to the object, not the pointer.
|
||||
|
||||
The element operator [] returns a reference to the object rather than a
|
||||
pointer. Storage is not allocated during construction or use but is
|
||||
supplied to the constructor as an argument.
|
||||
See Also
|
||||
Foam::PtrList
|
||||
|
||||
SourceFiles
|
||||
UPtrListI.H
|
||||
UPtrList.C
|
||||
UPtrListIO.C
|
||||
|
||||
@ -43,337 +44,271 @@ SourceFiles
|
||||
|
||||
#include "List.H"
|
||||
#include "PtrList.H"
|
||||
#include <iterator>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend classes
|
||||
template<class T> class PtrList;
|
||||
// Forward declarations
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
template<class T> class PtrList;
|
||||
template<class T> class UPtrList;
|
||||
|
||||
template<class T>
|
||||
inline typename UPtrList<T>::iterator operator+
|
||||
(
|
||||
const typename UPtrList<T>::iterator&,
|
||||
label
|
||||
);
|
||||
|
||||
template<class T>
|
||||
inline typename UPtrList<T>::iterator operator+
|
||||
(
|
||||
label,
|
||||
const typename UPtrList<T>::iterator&
|
||||
);
|
||||
|
||||
template<class T>
|
||||
inline typename UPtrList<T>::iterator operator-
|
||||
(
|
||||
const typename UPtrList<T>::iterator&,
|
||||
label
|
||||
);
|
||||
|
||||
template<class T>
|
||||
inline label operator-
|
||||
(
|
||||
const typename UPtrList<T>::iterator&,
|
||||
const typename UPtrList<T>::iterator&
|
||||
);
|
||||
|
||||
template<class T>
|
||||
inline typename UPtrList<T>::const_iterator operator+
|
||||
(
|
||||
const typename UPtrList<T>::const_iterator&,
|
||||
label
|
||||
);
|
||||
|
||||
template<class T>
|
||||
inline typename UPtrList<T>::const_iterator operator+
|
||||
(
|
||||
label,
|
||||
const typename UPtrList<T>::const_iterator&
|
||||
);
|
||||
|
||||
template<class T>
|
||||
inline typename UPtrList<T>::const_iterator operator-
|
||||
(
|
||||
const typename UPtrList<T>::const_iterator&,
|
||||
label
|
||||
);
|
||||
|
||||
template<class T>
|
||||
inline label operator-
|
||||
(
|
||||
const typename UPtrList<T>::const_iterator&,
|
||||
const typename UPtrList<T>::const_iterator&
|
||||
);
|
||||
|
||||
template<class T>
|
||||
Istream& operator>>(Istream&, UPtrList<T>&);
|
||||
|
||||
template<class T>
|
||||
Ostream& operator<<(Ostream&, const UPtrList<T>&);
|
||||
template<class T> Ostream& operator<<(Ostream& os, const UPtrList<T>& lst);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class UPtrList Declaration
|
||||
Class UPtrList Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class T>
|
||||
class UPtrList
|
||||
{
|
||||
// Private data
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
List<T*> ptrs_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Related types
|
||||
// STL type definitions
|
||||
|
||||
//- Declare friendship with the UPtrList class
|
||||
friend class PtrList<T>;
|
||||
//- Type of values the list contains
|
||||
typedef T value_type;
|
||||
|
||||
//- A non-const reference to the value_type
|
||||
typedef T& reference;
|
||||
|
||||
//- A const reference to the value_type
|
||||
typedef const T& const_reference;
|
||||
|
||||
//- Random-access iterator with non-const access
|
||||
class iterator;
|
||||
|
||||
//- Random-access iterator with const access
|
||||
class const_iterator;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Null Constructor
|
||||
UPtrList();
|
||||
//- Construct null
|
||||
UPtrList() = default;
|
||||
|
||||
//- Construct with size specified
|
||||
explicit UPtrList(const label);
|
||||
//- Construct with specified size, each element initialized to nullptr
|
||||
explicit inline UPtrList(const label nElem);
|
||||
|
||||
//- Construct from UList
|
||||
explicit UPtrList(UList<T>&);
|
||||
//- Construct from PtrList, copying addresses of each list element.
|
||||
// The argument is non-const access since this UPtrList can be used
|
||||
// to change its values.
|
||||
explicit inline UPtrList(PtrList<T>& lst);
|
||||
|
||||
//- Construct from PtrList
|
||||
explicit UPtrList(PtrList<T>&);
|
||||
//- Construct from UList, taking addresses of each list element
|
||||
explicit UPtrList(UList<T>& lst);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
UPtrList(const Xfer<UPtrList<T>>&);
|
||||
inline UPtrList(const Xfer<UPtrList<T>>& lst);
|
||||
|
||||
//- Construct as copy or re-use as specified
|
||||
UPtrList(UPtrList<T>&, bool reuse);
|
||||
inline UPtrList(UPtrList<T>& lst, bool reuse);
|
||||
|
||||
//- Copy construct
|
||||
inline UPtrList(const UPtrList<T>& lst) = default;
|
||||
|
||||
//- Move construct
|
||||
inline UPtrList(UPtrList<T>&& lst);
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
// Access
|
||||
// Access
|
||||
|
||||
//- Return the number of elements in the UPtrList
|
||||
inline label size() const;
|
||||
//- Return the number of elements in the UPtrList
|
||||
inline label size() const;
|
||||
|
||||
//- Return true if the UPtrList is empty (ie, size() is zero)
|
||||
inline bool empty() const;
|
||||
//- Return true if the UPtrList is empty (ie, size() is zero)
|
||||
inline bool empty() const;
|
||||
|
||||
//- Swap content with another UPtrList
|
||||
inline void swap(UPtrList<T>& lst);
|
||||
//- Return reference to the first element of the list
|
||||
inline T& first();
|
||||
|
||||
//- Return reference to the first element of the list
|
||||
inline T& first();
|
||||
//- Return reference to first element of the list
|
||||
inline const T& first() const;
|
||||
|
||||
//- Return reference to first element of the list
|
||||
inline const T& first() const;
|
||||
//- Return reference to the last element of the list
|
||||
inline T& last();
|
||||
|
||||
//- Return reference to the last element of the list
|
||||
inline T& last();
|
||||
|
||||
//- Return reference to the last element of the list
|
||||
inline const T& last() const;
|
||||
//- Return reference to the last element of the list
|
||||
inline const T& last() const;
|
||||
|
||||
|
||||
// Edit
|
||||
// Edit
|
||||
|
||||
//- Reset size of UPtrList. This can only be used to set the size
|
||||
// of an empty UPtrList, extend a UPtrList, remove entries from
|
||||
// the end of a UPtrList
|
||||
void setSize(const label);
|
||||
//- Set list size to zero.
|
||||
inline void clear();
|
||||
|
||||
//- Reset size of UPtrList. This can only be used to set the size
|
||||
// of an empty UPtrList, extend a UPtrList, remove entries from
|
||||
// the end of a UPtrList
|
||||
inline void resize(const label);
|
||||
//- Reset size of UPtrList.
|
||||
// New entries are initialized to nullptr.
|
||||
inline void setSize(const label newLen);
|
||||
|
||||
//- Clear the UPtrList, i.e. set size to zero
|
||||
void clear();
|
||||
//- Reset size of UPtrList.
|
||||
// New entries are initialized to nullptr.
|
||||
inline void resize(const label newLen);
|
||||
|
||||
//- Transfer the contents of the argument UPtrList into this
|
||||
// UPtrList and annul the argument list
|
||||
void transfer(UPtrList<T>&);
|
||||
//- Append an element to the end of the list
|
||||
inline void append(T* ptr);
|
||||
|
||||
//- Transfer contents to the Xfer container
|
||||
inline Xfer<UPtrList<T>> xfer();
|
||||
//- Swap content
|
||||
inline void swap(UPtrList<T>& lst);
|
||||
|
||||
//- Is element set
|
||||
inline bool set(const label) const;
|
||||
//- Transfer contents into this list and annul the argument
|
||||
inline void transfer(UPtrList<T>& lst);
|
||||
|
||||
//- Set element. Return old element (can be nullptr).
|
||||
// No checks on new element
|
||||
inline T* set(const label, T*);
|
||||
//- Transfer contents to the Xfer container
|
||||
inline Xfer<UPtrList<T>> xfer();
|
||||
|
||||
//- Reorders elements. Ordering does not have to be done in
|
||||
// ascending or descending order. Reordering has to be unique.
|
||||
// (is shuffle)
|
||||
void reorder(const labelUList&);
|
||||
//- Return true if element is set (ie, not a nullptr)
|
||||
inline bool set(const label i) const;
|
||||
|
||||
//- Set element to given pointer and return old element (can be null).
|
||||
// No checks on new element
|
||||
inline T* set(const label i, T* ptr);
|
||||
|
||||
//- Reorder elements. Reordering must be unique (ie, shuffle).
|
||||
void reorder(const labelUList& oldToNew);
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
//- Return element const reference
|
||||
inline const T& operator[](const label) const;
|
||||
inline const T& operator[](const label i) const;
|
||||
|
||||
//- Return element reference
|
||||
inline T& operator[](const label);
|
||||
inline T& operator[](const label i);
|
||||
|
||||
//- Return element const pointer
|
||||
inline const T* operator()(const label) const;
|
||||
inline const T* operator()(const label i) const;
|
||||
|
||||
//- Copy assignment
|
||||
UPtrList<T>& operator=(const UPtrList<T>& lst) = default;
|
||||
|
||||
//- Move assignment
|
||||
inline void operator=(UPtrList<T>&& lst);
|
||||
|
||||
|
||||
// STL type definitions
|
||||
// Iterators
|
||||
|
||||
//- Type of values the UPtrList contains
|
||||
typedef T value_type;
|
||||
|
||||
//- Type that can be used for storing into UPtrList::value_type objects
|
||||
typedef T& reference;
|
||||
|
||||
//- Type that can be used for storing into constant UPtrList::value_type
|
||||
// objects
|
||||
typedef const T& const_reference;
|
||||
|
||||
|
||||
// STL iterator
|
||||
// Random access iterator for traversing UPtrList
|
||||
|
||||
class iterator;
|
||||
friend class iterator;
|
||||
|
||||
//- An STL iterator
|
||||
//- Random-access iterator with non-const access
|
||||
class iterator
|
||||
{
|
||||
T** ptr_;
|
||||
|
||||
public:
|
||||
|
||||
//- Construct for a given UPtrList entry
|
||||
inline iterator(T**);
|
||||
using iterator_category = std::random_access_iterator_tag;
|
||||
using value_type = T;
|
||||
using difference_type = label;
|
||||
using pointer = T*;
|
||||
using reference = T&;
|
||||
friend class const_iterator;
|
||||
|
||||
//- Construct for a given entry
|
||||
inline iterator(T** ptr);
|
||||
|
||||
// Member operators
|
||||
|
||||
inline bool operator==(const iterator&) const;
|
||||
inline bool operator!=(const iterator&) const;
|
||||
inline bool operator==(const iterator& iter) const;
|
||||
inline bool operator!=(const iterator& iter) const;
|
||||
|
||||
inline T& operator*();
|
||||
inline T& operator()();
|
||||
inline reference operator*() const;
|
||||
inline reference operator()() const;
|
||||
|
||||
inline iterator operator++();
|
||||
inline iterator operator++(int);
|
||||
// Forward iteration
|
||||
inline iterator& operator++();
|
||||
inline iterator operator++(int);
|
||||
|
||||
inline iterator operator--();
|
||||
inline iterator operator--(int);
|
||||
inline iterator& operator--();
|
||||
inline iterator operator--(int);
|
||||
|
||||
inline iterator operator+=(label);
|
||||
// Random-access
|
||||
inline iterator& operator+=(difference_type n);
|
||||
inline iterator& operator-=(difference_type n);
|
||||
inline iterator operator+(difference_type n) const;
|
||||
inline iterator operator-(difference_type n) const;
|
||||
|
||||
friend iterator operator+ <T>(const iterator&, label);
|
||||
friend iterator operator+ <T>(label, const iterator&);
|
||||
inline difference_type operator-(const iterator& iter) const;
|
||||
|
||||
inline iterator operator-=(label);
|
||||
inline reference operator[](difference_type n) const;
|
||||
|
||||
friend iterator operator- <T>(const iterator&, label);
|
||||
inline bool operator<(const iterator& iter) const;
|
||||
inline bool operator>(const iterator& iter) const;
|
||||
|
||||
friend label operator- <T>
|
||||
(
|
||||
const iterator&,
|
||||
const iterator&
|
||||
);
|
||||
|
||||
inline T& operator[](label);
|
||||
|
||||
inline bool operator<(const iterator&) const;
|
||||
inline bool operator>(const iterator&) const;
|
||||
|
||||
inline bool operator<=(const iterator&) const;
|
||||
inline bool operator>=(const iterator&) const;
|
||||
inline bool operator<=(const iterator& iter) const;
|
||||
inline bool operator>=(const iterator& iter) const;
|
||||
};
|
||||
|
||||
//- Return an iterator to begin traversing the UPtrList
|
||||
inline iterator begin();
|
||||
|
||||
//- Return an iterator to end traversing the UPtrList
|
||||
inline iterator end();
|
||||
|
||||
|
||||
// STL const_iterator
|
||||
// Random access iterator for traversing UPtrList
|
||||
|
||||
//- An STL-conforming const_iterator
|
||||
//- Random-access iterator with const access
|
||||
class const_iterator
|
||||
{
|
||||
const T* const* ptr_;
|
||||
|
||||
public:
|
||||
|
||||
//- Construct for a given UPtrList entry
|
||||
inline const_iterator(const T* const*);
|
||||
using iterator_category = std::random_access_iterator_tag;
|
||||
using value_type = const T;
|
||||
using difference_type = label;
|
||||
using pointer = const T*;
|
||||
using reference = const T&;
|
||||
|
||||
//- Construct from an iterator
|
||||
inline const_iterator(const iterator&);
|
||||
//- Construct for a given entry
|
||||
inline const_iterator(const T* const* ptr);
|
||||
|
||||
//- Copy construct from non-const iterator
|
||||
inline const_iterator(const iterator& iter);
|
||||
|
||||
// Member operators
|
||||
|
||||
inline bool operator==(const const_iterator&) const;
|
||||
inline bool operator!=(const const_iterator&) const;
|
||||
inline bool operator==(const const_iterator& iter) const;
|
||||
inline bool operator!=(const const_iterator& iter) const;
|
||||
|
||||
typedef const T& Tref;
|
||||
inline Tref operator*();
|
||||
inline Tref operator()();
|
||||
inline reference operator*() const;
|
||||
inline reference operator()() const;
|
||||
|
||||
inline const_iterator operator++();
|
||||
inline const_iterator operator++(int);
|
||||
// Forward iteration
|
||||
inline const_iterator& operator++();
|
||||
inline const_iterator operator++(int);
|
||||
|
||||
inline const_iterator operator--();
|
||||
inline const_iterator operator--(int);
|
||||
inline const_iterator& operator--();
|
||||
inline const_iterator operator--(int);
|
||||
|
||||
inline const_iterator operator+=(label);
|
||||
// Random-access
|
||||
inline const_iterator& operator+=(difference_type n);
|
||||
inline const_iterator& operator-=(difference_type n);
|
||||
inline const_iterator operator+(difference_type n) const;
|
||||
inline const_iterator operator-(difference_type n) const;
|
||||
|
||||
friend const_iterator operator+ <T>
|
||||
(
|
||||
const const_iterator&,
|
||||
label
|
||||
);
|
||||
friend const_iterator operator+ <T>
|
||||
(
|
||||
label,
|
||||
const const_iterator&
|
||||
);
|
||||
inline difference_type operator-(const const_iterator& iter) const;
|
||||
|
||||
inline const_iterator operator-=(label);
|
||||
inline reference operator[](difference_type n) const;
|
||||
|
||||
friend const_iterator operator- <T>
|
||||
(
|
||||
const const_iterator&,
|
||||
label
|
||||
);
|
||||
inline bool operator<(const const_iterator& iter) const;
|
||||
inline bool operator>(const const_iterator& iter) const;
|
||||
|
||||
friend label operator- <T>
|
||||
(
|
||||
const const_iterator&,
|
||||
const const_iterator&
|
||||
);
|
||||
|
||||
inline const T& operator[](label);
|
||||
|
||||
inline bool operator<(const const_iterator&) const;
|
||||
inline bool operator>(const const_iterator&) const;
|
||||
|
||||
inline bool operator<=(const const_iterator&) const;
|
||||
inline bool operator>=(const const_iterator&) const;
|
||||
inline bool operator<=(const const_iterator& iter) const;
|
||||
inline bool operator>=(const const_iterator& iter) const;
|
||||
};
|
||||
|
||||
|
||||
//- Return an iterator to begin traversing the UPtrList
|
||||
inline iterator begin();
|
||||
|
||||
//- Return an iterator to end traversing the UPtrList
|
||||
inline iterator end();
|
||||
|
||||
//- Return an const_iterator to begin traversing the UPtrList
|
||||
inline const_iterator cbegin() const;
|
||||
|
||||
@ -390,7 +325,7 @@ public:
|
||||
// IOstream operator
|
||||
|
||||
//- Write UPtrList to Ostream
|
||||
friend Ostream& operator<< <T>(Ostream&, const UPtrList<T>&);
|
||||
friend Ostream& operator<< <T>(Ostream& os, const UPtrList<T>& lst);
|
||||
};
|
||||
|
||||
|
||||
@ -406,6 +341,7 @@ public:
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "UPtrList.C"
|
||||
#include "UPtrListIO.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -23,6 +23,43 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline Foam::UPtrList<T>::UPtrList(const label nElem)
|
||||
:
|
||||
ptrs_(nElem, reinterpret_cast<T*>(0))
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::UPtrList<T>::UPtrList(PtrList<T>& lst)
|
||||
:
|
||||
ptrs_(lst.ptrs_)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::UPtrList<T>::UPtrList(UPtrList<T>&& lst)
|
||||
:
|
||||
ptrs_(std::move(lst.ptrs_))
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::UPtrList<T>::UPtrList(const Xfer<UPtrList<T>>& lst)
|
||||
{
|
||||
transfer(lst());
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::UPtrList<T>::UPtrList(UPtrList<T>& lst, bool reuse)
|
||||
:
|
||||
ptrs_(lst.ptrs_, reuse)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
@ -39,6 +76,13 @@ inline bool Foam::UPtrList<T>::empty() const
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::UPtrList<T>::clear()
|
||||
{
|
||||
ptrs_.clear();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::UPtrList<T>::swap(UPtrList<T>& lst)
|
||||
{
|
||||
@ -46,6 +90,13 @@ inline void Foam::UPtrList<T>::swap(UPtrList<T>& lst)
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::UPtrList<T>::transfer(UPtrList<T>& lst)
|
||||
{
|
||||
ptrs_.transfer(lst.ptrs_);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline T& Foam::UPtrList<T>::first()
|
||||
{
|
||||
@ -75,9 +126,36 @@ inline const T& Foam::UPtrList<T>::last() const
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::UPtrList<T>::resize(const label newSize)
|
||||
inline void Foam::UPtrList<T>::setSize(const label newLen)
|
||||
{
|
||||
this->setSize(newSize);
|
||||
if (newLen <= 0)
|
||||
{
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
const label oldLen = this->size();
|
||||
if (newLen != oldLen)
|
||||
{
|
||||
// Truncate or extend (new elements initialized to nullptr)
|
||||
ptrs_.setSize(newLen, reinterpret_cast<T*>(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::UPtrList<T>::resize(const label nElem)
|
||||
{
|
||||
this->setSize(nElem);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::UPtrList<T>::append(T* ptr)
|
||||
{
|
||||
const label idx = this->size();
|
||||
ptrs_.setSize(idx + 1);
|
||||
ptrs_[idx] = ptr;
|
||||
}
|
||||
|
||||
|
||||
@ -153,158 +231,149 @@ inline Foam::UPtrList<T>::iterator::iterator(T** ptr)
|
||||
ptr_(ptr)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const
|
||||
{
|
||||
return ptr_ == iter.ptr_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline bool Foam::UPtrList<T>::iterator::operator!=(const iterator& iter) const
|
||||
{
|
||||
return ptr_ != iter.ptr_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline T& Foam::UPtrList<T>::iterator::operator*()
|
||||
inline T& Foam::UPtrList<T>::iterator::operator*() const
|
||||
{
|
||||
return **ptr_;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T& Foam::UPtrList<T>::iterator::operator()()
|
||||
{
|
||||
return operator*();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
inline T& Foam::UPtrList<T>::iterator::operator()() const
|
||||
{
|
||||
return **ptr_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator&
|
||||
Foam::UPtrList<T>::iterator::operator++()
|
||||
{
|
||||
++ptr_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
Foam::UPtrList<T>::iterator::operator++(int)
|
||||
{
|
||||
iterator tmp = *this;
|
||||
iterator iter(*this);
|
||||
++ptr_;
|
||||
return tmp;
|
||||
return iter;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
inline typename Foam::UPtrList<T>::iterator&
|
||||
Foam::UPtrList<T>::iterator::operator--()
|
||||
{
|
||||
--ptr_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
Foam::UPtrList<T>::iterator::operator--(int)
|
||||
{
|
||||
iterator tmp = *this;
|
||||
iterator iter(*this);
|
||||
--ptr_;
|
||||
return tmp;
|
||||
return iter;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
inline typename Foam::UPtrList<T>::iterator&
|
||||
Foam::UPtrList<T>::iterator::operator+=(label n)
|
||||
{
|
||||
ptr_ += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
Foam::operator+(const typename UPtrList<T>::iterator& iter, label n)
|
||||
{
|
||||
typename UPtrList<T>::iterator tmp = iter;
|
||||
return tmp += n;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
Foam::operator+(label n, const typename UPtrList<T>::iterator& iter)
|
||||
{
|
||||
typename UPtrList<T>::iterator tmp = iter;
|
||||
return tmp += n;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
inline typename Foam::UPtrList<T>::iterator&
|
||||
Foam::UPtrList<T>::iterator::operator-=(label n)
|
||||
{
|
||||
ptr_ -= n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
Foam::operator-(const typename UPtrList<T>::iterator& iter, label n)
|
||||
Foam::UPtrList<T>::iterator::operator+(label n) const
|
||||
{
|
||||
typename UPtrList<T>::iterator tmp = iter;
|
||||
return tmp -= n;
|
||||
return iterator(ptr_ + n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline Foam::label Foam::operator-
|
||||
(
|
||||
const typename UPtrList<T>::iterator& iter1,
|
||||
const typename UPtrList<T>::iterator& iter2
|
||||
)
|
||||
{
|
||||
return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T& Foam::UPtrList<T>::iterator::operator[](label n)
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
Foam::UPtrList<T>::iterator::operator-(label n) const
|
||||
{
|
||||
return iterator(ptr_ - n);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::label
|
||||
Foam::UPtrList<T>::iterator::operator-(const iterator& iter) const
|
||||
{
|
||||
return (ptr_ - iter.ptr_);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline T& Foam::UPtrList<T>::iterator::operator[](label n) const
|
||||
{
|
||||
return *(*this + n);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline bool Foam::UPtrList<T>::iterator::operator<(const iterator& iter) const
|
||||
{
|
||||
return ptr_ < iter.ptr_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline bool Foam::UPtrList<T>::iterator::operator>(const iterator& iter) const
|
||||
{
|
||||
return ptr_ > iter.ptr_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline bool Foam::UPtrList<T>::iterator::operator<=(const iterator& iter) const
|
||||
{
|
||||
return ptr_ <= iter.ptr_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline bool Foam::UPtrList<T>::iterator::operator>=(const iterator& iter) const
|
||||
{
|
||||
return ptr_ >= iter.ptr_;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
Foam::UPtrList<T>::begin()
|
||||
{
|
||||
return ptrs_.begin();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
Foam::UPtrList<T>::end()
|
||||
{
|
||||
return ptrs_.end();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * //
|
||||
|
||||
@ -343,21 +412,21 @@ inline bool Foam::UPtrList<T>::const_iterator::operator!=
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const T& Foam::UPtrList<T>::const_iterator::operator*()
|
||||
inline const T& Foam::UPtrList<T>::const_iterator::operator*() const
|
||||
{
|
||||
return **ptr_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const T& Foam::UPtrList<T>::const_iterator::operator()()
|
||||
inline const T& Foam::UPtrList<T>::const_iterator::operator()() const
|
||||
{
|
||||
return operator*();
|
||||
return **ptr_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
inline typename Foam::UPtrList<T>::const_iterator&
|
||||
Foam::UPtrList<T>::const_iterator::operator++()
|
||||
{
|
||||
++ptr_;
|
||||
@ -369,14 +438,14 @@ template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
Foam::UPtrList<T>::const_iterator::operator++(int)
|
||||
{
|
||||
const_iterator tmp = *this;
|
||||
const_iterator iter(*this);
|
||||
++ptr_;
|
||||
return tmp;
|
||||
return iter;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
inline typename Foam::UPtrList<T>::const_iterator&
|
||||
Foam::UPtrList<T>::const_iterator::operator--()
|
||||
{
|
||||
--ptr_;
|
||||
@ -388,14 +457,14 @@ template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
Foam::UPtrList<T>::const_iterator::operator--(int)
|
||||
{
|
||||
const_iterator tmp = *this;
|
||||
const_iterator iter(*this);
|
||||
--ptr_;
|
||||
return tmp;
|
||||
return iter;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
inline typename Foam::UPtrList<T>::const_iterator&
|
||||
Foam::UPtrList<T>::const_iterator::operator+=(label n)
|
||||
{
|
||||
ptr_ += n;
|
||||
@ -404,25 +473,7 @@ Foam::UPtrList<T>::const_iterator::operator+=(label n)
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
Foam::operator+(const typename UPtrList<T>::const_iterator& iter, label n)
|
||||
{
|
||||
typename UPtrList<T>::const_iterator tmp = iter;
|
||||
return tmp += n;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
Foam::operator+(label n, const typename UPtrList<T>::const_iterator& iter)
|
||||
{
|
||||
typename UPtrList<T>::const_iterator tmp = iter;
|
||||
return tmp += n;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
inline typename Foam::UPtrList<T>::const_iterator&
|
||||
Foam::UPtrList<T>::const_iterator::operator-=(label n)
|
||||
{
|
||||
ptr_ -= n;
|
||||
@ -432,26 +483,31 @@ Foam::UPtrList<T>::const_iterator::operator-=(label n)
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
Foam::operator-(const typename UPtrList<T>::const_iterator& iter, label n)
|
||||
Foam::UPtrList<T>::const_iterator::operator+(label n) const
|
||||
{
|
||||
typename UPtrList<T>::const_iterator tmp = iter;
|
||||
return tmp -= n;
|
||||
return const_iterator(ptr_ + n);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::label Foam::operator-
|
||||
(
|
||||
const typename UPtrList<T>::const_iterator& iter1,
|
||||
const typename UPtrList<T>::const_iterator& iter2
|
||||
)
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
Foam::UPtrList<T>::const_iterator::operator-(label n) const
|
||||
{
|
||||
return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
|
||||
return const_iterator(ptr_ - n);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const T& Foam::UPtrList<T>::const_iterator::operator[](label n)
|
||||
inline Foam::label
|
||||
Foam::UPtrList<T>::const_iterator::operator-(const const_iterator& iter) const
|
||||
{
|
||||
return (ptr_ - iter.ptr_);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const T&
|
||||
Foam::UPtrList<T>::const_iterator::operator[](label n) const
|
||||
{
|
||||
return *(*this + n);
|
||||
}
|
||||
@ -497,6 +553,40 @@ inline bool Foam::UPtrList<T>::const_iterator::operator>=
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
Foam::UPtrList<T>::begin()
|
||||
{
|
||||
return ptrs_.begin();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::iterator
|
||||
Foam::UPtrList<T>::end()
|
||||
{
|
||||
return ptrs_.end();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
Foam::UPtrList<T>::cbegin() const
|
||||
{
|
||||
return ptrs_.cbegin();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
Foam::UPtrList<T>::cend() const
|
||||
{
|
||||
return ptrs_.cend();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
Foam::UPtrList<T>::begin() const
|
||||
@ -513,19 +603,13 @@ Foam::UPtrList<T>::end() const
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
Foam::UPtrList<T>::cbegin() const
|
||||
{
|
||||
return ptrs_.begin();
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline typename Foam::UPtrList<T>::const_iterator
|
||||
Foam::UPtrList<T>::cend() const
|
||||
inline void Foam::UPtrList<T>::operator=(UPtrList<T>&& lst)
|
||||
{
|
||||
return ptrs_.end();
|
||||
this->clear();
|
||||
this->swap(lst);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -29,18 +29,18 @@ License
|
||||
// * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const UPtrList<T>& L)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const UPtrList<T>& lst)
|
||||
{
|
||||
const label sz = L.size();
|
||||
const label len = lst.size();
|
||||
|
||||
// Size and start delimiter
|
||||
os << nl << indent << sz << nl
|
||||
os << nl << indent << len << nl
|
||||
<< indent << token::BEGIN_LIST << incrIndent << nl;
|
||||
|
||||
// Contents
|
||||
for (label i=0; i < sz; ++i)
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
os << L[i] << nl;
|
||||
os << lst[i] << nl;
|
||||
}
|
||||
|
||||
// End delimiter
|
||||
|
||||
@ -623,17 +623,6 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const dimensioned<Type>& dt)
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
bool Foam::operator>
|
||||
(
|
||||
const dimensioned<Type>& dt1,
|
||||
const dimensioned<Type>& dt2
|
||||
)
|
||||
{
|
||||
return dt1.value() > dt2.value();
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool Foam::operator<
|
||||
(
|
||||
@ -645,6 +634,17 @@ bool Foam::operator<
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool Foam::operator>
|
||||
(
|
||||
const dimensioned<Type>& dt1,
|
||||
const dimensioned<Type>& dt2
|
||||
)
|
||||
{
|
||||
return dt2.value() < dt1.value();
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::dimensioned<Type> Foam::operator+
|
||||
(
|
||||
|
||||
@ -274,10 +274,10 @@ template<class Type>
|
||||
dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
|
||||
|
||||
template<class Type>
|
||||
bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
|
||||
bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
|
||||
|
||||
template<class Type>
|
||||
bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
|
||||
bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
|
||||
|
||||
template<class Type>
|
||||
dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
|
||||
|
||||
@ -89,8 +89,8 @@ readField
|
||||
{
|
||||
for
|
||||
(
|
||||
IDLList<entry>::const_reverse_iterator iter = dict.rbegin();
|
||||
iter != dict.rend();
|
||||
IDLList<entry>::const_reverse_iterator iter = dict.crbegin();
|
||||
iter != dict.crend();
|
||||
++iter
|
||||
)
|
||||
{
|
||||
|
||||
@ -1458,7 +1458,7 @@ Foam::instantList Foam::fileOperations::masterUncollatedFileOperation::findTimes
|
||||
}
|
||||
Pstream::scatter(times);
|
||||
|
||||
instantList* tPtr = new instantList(times.xfer());
|
||||
instantList* tPtr = new instantList(std::move(times));
|
||||
|
||||
times_.insert(directory, tPtr);
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -38,29 +38,18 @@ Description
|
||||
|
||||
When transferring between dissimilar types, the xferCopyTo() and
|
||||
xferMoveTo() functions can prove useful. An example is transferring
|
||||
from a DynamicList to a List. Since the
|
||||
List\<T\>::transfer(List\<T\>&) method could result in some allocated
|
||||
memory becoming inaccessible, the xferMoveTo() function should be used to
|
||||
invoke the correct List\<T\>::transfer(DynamicList\<T\>&) method.
|
||||
from a DynamicList to a List.
|
||||
|
||||
\code
|
||||
DynamicList<label> dynLst;
|
||||
List<label> list1;
|
||||
DynamicList<label> list2;
|
||||
...
|
||||
labelList plainLst( xferMoveTo<labelList>(dynLst) );
|
||||
\endcode
|
||||
|
||||
Of course, since this example is a very common operation, the
|
||||
DynamicList::xfer() method transfers to a plain List anyhow.
|
||||
It would thus be simpler (and clearer) just to use the following code:
|
||||
|
||||
\code
|
||||
DynamicList<label> dynLst;
|
||||
...
|
||||
labelList plainLst(dynLst.xfer());
|
||||
SomeClass obj(xferCopy(list1), xferMoveTo<labelList>(list1));
|
||||
\endcode
|
||||
|
||||
See also
|
||||
xferCopy, xferCopyTo, xferMove, xferMoveTo, xferTmp
|
||||
xferCopy, xferCopyTo, xferMove, xferMoveTo
|
||||
|
||||
SourceFiles
|
||||
XferI.H
|
||||
@ -75,9 +64,6 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
template<class T> class tmp;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class Xfer Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -95,81 +81,80 @@ public:
|
||||
|
||||
typedef T Type;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Store object pointer and manage its deletion
|
||||
// Can also be used later to transfer by assignment
|
||||
inline explicit Xfer(T* p = nullptr);
|
||||
|
||||
//- Construct by copying or by transferring the parameter contents
|
||||
inline explicit Xfer(T& t, bool allowTransfer=false);
|
||||
|
||||
//- Construct by copying the parameter contents
|
||||
inline explicit Xfer(const T& t);
|
||||
|
||||
//- Construct by transferring the contents
|
||||
inline Xfer(const Xfer<T>& t);
|
||||
//- Construct, transferring its contents
|
||||
inline Xfer(const Xfer<T>& xf);
|
||||
|
||||
|
||||
//- Destructor
|
||||
inline ~Xfer();
|
||||
|
||||
|
||||
// Member Functions
|
||||
// Static Member Functions
|
||||
|
||||
//- Return a null object reference
|
||||
inline static const Xfer<T>& null();
|
||||
|
||||
//- Construct new Xfer container with forwarding arguments to T
|
||||
template<class... Args>
|
||||
inline static Xfer<T> New(Args&&... args);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Pointer to the underlying object
|
||||
inline T* get() const;
|
||||
|
||||
//- Swaps the managed objects
|
||||
void swap(Xfer<T>& other) noexcept;
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Transfer the contents into the object
|
||||
inline void operator=(T& t);
|
||||
//- Transfer contents into the object
|
||||
inline void operator=(const Xfer<T>& xf);
|
||||
|
||||
//- Transfer the contents into the object
|
||||
inline void operator=(const Xfer<T>& t);
|
||||
//- Reference to the underlying object
|
||||
inline T& operator*() const;
|
||||
|
||||
//- Reference to the underlying datatype
|
||||
//- Pointer to the underlying object
|
||||
inline T* operator->() const;
|
||||
|
||||
//- Reference to the underlying object
|
||||
inline T& operator()() const;
|
||||
|
||||
//- Pointer to the underlying datatype
|
||||
inline T* operator->() const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
//- Construct by copying the contents of the \a arg
|
||||
|
||||
//- Copy construct contents of the \a obj
|
||||
//
|
||||
// \sa xferCopyTo, xferMove, xferMoveTo, xferTmp and Foam::Xfer
|
||||
// \sa xferCopyTo, xferMove, xferMoveTo and Foam::Xfer
|
||||
template<class T>
|
||||
inline Xfer<T> xferCopy(const T& t);
|
||||
inline Xfer<T> xferCopy(const T& obj);
|
||||
|
||||
//- Construct by transferring the contents of the \a arg
|
||||
//- Transfer construct contents of the \a obj
|
||||
//
|
||||
// \sa xferCopy, xferCopyTo, xferMoveTo, xferTmp and Foam::Xfer
|
||||
// \sa xferCopy, xferCopyTo, xferMoveTo and Foam::Xfer
|
||||
template<class T>
|
||||
inline Xfer<T> xferMove(T& t);
|
||||
inline Xfer<T> xferMove(T& obj);
|
||||
|
||||
|
||||
//- Construct by transferring the contents of the \a arg
|
||||
//- Copy construct contents of the \a obj from dissimilar type
|
||||
//
|
||||
// \sa xferCopy, xferCopyTo, xferMove, xferMoveTo and Foam::Xfer
|
||||
template<class T>
|
||||
inline Xfer<T> xferTmp(Foam::tmp<T>& tt);
|
||||
// \sa xferCopy, xferMove, xferMoveTo and Foam::Xfer
|
||||
template<class T, class From>
|
||||
inline Xfer<T> xferCopyTo(const From& obj);
|
||||
|
||||
|
||||
//- Construct by copying the contents of the \a arg
|
||||
// between dissimilar types
|
||||
//
|
||||
// \sa xferCopy, xferMove, xferMoveTo, xferTmp and Foam::Xfer
|
||||
template<class To, class From>
|
||||
inline Xfer<To> xferCopyTo(const From& t);
|
||||
|
||||
|
||||
//- Construct by transferring the contents of the \a arg
|
||||
// between dissimilar types
|
||||
//- Transfer construct contents of the \a obj from dissimilar type
|
||||
//
|
||||
// \par Example Use
|
||||
// \code
|
||||
@ -178,9 +163,9 @@ inline Xfer<To> xferCopyTo(const From& t);
|
||||
// labelList plainLst( xferMoveTo<labelList>(dynLst) );
|
||||
// \endcode
|
||||
//
|
||||
// \sa xferCopy, xferCopyTo, xferMove, xferTmp and Foam::Xfer
|
||||
template<class To, class From>
|
||||
inline Xfer<To> xferMoveTo(From& t);
|
||||
// \sa xferCopy, xferCopyTo, xferMove and Foam::Xfer
|
||||
template<class T, class From>
|
||||
inline Xfer<T> xferMoveTo(From& obj);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -24,6 +24,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "nullObject.H"
|
||||
#include <utility>
|
||||
|
||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
@ -34,6 +35,15 @@ inline const Foam::Xfer<T>& Foam::Xfer<T>::null()
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
template<class... Args>
|
||||
inline Foam::Xfer<T> Foam::Xfer<T>::New(Args&&... args)
|
||||
{
|
||||
T* ptr = new T(std::forward<Args>(args)...);
|
||||
return Foam::Xfer<T>(ptr);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
@ -44,36 +54,35 @@ inline Foam::Xfer<T>::Xfer(T* p)
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::Xfer<T>::Xfer(T& t, bool allowTransfer)
|
||||
inline Foam::Xfer<T>::Xfer(const Xfer<T>& xf)
|
||||
:
|
||||
ptr_(new T)
|
||||
{
|
||||
if (allowTransfer)
|
||||
T* p = xf.get();
|
||||
|
||||
if (p && Foam::notNull(p))
|
||||
{
|
||||
ptr_->transfer(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr_->operator=(t);
|
||||
ptr_->transfer(*p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline Foam::Xfer<T>::Xfer(const T& t)
|
||||
:
|
||||
ptr_(new T)
|
||||
inline T* Foam::Xfer<T>::get() const
|
||||
{
|
||||
ptr_->operator=(t);
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::Xfer<T>::Xfer(const Xfer<T>& t)
|
||||
:
|
||||
ptr_(new T)
|
||||
inline void Foam::Xfer<T>::swap(Xfer<T>& other) noexcept
|
||||
{
|
||||
ptr_->transfer(*(t.ptr_));
|
||||
// Swap pointers
|
||||
T* tmp = ptr_;
|
||||
ptr_ = other.ptr;
|
||||
other.ptr_ = tmp;
|
||||
}
|
||||
|
||||
|
||||
@ -82,36 +91,29 @@ inline Foam::Xfer<T>::Xfer(const Xfer<T>& t)
|
||||
template<class T>
|
||||
inline Foam::Xfer<T>::~Xfer()
|
||||
{
|
||||
delete ptr_;
|
||||
if (ptr_ && Foam::notNull(ptr_))
|
||||
{
|
||||
delete ptr_;
|
||||
}
|
||||
ptr_ = nullptr;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline void Foam::Xfer<T>::operator=(T& t)
|
||||
inline void Foam::Xfer<T>::operator=(const Xfer<T>& xf)
|
||||
{
|
||||
ptr_->transfer(t);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::Xfer<T>::operator=(const Xfer<T>& t)
|
||||
{
|
||||
// silently ignore attempted copy to self
|
||||
if (this != &t)
|
||||
// Silently ignore attempted copy to self
|
||||
if (this != &xf)
|
||||
{
|
||||
ptr_->transfer(*(t.ptr_));
|
||||
ptr_->transfer(*xf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline T& Foam::Xfer<T>::operator()() const
|
||||
inline T& Foam::Xfer<T>::operator*() const
|
||||
{
|
||||
return *ptr_;
|
||||
}
|
||||
@ -124,45 +126,46 @@ inline T* Foam::Xfer<T>::operator->() const
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Helper Functions * * * * * * * * * * * * * * * //
|
||||
template<class T>
|
||||
inline T& Foam::Xfer<T>::operator()() const
|
||||
{
|
||||
return *ptr_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline Foam::Xfer<T> Foam::xferCopy(const T& t)
|
||||
inline Foam::Xfer<T> Foam::xferCopy(const T& obj)
|
||||
{
|
||||
return Foam::Xfer<T>(t);
|
||||
T* ptr = new T(obj);
|
||||
return Foam::Xfer<T>(ptr);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class From>
|
||||
inline Foam::Xfer<T> Foam::xferCopyTo(const From& obj)
|
||||
{
|
||||
T* ptr = new T(obj);
|
||||
return Foam::Xfer<T>(ptr);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::Xfer<T> Foam::xferMove(T& t)
|
||||
inline Foam::Xfer<T> Foam::xferMove(T& obj)
|
||||
{
|
||||
return Foam::Xfer<T>(t, true);
|
||||
T* ptr = new T;
|
||||
ptr->transfer(obj);
|
||||
return Foam::Xfer<T>(ptr);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::Xfer<T> Foam::xferTmp(Foam::tmp<T>& tt)
|
||||
template<class T, class From>
|
||||
inline Foam::Xfer<T> Foam::xferMoveTo(From& obj)
|
||||
{
|
||||
return Foam::Xfer<T>(tt(), tt.isTmp());
|
||||
}
|
||||
|
||||
|
||||
template<class To, class From>
|
||||
inline Foam::Xfer<To> Foam::xferCopyTo(const From& t)
|
||||
{
|
||||
Foam::Xfer<To> xf;
|
||||
xf() = t;
|
||||
return xf;
|
||||
}
|
||||
|
||||
|
||||
template<class To, class From>
|
||||
inline Foam::Xfer<To> Foam::xferMoveTo(From& t)
|
||||
{
|
||||
Foam::Xfer<To> xf;
|
||||
xf().transfer(t);
|
||||
return xf;
|
||||
T* ptr = new T;
|
||||
ptr->transfer(obj);
|
||||
return Foam::Xfer<T>(ptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -63,12 +63,12 @@ class tmp
|
||||
CONST_REF
|
||||
};
|
||||
|
||||
//- Type of object
|
||||
type type_;
|
||||
|
||||
//- Pointer to object
|
||||
mutable T* ptr_;
|
||||
|
||||
//- Type of object
|
||||
type type_;
|
||||
|
||||
|
||||
// Private member operators
|
||||
|
||||
|
||||
@ -48,16 +48,16 @@ inline void Foam::tmp<T>::operator++()
|
||||
template<class T>
|
||||
inline Foam::tmp<T>::tmp()
|
||||
:
|
||||
type_(TMP),
|
||||
ptr_(nullptr)
|
||||
ptr_(nullptr),
|
||||
type_(TMP)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::tmp<T>::tmp(T* p)
|
||||
:
|
||||
type_(TMP),
|
||||
ptr_(p)
|
||||
ptr_(p),
|
||||
type_(TMP)
|
||||
{
|
||||
if (p && !p->unique())
|
||||
{
|
||||
@ -72,16 +72,16 @@ inline Foam::tmp<T>::tmp(T* p)
|
||||
template<class T>
|
||||
inline Foam::tmp<T>::tmp(const T& t)
|
||||
:
|
||||
type_(CONST_REF),
|
||||
ptr_(const_cast<T*>(&t))
|
||||
ptr_(const_cast<T*>(&t)),
|
||||
type_(CONST_REF)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::tmp<T>::tmp(const tmp<T>& t)
|
||||
:
|
||||
type_(t.type_),
|
||||
ptr_(t.ptr_)
|
||||
ptr_(t.ptr_),
|
||||
type_(t.type_)
|
||||
{
|
||||
if (isTmp())
|
||||
{
|
||||
@ -102,8 +102,8 @@ inline Foam::tmp<T>::tmp(const tmp<T>& t)
|
||||
template<class T>
|
||||
inline Foam::tmp<T>::tmp(const tmp<T>&& t)
|
||||
:
|
||||
type_(t.type_),
|
||||
ptr_(t.ptr_)
|
||||
ptr_(t.ptr_),
|
||||
type_(t.type_)
|
||||
{
|
||||
if (isTmp())
|
||||
{
|
||||
@ -115,8 +115,8 @@ inline Foam::tmp<T>::tmp(const tmp<T>&& t)
|
||||
template<class T>
|
||||
inline Foam::tmp<T>::tmp(const tmp<T>& t, bool allowTransfer)
|
||||
:
|
||||
type_(t.type_),
|
||||
ptr_(t.ptr_)
|
||||
ptr_(t.ptr_),
|
||||
type_(t.type_)
|
||||
{
|
||||
if (isTmp())
|
||||
{
|
||||
@ -335,8 +335,8 @@ inline void Foam::tmp<T>::operator=(T* p)
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
type_ = TMP;
|
||||
ptr_ = p;
|
||||
type_ = TMP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -69,11 +69,11 @@ public:
|
||||
//- Construct given size, with invalid point labels (-1)
|
||||
explicit inline cell(const label sz);
|
||||
|
||||
//- Construct from list of labels
|
||||
//- Copy construct from list of labels
|
||||
explicit inline cell(const labelUList& lst);
|
||||
|
||||
//- Construct by transferring list of labels
|
||||
explicit inline cell(const Xfer<labelList>& lst);
|
||||
//- Move construct from list of labels
|
||||
explicit inline cell(labelList&& lst);
|
||||
|
||||
//- Construct from Istream
|
||||
inline cell(Istream& is);
|
||||
|
||||
@ -41,9 +41,9 @@ inline Foam::cell::cell(const labelUList& lst)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::cell::cell(const Xfer<labelList>& lst)
|
||||
inline Foam::cell::cell(labelList&& lst)
|
||||
:
|
||||
labelList(lst)
|
||||
labelList(std::move(lst))
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -606,23 +606,26 @@ Foam::face Foam::face::reverseFace() const
|
||||
// Reverse the label list and return
|
||||
// The starting points of the original and reverse face are identical.
|
||||
|
||||
const labelList& f = *this;
|
||||
labelList newList(size());
|
||||
const labelUList& origFace = *this;
|
||||
const label len = origFace.size();
|
||||
|
||||
newList[0] = f[0];
|
||||
|
||||
for (label pointi = 1; pointi < newList.size(); pointi++)
|
||||
face newFace(len);
|
||||
if (len)
|
||||
{
|
||||
newList[pointi] = f[size() - pointi];
|
||||
newFace[0] = origFace[0];
|
||||
for (label i=1; i < len; ++i)
|
||||
{
|
||||
newFace[i] = origFace[len - i];
|
||||
}
|
||||
}
|
||||
|
||||
return face(xferMove(newList));
|
||||
return newFace;
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::face::which(const label globalIndex) const
|
||||
{
|
||||
const labelList& f = *this;
|
||||
const labelUList& f = *this;
|
||||
|
||||
forAll(f, localIdx)
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user