Merge branch 'feature-improved-container-classes' into 'develop'

improved container classes

See merge request !108
This commit is contained in:
Andrew Heather
2017-05-04 16:48:57 +01:00
106 changed files with 3532 additions and 1645 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -41,6 +41,8 @@ int main(int argc, char *argv[])
{
DLList<scalar> myList;
Info<< "DLList<scalar>" << nl;
for (int i = 0; i<10; i++)
{
myList.append(1.3*i);
@ -49,9 +51,7 @@ int main(int argc, char *argv[])
myList.append(100.3);
myList.append(500.3);
Info<< nl << "And again using STL iterator: " << nl << endl;
forAllIter(DLList<scalar>, myList, iter)
forAllConstIters(myList, iter)
{
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;
forAllIter(DLList<scalar>, myList, iter)
forAllIters(myList, iter)
{
Info<< "Removing " << myList.remove(iter) << endl;
}
@ -68,13 +68,10 @@ int main(int argc, char *argv[])
myList.append(200.3);
myList.append(100.3);
Info<< nl << "And again using STL const_iterator: " << nl << endl;
forAllConstIter(DLList<scalar>, myList, iter)
Info<< nl << "Using range-based for: " << nl << endl;
for (auto val : myList)
{
Info<< "element:" << *iter << endl;
Info<< "element:" << val << 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::last());
forAllIter(DLList<scalar>, myList, iter)
for (auto val : myList)
{
Info<< "element:" << *iter << endl;
Info<< "element:" << val << endl;
}
Info<< nl << "swapDown" << endl;
@ -94,12 +91,11 @@ int main(int argc, char *argv[])
myList.swapDown(myList.DLListBase::first());
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
<< "original: " << myList << endl;

View File

@ -168,9 +168,24 @@ int main(int argc, char *argv[])
Info<< nl << "scalarDict2: " << endl;
forAllConstIter(PtrDictionary<Scalar>, scalarDict2, iter)
{
std::cout<< "iter: " << typeid(*iter).name() << '\n';
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);

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,6 +28,8 @@ Description
#include "hashedWordList.H"
#include "HashSet.H"
#include "Map.H"
#include "labelPairHashes.H"
#include "FlatOutput.H"
using namespace Foam;
@ -65,6 +67,14 @@ int main(int argc, char *argv[])
tableB.insert("value5", 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
{
{ 1, 1 },
@ -122,14 +132,23 @@ int main(int argc, char *argv[])
<< (wordHashSet(setA) | wordHashSet(tableA) | wordHashSet(tableB))
<< nl;
labelHashSet setB
{
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;
labelPair pair(12, 15);
setB.set(pair);
Info<< "setB : " << setB << endl;
setB.unset(pair);
labelHashSet setC(1);
setC.insert(2008);
setC.insert(1984);
@ -139,7 +158,7 @@ int main(int argc, char *argv[])
labelHashSet setD(1);
setD.insert({11, 100, 49, 36, 2008});
Info<< "setD : " << setD << endl;
Info<< "setD : " << flatOutput(setD) << endl;
Info<< "setB == setC: " << (setB == setC) << 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 : " << setD << endl;
Info<< "setD : " << flatOutput(setD) << endl;
// this doesn't work (yet?)
// This should not work (yet?)
// setD[12] = true;
List<label> someLst(10);
@ -191,8 +210,14 @@ int main(int argc, char *argv[])
label added = setD.set(someLst);
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;
}

View File

@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "HashTable.H"
#include "List.H"
#include "IOstreams.H"
#include "IStringStream.H"
#include "OStringStream.H"
@ -62,7 +63,7 @@ int main()
Info<< "\ntable1 sortedToc: " << table1.sortedToc() << endl;
table1.printInfo(Info)
<< "table1 [" << table1.size() << "] " << endl;
forAllConstIter(HashTable<scalar>, table1, iter)
forAllConstIters(table1, iter)
{
Info<< iter.key() << " => " << iter() << nl;
}
@ -106,7 +107,7 @@ int main()
<< "\ntable3" << table3 << nl;
Info<< "\nerase table2 by iterator" << nl;
forAllIter(HashTable<scalar>, table2, iter)
forAllIters(table2, iter)
{
Info<< "erasing " << iter.key() << " => " << iter.object() << " ... ";
table2.erase(iter);
@ -177,6 +178,23 @@ int main()
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";
return 0;

View File

@ -78,7 +78,7 @@ int main(int argc, char *argv[])
Info<< nl << "And again using STL iterator: " << nl << endl;
forAllIter(SLList<scalar>, myList, iter)
forAllIters(myList, iter)
{
Info<< "element:" << *iter << endl;
}
@ -87,7 +87,7 @@ int main(int argc, char *argv[])
const ISLList<Scalar>& const_myList = myList;
forAllConstIter(SLList<scalar>, const_myList, iter)
forAllConstIters(const_myList, iter)
{
Info<< "element:" << *iter << endl;
}

View File

@ -76,7 +76,6 @@ int main(int argc, char *argv[])
Info<<"is >>: " << intlist << endl;
}
List<vector> list1(IStringStream("1 ((0 1 2))")());
Info<< "list1: " << list1 << endl;
@ -150,7 +149,6 @@ int main(int argc, char *argv[])
Info<< "normal: " << longLabelList << nl;
Info<< "flatOutput: " << flatOutput(longLabelList) << nl;
// Info<< "flatOutput(14): " << flatOutput(longLabelList, 14) << nl;
// Info<< "flatOutput(15): " << flatOutput(longLabelList, 15) << nl;
stringList longStringList(12);
forAll(longStringList, i)
@ -165,6 +163,66 @@ int main(int argc, char *argv[])
// 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;
wordList wLst;
stringList sLst;

View File

@ -77,24 +77,12 @@ int main(int argc, char *argv[])
<< "] = '" << namedEnumTest::namedEnum[opt] << "'" << nl;
}
#if __cplusplus > 201100L
// C++11
Info<< "loop over enums (C++11 for range):" << nl;
for (auto const& opt : options)
for (const auto& opt : options)
{
Info<< "option[" << opt
<< "] = '" << 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
<< namedEnumTest::namedEnum["a"] << nl

View File

@ -52,29 +52,29 @@ int main(int argc, char *argv[])
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;
const SLList<scalar>& const_myList = myList;
forAllConstIter(SLList<scalar>, const_myList, iter)
forAllConstIters(const_myList, iter)
{
Info<< "element:" << *iter << endl;
}
forAllIter(SLList<scalar>, myList, iter)
forAllIters(myList, iter)
{
Info<< "Removing element:" << *iter << endl;
myList.remove(iter);
}
forAllConstIter(SLList<scalar>, const_myList, iter)
for (const auto& val : const_myList)
{
Info<< "element:" << *iter << endl;
Info<< "element:" << val << endl;
}

View File

@ -31,6 +31,7 @@ Description
#include "Tuple2.H"
#include "label.H"
#include "scalar.H"
#include "List.H"
using namespace Foam;
@ -39,9 +40,25 @@ using namespace Foam;
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;

View File

@ -0,0 +1,3 @@
Test-cpluplus1.C
EXE = $(FOAM_USER_APPBIN)/Test-cpluplus1

View File

@ -0,0 +1,2 @@
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */
/* EXE_LIBS = -lfiniteVolume */

View 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;
}
// ************************************************************************* //

View File

@ -31,6 +31,7 @@ Description
#include "argList.H"
#include "edgeList.H"
#include "edgeHashes.H"
using namespace Foam;
@ -66,6 +67,17 @@ int main(int argc, char *argv[])
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;
// doesn't work e4 = -1;
@ -79,6 +91,28 @@ int main(int argc, char *argv[])
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})
{
bool ok = e4.erase(i);

View File

@ -28,10 +28,6 @@ Description
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "IOobject.H"
#include "IOstreams.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "labelRanges.H"
using namespace Foam;
@ -42,6 +38,7 @@ using namespace Foam;
int main(int argc, char *argv[])
{
argList::noParallel();
argList::noFunctionObjects();
argList::validArgs.insert("start size .. startN sizeN");
argList::addOption("verbose");
argList::addNote
@ -57,6 +54,34 @@ int main(int argc, char *argv[])
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;
labelRanges ranges;
@ -76,12 +101,9 @@ int main(int argc, char *argv[])
}
{
label start = 0;
label size = 0;
IStringStream(args[argI])() >> start;
label start = args.argRead<label>(argI);
label size = args.argRead<label>(argI+1);
++argI;
IStringStream(args[argI])() >> size;
range.reset(start, size);
}
@ -90,9 +112,9 @@ int main(int argc, char *argv[])
if (removeMode)
{
Info<< "del " << range << " :";
forAllConstIter(labelRange, range, iter)
for (auto i : range)
{
Info<< " " << iter();
Info<< " " << i;
}
Info<< nl;
@ -101,9 +123,9 @@ int main(int argc, char *argv[])
else
{
Info<< "add " << range << " :";
forAllConstIter(labelRange, range, iter)
for (auto i : range)
{
Info<< " " << iter();
Info<< " " << i;
}
Info<< nl;

View File

@ -1,3 +1,3 @@
Test-nullObject.C
EXE = $(FOAM_USER_APPBIN)/nullObject
EXE = $(FOAM_USER_APPBIN)/Test-nullObject

View File

@ -21,6 +21,17 @@ int main()
SimpleClass* ptrToClass = new SimpleClass;
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))
{
Info<< "Pass: ptrToClass is not null" << endl;

View File

@ -29,6 +29,9 @@ Description
#include "pTraits.H"
#include "vector.H"
#include "tensor.H"
#include "uLabel.H"
#include <type_traits>
using namespace Foam;
@ -40,7 +43,10 @@ void printTraits()
{
Info<< pTraits<T>::typeName
<< ": 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()
{
printTraits<bool>();
@ -71,6 +80,27 @@ int main()
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;
return 0;

View File

@ -536,12 +536,7 @@ Foam::label Foam::DistributedDelaunayMesh<Triangulation>::referVertices
if (!pointsNotInserted.empty())
{
for
(
labelPairHashSet::const_iterator iter = pointsNotInserted.begin();
iter != pointsNotInserted.end();
++iter
)
forAllConstIters(pointsNotInserted, iter)
{
if (receivedVertices.found(iter.key()))
{

View File

@ -24,16 +24,14 @@ License
\*---------------------------------------------------------------------------*/
#include "regExp.H"
#include "string.H"
#include "List.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class StringType>
bool Foam::regExp::matchGrouping
(
const std::string& text,
List<StringType>& groups
List<std::string>& groups
) const
{
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);
}
// ************************************************************************* //

View File

@ -51,7 +51,6 @@ namespace Foam
{
// Forward declaration of classes
class string;
template<class T> class List;
@ -76,12 +75,10 @@ class regExp
void operator=(const regExp&) = delete;
//- 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
(
const std::string&,
List<StringType>& groups
List<std::string>& groups
) const;
@ -96,16 +93,7 @@ public:
// range: '[', ']' \n
//
// Don't bother checking for '{digit}' bounds
inline static bool meta(const char c)
{
return
(
(c == '.') // any character
|| (c == '*' || c == '+' || c == '?') // quantifiers
|| (c == '(' || c == ')' || c == '|') // grouping/branching
|| (c == '[' || c == ']') // range
);
}
inline static bool meta(const char c);
// Constructors
@ -129,22 +117,13 @@ public:
// Access
//- Return true if a precompiled expression does not exist
inline bool empty() const
{
return !preg_;
}
inline bool empty() const;
//- Does a precompiled expression exist?
inline bool exists() const
{
return preg_ ? true : false;
}
inline bool exists() const;
//- The number of capture groups for a non-empty expression
inline unsigned ngroups() const
{
return preg_ ? preg_->re_nsub : 0;
}
inline unsigned ngroups() const;
// Editing
@ -173,26 +152,19 @@ public:
// The begin-of-line (^) and end-of-line ($) anchors are implicit
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
bool search(const std::string& text) const
{
return std::string::npos != find(text);
}
bool search(const std::string& text) const;
// Member Operators
//- Assign and compile pattern from a character array
// Always case sensitive
void operator=(const char* pattern);
inline void operator=(const char* pattern);
//- Assign and compile pattern from string
// 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
// ************************************************************************* //

View 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);
}
// ************************************************************************* //

View File

@ -31,7 +31,7 @@ License
template<class T, class Key, class Hash>
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
)
:
HashTable<T*, Key, Hash>()
parent_type(ht.capacity())
{
for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter)
{
const T* ptr = *iter;
const T* ptr = iter.object();
if (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>
T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
{
T* ptr = *iter;
HashTable<T*, Key, Hash>::erase(iter);
T* ptr = iter.object();
this->parent_type::erase(iter);
return ptr;
}
@ -81,9 +81,9 @@ T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
template<class T, class Key, class Hash>
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)
{
@ -102,17 +102,12 @@ bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
template<class T, class Key, class Hash>
void Foam::HashPtrTable<T, Key, Hash>::clear()
{
for
(
iterator iter = this->begin();
iter != this->end();
++iter
)
for (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)
{
const T* ptr = *iter;
const T* ptr = iter.object();
if (ptr)
{
this->insert(iter.key(), new T(*ptr));

View File

@ -25,7 +25,7 @@ Class
Foam::HashPtrTable
Description
A HashTable specialization for hashing pointers.
A HashTable of pointers to objects of type \<T\>.
SourceFiles
HashPtrTable.C
@ -51,10 +51,10 @@ class Ostream;
template<class T, class Key, class Hash> class HashPtrTable;
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>
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);
public:
typedef typename HashTable<T*, Key, Hash>::iterator iterator;
typedef typename HashTable<T*, Key, Hash>::const_iterator const_iterator;
//- The template instance used for this table
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
@ -100,7 +105,7 @@ public:
HashPtrTable(const dictionary& dict);
//- Construct as copy
HashPtrTable(const HashPtrTable<T, Key, Hash>& ht);
HashPtrTable(const this_type& ht);
//- Destructor
@ -109,25 +114,25 @@ public:
// Member Functions
// Edit
// Edit
//- Remove and return the pointer specified by given iterator
T* remove(iterator& iter);
//- Remove and return the pointer specified by given iterator
T* remove(iterator& iter);
//- Erase an hashedEntry specified by given iterator
bool erase(iterator& iter);
//- Erase an hashedEntry specified by given iterator
bool erase(iterator& iter);
//- Clear all entries from table
void clear();
//- Clear all entries from table
void clear();
//- Write
void write(Ostream& os) const;
//- Write
void write(Ostream& os) const;
// Member Operators
//- Copy assignment
void operator=(const HashPtrTable<T, Key, Hash>& rhs);
void operator=(const this_type& rhs);
// IOstream Operators
@ -135,13 +140,13 @@ public:
friend Istream& operator>> <T, Key, Hash>
(
Istream& is,
HashPtrTable<T, Key, Hash>& L
HashPtrTable<T, Key, Hash>& tbl
);
friend Ostream& operator<< <T, Key, Hash>
(
Ostream& os,
const HashPtrTable<T, Key, Hash>& L
const HashPtrTable<T, Key, Hash>& tbl
);
};

View File

@ -35,7 +35,7 @@ template<class T, class Key, class Hash>
template<class INew>
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);
@ -131,7 +131,7 @@ void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt)
<< 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)
{
this->insert
(
iter().keyword(),
inewt(dict.subDict(iter().keyword())).ptr()
);
const word& k = iter().keyword();
this->insert(k, inewt(dict.subDict(k)).ptr());
}
}
@ -157,16 +155,9 @@ void Foam::HashPtrTable<T, Key, Hash>::read
template<class T, class Key, class Hash>
void Foam::HashPtrTable<T, Key, Hash>::write(Ostream& os) const
{
for
(
typename HashPtrTable<T, Key, Hash>::const_iterator
iter = this->begin();
iter != this->end();
++iter
)
for (const_iterator iter = this->begin(); iter != this->end(); ++iter)
{
const T* ptr = *iter;
const T* ptr = iter.object();
if (ptr)
{
ptr->write(os);
@ -202,10 +193,10 @@ Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(const dictionary& dict)
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
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();
L.read(is, INew<T>());
tbl.clear();
tbl.read(is, INew<T>());
return is;
}
@ -215,21 +206,18 @@ template<class T, class Key, class Hash>
Foam::Ostream& Foam::operator<<
(
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
os << nl << L.size() << nl << token::BEGIN_LIST << nl;
os << nl << tbl.size() << nl << token::BEGIN_LIST << nl;
// Write contents
for
(
typename HashPtrTable<T, Key, Hash>::const_iterator iter = L.begin();
iter != L.end();
++iter
)
for (const_iterator iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
{
const T* ptr = *iter;
const T* ptr = iter.object();
os << iter.key();
if (ptr)
@ -242,8 +230,7 @@ Foam::Ostream& Foam::operator<<
// Write end delimiter
os << token::END_LIST;
// Check state of IOstream
os.check("Ostream& operator<<(Ostream&, const HashPtrTable&)");
os.check(FUNCTION_NAME);
return os;
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,6 +27,52 @@ License
#define HashSet_C
#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 * * * * * * * * * * * * * * //
@ -35,9 +81,22 @@ Foam::HashSet<Key, Hash>::HashSet(const UList<Key>& lst)
:
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())
{
for (const Key& k : lst)
for (const auto& k : lst)
{
this->insert(k);
}
@ -58,20 +117,17 @@ template<class Key, class Hash>
template<class AnyType, class AnyHash>
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
(
typename HashTable<AnyType, Key, AnyHash>::const_iterator
cit = h.cbegin();
cit != h.cend();
++cit
)
using other_iter =
typename HashTable<AnyType, Key, AnyHash>::const_iterator;
for (other_iter iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
{
this->insert(cit.key());
this->insert(iter.key());
}
}
@ -81,36 +137,49 @@ Foam::HashSet<Key, Hash>::HashSet
template<class Key, class Hash>
Foam::label Foam::HashSet<Key, Hash>::insert(const UList<Key>& lst)
{
label count = 0;
forAll(lst, elemI)
{
if (this->insert(lst[elemI]))
{
++count;
}
}
return count;
return insertMultiple(lst.begin(), lst.end());
}
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>
Foam::label Foam::HashSet<Key, Hash>::insert(std::initializer_list<Key> lst)
{
label count = 0;
for (const Key& k : lst)
{
if (this->insert(k))
{
++count;
}
}
return count;
return insertMultiple(lst.begin(), lst.end());
}
// * * * * * * * * * * * * * * * 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>
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>
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 * * * * * * * * * * * * * */
template<class Key, class Hash>
@ -243,6 +321,66 @@ Foam::operator^
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

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -52,6 +52,13 @@ Description
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
\*---------------------------------------------------------------------------*/
@ -61,11 +68,39 @@ class HashSet
:
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:
typedef typename HashTable<nil, Key, Hash>::iterator iterator;
typedef typename HashTable<nil, Key, Hash>::const_iterator const_iterator;
//- The template instance used for this HashSet
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
@ -73,59 +108,68 @@ public:
//- Construct given initial size
HashSet(const label size = 128)
:
HashTable<nil, Key, Hash>(size)
parent_type(size)
{}
//- Construct from Istream
HashSet(Istream& is)
:
HashTable<nil, Key, Hash>(is)
parent_type(is)
{}
//- 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
HashSet(std::initializer_list<Key>);
HashSet(std::initializer_list<Key> lst);
//- Construct as copy
HashSet(const HashSet<Key, Hash>& hs)
:
HashTable<nil, Key, Hash>(hs)
parent_type(hs)
{}
//- Construct by transferring the parameter contents
HashSet(const Xfer<HashSet<Key, Hash>>& hs)
:
HashTable<nil, Key, Hash>(hs)
parent_type(hs)
{}
//- Construct by transferring the parameter contents
HashSet(const Xfer<HashTable<nil, Key, Hash>>& hs)
:
HashTable<nil, Key, Hash>(hs)
parent_type(hs)
{}
//- Construct from the keys of another HashTable,
// the type of values held is arbitrary.
template<class AnyType, class AnyHash>
HashSet(const HashTable<AnyType, Key, AnyHash>& h);
explicit HashSet(const HashTable<AnyType, Key, AnyHash>& tbl);
// Member Functions
// Edit
// Edit
//- Insert a new entry
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
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
// Return the number of new elements inserted
label insert(std::initializer_list<Key> lst);
@ -142,6 +186,13 @@ public:
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)
label set(std::initializer_list<Key> lst)
{
@ -151,21 +202,75 @@ public:
//- Unset the specified key - same as erase
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
//- 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()
inline bool operator[](const Key& key) const;
//- Equality. Two hashset are equal when they have the same keys.
// 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.
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
@ -185,6 +290,16 @@ public:
//- Remove entries listed in the given HashSet from this HashSet
void operator-=(const HashSet<Key, Hash>& rhs);
// IOstream Operator
friend Ostream& operator<< <Key, Hash>
(
Ostream& os,
const HashSet<Key, Hash>& tbl
);
};

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,8 +28,38 @@ License
#include "HashTable.H"
#include "List.H"
#include "FixedList.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 * * * * * * * * * * * * * * //
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++)
{
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)
{
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
)
:
HashTable<T, Key, Hash>(lst.size())
HashTable<T, Key, Hash>(2*lst.size())
{
for (const Tuple2<Key, T>& pair : lst)
{
@ -238,8 +268,8 @@ bool Foam::HashTable<T, Key, Hash>::set
const label hashIdx = hashKeyIndex(key);
hashedEntry* existing = 0;
hashedEntry* prev = 0;
hashedEntry* existing = nullptr;
hashedEntry* prev = nullptr;
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
{
@ -251,10 +281,10 @@ bool Foam::HashTable<T, Key, Hash>::set
prev = ep;
}
// Not found, insert it at the head
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_++;
if (double(nElmts_)/tableSize_ > 0.8 && tableSize_ < maxTableSize)
@ -286,7 +316,7 @@ bool Foam::HashTable<T, Key, Hash>::set
{
// Found - overwrite existing entry
// 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
if (prev)
@ -306,17 +336,17 @@ bool Foam::HashTable<T, Key, Hash>::set
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
if (entryPtr_)
{
// Search element before entryPtr_
hashedEntry* prev = 0;
entry_type* prev = nullptr;
for
(
hashedEntry* ep = hashTable_->table_[hashIndex_];
entry_type* ep = hashTable_->table_[hashIndex_];
ep;
ep = ep->next_
)
@ -341,8 +371,7 @@ bool Foam::HashTable<T, Key, Hash>::iteratorBase::erase()
hashTable_->table_[hashIndex_] = entryPtr_->next_;
delete entryPtr_;
// Assign any non-nullptr value so it doesn't look
// like end()/cend()
// Assign any non-nullptr value so it doesn't look like end()
entryPtr_ = reinterpret_cast<hashedEntry*>(this);
// 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>
Foam::label Foam::HashTable<T, Key, Hash>::erase(const UList<Key>& keys)
{
const label nTotal = nElmts_;
label count = 0;
return eraseMultiple(keys.begin(), keys.end());
}
// 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>
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
// Could optimize depending on which hash is smaller ...
for (iterator iter = begin(); iter != end(); ++iter)
if (other.size() < nTotal)
{
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>
void Foam::HashTable<T, Key, Hash>::resize(const label sz)
{
label newSize = HashTableCore::canonicalSize(sz);
const label newSize = HashTableCore::canonicalSize(sz);
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)
{
tmpTable->insert(iter.key(), *iter);
tmpTable->insert(iter.key(), iter.object());
}
label oldSize = tableSize_;
const label oldSize = tableSize_;
tableSize_ = tmpTable->tableSize_;
tmpTable->tableSize_ = oldSize;
@ -480,7 +546,7 @@ void Foam::HashTable<T, Key, Hash>::clear()
ep = next;
}
delete ep;
table_[hashIdx] = 0;
table_[hashIdx] = nullptr;
}
}
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>
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)
{
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()
if (!tableSize_)
{
resize(lst.size());
resize(2*lst.size());
}
else
{
clear();
}
for (const Tuple2<Key, T>& pair : lst)
for (const auto& pair : lst)
{
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)
{
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;
}
@ -618,7 +671,7 @@ bool Foam::HashTable<T, Key, Hash>::operator!=
const HashTable<T, Key, Hash>& rhs
) const
{
return !(operator==(rhs));
return !operator==(rhs);
}

View File

@ -34,9 +34,17 @@ Note
often result in a different hash order. Use a sorted table-of-contents
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
HashTableI.H
HashTable.C
HashTableCore.C
HashTableIO.C
\*---------------------------------------------------------------------------*/
@ -49,6 +57,8 @@ SourceFiles
#include "word.H"
#include "Xfer.H"
#include "className.H"
#include "nullObject.H"
#include <initializer_list>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -60,32 +70,30 @@ namespace Foam
template<class T> class List;
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 HashPtrTable;
template<class Type1, class Type2>
class Tuple2;
template<class T, class Key, class Hash>
Istream& operator>>(Istream& is, HashTable<T, Key, Hash>& L);
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
{
//- Return a canonical (power-of-two) size
static label canonicalSize(const label size);
//- Maximum allowable table size
//- Maximum allowable internal table size. Approximately labelMax/4
static const label maxTableSize;
//- Return a canonical (power-of-two) of the requested size.
static label canonicalSize(const label requested_size);
//- Construct null
HashTableCore()
{}
@ -93,25 +101,57 @@ struct HashTableCore
//- Define template name and debug
ClassName("HashTable");
//- A zero-sized end iterator
struct iteratorEnd
static_assert
(
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
iteratorEnd()
{}
label size_;
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:
//- 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
//- Structure to hold a hashed entry with SLList for collisions
//- Structure to hold a hashed entry, with a SLList for collisions
struct hashedEntry
{
//- The lookup key
Key key_;
//- Pointer to next hashedEntry in sub-list
hashedEntry* next_;
//- The data object
T obj_;
//- Construct from key, next pointer and object
inline hashedEntry(const Key&, hashedEntry* next, const T&);
//- Pointer to next hashedEntry in sub-list
hashedEntry* next_;
//- Construct from key, next pointer and object
inline hashedEntry(const Key& key, const T& obj, hashedEntry* next);
private:
//- Disallow default bitwise copy construct
@ -169,39 +245,40 @@ class HashTable
// No checks for zero-sized tables.
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);
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:
// 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
//- Construct given initial table size
HashTable(const label size = 128);
//- Construct from Istream
HashTable(Istream&, const label size = 128);
HashTable(Istream& is, const label size = 128);
//- Construct as copy
HashTable(const HashTable<T, Key, Hash>& ht);
@ -219,83 +296,89 @@ public:
// Member Functions
// Access
// Access
//- The size of the underlying table
inline label capacity() const;
//- The size of the underlying table
inline label capacity() const;
//- Return number of elements in table
inline label size() const;
//- Return number of elements in table
inline label size() const;
//- Return true if the hash table is empty
inline bool empty() const;
//- Return true if the hash table is empty
inline bool empty() const;
//- Return true if hashedEntry is found in table
bool found(const Key& key) const;
//- Return true if hashedEntry is found in table
bool found(const Key& key) const;
//- Find and return an iterator set at the hashedEntry
// If not found iterator = end()
iterator find(const Key& key);
//- Find and return an iterator set at the hashedEntry
// If not found iterator = end()
iterator find(const Key& key);
//- Find and return an const_iterator set at the hashedEntry
// If not found iterator = end()
const_iterator find(const Key& key) const;
//- Find and return an const_iterator set at the hashedEntry
// If not found iterator = end()
const_iterator find(const Key& key) const;
//- Return the table of contents
List<Key> toc() const;
//- Return the table of contents
List<Key> toc() const;
//- Return the table of contents as a sorted list
List<Key> sortedToc() const;
//- Print information
Ostream& printInfo(Ostream& os) const;
//- Return the table of contents as a sorted list
List<Key> sortedToc() const;
// Edit
// Edit
//- Insert a new hashedEntry
inline bool insert(const Key& key, const T& newEntry);
//- Insert a new hashedEntry
// 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
inline bool set(const Key& key, const T& newEntry);
//- Assign a new hashedEntry, overwriting existing entries.
// Returns true.
inline bool set(const Key& key, const T& newEntry);
//- Erase a hashedEntry specified by given iterator
// This invalidates the iterator until the next operator++
bool erase(const iterator& iter);
//- Erase a hashedEntry specified by given iterator
// This invalidates the iterator until the next ++ operation
bool erase(const iterator& iter);
//- Erase a hashedEntry specified by the given key
bool erase(const Key& key);
//- Erase a hashedEntry specified by the given key
bool erase(const Key& key);
//- Remove entries given by the listed keys from this HashTable
// Return the number of elements removed
label erase(const UList<Key>& keys);
//- Remove entries given by the listed keys from this HashTable
// Return the number of elements removed
label erase(const UList<Key>& keys);
//- Remove entries given by the given keys from this HashTable
// 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>& rhs);
//- Remove entries given by the listed keys from this HashTable
// Return the number of elements removed
template<unsigned Size>
label erase(const FixedList<Key, Size>& keys);
//- Resize the hash table for efficiency
void resize(const label sz);
//- Remove entries given by the listed keys from this HashTable
// Return the number of elements removed
label erase(std::initializer_list<Key> keys);
//- Clear all entries from table
void clear();
//- Remove entries given by the given keys from this HashTable
// 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.
// Equivalent to clear() followed by resize(0)
void clearStorage();
//- Resize the hash table for efficiency
void resize(const label sz);
//- Shrink the allocated table to approx. twice number of elements
void shrink();
//- Clear all entries from table
void clear();
//- Transfer the contents of the argument table into this table
// and annul the argument table.
void transfer(HashTable<T, Key, Hash>& ht);
//- Clear the table entries and the table itself.
// Equivalent to clear() followed by resize(0)
void clearStorage();
//- Transfer contents to the Xfer container
inline Xfer<HashTable<T, Key, Hash>> xfer();
//- Transfer the contents of the argument table into this table
// 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
@ -306,13 +389,15 @@ public:
//- Find and return a hashedEntry
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);
//- Assignment
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);
//- 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;
// 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;
protected:
// 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
// and prevent most external usage.
// iterator and const_iterator have the same size, allowing
// 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
// This allows use of the default bitwise copy/assignment
HashTable<T, Key, Hash>* hashTable_;
private:
using entry_type = hashedEntry;
//- Current element
hashedEntry* entryPtr_;
// Private Data
//- Current hash index
label hashIndex_;
//- Currently selected entry.
// 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:
// Constructors
// Protected Member Functions
//- Construct null - equivalent to an 'end' position
inline iteratorBase();
//- Increment to the next position
inline void increment();
//- Construct from hash table, moving to its 'begin' position
inline explicit iteratorBase
(
const HashTable<T, Key, Hash>* hashTbl
);
//- The referenced object/value element
inline T& element() const;
//- Construct from hash table, element and hash index
inline iteratorBase
(
const HashTable<T, Key, Hash>* hashTbl,
const hashedEntry* elmt,
const label hashIndex
);
//- Erase the entry at the current position
bool erase();
// 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:
// Member operators
// Constructors
// Access
//- Construct null (end iterator)
inline iterator_base();
//- True if iterator points to a hashedEntry.
// This can be used instead of a comparison to end()
inline bool found() const;
//- Construct from begin of hash-table
inline explicit iterator_base(const table_type* hashTbl);
//- Return the Key corresponding to the iterator
inline const Key& key() const;
//- Construct from hash table, element and hash index
inline iterator_base
(
const table_type* hashTbl,
const entry_type* elmt,
const label hashIndex
);
//- Return const access to referenced object
inline const T& cobject() const;
// Member functions/operators
//- Compare hashedEntry element pointers
inline bool operator==(const iteratorBase& iter) const;
inline bool operator!=(const iteratorBase& iter) const;
//- True if iterator points to an entry
// This can be used directly instead of comparing to end()
inline bool found() const;
//- Compare hashedEntry to iteratorEnd pointers
inline bool operator==(const iteratorEnd& unused) const;
inline bool operator!=(const iteratorEnd& unused) const;
//- Return the Key corresponding to the iterator
inline const Key& key() 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
:
public iteratorBase
public iterator_base
{
friend class HashTable;
// 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
);
friend class HashTable; // Uses iterator::erase() method
using entry_type = hashedEntry;
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)
inline iterator();
// Constructors
//- Construct end iterator
inline iterator(const iteratorEnd& unused);
//- Construct null (end iterator)
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
using iteratorBase::object;
// Member functions/operators
//- Return non-const access to referenced object
inline T& operator*();
inline T& operator()();
//- Return non-const access to referenced object
inline reference object() const;
//- Return const access to referenced object
inline const T& operator*() const;
inline const T& operator()() const;
//- Return non-const access to referenced object
inline reference operator*() const;
inline reference operator()() const;
inline iterator& operator++();
inline iterator operator++(int);
inline iterator& operator++();
inline iterator operator++(int);
};
//- Iterator set to the beginning of the HashTable
inline iterator begin();
// STL const_iterator
//- An STL-conforming const_iterator
//- Forward iterator with const access
class const_iterator
:
public iteratorBase
public iterator_base
{
friend class HashTable;
// 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
);
using entry_type = const hashedEntry;
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)
inline const_iterator();
// Constructors
//- Construct from iterator
inline const_iterator(const iterator& iter);
//- Construct null (end iterator)
inline const_iterator();
//- Construct end iterator
inline const_iterator(const iteratorEnd& unused);
//- Construct from begin of hash-table
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
inline const T& operator*() const;
inline const T& operator()() const;
// Member functions/operators
inline const_iterator& operator++();
inline const_iterator operator++(int);
//- Return const access to referenced object
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
inline const_iterator cbegin() const;
//- const_iterator set to the beginning of the HashTable
inline const_iterator begin() const;
//- iterator to signal the end for any HashTable
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
@ -548,7 +670,7 @@ public:
friend Ostream& operator<< <T, Key, Hash>
(
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"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -33,38 +33,53 @@ namespace Foam
defineTypeNameAndDebug(HashTableCore, 0);
}
const Foam::label Foam::HashTableCore::maxTableSize
(
Foam::HashTableCore::canonicalSize
(
Foam::labelMax/2
)
);
// Approximately labelMax/4
const Foam::label Foam::HashTableCore::maxTableSize(1 << (sizeof(label)*8-3));
// * * * * * * * * * * * * * * 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;
}
// enforce power of two
uLabel goodSize = size;
// 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.
if (goodSize & (goodSize - 1))
uLabel powerOfTwo = 8; // lower-limit
const uLabel size = requested_size;
if (size < powerOfTwo)
{
// brute-force is fast enough
goodSize = 1;
while (goodSize < unsigned(size))
{
goodSize <<= 1;
}
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 goodSize;
return powerOfTwo;
}
else
{
return size;
}
}

View 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>();
}
// ************************************************************************* //

View File

@ -31,13 +31,13 @@ template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::hashedEntry::hashedEntry
(
const Key& key,
hashedEntry* next,
const T& obj
const T& obj,
hashedEntry* next
)
:
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);
if (iter == this->end())
if (!iter.found())
{
FatalErrorInFunction
<< key << " not found in table. Valid entries: "
@ -120,7 +120,7 @@ inline T& Foam::HashTable<T, Key, Hash>::operator[](const Key& key)
<< 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);
if (iter == this->cend())
if (!iter.found())
{
FatalErrorInFunction
<< 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);
}
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);
if (iter == this->end())
if (iter.found())
{
this->insert(key, T());
return *find(key);
}
else
{
return *iter;
return iter.object();
}
this->insert(key, T());
return find(key).object();
}
// * * * * * * * * * * * * * * * iterator base * * * * * * * * * * * * * * * //
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_(0),
entryPtr_(nullptr),
hashTable_(nullptr),
hashIndex_(0)
{}
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_(0),
entryPtr_(const_cast<entry_type*>(elmt)),
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)
{
if (hashTable_->nElmts_)
if (hashTable_ && hashTable_->nElmts_)
{
// find first non-nullptr table entry
while
@ -192,30 +204,16 @@ inline Foam::HashTable<T, Key, Hash>::iteratorBase::iteratorBase
if (hashIndex_ >= hashTable_->tableSize_)
{
// make into an end iterator
entryPtr_ = 0;
entryPtr_ = nullptr;
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>
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
if (hashIndex_ < 0)
@ -251,7 +249,7 @@ Foam::HashTable<T, Key, Hash>::iteratorBase::increment()
if (hashIndex_ >= hashTable_->tableSize_)
{
// make into an end iterator
entryPtr_ = 0;
entryPtr_ = nullptr;
hashIndex_ = 0;
}
}
@ -259,40 +257,30 @@ Foam::HashTable<T, Key, Hash>::iteratorBase::increment()
template<class T, class Key, class Hash>
inline bool
Foam::HashTable<T, Key, Hash>::iteratorBase::found() const
Foam::HashTable<T, Key, Hash>::iterator_base::found() const
{
return entryPtr_;
}
template<class T, class Key, class Hash>
inline
const Key& Foam::HashTable<T, Key, Hash>::iteratorBase::key() const
inline const Key& Foam::HashTable<T, Key, Hash>::iterator_base::key() const
{
return entryPtr_->key_;
}
template<class T, class Key, class Hash>
inline T&
Foam::HashTable<T, Key, Hash>::iteratorBase::object()
inline T& Foam::HashTable<T, Key, Hash>::iterator_base::element() const
{
return entryPtr_->obj_;
}
template<class T, class Key, class Hash>
inline const T&
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==
inline bool Foam::HashTable<T, Key, Hash>::iterator_base::operator==
(
const iteratorBase& iter
const iterator_base& iter
) const
{
return entryPtr_ == iter.entryPtr_;
@ -300,32 +288,36 @@ inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator==
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
{
return entryPtr_ != iter.entryPtr_;
}
// * * * * * * * * * * * * * * key iterator base * * * * * * * * * * * * * * //
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
{
return !entryPtr_;
}
const WrappedIterator& iter
)
:
WrappedIterator(iter)
{}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator!=
(
const iteratorEnd&
) const
template<class WrappedIterator>
inline const Key&
Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
::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>
inline Foam::HashTable<T, Key, Hash>::iterator::iterator()
:
iteratorBase()
iterator_base()
{}
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
(
const iteratorEnd&
table_type* hashTbl
)
:
iteratorBase()
iterator_base(hashTbl)
{}
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
(
HashTable<T, Key, Hash>* hashTbl
)
:
iteratorBase(hashTbl)
{}
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
(
HashTable<T, Key, Hash>* hashTbl,
hashedEntry* elmt,
table_type* hashTbl,
entry_type* elmt,
const label hashIndex
)
:
iteratorBase(hashTbl, elmt, hashIndex)
iterator_base(hashTbl, elmt, hashIndex)
{}
template<class T, class Key, class Hash>
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();
}
@ -380,31 +370,14 @@ Foam::HashTable<T, Key, Hash>::iterator::operator*()
template<class T, class Key, class Hash>
inline T&
Foam::HashTable<T, Key, Hash>::iterator::operator()()
Foam::HashTable<T, Key, Hash>::iterator::operator()() const
{
return this->object();
}
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 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&
inline typename Foam::HashTable<T, Key, Hash>::iterator&
Foam::HashTable<T, Key, Hash>::iterator::operator++()
{
this->increment();
@ -422,20 +395,12 @@ Foam::HashTable<T, Key, Hash>::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);
}
// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * //
template<class T, class Key, class Hash>
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
)
:
iteratorBase(iter)
iterator_base(iter)
{}
template<class T, class Key, class Hash>
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>
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
(
const HashTable<T, Key, Hash>* hashTbl
)
:
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,
table_type* hashTbl,
entry_type* elmt,
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>
inline const T&
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&
Foam::HashTable<T, Key, Hash>::const_iterator::operator()() const
{
return this->cobject();
return this->object();
}
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>::const_iterator::operator++()
{
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>
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
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>
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::begin() const
inline const typename Foam::HashTable<T, Key, Hash>::iterator&
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>();
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -43,7 +43,7 @@ Foam::HashTable<T, Key, Hash>::HashTable(Istream& is, const label size)
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 * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::Ostream&
Foam::HashTable<T, Key, Hash>::printInfo(Ostream& os) const
Foam::Ostream& Foam::HashTable<T, Key, Hash>::printInfo(Ostream& os) const
{
label used = 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 * * * * * * * * * * * * //
template<class T, class Key, class Hash>
@ -215,28 +261,25 @@ template<class T, class Key, class Hash>
Foam::Ostream& Foam::operator<<
(
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
os << nl << L.size() << nl << token::BEGIN_LIST << nl;
os << nl << tbl.size() << nl << token::BEGIN_LIST << nl;
// Write contents
for
(
typename HashTable<T, Key, Hash>::const_iterator iter = L.cbegin();
iter != L.cend();
++iter
)
for (const_iterator iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
{
os << iter.key() << token::SPACE << iter() << nl;
os << iter.key() << token::SPACE << iter.object() << nl;
}
// Write end delimiter
os << token::END_LIST;
// Check state of IOstream
os.check("Ostream& operator<<(Ostream&, const HashTable&)");
os.check(FUNCTION_NAME);
return os;
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -51,50 +51,54 @@ class Map
:
public HashTable<T, label, Hash<label>>
{
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
//- Construct given initial size
Map(const label size = 128)
:
HashTable<T, label, Hash<label>>(size)
parent_type(size)
{}
//- Construct from Istream
Map(Istream& is)
:
HashTable<T, label, Hash<label>>(is)
parent_type(is)
{}
//- Construct as copy
Map(const Map<T>& map)
:
HashTable<T, label, Hash<label>>(map)
parent_type(map)
{}
//- Construct by transferring the parameter contents
Map(const Xfer<Map<T>>& map)
:
HashTable<T, label, Hash<label>>(map)
parent_type(map)
{}
//- Construct by transferring the parameter contents
Map(const Xfer<HashTable<T, label, Hash<label>>>& map)
:
HashTable<T, label, Hash<label>>(map)
parent_type(map)
{}
//- Construct from an initializer list
Map(std::initializer_list<Tuple2<label, T>> map)
:
HashTable<T, label, Hash<label>>(map)
parent_type(map)
{}
};

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -51,27 +51,33 @@ class PtrMap
:
public HashPtrTable<T, label, Hash<label>>
{
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
//- Construct given initial map size
PtrMap(const label size = 128)
:
HashPtrTable<T, label, Hash<label>>(size)
parent_type(size)
{}
//- Construct from Istream
PtrMap(Istream& is)
:
HashPtrTable<T, label, Hash<label>>(is)
parent_type(is)
{}
//- Construct as copy
PtrMap(const PtrMap<T>& map)
PtrMap(const this_type& map)
:
HashPtrTable<T, label, Hash<label>>(map)
parent_type(map)
{}
};

View File

@ -30,32 +30,6 @@ License
#include "List.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 * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>

View File

@ -78,8 +78,8 @@ template<class T, class Key, class Hash> Ostream& operator<<
//- Template-invariant bits for StaticHashTable
struct StaticHashTableCore
{
//- Return a canonical (power-of-two) size
static label canonicalSize(const label);
//- Return a canonical (power-of-two) of the requested size.
static label canonicalSize(const label requested_size);
//- Construct null
StaticHashTableCore()
@ -119,9 +119,6 @@ class StaticHashTable
//- The current number of elements in table
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.
// No checks for zero-sized tables.
inline label hashKeyIndex(const Key&) const;
@ -397,7 +394,7 @@ private:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "StaticHashTableI.H"
#include "StaticHashTableI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "StaticHashTable.H"
#include "uLabel.H"
// * * * * * * * * * * * * * * 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;
}
}
// ************************************************************************* //

View File

@ -329,7 +329,7 @@ public:
//- Return size of the largest possible FixedList
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;
//- Swap two FixedLists of the same type in constant time

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,6 +40,7 @@ SourceFiles
#define SubList_H
#include "List.H"
#include "labelRange.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -55,7 +56,6 @@ class SubList
:
public UList<T>
{
public:
// Static Member Functions
@ -81,6 +81,23 @@ public:
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
@ -88,13 +105,13 @@ public:
inline operator const Foam::List<T>&() const;
//- 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
inline void operator=(const UList<T>&);
inline void operator=(const UList<T>& list);
//- Assignment of all entries to the given value
inline void operator=(const T&);
inline void operator=(const T& t);
};

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -51,7 +51,6 @@ inline Foam::SubList<T>::SubList
UList<T>(&(list.v_[startIndex]), subSize)
{
#ifdef FULLDEBUG
// Artificially allow the start of a zero-sized subList to be
// one past the end of the original list.
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 * * * * * * * * * * * * * //
template<class T>
@ -88,16 +109,16 @@ inline Foam::SubList<T>::operator const Foam::List<T>&() const
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>
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);
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,9 +26,49 @@ License
#include "UList.H"
#include "ListLoopM.H"
#include "contiguous.H"
#include "labelRange.H"
#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 * * * * * * * * * * * * * //
template<class T>
@ -64,6 +104,47 @@ void Foam::UList<T>::deepCopy(const UList<T>& a)
// * * * * * * * * * * * * * * * 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>
void Foam::UList<T>::operator=(const T& t)
{

View File

@ -47,13 +47,16 @@ SourceFiles
#include "uLabel.H"
#include "nullObject.H"
#include "zero.H"
#include "stdFoam.H"
#include <initializer_list>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend classes
// Forward declarations
class labelRange;
template<class T> class List;
template<class T> class SubList;
@ -100,6 +103,16 @@ protected:
//- Write the UList with its compound type
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:
@ -238,6 +251,29 @@ public:
// an out-of-range element returns false without any ill-effects
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>&
inline operator const Foam::List<T>&() const;
@ -253,12 +289,10 @@ public:
//- Type of values the UList contains
typedef T value_type;
//- Type that can be used for storing into
// UList::value_type objects
//- The type used for storing into value_type objects
typedef T& reference;
//- Type that can be used for storing into
// constant UList::value_type objects
//- The type used for reading from constant value_type objects.
typedef const T& const_reference;
//- The type that can represent the difference between any two
@ -427,69 +461,6 @@ inline void reverse(UList<T>& ul);
#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

View File

@ -71,7 +71,7 @@ inline Foam::label Foam::UList<T>::rcIndex(const label i) const
template<class T>
inline void Foam::UList<T>::checkStart(const label start) const
{
if (start<0 || (start && start>=size_))
if (start < 0 || (start && start >= size_))
{
FatalErrorInFunction
<< "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>
inline void Foam::UList<T>::checkSize(const label size) const
{
if (size<0 || size>size_)
if (size < 0 || size > size_)
{
FatalErrorInFunction
<< "size " << size << " out of range 0 ... " << size_
@ -162,7 +162,6 @@ inline void Foam::UList<T>::shallowCopy(const UList<T>& a)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
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];
}
namespace Foam
{
// Template specialization for bool
@ -191,7 +189,6 @@ namespace Foam
}
}
template<class T>
inline const T& Foam::UList<T>::operator[](const label i) const
{

View File

@ -64,14 +64,14 @@ Enum Foam::NamedEnum<Enum, nEnum>::read(Istream& is) const
HashTable<int>::const_iterator iter = find(name);
if (iter == HashTable<int>::end())
if (!iter.found())
{
FatalIOErrorInFunction(is)
<< name << " is not in enumeration: "
<< sortedToc() << exit(FatalIOError);
}
return Enum(iter());
return Enum(iter.object());
}

View 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
// ************************************************************************* //

View File

@ -50,11 +50,8 @@ namespace Foam
class boundBox;
template<class T> class tmp;
bool operator==(const boundBox&, const boundBox&);
bool operator!=(const boundBox&, const boundBox&);
Istream& operator>>(Istream&, boundBox&);
Ostream& operator<<(Ostream&, const boundBox&);
Istream& operator>>(Istream& is, boundBox& bb);
Ostream& operator<<(Ostream& os, const boundBox& bb);
/*---------------------------------------------------------------------------*\
@ -289,12 +286,6 @@ public:
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
friend Istream& operator>>(Istream& is, boundBox& bb);
@ -306,6 +297,11 @@ public:
template<>
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);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -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)
{
return (a.min_ == b.min_) && (a.max_ == b.max_);
return (a.min() == b.min()) && (a.max() == b.max());
}

View File

@ -63,7 +63,7 @@ inline Foam::label Foam::cell::nFaces() const
inline bool Foam::operator!=(const cell& a, const cell& b)
{
return (!(a == b));
return !(a == b);
}

View File

@ -59,7 +59,7 @@ Ostream& operator<<(Ostream& os, const cellModel& c);
/*---------------------------------------------------------------------------*\
Class cellModel Declaration
Class cellModel Declaration
\*---------------------------------------------------------------------------*/
class cellModel
@ -122,13 +122,13 @@ public:
inline label nFaces() const;
//- 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
inline const faceList& modelFaces() const;
//- Return list of faces
inline faceList faces(const labelList& pointLabels) const;
inline faceList faces(const UList<label>& pointLabels) const;
//- Vector centroid

View File

@ -21,45 +21,38 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "cellModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const word& cellModel::name() const
inline const Foam::word& Foam::cellModel::name() const
{
return name_;
}
inline label cellModel::index() const
inline Foam::label Foam::cellModel::index() const
{
return index_;
}
inline label cellModel::nPoints() const
inline Foam::label Foam::cellModel::nPoints() const
{
return nPoints_;
}
inline label cellModel::nEdges() const
inline Foam::label Foam::cellModel::nEdges() const
{
return edges_.size();
}
inline label cellModel::nFaces() const
inline Foam::label Foam::cellModel::nFaces() const
{
return faces_.size();
}
@ -67,7 +60,10 @@ inline label cellModel::nFaces() const
// Return the faces of a cellModel by untangling the geometry
// 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());
@ -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_;
}
@ -94,7 +90,10 @@ inline const faceList& cellModel::modelFaces() const
// Return the faces of a cellModel by untangling the geometry
// 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());
@ -120,20 +119,16 @@ inline faceList cellModel::faces(const labelList& pointLabels) const
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// 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);
}
// 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);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -28,6 +28,14 @@ Description
An edge is a list of two point labels. The functionality it provides
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
edgeI.H
@ -37,6 +45,7 @@ SourceFiles
#define edge_H
#include "FixedList.H"
#include "labelPair.H"
#include "pointField.H"
#include "linePointRef.H"
@ -45,21 +54,32 @@ SourceFiles
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
:
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:
@ -79,6 +99,9 @@ public:
//- Construct, optionally sorted with start less-than end
inline edge(const label from, const label to, const bool doSort);
//- Construct from two labels
inline edge(const labelPair& pair);
//- Construct from FixedList
inline edge(const FixedList<label, 2>& lst);
@ -91,6 +114,8 @@ public:
// Member Functions
// Access
//- Return start vertex label
inline label start() const;
@ -103,82 +128,157 @@ public:
//- Return end vertex label
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?
// Negative point labels never connect.
inline bool connects(const edge& other) const;
//- 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;
//- Given one vertex index, return the other one.
// No special treatment for negative point labels.
inline label otherVertex(const label index) const;
//- 'Collapse' edge by marking duplicate point labels.
// Duplicates point labels are marked with '-1'.
// (the lower vertex is retained).
// Return the collapsed size.
// Editing
//- 'Collapse' edge by marking duplicate point labels as '-1',
// the lower vertex is retained.
// Return the effective size after collapsing.
inline label collapse();
//- Return true if point label is found in edge
// No special treatment for '-1'.
inline bool found(const label index) const;
//- Flip the edge in-place.
// No special handling of negative point labels.
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.
// Similar to a HashTable::size().
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.
// Similar to a HashTable::insert().
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'.
// Returns true on success. A negative label never removes.
// Returns the number of changes. A negative label never removes.
// 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
inline bool sorted() const;
// Geometric functions
//- Sort start/end that start is less-than end
inline void sort();
//- Flip the edge in-place.
inline void flip();
//- Return reverse edge
inline edge reverseEdge() const;
//- Return centre (centroid)
//- Return centre point (centroid) of the edge.
// No special handling of negative point labels.
inline point centre(const UList<point>& pts) const;
//- Return the vector (end - start)
// No special handling of negative point labels.
inline vector vec(const UList<point>& pts) const;
//- Return the unit vector (end - start)
// No special handling of negative point labels.
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;
//- Return edge line
// No special handling of negative point labels.
inline linePointRef line(const UList<point>& pts) const;
// Comparison
//- Compare edges
// Returns:
// - 0: different
// - +1: identical
// - -1: same edge, but different orientation
// - +1: identical values and order used
// - -1: identical values, but in different order
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 incrementally.
template<>

View File

@ -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 * * * * * * * * * * * * * * //
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)
{
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
{
return (index == start() || index == end());
// -1: always false
return (index >= 0 && (index == start() || index == end()));
}
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
{
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
{
@ -182,12 +262,12 @@ inline Foam::label Foam::edge::collapse()
// catch any '-1' (eg, if called multiple times)
label n = 2;
if (start() == end() || end() == -1)
if (start() == end() || end() < 0)
{
end() = -1;
--n;
}
if (start() == -1)
if (start() < 0)
{
--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
{
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
{
#ifdef FULLDEBUG
if (start() < 0 || end() < 0)
{
FatalErrorInFunction
<< "negative point index on edge " << *this
<< abort(FatalError);
}
#endif
return 0.5*(pts[start()] + pts[end()]);
}
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()];
}
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()];
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
{
#ifdef FULLDEBUG
if (start() < 0 || end() < 0)
{
FatalErrorInFunction
<< "negative point index on edge " << *this
<< abort(FatalError);
}
#endif
return linePointRef(pts[start()], pts[end()]);
}
// * * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
inline bool Foam::operator==(const edge& a, const edge& b)
{

View File

@ -65,8 +65,6 @@ class triFace;
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
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);
/*---------------------------------------------------------------------------*\
@ -382,12 +380,6 @@ public:
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
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
//- Find the longest edge on a face. Face point labels index into pts.

View File

@ -135,14 +135,14 @@ inline Foam::label Foam::face::nTriangles() const
return size() - 2;
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
inline bool Foam::operator==(const face& a, const face& b)
{
return face::compare(a,b) != 0;
}
inline bool Foam::operator!=(const face& a, const face& b)
{
return face::compare(a,b) == 0;

View File

@ -162,8 +162,7 @@ inline Foam::Ostream& Foam::operator<<(Ostream& os, const labelledTri& t)
}
// Check state of Ostream
os.check("Ostream& operator<<(Ostream&, const labelledTri&)");
os.check(FUNCTION_NAME);
return os;
}

View File

@ -229,13 +229,16 @@ public:
// - -1: same face, but different orientation
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 incrementally.
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
template<>
class offsetOp<triFace>

View File

@ -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)
{

View File

@ -84,31 +84,18 @@ public:
// Member Functions
//- Is there a hit
bool hit() const
inline bool hit() const
{
return hit_;
}
//- Return hit object
label hitObject() const
inline label hitObject() const
{
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
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

View File

@ -487,14 +487,14 @@ void Foam::plane::writeDict(Ostream& os) const
os.endBlock() << flush;
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
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)
{
return !(a == b);

View File

@ -49,8 +49,6 @@ namespace Foam
// Forward declaration of friend functions and operators
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);
@ -193,7 +191,7 @@ public:
//- Return the cutting line between this plane and another.
// 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
point planePlaneIntersect
@ -217,12 +215,6 @@ public:
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
//- 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

View File

@ -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 * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const treeBoundBox& bb)

View File

@ -77,10 +77,6 @@ class Random;
// Forward declaration of friend functions and operators
class treeBoundBox;
bool operator==(const treeBoundBox& a, const treeBoundBox& b);
bool operator!=(const treeBoundBox& a, const treeBoundBox& b);
Istream& operator>>(Istream& is, treeBoundBox& bb);
Ostream& operator<<(Ostream& os, const treeBoundBox& bb);
@ -340,12 +336,6 @@ public:
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
friend Istream& operator>>(Istream& is, treeBoundBox& bb);
@ -358,6 +348,12 @@ template<>
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

View File

@ -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);
}
// ************************************************************************* //

View File

@ -70,9 +70,9 @@ public:
}
//- 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
@ -134,18 +134,20 @@ public:
}
// Comparison
//- Compare Pairs
// Returning:
// Returns:
// - 0: different
// - +1: identical
// - -1: same pair, but reversed order
// - +1: identical values and order used
// - -1: identical values, but in reversed order
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;
}
else if (a == reverse(b))
else if (a[0] == b[1] && a[1] == b[0])
{
return -1;
}
@ -157,6 +159,8 @@ public:
};
// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
template<class Type>
Pair<Type> reverse(const Pair<Type>& p)
{
@ -167,14 +171,14 @@ Pair<Type> reverse(const Pair<Type>& p)
template<class Type>
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>
bool operator!=(const Pair<Type>& a, const Pair<Type>& b)
{
return !(a == b);
return Pair<Type>::compare(a,b) == 0;
}

View File

@ -25,7 +25,9 @@ Class
Foam::Tuple2
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
Foam::Pair for storing two objects of identical types.
@ -48,10 +50,10 @@ template<class Type1, class Type2>
class Tuple2;
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>
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_;
Type2 s_;
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
//- Null constructor for lists
//- Null constructor for lists and hashes
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>
inline Istream& operator>>(Istream& is, Tuple2<Type1, Type2>& t2)
{

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -25,7 +25,9 @@ Class
Foam::nullObject
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
nullObjectI.H
@ -47,20 +49,41 @@ namespace Foam
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
NullObject()
:
null{nullptr}
{}
//- Disallow default bitwise copy construct
NullObject(const NullObject&);
NullObject(const NullObject&) = delete;
//- Disallow default bitwise assignment
void operator=(const NullObject&);
void operator=(const NullObject&) = delete;
public:
//- The unique null object
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;
}
};

View File

@ -29,7 +29,10 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::labelRange::debug(::Foam::debug::debugSwitch("labelRange", 0));
namespace Foam
{
int labelRange::debug(debug::debugSwitch("labelRange", 0));
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -49,11 +52,17 @@ void Foam::labelRange::adjust()
{
if (start_ < 0)
{
size_ += start_;
if (size_ <= 0)
{
size_ = 0;
}
else
{
size_ += start_;
}
start_ = 0;
}
if (size_ < 0)
else if (size_ < 0)
{
size_ = 0;
}
@ -62,22 +71,21 @@ void Foam::labelRange::adjust()
bool Foam::labelRange::overlaps(const labelRange& range, bool touches) const
{
const label final = touches ? 1 : 0;
const label extra = touches ? 1 : 0;
return
(
this->size()
&& range.size()
this->size() && range.size()
&&
(
(
range.first() >= this->first()
&& range.first() <= this->last() + final
&& range.first() <= this->last() + extra
)
||
(
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;
}
else if (!range.size_)
else if (!range.size())
{
return range;
}
const label lower = Foam::min(this->first(), range.first());
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 * * * * * * * * * * * * * //
void Foam::labelRange::operator+=(const labelRange& rhs)
Foam::labelRange Foam::labelRange::subset(const labelRange& range) const
{
if (!size_)
{
// trivial case
operator=(rhs);
}
else if (rhs.size_)
{
const label lower = Foam::min(this->first(), rhs.first());
const label upper = Foam::max(this->last(), rhs.last());
const label lower = Foam::max(this->first(), range.first());
const label upper = Foam::min(this->last(), range.last());
const label total = upper+1 - lower;
// last = start+size-1
// size = last+1-start
start_ = lower;
size_ = upper - lower + 1;
if (total > 0)
{
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
os << token::BEGIN_LIST
<< range.start_ << token::SPACE << range.size_
<< range.start() << token::SPACE << range.size()
<< token::END_LIST;
os.check("operator<<(Ostream&, const labelRange&)");

View File

@ -25,7 +25,7 @@ Class
Foam::labelRange
Description
A range of labels.
A range of labels defined by a start and a size.
SourceFiles
labelRange.C
@ -65,29 +65,25 @@ public:
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
class less
{
public:
//- The type that can represent the difference between two iterators
typedef label difference_type;
bool operator()(const labelRange& a, const labelRange& b)
{
return a.operator<(b);
}
};
//- The type that can represent the size of the range
typedef label size_type;
// Constructors
//- Construct an empty range with zero as start and size.
//- An empty range with zero for start/size.
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.
// Always reduce a negative size to zero.
inline labelRange
(
const label start,
@ -101,12 +97,21 @@ public:
// Member Functions
//- Alias for setSize(const label)
inline void resize(const label n);
//- Adjust start position
inline void setStart(const label i);
//- Adjust size
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
inline void clear();
@ -116,21 +121,29 @@ public:
//- Adjust the start to avoid any negative indices
void adjust();
//- Is the range valid (non-empty)?
//- Is the range non-empty?
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;
//- The (inclusive) lower value of the range
//- The (inclusive) lower value of the range - same as start
inline label first() const;
//- The (inclusive) upper value of the range
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.
// Always reduce a negative size to zero.
// Return true if the updated range valid (non-empty).
inline bool reset
(
@ -139,8 +152,8 @@ public:
const bool adjustStart = false
);
//- Return true if the value is within the range
inline bool contains(const label value) const;
//- Return true if the value is located the range
inline bool found(const label value) const;
//- Return true if the ranges overlap.
// 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.
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
//- Return element in range, no bounds checking
inline label operator[](const label i) const;
//- Return element in the range, no bounds checking
inline label operator[](const label localIndex) const;
//- Comparison function for sorting, compares the start.
// If the start values are equal, also compares the size.
inline bool operator<(const labelRange& rhs) const;
//- Increase the size by 1.
inline label operator++();
inline label operator++(int);
//- Join ranges, squashing any gaps in between
// A prior overlaps() check can be used to avoid squashing gaps.
void operator+=(const labelRange& rhs);
inline bool operator==(const labelRange& rhs) const;
inline bool operator!=(const labelRange& rhs) const;
//- Decrease the size by 1, but never below 0.
inline label operator--();
inline label operator--(int);
// STL iterator
//- An STL const_iterator
//- Forward iterator with const access
class const_iterator
{
friend class labelRange;
// 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
);
//- The current label (not the local index)
label index_;
public:
// Member operators
// Constructors
inline bool operator==(const const_iterator& iter) const;
inline bool operator!=(const const_iterator& iter) const;
//- Construct from range at given local index.
// A negative index signals the 'end' position
inline const_iterator(const labelRange* range, const label i = 0);
inline label operator*() const;
inline label operator()() const;
// Member operators
inline const_iterator& operator++();
inline const_iterator operator++(int);
//- Return the current label
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
// 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;
//- A const_iterator set to beyond the end of the range
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
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

View File

@ -60,42 +60,21 @@ inline Foam::labelRange::labelRange
inline Foam::labelRange::const_iterator::const_iterator
(
const labelRange& range,
const bool endIter
const labelRange* range,
const label i
)
:
range_(range),
index_(endIter ? range_.size() : 0)
index_
(
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
{
return range_[index_];
}
inline Foam::label Foam::labelRange::const_iterator::operator()() const
{
return range_[index_];
return 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
{
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
{
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 * * * * * * * * * * * * * //
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)
{
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)
{
size_ = 0;
}
inline void Foam::labelRange::increment()
{
++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
{
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
(
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 * * * * * * * * * * * * * //
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
(
this->first() < rhs.first()
|| (this->first() == rhs.first() && this->size() < rhs.size())
);
return ++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;
}

View File

@ -44,7 +44,7 @@ void Foam::labelRanges::insertBefore
<< *this << endl;
}
ParentType::setSize(nElem+1);
StorageContainer::setSize(nElem+1);
if (labelRange::debug)
{
@ -58,7 +58,7 @@ void Foam::labelRanges::insertBefore
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
@ -66,7 +66,7 @@ void Foam::labelRanges::insertBefore
{
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;
forAll(*this, elemI)
{
if (!ParentType::operator[](elemI).empty())
if (!StorageContainer::operator[](elemI).empty())
{
if (nElem != elemI)
{
ParentType::operator[](nElem) = ParentType::operator[](elemI);
StorageContainer::operator[](nElem) =
StorageContainer::operator[](elemI);
}
++nElem;
}
}
// 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
forAll(*this, elemI)
{
labelRange& currRange = ParentType::operator[](elemI);
labelRange& currRange = StorageContainer::operator[](elemI);
if (currRange.overlaps(range, true))
{
// absorb into the existing (adjacent/overlapping) range
currRange += range;
currRange.join(range);
// might connect with the next following range(s)
for (; elemI < this->size()-1; ++elemI)
{
labelRange& nextRange = ParentType::operator[](elemI+1);
labelRange& nextRange = StorageContainer::operator[](elemI+1);
if (currRange.overlaps(nextRange, true))
{
currRange += nextRange;
currRange.join(nextRange);
nextRange.clear();
}
else
@ -187,7 +188,7 @@ bool Foam::labelRanges::remove(const labelRange& range)
forAll(*this, elemI)
{
labelRange& currRange = ParentType::operator[](elemI);
labelRange& currRange = StorageContainer::operator[](elemI);
if (range.first() > currRange.first())
{
@ -290,14 +291,14 @@ bool Foam::labelRanges::remove(const labelRange& range)
Foam::Istream& Foam::operator>>(Istream& is, labelRanges& ranges)
{
is >> static_cast<labelRanges::ParentType&>(ranges);
is >> static_cast<labelRanges::StorageContainer&>(ranges);
return is;
}
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;
}

View File

@ -62,7 +62,7 @@ class labelRanges
{
// Private typedefs for convenience
typedef DynamicList<labelRange> ParentType;
typedef DynamicList<labelRange> StorageContainer;
// Private Member Functions
@ -99,8 +99,8 @@ public:
//- Return true if the list is empty
using DynamicList<labelRange>::empty;
//- Return true if the value is within any of the ranges
inline bool contains(const label value) const;
//- Return true if the value is found any of the sub-ranges
inline bool found(const label value) const;
//- Add the range to the list
bool add(const labelRange& range);
@ -116,38 +116,35 @@ public:
{
friend class labelRanges;
// Private data
// Private data
//- Reference to the list for which this is an iterator
const labelRanges& list_;
//- Reference to the list for which this is an iterator
const labelRanges* list_;
//- Current list index
label index_;
//- Current list-index
label index_;
//- Index of current element at listIndex
label subIndex_;
//- Index of current element at list-index
label subIndex_;
// Constructors
// Constructors
//- Construct from ranges at 'begin' or 'end' position
inline const_iterator
(
const labelRanges& lst,
const bool endIter = false
);
//- Construct from ranges at given index.
// A negative index signals the 'end' position
inline const_iterator(const labelRanges* lst, const label i);
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*();
inline label operator()();
//- Return the current label
inline label operator*();
inline const_iterator& operator++();
inline const_iterator operator++(int);
inline const_iterator& operator++();
inline const_iterator operator++(int);
};

View File

@ -28,13 +28,13 @@ License
inline Foam::labelRanges::labelRanges()
:
ParentType()
StorageContainer()
{}
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
(
const labelRanges& lst,
const bool endIter
const labelRanges* lst,
const label i
)
:
list_(lst),
index_(endIter ? lst.size() : 0),
index_(i < 0 ? lst->size() : i),
subIndex_(0)
{}
@ -76,20 +76,14 @@ inline bool Foam::labelRanges::const_iterator::operator!=
inline Foam::label Foam::labelRanges::const_iterator::operator*()
{
return list_[index_][subIndex_];
}
inline Foam::label Foam::labelRanges::const_iterator::operator()()
{
return list_[index_][subIndex_];
return list_->operator[](index_)[subIndex_];
}
inline Foam::labelRanges::const_iterator&
Foam::labelRanges::const_iterator::operator++()
{
if (++subIndex_ >= list_[index_].size())
if (++subIndex_ >= list_->operator[](index_).size())
{
// Next sub-list
++index_;
@ -111,35 +105,35 @@ Foam::labelRanges::const_iterator::operator++(int)
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
{
return const_iterator(*this, true);
return const_iterator(this, -1);
}
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
{
return const_iterator(*this, true);
return const_iterator(this, -1);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::labelRanges::contains(const label value) const
inline bool Foam::labelRanges::found(const label value) const
{
forAll(*this, i)
{
if (this->ParentType::operator[](i).contains(value))
if (StorageContainer::operator[](i).found(value))
{
return true;
}

View File

@ -28,7 +28,10 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::scalarRange::debug(::Foam::debug::debugSwitch("scalarRange", 0));
namespace Foam
{
int scalarRange::debug(debug::debugSwitch("scalarRange", 0));
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -47,11 +50,9 @@ Foam::scalarRange::scalarRange(const scalar lower, const scalar upper)
value_(lower),
value2_(upper)
{
// mark invalid range as empty
if (lower > upper)
{
type_ = EMPTY;
value_ = value2_ = 0;
clear(); // Mark invalid range as empty
}
}
@ -73,6 +74,14 @@ Foam::scalarRange::scalarRange(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::scalarRange::clear()
{
type_ = scalarRange::EMPTY;
value_ = 0;
value2_ = 0;
}
bool Foam::scalarRange::empty() const
{
return type_ == EMPTY;
@ -210,15 +219,14 @@ Foam::Istream& Foam::operator>>(Istream& is, scalarRange& range)
// a number is now required
if (!toks[nTok-1].isNumber())
{
is.setBad();
range.type_ = scalarRange::EMPTY;
range.value_ = range.value2_ = 0;
range.clear(); // Mark invalid range as empty
Info<< "rejected ill-formed or empty range:";
for (label i=0; i<nTok; ++i)
{
Info<< " " << toks[i];
}
Info<< endl;
is.setBad();
return is;
}
@ -245,15 +253,14 @@ Foam::Istream& Foam::operator>>(Istream& is, scalarRange& range)
{
if (range.type_ == scalarRange::UPPER)
{
is.setBad();
range.type_ = scalarRange::EMPTY;
range.value_ = range.value2_ = 0;
range.clear(); // Mark invalid range as empty
Info<< "rejected ill-formed range:";
for (label i=0; i<nTok; ++i)
{
Info<< " " << toks[i];
}
Info<< endl;
is.setBad();
return is;
}
@ -308,16 +315,15 @@ Foam::Istream& Foam::operator>>(Istream& is, scalarRange& range)
)
)
{
is.setBad();
range.type_ = scalarRange::EMPTY;
range.value_ = range.value2_ = 0;
range.clear(); // Mark invalid range as empty
Info<< "rejected ill-formed range:";
for (label i=0; i<nTok; ++i)
{
Info<< " " << toks[i];
}
Info<< endl;
is.setBad();
return is;
}
return is;

View File

@ -52,8 +52,8 @@ class Ostream;
// Forward declaration of friend functions and operators
class scalarRange;
Istream& operator>>(Istream&, scalarRange&);
Ostream& operator<<(Ostream&, const scalarRange&);
Istream& operator>>(Istream& is, scalarRange& range);
Ostream& operator<<(Ostream& os, const scalarRange& range);
/*---------------------------------------------------------------------------*\
@ -73,7 +73,7 @@ class scalarRange
};
// Private data
// Private Member Data
enum rangeType type_;
scalar value_;
@ -96,11 +96,14 @@ public:
//- Construct from Istream.
// Since commas can be used as list delimiters,
// leading and trailing commas are ignored.
scalarRange(Istream&);
scalarRange(Istream& is);
// Member Functions
//- Reset to an empty range.
void clear();
//- Is the range empty?
bool empty() const;
@ -121,19 +124,19 @@ public:
scalar upper() const;
//- Return true if the value is within the range
bool selected(const scalar) const;
bool selected(const scalar value) const;
// Member Operators
bool operator==(const scalarRange&) const;
bool operator!=(const scalarRange&) const;
bool operator==(const scalarRange& range) const;
bool operator!=(const scalarRange& range) const;
// IOstream Operators
friend Istream& operator>>(Istream&, scalarRange&);
friend Ostream& operator<<(Ostream&, const scalarRange&);
friend Istream& operator>>(Istream& is, scalarRange& range);
friend Ostream& operator<<(Ostream& os, const scalarRange& range);
};

View File

@ -72,7 +72,7 @@ bool Foam::scalarRanges::selected(const scalar value) const
Foam::List<bool> Foam::scalarRanges::selected
(
const List<scalar>& values
const UList<scalar>& values
) const
{
List<bool> lst(values.size(), false);

View File

@ -55,27 +55,28 @@ public:
// Constructors
//- Construct Null
//- Construct null
scalarRanges();
//- Construct from Istream.
// The list items are comma-delimited.
scalarRanges(Istream&);
scalarRanges(Istream& is);
// Member Functions
//- 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
// 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
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
void inplaceSelect(List<scalar>&) const;
void inplaceSelect(List<scalar>& values) const;
};

View File

@ -68,28 +68,28 @@ public:
// Member Functions
// Access
// Access
inline label size() const;
inline bool empty() const;
inline label size() const;
inline bool empty() const;
//- Return underlying list of wordRe
inline const UList<wordRe>& operator()() const;
//- Return underlying list of wordRe
inline const UList<wordRe>& operator()() const;
// Searching
// Searching
//- Return true if string matches any of the regular expressions
// Smart match as regular expression or as a string.
// Optionally specify a literal match only.
inline bool match(const string&, bool literalMatch=false) const;
//- Return true if string matches any of the regular expressions
// Smart match as regular expression or as a string.
// Optionally specify a literal match only.
inline bool match(const std::string&, bool literalMatch=false) const;
// Helpers
// Helpers
//- Return a wordReList with duplicate words filtered out.
// No filtering is done on regular expressions.
static wordReList uniq(const UList<wordRe>& input);
//- Return a wordReList with duplicate words filtered out.
// No filtering is done on regular expressions.
static wordReList uniq(const UList<wordRe>& input);
};

View File

@ -58,14 +58,14 @@ Foam::wordReListMatcher::operator()() const
inline bool Foam::wordReListMatcher::match
(
const string& str,
const std::string& text,
bool literalMatch
) const
{
const label nElem = reList_.size();
for (label elemI = 0; elemI < nElem; ++elemI)
const label n = reList_.size();
for (label i = 0; i < n; ++i)
{
if (reList_[elemI].match(str, literalMatch))
if (reList_[i].match(text, literalMatch))
{
return true;
}

View File

@ -63,9 +63,9 @@ class Ostream;
// Forward declaration of friend functions and operators
class string;
Istream& operator>>(Istream&, string&);
Ostream& operator<<(Ostream&, const string&);
Ostream& operator<<(Ostream&, const std::string&);
Istream& operator>>(Istream& is, string& s);
Ostream& operator<<(Ostream& os, const string& s);
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
size_type count(const char c) const;
//- Is this string type valid?
//- Does the string contain valid characters only?
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.
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
template<class String>
static inline bool stripInvalid(string& str);
static inline bool stripInvalid(std::string& str);
//- Return a valid String from the given 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
template<class String>
static inline string quotemeta
(
const string& str,
const std::string& str,
const char quote = '\\'
);
//- 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
using std::string::replace;

View File

@ -61,7 +61,7 @@ inline Foam::string::string(const char c)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
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)
{
@ -75,7 +75,7 @@ inline bool Foam::string::valid(const string& str)
template<class String>
inline bool Foam::string::stripInvalid(string& str)
inline bool Foam::string::stripInvalid(std::string& str)
{
if (!valid<String>(str))
{
@ -85,11 +85,11 @@ inline bool Foam::string::stripInvalid(string& str)
for
(
const_iterator iter1 = iter2;
iter1 != const_cast<const string&>(str).end();
iter1 != const_cast<const std::string&>(str).end();
iter1++
)
{
char c = *iter1;
const char c = *iter1;
if (String::valid(c))
{
@ -109,20 +109,21 @@ inline bool Foam::string::stripInvalid(string& str)
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;
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
}
else if (escaped)
{
escaped = false;
escaped = 0;
}
else if (String::meta(*iter))
else if (String::meta(c))
{
return true;
}
@ -133,7 +134,7 @@ inline bool Foam::string::meta(const string& str, const char quote)
template<class 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)
{
@ -146,7 +147,8 @@ Foam::string::quotemeta(const string& str, const char quote)
int escaped = 0;
for (const_iterator iter = str.begin(); iter != str.end(); ++iter)
{
if (*iter == quote)
const char c = *iter;
if (c == quote)
{
escaped ^= 1; // toggle state
}
@ -154,12 +156,12 @@ Foam::string::quotemeta(const string& str, const char quote)
{
escaped = 0;
}
else if (String::meta(*iter))
else if (String::meta(c))
{
sQuoted += quote;
}
sQuoted += *iter;
sQuoted += c;
}
sQuoted.resize(sQuoted.length());
@ -169,17 +171,17 @@ Foam::string::quotemeta(const string& str, const char quote)
template<class String>
inline String Foam::string::validate(const string& str)
inline String Foam::string::validate(const std::string& str)
{
string ss = str;
stripInvalid<String>(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
return (str == *this);
return (text == *this);
}

View File

@ -183,7 +183,7 @@ Foam::string& Foam::stringOps::inplaceExpand
HashTable<string, word, string::hash>::const_iterator fnd =
mapping.find(varName);
if (fnd != HashTable<string, word, string::hash>::end())
if (fnd.found())
{
if (altPos != string::npos && altType == '+')
{

View File

@ -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
(
const labelHashSet& globalCellMap,

View File

@ -177,6 +177,14 @@ public:
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.
void setLargeCellSubset
(

View File

@ -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
(
const labelHashSet& faceLabels
@ -99,12 +115,7 @@ Foam::labelHashSet Foam::motionSmootherAlgo::getPoints
forAllConstIter(labelHashSet, faceLabels, iter)
{
const face& f = mesh_.faces()[iter.key()];
forAll(f, fp)
{
usedPoints.insert(f[fp]);
}
usedPoints.insert(mesh_.faces()[iter.key()]);
}
return usedPoints;

View File

@ -209,7 +209,10 @@ class motionSmootherAlgo
static void checkFld(const pointScalarField&);
//- 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
tmp<scalarField> calcEdgeWeights(const pointField&) const;

View File

@ -42,7 +42,7 @@ defineTypeNameAndDebug(edgeCollapser, 0);
}
Foam::HashSet<Foam::label> Foam::edgeCollapser::checkBadFaces
Foam::labelHashSet Foam::edgeCollapser::checkBadFaces
(
const polyMesh& mesh,
const dictionary& meshQualityDict

View File

@ -263,7 +263,7 @@ public:
// Check
//- Calls motionSmoother::checkMesh and returns a set of bad faces
static HashSet<label> checkBadFaces
static labelHashSet checkBadFaces
(
const polyMesh& mesh,
const dictionary& meshQualityDict

View File

@ -178,7 +178,7 @@ bool Foam::functionObjects::ddt2::execute()
{
results_.clear();
wordHashSet candidates = subsetStrings(selectFields_, mesh_.names());
wordHashSet candidates(subsetStrings(selectFields_, mesh_.names()));
DynamicList<word> missing(selectFields_.size());
DynamicList<word> ignored(selectFields_.size());

View File

@ -135,7 +135,7 @@ bool Foam::functionObjects::zeroGradient::execute()
{
results_.clear();
wordHashSet candidates = subsetStrings(selectFields_, mesh_.names());
wordHashSet candidates(subsetStrings(selectFields_, mesh_.names()));
DynamicList<word> missing(selectFields_.size());
DynamicList<word> ignored(selectFields_.size());

View File

@ -246,7 +246,7 @@ bool Foam::functionObjects::ensightWrite::write()
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> ignored(selectFields_.size());

View File

@ -1352,6 +1352,12 @@ public:
const labelHashSet& set
) 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.
labelList growFaceCellFace
(

View File

@ -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.
Foam::labelList Foam::meshRefinement::growFaceCellFace
(
@ -798,29 +854,12 @@ Foam::labelList Foam::meshRefinement::growFaceCellFace
{
boolList selected(mesh_.nFaces(), false);
forAllConstIter(faceSet, set, iter)
forAllConstIter(labelHashSet, set, iter)
{
label faceI = iter.key();
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;
}
}
const label faceI = iter.key();
markGrowFaceCellFace(mesh_, faceI, selected);
}
syncTools::syncFaceList
(
mesh_,

View File

@ -30,22 +30,24 @@ License
Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
(
const dictionary& dict, const objectRegistry& obr
const dictionary& dict,
const objectRegistry& obr
)
{
if (debug)
{
Pout<< "coordinateRotation::New(const dictionary&) : "
Pout<< "coordinateRotation::New"
"(const dictionary&, const objectRegistry&) : "
<< "constructing coordinateRotation"
<< endl;
}
word rotType = dict.lookup("type");
const word rotType = dict.lookup("type");
objectRegistryConstructorTable::iterator cstrIter =
objectRegistryConstructorTablePtr_->find(rotType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
if (!cstrIter.found())
{
FatalIOErrorInFunction
(
@ -54,7 +56,7 @@ Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
<< rotType << nl << nl
<< "Valid coordinateRotation types are :" << nl
<< "[default: axes ]"
<< dictionaryConstructorTablePtr_->sortedToc()
<< objectRegistryConstructorTablePtr_->sortedToc()
<< exit(FatalIOError);
}
@ -74,12 +76,12 @@ Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
<< endl;
}
word rotType = dict.lookup("type");
const word rotType = dict.lookup("type");
dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(rotType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
if (!cstrIter.found())
{
FatalIOErrorInFunction
(

View File

@ -25,12 +25,16 @@ License
#include "edgeFaceCirculator.H"
#include "primitiveMesh.H"
#include "nullObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::edgeFaceCirculator Foam::edgeFaceCirculator::endConstIter
(
*reinterpret_cast<primitiveMesh*>(0), // primitiveMesh
*reinterpret_cast<const primitiveMesh*>
(
NullObject::nullObject.pointer() // nullptr dummy
),
-1, // faceLabel
false, // ownerSide
-1, // index

View File

@ -30,29 +30,26 @@ License
#include "addToRunTimeSelectionTable.H"
#include "mapDistributePolyMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(cellSet, 0);
addToRunTimeSelectionTable(topoSet, cellSet, word);
addToRunTimeSelectionTable(topoSet, cellSet, size);
addToRunTimeSelectionTable(topoSet, cellSet, set);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
cellSet::cellSet(const IOobject& obj)
Foam::cellSet::cellSet(const IOobject& obj)
:
topoSet(obj, typeName)
{}
cellSet::cellSet
Foam::cellSet::cellSet
(
const polyMesh& mesh,
const word& name,
@ -67,7 +64,7 @@ cellSet::cellSet
}
cellSet::cellSet
Foam::cellSet::cellSet
(
const polyMesh& mesh,
const word& name,
@ -79,7 +76,7 @@ cellSet::cellSet
{}
cellSet::cellSet
Foam::cellSet::cellSet
(
const polyMesh& mesh,
const word& name,
@ -91,7 +88,7 @@ cellSet::cellSet
{}
cellSet::cellSet
Foam::cellSet::cellSet
(
const polyMesh& mesh,
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)
cellSet::cellSet
Foam::cellSet::cellSet
(
const Time& runTime,
const word& name,
@ -114,32 +123,13 @@ cellSet::cellSet
:
topoSet
(
IOobject
(
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
),
findIOobject(runTime, name, r, w),
typeName
)
{}
cellSet::cellSet
Foam::cellSet::cellSet
(
const Time& runTime,
const word& name,
@ -149,32 +139,13 @@ cellSet::cellSet
:
topoSet
(
IOobject
(
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
),
findIOobject(runTime, name, IOobject::NO_READ, w),
size
)
{}
cellSet::cellSet
Foam::cellSet::cellSet
(
const Time& runTime,
const word& name,
@ -184,26 +155,7 @@ cellSet::cellSet
:
topoSet
(
IOobject
(
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
),
findIOobject(runTime, name, IOobject::NO_READ, w),
set
)
{}
@ -211,25 +163,25 @@ cellSet::cellSet
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
cellSet::~cellSet()
Foam::cellSet::~cellSet()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
label cellSet::maxSize(const polyMesh& mesh) const
Foam::label Foam::cellSet::maxSize(const polyMesh& mesh) const
{
return mesh.nCells();
}
void cellSet::updateMesh(const mapPolyMesh& morphMap)
void Foam::cellSet::updateMesh(const mapPolyMesh& morphMap)
{
updateLabels(morphMap.reverseCellMap());
}
void cellSet::distribute(const mapDistributePolyMesh& map)
void Foam::cellSet::distribute(const mapDistributePolyMesh& map)
{
boolList inSet(map.nOldCells());
forAllConstIter(cellSet, *this, iter)
@ -271,8 +223,4 @@ void Foam::cellSet::writeDebug
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -53,7 +53,7 @@ class cellSet
// Private Member Functions
//- Disallow default bitwise copy construct
cellSet(const cellSet&);
cellSet(const cellSet&) = delete;
public:
@ -81,7 +81,7 @@ public:
(
const polyMesh& mesh,
const word& name,
const label sizes,
const label size,
writeOption w=NO_WRITE
);
@ -90,7 +90,7 @@ public:
(
const polyMesh& mesh,
const word& name,
const topoSet&,
const topoSet& set,
writeOption w=NO_WRITE
);
@ -99,7 +99,16 @@ public:
(
const polyMesh& mesh,
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
);

View File

@ -31,29 +31,26 @@ License
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(faceSet, 0);
addToRunTimeSelectionTable(topoSet, faceSet, word);
addToRunTimeSelectionTable(topoSet, faceSet, size);
addToRunTimeSelectionTable(topoSet, faceSet, set);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
faceSet::faceSet(const IOobject& obj)
Foam::faceSet::faceSet(const IOobject& obj)
:
topoSet(obj, typeName)
{}
faceSet::faceSet
Foam::faceSet::faceSet
(
const polyMesh& mesh,
const word& name,
@ -67,7 +64,7 @@ faceSet::faceSet
}
faceSet::faceSet
Foam::faceSet::faceSet
(
const polyMesh& mesh,
const word& name,
@ -79,7 +76,7 @@ faceSet::faceSet
{}
faceSet::faceSet
Foam::faceSet::faceSet
(
const polyMesh& mesh,
const word& name,
@ -91,7 +88,7 @@ faceSet::faceSet
{}
faceSet::faceSet
Foam::faceSet::faceSet
(
const polyMesh& mesh,
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 * * * * * * * * * * * * * * * //
faceSet::~faceSet()
Foam::faceSet::~faceSet()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void faceSet::sync(const polyMesh& mesh)
void Foam::faceSet::sync(const polyMesh& mesh)
{
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();
}
void faceSet::updateMesh(const mapPolyMesh& morphMap)
void Foam::faceSet::updateMesh(const mapPolyMesh& morphMap)
{
updateLabels(morphMap.reverseFaceMap());
}
void faceSet::distribute(const mapDistributePolyMesh& map)
void Foam::faceSet::distribute(const mapDistributePolyMesh& map)
{
boolList inSet(map.nOldFaces());
forAllConstIter(faceSet, *this, iter)
@ -193,7 +202,7 @@ void faceSet::distribute(const mapDistributePolyMesh& map)
}
void faceSet::writeDebug
void Foam::faceSet::writeDebug
(
Ostream& os,
const primitiveMesh& mesh,
@ -204,8 +213,4 @@ void faceSet::writeDebug
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -51,7 +51,6 @@ class faceSet
public topoSet
{
public:
//- Runtime type information
@ -78,7 +77,7 @@ public:
(
const polyMesh& mesh,
const word& name,
const label,
const label size,
writeOption w=NO_WRITE
);
@ -87,7 +86,7 @@ public:
(
const polyMesh& mesh,
const word& name,
const topoSet&,
const topoSet& set,
writeOption w=NO_WRITE
);
@ -96,7 +95,16 @@ public:
(
const polyMesh& mesh,
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
);

View File

@ -28,32 +28,28 @@ License
#include "polyMesh.H"
#include "syncTools.H"
#include "mapDistributePolyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(pointSet, 0);
addToRunTimeSelectionTable(topoSet, pointSet, word);
addToRunTimeSelectionTable(topoSet, pointSet, size);
addToRunTimeSelectionTable(topoSet, pointSet, set);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
pointSet::pointSet(const IOobject& obj)
Foam::pointSet::pointSet(const IOobject& obj)
:
topoSet(obj, typeName)
{}
pointSet::pointSet
Foam::pointSet::pointSet
(
const polyMesh& mesh,
const word& name,
@ -67,7 +63,7 @@ pointSet::pointSet
}
pointSet::pointSet
Foam::pointSet::pointSet
(
const polyMesh& mesh,
const word& name,
@ -79,7 +75,7 @@ pointSet::pointSet
{}
pointSet::pointSet
Foam::pointSet::pointSet
(
const polyMesh& mesh,
const word& name,
@ -91,7 +87,7 @@ pointSet::pointSet
{}
pointSet::pointSet
Foam::pointSet::pointSet
(
const polyMesh& mesh,
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 * * * * * * * * * * * * * * * //
pointSet::~pointSet()
Foam::pointSet::~pointSet()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void pointSet::sync(const polyMesh& mesh)
void Foam::pointSet::sync(const polyMesh& mesh)
{
// 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();
}
void pointSet::updateMesh(const mapPolyMesh& morphMap)
void Foam::pointSet::updateMesh(const mapPolyMesh& morphMap)
{
updateLabels(morphMap.reversePointMap());
}
void pointSet::distribute(const mapDistributePolyMesh& map)
void Foam::pointSet::distribute(const mapDistributePolyMesh& map)
{
boolList inSet(map.nOldPoints());
forAllConstIter(pointSet, *this, iter)
@ -188,7 +196,7 @@ void pointSet::distribute(const mapDistributePolyMesh& map)
}
void pointSet::writeDebug
void Foam::pointSet::writeDebug
(
Ostream& os,
const primitiveMesh& mesh,
@ -198,8 +206,4 @@ void pointSet::writeDebug
topoSet::writeDebug(os, mesh.points(), maxLen);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -78,7 +78,16 @@ public:
(
const polyMesh& mesh,
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
);
@ -87,16 +96,16 @@ public:
(
const polyMesh& mesh,
const word& name,
const topoSet&,
const labelHashSet& set,
writeOption w=NO_WRITE
);
//- Construct from additional labelHashSet
//- Construct from additional list of labels for the labelHashSet
pointSet
(
const polyMesh& mesh,
const word& name,
const labelHashSet&,
const UList<label>& set,
writeOption w=NO_WRITE
);

Some files were not shown because too many files have changed in this diff Show More