mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'feature-improved-container-classes' into 'develop'
improved container classes See merge request !108
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -41,6 +41,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
DLList<scalar> myList;
|
DLList<scalar> myList;
|
||||||
|
|
||||||
|
Info<< "DLList<scalar>" << nl;
|
||||||
|
|
||||||
for (int i = 0; i<10; i++)
|
for (int i = 0; i<10; i++)
|
||||||
{
|
{
|
||||||
myList.append(1.3*i);
|
myList.append(1.3*i);
|
||||||
@ -49,9 +51,7 @@ int main(int argc, char *argv[])
|
|||||||
myList.append(100.3);
|
myList.append(100.3);
|
||||||
myList.append(500.3);
|
myList.append(500.3);
|
||||||
|
|
||||||
Info<< nl << "And again using STL iterator: " << nl << endl;
|
forAllConstIters(myList, iter)
|
||||||
|
|
||||||
forAllIter(DLList<scalar>, myList, iter)
|
|
||||||
{
|
{
|
||||||
Info<< "element:" << *iter << endl;
|
Info<< "element:" << *iter << endl;
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Info<< nl << "And again using the same STL iterator: " << nl << endl;
|
Info<< nl << "And again using the same STL iterator: " << nl << endl;
|
||||||
|
|
||||||
forAllIter(DLList<scalar>, myList, iter)
|
forAllIters(myList, iter)
|
||||||
{
|
{
|
||||||
Info<< "Removing " << myList.remove(iter) << endl;
|
Info<< "Removing " << myList.remove(iter) << endl;
|
||||||
}
|
}
|
||||||
@ -68,13 +68,10 @@ int main(int argc, char *argv[])
|
|||||||
myList.append(200.3);
|
myList.append(200.3);
|
||||||
myList.append(100.3);
|
myList.append(100.3);
|
||||||
|
|
||||||
|
Info<< nl << "Using range-based for: " << nl << endl;
|
||||||
Info<< nl << "And again using STL const_iterator: " << nl << endl;
|
for (auto val : myList)
|
||||||
|
|
||||||
|
|
||||||
forAllConstIter(DLList<scalar>, myList, iter)
|
|
||||||
{
|
{
|
||||||
Info<< "element:" << *iter << endl;
|
Info<< "element:" << val << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< nl << "Testing swapUp and swapDown: " << endl;
|
Info<< nl << "Testing swapUp and swapDown: " << endl;
|
||||||
@ -84,9 +81,9 @@ int main(int argc, char *argv[])
|
|||||||
myList.swapUp(myList.DLListBase::first());
|
myList.swapUp(myList.DLListBase::first());
|
||||||
myList.swapUp(myList.DLListBase::last());
|
myList.swapUp(myList.DLListBase::last());
|
||||||
|
|
||||||
forAllIter(DLList<scalar>, myList, iter)
|
for (auto val : myList)
|
||||||
{
|
{
|
||||||
Info<< "element:" << *iter << endl;
|
Info<< "element:" << val << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< nl << "swapDown" << endl;
|
Info<< nl << "swapDown" << endl;
|
||||||
@ -94,12 +91,11 @@ int main(int argc, char *argv[])
|
|||||||
myList.swapDown(myList.DLListBase::first());
|
myList.swapDown(myList.DLListBase::first());
|
||||||
myList.swapDown(myList.DLListBase::last());
|
myList.swapDown(myList.DLListBase::last());
|
||||||
|
|
||||||
forAllIter(DLList<scalar>, myList, iter)
|
for (auto val : myList)
|
||||||
{
|
{
|
||||||
Info<< "element:" << *iter << endl;
|
Info<< "element:" << val << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Info<< nl << "Testing transfer: " << nl << nl
|
Info<< nl << "Testing transfer: " << nl << nl
|
||||||
<< "original: " << myList << endl;
|
<< "original: " << myList << endl;
|
||||||
|
|
||||||
|
|||||||
@ -168,9 +168,24 @@ int main(int argc, char *argv[])
|
|||||||
Info<< nl << "scalarDict2: " << endl;
|
Info<< nl << "scalarDict2: " << endl;
|
||||||
forAllConstIter(PtrDictionary<Scalar>, scalarDict2, iter)
|
forAllConstIter(PtrDictionary<Scalar>, scalarDict2, iter)
|
||||||
{
|
{
|
||||||
|
std::cout<< "iter: " << typeid(*iter).name() << '\n';
|
||||||
|
|
||||||
Info<< "elem = " << *iter << endl;
|
Info<< "elem = " << *iter << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: the deduction seems to be different here.
|
||||||
|
// - returns pointer (as perhaps actually expected) not the
|
||||||
|
// underlying value.
|
||||||
|
forAllConstIters(scalarDict2, iter)
|
||||||
|
{
|
||||||
|
std::cout<< "iter: " << typeid(*iter).name() << '\n';
|
||||||
|
|
||||||
|
Info<< "elem = " << *(*iter) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<< "iter type: "
|
||||||
|
<< typeid(stdFoam::begin(scalarDict2)).name() << '\n';
|
||||||
|
|
||||||
scalarDict.transfer(scalarDict2);
|
scalarDict.transfer(scalarDict2);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -28,6 +28,8 @@ Description
|
|||||||
#include "hashedWordList.H"
|
#include "hashedWordList.H"
|
||||||
#include "HashSet.H"
|
#include "HashSet.H"
|
||||||
#include "Map.H"
|
#include "Map.H"
|
||||||
|
#include "labelPairHashes.H"
|
||||||
|
#include "FlatOutput.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
@ -65,6 +67,14 @@ int main(int argc, char *argv[])
|
|||||||
tableB.insert("value5", nil());
|
tableB.insert("value5", nil());
|
||||||
tableB.insert("value6", nil());
|
tableB.insert("value6", nil());
|
||||||
|
|
||||||
|
Info<< "tableA keys: "; tableA.writeKeys(Info) << endl;
|
||||||
|
|
||||||
|
auto keyIterPair = tableA.keys();
|
||||||
|
for (const auto& i : keyIterPair)
|
||||||
|
{
|
||||||
|
Info<<" keys: " << i << endl;
|
||||||
|
}
|
||||||
|
|
||||||
Map<label> mapA
|
Map<label> mapA
|
||||||
{
|
{
|
||||||
{ 1, 1 },
|
{ 1, 1 },
|
||||||
@ -122,14 +132,23 @@ int main(int argc, char *argv[])
|
|||||||
<< (wordHashSet(setA) | wordHashSet(tableA) | wordHashSet(tableB))
|
<< (wordHashSet(setA) | wordHashSet(tableA) | wordHashSet(tableB))
|
||||||
<< nl;
|
<< nl;
|
||||||
|
|
||||||
|
|
||||||
labelHashSet setB
|
labelHashSet setB
|
||||||
{
|
{
|
||||||
1, 11, 42
|
1, 11, 42
|
||||||
};
|
};
|
||||||
|
|
||||||
|
setB = FixedList<label, 4>({1, 2, 3, 4});
|
||||||
|
setB = {1, 2, 4};
|
||||||
|
setB = List<label>({1, 2, 4});
|
||||||
Info<< "setB : " << setB << endl;
|
Info<< "setB : " << setB << endl;
|
||||||
|
|
||||||
|
labelPair pair(12, 15);
|
||||||
|
setB.set(pair);
|
||||||
|
|
||||||
|
Info<< "setB : " << setB << endl;
|
||||||
|
setB.unset(pair);
|
||||||
|
|
||||||
|
|
||||||
labelHashSet setC(1);
|
labelHashSet setC(1);
|
||||||
setC.insert(2008);
|
setC.insert(2008);
|
||||||
setC.insert(1984);
|
setC.insert(1984);
|
||||||
@ -139,7 +158,7 @@ int main(int argc, char *argv[])
|
|||||||
labelHashSet setD(1);
|
labelHashSet setD(1);
|
||||||
setD.insert({11, 100, 49, 36, 2008});
|
setD.insert({11, 100, 49, 36, 2008});
|
||||||
|
|
||||||
Info<< "setD : " << setD << endl;
|
Info<< "setD : " << flatOutput(setD) << endl;
|
||||||
|
|
||||||
Info<< "setB == setC: " << (setB == setC) << endl;
|
Info<< "setB == setC: " << (setB == setC) << endl;
|
||||||
Info<< "setC != setD: " << (setC != setD) << endl;
|
Info<< "setC != setD: " << (setC != setD) << endl;
|
||||||
@ -178,9 +197,9 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "setD has no 11" << endl;
|
Info<< "setD has no 11" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< "setD : " << setD << endl;
|
Info<< "setD : " << flatOutput(setD) << endl;
|
||||||
|
|
||||||
// this doesn't work (yet?)
|
// This should not work (yet?)
|
||||||
// setD[12] = true;
|
// setD[12] = true;
|
||||||
|
|
||||||
List<label> someLst(10);
|
List<label> someLst(10);
|
||||||
@ -191,8 +210,14 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
label added = setD.set(someLst);
|
label added = setD.set(someLst);
|
||||||
Info<< "added " << added << " from " << someLst.size() << endl;
|
Info<< "added " << added << " from " << someLst.size() << endl;
|
||||||
Info<< "setD : " << setD << endl;
|
Info<< "setD : " << flatOutput(setD) << endl;
|
||||||
|
|
||||||
|
Info<< "setD for-range()" << nl;
|
||||||
|
|
||||||
|
for (auto i : setD)
|
||||||
|
{
|
||||||
|
Info << i << endl;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
|
#include "List.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
#include "IStringStream.H"
|
#include "IStringStream.H"
|
||||||
#include "OStringStream.H"
|
#include "OStringStream.H"
|
||||||
@ -62,7 +63,7 @@ int main()
|
|||||||
Info<< "\ntable1 sortedToc: " << table1.sortedToc() << endl;
|
Info<< "\ntable1 sortedToc: " << table1.sortedToc() << endl;
|
||||||
table1.printInfo(Info)
|
table1.printInfo(Info)
|
||||||
<< "table1 [" << table1.size() << "] " << endl;
|
<< "table1 [" << table1.size() << "] " << endl;
|
||||||
forAllConstIter(HashTable<scalar>, table1, iter)
|
forAllConstIters(table1, iter)
|
||||||
{
|
{
|
||||||
Info<< iter.key() << " => " << iter() << nl;
|
Info<< iter.key() << " => " << iter() << nl;
|
||||||
}
|
}
|
||||||
@ -106,7 +107,7 @@ int main()
|
|||||||
<< "\ntable3" << table3 << nl;
|
<< "\ntable3" << table3 << nl;
|
||||||
|
|
||||||
Info<< "\nerase table2 by iterator" << nl;
|
Info<< "\nerase table2 by iterator" << nl;
|
||||||
forAllIter(HashTable<scalar>, table2, iter)
|
forAllIters(table2, iter)
|
||||||
{
|
{
|
||||||
Info<< "erasing " << iter.key() << " => " << iter.object() << " ... ";
|
Info<< "erasing " << iter.key() << " => " << iter.object() << " ... ";
|
||||||
table2.erase(iter);
|
table2.erase(iter);
|
||||||
@ -177,6 +178,23 @@ int main()
|
|||||||
|
|
||||||
Info<< "\ntable1" << table1 << nl;
|
Info<< "\ntable1" << table1 << nl;
|
||||||
|
|
||||||
|
Info<< "\nrange-for(table1) - returns values" << nl;
|
||||||
|
for (const auto& it : table1)
|
||||||
|
{
|
||||||
|
Info<< "val:" << it << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< "\nrange-for(table1.keys()) - returns keys" << nl;
|
||||||
|
for (const auto& k : table1.keys())
|
||||||
|
{
|
||||||
|
Info<< "key:" << k << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// These do not yet work. Issues resolving the distance.
|
||||||
|
//
|
||||||
|
// List<scalar> table1vals(table1.begin(), table1.end());
|
||||||
|
// wordList table1keys(table1.begin(), table1.end());
|
||||||
|
|
||||||
Info<< "\nDone\n";
|
Info<< "\nDone\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -78,7 +78,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Info<< nl << "And again using STL iterator: " << nl << endl;
|
Info<< nl << "And again using STL iterator: " << nl << endl;
|
||||||
|
|
||||||
forAllIter(SLList<scalar>, myList, iter)
|
forAllIters(myList, iter)
|
||||||
{
|
{
|
||||||
Info<< "element:" << *iter << endl;
|
Info<< "element:" << *iter << endl;
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
const ISLList<Scalar>& const_myList = myList;
|
const ISLList<Scalar>& const_myList = myList;
|
||||||
|
|
||||||
forAllConstIter(SLList<scalar>, const_myList, iter)
|
forAllConstIters(const_myList, iter)
|
||||||
{
|
{
|
||||||
Info<< "element:" << *iter << endl;
|
Info<< "element:" << *iter << endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,7 +76,6 @@ int main(int argc, char *argv[])
|
|||||||
Info<<"is >>: " << intlist << endl;
|
Info<<"is >>: " << intlist << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<vector> list1(IStringStream("1 ((0 1 2))")());
|
List<vector> list1(IStringStream("1 ((0 1 2))")());
|
||||||
Info<< "list1: " << list1 << endl;
|
Info<< "list1: " << list1 << endl;
|
||||||
|
|
||||||
@ -150,7 +149,6 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "normal: " << longLabelList << nl;
|
Info<< "normal: " << longLabelList << nl;
|
||||||
Info<< "flatOutput: " << flatOutput(longLabelList) << nl;
|
Info<< "flatOutput: " << flatOutput(longLabelList) << nl;
|
||||||
// Info<< "flatOutput(14): " << flatOutput(longLabelList, 14) << nl;
|
// Info<< "flatOutput(14): " << flatOutput(longLabelList, 14) << nl;
|
||||||
// Info<< "flatOutput(15): " << flatOutput(longLabelList, 15) << nl;
|
|
||||||
|
|
||||||
stringList longStringList(12);
|
stringList longStringList(12);
|
||||||
forAll(longStringList, i)
|
forAll(longStringList, i)
|
||||||
@ -165,6 +163,66 @@ int main(int argc, char *argv[])
|
|||||||
// contiguous longStringList[i].resize(3, 'a' + i);
|
// contiguous longStringList[i].resize(3, 'a' + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test SubList and labelRange
|
||||||
|
{
|
||||||
|
Info<< nl;
|
||||||
|
labelList longLabelList = identity(25);
|
||||||
|
reverse(longLabelList);
|
||||||
|
|
||||||
|
FixedList<label, 6> fixedLabelList{0,1,2,3,4,5};
|
||||||
|
const labelList constLabelList = identity(25);
|
||||||
|
|
||||||
|
Info<< "full-list: " << flatOutput(longLabelList) << nl;
|
||||||
|
|
||||||
|
labelRange range1(-15, 25);
|
||||||
|
Info<<"sub range:" << range1 << "=";
|
||||||
|
Info<< SubList<label>(longLabelList, range1) << nl;
|
||||||
|
|
||||||
|
labelRange range2(7, 8);
|
||||||
|
Info<<"sub range:" << range2 << "=";
|
||||||
|
Info<< SubList<label>(longLabelList, range2) << nl;
|
||||||
|
|
||||||
|
// labelRange range2(7, 8);
|
||||||
|
Info<<"use range " << range2 << " to set value";
|
||||||
|
SubList<label>(longLabelList, range2) = -15;
|
||||||
|
Info<< "=> " << flatOutput(longLabelList) << nl;
|
||||||
|
|
||||||
|
// This syntax looks even nicer:
|
||||||
|
|
||||||
|
// GOOD: does not compile
|
||||||
|
// > constLabelList[labelRange(23,5)] = 5;
|
||||||
|
|
||||||
|
// Check correct overlaps
|
||||||
|
longLabelList[labelRange(-10, 12)] = 200;
|
||||||
|
longLabelList[{18,3}] = 100;
|
||||||
|
longLabelList[{23,3}] = 400;
|
||||||
|
// and complete misses
|
||||||
|
longLabelList[{500,50}] = 100;
|
||||||
|
|
||||||
|
// labelRange automatically suppresses -ve size -> nop
|
||||||
|
longLabelList[{5,-5}] = 42;
|
||||||
|
longLabelList[{21,100}] = 42;
|
||||||
|
|
||||||
|
//Good: does not compile
|
||||||
|
//> longLabelList[labelRange(20,50)] = constLabelList;
|
||||||
|
|
||||||
|
//Good: does not compile
|
||||||
|
// longLabelList[labelRange(20,50)] = fixedLabelList;
|
||||||
|
|
||||||
|
Info<< "updated: " << constLabelList[labelRange(23,5)] << nl;
|
||||||
|
Info<< "updated: " << flatOutput(longLabelList) << nl;
|
||||||
|
|
||||||
|
//Nope: sort(longLabelList[labelRange(18,5)]);
|
||||||
|
{
|
||||||
|
// Instead
|
||||||
|
UList<label> sub = longLabelList[labelRange(0, 8)];
|
||||||
|
sort(sub);
|
||||||
|
}
|
||||||
|
Info<< "sub-sorted: " << flatOutput(longLabelList) << nl;
|
||||||
|
|
||||||
|
// Info<<"Slice=" << longLabelList[labelRange(23,5)] << nl;
|
||||||
|
}
|
||||||
|
|
||||||
wordReList reLst;
|
wordReList reLst;
|
||||||
wordList wLst;
|
wordList wLst;
|
||||||
stringList sLst;
|
stringList sLst;
|
||||||
|
|||||||
@ -77,24 +77,12 @@ int main(int argc, char *argv[])
|
|||||||
<< "] = '" << namedEnumTest::namedEnum[opt] << "'" << nl;
|
<< "] = '" << namedEnumTest::namedEnum[opt] << "'" << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __cplusplus > 201100L
|
|
||||||
// C++11
|
|
||||||
Info<< "loop over enums (C++11 for range):" << nl;
|
Info<< "loop over enums (C++11 for range):" << nl;
|
||||||
for (auto const& opt : options)
|
for (const auto& opt : options)
|
||||||
{
|
{
|
||||||
Info<< "option[" << opt
|
Info<< "option[" << opt
|
||||||
<< "] = '" << namedEnumTest::namedEnum[opt] << "'" << nl;
|
<< "] = '" << namedEnumTest::namedEnum[opt] << "'" << nl;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
Info<< "loop over enums (via iterator):" << nl;
|
|
||||||
forAllConstIter(List<namedEnumTest::option>, options, iter)
|
|
||||||
{
|
|
||||||
const namedEnumTest::option& opt = *iter;
|
|
||||||
|
|
||||||
Info<< "option[" << opt
|
|
||||||
<< "] = '" << namedEnumTest::namedEnum[opt] << "'" << nl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Info<< nl
|
Info<< nl
|
||||||
<< namedEnumTest::namedEnum["a"] << nl
|
<< namedEnumTest::namedEnum["a"] << nl
|
||||||
|
|||||||
@ -52,29 +52,29 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Info<< nl << "And again using STL iterator: " << nl << endl;
|
Info<< nl << "And again using STL iterator: " << nl << endl;
|
||||||
|
|
||||||
forAllIter(SLList<scalar>, myList, iter)
|
for (const auto& val : myList)
|
||||||
{
|
{
|
||||||
Info<< "element:" << *iter << endl;
|
Info<< "element:" << val << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< nl << "And again using STL const_iterator: " << nl << endl;
|
Info<< nl << "And again using STL const_iterator: " << nl << endl;
|
||||||
|
|
||||||
const SLList<scalar>& const_myList = myList;
|
const SLList<scalar>& const_myList = myList;
|
||||||
|
|
||||||
forAllConstIter(SLList<scalar>, const_myList, iter)
|
forAllConstIters(const_myList, iter)
|
||||||
{
|
{
|
||||||
Info<< "element:" << *iter << endl;
|
Info<< "element:" << *iter << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
forAllIter(SLList<scalar>, myList, iter)
|
forAllIters(myList, iter)
|
||||||
{
|
{
|
||||||
Info<< "Removing element:" << *iter << endl;
|
Info<< "Removing element:" << *iter << endl;
|
||||||
myList.remove(iter);
|
myList.remove(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
forAllConstIter(SLList<scalar>, const_myList, iter)
|
for (const auto& val : const_myList)
|
||||||
{
|
{
|
||||||
Info<< "element:" << *iter << endl;
|
Info<< "element:" << val << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,7 @@ Description
|
|||||||
#include "Tuple2.H"
|
#include "Tuple2.H"
|
||||||
#include "label.H"
|
#include "label.H"
|
||||||
#include "scalar.H"
|
#include "scalar.H"
|
||||||
|
#include "List.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
@ -39,9 +40,25 @@ using namespace Foam;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Tuple2<label, scalar> t2(1, 3.2);
|
typedef Tuple2<label, scalar> indexedScalar;
|
||||||
|
|
||||||
Info<< t2 << " " << t2.first() << " " << t2.second() << endl;
|
indexedScalar t2(1, 3.2);
|
||||||
|
|
||||||
|
Info<< "tuple: "
|
||||||
|
<< t2 << " "
|
||||||
|
<< t2.first() << " " << t2.second() << endl;
|
||||||
|
|
||||||
|
List<indexedScalar> list1(10);
|
||||||
|
forAll(list1, i)
|
||||||
|
{
|
||||||
|
list1[i] = indexedScalar(-i, i*i);
|
||||||
|
}
|
||||||
|
|
||||||
|
sort(list1);
|
||||||
|
|
||||||
|
Info<< "tuples:" << nl
|
||||||
|
<< list1
|
||||||
|
<< endl;
|
||||||
|
|
||||||
Info<< "End\n" << endl;
|
Info<< "End\n" << endl;
|
||||||
|
|
||||||
|
|||||||
3
applications/test/cplusplus1/Make/files
Normal file
3
applications/test/cplusplus1/Make/files
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Test-cpluplus1.C
|
||||||
|
|
||||||
|
EXE = $(FOAM_USER_APPBIN)/Test-cpluplus1
|
||||||
2
applications/test/cplusplus1/Make/options
Normal file
2
applications/test/cplusplus1/Make/options
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */
|
||||||
|
/* EXE_LIBS = -lfiniteVolume */
|
||||||
88
applications/test/cplusplus1/Test-cpluplus1.C
Normal file
88
applications/test/cplusplus1/Test-cpluplus1.C
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / 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/>.
|
||||||
|
|
||||||
|
Description
|
||||||
|
Test miscellaneous C++ templates/functionality.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "string.H"
|
||||||
|
#include "IOstreams.H"
|
||||||
|
#include "UList.H"
|
||||||
|
#include "HashSet.H"
|
||||||
|
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
using namespace Foam;
|
||||||
|
|
||||||
|
// Macros to stringify macro contents.
|
||||||
|
#define STRINGIFY(content) #content
|
||||||
|
#define STRING_QUOTE(input) STRINGIFY(input)
|
||||||
|
|
||||||
|
#define PRINT_TYPEID(arg) \
|
||||||
|
Info<< typeid(arg).name() << " <= typeid of " << STRING_QUOTE(arg) << nl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
// Main program:
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
Info<< "various declaration types" << nl << nl;
|
||||||
|
|
||||||
|
PRINT_TYPEID(label);
|
||||||
|
PRINT_TYPEID(decltype(UList<label>::value_type()));
|
||||||
|
PRINT_TYPEID(decltype(std::declval<UList<label>>().cbegin()));
|
||||||
|
PRINT_TYPEID(decltype(*(std::declval<UList<label>>().cbegin())));
|
||||||
|
Info<< nl;
|
||||||
|
|
||||||
|
PRINT_TYPEID(decltype(HashTable<label>::key_type()));
|
||||||
|
PRINT_TYPEID(decltype(HashTable<label>::value_type()));
|
||||||
|
// Not yet: PRINT_TYPEID(decltype(HashTable<label>::mapped_type()));
|
||||||
|
PRINT_TYPEID(decltype(std::declval<HashTable<label>>().begin()));
|
||||||
|
PRINT_TYPEID(decltype(std::declval<const HashTable<label>>().begin()));
|
||||||
|
PRINT_TYPEID(decltype(*(std::declval<HashTable<label>>().begin())));
|
||||||
|
PRINT_TYPEID(decltype(*(std::declval<const HashTable<label>>().begin())));
|
||||||
|
|
||||||
|
PRINT_TYPEID(decltype(std::declval<const HashTable<label>>().keys()));
|
||||||
|
Info<< nl;
|
||||||
|
|
||||||
|
PRINT_TYPEID(decltype(HashSet<label>::key_type()));
|
||||||
|
PRINT_TYPEID(decltype(HashSet<label>::value_type()));
|
||||||
|
// Not yet: PRINT_TYPEID(decltype(HashSet<label>::mapped_type()));
|
||||||
|
PRINT_TYPEID(decltype(std::declval<HashSet<label>>().begin()));
|
||||||
|
PRINT_TYPEID(decltype(std::declval<const HashSet<label>>().begin()));
|
||||||
|
PRINT_TYPEID(decltype(*(std::declval<HashSet<label>>().begin())));
|
||||||
|
PRINT_TYPEID(decltype(*(std::declval<const HashSet<label>>().begin())));
|
||||||
|
Info<< nl;
|
||||||
|
|
||||||
|
Info << "\nEnd\n" << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -31,6 +31,7 @@ Description
|
|||||||
|
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
#include "edgeList.H"
|
#include "edgeList.H"
|
||||||
|
#include "edgeHashes.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
@ -66,6 +67,17 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Info<< e3 << " connects " << e2 << " => " << e2.connects(e3) << endl;
|
Info<< e3 << " connects " << e2 << " => " << e2.connects(e3) << endl;
|
||||||
|
|
||||||
|
labelPair labels(e3);
|
||||||
|
|
||||||
|
Info<< "as labelPair: " << labels << endl;
|
||||||
|
|
||||||
|
edge e5;
|
||||||
|
// Good: this fails (explicit constructor): printInfo(labels);
|
||||||
|
// Good: this also fails (no assignment operator): e5 = labels;
|
||||||
|
|
||||||
|
// OK: explicit
|
||||||
|
edge e6(labels);
|
||||||
|
|
||||||
Info<< nl << "hash-like functionality" << nl;
|
Info<< nl << "hash-like functionality" << nl;
|
||||||
|
|
||||||
// doesn't work e4 = -1;
|
// doesn't work e4 = -1;
|
||||||
@ -79,6 +91,28 @@ int main(int argc, char *argv[])
|
|||||||
printInfo(e4);
|
printInfo(e4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e4.start() = e4.end() = -1;
|
||||||
|
Info<< "insert from list\n";
|
||||||
|
labelHashSet newIndices({2, -1, 2, 1, 4, 1, 2, 3});
|
||||||
|
e4.insert(newIndices.toc());
|
||||||
|
printInfo(e4);
|
||||||
|
|
||||||
|
e4.start() = e4.end() = -1;
|
||||||
|
Info<< "insert from list\n";
|
||||||
|
e4.insert({0, 5, 2, -1, 2, 1, 4, 1, 2, 3});
|
||||||
|
printInfo(e4);
|
||||||
|
|
||||||
|
FixedList<label, 8> otherIndices{12, 2, -1, 1, 4, 1, 2, 3};
|
||||||
|
e4.start() = e4.end() = -1;
|
||||||
|
Info<< "insert from list: " << otherIndices << nl;
|
||||||
|
e4.insert(otherIndices);
|
||||||
|
printInfo(e4);
|
||||||
|
|
||||||
|
e4.start() = e4.end();
|
||||||
|
Info<< "erase from list: " << otherIndices << nl;
|
||||||
|
Info<< "removed " << e4.erase(otherIndices) << " values" << nl;
|
||||||
|
printInfo(e4);
|
||||||
|
|
||||||
for (label i : {-1, 0, 1, 3})
|
for (label i : {-1, 0, 1, 3})
|
||||||
{
|
{
|
||||||
bool ok = e4.erase(i);
|
bool ok = e4.erase(i);
|
||||||
|
|||||||
@ -28,10 +28,6 @@ Description
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
#include "IOobject.H"
|
|
||||||
#include "IOstreams.H"
|
|
||||||
#include "IFstream.H"
|
|
||||||
#include "IStringStream.H"
|
|
||||||
#include "labelRanges.H"
|
#include "labelRanges.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
@ -42,6 +38,7 @@ using namespace Foam;
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
argList::noParallel();
|
argList::noParallel();
|
||||||
|
argList::noFunctionObjects();
|
||||||
argList::validArgs.insert("start size .. startN sizeN");
|
argList::validArgs.insert("start size .. startN sizeN");
|
||||||
argList::addOption("verbose");
|
argList::addOption("verbose");
|
||||||
argList::addNote
|
argList::addNote
|
||||||
@ -57,6 +54,34 @@ int main(int argc, char *argv[])
|
|||||||
labelRange::debug = 1;
|
labelRange::debug = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Info<<"test sorting" << endl;
|
||||||
|
DynamicList<labelRange> list1(10);
|
||||||
|
list1.append(labelRange(25, 8));
|
||||||
|
list1.append(labelRange(0, 10));
|
||||||
|
list1.append(labelRange(15, 5));
|
||||||
|
list1.append(labelRange(50, -10));
|
||||||
|
|
||||||
|
sort(list1);
|
||||||
|
Info<<"sorted" << list1 << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Info<<"test intersections" << endl;
|
||||||
|
labelRange range1(-15, 25);
|
||||||
|
labelRange range2(7, 8);
|
||||||
|
labelRange range3(-20, 8);
|
||||||
|
labelRange range4(50, 8);
|
||||||
|
|
||||||
|
Info<<range1 << " & " << range2
|
||||||
|
<< " = " << range1.subset(range2) << nl;
|
||||||
|
|
||||||
|
Info<< range1 << " & " << range3
|
||||||
|
<< " = " << range1.subset(range3) << nl;
|
||||||
|
|
||||||
|
Info<< range2 << " & " << range4
|
||||||
|
<< " = " << range2.subset(range4) << nl;
|
||||||
|
}
|
||||||
|
|
||||||
labelRange range;
|
labelRange range;
|
||||||
labelRanges ranges;
|
labelRanges ranges;
|
||||||
@ -76,12 +101,9 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
label start = 0;
|
label start = args.argRead<label>(argI);
|
||||||
label size = 0;
|
label size = args.argRead<label>(argI+1);
|
||||||
|
|
||||||
IStringStream(args[argI])() >> start;
|
|
||||||
++argI;
|
++argI;
|
||||||
IStringStream(args[argI])() >> size;
|
|
||||||
|
|
||||||
range.reset(start, size);
|
range.reset(start, size);
|
||||||
}
|
}
|
||||||
@ -90,9 +112,9 @@ int main(int argc, char *argv[])
|
|||||||
if (removeMode)
|
if (removeMode)
|
||||||
{
|
{
|
||||||
Info<< "del " << range << " :";
|
Info<< "del " << range << " :";
|
||||||
forAllConstIter(labelRange, range, iter)
|
for (auto i : range)
|
||||||
{
|
{
|
||||||
Info<< " " << iter();
|
Info<< " " << i;
|
||||||
}
|
}
|
||||||
Info<< nl;
|
Info<< nl;
|
||||||
|
|
||||||
@ -101,9 +123,9 @@ int main(int argc, char *argv[])
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Info<< "add " << range << " :";
|
Info<< "add " << range << " :";
|
||||||
forAllConstIter(labelRange, range, iter)
|
for (auto i : range)
|
||||||
{
|
{
|
||||||
Info<< " " << iter();
|
Info<< " " << i;
|
||||||
}
|
}
|
||||||
Info<< nl;
|
Info<< nl;
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
Test-nullObject.C
|
Test-nullObject.C
|
||||||
|
|
||||||
EXE = $(FOAM_USER_APPBIN)/nullObject
|
EXE = $(FOAM_USER_APPBIN)/Test-nullObject
|
||||||
|
|||||||
@ -21,6 +21,17 @@ int main()
|
|||||||
SimpleClass* ptrToClass = new SimpleClass;
|
SimpleClass* ptrToClass = new SimpleClass;
|
||||||
SimpleClass& refToClass(*ptrToClass);
|
SimpleClass& refToClass(*ptrToClass);
|
||||||
|
|
||||||
|
typedef unsigned long ptrval;
|
||||||
|
|
||||||
|
Info<<"nullObject address=" << ptrval(&(nullObjectPtr)) << endl;
|
||||||
|
Info<<"sizeof(nullObject)" << " == "
|
||||||
|
<< sizeof(NullObject::nullObject)
|
||||||
|
<< " vs. sizeof(void*)" << " == " << sizeof(void*)
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
Info<<"nullObject pointer:" << ptrval(nullObjectPtr->pointer()) << endl;
|
||||||
|
Info<<"nullObject value:" << nullObjectPtr->value() << endl;
|
||||||
|
|
||||||
if (notNull(ptrToClass))
|
if (notNull(ptrToClass))
|
||||||
{
|
{
|
||||||
Info<< "Pass: ptrToClass is not null" << endl;
|
Info<< "Pass: ptrToClass is not null" << endl;
|
||||||
|
|||||||
@ -29,6 +29,9 @@ Description
|
|||||||
#include "pTraits.H"
|
#include "pTraits.H"
|
||||||
#include "vector.H"
|
#include "vector.H"
|
||||||
#include "tensor.H"
|
#include "tensor.H"
|
||||||
|
#include "uLabel.H"
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
@ -40,7 +43,10 @@ void printTraits()
|
|||||||
{
|
{
|
||||||
Info<< pTraits<T>::typeName
|
Info<< pTraits<T>::typeName
|
||||||
<< ": zero=" << pTraits<T>::zero
|
<< ": zero=" << pTraits<T>::zero
|
||||||
<< " one=" << pTraits<T>::one << endl;
|
<< " one=" << pTraits<T>::one
|
||||||
|
<< " integral=" << std::is_integral<T>::value
|
||||||
|
<< " floating=" << std::is_floating_point<T>::value
|
||||||
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -51,6 +57,9 @@ void printTraits(const pTraits<T>& p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#pragma GCC diagnostic warning "-Wmaybe-uninitialized"
|
||||||
|
#pragma GCC diagnostic warning "-Wuninitialized"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
printTraits<bool>();
|
printTraits<bool>();
|
||||||
@ -71,6 +80,27 @@ int main()
|
|||||||
|
|
||||||
printTraits(pTraits<scalar>(3.14159));
|
printTraits(pTraits<scalar>(3.14159));
|
||||||
|
|
||||||
|
label abc;
|
||||||
|
Info<< "unintialized primitive:"<< abc << endl;
|
||||||
|
|
||||||
|
label def = label();
|
||||||
|
Info<< "intialized primitive:"<< def << endl;
|
||||||
|
|
||||||
|
Info<< nl << "some interesting label limits:" << nl;
|
||||||
|
std::cout<< "sizeof = " << sizeof(label) << nl;
|
||||||
|
std::cout<< "min = " << pTraits<label>::min << nl;
|
||||||
|
std::cout<< "max = " << pTraits<label>::max << nl;
|
||||||
|
std::cout<< "umax = " << pTraits<uLabel>::max << nl;
|
||||||
|
|
||||||
|
std::cout<< "max_2 = " << pTraits<label>::max/2 << " == "
|
||||||
|
<< (1 << (sizeof(label)*8-2)) << nl;
|
||||||
|
|
||||||
|
std::cout<< "max_4 = " << pTraits<label>::max/4 << " == "
|
||||||
|
<< (1 << (sizeof(label)*8-3)) << nl;
|
||||||
|
|
||||||
|
std::cout<< "max_8 = " << pTraits<label>::max/8 << " == "
|
||||||
|
<< (1 << (sizeof(label)*8-4)) << nl;
|
||||||
|
|
||||||
Info<< "End\n" << endl;
|
Info<< "End\n" << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -536,12 +536,7 @@ Foam::label Foam::DistributedDelaunayMesh<Triangulation>::referVertices
|
|||||||
|
|
||||||
if (!pointsNotInserted.empty())
|
if (!pointsNotInserted.empty())
|
||||||
{
|
{
|
||||||
for
|
forAllConstIters(pointsNotInserted, iter)
|
||||||
(
|
|
||||||
labelPairHashSet::const_iterator iter = pointsNotInserted.begin();
|
|
||||||
iter != pointsNotInserted.end();
|
|
||||||
++iter
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (receivedVertices.found(iter.key()))
|
if (receivedVertices.found(iter.key()))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -24,16 +24,14 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "regExp.H"
|
#include "regExp.H"
|
||||||
#include "string.H"
|
|
||||||
#include "List.H"
|
#include "List.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
bool Foam::regExp::matchGrouping
|
bool Foam::regExp::matchGrouping
|
||||||
(
|
(
|
||||||
const std::string& text,
|
const std::string& text,
|
||||||
List<StringType>& groups
|
List<std::string>& groups
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (preg_ && !text.empty())
|
if (preg_ && !text.empty())
|
||||||
@ -194,7 +192,7 @@ std::string::size_type Foam::regExp::find(const std::string& text) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return string::npos;
|
return std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -231,28 +229,4 @@ bool Foam::regExp::match
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::regExp::match
|
|
||||||
(
|
|
||||||
const std::string& text,
|
|
||||||
List<Foam::string>& groups
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
return matchGrouping(text, groups);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
void Foam::regExp::operator=(const char* pattern)
|
|
||||||
{
|
|
||||||
set(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Foam::regExp::operator=(const std::string& pattern)
|
|
||||||
{
|
|
||||||
set(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -51,7 +51,6 @@ namespace Foam
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Forward declaration of classes
|
// Forward declaration of classes
|
||||||
class string;
|
|
||||||
template<class T> class List;
|
template<class T> class List;
|
||||||
|
|
||||||
|
|
||||||
@ -76,12 +75,10 @@ class regExp
|
|||||||
void operator=(const regExp&) = delete;
|
void operator=(const regExp&) = delete;
|
||||||
|
|
||||||
//- Return true if it matches and sets the sub-groups matched.
|
//- Return true if it matches and sets the sub-groups matched.
|
||||||
// Templated to support both std::string and Foam::string
|
|
||||||
template<class StringType>
|
|
||||||
bool matchGrouping
|
bool matchGrouping
|
||||||
(
|
(
|
||||||
const std::string&,
|
const std::string&,
|
||||||
List<StringType>& groups
|
List<std::string>& groups
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
|
||||||
@ -96,16 +93,7 @@ public:
|
|||||||
// range: '[', ']' \n
|
// range: '[', ']' \n
|
||||||
//
|
//
|
||||||
// Don't bother checking for '{digit}' bounds
|
// Don't bother checking for '{digit}' bounds
|
||||||
inline static bool meta(const char c)
|
inline static bool meta(const char c);
|
||||||
{
|
|
||||||
return
|
|
||||||
(
|
|
||||||
(c == '.') // any character
|
|
||||||
|| (c == '*' || c == '+' || c == '?') // quantifiers
|
|
||||||
|| (c == '(' || c == ')' || c == '|') // grouping/branching
|
|
||||||
|| (c == '[' || c == ']') // range
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
@ -129,22 +117,13 @@ public:
|
|||||||
// Access
|
// Access
|
||||||
|
|
||||||
//- Return true if a precompiled expression does not exist
|
//- Return true if a precompiled expression does not exist
|
||||||
inline bool empty() const
|
inline bool empty() const;
|
||||||
{
|
|
||||||
return !preg_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Does a precompiled expression exist?
|
//- Does a precompiled expression exist?
|
||||||
inline bool exists() const
|
inline bool exists() const;
|
||||||
{
|
|
||||||
return preg_ ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The number of capture groups for a non-empty expression
|
//- The number of capture groups for a non-empty expression
|
||||||
inline unsigned ngroups() const
|
inline unsigned ngroups() const;
|
||||||
{
|
|
||||||
return preg_ ? preg_->re_nsub : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Editing
|
// Editing
|
||||||
@ -173,26 +152,19 @@ public:
|
|||||||
// The begin-of-line (^) and end-of-line ($) anchors are implicit
|
// The begin-of-line (^) and end-of-line ($) anchors are implicit
|
||||||
bool match(const std::string& text, List<std::string>& groups) const;
|
bool match(const std::string& text, List<std::string>& groups) const;
|
||||||
|
|
||||||
//- Return true if it matches and sets the sub-groups matched
|
|
||||||
// The begin-of-line (^) and end-of-line ($) anchors are implicit
|
|
||||||
bool match(const std::string& text, List<string>& groups) const;
|
|
||||||
|
|
||||||
//- Return true if the regex was found within string
|
//- Return true if the regex was found within string
|
||||||
bool search(const std::string& text) const
|
bool search(const std::string& text) const;
|
||||||
{
|
|
||||||
return std::string::npos != find(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Assign and compile pattern from a character array
|
//- Assign and compile pattern from a character array
|
||||||
// Always case sensitive
|
// Always case sensitive
|
||||||
void operator=(const char* pattern);
|
inline void operator=(const char* pattern);
|
||||||
|
|
||||||
//- Assign and compile pattern from string
|
//- Assign and compile pattern from string
|
||||||
// Always case sensitive
|
// Always case sensitive
|
||||||
void operator=(const std::string& pattern);
|
inline void operator=(const std::string& pattern);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -202,6 +174,8 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#include "regExpI.H"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
81
src/OSspecific/POSIX/regExpI.H
Normal file
81
src/OSspecific/POSIX/regExpI.H
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / 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/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::regExp::meta(const char c)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
(
|
||||||
|
(c == '.') // any character
|
||||||
|
|| (c == '*' || c == '+' || c == '?') // quantifiers
|
||||||
|
|| (c == '(' || c == ')' || c == '|') // grouping/branching
|
||||||
|
|| (c == '[' || c == ']') // range
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::regExp::empty() const
|
||||||
|
{
|
||||||
|
return !preg_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::regExp::exists() const
|
||||||
|
{
|
||||||
|
return preg_ ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline unsigned Foam::regExp::ngroups() const
|
||||||
|
{
|
||||||
|
return preg_ ? preg_->re_nsub : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::regExp::search(const std::string& text) const
|
||||||
|
{
|
||||||
|
return std::string::npos != find(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline void Foam::regExp::operator=(const char* pattern)
|
||||||
|
{
|
||||||
|
set(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void Foam::regExp::operator=(const std::string& pattern)
|
||||||
|
{
|
||||||
|
set(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -31,7 +31,7 @@ License
|
|||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(const label size)
|
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(const label size)
|
||||||
:
|
:
|
||||||
HashTable<T*, Key, Hash>(size)
|
parent_type(size)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -41,11 +41,11 @@ Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
|
|||||||
const HashPtrTable<T, Key, Hash>& ht
|
const HashPtrTable<T, Key, Hash>& ht
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
HashTable<T*, Key, Hash>()
|
parent_type(ht.capacity())
|
||||||
{
|
{
|
||||||
for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter)
|
for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter)
|
||||||
{
|
{
|
||||||
const T* ptr = *iter;
|
const T* ptr = iter.object();
|
||||||
if (ptr)
|
if (ptr)
|
||||||
{
|
{
|
||||||
this->insert(iter.key(), new T(*ptr));
|
this->insert(iter.key(), new T(*ptr));
|
||||||
@ -72,8 +72,8 @@ Foam::HashPtrTable<T, Key, Hash>::~HashPtrTable()
|
|||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
|
T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
|
||||||
{
|
{
|
||||||
T* ptr = *iter;
|
T* ptr = iter.object();
|
||||||
HashTable<T*, Key, Hash>::erase(iter);
|
this->parent_type::erase(iter);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,9 +81,9 @@ T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
|
|||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
|
bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
|
||||||
{
|
{
|
||||||
T* ptr = *iter;
|
T* ptr = iter.object();
|
||||||
|
|
||||||
if (HashTable<T*, Key, Hash>::erase(iter))
|
if (this->parent_type::erase(iter))
|
||||||
{
|
{
|
||||||
if (ptr)
|
if (ptr)
|
||||||
{
|
{
|
||||||
@ -102,17 +102,12 @@ bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
|
|||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
void Foam::HashPtrTable<T, Key, Hash>::clear()
|
void Foam::HashPtrTable<T, Key, Hash>::clear()
|
||||||
{
|
{
|
||||||
for
|
for (iterator iter = this->begin(); iter != this->end(); ++iter)
|
||||||
(
|
|
||||||
iterator iter = this->begin();
|
|
||||||
iter != this->end();
|
|
||||||
++iter
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
delete *iter;
|
delete iter.object();
|
||||||
}
|
}
|
||||||
|
|
||||||
HashTable<T*, Key, Hash>::clear();
|
this->parent_type::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -136,7 +131,7 @@ void Foam::HashPtrTable<T, Key, Hash>::operator=
|
|||||||
|
|
||||||
for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter)
|
for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter)
|
||||||
{
|
{
|
||||||
const T* ptr = *iter;
|
const T* ptr = iter.object();
|
||||||
if (ptr)
|
if (ptr)
|
||||||
{
|
{
|
||||||
this->insert(iter.key(), new T(*ptr));
|
this->insert(iter.key(), new T(*ptr));
|
||||||
|
|||||||
@ -25,7 +25,7 @@ Class
|
|||||||
Foam::HashPtrTable
|
Foam::HashPtrTable
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A HashTable specialization for hashing pointers.
|
A HashTable of pointers to objects of type \<T\>.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
HashPtrTable.C
|
HashPtrTable.C
|
||||||
@ -51,10 +51,10 @@ class Ostream;
|
|||||||
template<class T, class Key, class Hash> class HashPtrTable;
|
template<class T, class Key, class Hash> class HashPtrTable;
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
Istream& operator>>(Istream& is, HashPtrTable<T, Key, Hash>& L);
|
Istream& operator>>(Istream& is, HashPtrTable<T, Key, Hash>& tbl);
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
Ostream& operator<<(Ostream& os, const HashPtrTable<T, Key, Hash>& L);
|
Ostream& operator<<(Ostream& os, const HashPtrTable<T, Key, Hash>& tbl);
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
@ -77,11 +77,16 @@ class HashPtrTable
|
|||||||
void read(const dictionary& dict, const INew& inewt);
|
void read(const dictionary& dict, const INew& inewt);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef typename HashTable<T*, Key, Hash>::iterator iterator;
|
//- The template instance used for this table
|
||||||
typedef typename HashTable<T*, Key, Hash>::const_iterator const_iterator;
|
typedef HashPtrTable<T, Key, Hash> this_type;
|
||||||
|
|
||||||
|
//- The template instance used for the parent HashTable
|
||||||
|
typedef HashTable<T*, Key, Hash> parent_type;
|
||||||
|
|
||||||
|
using iterator = typename parent_type::iterator;
|
||||||
|
using const_iterator = typename parent_type::const_iterator;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
@ -100,7 +105,7 @@ public:
|
|||||||
HashPtrTable(const dictionary& dict);
|
HashPtrTable(const dictionary& dict);
|
||||||
|
|
||||||
//- Construct as copy
|
//- Construct as copy
|
||||||
HashPtrTable(const HashPtrTable<T, Key, Hash>& ht);
|
HashPtrTable(const this_type& ht);
|
||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
@ -109,25 +114,25 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
// Edit
|
// Edit
|
||||||
|
|
||||||
//- Remove and return the pointer specified by given iterator
|
//- Remove and return the pointer specified by given iterator
|
||||||
T* remove(iterator& iter);
|
T* remove(iterator& iter);
|
||||||
|
|
||||||
//- Erase an hashedEntry specified by given iterator
|
//- Erase an hashedEntry specified by given iterator
|
||||||
bool erase(iterator& iter);
|
bool erase(iterator& iter);
|
||||||
|
|
||||||
//- Clear all entries from table
|
//- Clear all entries from table
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
//- Write
|
//- Write
|
||||||
void write(Ostream& os) const;
|
void write(Ostream& os) const;
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Copy assignment
|
//- Copy assignment
|
||||||
void operator=(const HashPtrTable<T, Key, Hash>& rhs);
|
void operator=(const this_type& rhs);
|
||||||
|
|
||||||
|
|
||||||
// IOstream Operators
|
// IOstream Operators
|
||||||
@ -135,13 +140,13 @@ public:
|
|||||||
friend Istream& operator>> <T, Key, Hash>
|
friend Istream& operator>> <T, Key, Hash>
|
||||||
(
|
(
|
||||||
Istream& is,
|
Istream& is,
|
||||||
HashPtrTable<T, Key, Hash>& L
|
HashPtrTable<T, Key, Hash>& tbl
|
||||||
);
|
);
|
||||||
|
|
||||||
friend Ostream& operator<< <T, Key, Hash>
|
friend Ostream& operator<< <T, Key, Hash>
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const HashPtrTable<T, Key, Hash>& L
|
const HashPtrTable<T, Key, Hash>& tbl
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,7 @@ template<class T, class Key, class Hash>
|
|||||||
template<class INew>
|
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& inewt)
|
||||||
{
|
{
|
||||||
is.fatalCheck("HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)");
|
is.fatalCheck(FUNCTION_NAME);
|
||||||
|
|
||||||
token firstToken(is);
|
token firstToken(is);
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt)
|
|||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
is.fatalCheck("HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)");
|
is.fatalCheck(FUNCTION_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -145,11 +145,9 @@ void Foam::HashPtrTable<T, Key, Hash>::read
|
|||||||
{
|
{
|
||||||
forAllConstIter(dictionary, dict, iter)
|
forAllConstIter(dictionary, dict, iter)
|
||||||
{
|
{
|
||||||
this->insert
|
const word& k = iter().keyword();
|
||||||
(
|
|
||||||
iter().keyword(),
|
this->insert(k, inewt(dict.subDict(k)).ptr());
|
||||||
inewt(dict.subDict(iter().keyword())).ptr()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,16 +155,9 @@ void Foam::HashPtrTable<T, Key, Hash>::read
|
|||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
void Foam::HashPtrTable<T, Key, Hash>::write(Ostream& os) const
|
void Foam::HashPtrTable<T, Key, Hash>::write(Ostream& os) const
|
||||||
{
|
{
|
||||||
|
for (const_iterator iter = this->begin(); iter != this->end(); ++iter)
|
||||||
for
|
|
||||||
(
|
|
||||||
typename HashPtrTable<T, Key, Hash>::const_iterator
|
|
||||||
iter = this->begin();
|
|
||||||
iter != this->end();
|
|
||||||
++iter
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
const T* ptr = *iter;
|
const T* ptr = iter.object();
|
||||||
if (ptr)
|
if (ptr)
|
||||||
{
|
{
|
||||||
ptr->write(os);
|
ptr->write(os);
|
||||||
@ -202,10 +193,10 @@ Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(const dictionary& dict)
|
|||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, HashPtrTable<T, Key, Hash>& L)
|
Foam::Istream& Foam::operator>>(Istream& is, HashPtrTable<T, Key, Hash>& tbl)
|
||||||
{
|
{
|
||||||
L.clear();
|
tbl.clear();
|
||||||
L.read(is, INew<T>());
|
tbl.read(is, INew<T>());
|
||||||
|
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
@ -215,21 +206,18 @@ template<class T, class Key, class Hash>
|
|||||||
Foam::Ostream& Foam::operator<<
|
Foam::Ostream& Foam::operator<<
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const HashPtrTable<T, Key, Hash>& L
|
const HashPtrTable<T, Key, Hash>& tbl
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
using const_iterator = typename HashPtrTable<T, Key, Hash>::const_iterator;
|
||||||
|
|
||||||
// Write size and start delimiter
|
// Write size and start delimiter
|
||||||
os << nl << L.size() << nl << token::BEGIN_LIST << nl;
|
os << nl << tbl.size() << nl << token::BEGIN_LIST << nl;
|
||||||
|
|
||||||
// Write contents
|
// Write contents
|
||||||
for
|
for (const_iterator iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
|
||||||
(
|
|
||||||
typename HashPtrTable<T, Key, Hash>::const_iterator iter = L.begin();
|
|
||||||
iter != L.end();
|
|
||||||
++iter
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
const T* ptr = *iter;
|
const T* ptr = iter.object();
|
||||||
|
|
||||||
os << iter.key();
|
os << iter.key();
|
||||||
if (ptr)
|
if (ptr)
|
||||||
@ -242,8 +230,7 @@ Foam::Ostream& Foam::operator<<
|
|||||||
// Write end delimiter
|
// Write end delimiter
|
||||||
os << token::END_LIST;
|
os << token::END_LIST;
|
||||||
|
|
||||||
// Check state of IOstream
|
os.check(FUNCTION_NAME);
|
||||||
os.check("Ostream& operator<<(Ostream&, const HashPtrTable&)");
|
|
||||||
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -27,6 +27,52 @@ License
|
|||||||
#define HashSet_C
|
#define HashSet_C
|
||||||
|
|
||||||
#include "HashSet.H"
|
#include "HashSet.H"
|
||||||
|
#include "FixedList.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
template<class InputIter>
|
||||||
|
inline Foam::label Foam::HashSet<Key, Hash>::insertMultiple
|
||||||
|
(
|
||||||
|
const InputIter begIter,
|
||||||
|
const InputIter endIter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
label changed = 0;
|
||||||
|
for (InputIter iter = begIter; iter != endIter; ++iter)
|
||||||
|
{
|
||||||
|
if (insert(*iter))
|
||||||
|
{
|
||||||
|
++changed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
template<class InputIter>
|
||||||
|
inline Foam::label Foam::HashSet<Key, Hash>::assignMultiple
|
||||||
|
(
|
||||||
|
const InputIter begIter,
|
||||||
|
const InputIter endIter,
|
||||||
|
const label sz
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!this->capacity())
|
||||||
|
{
|
||||||
|
// Could be zero-sized from a previous transfer()?
|
||||||
|
this->resize(sz);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
return insertMultiple(begIter, endIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -35,9 +81,22 @@ Foam::HashSet<Key, Hash>::HashSet(const UList<Key>& lst)
|
|||||||
:
|
:
|
||||||
HashTable<nil, Key, Hash>(2*lst.size())
|
HashTable<nil, Key, Hash>(2*lst.size())
|
||||||
{
|
{
|
||||||
forAll(lst, elemI)
|
for (const auto& k : lst)
|
||||||
{
|
{
|
||||||
this->insert(lst[elemI]);
|
this->insert(k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
template<unsigned Size>
|
||||||
|
Foam::HashSet<Key, Hash>::HashSet(const FixedList<Key, Size>& lst)
|
||||||
|
:
|
||||||
|
HashTable<nil, Key, Hash>(2*lst.size())
|
||||||
|
{
|
||||||
|
for (const auto& k : lst)
|
||||||
|
{
|
||||||
|
this->insert(k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +106,7 @@ Foam::HashSet<Key, Hash>::HashSet(std::initializer_list<Key> lst)
|
|||||||
:
|
:
|
||||||
HashTable<nil, Key, Hash>(2*lst.size())
|
HashTable<nil, Key, Hash>(2*lst.size())
|
||||||
{
|
{
|
||||||
for (const Key& k : lst)
|
for (const auto& k : lst)
|
||||||
{
|
{
|
||||||
this->insert(k);
|
this->insert(k);
|
||||||
}
|
}
|
||||||
@ -58,20 +117,17 @@ template<class Key, class Hash>
|
|||||||
template<class AnyType, class AnyHash>
|
template<class AnyType, class AnyHash>
|
||||||
Foam::HashSet<Key, Hash>::HashSet
|
Foam::HashSet<Key, Hash>::HashSet
|
||||||
(
|
(
|
||||||
const HashTable<AnyType, Key, AnyHash>& h
|
const HashTable<AnyType, Key, AnyHash>& tbl
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
HashTable<nil, Key, Hash>(h.size())
|
HashTable<nil, Key, Hash>(tbl.capacity())
|
||||||
{
|
{
|
||||||
for
|
using other_iter =
|
||||||
(
|
typename HashTable<AnyType, Key, AnyHash>::const_iterator;
|
||||||
typename HashTable<AnyType, Key, AnyHash>::const_iterator
|
|
||||||
cit = h.cbegin();
|
for (other_iter iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
|
||||||
cit != h.cend();
|
|
||||||
++cit
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->insert(cit.key());
|
this->insert(iter.key());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,36 +137,49 @@ Foam::HashSet<Key, Hash>::HashSet
|
|||||||
template<class Key, class Hash>
|
template<class Key, class Hash>
|
||||||
Foam::label Foam::HashSet<Key, Hash>::insert(const UList<Key>& lst)
|
Foam::label Foam::HashSet<Key, Hash>::insert(const UList<Key>& lst)
|
||||||
{
|
{
|
||||||
label count = 0;
|
return insertMultiple(lst.begin(), lst.end());
|
||||||
forAll(lst, elemI)
|
|
||||||
{
|
|
||||||
if (this->insert(lst[elemI]))
|
|
||||||
{
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
template<unsigned Size>
|
||||||
|
Foam::label Foam::HashSet<Key, Hash>::insert(const FixedList<Key, Size>& lst)
|
||||||
|
{
|
||||||
|
return insertMultiple(lst.begin(), lst.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Key, class Hash>
|
template<class Key, class Hash>
|
||||||
Foam::label Foam::HashSet<Key, Hash>::insert(std::initializer_list<Key> lst)
|
Foam::label Foam::HashSet<Key, Hash>::insert(std::initializer_list<Key> lst)
|
||||||
{
|
{
|
||||||
label count = 0;
|
return insertMultiple(lst.begin(), lst.end());
|
||||||
for (const Key& k : lst)
|
|
||||||
{
|
|
||||||
if (this->insert(k))
|
|
||||||
{
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
void Foam::HashSet<Key, Hash>::operator=(const UList<Key>& lst)
|
||||||
|
{
|
||||||
|
assignMultiple(lst.begin(), lst.end(), 2*lst.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
template<unsigned Size>
|
||||||
|
void Foam::HashSet<Key, Hash>::operator=(const FixedList<Key, Size>& lst)
|
||||||
|
{
|
||||||
|
assignMultiple(lst.begin(), lst.end(), 2*lst.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
void Foam::HashSet<Key, Hash>::operator=(std::initializer_list<Key> lst)
|
||||||
|
{
|
||||||
|
assignMultiple(lst.begin(), lst.end(), 2*lst.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Key, class Hash>
|
template<class Key, class Hash>
|
||||||
inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
|
inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
|
||||||
{
|
{
|
||||||
@ -142,7 +211,7 @@ bool Foam::HashSet<Key, Hash>::operator==(const HashSet<Key, Hash>& rhs) const
|
|||||||
template<class Key, class Hash>
|
template<class Key, class Hash>
|
||||||
bool Foam::HashSet<Key, Hash>::operator!=(const HashSet<Key, Hash>& rhs) const
|
bool Foam::HashSet<Key, Hash>::operator!=(const HashSet<Key, Hash>& rhs) const
|
||||||
{
|
{
|
||||||
return !(operator==(rhs));
|
return !operator==(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -200,6 +269,15 @@ void Foam::HashSet<Key, Hash>::operator-=(const HashSet<Key, Hash>& rhs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
Foam::Ostream& Foam::operator<<(Ostream& os, const HashSet<Key, Hash>& tbl)
|
||||||
|
{
|
||||||
|
return tbl.writeList(os, 10); // 10=consistent with UList
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
|
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
|
||||||
|
|
||||||
template<class Key, class Hash>
|
template<class Key, class Hash>
|
||||||
@ -243,6 +321,66 @@ Foam::operator^
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
inline typename Foam::HashSet<Key, Hash>::iterator
|
||||||
|
Foam::HashSet<Key, Hash>::begin()
|
||||||
|
{
|
||||||
|
return HashTableCore::iterator_begin<iterator>
|
||||||
|
(
|
||||||
|
static_cast<parent_type&>(*this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
inline typename Foam::HashSet<Key, Hash>::const_iterator
|
||||||
|
Foam::HashSet<Key, Hash>::begin() const
|
||||||
|
{
|
||||||
|
return HashTableCore::iterator_begin<const_iterator>
|
||||||
|
(
|
||||||
|
static_cast<const parent_type&>(*this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
inline typename Foam::HashSet<Key, Hash>::const_iterator
|
||||||
|
Foam::HashSet<Key, Hash>::cbegin() const
|
||||||
|
{
|
||||||
|
return HashTableCore::iterator_begin<const_iterator>
|
||||||
|
(
|
||||||
|
static_cast<const parent_type&>(*this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
inline const typename Foam::HashSet<Key, Hash>::iterator&
|
||||||
|
Foam::HashSet<Key, Hash>::end()
|
||||||
|
{
|
||||||
|
return HashTableCore::iterator_end<iterator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
inline const typename Foam::HashSet<Key, Hash>::const_iterator&
|
||||||
|
Foam::HashSet<Key, Hash>::end() const
|
||||||
|
{
|
||||||
|
return HashTableCore::iterator_end<const_iterator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
inline const typename Foam::HashSet<Key, Hash>::const_iterator&
|
||||||
|
Foam::HashSet<Key, Hash>::cend() const
|
||||||
|
{
|
||||||
|
return HashTableCore::iterator_cend<const_iterator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -52,6 +52,13 @@ Description
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward declaration of friend functions and operators
|
||||||
|
template<class Key, class Hash> class HashSet;
|
||||||
|
|
||||||
|
template<class Key, class Hash>
|
||||||
|
Ostream& operator<<(Ostream& os, const HashSet<Key, Hash>& tbl);
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class HashSet Declaration
|
Class HashSet Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -61,11 +68,39 @@ class HashSet
|
|||||||
:
|
:
|
||||||
public HashTable<nil, Key, Hash>
|
public HashTable<nil, Key, Hash>
|
||||||
{
|
{
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Insert values, using begin/end iterators.
|
||||||
|
template<class InputIter>
|
||||||
|
inline label insertMultiple
|
||||||
|
(
|
||||||
|
const InputIter begIter,
|
||||||
|
const InputIter endIter
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Assign using begin/end iterators.
|
||||||
|
template<class InputIter>
|
||||||
|
inline label assignMultiple
|
||||||
|
(
|
||||||
|
const InputIter begIter,
|
||||||
|
const InputIter endIter,
|
||||||
|
const label sz
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef typename HashTable<nil, Key, Hash>::iterator iterator;
|
//- The template instance used for this HashSet
|
||||||
typedef typename HashTable<nil, Key, Hash>::const_iterator const_iterator;
|
typedef HashSet<Key, Hash> this_type;
|
||||||
|
|
||||||
|
//- The template instance used for the parent HashTable
|
||||||
|
typedef HashTable<nil, Key, Hash> parent_type;
|
||||||
|
|
||||||
|
//- An iterator, returning reference to the key
|
||||||
|
using iterator = typename parent_type::key_iterator;
|
||||||
|
|
||||||
|
//- A const_iterator, returning reference to the key
|
||||||
|
using const_iterator = typename parent_type::const_key_iterator;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
@ -73,59 +108,68 @@ public:
|
|||||||
//- Construct given initial size
|
//- Construct given initial size
|
||||||
HashSet(const label size = 128)
|
HashSet(const label size = 128)
|
||||||
:
|
:
|
||||||
HashTable<nil, Key, Hash>(size)
|
parent_type(size)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
HashSet(Istream& is)
|
HashSet(Istream& is)
|
||||||
:
|
:
|
||||||
HashTable<nil, Key, Hash>(is)
|
parent_type(is)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct from UList of Key
|
//- Construct from UList of Key
|
||||||
HashSet(const UList<Key>& lst);
|
explicit HashSet(const UList<Key>& lst);
|
||||||
|
|
||||||
|
//- Construct from FixedList of Key
|
||||||
|
template<unsigned Size>
|
||||||
|
explicit HashSet(const FixedList<Key, Size>& lst);
|
||||||
|
|
||||||
//- Construct from an initializer list of Key
|
//- Construct from an initializer list of Key
|
||||||
HashSet(std::initializer_list<Key>);
|
HashSet(std::initializer_list<Key> lst);
|
||||||
|
|
||||||
//- Construct as copy
|
//- Construct as copy
|
||||||
HashSet(const HashSet<Key, Hash>& hs)
|
HashSet(const HashSet<Key, Hash>& hs)
|
||||||
:
|
:
|
||||||
HashTable<nil, Key, Hash>(hs)
|
parent_type(hs)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct by transferring the parameter contents
|
//- Construct by transferring the parameter contents
|
||||||
HashSet(const Xfer<HashSet<Key, Hash>>& hs)
|
HashSet(const Xfer<HashSet<Key, Hash>>& hs)
|
||||||
:
|
:
|
||||||
HashTable<nil, Key, Hash>(hs)
|
parent_type(hs)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct by transferring the parameter contents
|
//- Construct by transferring the parameter contents
|
||||||
HashSet(const Xfer<HashTable<nil, Key, Hash>>& hs)
|
HashSet(const Xfer<HashTable<nil, Key, Hash>>& hs)
|
||||||
:
|
:
|
||||||
HashTable<nil, Key, Hash>(hs)
|
parent_type(hs)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct from the keys of another HashTable,
|
//- Construct from the keys of another HashTable,
|
||||||
// the type of values held is arbitrary.
|
// the type of values held is arbitrary.
|
||||||
template<class AnyType, class AnyHash>
|
template<class AnyType, class AnyHash>
|
||||||
HashSet(const HashTable<AnyType, Key, AnyHash>& h);
|
explicit HashSet(const HashTable<AnyType, Key, AnyHash>& tbl);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
// Edit
|
// Edit
|
||||||
|
|
||||||
//- Insert a new entry
|
//- Insert a new entry
|
||||||
bool insert(const Key& key)
|
bool insert(const Key& key)
|
||||||
{
|
{
|
||||||
return HashTable<nil, Key, Hash>::insert(key, nil());
|
return this->parent_type::insert(key, nil());
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Insert keys from a UList of Key
|
//- Insert keys from the list of Key
|
||||||
// Return the number of new elements inserted
|
// Return the number of new elements inserted
|
||||||
label insert(const UList<Key>& lst);
|
label insert(const UList<Key>& lst);
|
||||||
|
|
||||||
|
//- Insert keys from the list of Key
|
||||||
|
// Return the number of new elements inserted
|
||||||
|
template<unsigned Size>
|
||||||
|
label insert(const FixedList<Key, Size>& lst);
|
||||||
|
|
||||||
//- Insert keys from a initializer list of Key
|
//- Insert keys from a initializer list of Key
|
||||||
// Return the number of new elements inserted
|
// Return the number of new elements inserted
|
||||||
label insert(std::initializer_list<Key> lst);
|
label insert(std::initializer_list<Key> lst);
|
||||||
@ -142,6 +186,13 @@ public:
|
|||||||
return insert(lst);
|
return insert(lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//- Same as insert (cannot overwrite nil content)
|
||||||
|
template<unsigned Size>
|
||||||
|
label set(const FixedList<Key, Size>& lst)
|
||||||
|
{
|
||||||
|
return insert(lst);
|
||||||
|
}
|
||||||
|
|
||||||
//- Same as insert (cannot overwrite nil content)
|
//- Same as insert (cannot overwrite nil content)
|
||||||
label set(std::initializer_list<Key> lst)
|
label set(std::initializer_list<Key> lst)
|
||||||
{
|
{
|
||||||
@ -151,21 +202,75 @@ public:
|
|||||||
//- Unset the specified key - same as erase
|
//- Unset the specified key - same as erase
|
||||||
bool unset(const Key& key)
|
bool unset(const Key& key)
|
||||||
{
|
{
|
||||||
return HashTable<nil, Key, Hash>::erase(key);
|
return this->parent_type::erase(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Unset the listed keys - same as erase
|
||||||
|
label unset(const UList<Key>& lst)
|
||||||
|
{
|
||||||
|
return this->parent_type::erase(lst);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Unset the listed keys - same as erase
|
||||||
|
template<unsigned Size>
|
||||||
|
label unset(const FixedList<Key, Size>& lst)
|
||||||
|
{
|
||||||
|
return this->parent_type::erase(lst);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Unset the listed keys - same as erase
|
||||||
|
label unset(std::initializer_list<Key> lst)
|
||||||
|
{
|
||||||
|
return this->parent_type::erase(lst);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// STL iterators
|
||||||
|
|
||||||
|
iterator begin();
|
||||||
|
const_iterator begin() const;
|
||||||
|
const_iterator cbegin() const;
|
||||||
|
|
||||||
|
const iterator& end();
|
||||||
|
const const_iterator& end() const;
|
||||||
|
const const_iterator& cend() const;
|
||||||
|
|
||||||
|
|
||||||
|
// Writing
|
||||||
|
|
||||||
|
//- Write the unordered keys as a list, with line-breaks if list length
|
||||||
|
// exceeds shortListLen. Using '0' suppresses line-breaks entirely.
|
||||||
|
Ostream& writeList(Ostream& os, const label shortListLen=0) const
|
||||||
|
{
|
||||||
|
return this->writeKeys(os, shortListLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
|
//- This operation doesn't make much sense for a hash-set
|
||||||
|
void operator()(const Key& key) = delete;
|
||||||
|
|
||||||
//- Return true if the entry exists, same as found()
|
//- Return true if the entry exists, same as found()
|
||||||
inline bool operator[](const Key& key) const;
|
inline bool operator[](const Key& key) const;
|
||||||
|
|
||||||
//- Equality. Two hashset are equal when they have the same keys.
|
//- Equality. Two hashset are equal when they have the same keys.
|
||||||
// Independent of table size or order.
|
// Independent of table size or order.
|
||||||
bool operator==(const HashSet<Key, Hash>& rhs) const;
|
bool operator==(const this_type& rhs) const;
|
||||||
|
|
||||||
//- The opposite of the equality operation.
|
//- The opposite of the equality operation.
|
||||||
bool operator!=(const HashSet<Key, Hash>& rhs) const;
|
bool operator!=(const this_type& rhs) const;
|
||||||
|
|
||||||
|
|
||||||
|
//- Assignment from a UList of keys
|
||||||
|
void operator=(const UList<Key>& lst);
|
||||||
|
|
||||||
|
//- Assignment from a FixedList of keys
|
||||||
|
template<unsigned Size>
|
||||||
|
void operator=(const FixedList<Key, Size>& lst);
|
||||||
|
|
||||||
|
//- Assignment from an initializer list of keys
|
||||||
|
void operator=(std::initializer_list<Key> lst);
|
||||||
|
|
||||||
|
|
||||||
//- Combine entries from HashSets
|
//- Combine entries from HashSets
|
||||||
@ -185,6 +290,16 @@ public:
|
|||||||
|
|
||||||
//- Remove entries listed in the given HashSet from this HashSet
|
//- Remove entries listed in the given HashSet from this HashSet
|
||||||
void operator-=(const HashSet<Key, Hash>& rhs);
|
void operator-=(const HashSet<Key, Hash>& rhs);
|
||||||
|
|
||||||
|
|
||||||
|
// IOstream Operator
|
||||||
|
|
||||||
|
friend Ostream& operator<< <Key, Hash>
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const HashSet<Key, Hash>& tbl
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -28,8 +28,38 @@ License
|
|||||||
|
|
||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
#include "List.H"
|
#include "List.H"
|
||||||
|
#include "FixedList.H"
|
||||||
#include "Tuple2.H"
|
#include "Tuple2.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
template<class InputIter>
|
||||||
|
Foam::label Foam::HashTable<T, Key, Hash>::eraseMultiple
|
||||||
|
(
|
||||||
|
const InputIter begIter,
|
||||||
|
const InputIter endIter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const label nTotal = this->size();
|
||||||
|
label changed = 0;
|
||||||
|
|
||||||
|
for
|
||||||
|
(
|
||||||
|
InputIter iter = begIter;
|
||||||
|
changed < nTotal && iter != endIter; // terminate early
|
||||||
|
++iter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (this->erase(*iter))
|
||||||
|
{
|
||||||
|
++changed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
@ -46,7 +76,7 @@ Foam::HashTable<T, Key, Hash>::HashTable(const label size)
|
|||||||
|
|
||||||
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
|
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
|
||||||
{
|
{
|
||||||
table_[hashIdx] = 0;
|
table_[hashIdx] = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +89,7 @@ Foam::HashTable<T, Key, Hash>::HashTable(const HashTable<T, Key, Hash>& ht)
|
|||||||
{
|
{
|
||||||
for (const_iterator iter = ht.cbegin(); iter != ht.cend(); ++iter)
|
for (const_iterator iter = ht.cbegin(); iter != ht.cend(); ++iter)
|
||||||
{
|
{
|
||||||
insert(iter.key(), *iter);
|
insert(iter.key(), iter.object());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +115,7 @@ Foam::HashTable<T, Key, Hash>::HashTable
|
|||||||
std::initializer_list<Tuple2<Key, T>> lst
|
std::initializer_list<Tuple2<Key, T>> lst
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
HashTable<T, Key, Hash>(lst.size())
|
HashTable<T, Key, Hash>(2*lst.size())
|
||||||
{
|
{
|
||||||
for (const Tuple2<Key, T>& pair : lst)
|
for (const Tuple2<Key, T>& pair : lst)
|
||||||
{
|
{
|
||||||
@ -238,8 +268,8 @@ bool Foam::HashTable<T, Key, Hash>::set
|
|||||||
|
|
||||||
const label hashIdx = hashKeyIndex(key);
|
const label hashIdx = hashKeyIndex(key);
|
||||||
|
|
||||||
hashedEntry* existing = 0;
|
hashedEntry* existing = nullptr;
|
||||||
hashedEntry* prev = 0;
|
hashedEntry* prev = nullptr;
|
||||||
|
|
||||||
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
|
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
|
||||||
{
|
{
|
||||||
@ -251,10 +281,10 @@ bool Foam::HashTable<T, Key, Hash>::set
|
|||||||
prev = ep;
|
prev = ep;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not found, insert it at the head
|
|
||||||
if (!existing)
|
if (!existing)
|
||||||
{
|
{
|
||||||
table_[hashIdx] = new hashedEntry(key, table_[hashIdx], newEntry);
|
// Not found, insert it at the head
|
||||||
|
table_[hashIdx] = new hashedEntry(key, newEntry, table_[hashIdx]);
|
||||||
nElmts_++;
|
nElmts_++;
|
||||||
|
|
||||||
if (double(nElmts_)/tableSize_ > 0.8 && tableSize_ < maxTableSize)
|
if (double(nElmts_)/tableSize_ > 0.8 && tableSize_ < maxTableSize)
|
||||||
@ -286,7 +316,7 @@ bool Foam::HashTable<T, Key, Hash>::set
|
|||||||
{
|
{
|
||||||
// Found - overwrite existing entry
|
// Found - overwrite existing entry
|
||||||
// this corresponds to the Perl convention
|
// this corresponds to the Perl convention
|
||||||
hashedEntry* ep = new hashedEntry(key, existing->next_, newEntry);
|
hashedEntry* ep = new hashedEntry(key, newEntry, existing->next_);
|
||||||
|
|
||||||
// Replace existing element - within list or insert at the head
|
// Replace existing element - within list or insert at the head
|
||||||
if (prev)
|
if (prev)
|
||||||
@ -306,17 +336,17 @@ bool Foam::HashTable<T, Key, Hash>::set
|
|||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
bool Foam::HashTable<T, Key, Hash>::iteratorBase::erase()
|
bool Foam::HashTable<T, Key, Hash>::iterator_base::erase()
|
||||||
{
|
{
|
||||||
// Note: entryPtr_ is nullptr for end(), so this catches that too
|
// Note: entryPtr_ is nullptr for end(), so this catches that too
|
||||||
if (entryPtr_)
|
if (entryPtr_)
|
||||||
{
|
{
|
||||||
// Search element before entryPtr_
|
// Search element before entryPtr_
|
||||||
hashedEntry* prev = 0;
|
entry_type* prev = nullptr;
|
||||||
|
|
||||||
for
|
for
|
||||||
(
|
(
|
||||||
hashedEntry* ep = hashTable_->table_[hashIndex_];
|
entry_type* ep = hashTable_->table_[hashIndex_];
|
||||||
ep;
|
ep;
|
||||||
ep = ep->next_
|
ep = ep->next_
|
||||||
)
|
)
|
||||||
@ -341,8 +371,7 @@ bool Foam::HashTable<T, Key, Hash>::iteratorBase::erase()
|
|||||||
hashTable_->table_[hashIndex_] = entryPtr_->next_;
|
hashTable_->table_[hashIndex_] = entryPtr_->next_;
|
||||||
delete entryPtr_;
|
delete entryPtr_;
|
||||||
|
|
||||||
// Assign any non-nullptr value so it doesn't look
|
// Assign any non-nullptr value so it doesn't look like end()
|
||||||
// like end()/cend()
|
|
||||||
entryPtr_ = reinterpret_cast<hashedEntry*>(this);
|
entryPtr_ = reinterpret_cast<hashedEntry*>(this);
|
||||||
|
|
||||||
// Mark with special hashIndex value to signal it has been rewound.
|
// Mark with special hashIndex value to signal it has been rewound.
|
||||||
@ -389,19 +418,28 @@ bool Foam::HashTable<T, Key, Hash>::erase(const Key& key)
|
|||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
Foam::label Foam::HashTable<T, Key, Hash>::erase(const UList<Key>& keys)
|
Foam::label Foam::HashTable<T, Key, Hash>::erase(const UList<Key>& keys)
|
||||||
{
|
{
|
||||||
const label nTotal = nElmts_;
|
return eraseMultiple(keys.begin(), keys.end());
|
||||||
label count = 0;
|
}
|
||||||
|
|
||||||
// Remove listed keys from this table - terminates early if possible
|
|
||||||
for (label keyI = 0; count < nTotal && keyI < keys.size(); ++keyI)
|
|
||||||
{
|
|
||||||
if (erase(keys[keyI]))
|
|
||||||
{
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
template<class T, class Key, class Hash>
|
||||||
|
template<unsigned Size>
|
||||||
|
Foam::label Foam::HashTable<T, Key, Hash>::erase
|
||||||
|
(
|
||||||
|
const FixedList<Key, Size>& keys
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return eraseMultiple(keys.begin(), keys.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
Foam::label Foam::HashTable<T, Key, Hash>::erase
|
||||||
|
(
|
||||||
|
std::initializer_list<Key> keys
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return eraseMultiple(keys.begin(), keys.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -409,29 +447,57 @@ template<class T, class Key, class Hash>
|
|||||||
template<class AnyType, class AnyHash>
|
template<class AnyType, class AnyHash>
|
||||||
Foam::label Foam::HashTable<T, Key, Hash>::erase
|
Foam::label Foam::HashTable<T, Key, Hash>::erase
|
||||||
(
|
(
|
||||||
const HashTable<AnyType, Key, AnyHash>& rhs
|
const HashTable<AnyType, Key, AnyHash>& other
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
label count = 0;
|
// Remove other keys from this table
|
||||||
|
const label nTotal = this->size();
|
||||||
|
label changed = 0;
|
||||||
|
|
||||||
// Remove rhs keys from this table - terminates early if possible
|
if (other.size() < nTotal)
|
||||||
// Could optimize depending on which hash is smaller ...
|
|
||||||
for (iterator iter = begin(); iter != end(); ++iter)
|
|
||||||
{
|
{
|
||||||
if (rhs.found(iter.key()) && erase(iter))
|
// other is smaller, use its keys for removal
|
||||||
|
using other_iter =
|
||||||
|
typename HashTable<AnyType, Key, AnyHash>::const_iterator;
|
||||||
|
|
||||||
|
for
|
||||||
|
(
|
||||||
|
other_iter iter = other.begin();
|
||||||
|
changed < nTotal && iter != other.end(); // terminate early
|
||||||
|
++iter
|
||||||
|
)
|
||||||
{
|
{
|
||||||
++count;
|
if (erase(iter.key()))
|
||||||
|
{
|
||||||
|
++changed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// other is same/larger: iterate ourselves and check for key in other
|
||||||
|
for
|
||||||
|
(
|
||||||
|
iterator iter = begin();
|
||||||
|
changed < nTotal && iter != end(); // terminate early
|
||||||
|
++iter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (other.found(iter.key()) && erase(iter))
|
||||||
|
{
|
||||||
|
++changed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
void Foam::HashTable<T, Key, Hash>::resize(const label sz)
|
void Foam::HashTable<T, Key, Hash>::resize(const label sz)
|
||||||
{
|
{
|
||||||
label newSize = HashTableCore::canonicalSize(sz);
|
const label newSize = HashTableCore::canonicalSize(sz);
|
||||||
|
|
||||||
if (newSize == tableSize_)
|
if (newSize == tableSize_)
|
||||||
{
|
{
|
||||||
@ -449,10 +515,10 @@ void Foam::HashTable<T, Key, Hash>::resize(const label sz)
|
|||||||
|
|
||||||
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
||||||
{
|
{
|
||||||
tmpTable->insert(iter.key(), *iter);
|
tmpTable->insert(iter.key(), iter.object());
|
||||||
}
|
}
|
||||||
|
|
||||||
label oldSize = tableSize_;
|
const label oldSize = tableSize_;
|
||||||
tableSize_ = tmpTable->tableSize_;
|
tableSize_ = tmpTable->tableSize_;
|
||||||
tmpTable->tableSize_ = oldSize;
|
tmpTable->tableSize_ = oldSize;
|
||||||
|
|
||||||
@ -480,7 +546,7 @@ void Foam::HashTable<T, Key, Hash>::clear()
|
|||||||
ep = next;
|
ep = next;
|
||||||
}
|
}
|
||||||
delete ep;
|
delete ep;
|
||||||
table_[hashIdx] = 0;
|
table_[hashIdx] = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nElmts_ = 0;
|
nElmts_ = 0;
|
||||||
@ -496,19 +562,6 @@ void Foam::HashTable<T, Key, Hash>::clearStorage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
|
||||||
void Foam::HashTable<T, Key, Hash>::shrink()
|
|
||||||
{
|
|
||||||
const label newSize = HashTableCore::canonicalSize(nElmts_);
|
|
||||||
|
|
||||||
if (newSize < tableSize_)
|
|
||||||
{
|
|
||||||
// Avoid having the table disappear on us
|
|
||||||
resize(newSize ? newSize : 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
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>& ht)
|
||||||
{
|
{
|
||||||
@ -558,7 +611,7 @@ void Foam::HashTable<T, Key, Hash>::operator=
|
|||||||
|
|
||||||
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
|
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
|
||||||
{
|
{
|
||||||
insert(iter.key(), *iter);
|
insert(iter.key(), iter.object());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,14 +625,14 @@ void Foam::HashTable<T, Key, Hash>::operator=
|
|||||||
// Could be zero-sized from a previous transfer()
|
// Could be zero-sized from a previous transfer()
|
||||||
if (!tableSize_)
|
if (!tableSize_)
|
||||||
{
|
{
|
||||||
resize(lst.size());
|
resize(2*lst.size());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const Tuple2<Key, T>& pair : lst)
|
for (const auto& pair : lst)
|
||||||
{
|
{
|
||||||
insert(pair.first(), pair.second());
|
insert(pair.first(), pair.second());
|
||||||
}
|
}
|
||||||
@ -600,9 +653,9 @@ bool Foam::HashTable<T, Key, Hash>::operator==
|
|||||||
|
|
||||||
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
|
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
|
||||||
{
|
{
|
||||||
const_iterator fnd = find(iter.key());
|
const_iterator other = find(iter.key());
|
||||||
|
|
||||||
if (fnd == cend() || fnd() != iter())
|
if (!other.found() || other.object() != iter.object())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -618,7 +671,7 @@ bool Foam::HashTable<T, Key, Hash>::operator!=
|
|||||||
const HashTable<T, Key, Hash>& rhs
|
const HashTable<T, Key, Hash>& rhs
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return !(operator==(rhs));
|
return !operator==(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -34,9 +34,17 @@ Note
|
|||||||
often result in a different hash order. Use a sorted table-of-contents
|
often result in a different hash order. Use a sorted table-of-contents
|
||||||
when the hash order is important.
|
when the hash order is important.
|
||||||
|
|
||||||
|
The end iterator of all hash-tables has a nullptr to the hash entry.
|
||||||
|
Thus avoid separate allocation for each table and use a single one with
|
||||||
|
a nullptr. The hash-table iterators always have an entry-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
|
SourceFiles
|
||||||
HashTableI.H
|
HashTableI.H
|
||||||
HashTable.C
|
HashTable.C
|
||||||
|
HashTableCore.C
|
||||||
HashTableIO.C
|
HashTableIO.C
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -49,6 +57,8 @@ SourceFiles
|
|||||||
#include "word.H"
|
#include "word.H"
|
||||||
#include "Xfer.H"
|
#include "Xfer.H"
|
||||||
#include "className.H"
|
#include "className.H"
|
||||||
|
#include "nullObject.H"
|
||||||
|
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
@ -60,32 +70,30 @@ namespace Foam
|
|||||||
|
|
||||||
template<class T> class List;
|
template<class T> class List;
|
||||||
template<class T> class UList;
|
template<class T> class UList;
|
||||||
|
template<class T, unsigned Size> class FixedList;
|
||||||
|
template<class T1, class T2> class Tuple2;
|
||||||
template<class T, class Key, class Hash> class HashTable;
|
template<class T, class Key, class Hash> class HashTable;
|
||||||
template<class T, class Key, class Hash> class HashPtrTable;
|
|
||||||
|
|
||||||
template<class Type1, class Type2>
|
|
||||||
class Tuple2;
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
Istream& operator>>(Istream& is, HashTable<T, Key, Hash>& L);
|
Istream& operator>>(Istream& is, HashTable<T, Key, Hash>& L);
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
Ostream& operator<<(Ostream& os, const HashTable<T, Key, Hash>& L);
|
Ostream& operator<<(Ostream& os, const HashTable<T, Key, Hash>& tbl);
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class HashTableCore Declaration
|
Class HashTableCore Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
//- Template-invariant bits for HashTable
|
//- Bits that are independent of the HashTable template parameters.
|
||||||
struct HashTableCore
|
struct HashTableCore
|
||||||
{
|
{
|
||||||
//- Return a canonical (power-of-two) size
|
//- Maximum allowable internal table size. Approximately labelMax/4
|
||||||
static label canonicalSize(const label size);
|
|
||||||
|
|
||||||
//- Maximum allowable table size
|
|
||||||
static const label maxTableSize;
|
static const label maxTableSize;
|
||||||
|
|
||||||
|
//- Return a canonical (power-of-two) of the requested size.
|
||||||
|
static label canonicalSize(const label requested_size);
|
||||||
|
|
||||||
//- Construct null
|
//- Construct null
|
||||||
HashTableCore()
|
HashTableCore()
|
||||||
{}
|
{}
|
||||||
@ -93,25 +101,57 @@ struct HashTableCore
|
|||||||
//- Define template name and debug
|
//- Define template name and debug
|
||||||
ClassName("HashTable");
|
ClassName("HashTable");
|
||||||
|
|
||||||
//- A zero-sized end iterator
|
static_assert
|
||||||
struct iteratorEnd
|
(
|
||||||
|
sizeof(NullObject) >= sizeof(void*),
|
||||||
|
"NullObject is too small to reinterpret_cast as HashTable::iterator"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//- Factory method to create a non-const iterator begin
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline static IteratorType iterator_begin(TableType& table);
|
||||||
|
|
||||||
|
//- Factory method to create a const iterator begin
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline static IteratorType iterator_begin(const TableType& table);
|
||||||
|
|
||||||
|
//- Factory method to create a const iterator begin
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline static IteratorType iterator_cbegin(const TableType& table);
|
||||||
|
|
||||||
|
//- Factory method to create a non-const iterator end
|
||||||
|
// Simply reinterprets a NullObject as a hash-table iterator.
|
||||||
|
template<class IteratorType>
|
||||||
|
inline static const IteratorType& iterator_end();
|
||||||
|
|
||||||
|
//- Factory method to create a const iterator cend
|
||||||
|
// Simply reinterprets a NullObject as a hash-table iterator.
|
||||||
|
template<class IteratorType>
|
||||||
|
inline static const IteratorType& iterator_cend();
|
||||||
|
|
||||||
|
|
||||||
|
//- Factory class for creating a begin/end pair for any const iterator.
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
class const_iterator_pair
|
||||||
{
|
{
|
||||||
//- Construct null
|
label size_;
|
||||||
iteratorEnd()
|
IteratorType iter_;
|
||||||
{}
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
inline const_iterator_pair(const TableType& tbl);
|
||||||
|
|
||||||
|
inline label size() const;
|
||||||
|
inline bool empty() const;
|
||||||
|
|
||||||
|
inline IteratorType begin() const;
|
||||||
|
inline IteratorType cbegin() const;
|
||||||
|
|
||||||
|
inline const IteratorType& end() const;
|
||||||
|
inline const IteratorType& cend() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
//- iteratorEnd set to beyond the end of any HashTable
|
|
||||||
inline static iteratorEnd cend()
|
|
||||||
{
|
|
||||||
return iteratorEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- iteratorEnd set to beyond the end of any HashTable
|
|
||||||
inline static iteratorEnd end()
|
|
||||||
{
|
|
||||||
return iteratorEnd();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -124,23 +164,59 @@ class HashTable
|
|||||||
:
|
:
|
||||||
public HashTableCore
|
public HashTableCore
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- The template instance used for this HashTable
|
||||||
|
typedef HashTable<T, Key, Hash> this_type;
|
||||||
|
|
||||||
|
|
||||||
|
// STL type definitions
|
||||||
|
|
||||||
|
//- Type of keys that the HashTable uses.
|
||||||
|
typedef Key key_type;
|
||||||
|
|
||||||
|
//- Type of values that the HashTable contains.
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
|
//- The type used for storing into value_type objects.
|
||||||
|
// This type is usually value_type&.
|
||||||
|
typedef T& reference;
|
||||||
|
|
||||||
|
//- The type used for reading from constant value_type objects.
|
||||||
|
typedef const T& const_reference;
|
||||||
|
|
||||||
|
//- The type to represent the difference between two iterators
|
||||||
|
typedef label difference_type;
|
||||||
|
|
||||||
|
//- The type that can represent the size of a HashTable.
|
||||||
|
typedef label size_type;
|
||||||
|
|
||||||
|
|
||||||
|
//- Forward iterator with non-const access
|
||||||
|
class iterator;
|
||||||
|
|
||||||
|
//- Forward iterator with const access
|
||||||
|
class const_iterator;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
// Private data type for table entries
|
// Private data type for table entries
|
||||||
|
|
||||||
//- Structure to hold a hashed entry with SLList for collisions
|
//- Structure to hold a hashed entry, with a SLList for collisions
|
||||||
struct hashedEntry
|
struct hashedEntry
|
||||||
{
|
{
|
||||||
//- The lookup key
|
//- The lookup key
|
||||||
Key key_;
|
Key key_;
|
||||||
|
|
||||||
//- Pointer to next hashedEntry in sub-list
|
|
||||||
hashedEntry* next_;
|
|
||||||
|
|
||||||
//- The data object
|
//- The data object
|
||||||
T obj_;
|
T obj_;
|
||||||
|
|
||||||
//- Construct from key, next pointer and object
|
//- Pointer to next hashedEntry in sub-list
|
||||||
inline hashedEntry(const Key&, hashedEntry* next, const T&);
|
hashedEntry* next_;
|
||||||
|
|
||||||
|
//- Construct from key, next pointer and object
|
||||||
|
inline hashedEntry(const Key& key, const T& obj, hashedEntry* next);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
@ -169,39 +245,40 @@ class HashTable
|
|||||||
// No checks for zero-sized tables.
|
// No checks for zero-sized tables.
|
||||||
inline label hashKeyIndex(const Key& key) const;
|
inline label hashKeyIndex(const Key& key) const;
|
||||||
|
|
||||||
//- Assign a new hashedEntry to a possibly already existing key
|
//- Assign a new hash-entry to a possibly already existing key.
|
||||||
|
// Return true if the new entry was set.
|
||||||
bool set(const Key& key, const T& newEntry, const bool protect);
|
bool set(const Key& key, const T& newEntry, const bool protect);
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//- Internally used base for iterator and const_iterator
|
||||||
|
class iterator_base;
|
||||||
|
|
||||||
|
//- Friendship with the iterator_base is required.
|
||||||
|
friend class iterator_base;
|
||||||
|
|
||||||
|
|
||||||
|
// Protected Member Functions
|
||||||
|
|
||||||
|
//- Remove using begin/end iterators of listed keys
|
||||||
|
template<class InputIter>
|
||||||
|
inline label eraseMultiple
|
||||||
|
(
|
||||||
|
const InputIter begIter,
|
||||||
|
const InputIter endIter
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Forward declaration of iterators
|
|
||||||
|
|
||||||
class iteratorBase;
|
|
||||||
class iterator;
|
|
||||||
class const_iterator;
|
|
||||||
|
|
||||||
//- Declare friendship with the HashPtrTable class
|
|
||||||
template<class T2, class Key2, class Hash2>
|
|
||||||
friend class HashPtrTable;
|
|
||||||
|
|
||||||
//- Declare friendship with the iteratorBase
|
|
||||||
friend class iteratorBase;
|
|
||||||
|
|
||||||
//- Declare friendship with the iterator
|
|
||||||
friend class iterator;
|
|
||||||
|
|
||||||
//- Declare friendship with the const_iterator
|
|
||||||
friend class const_iterator;
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct given initial table size
|
//- Construct given initial table size
|
||||||
HashTable(const label size = 128);
|
HashTable(const label size = 128);
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
HashTable(Istream&, const label size = 128);
|
HashTable(Istream& is, const label size = 128);
|
||||||
|
|
||||||
//- Construct as copy
|
//- Construct as copy
|
||||||
HashTable(const HashTable<T, Key, Hash>& ht);
|
HashTable(const HashTable<T, Key, Hash>& ht);
|
||||||
@ -219,83 +296,89 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
// Access
|
// Access
|
||||||
|
|
||||||
//- The size of the underlying table
|
//- The size of the underlying table
|
||||||
inline label capacity() const;
|
inline label capacity() const;
|
||||||
|
|
||||||
//- Return number of elements in table
|
//- Return number of elements in table
|
||||||
inline label size() const;
|
inline label size() const;
|
||||||
|
|
||||||
//- Return true if the hash table is empty
|
//- Return true if the hash table is empty
|
||||||
inline bool empty() const;
|
inline bool empty() const;
|
||||||
|
|
||||||
//- Return true if hashedEntry is found in table
|
//- Return true if hashedEntry is found in table
|
||||||
bool found(const Key& key) const;
|
bool found(const Key& key) const;
|
||||||
|
|
||||||
//- Find and return an iterator set at the hashedEntry
|
//- Find and return an iterator set at the hashedEntry
|
||||||
// If not found iterator = end()
|
// If not found iterator = end()
|
||||||
iterator find(const Key& key);
|
iterator find(const Key& key);
|
||||||
|
|
||||||
//- Find and return an const_iterator set at the hashedEntry
|
//- Find and return an const_iterator set at the hashedEntry
|
||||||
// If not found iterator = end()
|
// If not found iterator = end()
|
||||||
const_iterator find(const Key& key) const;
|
const_iterator find(const Key& key) const;
|
||||||
|
|
||||||
//- Return the table of contents
|
//- Return the table of contents
|
||||||
List<Key> toc() const;
|
List<Key> toc() const;
|
||||||
|
|
||||||
//- Return the table of contents as a sorted list
|
//- Return the table of contents as a sorted list
|
||||||
List<Key> sortedToc() const;
|
List<Key> sortedToc() const;
|
||||||
|
|
||||||
//- Print information
|
|
||||||
Ostream& printInfo(Ostream& os) const;
|
|
||||||
|
|
||||||
|
|
||||||
// Edit
|
// Edit
|
||||||
|
|
||||||
//- Insert a new hashedEntry
|
//- Insert a new hashedEntry
|
||||||
inline bool insert(const Key& key, const T& newEntry);
|
// Return true if the entry inserted, which means that it did
|
||||||
|
// not previously exist in the table.
|
||||||
|
inline bool insert(const Key& key, const T& newEntry);
|
||||||
|
|
||||||
//- Assign a new hashedEntry, overwriting existing entries
|
//- Assign a new hashedEntry, overwriting existing entries.
|
||||||
inline bool set(const Key& key, const T& newEntry);
|
// Returns true.
|
||||||
|
inline bool set(const Key& key, const T& newEntry);
|
||||||
|
|
||||||
//- Erase a hashedEntry specified by given iterator
|
//- Erase a hashedEntry specified by given iterator
|
||||||
// This invalidates the iterator until the next operator++
|
// This invalidates the iterator until the next ++ operation
|
||||||
bool erase(const iterator& iter);
|
bool erase(const iterator& iter);
|
||||||
|
|
||||||
//- Erase a hashedEntry specified by the given key
|
//- Erase a hashedEntry specified by the given key
|
||||||
bool erase(const Key& key);
|
bool erase(const Key& key);
|
||||||
|
|
||||||
//- Remove entries given by the listed keys from this HashTable
|
//- Remove entries given by the listed keys from this HashTable
|
||||||
// Return the number of elements removed
|
// Return the number of elements removed
|
||||||
label erase(const UList<Key>& keys);
|
label erase(const UList<Key>& keys);
|
||||||
|
|
||||||
//- Remove entries given by the given keys from this HashTable
|
//- Remove entries given by the listed keys from this HashTable
|
||||||
// Return the number of elements removed.
|
// Return the number of elements removed
|
||||||
// The parameter HashTable needs the same type of key, but the
|
template<unsigned Size>
|
||||||
// type of values held and the hashing function are arbitrary.
|
label erase(const FixedList<Key, Size>& keys);
|
||||||
template<class AnyType, class AnyHash>
|
|
||||||
label erase(const HashTable<AnyType, Key, AnyHash>& rhs);
|
|
||||||
|
|
||||||
//- Resize the hash table for efficiency
|
//- Remove entries given by the listed keys from this HashTable
|
||||||
void resize(const label sz);
|
// Return the number of elements removed
|
||||||
|
label erase(std::initializer_list<Key> keys);
|
||||||
|
|
||||||
//- Clear all entries from table
|
//- Remove entries given by the given keys from this HashTable
|
||||||
void clear();
|
// Return the number of elements removed.
|
||||||
|
// The parameter HashTable needs the same type of key, but the
|
||||||
|
// type of values held and the hashing function are arbitrary.
|
||||||
|
template<class AnyType, class AnyHash>
|
||||||
|
label erase(const HashTable<AnyType, Key, AnyHash>& other);
|
||||||
|
|
||||||
//- Clear the table entries and the table itself.
|
//- Resize the hash table for efficiency
|
||||||
// Equivalent to clear() followed by resize(0)
|
void resize(const label sz);
|
||||||
void clearStorage();
|
|
||||||
|
|
||||||
//- Shrink the allocated table to approx. twice number of elements
|
//- Clear all entries from table
|
||||||
void shrink();
|
void clear();
|
||||||
|
|
||||||
//- Transfer the contents of the argument table into this table
|
//- Clear the table entries and the table itself.
|
||||||
// and annul the argument table.
|
// Equivalent to clear() followed by resize(0)
|
||||||
void transfer(HashTable<T, Key, Hash>& ht);
|
void clearStorage();
|
||||||
|
|
||||||
//- Transfer contents to the Xfer container
|
//- Transfer the contents of the argument table into this table
|
||||||
inline Xfer<HashTable<T, Key, Hash>> xfer();
|
// and annul the argument table.
|
||||||
|
void transfer(HashTable<T, Key, Hash>& ht);
|
||||||
|
|
||||||
|
//- Transfer contents to the Xfer container
|
||||||
|
inline Xfer<HashTable<T, Key, Hash>> xfer();
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
@ -306,13 +389,15 @@ public:
|
|||||||
//- Find and return a hashedEntry
|
//- Find and return a hashedEntry
|
||||||
inline const T& operator[](const Key& key) const;
|
inline const T& operator[](const Key& key) const;
|
||||||
|
|
||||||
//- Find and return a hashedEntry, create it null if not present
|
//- Return existing entry or create a new entry.
|
||||||
|
// A newly created entry is created as a nameless T() and is thus
|
||||||
|
// value-initialized. For primitives, this will be zero.
|
||||||
inline T& operator()(const Key& key);
|
inline T& operator()(const Key& key);
|
||||||
|
|
||||||
//- Assignment
|
//- Assignment
|
||||||
void operator=(const HashTable<T, Key, Hash>& rhs);
|
void operator=(const HashTable<T, Key, Hash>& rhs);
|
||||||
|
|
||||||
//- Assignment to an initializer list
|
//- Assignment from an initializer list
|
||||||
void operator=(std::initializer_list<Tuple2<Key, T>> lst);
|
void operator=(std::initializer_list<Tuple2<Key, T>> lst);
|
||||||
|
|
||||||
//- Equality. Hash tables are equal if the keys and values are equal.
|
//- Equality. Hash tables are equal if the keys and values are equal.
|
||||||
@ -323,218 +408,255 @@ public:
|
|||||||
bool operator!=(const HashTable<T, Key, Hash>& rhs) const;
|
bool operator!=(const HashTable<T, Key, Hash>& rhs) const;
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
// STL type definitions
|
|
||||||
|
|
||||||
//- Type of values the HashTable contains.
|
|
||||||
typedef T value_type;
|
|
||||||
|
|
||||||
//- Type that can be used for storing into HashTable::value_type
|
|
||||||
// objects. This type is usually List::value_type&.
|
|
||||||
typedef T& reference;
|
|
||||||
|
|
||||||
//- Type that can be used for storing into constant
|
|
||||||
// HashTable::value_type objects. This type is usually const
|
|
||||||
// HashTable::value_type&.
|
|
||||||
typedef const T& const_reference;
|
|
||||||
|
|
||||||
//- The type that can represent the size of a HashTable.
|
|
||||||
typedef label size_type;
|
|
||||||
|
|
||||||
|
|
||||||
// Iterators and helpers
|
// Iterators and helpers
|
||||||
|
|
||||||
//- The iterator base for HashTable
|
//- The iterator base for HashTable (internal use only).
|
||||||
// Note: data and functions are protected, to allow reuse by iterator
|
// Note: data and functions are protected, to allow reuse by iterator
|
||||||
// and prevent most external usage.
|
// and prevent most external usage.
|
||||||
// iterator and const_iterator have the same size, allowing
|
// iterator and const_iterator have the same size, allowing
|
||||||
// us to reinterpret_cast between them (if desired)
|
// us to reinterpret_cast between them (if desired)
|
||||||
class iteratorBase
|
class iterator_base
|
||||||
{
|
{
|
||||||
// Private Data
|
public:
|
||||||
|
// Public typedefs
|
||||||
|
using table_type = this_type;
|
||||||
|
using key_type = this_type::key_type;
|
||||||
|
using difference_type = this_type::difference_type;
|
||||||
|
|
||||||
//- Pointer to the HashTable for which this is an iterator
|
private:
|
||||||
// This allows use of the default bitwise copy/assignment
|
using entry_type = hashedEntry;
|
||||||
HashTable<T, Key, Hash>* hashTable_;
|
|
||||||
|
|
||||||
//- Current element
|
// Private Data
|
||||||
hashedEntry* entryPtr_;
|
|
||||||
|
|
||||||
//- Current hash index
|
//- Currently selected entry.
|
||||||
label hashIndex_;
|
// MUST be the first member for easy comparison between iterators
|
||||||
|
// and for reinterpret_cast from nullObject
|
||||||
|
entry_type* entryPtr_;
|
||||||
|
|
||||||
|
//- Pointer to the hash-table for which this is an iterator
|
||||||
|
// This allows use of the default bitwise copy/assignment
|
||||||
|
table_type* hashTable_;
|
||||||
|
|
||||||
|
//- Current hash index within the hash-table data.
|
||||||
|
// A signed value, since erase() uses a negative value to signal
|
||||||
|
// the erasure state.
|
||||||
|
label hashIndex_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Constructors
|
// Protected Member Functions
|
||||||
|
|
||||||
//- Construct null - equivalent to an 'end' position
|
//- Increment to the next position
|
||||||
inline iteratorBase();
|
inline void increment();
|
||||||
|
|
||||||
//- Construct from hash table, moving to its 'begin' position
|
//- The referenced object/value element
|
||||||
inline explicit iteratorBase
|
inline T& element() const;
|
||||||
(
|
|
||||||
const HashTable<T, Key, Hash>* hashTbl
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Construct from hash table, element and hash index
|
//- Erase the entry at the current position
|
||||||
inline iteratorBase
|
bool erase();
|
||||||
(
|
|
||||||
const HashTable<T, Key, Hash>* hashTbl,
|
|
||||||
const hashedEntry* elmt,
|
|
||||||
const label hashIndex
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// Protected Member Functions
|
|
||||||
|
|
||||||
//- Increment to the next position
|
|
||||||
inline void increment();
|
|
||||||
|
|
||||||
//- Erase the HashTable element at the current position
|
|
||||||
bool erase();
|
|
||||||
|
|
||||||
//- Return non-const access to referenced object
|
|
||||||
inline T& object();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Member operators
|
// Constructors
|
||||||
|
|
||||||
// Access
|
//- Construct null (end iterator)
|
||||||
|
inline iterator_base();
|
||||||
|
|
||||||
//- True if iterator points to a hashedEntry.
|
//- Construct from begin of hash-table
|
||||||
// This can be used instead of a comparison to end()
|
inline explicit iterator_base(const table_type* hashTbl);
|
||||||
inline bool found() const;
|
|
||||||
|
|
||||||
//- Return the Key corresponding to the iterator
|
//- Construct from hash table, element and hash index
|
||||||
inline const Key& key() const;
|
inline iterator_base
|
||||||
|
(
|
||||||
|
const table_type* hashTbl,
|
||||||
|
const entry_type* elmt,
|
||||||
|
const label hashIndex
|
||||||
|
);
|
||||||
|
|
||||||
//- Return const access to referenced object
|
// Member functions/operators
|
||||||
inline const T& cobject() const;
|
|
||||||
|
|
||||||
//- Compare hashedEntry element pointers
|
//- True if iterator points to an entry
|
||||||
inline bool operator==(const iteratorBase& iter) const;
|
// This can be used directly instead of comparing to end()
|
||||||
inline bool operator!=(const iteratorBase& iter) const;
|
inline bool found() const;
|
||||||
|
|
||||||
//- Compare hashedEntry to iteratorEnd pointers
|
//- Return the Key corresponding to the iterator
|
||||||
inline bool operator==(const iteratorEnd& unused) const;
|
inline const Key& key() const;
|
||||||
inline bool operator!=(const iteratorEnd& unused) const;
|
|
||||||
|
//- Compare hash-entry element pointers
|
||||||
|
inline bool operator==(const iterator_base& iter) const;
|
||||||
|
inline bool operator!=(const iterator_base& iter) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//- An STL-conforming iterator
|
public:
|
||||||
|
|
||||||
|
//- An iterator wrapper for returning a reference to the key
|
||||||
|
template<class WrappedIterator>
|
||||||
|
class key_iterator_base
|
||||||
|
:
|
||||||
|
public WrappedIterator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using reference = const Key&;
|
||||||
|
using difference_type = typename WrappedIterator::difference_type;
|
||||||
|
|
||||||
|
//- Implicit conversion
|
||||||
|
inline key_iterator_base(const WrappedIterator& iter);
|
||||||
|
|
||||||
|
//- Return the key
|
||||||
|
inline reference operator*() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// STL iterator
|
||||||
|
|
||||||
|
//- Forward iterator with non-const access
|
||||||
class iterator
|
class iterator
|
||||||
:
|
:
|
||||||
public iteratorBase
|
public iterator_base
|
||||||
{
|
{
|
||||||
friend class HashTable;
|
friend class HashTable; // Uses iterator::erase() method
|
||||||
|
using entry_type = hashedEntry;
|
||||||
// Private Member Functions
|
|
||||||
|
|
||||||
//- Construct from hash table, moving to its 'begin' position
|
|
||||||
inline explicit iterator
|
|
||||||
(
|
|
||||||
HashTable<T, Key, Hash>* hashTbl
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Construct from hash table, element and hash index
|
|
||||||
inline iterator
|
|
||||||
(
|
|
||||||
HashTable<T, Key, Hash>* hashTbl,
|
|
||||||
hashedEntry* elmt,
|
|
||||||
const label hashIndex
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors
|
// Public typedefs
|
||||||
|
using table_type = this_type;
|
||||||
|
using key_type = this_type::key_type;
|
||||||
|
using reference = this_type::reference;
|
||||||
|
using difference_type = typename iterator_base::difference_type;
|
||||||
|
|
||||||
//- Construct null (end iterator)
|
// Constructors
|
||||||
inline iterator();
|
|
||||||
|
|
||||||
//- Construct end iterator
|
//- Construct null (end iterator)
|
||||||
inline iterator(const iteratorEnd& unused);
|
inline iterator();
|
||||||
|
|
||||||
|
//- Construct from begin of hash-table
|
||||||
|
inline explicit iterator(table_type* hashTbl);
|
||||||
|
|
||||||
// Member operators
|
//- Construct from hash table, element and hash index
|
||||||
|
// Used by the hash-table find() method.
|
||||||
|
inline iterator
|
||||||
|
(
|
||||||
|
table_type* hashTbl,
|
||||||
|
entry_type* elmt,
|
||||||
|
const label hashIndex
|
||||||
|
);
|
||||||
|
|
||||||
//- Return non-const access to referenced object
|
// Member functions/operators
|
||||||
using iteratorBase::object;
|
|
||||||
|
|
||||||
//- Return non-const access to referenced object
|
//- Return non-const access to referenced object
|
||||||
inline T& operator*();
|
inline reference object() const;
|
||||||
inline T& operator()();
|
|
||||||
|
|
||||||
//- Return const access to referenced object
|
//- Return non-const access to referenced object
|
||||||
inline const T& operator*() const;
|
inline reference operator*() const;
|
||||||
inline const T& operator()() const;
|
inline reference operator()() const;
|
||||||
|
|
||||||
inline iterator& operator++();
|
inline iterator& operator++();
|
||||||
inline iterator operator++(int);
|
inline iterator operator++(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
//- Iterator set to the beginning of the HashTable
|
|
||||||
inline iterator begin();
|
|
||||||
|
|
||||||
|
|
||||||
// STL const_iterator
|
// STL const_iterator
|
||||||
|
|
||||||
//- An STL-conforming const_iterator
|
//- Forward iterator with const access
|
||||||
class const_iterator
|
class const_iterator
|
||||||
:
|
:
|
||||||
public iteratorBase
|
public iterator_base
|
||||||
{
|
{
|
||||||
friend class HashTable;
|
using entry_type = const hashedEntry;
|
||||||
|
|
||||||
// Private Member Functions
|
|
||||||
|
|
||||||
//- Construct from hash table, moving to its 'begin' position
|
|
||||||
inline explicit const_iterator
|
|
||||||
(
|
|
||||||
const HashTable<T, Key, Hash>* hashTbl
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Construct from hash table, element and hash index
|
|
||||||
inline const_iterator
|
|
||||||
(
|
|
||||||
const HashTable<T, Key, Hash>* hashTbl,
|
|
||||||
const hashedEntry* elmt,
|
|
||||||
const label hashIndex
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors
|
// Public typedefs
|
||||||
|
using table_type = const this_type;
|
||||||
|
using key_type = this_type::key_type;
|
||||||
|
using reference = this_type::const_reference;
|
||||||
|
using difference_type = typename iterator_base::difference_type;
|
||||||
|
|
||||||
//- Construct null (end iterator)
|
// Constructors
|
||||||
inline const_iterator();
|
|
||||||
|
|
||||||
//- Construct from iterator
|
//- Construct null (end iterator)
|
||||||
inline const_iterator(const iterator& iter);
|
inline const_iterator();
|
||||||
|
|
||||||
//- Construct end iterator
|
//- Construct from begin of hash-table
|
||||||
inline const_iterator(const iteratorEnd& unused);
|
inline explicit const_iterator(table_type* hashTbl);
|
||||||
|
|
||||||
|
//- Construct from hash table, element and hash index.
|
||||||
|
// Used by the hash-table find() method.
|
||||||
|
inline const_iterator
|
||||||
|
(
|
||||||
|
table_type* hashTbl,
|
||||||
|
entry_type* elmt,
|
||||||
|
const label hashIndex
|
||||||
|
);
|
||||||
|
|
||||||
// Member operators
|
//- Copy construct from iterator
|
||||||
|
inline const_iterator(const iterator& iter);
|
||||||
|
|
||||||
//- Return const access to referenced object
|
// Member functions/operators
|
||||||
inline const T& operator*() const;
|
|
||||||
inline const T& operator()() const;
|
|
||||||
|
|
||||||
inline const_iterator& operator++();
|
//- Return const access to referenced object
|
||||||
inline const_iterator operator++(int);
|
inline reference object() const;
|
||||||
|
|
||||||
|
//- Return const access to referenced object
|
||||||
|
inline reference operator*() const;
|
||||||
|
inline reference operator()() const;
|
||||||
|
|
||||||
|
inline const_iterator& operator++();
|
||||||
|
inline const_iterator operator++(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//- Iterating over keys only
|
||||||
|
|
||||||
|
//- Forward iterator returning the key
|
||||||
|
using key_iterator = key_iterator_base<iterator>;
|
||||||
|
|
||||||
|
//- Forward const iterator returning the key
|
||||||
|
using const_key_iterator = key_iterator_base<const_iterator>;
|
||||||
|
|
||||||
|
//- A const iterator begin/end pair for iterating over keys
|
||||||
|
const_iterator_pair<const_key_iterator, this_type> keys() const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
const_iterator_pair<const_key_iterator,this_type>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Iterator access
|
||||||
|
|
||||||
|
//- Iterator set to the beginning of the HashTable
|
||||||
|
inline iterator begin();
|
||||||
|
|
||||||
|
//- const_iterator set to the beginning of the HashTable
|
||||||
|
inline const_iterator begin() const;
|
||||||
|
|
||||||
//- const_iterator set to the beginning of the HashTable
|
//- const_iterator set to the beginning of the HashTable
|
||||||
inline const_iterator cbegin() const;
|
inline const_iterator cbegin() const;
|
||||||
|
|
||||||
//- const_iterator set to the beginning of the HashTable
|
//- iterator to signal the end for any HashTable
|
||||||
inline const_iterator begin() const;
|
inline const iterator& end();
|
||||||
|
|
||||||
|
//- const_iterator to signal the end for any HashTable
|
||||||
|
inline const const_iterator& end() const;
|
||||||
|
|
||||||
|
//- const_iterator to signal the end for any HashTable
|
||||||
|
inline const const_iterator& cend() const;
|
||||||
|
|
||||||
|
|
||||||
|
// Writing
|
||||||
|
|
||||||
|
//- Print information
|
||||||
|
Ostream& printInfo(Ostream& os) const;
|
||||||
|
|
||||||
|
//- Write the unordered keys as a list, with line-breaks if list length
|
||||||
|
// exceeds shortListLen. Using '0' suppresses line-breaks entirely.
|
||||||
|
Ostream& writeKeys(Ostream& os, const label shortListLen=0) const;
|
||||||
|
|
||||||
|
|
||||||
// IOstream Operator
|
// IOstream Operator
|
||||||
@ -548,7 +670,7 @@ public:
|
|||||||
friend Ostream& operator<< <T, Key, Hash>
|
friend Ostream& operator<< <T, Key, Hash>
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const HashTable<T, Key, Hash>& L
|
const HashTable<T, Key, Hash>& tbl
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -559,7 +681,8 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#include "HashTableI.H"
|
#include "HashTableCoreI.H"
|
||||||
|
#include "HashTableI.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -33,38 +33,53 @@ namespace Foam
|
|||||||
defineTypeNameAndDebug(HashTableCore, 0);
|
defineTypeNameAndDebug(HashTableCore, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Foam::label Foam::HashTableCore::maxTableSize
|
|
||||||
(
|
// Approximately labelMax/4
|
||||||
Foam::HashTableCore::canonicalSize
|
const Foam::label Foam::HashTableCore::maxTableSize(1 << (sizeof(label)*8-3));
|
||||||
(
|
|
||||||
Foam::labelMax/2
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::label Foam::HashTableCore::canonicalSize(const label size)
|
Foam::label Foam::HashTableCore::canonicalSize(const label requested_size)
|
||||||
{
|
{
|
||||||
if (size < 1)
|
if (requested_size < 1)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// enforce power of two
|
// Enforce power of two - makes for a vey fast modulus etc.
|
||||||
uLabel goodSize = size;
|
// Use unsigned for these calculations.
|
||||||
|
//
|
||||||
|
// - The lower limit (8) is somewhat arbitrary, but if the hash table
|
||||||
|
// is too small, there will be many direct table collisions.
|
||||||
|
// - The uper limit (approx. labelMax/4) must be a power of two,
|
||||||
|
// need not be extremely large for hashing.
|
||||||
|
|
||||||
if (goodSize & (goodSize - 1))
|
uLabel powerOfTwo = 8; // lower-limit
|
||||||
|
|
||||||
|
const uLabel size = requested_size;
|
||||||
|
if (size < powerOfTwo)
|
||||||
{
|
{
|
||||||
// brute-force is fast enough
|
return powerOfTwo;
|
||||||
goodSize = 1;
|
|
||||||
while (goodSize < unsigned(size))
|
|
||||||
{
|
|
||||||
goodSize <<= 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if (requested_size >= maxTableSize)
|
||||||
|
{
|
||||||
|
return maxTableSize;
|
||||||
|
}
|
||||||
|
else if (size & (size-1)) // <- Modulus of i^2
|
||||||
|
{
|
||||||
|
// Determine power-of-two. Brute-force is fast enough.
|
||||||
|
while (powerOfTwo < size)
|
||||||
|
{
|
||||||
|
powerOfTwo <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
return goodSize;
|
return powerOfTwo;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
146
src/OpenFOAM/containers/HashTables/HashTable/HashTableCoreI.H
Normal file
146
src/OpenFOAM/containers/HashTables/HashTable/HashTableCoreI.H
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / 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/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * helper methods * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline IteratorType Foam::HashTableCore::iterator_begin
|
||||||
|
(
|
||||||
|
TableType& table
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return IteratorType(table.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline IteratorType Foam::HashTableCore::iterator_begin
|
||||||
|
(
|
||||||
|
const TableType& table
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return IteratorType(table.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline IteratorType Foam::HashTableCore::iterator_cbegin
|
||||||
|
(
|
||||||
|
const TableType& table
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return IteratorType(table.cbegin());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IteratorType>
|
||||||
|
inline const IteratorType& Foam::HashTableCore::iterator_end()
|
||||||
|
{
|
||||||
|
return *reinterpret_cast<const IteratorType*>(nullObjectPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IteratorType>
|
||||||
|
inline const IteratorType& Foam::HashTableCore::iterator_cend()
|
||||||
|
{
|
||||||
|
return *reinterpret_cast<const IteratorType*>(nullObjectPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * const iterator pair * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline Foam::HashTableCore::const_iterator_pair<IteratorType, TableType>
|
||||||
|
::const_iterator_pair
|
||||||
|
(
|
||||||
|
const TableType& tbl
|
||||||
|
)
|
||||||
|
:
|
||||||
|
size_(tbl.size()),
|
||||||
|
iter_(tbl.begin())
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline Foam::label
|
||||||
|
Foam::HashTableCore::const_iterator_pair<IteratorType, TableType>::size() const
|
||||||
|
{
|
||||||
|
return size_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline bool
|
||||||
|
Foam::HashTableCore::const_iterator_pair<IteratorType, TableType>::empty() const
|
||||||
|
{
|
||||||
|
return !size_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline IteratorType Foam::HashTableCore::const_iterator_pair
|
||||||
|
<
|
||||||
|
IteratorType,
|
||||||
|
TableType
|
||||||
|
>::begin() const
|
||||||
|
{
|
||||||
|
return iter_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline IteratorType Foam::HashTableCore::const_iterator_pair
|
||||||
|
<
|
||||||
|
IteratorType,
|
||||||
|
TableType
|
||||||
|
>::cbegin() const
|
||||||
|
{
|
||||||
|
return iter_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline const IteratorType& Foam::HashTableCore::const_iterator_pair
|
||||||
|
<
|
||||||
|
IteratorType,
|
||||||
|
TableType
|
||||||
|
>::end() const
|
||||||
|
{
|
||||||
|
return HashTableCore::iterator_cend<IteratorType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IteratorType, class TableType>
|
||||||
|
inline const IteratorType& Foam::HashTableCore::const_iterator_pair
|
||||||
|
<
|
||||||
|
IteratorType,
|
||||||
|
TableType
|
||||||
|
>::cend() const
|
||||||
|
{
|
||||||
|
return HashTableCore::iterator_cend<IteratorType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -31,13 +31,13 @@ template<class T, class Key, class Hash>
|
|||||||
inline Foam::HashTable<T, Key, Hash>::hashedEntry::hashedEntry
|
inline Foam::HashTable<T, Key, Hash>::hashedEntry::hashedEntry
|
||||||
(
|
(
|
||||||
const Key& key,
|
const Key& key,
|
||||||
hashedEntry* next,
|
const T& obj,
|
||||||
const T& obj
|
hashedEntry* next
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
key_(key),
|
key_(key),
|
||||||
next_(next),
|
obj_(obj),
|
||||||
obj_(obj)
|
next_(next)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ inline T& Foam::HashTable<T, Key, Hash>::operator[](const Key& key)
|
|||||||
{
|
{
|
||||||
iterator iter = this->find(key);
|
iterator iter = this->find(key);
|
||||||
|
|
||||||
if (iter == this->end())
|
if (!iter.found())
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< key << " not found in table. Valid entries: "
|
<< key << " not found in table. Valid entries: "
|
||||||
@ -120,7 +120,7 @@ inline T& Foam::HashTable<T, Key, Hash>::operator[](const Key& key)
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return *iter;
|
return iter.object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ inline const T& Foam::HashTable<T, Key, Hash>::operator[](const Key& key) const
|
|||||||
{
|
{
|
||||||
const_iterator iter = this->find(key);
|
const_iterator iter = this->find(key);
|
||||||
|
|
||||||
if (iter == this->cend())
|
if (!iter.found())
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< key << " not found in table. Valid entries: "
|
<< key << " not found in table. Valid entries: "
|
||||||
@ -137,7 +137,7 @@ inline const T& Foam::HashTable<T, Key, Hash>::operator[](const Key& key) const
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return *iter;
|
return iter.object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -146,40 +146,52 @@ inline T& Foam::HashTable<T, Key, Hash>::operator()(const Key& key)
|
|||||||
{
|
{
|
||||||
iterator iter = this->find(key);
|
iterator iter = this->find(key);
|
||||||
|
|
||||||
if (iter == this->end())
|
if (iter.found())
|
||||||
{
|
{
|
||||||
this->insert(key, T());
|
return iter.object();
|
||||||
return *find(key);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return *iter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->insert(key, T());
|
||||||
|
return find(key).object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * iterator base * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * iterator base * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline Foam::HashTable<T, Key, Hash>::iteratorBase::iteratorBase()
|
inline Foam::HashTable<T, Key, Hash>::iterator_base::iterator_base()
|
||||||
:
|
:
|
||||||
hashTable_(0),
|
entryPtr_(nullptr),
|
||||||
entryPtr_(0),
|
hashTable_(nullptr),
|
||||||
hashIndex_(0)
|
hashIndex_(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline Foam::HashTable<T, Key, Hash>::iteratorBase::iteratorBase
|
inline Foam::HashTable<T, Key, Hash>::iterator_base::iterator_base
|
||||||
(
|
(
|
||||||
const HashTable<T, Key, Hash>* hashTbl
|
const table_type* hashTbl,
|
||||||
|
const entry_type* elmt,
|
||||||
|
const label hashIndex
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
hashTable_(const_cast<HashTable<T, Key, Hash>*>(hashTbl)),
|
entryPtr_(const_cast<entry_type*>(elmt)),
|
||||||
entryPtr_(0),
|
hashTable_(const_cast<table_type*>(hashTbl)),
|
||||||
|
hashIndex_(hashIndex)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
inline Foam::HashTable<T, Key, Hash>::iterator_base::iterator_base
|
||||||
|
(
|
||||||
|
const table_type* hashTbl
|
||||||
|
)
|
||||||
|
:
|
||||||
|
entryPtr_(nullptr),
|
||||||
|
hashTable_(const_cast<table_type*>(hashTbl)),
|
||||||
hashIndex_(0)
|
hashIndex_(0)
|
||||||
{
|
{
|
||||||
if (hashTable_->nElmts_)
|
if (hashTable_ && hashTable_->nElmts_)
|
||||||
{
|
{
|
||||||
// find first non-nullptr table entry
|
// find first non-nullptr table entry
|
||||||
while
|
while
|
||||||
@ -192,30 +204,16 @@ inline Foam::HashTable<T, Key, Hash>::iteratorBase::iteratorBase
|
|||||||
if (hashIndex_ >= hashTable_->tableSize_)
|
if (hashIndex_ >= hashTable_->tableSize_)
|
||||||
{
|
{
|
||||||
// make into an end iterator
|
// make into an end iterator
|
||||||
entryPtr_ = 0;
|
entryPtr_ = nullptr;
|
||||||
hashIndex_ = 0;
|
hashIndex_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
|
||||||
inline Foam::HashTable<T, Key, Hash>::iteratorBase::iteratorBase
|
|
||||||
(
|
|
||||||
const HashTable<T, Key, Hash>* hashTbl,
|
|
||||||
const hashedEntry* elmt,
|
|
||||||
const label hashIndex
|
|
||||||
)
|
|
||||||
:
|
|
||||||
hashTable_(const_cast<HashTable<T, Key, Hash>*>(hashTbl)),
|
|
||||||
entryPtr_(const_cast<hashedEntry*>(elmt)),
|
|
||||||
hashIndex_(hashIndex)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline void
|
inline void
|
||||||
Foam::HashTable<T, Key, Hash>::iteratorBase::increment()
|
Foam::HashTable<T, Key, Hash>::iterator_base::increment()
|
||||||
{
|
{
|
||||||
// A negative index is a special value from erase
|
// A negative index is a special value from erase
|
||||||
if (hashIndex_ < 0)
|
if (hashIndex_ < 0)
|
||||||
@ -251,7 +249,7 @@ Foam::HashTable<T, Key, Hash>::iteratorBase::increment()
|
|||||||
if (hashIndex_ >= hashTable_->tableSize_)
|
if (hashIndex_ >= hashTable_->tableSize_)
|
||||||
{
|
{
|
||||||
// make into an end iterator
|
// make into an end iterator
|
||||||
entryPtr_ = 0;
|
entryPtr_ = nullptr;
|
||||||
hashIndex_ = 0;
|
hashIndex_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,40 +257,30 @@ Foam::HashTable<T, Key, Hash>::iteratorBase::increment()
|
|||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline bool
|
inline bool
|
||||||
Foam::HashTable<T, Key, Hash>::iteratorBase::found() const
|
Foam::HashTable<T, Key, Hash>::iterator_base::found() const
|
||||||
{
|
{
|
||||||
return entryPtr_;
|
return entryPtr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline
|
inline const Key& Foam::HashTable<T, Key, Hash>::iterator_base::key() const
|
||||||
const Key& Foam::HashTable<T, Key, Hash>::iteratorBase::key() const
|
|
||||||
{
|
{
|
||||||
return entryPtr_->key_;
|
return entryPtr_->key_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline T&
|
inline T& Foam::HashTable<T, Key, Hash>::iterator_base::element() const
|
||||||
Foam::HashTable<T, Key, Hash>::iteratorBase::object()
|
|
||||||
{
|
{
|
||||||
return entryPtr_->obj_;
|
return entryPtr_->obj_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline const T&
|
inline bool Foam::HashTable<T, Key, Hash>::iterator_base::operator==
|
||||||
Foam::HashTable<T, Key, Hash>::iteratorBase::cobject() const
|
|
||||||
{
|
|
||||||
return entryPtr_->obj_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
|
||||||
inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator==
|
|
||||||
(
|
(
|
||||||
const iteratorBase& iter
|
const iterator_base& iter
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return entryPtr_ == iter.entryPtr_;
|
return entryPtr_ == iter.entryPtr_;
|
||||||
@ -300,32 +288,36 @@ inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator==
|
|||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator!=
|
inline bool Foam::HashTable<T, Key, Hash>::iterator_base::operator!=
|
||||||
(
|
(
|
||||||
const iteratorBase& iter
|
const iterator_base& iter
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return entryPtr_ != iter.entryPtr_;
|
return entryPtr_ != iter.entryPtr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * key iterator base * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator==
|
template<class WrappedIterator>
|
||||||
|
inline Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
|
||||||
|
::key_iterator_base
|
||||||
(
|
(
|
||||||
const iteratorEnd&
|
const WrappedIterator& iter
|
||||||
) const
|
)
|
||||||
{
|
:
|
||||||
return !entryPtr_;
|
WrappedIterator(iter)
|
||||||
}
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator!=
|
template<class WrappedIterator>
|
||||||
(
|
inline const Key&
|
||||||
const iteratorEnd&
|
Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
|
||||||
) const
|
::operator*() const
|
||||||
{
|
{
|
||||||
return entryPtr_;
|
return this->key();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -334,45 +326,43 @@ inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator!=
|
|||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline Foam::HashTable<T, Key, Hash>::iterator::iterator()
|
inline Foam::HashTable<T, Key, Hash>::iterator::iterator()
|
||||||
:
|
:
|
||||||
iteratorBase()
|
iterator_base()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
|
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
|
||||||
(
|
(
|
||||||
const iteratorEnd&
|
table_type* hashTbl
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
iteratorBase()
|
iterator_base(hashTbl)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
|
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
|
||||||
(
|
(
|
||||||
HashTable<T, Key, Hash>* hashTbl
|
table_type* hashTbl,
|
||||||
)
|
entry_type* elmt,
|
||||||
:
|
|
||||||
iteratorBase(hashTbl)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
|
||||||
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
|
|
||||||
(
|
|
||||||
HashTable<T, Key, Hash>* hashTbl,
|
|
||||||
hashedEntry* elmt,
|
|
||||||
const label hashIndex
|
const label hashIndex
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
iteratorBase(hashTbl, elmt, hashIndex)
|
iterator_base(hashTbl, elmt, hashIndex)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline T&
|
inline T&
|
||||||
Foam::HashTable<T, Key, Hash>::iterator::operator*()
|
Foam::HashTable<T, Key, Hash>::iterator::object() const
|
||||||
|
{
|
||||||
|
return this->element();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
inline T&
|
||||||
|
Foam::HashTable<T, Key, Hash>::iterator::operator*() const
|
||||||
{
|
{
|
||||||
return this->object();
|
return this->object();
|
||||||
}
|
}
|
||||||
@ -380,31 +370,14 @@ Foam::HashTable<T, Key, Hash>::iterator::operator*()
|
|||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline T&
|
inline T&
|
||||||
Foam::HashTable<T, Key, Hash>::iterator::operator()()
|
Foam::HashTable<T, Key, Hash>::iterator::operator()() const
|
||||||
{
|
{
|
||||||
return this->object();
|
return this->object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline const T&
|
inline typename Foam::HashTable<T, Key, Hash>::iterator&
|
||||||
Foam::HashTable<T, Key, Hash>::iterator::operator*() const
|
|
||||||
{
|
|
||||||
return this->cobject();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
|
||||||
inline const T&
|
|
||||||
Foam::HashTable<T, Key, Hash>::iterator::operator()() const
|
|
||||||
{
|
|
||||||
return this->cobject();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
|
||||||
inline
|
|
||||||
typename Foam::HashTable<T, Key, Hash>::iterator&
|
|
||||||
Foam::HashTable<T, Key, Hash>::iterator::operator++()
|
Foam::HashTable<T, Key, Hash>::iterator::operator++()
|
||||||
{
|
{
|
||||||
this->increment();
|
this->increment();
|
||||||
@ -422,20 +395,12 @@ Foam::HashTable<T, Key, Hash>::iterator::operator++(int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * //
|
||||||
inline typename Foam::HashTable<T, Key, Hash>::iterator
|
|
||||||
Foam::HashTable<T, Key, Hash>::begin()
|
|
||||||
{
|
|
||||||
return iterator(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator()
|
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator()
|
||||||
:
|
:
|
||||||
iteratorBase()
|
iterator_base()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -445,47 +410,45 @@ inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
|
|||||||
const HashTable<T, Key, Hash>::iterator& iter
|
const HashTable<T, Key, Hash>::iterator& iter
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
iteratorBase(iter)
|
iterator_base(iter)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
|
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
|
||||||
(
|
(
|
||||||
const iteratorEnd&
|
table_type* hashTbl
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
iteratorBase()
|
iterator_base(hashTbl)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
|
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
|
||||||
(
|
(
|
||||||
const HashTable<T, Key, Hash>* hashTbl
|
table_type* hashTbl,
|
||||||
)
|
entry_type* elmt,
|
||||||
:
|
|
||||||
iteratorBase(hashTbl)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
|
||||||
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
|
|
||||||
(
|
|
||||||
const HashTable<T, Key, Hash>* hashTbl,
|
|
||||||
const hashedEntry* elmt,
|
|
||||||
const label hashIndex
|
const label hashIndex
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
iteratorBase(hashTbl, elmt, hashIndex)
|
iterator_base(hashTbl, elmt, hashIndex)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
inline const T&
|
||||||
|
Foam::HashTable<T, Key, Hash>::const_iterator::object() const
|
||||||
|
{
|
||||||
|
return this->element();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline const T&
|
inline const T&
|
||||||
Foam::HashTable<T, Key, Hash>::const_iterator::operator*() const
|
Foam::HashTable<T, Key, Hash>::const_iterator::operator*() const
|
||||||
{
|
{
|
||||||
return this->cobject();
|
return this->object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -493,13 +456,12 @@ template<class T, class Key, class Hash>
|
|||||||
inline const T&
|
inline const T&
|
||||||
Foam::HashTable<T, Key, Hash>::const_iterator::operator()() const
|
Foam::HashTable<T, Key, Hash>::const_iterator::operator()() const
|
||||||
{
|
{
|
||||||
return this->cobject();
|
return this->object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline
|
inline typename Foam::HashTable<T, Key, Hash>::const_iterator&
|
||||||
typename Foam::HashTable<T, Key, Hash>::const_iterator&
|
|
||||||
Foam::HashTable<T, Key, Hash>::const_iterator::operator++()
|
Foam::HashTable<T, Key, Hash>::const_iterator::operator++()
|
||||||
{
|
{
|
||||||
this->increment();
|
this->increment();
|
||||||
@ -517,6 +479,24 @@ Foam::HashTable<T, Key, Hash>::const_iterator::operator++(int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
inline typename Foam::HashTable<T, Key, Hash>::iterator
|
||||||
|
Foam::HashTable<T, Key, Hash>::begin()
|
||||||
|
{
|
||||||
|
return iterator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
|
||||||
|
Foam::HashTable<T, Key, Hash>::begin() const
|
||||||
|
{
|
||||||
|
return const_iterator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
|
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
|
||||||
Foam::HashTable<T, Key, Hash>::cbegin() const
|
Foam::HashTable<T, Key, Hash>::cbegin() const
|
||||||
@ -526,10 +506,26 @@ Foam::HashTable<T, Key, Hash>::cbegin() const
|
|||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
|
inline const typename Foam::HashTable<T, Key, Hash>::iterator&
|
||||||
Foam::HashTable<T, Key, Hash>::begin() const
|
Foam::HashTable<T, Key, Hash>::end()
|
||||||
{
|
{
|
||||||
return this->cbegin();
|
return iterator_end<iterator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
inline const typename Foam::HashTable<T, Key, Hash>::const_iterator&
|
||||||
|
Foam::HashTable<T, Key, Hash>::end() const
|
||||||
|
{
|
||||||
|
return iterator_end<const_iterator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
inline const typename Foam::HashTable<T, Key, Hash>::const_iterator&
|
||||||
|
Foam::HashTable<T, Key, Hash>::cend() const
|
||||||
|
{
|
||||||
|
return iterator_cend<const_iterator>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -43,7 +43,7 @@ Foam::HashTable<T, Key, Hash>::HashTable(Istream& is, const label size)
|
|||||||
|
|
||||||
for (label hashIdx = 0; hashIdx < tableSize_; ++hashIdx)
|
for (label hashIdx = 0; hashIdx < tableSize_; ++hashIdx)
|
||||||
{
|
{
|
||||||
table_[hashIdx] = 0;
|
table_[hashIdx] = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,8 +54,7 @@ Foam::HashTable<T, Key, Hash>::HashTable(Istream& is, const label size)
|
|||||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
Foam::Ostream&
|
Foam::Ostream& Foam::HashTable<T, Key, Hash>::printInfo(Ostream& os) const
|
||||||
Foam::HashTable<T, Key, Hash>::printInfo(Ostream& os) const
|
|
||||||
{
|
{
|
||||||
label used = 0;
|
label used = 0;
|
||||||
label maxChain = 0;
|
label maxChain = 0;
|
||||||
@ -90,6 +89,53 @@ Foam::HashTable<T, Key, Hash>::printInfo(Ostream& os) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
Foam::Ostream& Foam::HashTable<T, Key, Hash>::writeKeys
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const label shortListLen
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
// Similar to UList::writeList version except the following:
|
||||||
|
// - the keys can never be uniform
|
||||||
|
// - never write in binary
|
||||||
|
|
||||||
|
label i = this->size();
|
||||||
|
|
||||||
|
if (i <= 1 || !shortListLen || (i <= shortListLen))
|
||||||
|
{
|
||||||
|
// Write size and start delimiter
|
||||||
|
os << i << token::BEGIN_LIST;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
for (const_iterator iter = this->cbegin(); iter != this->cend(); ++iter)
|
||||||
|
{
|
||||||
|
if (i++) os << token::SPACE;
|
||||||
|
os << iter.key();
|
||||||
|
}
|
||||||
|
|
||||||
|
os << token::END_LIST; // End delimiter
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Write size and start delimiter
|
||||||
|
os << nl << i << nl << token::BEGIN_LIST << nl;
|
||||||
|
|
||||||
|
for (const_iterator iter = this->cbegin(); iter != this->cend(); ++iter)
|
||||||
|
{
|
||||||
|
os << iter.key() << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
os << token::END_LIST << nl; // End delimiter
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check state of IOstream
|
||||||
|
os.check(FUNCTION_NAME);
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
@ -215,28 +261,25 @@ template<class T, class Key, class Hash>
|
|||||||
Foam::Ostream& Foam::operator<<
|
Foam::Ostream& Foam::operator<<
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const HashTable<T, Key, Hash>& L
|
const HashTable<T, Key, Hash>& tbl
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
using const_iterator = typename HashTable<T, Key, Hash>::const_iterator;
|
||||||
|
|
||||||
// Write size and start delimiter
|
// Write size and start delimiter
|
||||||
os << nl << L.size() << nl << token::BEGIN_LIST << nl;
|
os << nl << tbl.size() << nl << token::BEGIN_LIST << nl;
|
||||||
|
|
||||||
// Write contents
|
// Write contents
|
||||||
for
|
for (const_iterator iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
|
||||||
(
|
|
||||||
typename HashTable<T, Key, Hash>::const_iterator iter = L.cbegin();
|
|
||||||
iter != L.cend();
|
|
||||||
++iter
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
os << iter.key() << token::SPACE << iter() << nl;
|
os << iter.key() << token::SPACE << iter.object() << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write end delimiter
|
// Write end delimiter
|
||||||
os << token::END_LIST;
|
os << token::END_LIST;
|
||||||
|
|
||||||
// Check state of IOstream
|
// Check state of IOstream
|
||||||
os.check("Ostream& operator<<(Ostream&, const HashTable&)");
|
os.check(FUNCTION_NAME);
|
||||||
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -51,50 +51,54 @@ class Map
|
|||||||
:
|
:
|
||||||
public HashTable<T, label, Hash<label>>
|
public HashTable<T, label, Hash<label>>
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef typename HashTable<T, label, Hash<label>>::iterator iterator;
|
//- The template instance used for this Map
|
||||||
|
typedef Map<T> this_type;
|
||||||
|
|
||||||
|
//- The template instance used for the parent HashTable
|
||||||
|
typedef HashTable<T, label, Hash<label>> parent_type;
|
||||||
|
|
||||||
|
using iterator = typename parent_type::iterator;
|
||||||
|
using const_iterator = typename parent_type::const_iterator;
|
||||||
|
|
||||||
typedef typename HashTable<T, label, Hash<label>>::const_iterator
|
|
||||||
const_iterator;
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct given initial size
|
//- Construct given initial size
|
||||||
Map(const label size = 128)
|
Map(const label size = 128)
|
||||||
:
|
:
|
||||||
HashTable<T, label, Hash<label>>(size)
|
parent_type(size)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
Map(Istream& is)
|
Map(Istream& is)
|
||||||
:
|
:
|
||||||
HashTable<T, label, Hash<label>>(is)
|
parent_type(is)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct as copy
|
//- Construct as copy
|
||||||
Map(const Map<T>& map)
|
Map(const Map<T>& map)
|
||||||
:
|
:
|
||||||
HashTable<T, label, Hash<label>>(map)
|
parent_type(map)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct by transferring the parameter contents
|
//- Construct by transferring the parameter contents
|
||||||
Map(const Xfer<Map<T>>& map)
|
Map(const Xfer<Map<T>>& map)
|
||||||
:
|
:
|
||||||
HashTable<T, label, Hash<label>>(map)
|
parent_type(map)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct by transferring the parameter contents
|
//- Construct by transferring the parameter contents
|
||||||
Map(const Xfer<HashTable<T, label, Hash<label>>>& map)
|
Map(const Xfer<HashTable<T, label, Hash<label>>>& map)
|
||||||
:
|
:
|
||||||
HashTable<T, label, Hash<label>>(map)
|
parent_type(map)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct from an initializer list
|
//- Construct from an initializer list
|
||||||
Map(std::initializer_list<Tuple2<label, T>> map)
|
Map(std::initializer_list<Tuple2<label, T>> map)
|
||||||
:
|
:
|
||||||
HashTable<T, label, Hash<label>>(map)
|
parent_type(map)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -51,27 +51,33 @@ class PtrMap
|
|||||||
:
|
:
|
||||||
public HashPtrTable<T, label, Hash<label>>
|
public HashPtrTable<T, label, Hash<label>>
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
//- The template instance used for this PtrMap
|
||||||
|
typedef PtrMap<T> this_type;
|
||||||
|
|
||||||
|
//- The template instance used for the parent HashTable
|
||||||
|
typedef HashPtrTable<T, label, Hash<label>> parent_type;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct given initial map size
|
//- Construct given initial map size
|
||||||
PtrMap(const label size = 128)
|
PtrMap(const label size = 128)
|
||||||
:
|
:
|
||||||
HashPtrTable<T, label, Hash<label>>(size)
|
parent_type(size)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
PtrMap(Istream& is)
|
PtrMap(Istream& is)
|
||||||
:
|
:
|
||||||
HashPtrTable<T, label, Hash<label>>(is)
|
parent_type(is)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct as copy
|
//- Construct as copy
|
||||||
PtrMap(const PtrMap<T>& map)
|
PtrMap(const this_type& map)
|
||||||
:
|
:
|
||||||
HashPtrTable<T, label, Hash<label>>(map)
|
parent_type(map)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -30,32 +30,6 @@ License
|
|||||||
#include "List.H"
|
#include "List.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::label Foam::StaticHashTableCore::canonicalSize(const label size)
|
|
||||||
{
|
|
||||||
if (size < 1)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enforce power of two
|
|
||||||
unsigned int goodSize = size;
|
|
||||||
|
|
||||||
if (goodSize & (goodSize - 1))
|
|
||||||
{
|
|
||||||
// Brute-force is fast enough
|
|
||||||
goodSize = 1;
|
|
||||||
while (goodSize < unsigned(size))
|
|
||||||
{
|
|
||||||
goodSize <<= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return goodSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
|
|||||||
@ -78,8 +78,8 @@ template<class T, class Key, class Hash> Ostream& operator<<
|
|||||||
//- Template-invariant bits for StaticHashTable
|
//- Template-invariant bits for StaticHashTable
|
||||||
struct StaticHashTableCore
|
struct StaticHashTableCore
|
||||||
{
|
{
|
||||||
//- Return a canonical (power-of-two) size
|
//- Return a canonical (power-of-two) of the requested size.
|
||||||
static label canonicalSize(const label);
|
static label canonicalSize(const label requested_size);
|
||||||
|
|
||||||
//- Construct null
|
//- Construct null
|
||||||
StaticHashTableCore()
|
StaticHashTableCore()
|
||||||
@ -119,9 +119,6 @@ class StaticHashTable
|
|||||||
//- The current number of elements in table
|
//- The current number of elements in table
|
||||||
label nElmts_;
|
label nElmts_;
|
||||||
|
|
||||||
//- Return a canonical (power-of-two) size
|
|
||||||
static label canonicalSize(const label);
|
|
||||||
|
|
||||||
//- Return the hash index of the Key within the current table size.
|
//- Return the hash index of the Key within the current table size.
|
||||||
// No checks for zero-sized tables.
|
// No checks for zero-sized tables.
|
||||||
inline label hashKeyIndex(const Key&) const;
|
inline label hashKeyIndex(const Key&) const;
|
||||||
@ -397,7 +394,7 @@ private:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#include "StaticHashTableI.H"
|
#include "StaticHashTableI.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,7 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "StaticHashTable.H"
|
#include "StaticHashTable.H"
|
||||||
|
#include "uLabel.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -33,4 +34,53 @@ defineTypeNameAndDebug(StaticHashTableCore, 0);
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Approximately labelMax/4
|
||||||
|
static const Foam::label maxTableSize(1 << (sizeof(Foam::label)*8-3));
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::label Foam::StaticHashTableCore::canonicalSize(const label requested_size)
|
||||||
|
{
|
||||||
|
if (requested_size < 1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enforce power of two - makes for a vey fast modulus etc.
|
||||||
|
// Use unsigned for these calculations.
|
||||||
|
//
|
||||||
|
// - The lower limit (8) is somewhat arbitrary, but if the hash table
|
||||||
|
// is too small, there will be many direct table collisions.
|
||||||
|
// - The uper limit (approx. labelMax/4) must be a power of two,
|
||||||
|
// need not be extremely large for hashing.
|
||||||
|
|
||||||
|
uLabel powerOfTwo = 8; // lower-limit
|
||||||
|
|
||||||
|
const uLabel size = requested_size;
|
||||||
|
if (size < powerOfTwo)
|
||||||
|
{
|
||||||
|
return powerOfTwo;
|
||||||
|
}
|
||||||
|
else if (requested_size >= maxTableSize)
|
||||||
|
{
|
||||||
|
return maxTableSize;
|
||||||
|
}
|
||||||
|
else if (size & (size-1)) // <- Modulus of i^2
|
||||||
|
{
|
||||||
|
// Determine power-of-two. Brute-force is fast enough.
|
||||||
|
while (powerOfTwo < size)
|
||||||
|
{
|
||||||
|
powerOfTwo <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return powerOfTwo;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -329,7 +329,7 @@ public:
|
|||||||
//- Return size of the largest possible FixedList
|
//- Return size of the largest possible FixedList
|
||||||
inline label max_size() const;
|
inline label max_size() const;
|
||||||
|
|
||||||
//- Return true if the FixedList is empty (ie, size() is zero)
|
//- Always false since zero-sized FixedList is compile-time disabled.
|
||||||
inline bool empty() const;
|
inline bool empty() const;
|
||||||
|
|
||||||
//- Swap two FixedLists of the same type in constant time
|
//- Swap two FixedLists of the same type in constant time
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -40,6 +40,7 @@ SourceFiles
|
|||||||
#define SubList_H
|
#define SubList_H
|
||||||
|
|
||||||
#include "List.H"
|
#include "List.H"
|
||||||
|
#include "labelRange.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -55,7 +56,6 @@ class SubList
|
|||||||
:
|
:
|
||||||
public UList<T>
|
public UList<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Static Member Functions
|
// Static Member Functions
|
||||||
@ -81,6 +81,23 @@ public:
|
|||||||
const label startIndex
|
const label startIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Construct from UList and a (start,size) range.
|
||||||
|
// The range is subsetted with the list size itself to ensure that the
|
||||||
|
// result always addresses a valid section of the list.
|
||||||
|
inline SubList
|
||||||
|
(
|
||||||
|
const UList<T>& list,
|
||||||
|
const labelRange& range
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from UList and a (start,size) range, but bypassing
|
||||||
|
// run-time range checking.
|
||||||
|
inline SubList
|
||||||
|
(
|
||||||
|
const labelRange& range,
|
||||||
|
const UList<T>& list
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
@ -88,13 +105,13 @@ public:
|
|||||||
inline operator const Foam::List<T>&() const;
|
inline operator const Foam::List<T>&() const;
|
||||||
|
|
||||||
//- Assignment of all entries to the given sub-list
|
//- Assignment of all entries to the given sub-list
|
||||||
inline void operator=(const SubList<T>&);
|
inline void operator=(const SubList<T>& list);
|
||||||
|
|
||||||
//- Assignment of all entries to the given list
|
//- Assignment of all entries to the given list
|
||||||
inline void operator=(const UList<T>&);
|
inline void operator=(const UList<T>& list);
|
||||||
|
|
||||||
//- Assignment of all entries to the given value
|
//- Assignment of all entries to the given value
|
||||||
inline void operator=(const T&);
|
inline void operator=(const T& t);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -51,7 +51,6 @@ inline Foam::SubList<T>::SubList
|
|||||||
UList<T>(&(list.v_[startIndex]), subSize)
|
UList<T>(&(list.v_[startIndex]), subSize)
|
||||||
{
|
{
|
||||||
#ifdef FULLDEBUG
|
#ifdef FULLDEBUG
|
||||||
|
|
||||||
// Artificially allow the start of a zero-sized subList to be
|
// Artificially allow the start of a zero-sized subList to be
|
||||||
// one past the end of the original list.
|
// one past the end of the original list.
|
||||||
if (subSize)
|
if (subSize)
|
||||||
@ -69,6 +68,28 @@ inline Foam::SubList<T>::SubList
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline Foam::SubList<T>::SubList
|
||||||
|
(
|
||||||
|
const UList<T>& list,
|
||||||
|
const labelRange& range
|
||||||
|
)
|
||||||
|
:
|
||||||
|
SubList<T>(list.validateRange(range), list)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline Foam::SubList<T>::SubList
|
||||||
|
(
|
||||||
|
const labelRange& range,
|
||||||
|
const UList<T>& list
|
||||||
|
)
|
||||||
|
:
|
||||||
|
SubList<T>(list, range.size(), range.start())
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@ -88,16 +109,16 @@ inline Foam::SubList<T>::operator const Foam::List<T>&() const
|
|||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline void Foam::SubList<T>::operator=(const SubList<T>& sl)
|
inline void Foam::SubList<T>::operator=(const SubList<T>& list)
|
||||||
{
|
{
|
||||||
UList<T>::deepCopy(sl);
|
UList<T>::deepCopy(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline void Foam::SubList<T>::operator=(const UList<T>& l)
|
inline void Foam::SubList<T>::operator=(const UList<T>& list)
|
||||||
{
|
{
|
||||||
UList<T>::deepCopy(l);
|
UList<T>::deepCopy(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -26,9 +26,49 @@ License
|
|||||||
#include "UList.H"
|
#include "UList.H"
|
||||||
#include "ListLoopM.H"
|
#include "ListLoopM.H"
|
||||||
#include "contiguous.H"
|
#include "contiguous.H"
|
||||||
|
#include "labelRange.H"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::labelRange Foam::UList<T>::validateRange(const labelRange& range) const
|
||||||
|
{
|
||||||
|
const labelRange slice = range.subset0(this->size());
|
||||||
|
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
this->checkStart(slice.start());
|
||||||
|
this->checkSize(slice.start() + slice.size());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return slice;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::labelRange Foam::UList<T>::validateRange
|
||||||
|
(
|
||||||
|
std::initializer_list<label> start_size_pair
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (start_size_pair.size() != 2)
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "range specified with " << start_size_pair.size()
|
||||||
|
<< " elements instead of 2"
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto iter = start_size_pair.begin();
|
||||||
|
|
||||||
|
const label beg = *(iter++);
|
||||||
|
const label sz = *iter;
|
||||||
|
|
||||||
|
return this->validateRange(labelRange(beg, sz));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@ -64,6 +104,47 @@ void Foam::UList<T>::deepCopy(const UList<T>& a)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::UList<T> Foam::UList<T>::operator[](const labelRange& range)
|
||||||
|
{
|
||||||
|
const labelRange slice = validateRange(range);
|
||||||
|
|
||||||
|
return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
const Foam::UList<T> Foam::UList<T>::operator[](const labelRange& range) const
|
||||||
|
{
|
||||||
|
const labelRange slice = validateRange(range);
|
||||||
|
|
||||||
|
return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::UList<T> Foam::UList<T>::operator[]
|
||||||
|
(
|
||||||
|
std::initializer_list<label> start_size_pair
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const labelRange slice = validateRange(start_size_pair);
|
||||||
|
|
||||||
|
return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
const Foam::UList<T> Foam::UList<T>::operator[]
|
||||||
|
(
|
||||||
|
std::initializer_list<label> start_size_range
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
// Restricted range
|
||||||
|
const labelRange slice = validateRange(start_size_range);
|
||||||
|
|
||||||
|
return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void Foam::UList<T>::operator=(const T& t)
|
void Foam::UList<T>::operator=(const T& t)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -47,13 +47,16 @@ SourceFiles
|
|||||||
#include "uLabel.H"
|
#include "uLabel.H"
|
||||||
#include "nullObject.H"
|
#include "nullObject.H"
|
||||||
#include "zero.H"
|
#include "zero.H"
|
||||||
|
#include "stdFoam.H"
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// Forward declaration of friend classes
|
// Forward declarations
|
||||||
|
class labelRange;
|
||||||
template<class T> class List;
|
template<class T> class List;
|
||||||
template<class T> class SubList;
|
template<class T> class SubList;
|
||||||
|
|
||||||
@ -100,6 +103,16 @@ protected:
|
|||||||
//- Write the UList with its compound type
|
//- Write the UList with its compound type
|
||||||
void writeEntry(Ostream& os) const;
|
void writeEntry(Ostream& os) const;
|
||||||
|
|
||||||
|
//- Return a validated (start,size) subset range, which means that it
|
||||||
|
// always addresses a valid section of the list.
|
||||||
|
labelRange validateRange(const labelRange& range) const;
|
||||||
|
|
||||||
|
//- Return a validated (start,size) subset range, which means that it
|
||||||
|
// always addresses a valid section of the list.
|
||||||
|
labelRange validateRange
|
||||||
|
(
|
||||||
|
std::initializer_list<label> start_size_pair
|
||||||
|
) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -238,6 +251,29 @@ public:
|
|||||||
// an out-of-range element returns false without any ill-effects
|
// an out-of-range element returns false without any ill-effects
|
||||||
inline const T& operator[](const label i) const;
|
inline const T& operator[](const label i) const;
|
||||||
|
|
||||||
|
//- Return (start,size) subset from UList with non-const access.
|
||||||
|
// The range is subsetted with the list size itself to ensure that the
|
||||||
|
// result always addresses a valid section of the list.
|
||||||
|
UList<T> operator[](const labelRange& range);
|
||||||
|
|
||||||
|
//- Return (start,size) subset from UList with const access.
|
||||||
|
// The range is subsetted with the list size itself to ensure that the
|
||||||
|
// result always addresses a valid section of the list.
|
||||||
|
const UList<T> operator[](const labelRange& range) const;
|
||||||
|
|
||||||
|
//- Return (start,size) subset from UList with non-const access.
|
||||||
|
// The range is subsetted with the list size itself to ensure that the
|
||||||
|
// result always addresses a valid section of the list.
|
||||||
|
UList<T> operator[](std::initializer_list<label> start_size_range);
|
||||||
|
|
||||||
|
//- Return (start,size) subset from UList with const access.
|
||||||
|
// The range is subsetted with the list size itself to ensure that the
|
||||||
|
// result always addresses a valid section of the list.
|
||||||
|
const UList<T> operator[]
|
||||||
|
(
|
||||||
|
std::initializer_list<label> start_size_range
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Allow cast to a const List<T>&
|
//- Allow cast to a const List<T>&
|
||||||
inline operator const Foam::List<T>&() const;
|
inline operator const Foam::List<T>&() const;
|
||||||
|
|
||||||
@ -253,12 +289,10 @@ public:
|
|||||||
//- Type of values the UList contains
|
//- Type of values the UList contains
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
|
|
||||||
//- Type that can be used for storing into
|
//- The type used for storing into value_type objects
|
||||||
// UList::value_type objects
|
|
||||||
typedef T& reference;
|
typedef T& reference;
|
||||||
|
|
||||||
//- Type that can be used for storing into
|
//- The type used for reading from constant value_type objects.
|
||||||
// constant UList::value_type objects
|
|
||||||
typedef const T& const_reference;
|
typedef const T& const_reference;
|
||||||
|
|
||||||
//- The type that can represent the difference between any two
|
//- The type that can represent the difference between any two
|
||||||
@ -427,69 +461,6 @@ inline void reverse(UList<T>& ul);
|
|||||||
|
|
||||||
#include "UListI.H"
|
#include "UListI.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
//- Loop across all elements in \a list
|
|
||||||
// \par Usage
|
|
||||||
// \code
|
|
||||||
// forAll(anyList, i)
|
|
||||||
// {
|
|
||||||
// statements;
|
|
||||||
// }
|
|
||||||
// \endcode
|
|
||||||
// \sa forAllReverse
|
|
||||||
#define forAll(list, i) \
|
|
||||||
for (Foam::label i=0; i<(list).size(); ++i)
|
|
||||||
|
|
||||||
//- Reverse loop across all elements in \a list
|
|
||||||
// \par Usage
|
|
||||||
// \code
|
|
||||||
// forAllReverse(anyList, i)
|
|
||||||
// {
|
|
||||||
// statements;
|
|
||||||
// }
|
|
||||||
// \endcode
|
|
||||||
// \sa forAll
|
|
||||||
#define forAllReverse(list, i) \
|
|
||||||
for (Foam::label i=(list).size()-1; i>=0; --i)
|
|
||||||
|
|
||||||
//- Iterate across all elements in the \a container object of type
|
|
||||||
// \a Container.
|
|
||||||
// \par Usage
|
|
||||||
// \code
|
|
||||||
// forAll(ContainerType, container, iter)
|
|
||||||
// {
|
|
||||||
// statements;
|
|
||||||
// }
|
|
||||||
// \endcode
|
|
||||||
// \sa forAllConstIter
|
|
||||||
#define forAllIter(Container,container,iter) \
|
|
||||||
for \
|
|
||||||
( \
|
|
||||||
Container::iterator iter = (container).begin(); \
|
|
||||||
iter != (container).end(); \
|
|
||||||
++iter \
|
|
||||||
)
|
|
||||||
|
|
||||||
//- Iterate across all elements in the \a container object of type
|
|
||||||
// \a Container with const access.
|
|
||||||
// \par Usage
|
|
||||||
// \code
|
|
||||||
// forAllConstIter(ContainerType, container, iter)
|
|
||||||
// {
|
|
||||||
// statements;
|
|
||||||
// }
|
|
||||||
// \endcode
|
|
||||||
// \sa forAllIter
|
|
||||||
#define forAllConstIter(Container,container,iter) \
|
|
||||||
for \
|
|
||||||
( \
|
|
||||||
Container::const_iterator iter = (container).cbegin(); \
|
|
||||||
iter != (container).cend(); \
|
|
||||||
++iter \
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#ifdef NoRepository
|
#ifdef NoRepository
|
||||||
|
|||||||
@ -71,7 +71,7 @@ inline Foam::label Foam::UList<T>::rcIndex(const label i) const
|
|||||||
template<class T>
|
template<class T>
|
||||||
inline void Foam::UList<T>::checkStart(const label start) const
|
inline void Foam::UList<T>::checkStart(const label start) const
|
||||||
{
|
{
|
||||||
if (start<0 || (start && start>=size_))
|
if (start < 0 || (start && start >= size_))
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "start " << start << " out of range 0 ... " << max(size_-1, 0)
|
<< "start " << start << " out of range 0 ... " << max(size_-1, 0)
|
||||||
@ -83,7 +83,7 @@ inline void Foam::UList<T>::checkStart(const label start) const
|
|||||||
template<class T>
|
template<class T>
|
||||||
inline void Foam::UList<T>::checkSize(const label size) const
|
inline void Foam::UList<T>::checkSize(const label size) const
|
||||||
{
|
{
|
||||||
if (size<0 || size>size_)
|
if (size < 0 || size > size_)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "size " << size << " out of range 0 ... " << size_
|
<< "size " << size << " out of range 0 ... " << size_
|
||||||
@ -162,7 +162,6 @@ inline void Foam::UList<T>::shallowCopy(const UList<T>& a)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline T& Foam::UList<T>::operator[](const label i)
|
inline T& Foam::UList<T>::operator[](const label i)
|
||||||
{
|
{
|
||||||
@ -172,7 +171,6 @@ inline T& Foam::UList<T>::operator[](const label i)
|
|||||||
return v_[i];
|
return v_[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
// Template specialization for bool
|
// Template specialization for bool
|
||||||
@ -191,7 +189,6 @@ namespace Foam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline const T& Foam::UList<T>::operator[](const label i) const
|
inline const T& Foam::UList<T>::operator[](const label i) const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -64,14 +64,14 @@ Enum Foam::NamedEnum<Enum, nEnum>::read(Istream& is) const
|
|||||||
|
|
||||||
HashTable<int>::const_iterator iter = find(name);
|
HashTable<int>::const_iterator iter = find(name);
|
||||||
|
|
||||||
if (iter == HashTable<int>::end())
|
if (!iter.found())
|
||||||
{
|
{
|
||||||
FatalIOErrorInFunction(is)
|
FatalIOErrorInFunction(is)
|
||||||
<< name << " is not in enumeration: "
|
<< name << " is not in enumeration: "
|
||||||
<< sortedToc() << exit(FatalIOError);
|
<< sortedToc() << exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Enum(iter());
|
return Enum(iter.object());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
212
src/OpenFOAM/include/stdFoam.H
Normal file
212
src/OpenFOAM/include/stdFoam.H
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / 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/>.
|
||||||
|
|
||||||
|
Namespace
|
||||||
|
stdFoam
|
||||||
|
|
||||||
|
Description
|
||||||
|
Includes some global templates and macros used by OpenFOAM.
|
||||||
|
|
||||||
|
Some of the templates are defined here correspond to useful
|
||||||
|
std templates that are part of future C++ standards, or that
|
||||||
|
are in a state of change. Defining them here provides some additional
|
||||||
|
control over which definition are used within the OpenFOAM code-base.
|
||||||
|
|
||||||
|
SeeAlso
|
||||||
|
- http://en.cppreference.com/w/cpp/iterator/end
|
||||||
|
- http://en.cppreference.com/w/cpp/iterator/begin
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef StdFoam_H
|
||||||
|
#define StdFoam_H
|
||||||
|
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace stdFoam
|
||||||
|
{
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
//- Return iterator to the beginning of the container \a c or array.
|
||||||
|
// Definition as per std::begin C++17
|
||||||
|
template<class C>
|
||||||
|
constexpr auto begin(C& c) -> decltype(c.begin())
|
||||||
|
{
|
||||||
|
return c.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Return const_iterator to the beginning of the container \a c or array.
|
||||||
|
// Definition as per std::begin C++17
|
||||||
|
template<class C>
|
||||||
|
constexpr auto begin(const C& c) -> decltype(c.begin())
|
||||||
|
{
|
||||||
|
return c.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Return const_iterator to the beginning of the container \a c or array.
|
||||||
|
// Definition as per std::cbegin C++17
|
||||||
|
template<class C>
|
||||||
|
constexpr auto cbegin(const C& c) -> decltype(c.begin())
|
||||||
|
{
|
||||||
|
return c.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Return iterator to the end of the container \a c or array.
|
||||||
|
// Definition as per std::end C++17
|
||||||
|
template<class C>
|
||||||
|
constexpr auto end(C& c) -> decltype(c.end())
|
||||||
|
{
|
||||||
|
return c.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Return const_iterator to the end of the container \a c or array.
|
||||||
|
// Definition as per std::end C++17
|
||||||
|
template<class C>
|
||||||
|
constexpr auto end(const C& c) -> decltype(c.end())
|
||||||
|
{
|
||||||
|
return c.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Return const_iterator to the end of the container \a c or array.
|
||||||
|
// Definition as per std::cend C++17
|
||||||
|
template<class C>
|
||||||
|
constexpr auto cend(const C& c) -> decltype(c.end())
|
||||||
|
{
|
||||||
|
return c.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // End namespace stdFoam
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
//- Iterate across all elements in the \a container object of type
|
||||||
|
// \a Container.
|
||||||
|
// \par Usage
|
||||||
|
// \code
|
||||||
|
// forAllIters(container, iter)
|
||||||
|
// {
|
||||||
|
// statements;
|
||||||
|
// }
|
||||||
|
// \endcode
|
||||||
|
// \sa forAllConstIters, forAllIter, forAllConstIters
|
||||||
|
#define forAllIters(container,it) \
|
||||||
|
for \
|
||||||
|
( \
|
||||||
|
auto it = stdFoam::begin(container); \
|
||||||
|
it != stdFoam::end(container); \
|
||||||
|
++it \
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
//- Iterate across all elements of the \a container object with const access.
|
||||||
|
// \par Usage
|
||||||
|
// \code
|
||||||
|
// forAllConstIters(container, iter)
|
||||||
|
// {
|
||||||
|
// statements;
|
||||||
|
// }
|
||||||
|
// \endcode
|
||||||
|
// \sa forAllIters, forAllIter, forAllConstIter
|
||||||
|
#define forAllConstIters(container,cit) \
|
||||||
|
for \
|
||||||
|
( \
|
||||||
|
auto cit = stdFoam::cbegin(container); \
|
||||||
|
cit != stdFoam::cend(container); \
|
||||||
|
++cit \
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
//- Loop across all elements in \a list
|
||||||
|
// \par Usage
|
||||||
|
// \code
|
||||||
|
// forAll(anyList, i)
|
||||||
|
// {
|
||||||
|
// statements;
|
||||||
|
// }
|
||||||
|
// \endcode
|
||||||
|
// \sa forAllReverse
|
||||||
|
#define forAll(list, i) \
|
||||||
|
for (Foam::label i=0; i<(list).size(); ++i)
|
||||||
|
|
||||||
|
|
||||||
|
//- Reverse loop across all elements in \a list
|
||||||
|
// \par Usage
|
||||||
|
// \code
|
||||||
|
// forAllReverse(anyList, i)
|
||||||
|
// {
|
||||||
|
// statements;
|
||||||
|
// }
|
||||||
|
// \endcode
|
||||||
|
// \sa forAll
|
||||||
|
#define forAllReverse(list, i) \
|
||||||
|
for (Foam::label i=(list).size()-1; i>=0; --i)
|
||||||
|
|
||||||
|
|
||||||
|
//- Iterate across all elements in the \a container object
|
||||||
|
// of type \a Container.
|
||||||
|
// \par Usage
|
||||||
|
// \code
|
||||||
|
// forAllIter(ContainerType, container, iter)
|
||||||
|
// {
|
||||||
|
// statements;
|
||||||
|
// }
|
||||||
|
// \endcode
|
||||||
|
// \sa forAllConstIter
|
||||||
|
#define forAllIter(Container,container,iter) \
|
||||||
|
for \
|
||||||
|
( \
|
||||||
|
Container::iterator iter = (container).begin(); \
|
||||||
|
iter != (container).end(); \
|
||||||
|
++iter \
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
//- Iterate across all elements in the \a container object
|
||||||
|
// of type \a Container with const access.
|
||||||
|
// \par Usage
|
||||||
|
// \code
|
||||||
|
// forAllConstIter(ContainerType, container, iter)
|
||||||
|
// {
|
||||||
|
// statements;
|
||||||
|
// }
|
||||||
|
// \endcode
|
||||||
|
// \sa forAllIter
|
||||||
|
#define forAllConstIter(Container,container,iter) \
|
||||||
|
for \
|
||||||
|
( \
|
||||||
|
Container::const_iterator iter = (container).cbegin(); \
|
||||||
|
iter != (container).cend(); \
|
||||||
|
++iter \
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -50,11 +50,8 @@ namespace Foam
|
|||||||
class boundBox;
|
class boundBox;
|
||||||
template<class T> class tmp;
|
template<class T> class tmp;
|
||||||
|
|
||||||
bool operator==(const boundBox&, const boundBox&);
|
Istream& operator>>(Istream& is, boundBox& bb);
|
||||||
bool operator!=(const boundBox&, const boundBox&);
|
Ostream& operator<<(Ostream& os, const boundBox& bb);
|
||||||
|
|
||||||
Istream& operator>>(Istream&, boundBox&);
|
|
||||||
Ostream& operator<<(Ostream&, const boundBox&);
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
@ -289,12 +286,6 @@ public:
|
|||||||
inline void operator+=(const boundBox& bb);
|
inline void operator+=(const boundBox& bb);
|
||||||
|
|
||||||
|
|
||||||
// Friend Operators
|
|
||||||
|
|
||||||
inline friend bool operator==(const boundBox& a, const boundBox& b);
|
|
||||||
inline friend bool operator!=(const boundBox& a, const boundBox& b);
|
|
||||||
|
|
||||||
|
|
||||||
// IOstream operator
|
// IOstream operator
|
||||||
|
|
||||||
friend Istream& operator>>(Istream& is, boundBox& bb);
|
friend Istream& operator>>(Istream& is, boundBox& bb);
|
||||||
@ -306,6 +297,11 @@ public:
|
|||||||
template<>
|
template<>
|
||||||
inline bool contiguous<boundBox>() {return contiguous<point>();}
|
inline bool contiguous<boundBox>() {return contiguous<point>();}
|
||||||
|
|
||||||
|
// Global Operators
|
||||||
|
|
||||||
|
inline bool operator==(const boundBox& a, const boundBox& b);
|
||||||
|
inline bool operator!=(const boundBox& a, const boundBox& b);
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|||||||
@ -268,11 +268,11 @@ inline void Foam::boundBox::operator+=(const boundBox& bb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline bool Foam::operator==(const boundBox& a, const boundBox& b)
|
inline bool Foam::operator==(const boundBox& a, const boundBox& b)
|
||||||
{
|
{
|
||||||
return (a.min_ == b.min_) && (a.max_ == b.max_);
|
return (a.min() == b.min()) && (a.max() == b.max());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -63,7 +63,7 @@ inline Foam::label Foam::cell::nFaces() const
|
|||||||
|
|
||||||
inline bool Foam::operator!=(const cell& a, const cell& b)
|
inline bool Foam::operator!=(const cell& a, const cell& b)
|
||||||
{
|
{
|
||||||
return (!(a == b));
|
return !(a == b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -59,7 +59,7 @@ Ostream& operator<<(Ostream& os, const cellModel& c);
|
|||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class cellModel Declaration
|
Class cellModel Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class cellModel
|
class cellModel
|
||||||
@ -122,13 +122,13 @@ public:
|
|||||||
inline label nFaces() const;
|
inline label nFaces() const;
|
||||||
|
|
||||||
//- Return list of edges
|
//- Return list of edges
|
||||||
inline edgeList edges(const labelList& pointLabels) const;
|
inline edgeList edges(const UList<label>& pointLabels) const;
|
||||||
|
|
||||||
//- Return a raw list of model faces
|
//- Return a raw list of model faces
|
||||||
inline const faceList& modelFaces() const;
|
inline const faceList& modelFaces() const;
|
||||||
|
|
||||||
//- Return list of faces
|
//- Return list of faces
|
||||||
inline faceList faces(const labelList& pointLabels) const;
|
inline faceList faces(const UList<label>& pointLabels) const;
|
||||||
|
|
||||||
|
|
||||||
//- Vector centroid
|
//- Vector centroid
|
||||||
|
|||||||
@ -21,45 +21,38 @@ License
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Description
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "error.H"
|
#include "error.H"
|
||||||
#include "cellModel.H"
|
#include "cellModel.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
namespace Foam
|
|
||||||
{
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline const word& cellModel::name() const
|
inline const Foam::word& Foam::cellModel::name() const
|
||||||
{
|
{
|
||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline label cellModel::index() const
|
inline Foam::label Foam::cellModel::index() const
|
||||||
{
|
{
|
||||||
return index_;
|
return index_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline label cellModel::nPoints() const
|
inline Foam::label Foam::cellModel::nPoints() const
|
||||||
{
|
{
|
||||||
return nPoints_;
|
return nPoints_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline label cellModel::nEdges() const
|
inline Foam::label Foam::cellModel::nEdges() const
|
||||||
{
|
{
|
||||||
return edges_.size();
|
return edges_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline label cellModel::nFaces() const
|
inline Foam::label Foam::cellModel::nFaces() const
|
||||||
{
|
{
|
||||||
return faces_.size();
|
return faces_.size();
|
||||||
}
|
}
|
||||||
@ -67,7 +60,10 @@ inline label cellModel::nFaces() const
|
|||||||
|
|
||||||
// Return the faces of a cellModel by untangling the geometry
|
// Return the faces of a cellModel by untangling the geometry
|
||||||
// supplied in terms of the face labels
|
// supplied in terms of the face labels
|
||||||
inline edgeList cellModel::edges(const labelList& pointLabels) const
|
inline Foam::edgeList Foam::cellModel::edges
|
||||||
|
(
|
||||||
|
const UList<label>& pointLabels
|
||||||
|
) const
|
||||||
{
|
{
|
||||||
edgeList e(edges_.size());
|
edgeList e(edges_.size());
|
||||||
|
|
||||||
@ -86,7 +82,7 @@ inline edgeList cellModel::edges(const labelList& pointLabels) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const faceList& cellModel::modelFaces() const
|
inline const Foam::faceList& Foam::cellModel::modelFaces() const
|
||||||
{
|
{
|
||||||
return faces_;
|
return faces_;
|
||||||
}
|
}
|
||||||
@ -94,7 +90,10 @@ inline const faceList& cellModel::modelFaces() const
|
|||||||
|
|
||||||
// Return the faces of a cellModel by untangling the geometry
|
// Return the faces of a cellModel by untangling the geometry
|
||||||
// supplied in terms of the face labels
|
// supplied in terms of the face labels
|
||||||
inline faceList cellModel::faces(const labelList& pointLabels) const
|
inline Foam::faceList Foam::cellModel::faces
|
||||||
|
(
|
||||||
|
const UList<label>& pointLabels
|
||||||
|
) const
|
||||||
{
|
{
|
||||||
faceList f(faces_.size());
|
faceList f(faces_.size());
|
||||||
|
|
||||||
@ -120,20 +119,16 @@ inline faceList cellModel::faces(const labelList& pointLabels) const
|
|||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// Equality operator: true => ptr to models are equal !
|
// Equality operator: true => ptr to models are equal !
|
||||||
inline bool operator==(const cellModel& m1, const cellModel& m2)
|
inline bool Foam::operator==(const cellModel& m1, const cellModel& m2)
|
||||||
{
|
{
|
||||||
return (&m1 == &m2);
|
return (&m1 == &m2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inequality operator: true => ptr to models are not equal !
|
// Inequality operator: true => ptr to models are not equal !
|
||||||
inline bool operator!=(const cellModel& m1, const cellModel& m2)
|
inline bool Foam::operator!=(const cellModel& m1, const cellModel& m2)
|
||||||
{
|
{
|
||||||
return (&m1 != &m2);
|
return (&m1 != &m2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -28,6 +28,14 @@ Description
|
|||||||
An edge is a list of two point labels. The functionality it provides
|
An edge is a list of two point labels. The functionality it provides
|
||||||
supports the discretisation on a 2-D flat mesh.
|
supports the discretisation on a 2-D flat mesh.
|
||||||
|
|
||||||
|
The edge is implemented as a FixedList of labels.
|
||||||
|
As well as geometrically relevant methods, it also provides methods
|
||||||
|
similar to HashSet for additional convenience.
|
||||||
|
Valid point labels are always non-negative (since they correspond to
|
||||||
|
addressing within the mesh). The value '-1' is used to tag invalid
|
||||||
|
point labels that correspond conceptually to open 'slots', which
|
||||||
|
can be filled with a HashSet-like functionality.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
edgeI.H
|
edgeI.H
|
||||||
|
|
||||||
@ -37,6 +45,7 @@ SourceFiles
|
|||||||
#define edge_H
|
#define edge_H
|
||||||
|
|
||||||
#include "FixedList.H"
|
#include "FixedList.H"
|
||||||
|
#include "labelPair.H"
|
||||||
#include "pointField.H"
|
#include "pointField.H"
|
||||||
#include "linePointRef.H"
|
#include "linePointRef.H"
|
||||||
|
|
||||||
@ -45,21 +54,32 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// Forward declaration of friend functions and operators
|
|
||||||
|
|
||||||
class edge;
|
|
||||||
inline bool operator==(const edge& a, const edge& b);
|
|
||||||
inline bool operator!=(const edge& a, const edge& b);
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class edge Declaration
|
Class edge Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class edge
|
class edge
|
||||||
:
|
:
|
||||||
public FixedList<label, 2>
|
public FixedList<label, 2>
|
||||||
{
|
{
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Insert values, using begin/end iterators.
|
||||||
|
template<class InputIter>
|
||||||
|
inline label insertMultiple
|
||||||
|
(
|
||||||
|
const InputIter begIter,
|
||||||
|
const InputIter endIter
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Remove values, using begin/end iterators.
|
||||||
|
template<class InputIter>
|
||||||
|
inline label eraseMultiple
|
||||||
|
(
|
||||||
|
const InputIter begIter,
|
||||||
|
const InputIter endIter
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -79,6 +99,9 @@ public:
|
|||||||
//- Construct, optionally sorted with start less-than end
|
//- Construct, optionally sorted with start less-than end
|
||||||
inline edge(const label from, const label to, const bool doSort);
|
inline edge(const label from, const label to, const bool doSort);
|
||||||
|
|
||||||
|
//- Construct from two labels
|
||||||
|
inline edge(const labelPair& pair);
|
||||||
|
|
||||||
//- Construct from FixedList
|
//- Construct from FixedList
|
||||||
inline edge(const FixedList<label, 2>& lst);
|
inline edge(const FixedList<label, 2>& lst);
|
||||||
|
|
||||||
@ -91,6 +114,8 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
|
// Access
|
||||||
|
|
||||||
//- Return start vertex label
|
//- Return start vertex label
|
||||||
inline label start() const;
|
inline label start() const;
|
||||||
|
|
||||||
@ -103,82 +128,157 @@ public:
|
|||||||
//- Return end vertex label
|
//- Return end vertex label
|
||||||
inline label& end();
|
inline label& end();
|
||||||
|
|
||||||
|
//- Return reverse edge as copy.
|
||||||
|
// No special handling of negative point labels.
|
||||||
|
inline edge reverseEdge() const;
|
||||||
|
|
||||||
|
|
||||||
|
// Queries
|
||||||
|
|
||||||
|
//- Return the smallest point label used by the edge
|
||||||
|
// No special handling of negative point labels.
|
||||||
|
inline label minVertex() const;
|
||||||
|
|
||||||
|
//- Return the largest point label used by the edge
|
||||||
|
// No special handling of negative point labels.
|
||||||
|
inline label maxVertex() const;
|
||||||
|
|
||||||
|
//- True if start() is less-than end()
|
||||||
|
// No special handling of negative point labels.
|
||||||
|
inline bool sorted() const;
|
||||||
|
|
||||||
|
//- Return true if point label is found in edge.
|
||||||
|
// Always false for a negative label.
|
||||||
|
inline bool found(const label index) const;
|
||||||
|
|
||||||
//- Do the edges share a common vertex index?
|
//- Do the edges share a common vertex index?
|
||||||
|
// Negative point labels never connect.
|
||||||
inline bool connects(const edge& other) const;
|
inline bool connects(const edge& other) const;
|
||||||
|
|
||||||
//- Return vertex common with otherEdge or -1 on failure
|
//- Return vertex common with otherEdge or -1 on failure
|
||||||
|
// Negative point labels are never considered common between edges.
|
||||||
inline label commonVertex(const edge& other) const;
|
inline label commonVertex(const edge& other) const;
|
||||||
|
|
||||||
//- Given one vertex index, return the other one.
|
//- Given one vertex index, return the other one.
|
||||||
|
// No special treatment for negative point labels.
|
||||||
inline label otherVertex(const label index) const;
|
inline label otherVertex(const label index) const;
|
||||||
|
|
||||||
//- 'Collapse' edge by marking duplicate point labels.
|
|
||||||
// Duplicates point labels are marked with '-1'.
|
// Editing
|
||||||
// (the lower vertex is retained).
|
|
||||||
// Return the collapsed size.
|
//- 'Collapse' edge by marking duplicate point labels as '-1',
|
||||||
|
// the lower vertex is retained.
|
||||||
|
// Return the effective size after collapsing.
|
||||||
inline label collapse();
|
inline label collapse();
|
||||||
|
|
||||||
//- Return true if point label is found in edge
|
//- Flip the edge in-place.
|
||||||
// No special treatment for '-1'.
|
// No special handling of negative point labels.
|
||||||
inline bool found(const label index) const;
|
inline void flip();
|
||||||
|
|
||||||
|
//- Sort so that start() is less-than end()
|
||||||
|
// No special handling of negative point labels.
|
||||||
|
inline void sort();
|
||||||
|
|
||||||
|
|
||||||
|
// Hash-like functions
|
||||||
|
|
||||||
//- Return the number of unique, valid (non -1) point labels.
|
//- Return the number of unique, valid (non -1) point labels.
|
||||||
// Similar to a HashTable::size().
|
// Similar to a HashTable::size().
|
||||||
inline label count() const;
|
inline label count() const;
|
||||||
|
|
||||||
//- Insert the index if it did not previously exist on the edge.
|
//- Return true if edge has no valid point labels.
|
||||||
|
inline bool empty() const;
|
||||||
|
|
||||||
|
//- 'Clears' edge by setting both ends to invalid point labels.
|
||||||
|
inline void clear();
|
||||||
|
|
||||||
|
//- Fill any open slot with the index if it did not previously exist.
|
||||||
// Returns true on success. A negative label never inserts.
|
// Returns true on success. A negative label never inserts.
|
||||||
// Similar to a HashTable::insert().
|
// Similar to a HashTable::insert().
|
||||||
inline bool insert(const label index);
|
inline bool insert(const label index);
|
||||||
|
|
||||||
|
//- Fill open slots with the indices if they did not previously exist.
|
||||||
|
// Returns true on success. Negative labels never insert.
|
||||||
|
// Return the number of slots filled.
|
||||||
|
// Similar to a HashTable::insert().
|
||||||
|
inline label insert(const UList<label>& lst);
|
||||||
|
|
||||||
|
//- Fill open slots with the indices if they did not previously exist.
|
||||||
|
// Returns true on success. Negative labels never insert.
|
||||||
|
// Return the number of slots filled.
|
||||||
|
// Similar to a HashTable::insert().
|
||||||
|
template<unsigned AnySize>
|
||||||
|
inline label insert(const FixedList<label, AnySize>& lst);
|
||||||
|
|
||||||
|
//- Fill open slots with the indices if they did not previously exist.
|
||||||
|
// Returns true on success. Negative labels never insert.
|
||||||
|
// Return the number of slots filled.
|
||||||
|
// Similar to a HashTable::insert().
|
||||||
|
inline label insert(std::initializer_list<label> lst);
|
||||||
|
|
||||||
//- Remove an existing index from the edge and set its location to '-1'.
|
//- Remove an existing index from the edge and set its location to '-1'.
|
||||||
// Returns true on success. A negative label never removes.
|
// Returns the number of changes. A negative label never removes.
|
||||||
// Similar to a HashTable::erase().
|
// Similar to a HashTable::erase().
|
||||||
inline bool erase(const label index);
|
inline label erase(const label index);
|
||||||
|
|
||||||
|
//- Remove existing indices from the edge and set locations to '-1'.
|
||||||
|
// Returns the number of changes.
|
||||||
|
inline label erase(const UList<label>& lst);
|
||||||
|
|
||||||
|
//- Remove existing indices from the edge and set locations to '-1'.
|
||||||
|
// Returns the number of changes.
|
||||||
|
template<unsigned AnySize>
|
||||||
|
inline label erase(const FixedList<label, AnySize>& lst);
|
||||||
|
|
||||||
|
//- Remove existing indices from the edge and set locations to '-1'.
|
||||||
|
// Returns the number of changes.
|
||||||
|
inline label erase(std::initializer_list<label> lst);
|
||||||
|
|
||||||
|
|
||||||
//- True if the edge is sorted such that start is less-than end
|
// Geometric functions
|
||||||
inline bool sorted() const;
|
|
||||||
|
|
||||||
//- Sort start/end that start is less-than end
|
//- Return centre point (centroid) of the edge.
|
||||||
inline void sort();
|
// No special handling of negative point labels.
|
||||||
|
|
||||||
//- Flip the edge in-place.
|
|
||||||
inline void flip();
|
|
||||||
|
|
||||||
//- Return reverse edge
|
|
||||||
inline edge reverseEdge() const;
|
|
||||||
|
|
||||||
//- Return centre (centroid)
|
|
||||||
inline point centre(const UList<point>& pts) const;
|
inline point centre(const UList<point>& pts) const;
|
||||||
|
|
||||||
//- Return the vector (end - start)
|
//- Return the vector (end - start)
|
||||||
|
// No special handling of negative point labels.
|
||||||
inline vector vec(const UList<point>& pts) const;
|
inline vector vec(const UList<point>& pts) const;
|
||||||
|
|
||||||
//- Return the unit vector (end - start)
|
//- Return the unit vector (end - start)
|
||||||
|
// No special handling of negative point labels.
|
||||||
inline vector unitVec(const UList<point>& pts) const;
|
inline vector unitVec(const UList<point>& pts) const;
|
||||||
|
|
||||||
//- Return scalar magnitude
|
//- Return scalar magnitude of the edge.
|
||||||
|
// No special handling of negative point labels.
|
||||||
inline scalar mag(const UList<point>& pts) const;
|
inline scalar mag(const UList<point>& pts) const;
|
||||||
|
|
||||||
//- Return edge line
|
//- Return edge line
|
||||||
|
// No special handling of negative point labels.
|
||||||
inline linePointRef line(const UList<point>& pts) const;
|
inline linePointRef line(const UList<point>& pts) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Comparison
|
||||||
|
|
||||||
//- Compare edges
|
//- Compare edges
|
||||||
// Returns:
|
// Returns:
|
||||||
// - 0: different
|
// - 0: different
|
||||||
// - +1: identical
|
// - +1: identical values and order used
|
||||||
// - -1: same edge, but different orientation
|
// - -1: identical values, but in different order
|
||||||
static inline int compare(const edge& a, const edge& b);
|
static inline int compare(const edge& a, const edge& b);
|
||||||
|
|
||||||
|
|
||||||
// Friend Operators
|
|
||||||
|
|
||||||
friend bool operator==(const edge& a, const edge& b);
|
|
||||||
friend bool operator!=(const edge& a, const edge& b);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Global Operators
|
||||||
|
|
||||||
|
//- Compare edges for equal content, ignoring orientation
|
||||||
|
inline bool operator==(const edge& a, const edge& b);
|
||||||
|
|
||||||
|
//- Compare edges for non-equal content, ignoring orientation
|
||||||
|
inline bool operator!=(const edge& a, const edge& b);
|
||||||
|
|
||||||
|
|
||||||
//- Hash specialization for hashing edges - a commutative hash value.
|
//- Hash specialization for hashing edges - a commutative hash value.
|
||||||
// Hash incrementally.
|
// Hash incrementally.
|
||||||
template<>
|
template<>
|
||||||
|
|||||||
@ -45,6 +45,66 @@ inline int Foam::edge::compare(const edge& a, const edge& b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class InputIter>
|
||||||
|
inline Foam::label Foam::edge::insertMultiple
|
||||||
|
(
|
||||||
|
const InputIter begIter,
|
||||||
|
const InputIter endIter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Available slots.
|
||||||
|
// Don't use count() since it has special treatment for duplicates
|
||||||
|
const int maxChange = (start() < 0 ? 1 : 0) + (end() < 0 ? 1 : 0);
|
||||||
|
|
||||||
|
int changed = 0;
|
||||||
|
if (maxChange)
|
||||||
|
{
|
||||||
|
for (InputIter iter = begIter; iter != endIter; ++iter)
|
||||||
|
{
|
||||||
|
if (insert(*iter))
|
||||||
|
{
|
||||||
|
if (++changed >= maxChange)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class InputIter>
|
||||||
|
inline Foam::label Foam::edge::eraseMultiple
|
||||||
|
(
|
||||||
|
const InputIter begIter,
|
||||||
|
const InputIter endIter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Occupied slots.
|
||||||
|
// Don't use count() since it has special treatment for duplicates
|
||||||
|
const int maxChange = (start() >= 0 ? 1 : 0) + (end() >= 0 ? 1 : 0);
|
||||||
|
|
||||||
|
int changed = 0;
|
||||||
|
if (maxChange)
|
||||||
|
{
|
||||||
|
for (InputIter iter = begIter; iter != endIter; ++iter)
|
||||||
|
{
|
||||||
|
changed += erase(*iter);
|
||||||
|
if (changed >= maxChange)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline Foam::edge::edge()
|
inline Foam::edge::edge()
|
||||||
@ -75,6 +135,13 @@ inline Foam::edge::edge(const label from, const label to, const bool doSort)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::edge::edge(const labelPair& pair)
|
||||||
|
{
|
||||||
|
start() = pair.first();
|
||||||
|
end() = pair.second();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::edge::edge(const FixedList<label, 2>& lst)
|
inline Foam::edge::edge(const FixedList<label, 2>& lst)
|
||||||
{
|
{
|
||||||
start() = lst[0];
|
start() = lst[0];
|
||||||
@ -127,27 +194,40 @@ inline Foam::label& Foam::edge::end()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::edge::minVertex() const
|
||||||
|
{
|
||||||
|
return (start() < end() ? start() : end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::edge::maxVertex() const
|
||||||
|
{
|
||||||
|
return (start() > end() ? start() : end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::edge::found(const label index) const
|
inline bool Foam::edge::found(const label index) const
|
||||||
{
|
{
|
||||||
return (index == start() || index == end());
|
// -1: always false
|
||||||
|
return (index >= 0 && (index == start() || index == end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::edge::connects(const edge& other) const
|
inline bool Foam::edge::connects(const edge& other) const
|
||||||
{
|
{
|
||||||
return (other.found(this->start()) || other.found(this->end()));
|
return (other.found(start()) || other.found(end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::label Foam::edge::commonVertex(const edge& other) const
|
inline Foam::label Foam::edge::commonVertex(const edge& other) const
|
||||||
{
|
{
|
||||||
if (other.found(this->start()))
|
if (other.found(start()))
|
||||||
{
|
{
|
||||||
return this->start();
|
return start();
|
||||||
}
|
}
|
||||||
else if (other.found(this->end()))
|
else if (other.found(end()))
|
||||||
{
|
{
|
||||||
return this->end();
|
return end();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -182,12 +262,12 @@ inline Foam::label Foam::edge::collapse()
|
|||||||
// catch any '-1' (eg, if called multiple times)
|
// catch any '-1' (eg, if called multiple times)
|
||||||
|
|
||||||
label n = 2;
|
label n = 2;
|
||||||
if (start() == end() || end() == -1)
|
if (start() == end() || end() < 0)
|
||||||
{
|
{
|
||||||
end() = -1;
|
end() = -1;
|
||||||
--n;
|
--n;
|
||||||
}
|
}
|
||||||
if (start() == -1)
|
if (start() < 0)
|
||||||
{
|
{
|
||||||
--n;
|
--n;
|
||||||
}
|
}
|
||||||
@ -196,80 +276,6 @@ inline Foam::label Foam::edge::collapse()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::label Foam::edge::count() const
|
|
||||||
{
|
|
||||||
label n = 2;
|
|
||||||
if (start() == end() || end() == -1)
|
|
||||||
{
|
|
||||||
--n;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (start() == -1)
|
|
||||||
{
|
|
||||||
--n;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::edge::insert(const label index)
|
|
||||||
{
|
|
||||||
if (index < 0)
|
|
||||||
{
|
|
||||||
// Can never insert invalid point labels.
|
|
||||||
// Use direct assignment for that.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (start() == -1)
|
|
||||||
{
|
|
||||||
// Store at [0], if not duplicate of [1]
|
|
||||||
if (index != end())
|
|
||||||
{
|
|
||||||
start() = index;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (end() == -1)
|
|
||||||
{
|
|
||||||
// Store at [1], if not duplicate of [0]
|
|
||||||
if (index != start())
|
|
||||||
{
|
|
||||||
end() = index;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::edge::erase(const label index)
|
|
||||||
{
|
|
||||||
if (index < 0)
|
|
||||||
{
|
|
||||||
// Can never remove invalid point labels!
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int n = 0;
|
|
||||||
if (index == start())
|
|
||||||
{
|
|
||||||
start() = -1;
|
|
||||||
++n;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Automatically handle duplicates, should not have been there anyhow
|
|
||||||
if (index == end())
|
|
||||||
{
|
|
||||||
end() = -1;
|
|
||||||
++n;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::edge::sorted() const
|
inline bool Foam::edge::sorted() const
|
||||||
{
|
{
|
||||||
return (start() < end());
|
return (start() < end());
|
||||||
@ -297,20 +303,173 @@ inline Foam::edge Foam::edge::reverseEdge() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void Foam::edge::clear()
|
||||||
|
{
|
||||||
|
start() = -1;
|
||||||
|
end() = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::edge::count() const
|
||||||
|
{
|
||||||
|
label n = 2;
|
||||||
|
if (start() == end() || end() < 0)
|
||||||
|
{
|
||||||
|
--n;
|
||||||
|
}
|
||||||
|
if (start() < 0)
|
||||||
|
{
|
||||||
|
--n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::edge::empty() const
|
||||||
|
{
|
||||||
|
return (start() < 0 && end() < 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::edge::insert(const label index)
|
||||||
|
{
|
||||||
|
if (index < 0)
|
||||||
|
{
|
||||||
|
// Cannot insert invalid point labels (use direct assignment for that)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start() < 0)
|
||||||
|
{
|
||||||
|
// Store at [0], if not duplicate of [1]
|
||||||
|
if (index != end())
|
||||||
|
{
|
||||||
|
start() = index;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (end() < 0)
|
||||||
|
{
|
||||||
|
// Store at [1], if not duplicate of [0]
|
||||||
|
if (index != start())
|
||||||
|
{
|
||||||
|
end() = index;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::edge::insert(const UList<label>& lst)
|
||||||
|
{
|
||||||
|
return insertMultiple(lst.begin(), lst.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<unsigned AnySize>
|
||||||
|
inline Foam::label Foam::edge::insert(const FixedList<label, AnySize>& lst)
|
||||||
|
{
|
||||||
|
return insertMultiple(lst.begin(), lst.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::edge::insert(std::initializer_list<label> lst)
|
||||||
|
{
|
||||||
|
return insertMultiple(lst.begin(), lst.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::edge::erase(const label index)
|
||||||
|
{
|
||||||
|
if (index < 0)
|
||||||
|
{
|
||||||
|
// Can never remove invalid point labels!
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
label n = 0;
|
||||||
|
if (index == start())
|
||||||
|
{
|
||||||
|
start() = -1;
|
||||||
|
++n;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Automatically handle duplicates, which should not have been there anyhow
|
||||||
|
if (index == end())
|
||||||
|
{
|
||||||
|
end() = -1;
|
||||||
|
++n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::edge::erase(const UList<label>& lst)
|
||||||
|
{
|
||||||
|
return eraseMultiple(lst.begin(), lst.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<unsigned AnySize>
|
||||||
|
inline Foam::label Foam::edge::erase(const FixedList<label, AnySize>& lst)
|
||||||
|
{
|
||||||
|
return eraseMultiple(lst.begin(), lst.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::edge::erase(std::initializer_list<label> lst)
|
||||||
|
{
|
||||||
|
return eraseMultiple(lst.begin(), lst.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Geometric
|
||||||
|
|
||||||
inline Foam::point Foam::edge::centre(const UList<point>& pts) const
|
inline Foam::point Foam::edge::centre(const UList<point>& pts) const
|
||||||
{
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
if (start() < 0 || end() < 0)
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "negative point index on edge " << *this
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0.5*(pts[start()] + pts[end()]);
|
return 0.5*(pts[start()] + pts[end()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::vector Foam::edge::vec(const UList<point>& pts) const
|
inline Foam::vector Foam::edge::vec(const UList<point>& pts) const
|
||||||
{
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
if (start() < 0 || end() < 0)
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "negative point index on edge " << *this
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return pts[end()] - pts[start()];
|
return pts[end()] - pts[start()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::vector Foam::edge::unitVec(const UList<point>& pts) const
|
inline Foam::vector Foam::edge::unitVec(const UList<point>& pts) const
|
||||||
{
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
if (start() < 0 || end() < 0)
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "negative point index on edge " << *this
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Foam::vector v = pts[end()] - pts[start()];
|
Foam::vector v = pts[end()] - pts[start()];
|
||||||
v /= ::Foam::mag(v) + VSMALL;
|
v /= ::Foam::mag(v) + VSMALL;
|
||||||
|
|
||||||
@ -326,11 +485,20 @@ inline Foam::scalar Foam::edge::mag(const UList<point>& pts) const
|
|||||||
|
|
||||||
inline Foam::linePointRef Foam::edge::line(const UList<point>& pts) const
|
inline Foam::linePointRef Foam::edge::line(const UList<point>& pts) const
|
||||||
{
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
if (start() < 0 || end() < 0)
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "negative point index on edge " << *this
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return linePointRef(pts[start()], pts[end()]);
|
return linePointRef(pts[start()], pts[end()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline bool Foam::operator==(const edge& a, const edge& b)
|
inline bool Foam::operator==(const edge& a, const edge& b)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -65,8 +65,6 @@ class triFace;
|
|||||||
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
|
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
|
||||||
class DynamicList;
|
class DynamicList;
|
||||||
|
|
||||||
inline bool operator==(const face& a, const face& b);
|
|
||||||
inline bool operator!=(const face& a, const face& b);
|
|
||||||
inline Istream& operator>>(Istream& is, face& f);
|
inline Istream& operator>>(Istream& is, face& f);
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
@ -382,12 +380,6 @@ public:
|
|||||||
static bool sameVertices(const face& a, const face& b);
|
static bool sameVertices(const face& a, const face& b);
|
||||||
|
|
||||||
|
|
||||||
// Friend Operators
|
|
||||||
|
|
||||||
friend bool operator==(const face& a, const face& b);
|
|
||||||
friend bool operator!=(const face& a, const face& b);
|
|
||||||
|
|
||||||
|
|
||||||
// Istream Operator
|
// Istream Operator
|
||||||
|
|
||||||
friend Istream& operator>>(Istream& is, face& f);
|
friend Istream& operator>>(Istream& is, face& f);
|
||||||
@ -418,6 +410,11 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Global operators
|
||||||
|
inline bool operator==(const face& a, const face& b);
|
||||||
|
inline bool operator!=(const face& a, const face& b);
|
||||||
|
|
||||||
|
|
||||||
// Global functions
|
// Global functions
|
||||||
|
|
||||||
//- Find the longest edge on a face. Face point labels index into pts.
|
//- Find the longest edge on a face. Face point labels index into pts.
|
||||||
|
|||||||
@ -135,14 +135,14 @@ inline Foam::label Foam::face::nTriangles() const
|
|||||||
return size() - 2;
|
return size() - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
|
||||||
|
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline bool Foam::operator==(const face& a, const face& b)
|
inline bool Foam::operator==(const face& a, const face& b)
|
||||||
{
|
{
|
||||||
return face::compare(a,b) != 0;
|
return face::compare(a,b) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::operator!=(const face& a, const face& b)
|
inline bool Foam::operator!=(const face& a, const face& b)
|
||||||
{
|
{
|
||||||
return face::compare(a,b) == 0;
|
return face::compare(a,b) == 0;
|
||||||
|
|||||||
@ -162,8 +162,7 @@ inline Foam::Ostream& Foam::operator<<(Ostream& os, const labelledTri& t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check state of Ostream
|
// Check state of Ostream
|
||||||
os.check("Ostream& operator<<(Ostream&, const labelledTri&)");
|
os.check(FUNCTION_NAME);
|
||||||
|
|
||||||
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -229,13 +229,16 @@ public:
|
|||||||
// - -1: same face, but different orientation
|
// - -1: same face, but different orientation
|
||||||
static inline int compare(const triFace& a, const triFace& b);
|
static inline int compare(const triFace& a, const triFace& b);
|
||||||
|
|
||||||
// Friend Operators
|
|
||||||
|
|
||||||
inline friend bool operator==(const triFace& a, const triFace& b);
|
|
||||||
inline friend bool operator!=(const triFace& a, const triFace& b);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool contiguous<triFace>() {return true;}
|
||||||
|
|
||||||
|
inline bool operator==(const triFace& a, const triFace& b);
|
||||||
|
inline bool operator!=(const triFace& a, const triFace& b);
|
||||||
|
|
||||||
|
|
||||||
//- Hash specialization for hashing triFace - a commutative hash value.
|
//- Hash specialization for hashing triFace - a commutative hash value.
|
||||||
// Hash incrementally.
|
// Hash incrementally.
|
||||||
template<>
|
template<>
|
||||||
@ -260,10 +263,6 @@ inline unsigned Hash<triFace>::operator()(const triFace& t) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline bool contiguous<triFace>() {return true;}
|
|
||||||
|
|
||||||
|
|
||||||
//- Hash specialization to offset faces in ListListOps::combineOffset
|
//- Hash specialization to offset faces in ListListOps::combineOffset
|
||||||
template<>
|
template<>
|
||||||
class offsetOp<triFace>
|
class offsetOp<triFace>
|
||||||
|
|||||||
@ -377,7 +377,7 @@ inline int Foam::triFace::edgeDirection(const edge& e) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline bool Foam::operator==(const triFace& a, const triFace& b)
|
inline bool Foam::operator==(const triFace& a, const triFace& b)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -84,31 +84,18 @@ public:
|
|||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Is there a hit
|
//- Is there a hit
|
||||||
bool hit() const
|
inline bool hit() const
|
||||||
{
|
{
|
||||||
return hit_;
|
return hit_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Return hit object
|
//- Return hit object
|
||||||
label hitObject() const
|
inline label hitObject() const
|
||||||
{
|
{
|
||||||
return hitObject_;
|
return hitObject_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Friend Operators
|
|
||||||
|
|
||||||
inline friend bool operator==(const objectHit& a, const objectHit& b)
|
|
||||||
{
|
|
||||||
return (a.hit_ == b.hit_) && (a.hitObject_ == b.hitObject_);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend bool operator!=(const objectHit& a, const objectHit& b)
|
|
||||||
{
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Ostream operator
|
// Ostream operator
|
||||||
|
|
||||||
inline friend Ostream& operator<<(Ostream& os, const objectHit& obj)
|
inline friend Ostream& operator<<(Ostream& os, const objectHit& obj)
|
||||||
@ -118,6 +105,20 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Global Operators
|
||||||
|
|
||||||
|
inline bool operator==(const objectHit& a, const objectHit& b)
|
||||||
|
{
|
||||||
|
return a.hit() == b.hit() && a.hitObject() == b.hitObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool operator!=(const objectHit& a, const objectHit& b)
|
||||||
|
{
|
||||||
|
return !(a == b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|||||||
@ -487,14 +487,14 @@ void Foam::plane::writeDict(Ostream& os) const
|
|||||||
os.endBlock() << flush;
|
os.endBlock() << flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
|
||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
bool Foam::operator==(const plane& a, const plane& b)
|
bool Foam::operator==(const plane& a, const plane& b)
|
||||||
{
|
{
|
||||||
return (a.point_ == b.point_ && a.normal_ == b.normal_);
|
return (a.refPoint() == b.refPoint() && a.normal() == b.normal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::operator!=(const plane& a, const plane& b)
|
bool Foam::operator!=(const plane& a, const plane& b)
|
||||||
{
|
{
|
||||||
return !(a == b);
|
return !(a == b);
|
||||||
|
|||||||
@ -49,8 +49,6 @@ namespace Foam
|
|||||||
// Forward declaration of friend functions and operators
|
// Forward declaration of friend functions and operators
|
||||||
|
|
||||||
class plane;
|
class plane;
|
||||||
bool operator==(const plane& a, const plane& b);
|
|
||||||
bool operator!=(const plane& a, const plane& b);
|
|
||||||
Ostream& operator<<(Ostream& os, const plane& pln);
|
Ostream& operator<<(Ostream& os, const plane& pln);
|
||||||
|
|
||||||
|
|
||||||
@ -193,7 +191,7 @@ public:
|
|||||||
|
|
||||||
//- Return the cutting line between this plane and another.
|
//- Return the cutting line between this plane and another.
|
||||||
// Returned as direction vector and point line goes through.
|
// Returned as direction vector and point line goes through.
|
||||||
ray planeIntersect(const plane&) const;
|
ray planeIntersect(const plane& plane2) const;
|
||||||
|
|
||||||
//- Return the cutting point between this plane and two other planes
|
//- Return the cutting point between this plane and two other planes
|
||||||
point planePlaneIntersect
|
point planePlaneIntersect
|
||||||
@ -217,12 +215,6 @@ public:
|
|||||||
void writeDict(Ostream& os) const;
|
void writeDict(Ostream& os) const;
|
||||||
|
|
||||||
|
|
||||||
// friend Operators
|
|
||||||
|
|
||||||
friend bool operator==(const plane& a, const plane& b);
|
|
||||||
friend bool operator!=(const plane& a, const plane& b);
|
|
||||||
|
|
||||||
|
|
||||||
// IOstream Operators
|
// IOstream Operators
|
||||||
|
|
||||||
//- Write plane properties
|
//- Write plane properties
|
||||||
@ -231,6 +223,12 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Global Operators
|
||||||
|
|
||||||
|
bool operator==(const plane& a, const plane& b);
|
||||||
|
bool operator!=(const plane& a, const plane& b);
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|||||||
@ -555,24 +555,6 @@ Foam::label Foam::treeBoundBox::distanceCmp
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
bool Foam::operator==(const treeBoundBox& a, const treeBoundBox& b)
|
|
||||||
{
|
|
||||||
return operator==
|
|
||||||
(
|
|
||||||
static_cast<const boundBox&>(a),
|
|
||||||
static_cast<const boundBox&>(b)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Foam::operator!=(const treeBoundBox& a, const treeBoundBox& b)
|
|
||||||
{
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const treeBoundBox& bb)
|
Foam::Ostream& Foam::operator<<(Ostream& os, const treeBoundBox& bb)
|
||||||
|
|||||||
@ -77,10 +77,6 @@ class Random;
|
|||||||
// Forward declaration of friend functions and operators
|
// Forward declaration of friend functions and operators
|
||||||
|
|
||||||
class treeBoundBox;
|
class treeBoundBox;
|
||||||
|
|
||||||
bool operator==(const treeBoundBox& a, const treeBoundBox& b);
|
|
||||||
bool operator!=(const treeBoundBox& a, const treeBoundBox& b);
|
|
||||||
|
|
||||||
Istream& operator>>(Istream& is, treeBoundBox& bb);
|
Istream& operator>>(Istream& is, treeBoundBox& bb);
|
||||||
Ostream& operator<<(Ostream& os, const treeBoundBox& bb);
|
Ostream& operator<<(Ostream& os, const treeBoundBox& bb);
|
||||||
|
|
||||||
@ -340,12 +336,6 @@ public:
|
|||||||
inline treeBoundBox extend(Random& rndGen, const scalar s) const;
|
inline treeBoundBox extend(Random& rndGen, const scalar s) const;
|
||||||
|
|
||||||
|
|
||||||
// Friend Operators
|
|
||||||
|
|
||||||
friend bool operator==(const treeBoundBox& a, const treeBoundBox& b);
|
|
||||||
friend bool operator!=(const treeBoundBox& a, const treeBoundBox& b);
|
|
||||||
|
|
||||||
|
|
||||||
// IOstream operator
|
// IOstream operator
|
||||||
|
|
||||||
friend Istream& operator>>(Istream& is, treeBoundBox& bb);
|
friend Istream& operator>>(Istream& is, treeBoundBox& bb);
|
||||||
@ -358,6 +348,12 @@ template<>
|
|||||||
inline bool contiguous<treeBoundBox>() {return contiguous<boundBox>();}
|
inline bool contiguous<treeBoundBox>() {return contiguous<boundBox>();}
|
||||||
|
|
||||||
|
|
||||||
|
// Global Operators
|
||||||
|
|
||||||
|
inline bool operator==(const treeBoundBox& a, const treeBoundBox& b);
|
||||||
|
inline bool operator!=(const treeBoundBox& a, const treeBoundBox& b);
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|||||||
@ -343,4 +343,17 @@ inline Foam::treeBoundBox Foam::treeBoundBox::extend
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::operator==(const treeBoundBox& a, const treeBoundBox& b)
|
||||||
|
{
|
||||||
|
return static_cast<const boundBox&>(a) == static_cast<const boundBox&>(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::operator!=(const treeBoundBox& a, const treeBoundBox& b)
|
||||||
|
{
|
||||||
|
return !(a == b);
|
||||||
|
}
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -70,9 +70,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- Construct from FixedList
|
//- Construct from FixedList
|
||||||
inline Pair(const FixedList<Type, 2>& fl)
|
inline Pair(const FixedList<Type, 2>& lst)
|
||||||
:
|
:
|
||||||
FixedList<Type, 2>(fl)
|
FixedList<Type, 2>(lst)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
@ -134,18 +134,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Comparison
|
||||||
|
|
||||||
//- Compare Pairs
|
//- Compare Pairs
|
||||||
// Returning:
|
// Returns:
|
||||||
// - 0: different
|
// - 0: different
|
||||||
// - +1: identical
|
// - +1: identical values and order used
|
||||||
// - -1: same pair, but reversed order
|
// - -1: identical values, but in reversed order
|
||||||
static inline int compare(const Pair<Type>& a, const Pair<Type>& b)
|
static inline int compare(const Pair<Type>& a, const Pair<Type>& b)
|
||||||
{
|
{
|
||||||
if (a == b)
|
if (a[0] == b[0] && a[1] == b[1])
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (a == reverse(b))
|
else if (a[0] == b[1] && a[1] == b[0])
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -157,6 +159,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
Pair<Type> reverse(const Pair<Type>& p)
|
Pair<Type> reverse(const Pair<Type>& p)
|
||||||
{
|
{
|
||||||
@ -167,14 +171,14 @@ Pair<Type> reverse(const Pair<Type>& p)
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
bool operator==(const Pair<Type>& a, const Pair<Type>& b)
|
bool operator==(const Pair<Type>& a, const Pair<Type>& b)
|
||||||
{
|
{
|
||||||
return (a.first() == b.first() && a.second() == b.second());
|
return Pair<Type>::compare(a,b) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
bool operator!=(const Pair<Type>& a, const Pair<Type>& b)
|
bool operator!=(const Pair<Type>& a, const Pair<Type>& b)
|
||||||
{
|
{
|
||||||
return !(a == b);
|
return Pair<Type>::compare(a,b) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,9 @@ Class
|
|||||||
Foam::Tuple2
|
Foam::Tuple2
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A 2-tuple for storing two objects of different types.
|
A 2-tuple for storing two objects of dissimilar types.
|
||||||
|
The container is similar in purpose to std::pair, but does not expose
|
||||||
|
its members directly.
|
||||||
|
|
||||||
See also
|
See also
|
||||||
Foam::Pair for storing two objects of identical types.
|
Foam::Pair for storing two objects of identical types.
|
||||||
@ -48,10 +50,10 @@ template<class Type1, class Type2>
|
|||||||
class Tuple2;
|
class Tuple2;
|
||||||
|
|
||||||
template<class Type1, class Type2>
|
template<class Type1, class Type2>
|
||||||
inline Istream& operator>>(Istream&, Tuple2<Type1, Type2>&);
|
inline Istream& operator>>(Istream& is, Tuple2<Type1, Type2>& t2);
|
||||||
|
|
||||||
template<class Type1, class Type2>
|
template<class Type1, class Type2>
|
||||||
inline Ostream& operator<<(Ostream&, const Tuple2<Type1, Type2>&);
|
inline Ostream& operator<<(Ostream& os, const Tuple2<Type1, Type2>& t2);
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
@ -66,12 +68,20 @@ class Tuple2
|
|||||||
Type1 f_;
|
Type1 f_;
|
||||||
Type2 s_;
|
Type2 s_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
// Typedefs (cf. std::pair)
|
||||||
|
|
||||||
|
//- Type of member first, the first template parameter (Type1)
|
||||||
|
typedef Type1 first_type;
|
||||||
|
|
||||||
|
//- Type of member second, the second template parameter (Type2)
|
||||||
|
typedef Type2 second_type;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Null constructor for lists
|
//- Null constructor for lists and hashes
|
||||||
inline Tuple2()
|
inline Tuple2()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -164,6 +174,59 @@ inline bool operator!=
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type1, class Type2>
|
||||||
|
inline bool operator<
|
||||||
|
(
|
||||||
|
const Tuple2<Type1, Type2>& a,
|
||||||
|
const Tuple2<Type1, Type2>& b
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
(
|
||||||
|
a.first() < b.first()
|
||||||
|
||
|
||||||
|
(
|
||||||
|
!(b.first() < a.first())
|
||||||
|
&& a.second() < b.second()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type1, class Type2>
|
||||||
|
inline bool operator<=
|
||||||
|
(
|
||||||
|
const Tuple2<Type1, Type2>& a,
|
||||||
|
const Tuple2<Type1, Type2>& b
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return !(b < a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type1, class Type2>
|
||||||
|
inline bool operator>
|
||||||
|
(
|
||||||
|
const Tuple2<Type1, Type2>& a,
|
||||||
|
const Tuple2<Type1, Type2>& b
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return (b < a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type1, class Type2>
|
||||||
|
inline bool operator>=
|
||||||
|
(
|
||||||
|
const Tuple2<Type1, Type2>& a,
|
||||||
|
const Tuple2<Type1, Type2>& b
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return !(a < b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type1, class Type2>
|
template<class Type1, class Type2>
|
||||||
inline Istream& operator>>(Istream& is, Tuple2<Type1, Type2>& t2)
|
inline Istream& operator>>(Istream& is, Tuple2<Type1, Type2>& t2)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -25,7 +25,9 @@ Class
|
|||||||
Foam::nullObject
|
Foam::nullObject
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Singleton null-object class and instance
|
Singleton null-object class and instance.
|
||||||
|
It occupies enough space to reinterpret its content as a class with
|
||||||
|
a null pointer for its content.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
nullObjectI.H
|
nullObjectI.H
|
||||||
@ -47,20 +49,41 @@ namespace Foam
|
|||||||
|
|
||||||
class NullObject
|
class NullObject
|
||||||
{
|
{
|
||||||
|
//- Ensure it occupies enough space to reinterpret_cast to a class
|
||||||
|
// having some member data
|
||||||
|
const union
|
||||||
|
{
|
||||||
|
void* ptr;
|
||||||
|
unsigned long val;
|
||||||
|
} null;
|
||||||
|
|
||||||
//- Private constructor
|
//- Private constructor
|
||||||
NullObject()
|
NullObject()
|
||||||
|
:
|
||||||
|
null{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
NullObject(const NullObject&);
|
NullObject(const NullObject&) = delete;
|
||||||
|
|
||||||
//- Disallow default bitwise assignment
|
//- Disallow default bitwise assignment
|
||||||
void operator=(const NullObject&);
|
void operator=(const NullObject&) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//- The unique null object
|
//- The unique null object
|
||||||
static const NullObject nullObject;
|
static const NullObject nullObject;
|
||||||
|
|
||||||
|
//- A nullptr pointer content
|
||||||
|
inline const void* pointer() const
|
||||||
|
{
|
||||||
|
return null.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- A zero value content
|
||||||
|
inline unsigned long value() const
|
||||||
|
{
|
||||||
|
return null.val;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,10 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
int Foam::labelRange::debug(::Foam::debug::debugSwitch("labelRange", 0));
|
namespace Foam
|
||||||
|
{
|
||||||
|
int labelRange::debug(debug::debugSwitch("labelRange", 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
@ -49,11 +52,17 @@ void Foam::labelRange::adjust()
|
|||||||
{
|
{
|
||||||
if (start_ < 0)
|
if (start_ < 0)
|
||||||
{
|
{
|
||||||
size_ += start_;
|
if (size_ <= 0)
|
||||||
|
{
|
||||||
|
size_ = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_ += start_;
|
||||||
|
}
|
||||||
start_ = 0;
|
start_ = 0;
|
||||||
}
|
}
|
||||||
|
else if (size_ < 0)
|
||||||
if (size_ < 0)
|
|
||||||
{
|
{
|
||||||
size_ = 0;
|
size_ = 0;
|
||||||
}
|
}
|
||||||
@ -62,22 +71,21 @@ void Foam::labelRange::adjust()
|
|||||||
|
|
||||||
bool Foam::labelRange::overlaps(const labelRange& range, bool touches) const
|
bool Foam::labelRange::overlaps(const labelRange& range, bool touches) const
|
||||||
{
|
{
|
||||||
const label final = touches ? 1 : 0;
|
const label extra = touches ? 1 : 0;
|
||||||
|
|
||||||
return
|
return
|
||||||
(
|
(
|
||||||
this->size()
|
this->size() && range.size()
|
||||||
&& range.size()
|
|
||||||
&&
|
&&
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
range.first() >= this->first()
|
range.first() >= this->first()
|
||||||
&& range.first() <= this->last() + final
|
&& range.first() <= this->last() + extra
|
||||||
)
|
)
|
||||||
||
|
||
|
||||||
(
|
(
|
||||||
this->first() >= range.first()
|
this->first() >= range.first()
|
||||||
&& this->first() <= range.last() + final
|
&& this->first() <= range.last() + extra
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -91,35 +99,78 @@ Foam::labelRange Foam::labelRange::join(const labelRange& range) const
|
|||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
else if (!range.size_)
|
else if (!range.size())
|
||||||
{
|
{
|
||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
|
|
||||||
const label lower = Foam::min(this->first(), range.first());
|
const label lower = Foam::min(this->first(), range.first());
|
||||||
const label upper = Foam::max(this->last(), range.last());
|
const label upper = Foam::max(this->last(), range.last());
|
||||||
const label sz = upper - lower + 1;
|
const label total = upper+1 - lower;
|
||||||
|
// last = start+size-1
|
||||||
|
// size = last+1-start
|
||||||
|
|
||||||
return labelRange(lower, sz);
|
return labelRange(lower, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
Foam::labelRange Foam::labelRange::subset(const labelRange& range) const
|
||||||
|
|
||||||
void Foam::labelRange::operator+=(const labelRange& rhs)
|
|
||||||
{
|
{
|
||||||
if (!size_)
|
const label lower = Foam::max(this->first(), range.first());
|
||||||
{
|
const label upper = Foam::min(this->last(), range.last());
|
||||||
// trivial case
|
const label total = upper+1 - lower;
|
||||||
operator=(rhs);
|
// last = start+size-1
|
||||||
}
|
// size = last+1-start
|
||||||
else if (rhs.size_)
|
|
||||||
{
|
|
||||||
const label lower = Foam::min(this->first(), rhs.first());
|
|
||||||
const label upper = Foam::max(this->last(), rhs.last());
|
|
||||||
|
|
||||||
start_ = lower;
|
if (total > 0)
|
||||||
size_ = upper - lower + 1;
|
{
|
||||||
|
return labelRange(lower, total);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return labelRange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::labelRange Foam::labelRange::subset
|
||||||
|
(
|
||||||
|
const label start,
|
||||||
|
const label size
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
const label lower = Foam::max(this->start(), start);
|
||||||
|
const label upper = Foam::min(this->last(), start+Foam::max(0,size-1));
|
||||||
|
const label total = upper+1 - lower;
|
||||||
|
// last = start+size-1
|
||||||
|
// size = last+1-start
|
||||||
|
|
||||||
|
if (total > 0)
|
||||||
|
{
|
||||||
|
return labelRange(lower, total);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return labelRange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::labelRange Foam::labelRange::subset0(const label size) const
|
||||||
|
{
|
||||||
|
const label lower = Foam::max(this->start(), 0);
|
||||||
|
const label upper = Foam::min(this->last(), Foam::max(0,size-1));
|
||||||
|
const label total = upper+1 - lower;
|
||||||
|
// last = start+size-1
|
||||||
|
// size = last+1-start
|
||||||
|
|
||||||
|
if (total > 0)
|
||||||
|
{
|
||||||
|
return labelRange(lower, total);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return labelRange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +199,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const labelRange& range)
|
|||||||
{
|
{
|
||||||
// Write ASCII only for now
|
// Write ASCII only for now
|
||||||
os << token::BEGIN_LIST
|
os << token::BEGIN_LIST
|
||||||
<< range.start_ << token::SPACE << range.size_
|
<< range.start() << token::SPACE << range.size()
|
||||||
<< token::END_LIST;
|
<< token::END_LIST;
|
||||||
|
|
||||||
os.check("operator<<(Ostream&, const labelRange&)");
|
os.check("operator<<(Ostream&, const labelRange&)");
|
||||||
|
|||||||
@ -25,7 +25,7 @@ Class
|
|||||||
Foam::labelRange
|
Foam::labelRange
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A range of labels.
|
A range of labels defined by a start and a size.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
labelRange.C
|
labelRange.C
|
||||||
@ -65,29 +65,25 @@ public:
|
|||||||
|
|
||||||
static int debug;
|
static int debug;
|
||||||
|
|
||||||
|
// STL type definitions similar to what UList has
|
||||||
|
|
||||||
// Public classes
|
//- Type of values the range contains
|
||||||
|
typedef label value_type;
|
||||||
|
|
||||||
//- Less function class for sorting labelRange
|
//- The type that can represent the difference between two iterators
|
||||||
class less
|
typedef label difference_type;
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bool operator()(const labelRange& a, const labelRange& b)
|
//- The type that can represent the size of the range
|
||||||
{
|
typedef label size_type;
|
||||||
return a.operator<(b);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct an empty range with zero as start and size.
|
//- An empty range with zero for start/size.
|
||||||
inline labelRange();
|
inline labelRange();
|
||||||
|
|
||||||
//- Construct a range from start and size.
|
//- Construct a range from start and size, enforcing non-negative size.
|
||||||
// Optionally adjust the start to avoid any negative indices.
|
// Optionally adjust the start to avoid any negative indices.
|
||||||
// Always reduce a negative size to zero.
|
|
||||||
inline labelRange
|
inline labelRange
|
||||||
(
|
(
|
||||||
const label start,
|
const label start,
|
||||||
@ -101,12 +97,21 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Alias for setSize(const label)
|
//- Adjust start position
|
||||||
inline void resize(const label n);
|
inline void setStart(const label i);
|
||||||
|
|
||||||
//- Adjust size
|
//- Adjust size
|
||||||
inline void setSize(const label n);
|
inline void setSize(const label n);
|
||||||
|
|
||||||
|
//- Alias for setSize()
|
||||||
|
inline void resize(const label n);
|
||||||
|
|
||||||
|
//- Decrease the size by 1, but never below 0.
|
||||||
|
inline void decrement();
|
||||||
|
|
||||||
|
//- Increase the size by 1.
|
||||||
|
inline void increment();
|
||||||
|
|
||||||
//- Reset to zero start and zero size
|
//- Reset to zero start and zero size
|
||||||
inline void clear();
|
inline void clear();
|
||||||
|
|
||||||
@ -116,21 +121,29 @@ public:
|
|||||||
//- Adjust the start to avoid any negative indices
|
//- Adjust the start to avoid any negative indices
|
||||||
void adjust();
|
void adjust();
|
||||||
|
|
||||||
//- Is the range valid (non-empty)?
|
//- Is the range non-empty?
|
||||||
inline bool valid() const;
|
inline bool valid() const;
|
||||||
|
|
||||||
//- Return the effective size of the range
|
//- The (inclusive) lower value of the range
|
||||||
|
inline label start() const;
|
||||||
|
|
||||||
|
//- The effective size of the range
|
||||||
inline label size() const;
|
inline label size() const;
|
||||||
|
|
||||||
//- The (inclusive) lower value of the range
|
//- The (inclusive) lower value of the range - same as start
|
||||||
inline label first() const;
|
inline label first() const;
|
||||||
|
|
||||||
//- The (inclusive) upper value of the range
|
//- The (inclusive) upper value of the range
|
||||||
inline label last() const;
|
inline label last() const;
|
||||||
|
|
||||||
//- Reset start and size.
|
//- The value before the start of the range
|
||||||
|
inline label before() const;
|
||||||
|
|
||||||
|
//- The value after the last element in the range
|
||||||
|
inline label after() const;
|
||||||
|
|
||||||
|
//- Reset start and size, enforcing non-negative size.
|
||||||
// Optionally adjust the start to avoid any negative indices.
|
// Optionally adjust the start to avoid any negative indices.
|
||||||
// Always reduce a negative size to zero.
|
|
||||||
// Return true if the updated range valid (non-empty).
|
// Return true if the updated range valid (non-empty).
|
||||||
inline bool reset
|
inline bool reset
|
||||||
(
|
(
|
||||||
@ -139,8 +152,8 @@ public:
|
|||||||
const bool adjustStart = false
|
const bool adjustStart = false
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Return true if the value is within the range
|
//- Return true if the value is located the range
|
||||||
inline bool contains(const label value) const;
|
inline bool found(const label value) const;
|
||||||
|
|
||||||
//- Return true if the ranges overlap.
|
//- Return true if the ranges overlap.
|
||||||
// Optional test for ranges that also just touch each other
|
// Optional test for ranges that also just touch each other
|
||||||
@ -150,73 +163,76 @@ public:
|
|||||||
// A prior overlaps() check can be used to avoid squashing gaps.
|
// A prior overlaps() check can be used to avoid squashing gaps.
|
||||||
labelRange join(const labelRange& range) const;
|
labelRange join(const labelRange& range) const;
|
||||||
|
|
||||||
|
//- Calculate the intersection of the range with another.
|
||||||
|
// If there is no intersection, it returns an empty range with zero
|
||||||
|
// for start/size.
|
||||||
|
labelRange subset(const labelRange& range) const;
|
||||||
|
|
||||||
|
//- Calculate the intersection with the given start/size range.
|
||||||
|
// If there is no intersection, it returns an empty range with zero
|
||||||
|
// for start/size.
|
||||||
|
labelRange subset(const label start, const label size) const;
|
||||||
|
|
||||||
|
//- Calculate the intersection with the given 0/size range.
|
||||||
|
// If there is no intersection, it returns an empty range with zero
|
||||||
|
// for start/size.
|
||||||
|
labelRange subset0(const label size) const;
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Return element in range, no bounds checking
|
//- Return element in the range, no bounds checking
|
||||||
inline label operator[](const label i) const;
|
inline label operator[](const label localIndex) const;
|
||||||
|
|
||||||
//- Comparison function for sorting, compares the start.
|
//- Increase the size by 1.
|
||||||
// If the start values are equal, also compares the size.
|
inline label operator++();
|
||||||
inline bool operator<(const labelRange& rhs) const;
|
inline label operator++(int);
|
||||||
|
|
||||||
//- Join ranges, squashing any gaps in between
|
//- Decrease the size by 1, but never below 0.
|
||||||
// A prior overlaps() check can be used to avoid squashing gaps.
|
inline label operator--();
|
||||||
void operator+=(const labelRange& rhs);
|
inline label operator--(int);
|
||||||
|
|
||||||
inline bool operator==(const labelRange& rhs) const;
|
|
||||||
inline bool operator!=(const labelRange& rhs) const;
|
|
||||||
|
|
||||||
|
|
||||||
// STL iterator
|
// STL iterator
|
||||||
|
|
||||||
//- An STL const_iterator
|
//- Forward iterator with const access
|
||||||
class const_iterator
|
class const_iterator
|
||||||
{
|
{
|
||||||
friend class labelRange;
|
//- The current label (not the local index)
|
||||||
|
label index_;
|
||||||
// Private data
|
|
||||||
|
|
||||||
//- Reference to the range for which this is an iterator
|
|
||||||
const labelRange& range_;
|
|
||||||
|
|
||||||
//- Current index
|
|
||||||
label index_;
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Construct from range at 'begin' or 'end' position
|
|
||||||
inline const_iterator
|
|
||||||
(
|
|
||||||
const labelRange& range,
|
|
||||||
const bool endIter = false
|
|
||||||
);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Member operators
|
// Constructors
|
||||||
|
|
||||||
inline bool operator==(const const_iterator& iter) const;
|
//- Construct from range at given local index.
|
||||||
inline bool operator!=(const const_iterator& iter) const;
|
// A negative index signals the 'end' position
|
||||||
|
inline const_iterator(const labelRange* range, const label i = 0);
|
||||||
|
|
||||||
inline label operator*() const;
|
// Member operators
|
||||||
inline label operator()() const;
|
|
||||||
|
|
||||||
inline const_iterator& operator++();
|
//- Return the current label
|
||||||
inline const_iterator operator++(int);
|
inline label operator*() const;
|
||||||
|
|
||||||
|
inline const_iterator& operator++();
|
||||||
|
inline const_iterator operator++(int);
|
||||||
|
|
||||||
|
inline bool operator==(const const_iterator& iter) const;
|
||||||
|
inline bool operator!=(const const_iterator& iter) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//- A const_iterator set to the beginning of the range
|
//- A const_iterator set to the beginning of the range
|
||||||
|
// The value returned is guaranteed to be the same as start()
|
||||||
|
inline const_iterator begin() const;
|
||||||
|
|
||||||
|
//- A const_iterator set to the beginning of the range
|
||||||
|
// The value returned is guaranteed to be the same as start()
|
||||||
inline const_iterator cbegin() const;
|
inline const_iterator cbegin() const;
|
||||||
|
|
||||||
//- A const_iterator set to beyond the end of the range
|
//- A const_iterator set to beyond the end of the range
|
||||||
inline const const_iterator cend() const;
|
inline const const_iterator cend() const;
|
||||||
|
|
||||||
//- A const_iterator set to the beginning of the range
|
|
||||||
inline const_iterator begin() const;
|
|
||||||
|
|
||||||
//- A const_iterator set to beyond the end of the range
|
//- A const_iterator set to beyond the end of the range
|
||||||
inline const const_iterator end() const;
|
inline const const_iterator end() const;
|
||||||
|
|
||||||
@ -229,6 +245,51 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Global Operators
|
||||||
|
|
||||||
|
inline bool operator==(const labelRange& a, const labelRange& b)
|
||||||
|
{
|
||||||
|
return (a.first() == b.first() && a.size() == b.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator!=(const labelRange& a, const labelRange& b)
|
||||||
|
{
|
||||||
|
return !(a == b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Comparison function for sorting, compares the start.
|
||||||
|
// If the start values are equal, also compares the size.
|
||||||
|
inline bool operator<(const labelRange& a, const labelRange& b)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
(
|
||||||
|
a.first() < b.first()
|
||||||
|
||
|
||||||
|
(
|
||||||
|
!(b.first() < a.first())
|
||||||
|
&& a.size() < b.size()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator<=(const labelRange& a, const labelRange& b)
|
||||||
|
{
|
||||||
|
return !(b < a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool operator>(const labelRange& a, const labelRange& b)
|
||||||
|
{
|
||||||
|
return (b < a);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator>=(const labelRange& a, const labelRange& b)
|
||||||
|
{
|
||||||
|
return !(a < b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|||||||
@ -60,42 +60,21 @@ inline Foam::labelRange::labelRange
|
|||||||
|
|
||||||
inline Foam::labelRange::const_iterator::const_iterator
|
inline Foam::labelRange::const_iterator::const_iterator
|
||||||
(
|
(
|
||||||
const labelRange& range,
|
const labelRange* range,
|
||||||
const bool endIter
|
const label i
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
range_(range),
|
index_
|
||||||
index_(endIter ? range_.size() : 0)
|
(
|
||||||
|
range->start()
|
||||||
|
+ ((i < 0 || i > range->size()) ? range->size() : i)
|
||||||
|
)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::labelRange::const_iterator::operator==
|
|
||||||
(
|
|
||||||
const const_iterator& iter
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
return (this->index_ == iter.index_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::labelRange::const_iterator::operator!=
|
|
||||||
(
|
|
||||||
const const_iterator& iter
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
return (this->index_ != iter.index_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline Foam::label Foam::labelRange::const_iterator::operator*() const
|
inline Foam::label Foam::labelRange::const_iterator::operator*() const
|
||||||
{
|
{
|
||||||
return range_[index_];
|
return index_;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline Foam::label Foam::labelRange::const_iterator::operator()() const
|
|
||||||
{
|
|
||||||
return range_[index_];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -116,46 +95,79 @@ Foam::labelRange::const_iterator::operator++(int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::labelRange::const_iterator Foam::labelRange::cbegin() const
|
inline bool Foam::labelRange::const_iterator::operator==
|
||||||
|
(
|
||||||
|
const const_iterator& iter
|
||||||
|
) const
|
||||||
{
|
{
|
||||||
return const_iterator(*this);
|
return (this->index_ == iter.index_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::labelRange::const_iterator Foam::labelRange::cend() const
|
inline bool Foam::labelRange::const_iterator::operator!=
|
||||||
|
(
|
||||||
|
const const_iterator& iter
|
||||||
|
) const
|
||||||
{
|
{
|
||||||
return const_iterator(*this, true);
|
return (this->index_ != iter.index_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::labelRange::const_iterator Foam::labelRange::begin() const
|
inline Foam::labelRange::const_iterator Foam::labelRange::begin() const
|
||||||
{
|
{
|
||||||
return const_iterator(*this);
|
return const_iterator(this, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::labelRange::const_iterator Foam::labelRange::cbegin() const
|
||||||
|
{
|
||||||
|
return const_iterator(this, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::labelRange::const_iterator Foam::labelRange::end() const
|
inline const Foam::labelRange::const_iterator Foam::labelRange::end() const
|
||||||
{
|
{
|
||||||
return const_iterator(*this, true);
|
return const_iterator(this, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline const Foam::labelRange::const_iterator Foam::labelRange::cend() const
|
||||||
|
{
|
||||||
|
return const_iterator(this, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline void Foam::labelRange::setStart(const label i)
|
||||||
|
{
|
||||||
|
start_ = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void Foam::labelRange::setSize(const label n)
|
||||||
|
{
|
||||||
|
size_ = n;
|
||||||
|
if (size_ < 0) size_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::labelRange::resize(const label n)
|
inline void Foam::labelRange::resize(const label n)
|
||||||
{
|
{
|
||||||
setSize(n);
|
setSize(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::labelRange::setSize(const label n)
|
inline void Foam::labelRange::decrement()
|
||||||
{
|
{
|
||||||
size_ = n;
|
--size_;
|
||||||
|
if (size_ < 0) size_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (size_ < 0)
|
|
||||||
{
|
inline void Foam::labelRange::increment()
|
||||||
size_ = 0;
|
{
|
||||||
}
|
++size_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -183,6 +195,12 @@ inline Foam::label Foam::labelRange::size() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::labelRange::start() const
|
||||||
|
{
|
||||||
|
return start_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::label Foam::labelRange::first() const
|
inline Foam::label Foam::labelRange::first() const
|
||||||
{
|
{
|
||||||
return start_;
|
return start_;
|
||||||
@ -195,6 +213,18 @@ inline Foam::label Foam::labelRange::last() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::labelRange::before() const
|
||||||
|
{
|
||||||
|
return start_ - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::labelRange::after() const
|
||||||
|
{
|
||||||
|
return start_ + size_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::labelRange::reset
|
inline bool Foam::labelRange::reset
|
||||||
(
|
(
|
||||||
const label start,
|
const label start,
|
||||||
@ -220,39 +250,44 @@ inline bool Foam::labelRange::reset
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::labelRange::contains(const label value) const
|
inline bool Foam::labelRange::found(const label value) const
|
||||||
{
|
{
|
||||||
return value >= this->first() && value <= this->last();
|
return (value >= this->first() && value <= this->last());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline Foam::label Foam::labelRange::operator[](const label i) const
|
inline Foam::label Foam::labelRange::operator[](const label localIndex) const
|
||||||
{
|
{
|
||||||
return start_ + i;
|
return start_ + localIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::labelRange::operator<(const labelRange& rhs) const
|
inline Foam::label Foam::labelRange::operator++()
|
||||||
{
|
{
|
||||||
return
|
return ++size_;
|
||||||
(
|
|
||||||
this->first() < rhs.first()
|
|
||||||
|| (this->first() == rhs.first() && this->size() < rhs.size())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::labelRange::operator==(const labelRange& rhs) const
|
inline Foam::label Foam::labelRange::operator++(int)
|
||||||
{
|
{
|
||||||
return start_ == rhs.start_ && size_ == rhs.size_;
|
return size_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::labelRange::operator!=(const labelRange& rhs) const
|
inline Foam::label Foam::labelRange::operator--()
|
||||||
{
|
{
|
||||||
return !(operator==(rhs));
|
decrement();
|
||||||
|
return size_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::labelRange::operator--(int)
|
||||||
|
{
|
||||||
|
const label old = size_;
|
||||||
|
decrement();
|
||||||
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,7 @@ void Foam::labelRanges::insertBefore
|
|||||||
<< *this << endl;
|
<< *this << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParentType::setSize(nElem+1);
|
StorageContainer::setSize(nElem+1);
|
||||||
|
|
||||||
if (labelRange::debug)
|
if (labelRange::debug)
|
||||||
{
|
{
|
||||||
@ -58,7 +58,7 @@ void Foam::labelRanges::insertBefore
|
|||||||
Info<<"copy from " << (i) << " to " << (i+1) << nl;
|
Info<<"copy from " << (i) << " to " << (i+1) << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParentType::operator[](i+1) = ParentType::operator[](i);
|
StorageContainer::operator[](i+1) = StorageContainer::operator[](i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally insert the range
|
// finally insert the range
|
||||||
@ -66,7 +66,7 @@ void Foam::labelRanges::insertBefore
|
|||||||
{
|
{
|
||||||
Info<< "finally insert the range at " << insert << nl;
|
Info<< "finally insert the range at " << insert << nl;
|
||||||
}
|
}
|
||||||
ParentType::operator[](insert) = range;
|
StorageContainer::operator[](insert) = range;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -76,18 +76,19 @@ void Foam::labelRanges::purgeEmpty()
|
|||||||
label nElem = 0;
|
label nElem = 0;
|
||||||
forAll(*this, elemI)
|
forAll(*this, elemI)
|
||||||
{
|
{
|
||||||
if (!ParentType::operator[](elemI).empty())
|
if (!StorageContainer::operator[](elemI).empty())
|
||||||
{
|
{
|
||||||
if (nElem != elemI)
|
if (nElem != elemI)
|
||||||
{
|
{
|
||||||
ParentType::operator[](nElem) = ParentType::operator[](elemI);
|
StorageContainer::operator[](nElem) =
|
||||||
|
StorageContainer::operator[](elemI);
|
||||||
}
|
}
|
||||||
++nElem;
|
++nElem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// truncate
|
// truncate
|
||||||
this->ParentType::setSize(nElem);
|
this->StorageContainer::setSize(nElem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -134,20 +135,20 @@ bool Foam::labelRanges::add(const labelRange& range)
|
|||||||
// find the correct place for insertion
|
// find the correct place for insertion
|
||||||
forAll(*this, elemI)
|
forAll(*this, elemI)
|
||||||
{
|
{
|
||||||
labelRange& currRange = ParentType::operator[](elemI);
|
labelRange& currRange = StorageContainer::operator[](elemI);
|
||||||
|
|
||||||
if (currRange.overlaps(range, true))
|
if (currRange.overlaps(range, true))
|
||||||
{
|
{
|
||||||
// absorb into the existing (adjacent/overlapping) range
|
// absorb into the existing (adjacent/overlapping) range
|
||||||
currRange += range;
|
currRange.join(range);
|
||||||
|
|
||||||
// might connect with the next following range(s)
|
// might connect with the next following range(s)
|
||||||
for (; elemI < this->size()-1; ++elemI)
|
for (; elemI < this->size()-1; ++elemI)
|
||||||
{
|
{
|
||||||
labelRange& nextRange = ParentType::operator[](elemI+1);
|
labelRange& nextRange = StorageContainer::operator[](elemI+1);
|
||||||
if (currRange.overlaps(nextRange, true))
|
if (currRange.overlaps(nextRange, true))
|
||||||
{
|
{
|
||||||
currRange += nextRange;
|
currRange.join(nextRange);
|
||||||
nextRange.clear();
|
nextRange.clear();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -187,7 +188,7 @@ bool Foam::labelRanges::remove(const labelRange& range)
|
|||||||
|
|
||||||
forAll(*this, elemI)
|
forAll(*this, elemI)
|
||||||
{
|
{
|
||||||
labelRange& currRange = ParentType::operator[](elemI);
|
labelRange& currRange = StorageContainer::operator[](elemI);
|
||||||
|
|
||||||
if (range.first() > currRange.first())
|
if (range.first() > currRange.first())
|
||||||
{
|
{
|
||||||
@ -290,14 +291,14 @@ bool Foam::labelRanges::remove(const labelRange& range)
|
|||||||
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, labelRanges& ranges)
|
Foam::Istream& Foam::operator>>(Istream& is, labelRanges& ranges)
|
||||||
{
|
{
|
||||||
is >> static_cast<labelRanges::ParentType&>(ranges);
|
is >> static_cast<labelRanges::StorageContainer&>(ranges);
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const labelRanges& ranges)
|
Foam::Ostream& Foam::operator<<(Ostream& os, const labelRanges& ranges)
|
||||||
{
|
{
|
||||||
os << static_cast<const labelRanges::ParentType&>(ranges);
|
os << static_cast<const labelRanges::StorageContainer&>(ranges);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -62,7 +62,7 @@ class labelRanges
|
|||||||
{
|
{
|
||||||
// Private typedefs for convenience
|
// Private typedefs for convenience
|
||||||
|
|
||||||
typedef DynamicList<labelRange> ParentType;
|
typedef DynamicList<labelRange> StorageContainer;
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
@ -99,8 +99,8 @@ public:
|
|||||||
//- Return true if the list is empty
|
//- Return true if the list is empty
|
||||||
using DynamicList<labelRange>::empty;
|
using DynamicList<labelRange>::empty;
|
||||||
|
|
||||||
//- Return true if the value is within any of the ranges
|
//- Return true if the value is found any of the sub-ranges
|
||||||
inline bool contains(const label value) const;
|
inline bool found(const label value) const;
|
||||||
|
|
||||||
//- Add the range to the list
|
//- Add the range to the list
|
||||||
bool add(const labelRange& range);
|
bool add(const labelRange& range);
|
||||||
@ -116,38 +116,35 @@ public:
|
|||||||
{
|
{
|
||||||
friend class labelRanges;
|
friend class labelRanges;
|
||||||
|
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Reference to the list for which this is an iterator
|
//- Reference to the list for which this is an iterator
|
||||||
const labelRanges& list_;
|
const labelRanges* list_;
|
||||||
|
|
||||||
//- Current list index
|
//- Current list-index
|
||||||
label index_;
|
label index_;
|
||||||
|
|
||||||
//- Index of current element at listIndex
|
//- Index of current element at list-index
|
||||||
label subIndex_;
|
label subIndex_;
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from ranges at 'begin' or 'end' position
|
//- Construct from ranges at given index.
|
||||||
inline const_iterator
|
// A negative index signals the 'end' position
|
||||||
(
|
inline const_iterator(const labelRanges* lst, const label i);
|
||||||
const labelRanges& lst,
|
|
||||||
const bool endIter = false
|
|
||||||
);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
inline bool operator==(const const_iterator& iter) const;
|
inline bool operator==(const const_iterator& iter) const;
|
||||||
inline bool operator!=(const const_iterator& iter) const;
|
inline bool operator!=(const const_iterator& iter) const;
|
||||||
|
|
||||||
inline label operator*();
|
//- Return the current label
|
||||||
inline label operator()();
|
inline label operator*();
|
||||||
|
|
||||||
inline const_iterator& operator++();
|
inline const_iterator& operator++();
|
||||||
inline const_iterator operator++(int);
|
inline const_iterator operator++(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -28,13 +28,13 @@ License
|
|||||||
|
|
||||||
inline Foam::labelRanges::labelRanges()
|
inline Foam::labelRanges::labelRanges()
|
||||||
:
|
:
|
||||||
ParentType()
|
StorageContainer()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::labelRanges::labelRanges(const label nElem)
|
inline Foam::labelRanges::labelRanges(const label nElem)
|
||||||
:
|
:
|
||||||
ParentType(nElem)
|
StorageContainer(nElem)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -42,12 +42,12 @@ inline Foam::labelRanges::labelRanges(const label nElem)
|
|||||||
|
|
||||||
inline Foam::labelRanges::const_iterator::const_iterator
|
inline Foam::labelRanges::const_iterator::const_iterator
|
||||||
(
|
(
|
||||||
const labelRanges& lst,
|
const labelRanges* lst,
|
||||||
const bool endIter
|
const label i
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
list_(lst),
|
list_(lst),
|
||||||
index_(endIter ? lst.size() : 0),
|
index_(i < 0 ? lst->size() : i),
|
||||||
subIndex_(0)
|
subIndex_(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -76,20 +76,14 @@ inline bool Foam::labelRanges::const_iterator::operator!=
|
|||||||
|
|
||||||
inline Foam::label Foam::labelRanges::const_iterator::operator*()
|
inline Foam::label Foam::labelRanges::const_iterator::operator*()
|
||||||
{
|
{
|
||||||
return list_[index_][subIndex_];
|
return list_->operator[](index_)[subIndex_];
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline Foam::label Foam::labelRanges::const_iterator::operator()()
|
|
||||||
{
|
|
||||||
return list_[index_][subIndex_];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::labelRanges::const_iterator&
|
inline Foam::labelRanges::const_iterator&
|
||||||
Foam::labelRanges::const_iterator::operator++()
|
Foam::labelRanges::const_iterator::operator++()
|
||||||
{
|
{
|
||||||
if (++subIndex_ >= list_[index_].size())
|
if (++subIndex_ >= list_->operator[](index_).size())
|
||||||
{
|
{
|
||||||
// Next sub-list
|
// Next sub-list
|
||||||
++index_;
|
++index_;
|
||||||
@ -111,35 +105,35 @@ Foam::labelRanges::const_iterator::operator++(int)
|
|||||||
|
|
||||||
inline Foam::labelRanges::const_iterator Foam::labelRanges::cbegin() const
|
inline Foam::labelRanges::const_iterator Foam::labelRanges::cbegin() const
|
||||||
{
|
{
|
||||||
return const_iterator(*this);
|
return const_iterator(this, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::labelRanges::const_iterator Foam::labelRanges::cend() const
|
inline const Foam::labelRanges::const_iterator Foam::labelRanges::cend() const
|
||||||
{
|
{
|
||||||
return const_iterator(*this, true);
|
return const_iterator(this, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::labelRanges::const_iterator Foam::labelRanges::begin() const
|
inline Foam::labelRanges::const_iterator Foam::labelRanges::begin() const
|
||||||
{
|
{
|
||||||
return const_iterator(*this);
|
return const_iterator(this, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::labelRanges::const_iterator Foam::labelRanges::end() const
|
inline const Foam::labelRanges::const_iterator Foam::labelRanges::end() const
|
||||||
{
|
{
|
||||||
return const_iterator(*this, true);
|
return const_iterator(this, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline bool Foam::labelRanges::contains(const label value) const
|
inline bool Foam::labelRanges::found(const label value) const
|
||||||
{
|
{
|
||||||
forAll(*this, i)
|
forAll(*this, i)
|
||||||
{
|
{
|
||||||
if (this->ParentType::operator[](i).contains(value))
|
if (StorageContainer::operator[](i).found(value))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,10 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
int Foam::scalarRange::debug(::Foam::debug::debugSwitch("scalarRange", 0));
|
namespace Foam
|
||||||
|
{
|
||||||
|
int scalarRange::debug(debug::debugSwitch("scalarRange", 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
@ -47,11 +50,9 @@ Foam::scalarRange::scalarRange(const scalar lower, const scalar upper)
|
|||||||
value_(lower),
|
value_(lower),
|
||||||
value2_(upper)
|
value2_(upper)
|
||||||
{
|
{
|
||||||
// mark invalid range as empty
|
|
||||||
if (lower > upper)
|
if (lower > upper)
|
||||||
{
|
{
|
||||||
type_ = EMPTY;
|
clear(); // Mark invalid range as empty
|
||||||
value_ = value2_ = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +74,14 @@ Foam::scalarRange::scalarRange(Istream& is)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::scalarRange::clear()
|
||||||
|
{
|
||||||
|
type_ = scalarRange::EMPTY;
|
||||||
|
value_ = 0;
|
||||||
|
value2_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::scalarRange::empty() const
|
bool Foam::scalarRange::empty() const
|
||||||
{
|
{
|
||||||
return type_ == EMPTY;
|
return type_ == EMPTY;
|
||||||
@ -210,15 +219,14 @@ Foam::Istream& Foam::operator>>(Istream& is, scalarRange& range)
|
|||||||
// a number is now required
|
// a number is now required
|
||||||
if (!toks[nTok-1].isNumber())
|
if (!toks[nTok-1].isNumber())
|
||||||
{
|
{
|
||||||
is.setBad();
|
range.clear(); // Mark invalid range as empty
|
||||||
range.type_ = scalarRange::EMPTY;
|
|
||||||
range.value_ = range.value2_ = 0;
|
|
||||||
Info<< "rejected ill-formed or empty range:";
|
Info<< "rejected ill-formed or empty range:";
|
||||||
for (label i=0; i<nTok; ++i)
|
for (label i=0; i<nTok; ++i)
|
||||||
{
|
{
|
||||||
Info<< " " << toks[i];
|
Info<< " " << toks[i];
|
||||||
}
|
}
|
||||||
Info<< endl;
|
Info<< endl;
|
||||||
|
is.setBad();
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,15 +253,14 @@ Foam::Istream& Foam::operator>>(Istream& is, scalarRange& range)
|
|||||||
{
|
{
|
||||||
if (range.type_ == scalarRange::UPPER)
|
if (range.type_ == scalarRange::UPPER)
|
||||||
{
|
{
|
||||||
is.setBad();
|
range.clear(); // Mark invalid range as empty
|
||||||
range.type_ = scalarRange::EMPTY;
|
|
||||||
range.value_ = range.value2_ = 0;
|
|
||||||
Info<< "rejected ill-formed range:";
|
Info<< "rejected ill-formed range:";
|
||||||
for (label i=0; i<nTok; ++i)
|
for (label i=0; i<nTok; ++i)
|
||||||
{
|
{
|
||||||
Info<< " " << toks[i];
|
Info<< " " << toks[i];
|
||||||
}
|
}
|
||||||
Info<< endl;
|
Info<< endl;
|
||||||
|
is.setBad();
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,16 +315,15 @@ Foam::Istream& Foam::operator>>(Istream& is, scalarRange& range)
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
is.setBad();
|
range.clear(); // Mark invalid range as empty
|
||||||
range.type_ = scalarRange::EMPTY;
|
|
||||||
range.value_ = range.value2_ = 0;
|
|
||||||
|
|
||||||
Info<< "rejected ill-formed range:";
|
Info<< "rejected ill-formed range:";
|
||||||
for (label i=0; i<nTok; ++i)
|
for (label i=0; i<nTok; ++i)
|
||||||
{
|
{
|
||||||
Info<< " " << toks[i];
|
Info<< " " << toks[i];
|
||||||
}
|
}
|
||||||
Info<< endl;
|
Info<< endl;
|
||||||
|
is.setBad();
|
||||||
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
return is;
|
return is;
|
||||||
|
|||||||
@ -52,8 +52,8 @@ class Ostream;
|
|||||||
|
|
||||||
// Forward declaration of friend functions and operators
|
// Forward declaration of friend functions and operators
|
||||||
class scalarRange;
|
class scalarRange;
|
||||||
Istream& operator>>(Istream&, scalarRange&);
|
Istream& operator>>(Istream& is, scalarRange& range);
|
||||||
Ostream& operator<<(Ostream&, const scalarRange&);
|
Ostream& operator<<(Ostream& os, const scalarRange& range);
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
@ -73,7 +73,7 @@ class scalarRange
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Private data
|
// Private Member Data
|
||||||
|
|
||||||
enum rangeType type_;
|
enum rangeType type_;
|
||||||
scalar value_;
|
scalar value_;
|
||||||
@ -96,11 +96,14 @@ public:
|
|||||||
//- Construct from Istream.
|
//- Construct from Istream.
|
||||||
// Since commas can be used as list delimiters,
|
// Since commas can be used as list delimiters,
|
||||||
// leading and trailing commas are ignored.
|
// leading and trailing commas are ignored.
|
||||||
scalarRange(Istream&);
|
scalarRange(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
|
//- Reset to an empty range.
|
||||||
|
void clear();
|
||||||
|
|
||||||
//- Is the range empty?
|
//- Is the range empty?
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
|
|
||||||
@ -121,19 +124,19 @@ public:
|
|||||||
scalar upper() const;
|
scalar upper() const;
|
||||||
|
|
||||||
//- Return true if the value is within the range
|
//- Return true if the value is within the range
|
||||||
bool selected(const scalar) const;
|
bool selected(const scalar value) const;
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
bool operator==(const scalarRange&) const;
|
bool operator==(const scalarRange& range) const;
|
||||||
bool operator!=(const scalarRange&) const;
|
bool operator!=(const scalarRange& range) const;
|
||||||
|
|
||||||
|
|
||||||
// IOstream Operators
|
// IOstream Operators
|
||||||
|
|
||||||
friend Istream& operator>>(Istream&, scalarRange&);
|
friend Istream& operator>>(Istream& is, scalarRange& range);
|
||||||
friend Ostream& operator<<(Ostream&, const scalarRange&);
|
friend Ostream& operator<<(Ostream& os, const scalarRange& range);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -72,7 +72,7 @@ bool Foam::scalarRanges::selected(const scalar value) const
|
|||||||
|
|
||||||
Foam::List<bool> Foam::scalarRanges::selected
|
Foam::List<bool> Foam::scalarRanges::selected
|
||||||
(
|
(
|
||||||
const List<scalar>& values
|
const UList<scalar>& values
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
List<bool> lst(values.size(), false);
|
List<bool> lst(values.size(), false);
|
||||||
|
|||||||
@ -55,27 +55,28 @@ public:
|
|||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct Null
|
//- Construct null
|
||||||
scalarRanges();
|
scalarRanges();
|
||||||
|
|
||||||
//- Construct from Istream.
|
//- Construct from Istream.
|
||||||
// The list items are comma-delimited.
|
// The list items are comma-delimited.
|
||||||
scalarRanges(Istream&);
|
scalarRanges(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Return true if the given value is within the ranges
|
//- Return true if the given value is within the ranges
|
||||||
bool selected(const scalar) const;
|
bool selected(const scalar value) const;
|
||||||
|
|
||||||
//- Return the set of selected entries in the given list
|
//- Return the set of selected entries in the given list
|
||||||
// that are within the ranges
|
// that are within the ranges
|
||||||
List<bool> selected(const List<scalar>&) const;
|
List<bool> selected(const UList<scalar>& values) const;
|
||||||
|
|
||||||
//- Select a list of values that are within the ranges
|
//- Select a list of values that are within the ranges
|
||||||
List<scalar> select(const List<scalar>&) const;
|
List<scalar> select(const List<scalar>& values) const;
|
||||||
|
|
||||||
//- Select a list of values that are within the ranges
|
//- Select a list of values that are within the ranges
|
||||||
void inplaceSelect(List<scalar>&) const;
|
void inplaceSelect(List<scalar>& values) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -68,28 +68,28 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
// Access
|
// Access
|
||||||
|
|
||||||
inline label size() const;
|
inline label size() const;
|
||||||
inline bool empty() const;
|
inline bool empty() const;
|
||||||
|
|
||||||
//- Return underlying list of wordRe
|
//- Return underlying list of wordRe
|
||||||
inline const UList<wordRe>& operator()() const;
|
inline const UList<wordRe>& operator()() const;
|
||||||
|
|
||||||
|
|
||||||
// Searching
|
// Searching
|
||||||
|
|
||||||
//- Return true if string matches any of the regular expressions
|
//- Return true if string matches any of the regular expressions
|
||||||
// Smart match as regular expression or as a string.
|
// Smart match as regular expression or as a string.
|
||||||
// Optionally specify a literal match only.
|
// Optionally specify a literal match only.
|
||||||
inline bool match(const string&, bool literalMatch=false) const;
|
inline bool match(const std::string&, bool literalMatch=false) const;
|
||||||
|
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
|
|
||||||
//- Return a wordReList with duplicate words filtered out.
|
//- Return a wordReList with duplicate words filtered out.
|
||||||
// No filtering is done on regular expressions.
|
// No filtering is done on regular expressions.
|
||||||
static wordReList uniq(const UList<wordRe>& input);
|
static wordReList uniq(const UList<wordRe>& input);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -58,14 +58,14 @@ Foam::wordReListMatcher::operator()() const
|
|||||||
|
|
||||||
inline bool Foam::wordReListMatcher::match
|
inline bool Foam::wordReListMatcher::match
|
||||||
(
|
(
|
||||||
const string& str,
|
const std::string& text,
|
||||||
bool literalMatch
|
bool literalMatch
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const label nElem = reList_.size();
|
const label n = reList_.size();
|
||||||
for (label elemI = 0; elemI < nElem; ++elemI)
|
for (label i = 0; i < n; ++i)
|
||||||
{
|
{
|
||||||
if (reList_[elemI].match(str, literalMatch))
|
if (reList_[i].match(text, literalMatch))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,9 +63,9 @@ class Ostream;
|
|||||||
|
|
||||||
// Forward declaration of friend functions and operators
|
// Forward declaration of friend functions and operators
|
||||||
class string;
|
class string;
|
||||||
Istream& operator>>(Istream&, string&);
|
Istream& operator>>(Istream& is, string& s);
|
||||||
Ostream& operator<<(Ostream&, const string&);
|
Ostream& operator<<(Ostream& os, const string& s);
|
||||||
Ostream& operator<<(Ostream&, const std::string&);
|
Ostream& operator<<(Ostream& os, const std::string& s);
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
@ -124,33 +124,33 @@ public:
|
|||||||
//- Count and return the number of a given character in the string
|
//- Count and return the number of a given character in the string
|
||||||
size_type count(const char c) const;
|
size_type count(const char c) const;
|
||||||
|
|
||||||
//- Is this string type valid?
|
//- Does the string contain valid characters only?
|
||||||
template<class String>
|
template<class String>
|
||||||
static inline bool valid(const string& str);
|
static inline bool valid(const std::string& str);
|
||||||
|
|
||||||
//- Does this string have particular meta-characters?
|
//- Does this string contain meta-characters?
|
||||||
// The meta characters can be optionally quoted.
|
// The meta characters can be optionally quoted.
|
||||||
template<class String>
|
template<class String>
|
||||||
static inline bool meta(const string& str, const char quote = '\\');
|
static inline bool meta(const std::string& str, const char quote='\\');
|
||||||
|
|
||||||
//- Strip invalid characters from the given string
|
//- Strip invalid characters from the given string
|
||||||
template<class String>
|
template<class String>
|
||||||
static inline bool stripInvalid(string& str);
|
static inline bool stripInvalid(std::string& str);
|
||||||
|
|
||||||
//- Return a valid String from the given string
|
//- Return a valid String from the given string
|
||||||
template<class String>
|
template<class String>
|
||||||
static inline String validate(const string& str);
|
static inline String validate(const std::string& str);
|
||||||
|
|
||||||
//- Return a String with quoted meta-characters from the given string
|
//- Return a String with quoted meta-characters from the given string
|
||||||
template<class String>
|
template<class String>
|
||||||
static inline string quotemeta
|
static inline string quotemeta
|
||||||
(
|
(
|
||||||
const string& str,
|
const std::string& str,
|
||||||
const char quote = '\\'
|
const char quote = '\\'
|
||||||
);
|
);
|
||||||
|
|
||||||
//- True when strings match literally
|
//- True when strings match literally
|
||||||
inline bool match(const std::string& str) const;
|
inline bool match(const std::string& text) const;
|
||||||
|
|
||||||
//- Avoid masking the normal std::string replace
|
//- Avoid masking the normal std::string replace
|
||||||
using std::string::replace;
|
using std::string::replace;
|
||||||
|
|||||||
@ -61,7 +61,7 @@ inline Foam::string::string(const char c)
|
|||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class String>
|
template<class String>
|
||||||
inline bool Foam::string::valid(const string& str)
|
inline bool Foam::string::valid(const std::string& str)
|
||||||
{
|
{
|
||||||
for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
|
for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
|
||||||
{
|
{
|
||||||
@ -75,7 +75,7 @@ inline bool Foam::string::valid(const string& str)
|
|||||||
|
|
||||||
|
|
||||||
template<class String>
|
template<class String>
|
||||||
inline bool Foam::string::stripInvalid(string& str)
|
inline bool Foam::string::stripInvalid(std::string& str)
|
||||||
{
|
{
|
||||||
if (!valid<String>(str))
|
if (!valid<String>(str))
|
||||||
{
|
{
|
||||||
@ -85,11 +85,11 @@ inline bool Foam::string::stripInvalid(string& str)
|
|||||||
for
|
for
|
||||||
(
|
(
|
||||||
const_iterator iter1 = iter2;
|
const_iterator iter1 = iter2;
|
||||||
iter1 != const_cast<const string&>(str).end();
|
iter1 != const_cast<const std::string&>(str).end();
|
||||||
iter1++
|
iter1++
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char c = *iter1;
|
const char c = *iter1;
|
||||||
|
|
||||||
if (String::valid(c))
|
if (String::valid(c))
|
||||||
{
|
{
|
||||||
@ -109,20 +109,21 @@ inline bool Foam::string::stripInvalid(string& str)
|
|||||||
|
|
||||||
|
|
||||||
template<class String>
|
template<class String>
|
||||||
inline bool Foam::string::meta(const string& str, const char quote)
|
inline bool Foam::string::meta(const std::string& str, const char quote)
|
||||||
{
|
{
|
||||||
int escaped = 0;
|
int escaped = 0;
|
||||||
for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
|
for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
|
||||||
{
|
{
|
||||||
if (quote && *iter == quote)
|
const char c = *iter;
|
||||||
|
if (quote && c == quote)
|
||||||
{
|
{
|
||||||
escaped ^= 1; // toggle state
|
escaped ^= 1; // toggle state
|
||||||
}
|
}
|
||||||
else if (escaped)
|
else if (escaped)
|
||||||
{
|
{
|
||||||
escaped = false;
|
escaped = 0;
|
||||||
}
|
}
|
||||||
else if (String::meta(*iter))
|
else if (String::meta(c))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -133,7 +134,7 @@ inline bool Foam::string::meta(const string& str, const char quote)
|
|||||||
|
|
||||||
template<class String>
|
template<class String>
|
||||||
inline Foam::string
|
inline Foam::string
|
||||||
Foam::string::quotemeta(const string& str, const char quote)
|
Foam::string::quotemeta(const std::string& str, const char quote)
|
||||||
{
|
{
|
||||||
if (!quote)
|
if (!quote)
|
||||||
{
|
{
|
||||||
@ -146,7 +147,8 @@ Foam::string::quotemeta(const string& str, const char quote)
|
|||||||
int escaped = 0;
|
int escaped = 0;
|
||||||
for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
|
for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
|
||||||
{
|
{
|
||||||
if (*iter == quote)
|
const char c = *iter;
|
||||||
|
if (c == quote)
|
||||||
{
|
{
|
||||||
escaped ^= 1; // toggle state
|
escaped ^= 1; // toggle state
|
||||||
}
|
}
|
||||||
@ -154,12 +156,12 @@ Foam::string::quotemeta(const string& str, const char quote)
|
|||||||
{
|
{
|
||||||
escaped = 0;
|
escaped = 0;
|
||||||
}
|
}
|
||||||
else if (String::meta(*iter))
|
else if (String::meta(c))
|
||||||
{
|
{
|
||||||
sQuoted += quote;
|
sQuoted += quote;
|
||||||
}
|
}
|
||||||
|
|
||||||
sQuoted += *iter;
|
sQuoted += c;
|
||||||
}
|
}
|
||||||
|
|
||||||
sQuoted.resize(sQuoted.length());
|
sQuoted.resize(sQuoted.length());
|
||||||
@ -169,17 +171,17 @@ Foam::string::quotemeta(const string& str, const char quote)
|
|||||||
|
|
||||||
|
|
||||||
template<class String>
|
template<class String>
|
||||||
inline String Foam::string::validate(const string& str)
|
inline String Foam::string::validate(const std::string& str)
|
||||||
{
|
{
|
||||||
string ss = str;
|
string ss = str;
|
||||||
stripInvalid<String>(ss);
|
stripInvalid<String>(ss);
|
||||||
return ss;
|
return ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Foam::string::match(const std::string& str) const
|
inline bool Foam::string::match(const std::string& text) const
|
||||||
{
|
{
|
||||||
// check as string
|
// check as string
|
||||||
return (str == *this);
|
return (text == *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -183,7 +183,7 @@ Foam::string& Foam::stringOps::inplaceExpand
|
|||||||
HashTable<string, word, string::hash>::const_iterator fnd =
|
HashTable<string, word, string::hash>::const_iterator fnd =
|
||||||
mapping.find(varName);
|
mapping.find(varName);
|
||||||
|
|
||||||
if (fnd != HashTable<string, word, string::hash>::end())
|
if (fnd.found())
|
||||||
{
|
{
|
||||||
if (altPos != string::npos && altType == '+')
|
if (altPos != string::npos && altType == '+')
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1384,6 +1384,23 @@ void Foam::fvMeshSubset::setLargeCellSubset
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::fvMeshSubset::setLargeCellSubset
|
||||||
|
(
|
||||||
|
const UList<label>& globalCellMap,
|
||||||
|
const label patchID,
|
||||||
|
const bool syncPar
|
||||||
|
)
|
||||||
|
{
|
||||||
|
labelList region(baseMesh().nCells(), 0);
|
||||||
|
|
||||||
|
for (auto cellId : globalCellMap)
|
||||||
|
{
|
||||||
|
region[cellId] = 1;
|
||||||
|
}
|
||||||
|
setLargeCellSubset(region, 1, patchID, syncPar);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::fvMeshSubset::setLargeCellSubset
|
void Foam::fvMeshSubset::setLargeCellSubset
|
||||||
(
|
(
|
||||||
const labelHashSet& globalCellMap,
|
const labelHashSet& globalCellMap,
|
||||||
|
|||||||
@ -177,6 +177,14 @@ public:
|
|||||||
const bool syncCouples = true
|
const bool syncCouples = true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- setLargeCellSubset but only marking certain cells
|
||||||
|
void setLargeCellSubset
|
||||||
|
(
|
||||||
|
const UList<label>& globalCellMap,
|
||||||
|
const label patchID = -1,
|
||||||
|
const bool syncPar = true
|
||||||
|
);
|
||||||
|
|
||||||
//- setLargeCellSubset but with labelHashSet.
|
//- setLargeCellSubset but with labelHashSet.
|
||||||
void setLargeCellSubset
|
void setLargeCellSubset
|
||||||
(
|
(
|
||||||
|
|||||||
@ -90,6 +90,22 @@ void Foam::motionSmootherAlgo::checkFld(const pointScalarField& fld)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::labelHashSet Foam::motionSmootherAlgo::getPoints
|
||||||
|
(
|
||||||
|
const UList<label>& faceLabels
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
labelHashSet usedPoints(mesh_.nPoints()/100);
|
||||||
|
|
||||||
|
for (auto faceId : faceLabels)
|
||||||
|
{
|
||||||
|
usedPoints.insert(mesh_.faces()[faceId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return usedPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::labelHashSet Foam::motionSmootherAlgo::getPoints
|
Foam::labelHashSet Foam::motionSmootherAlgo::getPoints
|
||||||
(
|
(
|
||||||
const labelHashSet& faceLabels
|
const labelHashSet& faceLabels
|
||||||
@ -99,12 +115,7 @@ Foam::labelHashSet Foam::motionSmootherAlgo::getPoints
|
|||||||
|
|
||||||
forAllConstIter(labelHashSet, faceLabels, iter)
|
forAllConstIter(labelHashSet, faceLabels, iter)
|
||||||
{
|
{
|
||||||
const face& f = mesh_.faces()[iter.key()];
|
usedPoints.insert(mesh_.faces()[iter.key()]);
|
||||||
|
|
||||||
forAll(f, fp)
|
|
||||||
{
|
|
||||||
usedPoints.insert(f[fp]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return usedPoints;
|
return usedPoints;
|
||||||
|
|||||||
@ -209,7 +209,10 @@ class motionSmootherAlgo
|
|||||||
static void checkFld(const pointScalarField&);
|
static void checkFld(const pointScalarField&);
|
||||||
|
|
||||||
//- Get points used by given faces
|
//- Get points used by given faces
|
||||||
labelHashSet getPoints(const labelHashSet&) const;
|
labelHashSet getPoints(const UList<label>& faceLabels) const;
|
||||||
|
|
||||||
|
//- Get points used by given faces
|
||||||
|
labelHashSet getPoints(const labelHashSet& faceLabels) const;
|
||||||
|
|
||||||
//- Calculate per-edge weight
|
//- Calculate per-edge weight
|
||||||
tmp<scalarField> calcEdgeWeights(const pointField&) const;
|
tmp<scalarField> calcEdgeWeights(const pointField&) const;
|
||||||
|
|||||||
@ -42,7 +42,7 @@ defineTypeNameAndDebug(edgeCollapser, 0);
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::HashSet<Foam::label> Foam::edgeCollapser::checkBadFaces
|
Foam::labelHashSet Foam::edgeCollapser::checkBadFaces
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const dictionary& meshQualityDict
|
const dictionary& meshQualityDict
|
||||||
|
|||||||
@ -263,7 +263,7 @@ public:
|
|||||||
// Check
|
// Check
|
||||||
|
|
||||||
//- Calls motionSmoother::checkMesh and returns a set of bad faces
|
//- Calls motionSmoother::checkMesh and returns a set of bad faces
|
||||||
static HashSet<label> checkBadFaces
|
static labelHashSet checkBadFaces
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const dictionary& meshQualityDict
|
const dictionary& meshQualityDict
|
||||||
|
|||||||
@ -178,7 +178,7 @@ bool Foam::functionObjects::ddt2::execute()
|
|||||||
{
|
{
|
||||||
results_.clear();
|
results_.clear();
|
||||||
|
|
||||||
wordHashSet candidates = subsetStrings(selectFields_, mesh_.names());
|
wordHashSet candidates(subsetStrings(selectFields_, mesh_.names()));
|
||||||
DynamicList<word> missing(selectFields_.size());
|
DynamicList<word> missing(selectFields_.size());
|
||||||
DynamicList<word> ignored(selectFields_.size());
|
DynamicList<word> ignored(selectFields_.size());
|
||||||
|
|
||||||
|
|||||||
@ -135,7 +135,7 @@ bool Foam::functionObjects::zeroGradient::execute()
|
|||||||
{
|
{
|
||||||
results_.clear();
|
results_.clear();
|
||||||
|
|
||||||
wordHashSet candidates = subsetStrings(selectFields_, mesh_.names());
|
wordHashSet candidates(subsetStrings(selectFields_, mesh_.names()));
|
||||||
DynamicList<word> missing(selectFields_.size());
|
DynamicList<word> missing(selectFields_.size());
|
||||||
DynamicList<word> ignored(selectFields_.size());
|
DynamicList<word> ignored(selectFields_.size());
|
||||||
|
|
||||||
|
|||||||
@ -246,7 +246,7 @@ bool Foam::functionObjects::ensightWrite::write()
|
|||||||
ensCase().setTime(t.value(), t.timeIndex());
|
ensCase().setTime(t.value(), t.timeIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
wordHashSet candidates = subsetStrings(selectFields_, mesh_.names());
|
wordHashSet candidates(subsetStrings(selectFields_, mesh_.names()));
|
||||||
DynamicList<word> missing(selectFields_.size());
|
DynamicList<word> missing(selectFields_.size());
|
||||||
DynamicList<word> ignored(selectFields_.size());
|
DynamicList<word> ignored(selectFields_.size());
|
||||||
|
|
||||||
|
|||||||
@ -1352,6 +1352,12 @@ public:
|
|||||||
const labelHashSet& set
|
const labelHashSet& set
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
// Pick up faces of cells of faces in set.
|
||||||
|
labelList growFaceCellFace
|
||||||
|
(
|
||||||
|
const UList<label>& set
|
||||||
|
) const;
|
||||||
|
|
||||||
// Pick up faces of cells of faces in set.
|
// Pick up faces of cells of faces in set.
|
||||||
labelList growFaceCellFace
|
labelList growFaceCellFace
|
||||||
(
|
(
|
||||||
|
|||||||
@ -790,6 +790,62 @@ Foam::labelList Foam::meshRefinement::collectFaces
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
// Pick up faces of cells of faces in set.
|
||||||
|
// file-scope
|
||||||
|
static inline void markGrowFaceCellFace
|
||||||
|
(
|
||||||
|
const polyMesh& pMesh,
|
||||||
|
const label faceI,
|
||||||
|
boolList& selected
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const label own = pMesh.faceOwner()[faceI];
|
||||||
|
|
||||||
|
const cell& ownFaces = pMesh.cells()[own];
|
||||||
|
forAll(ownFaces, ownFaceI)
|
||||||
|
{
|
||||||
|
selected[ownFaces[ownFaceI]] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pMesh.isInternalFace(faceI))
|
||||||
|
{
|
||||||
|
const label nbr = pMesh.faceNeighbour()[faceI];
|
||||||
|
|
||||||
|
const cell& nbrFaces = pMesh.cells()[nbr];
|
||||||
|
forAll(nbrFaces, nbrFaceI)
|
||||||
|
{
|
||||||
|
selected[nbrFaces[nbrFaceI]] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Pick up faces of cells of faces in set.
|
||||||
|
Foam::labelList Foam::meshRefinement::growFaceCellFace
|
||||||
|
(
|
||||||
|
const UList<label>& set
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
boolList selected(mesh_.nFaces(), false);
|
||||||
|
|
||||||
|
for (auto faceI : set)
|
||||||
|
{
|
||||||
|
markGrowFaceCellFace(mesh_, faceI, selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
syncTools::syncFaceList
|
||||||
|
(
|
||||||
|
mesh_,
|
||||||
|
selected,
|
||||||
|
orEqOp<bool>() // combine operator
|
||||||
|
);
|
||||||
|
return findIndices(selected, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Pick up faces of cells of faces in set.
|
// Pick up faces of cells of faces in set.
|
||||||
Foam::labelList Foam::meshRefinement::growFaceCellFace
|
Foam::labelList Foam::meshRefinement::growFaceCellFace
|
||||||
(
|
(
|
||||||
@ -798,29 +854,12 @@ Foam::labelList Foam::meshRefinement::growFaceCellFace
|
|||||||
{
|
{
|
||||||
boolList selected(mesh_.nFaces(), false);
|
boolList selected(mesh_.nFaces(), false);
|
||||||
|
|
||||||
forAllConstIter(faceSet, set, iter)
|
forAllConstIter(labelHashSet, set, iter)
|
||||||
{
|
{
|
||||||
label faceI = iter.key();
|
const label faceI = iter.key();
|
||||||
|
markGrowFaceCellFace(mesh_, faceI, selected);
|
||||||
label own = mesh_.faceOwner()[faceI];
|
|
||||||
|
|
||||||
const cell& ownFaces = mesh_.cells()[own];
|
|
||||||
forAll(ownFaces, ownFaceI)
|
|
||||||
{
|
|
||||||
selected[ownFaces[ownFaceI]] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mesh_.isInternalFace(faceI))
|
|
||||||
{
|
|
||||||
label nbr = mesh_.faceNeighbour()[faceI];
|
|
||||||
|
|
||||||
const cell& nbrFaces = mesh_.cells()[nbr];
|
|
||||||
forAll(nbrFaces, nbrFaceI)
|
|
||||||
{
|
|
||||||
selected[nbrFaces[nbrFaceI]] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
syncTools::syncFaceList
|
syncTools::syncFaceList
|
||||||
(
|
(
|
||||||
mesh_,
|
mesh_,
|
||||||
|
|||||||
@ -30,22 +30,24 @@ License
|
|||||||
|
|
||||||
Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
|
Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
|
||||||
(
|
(
|
||||||
const dictionary& dict, const objectRegistry& obr
|
const dictionary& dict,
|
||||||
|
const objectRegistry& obr
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
Pout<< "coordinateRotation::New(const dictionary&) : "
|
Pout<< "coordinateRotation::New"
|
||||||
|
"(const dictionary&, const objectRegistry&) : "
|
||||||
<< "constructing coordinateRotation"
|
<< "constructing coordinateRotation"
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
word rotType = dict.lookup("type");
|
const word rotType = dict.lookup("type");
|
||||||
|
|
||||||
objectRegistryConstructorTable::iterator cstrIter =
|
objectRegistryConstructorTable::iterator cstrIter =
|
||||||
objectRegistryConstructorTablePtr_->find(rotType);
|
objectRegistryConstructorTablePtr_->find(rotType);
|
||||||
|
|
||||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
if (!cstrIter.found())
|
||||||
{
|
{
|
||||||
FatalIOErrorInFunction
|
FatalIOErrorInFunction
|
||||||
(
|
(
|
||||||
@ -54,7 +56,7 @@ Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
|
|||||||
<< rotType << nl << nl
|
<< rotType << nl << nl
|
||||||
<< "Valid coordinateRotation types are :" << nl
|
<< "Valid coordinateRotation types are :" << nl
|
||||||
<< "[default: axes ]"
|
<< "[default: axes ]"
|
||||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
<< objectRegistryConstructorTablePtr_->sortedToc()
|
||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,12 +76,12 @@ Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
|
|||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
word rotType = dict.lookup("type");
|
const word rotType = dict.lookup("type");
|
||||||
|
|
||||||
dictionaryConstructorTable::iterator cstrIter =
|
dictionaryConstructorTable::iterator cstrIter =
|
||||||
dictionaryConstructorTablePtr_->find(rotType);
|
dictionaryConstructorTablePtr_->find(rotType);
|
||||||
|
|
||||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
if (!cstrIter.found())
|
||||||
{
|
{
|
||||||
FatalIOErrorInFunction
|
FatalIOErrorInFunction
|
||||||
(
|
(
|
||||||
|
|||||||
@ -25,12 +25,16 @@ License
|
|||||||
|
|
||||||
#include "edgeFaceCirculator.H"
|
#include "edgeFaceCirculator.H"
|
||||||
#include "primitiveMesh.H"
|
#include "primitiveMesh.H"
|
||||||
|
#include "nullObject.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
const Foam::edgeFaceCirculator Foam::edgeFaceCirculator::endConstIter
|
const Foam::edgeFaceCirculator Foam::edgeFaceCirculator::endConstIter
|
||||||
(
|
(
|
||||||
*reinterpret_cast<primitiveMesh*>(0), // primitiveMesh
|
*reinterpret_cast<const primitiveMesh*>
|
||||||
|
(
|
||||||
|
NullObject::nullObject.pointer() // nullptr dummy
|
||||||
|
),
|
||||||
-1, // faceLabel
|
-1, // faceLabel
|
||||||
false, // ownerSide
|
false, // ownerSide
|
||||||
-1, // index
|
-1, // index
|
||||||
|
|||||||
@ -30,29 +30,26 @@ License
|
|||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
#include "mapDistributePolyMesh.H"
|
#include "mapDistributePolyMesh.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
defineTypeNameAndDebug(cellSet, 0);
|
defineTypeNameAndDebug(cellSet, 0);
|
||||||
|
|
||||||
addToRunTimeSelectionTable(topoSet, cellSet, word);
|
addToRunTimeSelectionTable(topoSet, cellSet, word);
|
||||||
addToRunTimeSelectionTable(topoSet, cellSet, size);
|
addToRunTimeSelectionTable(topoSet, cellSet, size);
|
||||||
addToRunTimeSelectionTable(topoSet, cellSet, set);
|
addToRunTimeSelectionTable(topoSet, cellSet, set);
|
||||||
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
cellSet::cellSet(const IOobject& obj)
|
Foam::cellSet::cellSet(const IOobject& obj)
|
||||||
:
|
:
|
||||||
topoSet(obj, typeName)
|
topoSet(obj, typeName)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
cellSet::cellSet
|
Foam::cellSet::cellSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -67,7 +64,7 @@ cellSet::cellSet
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cellSet::cellSet
|
Foam::cellSet::cellSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -79,7 +76,7 @@ cellSet::cellSet
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
cellSet::cellSet
|
Foam::cellSet::cellSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -91,7 +88,7 @@ cellSet::cellSet
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
cellSet::cellSet
|
Foam::cellSet::cellSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -103,8 +100,20 @@ cellSet::cellSet
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::cellSet::cellSet
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const word& name,
|
||||||
|
const UList<label>& set,
|
||||||
|
writeOption w
|
||||||
|
)
|
||||||
|
:
|
||||||
|
topoSet(mesh, name, set, w)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// Database constructors (for when no mesh available)
|
// Database constructors (for when no mesh available)
|
||||||
cellSet::cellSet
|
Foam::cellSet::cellSet
|
||||||
(
|
(
|
||||||
const Time& runTime,
|
const Time& runTime,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -114,32 +123,13 @@ cellSet::cellSet
|
|||||||
:
|
:
|
||||||
topoSet
|
topoSet
|
||||||
(
|
(
|
||||||
IOobject
|
findIOobject(runTime, name, r, w),
|
||||||
(
|
|
||||||
name,
|
|
||||||
runTime.findInstance
|
|
||||||
(
|
|
||||||
polyMesh::meshSubDir/"sets", //polyMesh::meshSubDir,
|
|
||||||
word::null, //"faces"
|
|
||||||
IOobject::MUST_READ,
|
|
||||||
runTime.findInstance
|
|
||||||
(
|
|
||||||
polyMesh::meshSubDir,
|
|
||||||
"faces",
|
|
||||||
IOobject::READ_IF_PRESENT
|
|
||||||
)
|
|
||||||
),
|
|
||||||
polyMesh::meshSubDir/"sets",
|
|
||||||
runTime,
|
|
||||||
r,
|
|
||||||
w
|
|
||||||
),
|
|
||||||
typeName
|
typeName
|
||||||
)
|
)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
cellSet::cellSet
|
Foam::cellSet::cellSet
|
||||||
(
|
(
|
||||||
const Time& runTime,
|
const Time& runTime,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -149,32 +139,13 @@ cellSet::cellSet
|
|||||||
:
|
:
|
||||||
topoSet
|
topoSet
|
||||||
(
|
(
|
||||||
IOobject
|
findIOobject(runTime, name, IOobject::NO_READ, w),
|
||||||
(
|
|
||||||
name,
|
|
||||||
runTime.findInstance
|
|
||||||
(
|
|
||||||
polyMesh::meshSubDir/"sets", //polyMesh::meshSubDir,
|
|
||||||
word::null, //"faces"
|
|
||||||
IOobject::NO_READ,
|
|
||||||
runTime.findInstance
|
|
||||||
(
|
|
||||||
polyMesh::meshSubDir,
|
|
||||||
"faces",
|
|
||||||
IOobject::READ_IF_PRESENT
|
|
||||||
)
|
|
||||||
),
|
|
||||||
polyMesh::meshSubDir/"sets",
|
|
||||||
runTime,
|
|
||||||
IOobject::NO_READ,
|
|
||||||
w
|
|
||||||
),
|
|
||||||
size
|
size
|
||||||
)
|
)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
cellSet::cellSet
|
Foam::cellSet::cellSet
|
||||||
(
|
(
|
||||||
const Time& runTime,
|
const Time& runTime,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -184,26 +155,7 @@ cellSet::cellSet
|
|||||||
:
|
:
|
||||||
topoSet
|
topoSet
|
||||||
(
|
(
|
||||||
IOobject
|
findIOobject(runTime, name, IOobject::NO_READ, w),
|
||||||
(
|
|
||||||
name,
|
|
||||||
runTime.findInstance
|
|
||||||
(
|
|
||||||
polyMesh::meshSubDir/"sets", //polyMesh::meshSubDir,
|
|
||||||
word::null, //"faces"
|
|
||||||
IOobject::NO_READ,
|
|
||||||
runTime.findInstance
|
|
||||||
(
|
|
||||||
polyMesh::meshSubDir,
|
|
||||||
"faces",
|
|
||||||
IOobject::READ_IF_PRESENT
|
|
||||||
)
|
|
||||||
),
|
|
||||||
polyMesh::meshSubDir/"sets",
|
|
||||||
runTime,
|
|
||||||
IOobject::NO_READ,
|
|
||||||
w
|
|
||||||
),
|
|
||||||
set
|
set
|
||||||
)
|
)
|
||||||
{}
|
{}
|
||||||
@ -211,25 +163,25 @@ cellSet::cellSet
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
cellSet::~cellSet()
|
Foam::cellSet::~cellSet()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
label cellSet::maxSize(const polyMesh& mesh) const
|
Foam::label Foam::cellSet::maxSize(const polyMesh& mesh) const
|
||||||
{
|
{
|
||||||
return mesh.nCells();
|
return mesh.nCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void cellSet::updateMesh(const mapPolyMesh& morphMap)
|
void Foam::cellSet::updateMesh(const mapPolyMesh& morphMap)
|
||||||
{
|
{
|
||||||
updateLabels(morphMap.reverseCellMap());
|
updateLabels(morphMap.reverseCellMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void cellSet::distribute(const mapDistributePolyMesh& map)
|
void Foam::cellSet::distribute(const mapDistributePolyMesh& map)
|
||||||
{
|
{
|
||||||
boolList inSet(map.nOldCells());
|
boolList inSet(map.nOldCells());
|
||||||
forAllConstIter(cellSet, *this, iter)
|
forAllConstIter(cellSet, *this, iter)
|
||||||
@ -271,8 +223,4 @@ void Foam::cellSet::writeDebug
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -53,7 +53,7 @@ class cellSet
|
|||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
cellSet(const cellSet&);
|
cellSet(const cellSet&) = delete;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -81,7 +81,7 @@ public:
|
|||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
const label sizes,
|
const label size,
|
||||||
writeOption w=NO_WRITE
|
writeOption w=NO_WRITE
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ public:
|
|||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
const topoSet&,
|
const topoSet& set,
|
||||||
writeOption w=NO_WRITE
|
writeOption w=NO_WRITE
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -99,7 +99,16 @@ public:
|
|||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
const labelHashSet&,
|
const labelHashSet& set,
|
||||||
|
writeOption w=NO_WRITE
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from additional list of labels for the labelHashSet
|
||||||
|
cellSet
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const word& name,
|
||||||
|
const UList<label>& set,
|
||||||
writeOption w=NO_WRITE
|
writeOption w=NO_WRITE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -31,29 +31,26 @@ License
|
|||||||
|
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
defineTypeNameAndDebug(faceSet, 0);
|
defineTypeNameAndDebug(faceSet, 0);
|
||||||
|
|
||||||
addToRunTimeSelectionTable(topoSet, faceSet, word);
|
addToRunTimeSelectionTable(topoSet, faceSet, word);
|
||||||
addToRunTimeSelectionTable(topoSet, faceSet, size);
|
addToRunTimeSelectionTable(topoSet, faceSet, size);
|
||||||
addToRunTimeSelectionTable(topoSet, faceSet, set);
|
addToRunTimeSelectionTable(topoSet, faceSet, set);
|
||||||
|
}
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
Foam::faceSet::faceSet(const IOobject& obj)
|
||||||
|
|
||||||
faceSet::faceSet(const IOobject& obj)
|
|
||||||
:
|
:
|
||||||
topoSet(obj, typeName)
|
topoSet(obj, typeName)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
faceSet::faceSet
|
Foam::faceSet::faceSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -67,7 +64,7 @@ faceSet::faceSet
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
faceSet::faceSet
|
Foam::faceSet::faceSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -79,7 +76,7 @@ faceSet::faceSet
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
faceSet::faceSet
|
Foam::faceSet::faceSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -91,7 +88,7 @@ faceSet::faceSet
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
faceSet::faceSet
|
Foam::faceSet::faceSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -103,15 +100,27 @@ faceSet::faceSet
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::faceSet::faceSet
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const word& name,
|
||||||
|
const UList<label>& set,
|
||||||
|
writeOption w
|
||||||
|
)
|
||||||
|
:
|
||||||
|
topoSet(mesh, name, set, w)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
faceSet::~faceSet()
|
Foam::faceSet::~faceSet()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void faceSet::sync(const polyMesh& mesh)
|
void Foam::faceSet::sync(const polyMesh& mesh)
|
||||||
{
|
{
|
||||||
boolList set(mesh.nFaces(), false);
|
boolList set(mesh.nFaces(), false);
|
||||||
|
|
||||||
@ -150,19 +159,19 @@ void faceSet::sync(const polyMesh& mesh)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
label faceSet::maxSize(const polyMesh& mesh) const
|
Foam::label Foam::faceSet::maxSize(const polyMesh& mesh) const
|
||||||
{
|
{
|
||||||
return mesh.nFaces();
|
return mesh.nFaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void faceSet::updateMesh(const mapPolyMesh& morphMap)
|
void Foam::faceSet::updateMesh(const mapPolyMesh& morphMap)
|
||||||
{
|
{
|
||||||
updateLabels(morphMap.reverseFaceMap());
|
updateLabels(morphMap.reverseFaceMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void faceSet::distribute(const mapDistributePolyMesh& map)
|
void Foam::faceSet::distribute(const mapDistributePolyMesh& map)
|
||||||
{
|
{
|
||||||
boolList inSet(map.nOldFaces());
|
boolList inSet(map.nOldFaces());
|
||||||
forAllConstIter(faceSet, *this, iter)
|
forAllConstIter(faceSet, *this, iter)
|
||||||
@ -193,7 +202,7 @@ void faceSet::distribute(const mapDistributePolyMesh& map)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void faceSet::writeDebug
|
void Foam::faceSet::writeDebug
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const primitiveMesh& mesh,
|
const primitiveMesh& mesh,
|
||||||
@ -204,8 +213,4 @@ void faceSet::writeDebug
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -51,7 +51,6 @@ class faceSet
|
|||||||
public topoSet
|
public topoSet
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//- Runtime type information
|
//- Runtime type information
|
||||||
@ -78,7 +77,7 @@ public:
|
|||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
const label,
|
const label size,
|
||||||
writeOption w=NO_WRITE
|
writeOption w=NO_WRITE
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -87,7 +86,7 @@ public:
|
|||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
const topoSet&,
|
const topoSet& set,
|
||||||
writeOption w=NO_WRITE
|
writeOption w=NO_WRITE
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -96,7 +95,16 @@ public:
|
|||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
const labelHashSet&,
|
const labelHashSet& set,
|
||||||
|
writeOption w=NO_WRITE
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from additional list of labels for the labelHashSet
|
||||||
|
faceSet
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const word& name,
|
||||||
|
const UList<label>& set,
|
||||||
writeOption w=NO_WRITE
|
writeOption w=NO_WRITE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -28,32 +28,28 @@ License
|
|||||||
#include "polyMesh.H"
|
#include "polyMesh.H"
|
||||||
#include "syncTools.H"
|
#include "syncTools.H"
|
||||||
#include "mapDistributePolyMesh.H"
|
#include "mapDistributePolyMesh.H"
|
||||||
|
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
namespace Foam
|
|
||||||
{
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
defineTypeNameAndDebug(pointSet, 0);
|
defineTypeNameAndDebug(pointSet, 0);
|
||||||
|
|
||||||
addToRunTimeSelectionTable(topoSet, pointSet, word);
|
addToRunTimeSelectionTable(topoSet, pointSet, word);
|
||||||
addToRunTimeSelectionTable(topoSet, pointSet, size);
|
addToRunTimeSelectionTable(topoSet, pointSet, size);
|
||||||
addToRunTimeSelectionTable(topoSet, pointSet, set);
|
addToRunTimeSelectionTable(topoSet, pointSet, set);
|
||||||
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
pointSet::pointSet(const IOobject& obj)
|
Foam::pointSet::pointSet(const IOobject& obj)
|
||||||
:
|
:
|
||||||
topoSet(obj, typeName)
|
topoSet(obj, typeName)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
pointSet::pointSet
|
Foam::pointSet::pointSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -67,7 +63,7 @@ pointSet::pointSet
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pointSet::pointSet
|
Foam::pointSet::pointSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -79,7 +75,7 @@ pointSet::pointSet
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
pointSet::pointSet
|
Foam::pointSet::pointSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -91,7 +87,7 @@ pointSet::pointSet
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
pointSet::pointSet
|
Foam::pointSet::pointSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
@ -103,15 +99,27 @@ pointSet::pointSet
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::pointSet::pointSet
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const word& name,
|
||||||
|
const UList<label>& set,
|
||||||
|
writeOption w
|
||||||
|
)
|
||||||
|
:
|
||||||
|
topoSet(mesh, name, set, w)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
pointSet::~pointSet()
|
Foam::pointSet::~pointSet()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void pointSet::sync(const polyMesh& mesh)
|
void Foam::pointSet::sync(const polyMesh& mesh)
|
||||||
{
|
{
|
||||||
// Convert to boolList
|
// Convert to boolList
|
||||||
|
|
||||||
@ -145,19 +153,19 @@ void pointSet::sync(const polyMesh& mesh)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
label pointSet::maxSize(const polyMesh& mesh) const
|
Foam::label Foam::pointSet::maxSize(const polyMesh& mesh) const
|
||||||
{
|
{
|
||||||
return mesh.nPoints();
|
return mesh.nPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void pointSet::updateMesh(const mapPolyMesh& morphMap)
|
void Foam::pointSet::updateMesh(const mapPolyMesh& morphMap)
|
||||||
{
|
{
|
||||||
updateLabels(morphMap.reversePointMap());
|
updateLabels(morphMap.reversePointMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void pointSet::distribute(const mapDistributePolyMesh& map)
|
void Foam::pointSet::distribute(const mapDistributePolyMesh& map)
|
||||||
{
|
{
|
||||||
boolList inSet(map.nOldPoints());
|
boolList inSet(map.nOldPoints());
|
||||||
forAllConstIter(pointSet, *this, iter)
|
forAllConstIter(pointSet, *this, iter)
|
||||||
@ -188,7 +196,7 @@ void pointSet::distribute(const mapDistributePolyMesh& map)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void pointSet::writeDebug
|
void Foam::pointSet::writeDebug
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const primitiveMesh& mesh,
|
const primitiveMesh& mesh,
|
||||||
@ -198,8 +206,4 @@ void pointSet::writeDebug
|
|||||||
topoSet::writeDebug(os, mesh.points(), maxLen);
|
topoSet::writeDebug(os, mesh.points(), maxLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -78,7 +78,16 @@ public:
|
|||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
const label,
|
const label size,
|
||||||
|
writeOption w=NO_WRITE
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from existing set
|
||||||
|
pointSet
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const word& name,
|
||||||
|
const topoSet& set,
|
||||||
writeOption w=NO_WRITE
|
writeOption w=NO_WRITE
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -87,16 +96,16 @@ public:
|
|||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
const topoSet&,
|
const labelHashSet& set,
|
||||||
writeOption w=NO_WRITE
|
writeOption w=NO_WRITE
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct from additional labelHashSet
|
//- Construct from additional list of labels for the labelHashSet
|
||||||
pointSet
|
pointSet
|
||||||
(
|
(
|
||||||
const polyMesh& mesh,
|
const polyMesh& mesh,
|
||||||
const word& name,
|
const word& name,
|
||||||
const labelHashSet&,
|
const UList<label>& set,
|
||||||
writeOption w=NO_WRITE
|
writeOption w=NO_WRITE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user