Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop

This commit is contained in:
mattijs
2017-05-17 12:53:10 +01:00
43 changed files with 911 additions and 505 deletions

View File

@ -56,7 +56,6 @@ int main(int argc, char *argv[])
Info<< "element:" << *iter << endl; Info<< "element:" << *iter << endl;
} }
Info<< nl << "And again using the same STL iterator: " << nl << endl; Info<< nl << "And again using the same STL iterator: " << nl << endl;
forAllIters(myList, iter) forAllIters(myList, iter)

View File

@ -36,14 +36,9 @@ void printTable(const HashPtrTable<T>& table)
{ {
Info<< table.size() << nl << "(" << nl; Info<< table.size() << nl << "(" << nl;
for forAllConstIters(table, iter)
(
typename HashPtrTable<T>::const_iterator iter = table.cbegin();
iter != table.cend();
++iter
)
{ {
const T* ptr = *iter; const T* ptr = iter.object();
Info<< iter.key() << " = "; Info<< iter.key() << " = ";
if (ptr) if (ptr)
{ {
@ -57,6 +52,22 @@ void printTable(const HashPtrTable<T>& table)
} }
Info<< ")" << endl; Info<< ")" << endl;
// Values only, with for-range
Info<< "values (";
for (auto val : table)
{
Info<< ' ';
if (val)
{
Info<< *val;
}
else
{
Info<< "nullptr";
}
}
Info<< " )" << nl;
} }
@ -68,7 +79,9 @@ int main()
HashPtrTable<double> myTable; HashPtrTable<double> myTable;
myTable.insert("abc", new double(42.1)); myTable.insert("abc", new double(42.1));
myTable.insert("def", nullptr); myTable.insert("def", nullptr);
myTable.insert("ghi", new double(3.14159)); myTable.insert("pi", new double(3.14159));
myTable.insert("natlog", new double(2.718282));
myTable.insert("sqrt2", new double(1.414214));
// Info<< myTable << endl; // Info<< myTable << endl;
printTable(myTable); printTable(myTable);
@ -79,8 +92,20 @@ int main()
printTable(copy); printTable(copy);
Info<< copy << endl; Info<< copy << endl;
Info<<"\nerase some existing and non-existing entries" << nl;
auto iter = myTable.find("pi");
myTable.erase(iter);
iter = myTable.find("unknownKey");
myTable.erase(iter);
myTable.erase("abc");
myTable.erase("unknownKey");
printTable(myTable);
return 0; return 0;
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -197,8 +197,12 @@ int main(int argc, char *argv[])
Info<< "setD has no 11" << endl; Info<< "setD has no 11" << endl;
} }
Info<< "setB : " << flatOutput(setB) << endl;
Info<< "setD : " << flatOutput(setD) << endl; Info<< "setD : " << flatOutput(setD) << endl;
setD -= setB;
Info<< "setD -= setB : " << flatOutput(setD) << endl;
// This should not work (yet?) // This should not work (yet?)
// setD[12] = true; // setD[12] = true;

View File

@ -25,6 +25,9 @@ License
#include "HashTable.H" #include "HashTable.H"
#include "List.H" #include "List.H"
#include "SortableList.H"
#include "DynamicList.H"
#include "FlatOutput.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "OStringStream.H" #include "OStringStream.H"
@ -163,15 +166,15 @@ int main()
<< "\ntable2" << table2 << nl; << "\ntable2" << table2 << nl;
Info<< "\ntable3" << table3 Info<< "\ntable3" << table2
<< "\nclearStorage table3 ... "; << "\nclearStorage table2 ... ";
table3.clearStorage(); table2.clearStorage();
Info<< table3 << nl; Info<< table2 << nl;
table1 = table1 =
{ {
{"aca", 3.0}, {"abc", 3.0},
{"aaw", 6.0}, {"def", 6.0},
{"acr", 8.0}, {"acr", 8.0},
{"aec", 10.0} {"aec", 10.0}
}; };
@ -193,7 +196,43 @@ int main()
// These do not yet work. Issues resolving the distance. // These do not yet work. Issues resolving the distance.
// //
// List<scalar> table1vals(table1.begin(), table1.end()); // List<scalar> table1vals(table1.begin(), table1.end());
// wordList table1keys(table1.begin(), table1.end());
{
Info<<"distance/size: "
<< std::distance(table1.begin(), table1.end())
<< "/" << table1.size()
<< " and "
<< std::distance(table1.keys().begin(), table1.keys().end())
<< "/" << table1.keys().size()
<< nl;
SortableList<word> sortKeys
// DynamicList<word> sortKeys
(
table1.keys().begin(),
table1.keys().end()
);
Info<<"sortKeys: " << flatOutput(sortKeys) << nl;
}
Info<< "\nFrom table1: " << flatOutput(table1.sortedToc()) << nl
<< "retain keys: " << flatOutput(table3.sortedToc()) << nl;
table1.retain(table3);
Info<< "-> " << flatOutput(table1.sortedToc()) << nl;
Info<< "Lookup non-existent" << nl;
Info<< table1.lookup("missing-const", 1.2345e+6)
<< " // const-access" << nl;
Info<< table1("missing-inadvertent", 3.14159)
<< " // (inadvertent?) non-const access" << nl;
Info<< table1("missing-autovivify")
<< " // Known auto-vivification (non-const access)" << nl;
Info<<"\ntable1: " << table1 << endl;
Info<< "\nDone\n"; Info<< "\nDone\n";

View File

@ -42,6 +42,7 @@ See also
#include "vector.H" #include "vector.H"
#include "labelRange.H" #include "labelRange.H"
#include "scalarList.H"
#include "ListOps.H" #include "ListOps.H"
#include "SubList.H" #include "SubList.H"
@ -144,6 +145,18 @@ int main(int argc, char *argv[])
labelList longLabelList = identity(15); labelList longLabelList = identity(15);
// This does not work:
// scalarList slist = identity(15);
//
// More writing, but does work:
scalarList slist
(
labelRange::null.begin(),
labelRange::identity(15).end()
);
Info<<"scalar identity:" << flatOutput(slist) << endl;
Info<< "labels (contiguous=" << contiguous<label>() << ")" << nl; Info<< "labels (contiguous=" << contiguous<label>() << ")" << nl;
Info<< "normal: " << longLabelList << nl; Info<< "normal: " << longLabelList << nl;
@ -220,7 +233,32 @@ int main(int argc, char *argv[])
} }
Info<< "sub-sorted: " << flatOutput(longLabelList) << nl; Info<< "sub-sorted: " << flatOutput(longLabelList) << nl;
// Info<<"Slice=" << longLabelList[labelRange(23,5)] << nl; // construct from a label-range
labelRange range(25,15);
labelList ident(range.begin(), range.end());
Info<<"range-list (label)=" << ident << nl;
List<scalar> sident(range.begin(), range.end());
Info<<"range-list (scalar)=" << sident << nl;
// Sub-ranges also work
List<scalar> sident2(range(3), range(10));
Info<<"range-list (scalar)=" << sident2 << nl;
// VERY BAD IDEA: List<scalar> sident3(range(10), range(3));
// This doesn't work, and don't know what it should do anyhow
// List<vector> vident(range.begin(), range.end());
// Info<<"range-list (vector)=" << vident << nl;
// Even weird things like this
List<scalar> sident4
(
labelRange().begin(),
labelRange::identity(8).end()
);
Info<<"range-list (scalar)=" << sident4 << nl;
} }
wordReList reLst; wordReList reLst;

View File

@ -58,7 +58,7 @@ int main(int argc, char *argv[])
Info<<"test sorting" << endl; Info<<"test sorting" << endl;
DynamicList<labelRange> list1(10); DynamicList<labelRange> list1(10);
list1.append(labelRange(25, 8)); list1.append(labelRange(25, 8));
list1.append(labelRange(0, 10)); list1.append(labelRange::identity(8));
list1.append(labelRange(15, 5)); list1.append(labelRange(15, 5));
list1.append(labelRange(50, -10)); list1.append(labelRange(50, -10));

View File

@ -72,15 +72,22 @@ Foam::HashPtrTable<T, Key, Hash>::~HashPtrTable()
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter) T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
{ {
if (iter.found())
{
T* ptr = iter.object(); T* ptr = iter.object();
this->parent_type::erase(iter); this->parent_type::erase(iter);
return ptr; return ptr;
}
return nullptr;
} }
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter) bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
{ {
if (iter.found())
{
T* ptr = iter.object(); T* ptr = iter.object();
if (this->parent_type::erase(iter)) if (this->parent_type::erase(iter))
@ -92,10 +99,17 @@ bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
return true; return true;
} }
else
{
return false;
} }
return false;
}
template<class T, class Key, class Hash>
bool Foam::HashPtrTable<T, Key, Hash>::erase(const Key& key)
{
auto iter = this->find(key);
return this->erase(iter);
} }

View File

@ -116,12 +116,17 @@ public:
// Edit // Edit
//- Remove and return the pointer specified by given iterator //- Remove and return the pointer specified by given iterator.
// Includes a safeguard against the end-iterator.
T* remove(iterator& iter); T* remove(iterator& iter);
//- Erase an hashedEntry specified by given iterator //- Erase an entry specified by given iterator
// Includes a safeguard against the end-iterator.
bool erase(iterator& iter); bool erase(iterator& iter);
//- Erase an entry specified by the given key
bool erase(const Key& key);
//- Clear all entries from table //- Clear all entries from table
void clear(); void clear();

View File

@ -227,16 +227,9 @@ void Foam::HashSet<Key, Hash>::operator|=(const HashSet<Key, Hash>& rhs)
template<class Key, class Hash> template<class Key, class Hash>
void Foam::HashSet<Key, Hash>::operator&=(const HashSet<Key, Hash>& rhs) inline void Foam::HashSet<Key, Hash>::operator&=(const HashSet<Key, Hash>& rhs)
{ {
// Remove elements not also found in rhs this->parent_type::retain(rhs);
for (iterator iter = this->begin(); iter != this->end(); ++iter)
{
if (!rhs.found(iter.key()))
{
this->erase(iter);
}
}
} }
@ -259,13 +252,9 @@ void Foam::HashSet<Key, Hash>::operator^=(const HashSet<Key, Hash>& rhs)
template<class Key, class Hash> template<class Key, class Hash>
void Foam::HashSet<Key, Hash>::operator-=(const HashSet<Key, Hash>& rhs) inline void Foam::HashSet<Key, Hash>::operator-=(const HashSet<Key, Hash>& rhs)
{ {
// Remove rhs elements from lhs this->parent_type::erase(rhs);
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
this->erase(iter.key());
}
} }

View File

@ -277,7 +277,7 @@ public:
void operator|=(const HashSet<Key, Hash>& rhs); void operator|=(const HashSet<Key, Hash>& rhs);
//- Only retain entries found in both HashSets //- Only retain entries found in both HashSets
void operator&=(const HashSet<Key, Hash>& rhs); inline void operator&=(const HashSet<Key, Hash>& rhs);
//- Only retain unique entries (xor) //- Only retain unique entries (xor)
void operator^=(const HashSet<Key, Hash>& rhs); void operator^=(const HashSet<Key, Hash>& rhs);
@ -289,7 +289,7 @@ public:
} }
//- Remove entries listed in the given HashSet from this HashSet //- Remove entries listed in the given HashSet from this HashSet
void operator-=(const HashSet<Key, Hash>& rhs); inline void operator-=(const HashSet<Key, Hash>& rhs);
// IOstream Operator // IOstream Operator

View File

@ -257,7 +257,7 @@ template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::set bool Foam::HashTable<T, Key, Hash>::set
( (
const Key& key, const Key& key,
const T& newEntry, const T& obj,
const bool protect const bool protect
) )
{ {
@ -284,7 +284,7 @@ bool Foam::HashTable<T, Key, Hash>::set
if (!existing) if (!existing)
{ {
// Not found, insert it at the head // Not found, insert it at the head
table_[hashIdx] = new hashedEntry(key, newEntry, table_[hashIdx]); table_[hashIdx] = new hashedEntry(key, obj, table_[hashIdx]);
nElmts_++; nElmts_++;
if (double(nElmts_)/tableSize_ > 0.8 && tableSize_ < maxTableSize) if (double(nElmts_)/tableSize_ > 0.8 && tableSize_ < maxTableSize)
@ -316,7 +316,7 @@ bool Foam::HashTable<T, Key, Hash>::set
{ {
// Found - overwrite existing entry // Found - overwrite existing entry
// this corresponds to the Perl convention // this corresponds to the Perl convention
hashedEntry* ep = new hashedEntry(key, newEntry, existing->next_); hashedEntry* ep = new hashedEntry(key, obj, existing->next_);
// Replace existing element - within list or insert at the head // Replace existing element - within list or insert at the head
if (prev) if (prev)
@ -411,7 +411,8 @@ bool Foam::HashTable<T, Key, Hash>::erase(const iterator& iter)
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::erase(const Key& key) bool Foam::HashTable<T, Key, Hash>::erase(const Key& key)
{ {
return erase(find(key)); auto iter = find(key);
return erase(iter);
} }
@ -450,16 +451,16 @@ Foam::label Foam::HashTable<T, Key, Hash>::erase
const HashTable<AnyType, Key, AnyHash>& other const HashTable<AnyType, Key, AnyHash>& other
) )
{ {
// Remove other keys from this table
const label nTotal = this->size(); const label nTotal = this->size();
label changed = 0; label changed = 0;
if (other.size() < nTotal)
{
// other is smaller, use its keys for removal
using other_iter = using other_iter =
typename HashTable<AnyType, Key, AnyHash>::const_iterator; typename HashTable<AnyType, Key, AnyHash>::const_iterator;
if (other.size() <= nTotal)
{
// The other is smaller/same-size, use its keys for removal
for for
( (
other_iter iter = other.begin(); other_iter iter = other.begin();
@ -475,7 +476,7 @@ Foam::label Foam::HashTable<T, Key, Hash>::erase
} }
else else
{ {
// other is same/larger: iterate ourselves and check for key in other // We are smaller: remove if found in the other hash
for for
( (
iterator iter = begin(); iterator iter = begin();
@ -494,6 +495,39 @@ Foam::label Foam::HashTable<T, Key, Hash>::erase
} }
template<class T, class Key, class Hash>
template<class AnyType, class AnyHash>
Foam::label Foam::HashTable<T, Key, Hash>::retain
(
const HashTable<AnyType, Key, AnyHash>& other
)
{
const label nTotal = this->size();
label changed = 0;
if (other.empty())
{
// Trivial case
changed = nTotal;
this->clear();
}
else
{
// Inverted logic: remove if *not* found in the other hash
for (iterator iter = begin(); iter != end(); ++iter)
{
if (!other.found(iter.key()) && erase(iter))
{
++changed;
}
}
}
return changed;
}
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
void Foam::HashTable<T, Key, Hash>::resize(const label sz) void Foam::HashTable<T, Key, Hash>::resize(const label sz)
{ {

View File

@ -44,6 +44,7 @@ Note
SourceFiles SourceFiles
HashTableI.H HashTableI.H
HashTable.C HashTable.C
HashTableCoreI.H
HashTableCore.C HashTableCore.C
HashTableIO.C HashTableIO.C
@ -60,6 +61,7 @@ SourceFiles
#include "nullObject.H" #include "nullObject.H"
#include <initializer_list> #include <initializer_list>
#include <iterator>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -178,10 +180,17 @@ public:
//- Type of values that the HashTable contains. //- Type of values that the HashTable contains.
typedef T value_type; typedef T value_type;
//- The type used for storing into value_type objects.
// This type is usually value_type&.
typedef T* pointer;
//- The type used for storing into value_type objects. //- The type used for storing into value_type objects.
// This type is usually value_type&. // This type is usually value_type&.
typedef T& reference; typedef T& reference;
//- The type used for reading from constant value_type objects.
typedef const T* const_pointer;
//- The type used for reading from constant value_type objects. //- The type used for reading from constant value_type objects.
typedef const T& const_reference; typedef const T& const_reference;
@ -247,7 +256,7 @@ private:
//- Assign a new hash-entry 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. // Return true if the new entry was set.
bool set(const Key& key, const T& newEntry, const bool protect); bool set(const Key& key, const T& obj, const bool protect);
protected: protected:
@ -307,17 +316,20 @@ public:
//- Return true if the hash table is empty //- Return true if the hash table is empty
inline bool empty() const; inline bool empty() const;
//- Return true if hashedEntry is found in table //- Return true if hashed entry is found in table
bool found(const Key& key) const; bool found(const Key& key) const;
//- Find and return an iterator set at the hashedEntry //- Find and return an iterator set at the hashed entry
// If not found iterator = end() // If not found iterator = end()
iterator find(const Key& key); iterator find(const Key& key);
//- Find and return an const_iterator set at the hashedEntry //- Find and return an const_iterator set at the hashed entry
// If not found iterator = end() // If not found iterator = end()
const_iterator find(const Key& key) const; const_iterator find(const Key& key) const;
//- Return hashed entry if it exists, or return the given default
inline const T& lookup(const Key& key, const T& deflt) const;
//- Return the table of contents //- Return the table of contents
List<Key> toc() const; List<Key> toc() const;
@ -327,42 +339,58 @@ public:
// Edit // Edit
//- Insert a new hashedEntry //- Insert a new entry
// Return true if the entry inserted, which means that it did // Return true if the entry inserted, which means that it did
// not previously exist in the table. // not previously exist in the table.
inline bool insert(const Key& key, const T& newEntry); inline bool insert(const Key& key, const T& obj);
//- Assign a new hashedEntry, overwriting existing entries. //- Assign a new entry, overwriting existing entries.
// Returns true. // Returns true.
inline bool set(const Key& key, const T& newEntry); inline bool set(const Key& key, const T& obj);
//- Erase a hashedEntry specified by given iterator //- Erase an entry specified by given iterator
// This invalidates the iterator until the next ++ operation // This invalidates the iterator until the next ++ operation.
//
// Includes a safeguard against the end-iterator such that the
// following is safe:
// \code
// auto iter = table.find(unknownKey);
// table.erase(iter);
// \endcode
// which is what \code table.erase(unknownKey) \endcode does anyhow
bool erase(const iterator& iter); bool erase(const iterator& iter);
//- Erase a hashedEntry specified by the given key //- Erase an entry specified by the given key
bool erase(const Key& key); bool erase(const Key& key);
//- Remove entries given by the listed keys from this HashTable //- Remove table entries given by the listed keys
// Return the number of elements removed // Return the number of elements removed
label erase(const UList<Key>& keys); label erase(const UList<Key>& keys);
//- Remove entries given by the listed keys from this HashTable //- Remove table entries given by the listed keys
// Return the number of elements removed // Return the number of elements removed
template<unsigned Size> template<unsigned Size>
label erase(const FixedList<Key, Size>& keys); label erase(const FixedList<Key, Size>& keys);
//- Remove entries given by the listed keys from this HashTable //- Remove table entries given by the listed keys
// Return the number of elements removed // Return the number of elements removed
label erase(std::initializer_list<Key> keys); label erase(std::initializer_list<Key> keys);
//- Remove entries given by the given keys from this HashTable //- Remove table entries given by keys of the other hash-table.
// Return the number of elements removed. // Return the number of elements removed.
// The parameter HashTable needs the same type of key, but the //
// The other hash-table must have the same type of key, but the
// type of values held and the hashing function are arbitrary. // type of values held and the hashing function are arbitrary.
template<class AnyType, class AnyHash> template<class AnyType, class AnyHash>
label erase(const HashTable<AnyType, Key, AnyHash>& other); label erase(const HashTable<AnyType, Key, AnyHash>& other);
//- Retain table entries given by keys of the other hash-table.
//
// The other hash-table must have the same type of key, but the
// type of values held and the hashing function are arbitrary.
template<class AnyType, class AnyHash>
label retain(const HashTable<AnyType, Key, AnyHash>& other);
//- Resize the hash table for efficiency //- Resize the hash table for efficiency
void resize(const label sz); void resize(const label sz);
@ -383,10 +411,10 @@ public:
// Member Operators // Member Operators
//- Find and return a hashedEntry //- Find and return a hashed entry. FatalError if it does not exist.
inline T& operator[](const Key& key); inline T& operator[](const Key& key);
//- Find and return a hashedEntry //- Find and return a hashed entry. FatalError if it does not exist.
inline const T& operator[](const Key& key) const; inline const T& operator[](const Key& key) const;
//- Return existing entry or create a new entry. //- Return existing entry or create a new entry.
@ -394,6 +422,12 @@ public:
// value-initialized. For primitives, this will be zero. // value-initialized. For primitives, this will be zero.
inline T& operator()(const Key& key); inline T& operator()(const Key& key);
//- Return existing entry or insert a new entry.
inline T& operator()(const Key& key, const T& deflt);
//- Return hashed entry if it exists, or return the given default
inline const T& operator()(const Key& key, const T& deflt) const;
//- Assignment //- Assignment
void operator=(const HashTable<T, Key, Hash>& rhs); void operator=(const HashTable<T, Key, Hash>& rhs);
@ -423,6 +457,7 @@ protected:
// Public typedefs // Public typedefs
using table_type = this_type; using table_type = this_type;
using key_type = this_type::key_type; using key_type = this_type::key_type;
using iterator_category = std::forward_iterator_tag;
using difference_type = this_type::difference_type; using difference_type = this_type::difference_type;
private: private:
@ -500,16 +535,20 @@ public:
public WrappedIterator public WrappedIterator
{ {
public: public:
using value_type = this_type::key_type;
using pointer = const Key*;
using reference = const Key&; using reference = const Key&;
using difference_type = typename WrappedIterator::difference_type;
//- Implicit conversion //- Implicit conversion
inline key_iterator_base(const WrappedIterator& iter); inline key_iterator_base(const WrappedIterator& iter);
//- Return the key //- Return the key
inline reference operator*() const; inline reference operator*() const;
}; inline reference operator()() const;
inline key_iterator_base& operator++();
inline key_iterator_base operator++(int);
};
// STL iterator // STL iterator
@ -526,9 +565,9 @@ public:
// Public typedefs // Public typedefs
using table_type = this_type; using table_type = this_type;
using key_type = this_type::key_type; using value_type = this_type::value_type;
using pointer = this_type::pointer;
using reference = this_type::reference; using reference = this_type::reference;
using difference_type = typename iterator_base::difference_type;
// Constructors // Constructors
@ -574,9 +613,9 @@ public:
// Public typedefs // Public typedefs
using table_type = const this_type; using table_type = const this_type;
using key_type = this_type::key_type; using value_type = const this_type::value_type;
using pointer = this_type::const_pointer;
using reference = this_type::const_reference; using reference = this_type::const_reference;
using difference_type = typename iterator_base::difference_type;
// Constructors // Constructors

View File

@ -79,10 +79,10 @@ template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::insert inline bool Foam::HashTable<T, Key, Hash>::insert
( (
const Key& key, const Key& key,
const T& newEntry const T& obj
) )
{ {
return this->set(key, newEntry, true); return this->set(key, obj, true);
} }
@ -90,10 +90,10 @@ template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::set inline bool Foam::HashTable<T, Key, Hash>::set
( (
const Key& key, const Key& key,
const T& newEntry const T& obj
) )
{ {
return this->set(key, newEntry, false); return this->set(key, obj, false);
} }
@ -105,6 +105,18 @@ Foam::HashTable<T, Key, Hash>::xfer()
} }
template<class T, class Key, class Hash>
inline const T& Foam::HashTable<T, Key, Hash>::lookup
(
const Key& key,
const T& deflt
) const
{
const_iterator iter = this->find(key);
return iter.found() ? iter.object() : deflt;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
@ -156,6 +168,36 @@ inline T& Foam::HashTable<T, Key, Hash>::operator()(const Key& key)
} }
template<class T, class Key, class Hash>
inline T& Foam::HashTable<T, Key, Hash>::operator()
(
const Key& key,
const T& deflt
)
{
iterator iter = this->find(key);
if (iter.found())
{
return iter.object();
}
this->insert(key, deflt);
return find(key).object();
}
template<class T, class Key, class Hash>
inline const T& Foam::HashTable<T, Key, Hash>::operator()
(
const Key& key,
const T& deflt
) const
{
return this->lookup(key, deflt);
}
// * * * * * * * * * * * * * * * iterator base * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * iterator base * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
@ -321,6 +363,39 @@ Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
} }
template<class T, class Key, class Hash>
template<class WrappedIterator>
inline const Key&
Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
::operator()() const
{
return this->key();
}
template<class T, class Key, class Hash>
template<class WrappedIterator>
inline Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>&
Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
::operator++()
{
this->increment();
return *this;
}
template<class T, class Key, class Hash>
template<class WrappedIterator>
inline Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
::operator++(int)
{
key_iterator_base old = *this;
this->increment();
return old;
}
// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
template<class T, class Key, class Hash> template<class T, class Key, class Hash>

View File

@ -203,7 +203,7 @@ template<class T, class Key, class Hash>
bool Foam::StaticHashTable<T, Key, Hash>::set bool Foam::StaticHashTable<T, Key, Hash>::set
( (
const Key& key, const Key& key,
const T& newEntry, const T& obj,
const bool protect const bool protect
) )
{ {
@ -229,7 +229,7 @@ bool Foam::StaticHashTable<T, Key, Hash>::set
localObjects.setSize(existing+1); localObjects.setSize(existing+1);
localKeys[existing] = key; localKeys[existing] = key;
localObjects[existing] = newEntry; localObjects[existing] = obj;
nElmts_++; nElmts_++;
} }
@ -250,7 +250,7 @@ bool Foam::StaticHashTable<T, Key, Hash>::set
{ {
// Found - overwrite existing entry // Found - overwrite existing entry
// this corresponds to the Perl convention // this corresponds to the Perl convention
objects_[hashIdx][existing] = newEntry; objects_[hashIdx][existing] = obj;
} }
return true; return true;

View File

@ -121,10 +121,10 @@ class StaticHashTable
//- Return the hash index of the Key within the current table size. //- Return the hash index of the Key within the current table size.
// No checks for zero-sized tables. // No checks for zero-sized tables.
inline label hashKeyIndex(const Key&) const; inline label hashKeyIndex(const Key& key) const;
//- Assign a new hashed entry to a possibly already existing key //- Assign a new hashed entry to a possibly already existing key
bool set(const Key&, const T& newElmt, bool protect); bool set(const Key& key, const T& obj, bool protect);
public: public:

View File

@ -26,8 +26,6 @@ License
#include "error.H" #include "error.H"
#include "IOstreams.H" #include "IOstreams.H"
// * * * * * * * * * * * * * Private Member Classes * * * * * * * * * * * * //
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
@ -59,10 +57,10 @@ template<class T, class Key, class Hash>
inline bool Foam::StaticHashTable<T, Key, Hash>::insert inline bool Foam::StaticHashTable<T, Key, Hash>::insert
( (
const Key& key, const Key& key,
const T& newEntry const T& obj
) )
{ {
return set(key, newEntry, true); return set(key, obj, true);
} }
@ -70,10 +68,10 @@ template<class T, class Key, class Hash>
inline bool Foam::StaticHashTable<T, Key, Hash>::set inline bool Foam::StaticHashTable<T, Key, Hash>::set
( (
const Key& key, const Key& key,
const T& newEntry const T& obj
) )
{ {
return set(key, newEntry, false); return set(key, obj, false);
} }

View File

@ -254,14 +254,14 @@ public:
// Member operators // Member operators
T& operator*() T& operator*() const
{ {
return return
static_cast<link&> static_cast<link&>
(LListBase_iterator::operator*()).obj_; (LListBase_iterator::operator*()).obj_;
} }
T& operator()() T& operator()() const
{ {
return operator*(); return operator*();
} }
@ -312,14 +312,14 @@ public:
// Member operators // Member operators
const T& operator*() const T& operator*() const
{ {
return return
static_cast<const link&> static_cast<const link&>
(LListBase_const_iterator::operator*()).obj_; (LListBase_const_iterator::operator*()).obj_;
} }
const T& operator()() const T& operator()() const
{ {
return operator*(); return operator*();
} }

View File

@ -196,12 +196,12 @@ public:
// Member operators // Member operators
T& operator*() T& operator*() const
{ {
return *(LList<LListBase, T*>::iterator::operator*()); return *(LList<LListBase, T*>::iterator::operator*());
} }
T& operator()() T& operator()() const
{ {
return operator*(); return operator*();
} }
@ -235,12 +235,12 @@ public:
// Member operators // Member operators
const T& operator*() const T& operator*() const
{ {
return *(LList<LListBase, T*>::const_iterator::operator*()); return *(LList<LListBase, T*>::const_iterator::operator*());
} }
const T& operator()() const T& operator()() const
{ {
return operator*(); return operator*();
} }

View File

@ -192,12 +192,12 @@ public:
// Member operators // Member operators
T& operator*() T& operator*() const
{ {
return static_cast<T&>(LListBase_iterator::operator*()); return static_cast<T&>(LListBase_iterator::operator*());
} }
T& operator()() T& operator()() const
{ {
return operator*(); return operator*();
} }
@ -247,14 +247,14 @@ public:
// Member operators // Member operators
const T& operator*() const T& operator*() const
{ {
return return
static_cast<const T&> static_cast<const T&>
(LListBase_const_iterator::operator*()); (LListBase_const_iterator::operator*());
} }
const T& operator()() const T& operator()() const
{ {
return operator*(); return operator*();
} }
@ -309,14 +309,14 @@ public:
// Member operators // Member operators
const T& operator*() const T& operator*() const
{ {
return return
static_cast<const T&> static_cast<const T&>
(LListBase::const_reverse_iterator::operator*()); (LListBase::const_reverse_iterator::operator*());
} }
const T& operator()() const T& operator()() const
{ {
return operator*(); return operator*();
} }

View File

@ -188,7 +188,7 @@ Foam::DLListBase::link* Foam::DLListBase::removeHead()
if (!first_) if (!first_)
{ {
last_ = 0; last_ = nullptr;
} }
f->deregister(); f->deregister();
@ -204,8 +204,8 @@ Foam::DLListBase::link* Foam::DLListBase::remove(DLListBase::link* l)
if (l == first_ && first_ == last_) if (l == first_ && first_ == last_)
{ {
first_ = 0; first_ = nullptr;
last_ = 0; last_ = nullptr;
} }
else if (l == first_) else if (l == first_)
{ {

View File

@ -25,9 +25,10 @@ Class
Foam::DLListBase Foam::DLListBase
Description Description
Base doubly-linked list. Base for doubly-linked lists.
SourceFiles SourceFiles
DLListBaseI.H
DLListBase.C DLListBase.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -84,10 +85,10 @@ private:
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
DLListBase(const DLListBase&); DLListBase(const DLListBase&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const DLListBase&); void operator=(const DLListBase&) = delete;
public: public:
@ -184,8 +185,6 @@ public:
friend class DLListBase; friend class DLListBase;
friend class const_iterator; friend class const_iterator;
// Private data
//- Reference to the list this is an iterator for //- Reference to the list this is an iterator for
DLListBase& curList_; DLListBase& curList_;
@ -195,8 +194,6 @@ public:
//- Copy of the link //- Copy of the link
link curLink_; link curLink_;
// Private Member Functions
//- Construct for a given SLListBase with nullptr element and link. //- Construct for a given SLListBase with nullptr element and link.
// Only used to create endIter // Only used to create endIter
inline iterator(DLListBase&); inline iterator(DLListBase&);
@ -206,14 +203,15 @@ public:
//- Construct for a given DLListBase and link //- Construct for a given DLListBase and link
inline iterator(DLListBase&, link*); inline iterator(DLListBase&, link*);
// Member operators //- Currently pointing at a valid entry
inline bool found() const;
inline void operator=(const iterator&); inline void operator=(const iterator& iter);
inline bool operator==(const iterator&) const; inline bool operator==(const iterator& iter) const;
inline bool operator!=(const iterator&) const; inline bool operator!=(const iterator& iter) const;
inline link& operator*(); inline link& operator*() const;
inline iterator& operator++(); inline iterator& operator++();
inline iterator operator++(int); inline iterator operator++(int);
@ -228,8 +226,6 @@ public:
//- An STL-conforming const_iterator //- An STL-conforming const_iterator
class const_iterator class const_iterator
{ {
// Private data
//- Reference to the list this is an iterator for //- Reference to the list this is an iterator for
const DLListBase& curList_; const DLListBase& curList_;
@ -242,16 +238,17 @@ public:
inline const_iterator(const DLListBase&, const link*); inline const_iterator(const DLListBase&, const link*);
//- Construct from a non-const iterator //- Construct from a non-const iterator
inline const_iterator(const iterator&); inline const_iterator(const DLListBase::iterator& iter);
// Member operators //- Currently pointing at a valid entry
inline bool found() const;
inline void operator=(const const_iterator&); inline void operator=(const const_iterator& iter);
inline bool operator==(const const_iterator&) const; inline bool operator==(const const_iterator& iter) const;
inline bool operator!=(const const_iterator&) const; inline bool operator!=(const const_iterator& iter) const;
inline const link& operator*(); inline const link& operator*() const;
inline const_iterator& operator++(); inline const_iterator& operator++();
inline const_iterator operator++(int); inline const_iterator operator++(int);
@ -269,8 +266,6 @@ public:
//- An STL-conforming const_reverse_iterator //- An STL-conforming const_reverse_iterator
class const_reverse_iterator class const_reverse_iterator
{ {
// Private data
//- Reference to the list this is an reverse_iterator for //- Reference to the list this is an reverse_iterator for
const DLListBase& curList_; const DLListBase& curList_;
@ -280,16 +275,17 @@ public:
public: public:
//- Construct for a given DLListBase and link //- Construct for a given DLListBase and link
inline const_reverse_iterator(const DLListBase&, const link*); inline const_reverse_iterator(const DLListBase& lst, const link*);
// Member operators //- Currently pointing at a valid entry
inline bool found() const;
inline void operator=(const const_reverse_iterator&); inline void operator=(const const_reverse_iterator& iter);
inline bool operator==(const const_reverse_iterator&) const; inline bool operator==(const const_reverse_iterator& iter) const;
inline bool operator!=(const const_reverse_iterator&) const; inline bool operator!=(const const_reverse_iterator& iter) const;
inline const link& operator*(); inline const link& operator*() const;
inline const_reverse_iterator& operator++(); inline const_reverse_iterator& operator++();
inline const_reverse_iterator operator++(int); inline const_reverse_iterator operator++(int);

View File

@ -29,15 +29,15 @@ License
inline Foam::DLListBase::link::link() inline Foam::DLListBase::link::link()
: :
prev_(0), prev_(nullptr),
next_(0) next_(nullptr)
{} {}
inline Foam::DLListBase::DLListBase() inline Foam::DLListBase::DLListBase()
: :
first_(0), first_(nullptr),
last_(0), last_(nullptr),
nElmts_(0) nElmts_(0)
{} {}
@ -63,14 +63,14 @@ inline Foam::DLListBase::~DLListBase()
inline bool Foam::DLListBase::link::registered() const inline bool Foam::DLListBase::link::registered() const
{ {
return prev_ != 0 && next_ != 0; return prev_ != nullptr && next_ != nullptr;
} }
inline void Foam::DLListBase::link::deregister() inline void Foam::DLListBase::link::deregister()
{ {
prev_ = 0; prev_ = nullptr;
next_ = 0; next_ = nullptr;
} }
@ -140,8 +140,8 @@ Foam::DLListBase::last() const
inline void Foam::DLListBase::clear() inline void Foam::DLListBase::clear()
{ {
first_ = 0; first_ = nullptr;
last_ = 0; last_ = nullptr;
nElmts_ = 0; nElmts_ = 0;
} }
@ -195,6 +195,12 @@ inline Foam::DLListBase::iterator::iterator(DLListBase& s)
{} {}
inline bool Foam::DLListBase::iterator::found() const
{
return (curElmt_ != nullptr);
}
inline void Foam::DLListBase::iterator::operator=(const iterator& iter) inline void Foam::DLListBase::iterator::operator=(const iterator& iter)
{ {
curElmt_ = iter.curElmt_; curElmt_ = iter.curElmt_;
@ -215,7 +221,7 @@ inline bool Foam::DLListBase::iterator::operator!=(const iterator& iter) const
inline Foam::DLListBase::link& inline Foam::DLListBase::link&
Foam::DLListBase::iterator::operator*() Foam::DLListBase::iterator::operator*() const
{ {
return *curElmt_; return *curElmt_;
} }
@ -226,9 +232,9 @@ Foam::DLListBase::iterator::operator++()
{ {
// Check if the curElmt_ is the last element (if it points to itself) // Check if the curElmt_ is the last element (if it points to itself)
// or if the list is empty because the last element may have been removed // or if the list is empty because the last element may have been removed
if (curLink_.next_ == curElmt_ || curList_.last_ == 0) if (curLink_.next_ == curElmt_ || curList_.last_ == nullptr)
{ {
curElmt_ = 0; curElmt_ = nullptr;
} }
else else
{ {
@ -282,13 +288,22 @@ inline Foam::DLListBase::const_iterator::const_iterator
{} {}
inline Foam::DLListBase::const_iterator::const_iterator(const iterator& iter) inline Foam::DLListBase::const_iterator::const_iterator
(
const DLListBase::iterator& iter
)
: :
curList_(iter.curList_), curList_(iter.curList_),
curElmt_(iter.curElmt_) curElmt_(iter.curElmt_)
{} {}
inline bool Foam::DLListBase::const_iterator::found() const
{
return (curElmt_ != nullptr);
}
inline void Foam::DLListBase::const_iterator::operator= inline void Foam::DLListBase::const_iterator::operator=
( (
const const_iterator& iter const const_iterator& iter
@ -317,7 +332,7 @@ inline bool Foam::DLListBase::const_iterator::operator!=
inline const Foam::DLListBase::link& inline const Foam::DLListBase::link&
Foam::DLListBase::const_iterator::operator*() Foam::DLListBase::const_iterator::operator*() const
{ {
return *curElmt_; return *curElmt_;
} }
@ -328,7 +343,7 @@ Foam::DLListBase::const_iterator::operator++()
{ {
if (curElmt_ == curList_.last_) if (curElmt_ == curList_.last_)
{ {
curElmt_ = 0; curElmt_ = nullptr;
} }
else else
{ {
@ -387,15 +402,21 @@ Foam::DLListBase::end() const
inline Foam::DLListBase::const_reverse_iterator::const_reverse_iterator inline Foam::DLListBase::const_reverse_iterator::const_reverse_iterator
( (
const DLListBase& s, const DLListBase& lst,
const link* elmt const link* elmt
) )
: :
curList_(s), curList_(lst),
curElmt_(elmt) curElmt_(elmt)
{} {}
inline bool Foam::DLListBase::const_reverse_iterator::found() const
{
return (curElmt_ != nullptr);
}
inline void Foam::DLListBase::const_reverse_iterator::operator= inline void Foam::DLListBase::const_reverse_iterator::operator=
( (
const const_reverse_iterator& iter const const_reverse_iterator& iter
@ -424,7 +445,7 @@ inline bool Foam::DLListBase::const_reverse_iterator::operator!=
inline const Foam::DLListBase::link& inline const Foam::DLListBase::link&
Foam::DLListBase::const_reverse_iterator::operator*() Foam::DLListBase::const_reverse_iterator::operator*() const
{ {
return *curElmt_; return *curElmt_;
} }
@ -435,7 +456,7 @@ Foam::DLListBase::const_reverse_iterator::operator++()
{ {
if (curElmt_ == curList_.first_) if (curElmt_ == curList_.first_)
{ {
curElmt_ = 0; curElmt_ = nullptr;
} }
else else
{ {
@ -460,7 +481,7 @@ Foam::DLListBase::crbegin() const
{ {
if (size()) if (size())
{ {
return const_reverse_iterator(*this, last()); return const_reverse_iterator(*this, this->last());
} }
else else
{ {

View File

@ -79,7 +79,7 @@ Foam::SLListBase::link* Foam::SLListBase::removeHead()
{ {
nElmts_--; nElmts_--;
if (last_ == 0) if (last_ == nullptr)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "remove from empty list" << "remove from empty list"
@ -90,7 +90,7 @@ Foam::SLListBase::link* Foam::SLListBase::removeHead()
if (f == last_) if (f == last_)
{ {
last_ = 0; last_ = nullptr;
} }
else else
{ {
@ -132,7 +132,7 @@ Foam::SLListBase::link* Foam::SLListBase::remove(SLListBase::link* it)
prev = p; prev = p;
} }
return 0; return nullptr;
} }

View File

@ -25,9 +25,10 @@ Class
Foam::SLListBase Foam::SLListBase
Description Description
Base singly-linked list. Base for singly-linked lists.
SourceFiles SourceFiles
SLListBaseI.H
SLListBase.C SLListBase.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -81,10 +82,10 @@ private:
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
SLListBase(const SLListBase&); SLListBase(const SLListBase&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const SLListBase&); void operator=(const SLListBase&) = delete;
public: public:
@ -166,8 +167,6 @@ public:
friend class SLListBase; friend class SLListBase;
friend class const_iterator; friend class const_iterator;
// Private data
//- Reference to the list this is an iterator for //- Reference to the list this is an iterator for
SLListBase& curList_; SLListBase& curList_;
@ -177,8 +176,6 @@ public:
//- Copy of the link //- Copy of the link
link curLink_; link curLink_;
// Private Member Functions
//- Construct for a given SLListBase with nullptr element and link. //- Construct for a given SLListBase with nullptr element and link.
// Only used to create endIter // Only used to create endIter
inline iterator(SLListBase&); inline iterator(SLListBase&);
@ -188,14 +185,15 @@ public:
//- Construct for a given SLListBase and link //- Construct for a given SLListBase and link
inline iterator(SLListBase&, link*); inline iterator(SLListBase&, link*);
// Member operators //- Currently pointing at a valid entry
inline bool found() const;
inline void operator=(const iterator&); inline void operator=(const iterator& iter);
inline bool operator==(const iterator&) const; inline bool operator==(const iterator& iter) const;
inline bool operator!=(const iterator&) const; inline bool operator!=(const iterator& iter) const;
inline link& operator*(); inline link& operator*() const;
inline iterator& operator++(); inline iterator& operator++();
inline iterator operator++(int); inline iterator operator++(int);
@ -210,8 +208,6 @@ public:
//- An STL-conforming const_iterator //- An STL-conforming const_iterator
class const_iterator class const_iterator
{ {
// Private data
//- Reference to the list this is an iterator for //- Reference to the list this is an iterator for
const SLListBase& curList_; const SLListBase& curList_;
@ -224,17 +220,17 @@ public:
inline const_iterator(const SLListBase&, const link*); inline const_iterator(const SLListBase&, const link*);
//- Construct from a non-const iterator //- Construct from a non-const iterator
inline const_iterator(const iterator&); inline const_iterator(const SLListBase::iterator& iter);
//- Currently pointing at a valid entry
inline bool found() const;
// Member operators inline void operator=(const const_iterator& iter);
inline void operator=(const const_iterator&); inline bool operator==(const const_iterator& iter) const;
inline bool operator!=(const const_iterator& iter) const;
inline bool operator==(const const_iterator&) const; inline const link& operator*() const;
inline bool operator!=(const const_iterator&) const;
inline const link& operator*();
inline const_iterator& operator++(); inline const_iterator& operator++();
inline const_iterator operator++(int); inline const_iterator operator++(int);

View File

@ -21,9 +21,6 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Base singly-linked list.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "error.H" #include "error.H"
@ -32,7 +29,7 @@ Description
inline Foam::SLListBase::link::link() inline Foam::SLListBase::link::link()
: :
next_(0) next_(nullptr)
{} {}
@ -44,16 +41,22 @@ inline Foam::SLListBase::link::link(link* p)
inline Foam::SLListBase::SLListBase() inline Foam::SLListBase::SLListBase()
: :
last_(0), last_(nullptr),
nElmts_(0) nElmts_(0)
{} {}
inline Foam::SLListBase::SLListBase(link* a) inline Foam::SLListBase::SLListBase(link* a)
: :
last_(a->next_ = a), last_(a),
nElmts_(1) nElmts_(0)
{} {
if (a) // protect against nullptr
{
a->next_ = a;
nElmts_ = 1;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
@ -130,7 +133,7 @@ Foam::SLListBase::last() const
inline void Foam::SLListBase::clear() inline void Foam::SLListBase::clear()
{ {
last_ = 0; last_ = nullptr;
nElmts_ = 0; nElmts_ = 0;
} }
@ -171,6 +174,12 @@ inline Foam::SLListBase::iterator::iterator(SLListBase& s)
{} {}
inline bool Foam::SLListBase::iterator::found() const
{
return (curElmt_ != nullptr);
}
inline void Foam::SLListBase::iterator::operator=(const iterator& iter) inline void Foam::SLListBase::iterator::operator=(const iterator& iter)
{ {
curElmt_ = iter.curElmt_; curElmt_ = iter.curElmt_;
@ -190,7 +199,7 @@ inline bool Foam::SLListBase::iterator::operator!=(const iterator& iter) const
} }
inline Foam::SLListBase::link& Foam::SLListBase::iterator::operator*() inline Foam::SLListBase::link& Foam::SLListBase::iterator::operator*() const
{ {
return *curElmt_; return *curElmt_;
} }
@ -198,9 +207,9 @@ inline Foam::SLListBase::link& Foam::SLListBase::iterator::operator*()
inline Foam::SLListBase::iterator& Foam::SLListBase::iterator::operator++() inline Foam::SLListBase::iterator& Foam::SLListBase::iterator::operator++()
{ {
if (curElmt_ == curList_.last_ || curList_.last_ == 0) if (curElmt_ == curList_.last_ || curList_.last_ == nullptr)
{ {
curElmt_ = 0; curElmt_ = nullptr;
} }
else else
{ {
@ -255,13 +264,22 @@ inline Foam::SLListBase::const_iterator::const_iterator
{} {}
inline Foam::SLListBase::const_iterator::const_iterator(const iterator& iter) inline Foam::SLListBase::const_iterator::const_iterator
(
const SLListBase::iterator& iter
)
: :
curList_(iter.curList_), curList_(iter.curList_),
curElmt_(iter.curElmt_) curElmt_(iter.curElmt_)
{} {}
inline bool Foam::SLListBase::const_iterator::found() const
{
return (curElmt_ != nullptr);
}
inline void Foam::SLListBase::const_iterator::operator= inline void Foam::SLListBase::const_iterator::operator=
( (
const const_iterator& iter const const_iterator& iter
@ -290,7 +308,7 @@ inline bool Foam::SLListBase::const_iterator::operator!=
inline const Foam::SLListBase::link& inline const Foam::SLListBase::link&
Foam::SLListBase::const_iterator::operator*() Foam::SLListBase::const_iterator::operator*() const
{ {
return *curElmt_; return *curElmt_;
} }
@ -301,7 +319,7 @@ Foam::SLListBase::const_iterator::operator++()
{ {
if (curElmt_ == curList_.last_) if (curElmt_ == curList_.last_)
{ {
curElmt_ = 0; curElmt_ = nullptr;
} }
else else
{ {

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -59,14 +59,14 @@ class DynamicList;
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
Ostream& operator<< Ostream& operator<<
( (
Ostream&, Ostream& os,
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
); );
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
Istream& operator>> Istream& operator>>
( (
Istream&, Istream& is,
DynamicList<T, SizeInc, SizeMult, SizeDiv>& DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
); );
@ -105,29 +105,37 @@ public:
inline DynamicList(); inline DynamicList();
//- Construct given size. //- Construct given size.
explicit inline DynamicList(const label); explicit inline DynamicList(const label nElem);
//- Construct with given size and value for all elements. //- Construct with given size and value for all elements.
inline DynamicList(const label, const T&); inline DynamicList(const label nElem, const T& a);
//- Construct copy. //- Construct copy.
inline DynamicList(const DynamicList<T, SizeInc, SizeMult, SizeDiv>&); inline DynamicList
(
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
);
//- Construct from UList. Size set to UList size. //- Construct from UList. Size set to UList size.
// Also constructs from DynamicList with different sizing parameters. // Also constructs from DynamicList with different sizing parameters.
explicit inline DynamicList(const UList<T>&); explicit inline DynamicList(const UList<T>& lst);
//- Construct given begin/end iterators.
// Uses std::distance to determine the size.
template<class InputIterator>
inline DynamicList(InputIterator begIter, InputIterator endIter);
//- Construct from an initializer list. Size set to list size. //- Construct from an initializer list. Size set to list size.
explicit inline DynamicList(std::initializer_list<T>); explicit inline DynamicList(std::initializer_list<T> lst);
//- Construct from UIndirectList. Size set to UIndirectList size. //- Construct from UIndirectList. Size set to UIndirectList size.
explicit inline DynamicList(const UIndirectList<T>&); explicit inline DynamicList(const UIndirectList<T>& lst);
//- Construct by transferring the parameter contents //- Construct by transferring the parameter contents
explicit inline DynamicList(const Xfer<List<T>>&); explicit inline DynamicList(const Xfer<List<T>>& lst);
//- Construct from Istream. Size set to size of list read. //- Construct from Istream. Size set to size of list read.
explicit DynamicList(Istream&); explicit DynamicList(Istream& is);
// Member Functions // Member Functions
@ -143,31 +151,31 @@ public:
// The addressed size will be truncated if needed to fit, but will // The addressed size will be truncated if needed to fit, but will
// remain otherwise untouched. // remain otherwise untouched.
// Use this or reserve() in combination with append(). // Use this or reserve() in combination with append().
inline void setCapacity(const label); inline void setCapacity(const label nElem);
//- Alter the addressed list size. //- Alter the addressed list size.
// New space will be allocated if required. // New space will be allocated if required.
// Use this to resize the list prior to using the operator[] for // Use this to resize the list prior to using the operator[] for
// setting values (as per List usage). // setting values (as per List usage).
inline void setSize(const label); inline void setSize(const label nElem);
//- Alter the addressed list size and fill new space with a //- Alter the addressed list size and fill new space with a
// constant. // constant.
inline void setSize(const label, const T&); inline void setSize(const label nElem, const T& t);
//- Alter the addressed list size. //- Alter the addressed list size.
// New space will be allocated if required. // New space will be allocated if required.
// Use this to resize the list prior to using the operator[] for // Use this to resize the list prior to using the operator[] for
// setting values (as per List usage). // setting values (as per List usage).
inline void resize(const label); inline void resize(const label nElem);
//- Alter the addressed list size and fill new space with a //- Alter the addressed list size and fill new space with a
// constant. // constant.
inline void resize(const label, const T&); inline void resize(const label nElem, const T& t);
//- Reserve allocation space for at least this size. //- Reserve allocation space for at least this size.
// Never shrinks the allocated size, use setCapacity() for that. // Never shrinks the allocated size, use setCapacity() for that.
inline void reserve(const label); inline void reserve(const label nElem);
//- Clear the addressed list, i.e. set the size to zero. //- Clear the addressed list, i.e. set the size to zero.
// Allocated size does not change // Allocated size does not change
@ -181,10 +189,13 @@ public:
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink(); inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink();
//- Transfer contents of the argument List into this. //- Transfer contents of the argument List into this.
inline void transfer(List<T>&); inline void transfer(List<T>& lst);
//- Transfer contents of the argument DynamicList into this. //- Transfer contents of the argument DynamicList into this.
inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&); inline void transfer
(
DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
);
//- Transfer contents to the Xfer container as a plain List //- Transfer contents to the Xfer container as a plain List
inline Xfer<List<T>> xfer(); inline Xfer<List<T>> xfer();
@ -195,25 +206,25 @@ public:
//- Append an element at the end of the list //- Append an element at the end of the list
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
( (
const T& const T& t
); );
//- Append a List at the end of this list //- Append a List at the end of this list
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
( (
const UList<T>& const UList<T>& lst
); );
//- Append an initializer list at the end of this list. //- Append an initializer list at the end of this list.
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
( (
std::initializer_list<T> std::initializer_list<T> lst
); );
//- Append a UIndirectList at the end of this list //- Append a UIndirectList at the end of this list
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
( (
const UIndirectList<T>& const UIndirectList<T>& lst
); );
//- Remove and return the top element //- Remove and return the top element
@ -221,32 +232,35 @@ public:
//- Return non-const access to an element, resizing list if //- Return non-const access to an element, resizing list if
// necessary // necessary
inline T& operator()(const label); inline T& operator()(const label elemI);
//- Assignment of all addressed entries to the given value //- Assignment of all addressed entries to the given value
inline void operator=(const T&); inline void operator=(const T& t);
//- Assignment to DynamicList //- Assignment to DynamicList
inline void operator= inline void operator=
( (
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
); );
//- Assignment to UList //- Assignment to UList
inline void operator=(const UList<T>&); inline void operator=(const UList<T>& lst);
//- Assignment from initializer list //- Assignment from initializer list
inline void operator=(std::initializer_list<T>); inline void operator=(std::initializer_list<T> lst);
//- Assignment to UIndirectList //- Assignment to UIndirectList
inline void operator=(const UIndirectList<T>&); inline void operator=(const UIndirectList<T>& lst);
// STL member functions // STL member functions
//- Erase an element, move the remaining elements to fill the gap //- Erase an element, move the remaining elements to fill the gap
// and resize the List // and resize the List
typename UList<T>::iterator erase(typename UList<T>::iterator); typename UList<T>::iterator erase
(
typename UList<T>::iterator curIter
);
// IOstream operators // IOstream operators
@ -254,15 +268,15 @@ public:
// Write DynamicList to Ostream. // Write DynamicList to Ostream.
friend Ostream& operator<< <T, SizeInc, SizeMult, SizeDiv> friend Ostream& operator<< <T, SizeInc, SizeMult, SizeDiv>
( (
Ostream&, Ostream& os,
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
); );
//- Read from Istream, discarding contents of existing DynamicList. //- Read from Istream, discarding contents of existing DynamicList.
friend Istream& operator>> <T, SizeInc, SizeMult, SizeDiv> friend Istream& operator>> <T, SizeInc, SizeMult, SizeDiv>
( (
Istream&, Istream& is,
DynamicList<T, SizeInc, SizeMult, SizeDiv>& DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
); );
}; };

View File

@ -80,6 +80,19 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
{} {}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
template<class InputIterator>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
(
InputIterator begIter,
InputIterator endIter
)
:
List<T>(begIter, endIter),
capacity_(this->size())
{}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
( (

View File

@ -128,11 +128,12 @@ public:
explicit inline FixedList(const T& t); explicit inline FixedList(const T& t);
//- Construct from C-array //- Construct from C-array
explicit inline FixedList(const T v[Size]); explicit inline FixedList(const T lst[Size]);
//- Construct given start and end iterators //- Construct given begin/end iterators
// Uses std::distance when verifying the size.
template<class InputIterator> template<class InputIterator>
inline FixedList(InputIterator first, InputIterator last); inline FixedList(InputIterator begIter, InputIterator endIter);
//- Construct from an initializer list //- Construct from an initializer list
inline FixedList(std::initializer_list<T> lst); inline FixedList(std::initializer_list<T> lst);

View File

@ -37,7 +37,7 @@ inline Foam::FixedList<T, Size>::FixedList()
template<class T, unsigned Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const T& t) inline Foam::FixedList<T, Size>::FixedList(const T& t)
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = t; v_[i] = t;
} }
@ -45,11 +45,11 @@ inline Foam::FixedList<T, Size>::FixedList(const T& t)
template<class T, unsigned Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const T v[Size]) inline Foam::FixedList<T, Size>::FixedList(const T lst[Size])
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = v[i]; v_[i] = lst[i];
} }
} }
@ -58,25 +58,33 @@ template<class T, unsigned Size>
template<class InputIterator> template<class InputIterator>
Foam::FixedList<T, Size>::FixedList Foam::FixedList<T, Size>::FixedList
( (
InputIterator first, InputIterator begIter,
InputIterator last InputIterator endIter
) )
{ {
checkSize(std::distance(first, last)); checkSize(std::distance(begIter, endIter));
InputIterator iter = first; InputIterator iter = begIter;
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = *iter++; v_[i] = *iter;
++iter;
} }
} }
template<class T, unsigned Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(std::initializer_list<T> lst) inline Foam::FixedList<T, Size>::FixedList(std::initializer_list<T> lst)
: {
FixedList<T, Size>(lst.begin(), lst.end()) checkSize(lst.size());
{}
auto iter = lst.begin();
for (unsigned i=0; i<Size; ++i)
{
v_[i] = *iter;
++iter;
}
}
template<class T, unsigned Size> template<class T, unsigned Size>
@ -84,7 +92,7 @@ inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst)
{ {
checkSize(lst.size()); checkSize(lst.size());
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
@ -97,9 +105,10 @@ inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
checkSize(lst.size()); checkSize(lst.size());
typename SLList<T>::const_iterator iter = lst.begin(); typename SLList<T>::const_iterator iter = lst.begin();
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = *iter++; v_[i] = *iter;
++iter;
} }
} }
@ -107,7 +116,7 @@ inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
template<class T, unsigned Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst) inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst)
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
@ -200,7 +209,7 @@ inline void Foam::FixedList<T, Size>::setSize(const label s)
template<class T, unsigned Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst) inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst)
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
@ -276,7 +285,7 @@ inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
template<class T, unsigned Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::operator=(const T lst[Size]) inline void Foam::FixedList<T, Size>::operator=(const T lst[Size])
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
@ -287,7 +296,7 @@ inline void Foam::FixedList<T, Size>::operator=(const UList<T>& lst)
{ {
checkSize(lst.size()); checkSize(lst.size());
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
@ -299,9 +308,10 @@ inline void Foam::FixedList<T, Size>::operator=(const SLList<T>& lst)
checkSize(lst.size()); checkSize(lst.size());
typename SLList<T>::const_iterator iter = lst.begin(); typename SLList<T>::const_iterator iter = lst.begin();
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = *iter++; v_[i] = *iter;
++iter;
} }
} }
@ -310,17 +320,18 @@ inline void Foam::FixedList<T, Size>::operator=(std::initializer_list<T> lst)
{ {
checkSize(lst.size()); checkSize(lst.size());
typename std::initializer_list<T>::iterator iter = lst.begin(); auto iter = lst.begin();
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = *iter++; v_[i] = *iter;
++iter;
} }
} }
template<class T, unsigned Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::operator=(const T& t) inline void Foam::FixedList<T, Size>::operator=(const T& t)
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = t; v_[i] = t;
} }
@ -464,7 +475,7 @@ inline unsigned Foam::FixedList<T, Size>::Hash<HashT>::operator()
// Hash incrementally // Hash incrementally
unsigned val = seed; unsigned val = seed;
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
val = HashT()(lst[i], val); val = HashT()(lst[i], val);
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -160,7 +160,7 @@ Foam::List<T>::List(List<T>& a, bool reuse)
if (reuse) if (reuse)
{ {
this->v_ = a.v_; this->v_ = a.v_;
a.v_ = 0; a.v_ = nullptr;
a.size_ = 0; a.size_ = 0;
} }
else if (this->size_) else if (this->size_)
@ -186,19 +186,19 @@ Foam::List<T>::List(List<T>& a, bool reuse)
template<class T> template<class T>
Foam::List<T>::List(const UList<T>& a, const labelUList& map) Foam::List<T>::List(const UList<T>& a, const labelUList& mapAddressing)
: :
UList<T>(nullptr, map.size()) UList<T>(nullptr, mapAddressing.size())
{ {
if (this->size_) if (this->size_)
{ {
// Note:cannot use List_ELEM since third argument has to be index. // Note: cannot use List_ELEM since third argument has to be index.
alloc(); alloc();
forAll(*this, i) forAll(*this, i)
{ {
this->operator[](i) = a[map[i]]; this->operator[](i) = a[mapAddressing[i]];
} }
} }
} }
@ -206,9 +206,9 @@ Foam::List<T>::List(const UList<T>& a, const labelUList& map)
template<class T> template<class T>
template<class InputIterator> template<class InputIterator>
Foam::List<T>::List(InputIterator first, InputIterator last) Foam::List<T>::List(InputIterator begIter, InputIterator endIter)
: :
List<T>(first, last, std::distance(first, last)) List<T>(begIter, endIter, std::distance(begIter, endIter))
{} {}
@ -231,6 +231,8 @@ Foam::List<T>::List(const PtrList<T>& lst)
} }
// Note: using first/last is not entirely accurate.
// But since the list size is correct, last() is actually ignored.
template<class T> template<class T>
Foam::List<T>::List(const SLList<T>& lst) Foam::List<T>::List(const SLList<T>& lst)
: :
@ -259,7 +261,7 @@ Foam::List<T>::List(const BiIndirectList<T>& lst)
template<class T> template<class T>
Foam::List<T>::List(std::initializer_list<T> lst) Foam::List<T>::List(std::initializer_list<T> lst)
: :
List<T>(lst.begin(), lst.end()) List<T>(lst.begin(), lst.end(), lst.size())
{} {}
@ -326,7 +328,7 @@ void Foam::List<T>::setSize(const label newSize)
template<class T> template<class T>
void Foam::List<T>::setSize(const label newSize, const T& a) void Foam::List<T>::setSize(const label newSize, const T& a)
{ {
label oldSize = label(this->size_); const label oldSize = label(this->size_);
this->setSize(newSize); this->setSize(newSize);
if (newSize > oldSize) if (newSize > oldSize)
@ -346,7 +348,7 @@ void Foam::List<T>::transfer(List<T>& a)
this->v_ = a.v_; this->v_ = a.v_;
a.size_ = 0; a.size_ = 0;
a.v_ = 0; a.v_ = nullptr;
} }
@ -419,14 +421,9 @@ void Foam::List<T>::operator=(const SLList<T>& lst)
if (this->size_) if (this->size_)
{ {
label i = 0; label i = 0;
for for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
(
typename SLList<T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{ {
this->operator[](i++) = iter(); this->operator[](i++) = *iter;
} }
} }
} }
@ -453,10 +450,11 @@ void Foam::List<T>::operator=(std::initializer_list<T> lst)
{ {
reAlloc(lst.size()); reAlloc(lst.size());
typename std::initializer_list<T>::iterator iter = lst.begin(); auto iter = lst.begin();
forAll(*this, i) forAll(*this, i)
{ {
this->operator[](i) = *iter++; this->operator[](i) = *iter;
++iter;
} }
} }

View File

@ -58,7 +58,7 @@ class Ostream;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
template<class T> class List; template<class T> class List;
template<class T> Istream& operator>>(Istream&, List<T>&); template<class T> Istream& operator>>(Istream& is, List<T>& L);
template<class T, unsigned Size> class FixedList; template<class T, unsigned Size> class FixedList;
template<class T> class PtrList; template<class T> class PtrList;
@ -95,22 +95,28 @@ class List
//- Copy list of given type //- Copy list of given type
template<class List2> template<class List2>
inline void copyList(const List2&); inline void copyList(const List2& lst);
//- Allocate storage and copy list of given type //- Allocate storage and copy list of given type
template<class List2> template<class List2>
inline void allocCopyList(const List2&); inline void allocCopyList(const List2& lst);
//- Construct given start and end iterators and number of elements //- Construct given begin/end iterators and number of elements
// Since the size is provided, the end iterator is actually ignored.
template<class InputIterator> template<class InputIterator>
inline List(InputIterator first, InputIterator last, const label s); inline List
(
InputIterator begIter,
InputIterator endIter,
const label s
);
protected: protected:
//- Override size to be inconsistent with allocated storage. //- Override size to be inconsistent with allocated storage.
// Use with care // Use with care
inline void size(const label); inline void size(const label n);
public: public:
@ -127,55 +133,56 @@ public:
inline List(); inline List();
//- Construct with given size //- Construct with given size
explicit List(const label); explicit List(const label s);
//- Construct with given size and value for all elements //- Construct with given size and value for all elements
List(const label, const T&); List(const label s, const T& a);
//- Construct with given size initializing all elements to zero //- Construct with given size initializing all elements to zero
List(const label, const zero); List(const label s, const zero);
//- Copy constructor //- Copy constructor
List(const List<T>&); List(const List<T>& a);
//- Copy constructor from list containing another type //- Copy constructor from list containing another type
template<class T2> template<class T2>
explicit List(const List<T2>&); explicit List(const List<T2>& a);
//- Construct by transferring the parameter contents //- Construct by transferring the parameter contents
List(const Xfer<List<T>>&); List(const Xfer<List<T>>& lst);
//- Construct as copy or re-use as specified //- Construct as copy or re-use as specified
List(List<T>&, bool reuse); List(List<T>& a, bool reuse);
//- Construct as subset //- Construct as subset
List(const UList<T>&, const labelUList& mapAddressing); List(const UList<T>& a, const labelUList& mapAddressing);
//- Construct given start and end iterators //- Construct given begin/end iterators.
// Uses std::distance to determine the size.
template<class InputIterator> template<class InputIterator>
List(InputIterator first, InputIterator last); List(InputIterator begIter, InputIterator endIter);
//- Construct as copy of FixedList<T, Size> //- Construct as copy of FixedList<T, Size>
template<unsigned Size> template<unsigned Size>
explicit List(const FixedList<T, Size>&); explicit List(const FixedList<T, Size>& lst);
//- Construct as copy of PtrList<T> //- Construct as copy of PtrList<T>
explicit List(const PtrList<T>&); explicit List(const PtrList<T>& lst);
//- Construct as copy of SLList<T> //- Construct as copy of SLList<T>
explicit List(const SLList<T>&); explicit List(const SLList<T>& lst);
//- Construct as copy of UIndirectList<T> //- Construct as copy of UIndirectList<T>
explicit List(const UIndirectList<T>&); explicit List(const UIndirectList<T>& lst);
//- Construct as copy of BiIndirectList<T> //- Construct as copy of BiIndirectList<T>
explicit List(const BiIndirectList<T>&); explicit List(const BiIndirectList<T>& lst);
//- Construct from an initializer list //- Construct from an initializer list
List(std::initializer_list<T>); List(std::initializer_list<T> lst);
//- Construct from Istream //- Construct from Istream
List(Istream&); List(Istream& is);
//- Clone //- Clone
inline autoPtr<List<T>> clone() const; inline autoPtr<List<T>> clone() const;
@ -200,47 +207,48 @@ public:
// Edit // Edit
//- Alias for setSize(const label) //- Alias for setSize(const label)
inline void resize(const label); inline void resize(const label newSize);
//- Alias for setSize(const label, const T&) //- Alias for setSize(const label, const T&)
inline void resize(const label, const T&); inline void resize(const label newSize, const T& a);
//- Reset size of List //- Reset size of List
void setSize(const label); void setSize(const label newSize);
//- Reset size of List and value for new elements //- Reset size of List and value for new elements
void setSize(const label, const T&); void setSize(const label newSize, const T& a);
//- Clear the list, i.e. set size to zero //- Clear the list, i.e. set size to zero
inline void clear(); inline void clear();
//- Append an element at the end of the list //- Append an element at the end of the list
inline void append(const T&); inline void append(const T& t);
//- Append a List at the end of this list //- Append a List at the end of this list
inline void append(const UList<T>&); inline void append(const UList<T>& lst);
//- Append a UIndirectList at the end of this list //- Append a UIndirectList at the end of this list
inline void append(const UIndirectList<T>&); inline void append(const UIndirectList<T>& lst);
//- Transfer the contents of the argument List into this list //- Transfer the contents of the argument List into this list
// and annul the argument list // and annul the argument list
void transfer(List<T>&); void transfer(List<T>& a);
//- Transfer the contents of the argument List into this list //- Transfer the contents of the argument List into this list
// and annul the argument list // and annul the argument list
template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&); void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>& a);
//- Transfer the contents of the argument List into this list //- Transfer the contents of the argument List into this list
// and annul the argument list // and annul the argument list
void transfer(SortableList<T>&); void transfer(SortableList<T>& a);
//- Transfer contents to the Xfer container //- Transfer contents to the Xfer container
inline Xfer<List<T>> xfer(); inline Xfer<List<T>> xfer();
//- Return subscript-checked element of UList //- Return subscript-checked element of UList.
inline T& newElmt(const label); // Resize list if required.
inline T& newElmt(const label i);
//- Disallow implicit shallowCopy //- Disallow implicit shallowCopy
@ -250,25 +258,25 @@ public:
// Member operators // Member operators
//- Assignment to UList operator. Takes linear time //- Assignment to UList operator. Takes linear time
void operator=(const UList<T>&); void operator=(const UList<T>& a);
//- Assignment operator. Takes linear time //- Assignment operator. Takes linear time
void operator=(const List<T>&); void operator=(const List<T>& a);
//- Assignment to SLList operator. Takes linear time //- Assignment to SLList operator. Takes linear time
void operator=(const SLList<T>&); void operator=(const SLList<T>& lst);
//- Assignment to UIndirectList operator. Takes linear time //- Assignment to UIndirectList operator. Takes linear time
void operator=(const UIndirectList<T>&); void operator=(const UIndirectList<T>& lst);
//- Assignment to BiIndirectList operator. Takes linear time //- Assignment to BiIndirectList operator. Takes linear time
void operator=(const BiIndirectList<T>&); void operator=(const BiIndirectList<T>& lst);
//- Assignment to an initializer list //- Assignment to an initializer list
void operator=(std::initializer_list<T>); void operator=(std::initializer_list<T> lst);
//- Assignment of all entries to the given value //- Assignment of all entries to the given value
inline void operator=(const T&); inline void operator=(const T& t);
//- Assignment of all entries to zero //- Assignment of all entries to zero
inline void operator=(const zero); inline void operator=(const zero);
@ -278,7 +286,7 @@ public:
//- Read List from Istream, discarding contents of existing List //- Read List from Istream, discarding contents of existing List
friend Istream& operator>> <T> friend Istream& operator>> <T>
(Istream&, List<T>&); (Istream& is, List<T>& L);
}; };
@ -290,7 +298,7 @@ public:
// \endcode // \endcode
// Mostly useful for handling command-line arguments // Mostly useful for handling command-line arguments
template<class T> template<class T>
List<T> readList(Istream&); List<T> readList(Istream& is);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -77,8 +77,8 @@ template<class T>
template<class InputIterator> template<class InputIterator>
inline Foam::List<T>::List inline Foam::List<T>::List
( (
InputIterator first, InputIterator begIter,
InputIterator last, InputIterator endIter,
const label s const label s
) )
: :
@ -88,10 +88,11 @@ inline Foam::List<T>::List
{ {
alloc(); alloc();
InputIterator iter = first; InputIterator iter = begIter;
forAll(*this, i) forAll(*this, i)
{ {
this->operator[](i) = *iter++; this->operator[](i) = *iter;
++iter;
} }
} }
} }
@ -126,7 +127,7 @@ inline void Foam::List<T>::clear()
if (this->v_) if (this->v_)
{ {
delete[] this->v_; delete[] this->v_;
this->v_ = 0; this->v_ = nullptr;
} }
this->size_ = 0; this->size_ = 0;

View File

@ -28,7 +28,7 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T> template<class T>
Foam::SortableList<T>::SortableList() inline Foam::SortableList<T>::SortableList()
{} {}
@ -51,14 +51,14 @@ Foam::SortableList<T>::SortableList(const Xfer<List<T>>& values)
template<class T> template<class T>
Foam::SortableList<T>::SortableList(const label size) inline Foam::SortableList<T>::SortableList(const label size)
: :
List<T>(size) List<T>(size)
{} {}
template<class T> template<class T>
Foam::SortableList<T>::SortableList(const label size, const T& val) inline Foam::SortableList<T>::SortableList(const label size, const T& val)
: :
List<T>(size, val) List<T>(size, val)
{} {}
@ -72,6 +72,20 @@ Foam::SortableList<T>::SortableList(const SortableList<T>& lst)
{} {}
template<class T>
template<class InputIterator>
inline Foam::SortableList<T>::SortableList
(
InputIterator begIter,
InputIterator endIter
)
:
List<T>(begIter, endIter)
{
sort();
}
template<class T> template<class T>
Foam::SortableList<T>::SortableList(std::initializer_list<T> values) Foam::SortableList<T>::SortableList(std::initializer_list<T> values)
: :
@ -140,9 +154,9 @@ Foam::Xfer<Foam::List<T>> Foam::SortableList<T>::xfer()
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T> template<class T>
inline void Foam::SortableList<T>::operator=(const T& t) inline void Foam::SortableList<T>::operator=(const T& val)
{ {
UList<T>::operator=(t); UList<T>::operator=(val);
} }

View File

@ -65,27 +65,32 @@ public:
// Constructors // Constructors
//- Null constructor, sort later (eg, after assignment or transfer) //- Null constructor, sort later (eg, after assignment or transfer)
SortableList(); inline SortableList();
//- Construct from UList, sorting immediately //- Construct from UList, sorting immediately
explicit SortableList(const UList<T>&); explicit SortableList(const UList<T>& values);
//- Construct from transferred List, sorting immediately //- Construct from transferred List, sorting immediately
explicit SortableList(const Xfer<List<T>>&); explicit SortableList(const Xfer<List<T>>& values);
//- Construct given size. Sort later on //- Construct given size. Sort later on
// The indices remain empty until the list is sorted // The indices remain empty until the list is sorted
explicit SortableList(const label size); explicit inline SortableList(const label size);
//- Construct given size and initial value. Sort later on //- Construct given size and initial value. Sort later on
// The indices remain empty until the list is sorted // The indices remain empty until the list is sorted
SortableList(const label size, const T&); inline SortableList(const label size, const T& val);
//- Construct given begin/end iterators.
// Uses std::distance to determine the size.
template<class InputIterator>
inline SortableList(InputIterator begIter, InputIterator endIter);
//- Construct as copy //- Construct as copy
SortableList(const SortableList<T>&); inline SortableList(const SortableList<T>& lst);
//- Construct from an initializer list, sorting immediately //- Construct from an initializer list, sorting immediately
SortableList(std::initializer_list<T>); SortableList(std::initializer_list<T> values);
// Member Functions // Member Functions
@ -122,16 +127,16 @@ public:
// Member Operators // Member Operators
//- Assignment of all entries to the given value //- Assignment of all entries to the given value
inline void operator=(const T&); inline void operator=(const T& val);
//- Assignment to UList operator. Takes linear time //- Assignment to UList operator. Takes linear time
inline void operator=(const UList<T>&); inline void operator=(const UList<T>& lst);
//- Assignment operator. Takes linear time //- Assignment operator. Takes linear time
inline void operator=(const SortableList<T>&); inline void operator=(const SortableList<T>& lst);
//- Assignment to an initializer list //- Assignment to an initializer list
void operator=(std::initializer_list<T>); void operator=(std::initializer_list<T> lst);
}; };

View File

@ -91,9 +91,9 @@ Foam::IOobjectList::IOobjectList
} }
Foam::IOobjectList::IOobjectList(const IOobjectList& ioOL) Foam::IOobjectList::IOobjectList(const IOobjectList& iolist)
: :
HashPtrTable<IOobject>(ioOL) HashPtrTable<IOobject>(iolist)
{} {}
@ -113,17 +113,7 @@ bool Foam::IOobjectList::add(IOobject& io)
bool Foam::IOobjectList::remove(IOobject& io) bool Foam::IOobjectList::remove(IOobject& io)
{ {
HashPtrTable<IOobject>::iterator iter = return erase(io.name());
HashPtrTable<IOobject>::find(io.name());
if (iter != end())
{
return erase(iter);
}
else
{
return false;
}
} }
@ -131,7 +121,7 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
{ {
HashPtrTable<IOobject>::const_iterator iter = find(name); HashPtrTable<IOobject>::const_iterator iter = find(name);
if (iter != end()) if (iter.found())
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
@ -152,68 +142,80 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
} }
Foam::IOobjectList Foam::IOobjectList::lookup(const wordRe& name) const Foam::IOobjectList Foam::IOobjectList::lookup(const wordRe& matcher) const
{ {
IOobjectList objectsOfName(size()); IOobjectList results(size());
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (name.match(iter()->name())) if (matcher.match(iter.key()))
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
InfoInFunction << "Found " << iter.key() << endl; InfoInFunction << "Found " << iter.key() << endl;
} }
objectsOfName.insert(iter.key(), new IOobject(*iter())); results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
} }
} }
return objectsOfName; return results;
} }
Foam::IOobjectList Foam::IOobjectList::lookup(const wordReList& patterns) const Foam::IOobjectList Foam::IOobjectList::lookup(const wordReList& matcher) const
{ {
wordReListMatcher names(patterns); wordReListMatcher mat(matcher);
IOobjectList objectsOfName(size()); IOobjectList results(size());
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (names.match(iter()->name())) if (mat.match(iter.key()))
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
InfoInFunction << "Found " << iter.key() << endl; InfoInFunction << "Found " << iter.key() << endl;
} }
objectsOfName.insert(iter.key(), new IOobject(*iter())); results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
} }
} }
return objectsOfName; return results;
} }
Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& clsName) const
{ {
IOobjectList objectsOfClass(size()); IOobjectList results(size());
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (iter()->headerClassName() == ClassName) if (iter()->headerClassName() == clsName)
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
InfoInFunction << "Found " << iter.key() << endl; InfoInFunction << "Found " << iter.key() << endl;
} }
objectsOfClass.insert(iter.key(), new IOobject(*iter())); results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
} }
} }
return objectsOfClass; return results;
} }
@ -231,33 +233,33 @@ Foam::wordList Foam::IOobjectList::sortedNames() const
Foam::wordList Foam::IOobjectList::names Foam::wordList Foam::IOobjectList::names
( (
const word& ClassName const word& clsName
) const ) const
{ {
wordList objectNames(size()); wordList objNames(size());
label count = 0; label count = 0;
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (iter()->headerClassName() == ClassName) if (iter()->headerClassName() == clsName)
{ {
objectNames[count++] = iter.key(); objNames[count++] = iter.key();
} }
} }
objectNames.setSize(count); objNames.setSize(count);
return objectNames; return objNames;
} }
Foam::wordList Foam::IOobjectList::names Foam::wordList Foam::IOobjectList::names
( (
const word& ClassName, const word& clsName,
const wordRe& matcher const wordRe& matcher
) const ) const
{ {
wordList objNames = names(ClassName); wordList objNames = names(clsName);
return wordList(objNames, findStrings(matcher, objNames)); return wordList(objNames, findStrings(matcher, objNames));
} }
@ -265,11 +267,11 @@ Foam::wordList Foam::IOobjectList::names
Foam::wordList Foam::IOobjectList::names Foam::wordList Foam::IOobjectList::names
( (
const word& ClassName, const word& clsName,
const wordReList& matcher const wordReList& matcher
) const ) const
{ {
wordList objNames = names(ClassName); wordList objNames = names(clsName);
return wordList(objNames, findStrings(matcher, objNames)); return wordList(objNames, findStrings(matcher, objNames));
} }
@ -277,10 +279,10 @@ Foam::wordList Foam::IOobjectList::names
Foam::wordList Foam::IOobjectList::sortedNames Foam::wordList Foam::IOobjectList::sortedNames
( (
const word& ClassName const word& clsName
) const ) const
{ {
wordList sortedLst = names(ClassName); wordList sortedLst = names(clsName);
sort(sortedLst); sort(sortedLst);
return sortedLst; return sortedLst;
@ -289,11 +291,11 @@ Foam::wordList Foam::IOobjectList::sortedNames
Foam::wordList Foam::IOobjectList::sortedNames Foam::wordList Foam::IOobjectList::sortedNames
( (
const word& ClassName, const word& clsName,
const wordRe& matcher const wordRe& matcher
) const ) const
{ {
wordList sortedLst = names(ClassName, matcher); wordList sortedLst = names(clsName, matcher);
sort(sortedLst); sort(sortedLst);
return sortedLst; return sortedLst;
@ -302,11 +304,11 @@ Foam::wordList Foam::IOobjectList::sortedNames
Foam::wordList Foam::IOobjectList::sortedNames Foam::wordList Foam::IOobjectList::sortedNames
( (
const word& ClassName, const word& clsName,
const wordReList& matcher const wordReList& matcher
) const ) const
{ {
wordList sortedLst = names(ClassName, matcher); wordList sortedLst = names(clsName, matcher);
sort(sortedLst); sort(sortedLst);
return sortedLst; return sortedLst;

View File

@ -77,7 +77,7 @@ public:
); );
//- Construct as copy //- Construct as copy
IOobjectList(const IOobjectList&); IOobjectList(const IOobjectList& iolist);
//- Destructor //- Destructor
@ -87,52 +87,56 @@ public:
// Member functions // Member functions
//- Add an IOobject to the list //- Add an IOobject to the list
bool add(IOobject&); bool add(IOobject& io);
//- Remove an IOobject from the list //- Remove an IOobject from the list
bool remove(IOobject&); bool remove(IOobject& io);
//- Lookup a given name and return IOobject ptr if found else nullptr //- Lookup a given name and return IOobject ptr if found else nullptr
IOobject* lookup(const word& name) const; IOobject* lookup(const word& name) const;
//- Return the list for all IOobects whose name matches name //- The list of all IOobects with matching names
IOobjectList lookup(const wordRe& name) const; IOobjectList lookup(const wordRe& matcher) const;
//- Return the list for all IOobects whose name matches name //- The list of all IOobjects with matching names
IOobjectList lookup(const wordReList& patterns) const; IOobjectList lookup(const wordReList& matcher) const;
//- Return the list for all IOobjects of a given class //- The list of all IOobjects with the given class name
IOobjectList lookupClass(const word& className) const; IOobjectList lookupClass(const word& clsName) const;
//- A list of names of the IOobjects //- A list of names of the IOobjects
wordList names() const; wordList names() const;
//- A list of names of IOobjects of the given class //- The names of IOobjects with the given class name
wordList names(const word& className) const; wordList names(const word& clsName) const;
//- A list of names of IOobjects of the given class, //- The names of IOobjects with the given class name that also
// and that also satisfy the input matcher // have a name satisfying the input matcher
wordList names(const word& className, const wordRe&) const; wordList names(const word& clsName, const wordRe& matcher) const;
//- A list of names of IOobjects of the given class, //- The names of IOobjects with the given class name that also
// and that also satisfy the input matchers // have a name satisfying the input matcher
wordList names(const word& className, const wordReList&) const; wordList names(const word& clsName, const wordReList& matcher) const;
//- A sorted list of names of the IOobjects //- A sorted list of names of the IOobjects
wordList sortedNames() const; wordList sortedNames() const;
//- A sorted list of names of IOobjects of given class //- The sorted names of IOobjects with the given class name
wordList sortedNames(const word& className) const; wordList sortedNames(const word& clsName) const;
//- A sorted list of names of IOobjects of the given class, //- The sorted names of IOobjects with the given class name that also
// and that also satisfy the input matcher // have a name satisfying the input matcher
wordList sortedNames(const word& className, const wordRe&) const; wordList sortedNames(const word& clsName, const wordRe& matcher) const;
//- A sorted list of names of IOobjects of the given class, //- The sorted names of IOobjects with the given class name that also
// and that also satisfy the input matchers // have a name satisfying the input matcher
wordList sortedNames(const word& className, const wordReList&) const; wordList sortedNames
(
const word& clsName,
const wordReList& matcher
) const;
}; };

View File

@ -161,7 +161,7 @@ const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr
bool Foam::dictionary::findInPatterns bool Foam::dictionary::findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::const_iterator& wcLink, DLList<entry*>::const_iterator& wcLink,
DLList<autoPtr<regExp>>::const_iterator& reLink DLList<autoPtr<regExp>>::const_iterator& reLink
) const ) const
@ -173,8 +173,8 @@ bool Foam::dictionary::findInPatterns
if if
( (
patternMatch patternMatch
? reLink()->match(Keyword) ? reLink()->match(keyword)
: wcLink()->keyword() == Keyword : wcLink()->keyword() == keyword
) )
{ {
return true; return true;
@ -192,7 +192,7 @@ bool Foam::dictionary::findInPatterns
bool Foam::dictionary::findInPatterns bool Foam::dictionary::findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::iterator& wcLink, DLList<entry*>::iterator& wcLink,
DLList<autoPtr<regExp>>::iterator& reLink DLList<autoPtr<regExp>>::iterator& reLink
) )
@ -204,8 +204,8 @@ bool Foam::dictionary::findInPatterns
if if
( (
patternMatch patternMatch
? reLink()->match(Keyword) ? reLink()->match(keyword)
: wcLink()->keyword() == Keyword : wcLink()->keyword() == keyword
) )
{ {
return true; return true;
@ -951,11 +951,11 @@ void Foam::dictionary::set(const keyType& k, const dictionary& d)
} }
bool Foam::dictionary::remove(const word& Keyword) bool Foam::dictionary::remove(const word& keyword)
{ {
HashTable<entry*>::iterator iter = hashedEntries_.find(Keyword); HashTable<entry*>::iterator iter = hashedEntries_.find(keyword);
if (iter != hashedEntries_.end()) if (iter.found())
{ {
// Delete from patterns first // Delete from patterns first
DLList<entry*>::iterator wcLink = DLList<entry*>::iterator wcLink =
@ -964,7 +964,7 @@ bool Foam::dictionary::remove(const word& Keyword)
patternRegexps_.begin(); patternRegexps_.begin();
// Find in pattern using exact match only // Find in pattern using exact match only
if (findInPatterns(false, Keyword, wcLink, reLink)) if (findInPatterns(false, keyword, wcLink, reLink))
{ {
patternEntries_.remove(wcLink); patternEntries_.remove(wcLink);
patternRegexps_.remove(reLink); patternRegexps_.remove(reLink);

View File

@ -204,7 +204,7 @@ class dictionary
bool findInPatterns bool findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::const_iterator& wcLink, DLList<entry*>::const_iterator& wcLink,
DLList<autoPtr<regExp>>::const_iterator& reLink DLList<autoPtr<regExp>>::const_iterator& reLink
) const; ) const;
@ -213,7 +213,7 @@ class dictionary
bool findInPatterns bool findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::iterator& wcLink, DLList<entry*>::iterator& wcLink,
DLList<autoPtr<regExp>>::iterator& reLink DLList<autoPtr<regExp>>::iterator& reLink
); );
@ -518,7 +518,7 @@ public:
void set(const keyType& k, const T& t); void set(const keyType& k, const T& t);
//- Remove an entry specified by keyword //- Remove an entry specified by keyword
bool remove(const word& Keyword); bool remove(const word& keyword);
//- Change the keyword for an entry, //- Change the keyword for an entry,
// optionally forcing overwrite of an existing entry // optionally forcing overwrite of an existing entry

View File

@ -57,7 +57,7 @@ class dictionary;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
class entry; class entry;
Ostream& operator<<(Ostream&, const entry&); Ostream& operator<<(Ostream& os, const entry& e);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class entry Declaration Class entry Declaration
@ -75,11 +75,16 @@ class entry
// Private Member Functions // Private Member Functions
//- Get the next valid keyword. Return true if is valid keyType. //- Get the next valid keyword. Return true if a valid keyType.
static bool getKeyword(keyType&, token&, Istream&); static bool getKeyword
(
keyType& keyword,
token& keywordToken,
Istream& is
);
//- Get the next valid keyword otherwise return false //- Get the next valid keyword otherwise return false
static bool getKeyword(keyType&, Istream&); static bool getKeyword(keyType& keyword, Istream& is);
public: public:
@ -90,10 +95,10 @@ public:
// Constructors // Constructors
//- Construct from keyword //- Construct from keyword
entry(const keyType&); entry(const keyType& keyword);
//- Construct as copy //- Construct as copy
entry(const entry&); entry(const entry& e);
//- Construct on freestore as copy with reference to the //- Construct on freestore as copy with reference to the
// dictionary the copy belongs to // dictionary the copy belongs to
@ -107,7 +112,7 @@ public:
virtual autoPtr<entry> clone() const; virtual autoPtr<entry> clone() const;
//- Construct from Istream and insert into dictionary //- Construct from Istream and insert into dictionary
static bool New(dictionary& parentDict, Istream&); static bool New(dictionary& parentDict, Istream& is);
//- Construct on freestore from Istream and return //- Construct on freestore from Istream and return
static autoPtr<entry> New(Istream& is); static autoPtr<entry> New(Istream& is);
@ -179,7 +184,7 @@ public:
// Ostream operator // Ostream operator
friend Ostream& operator<<(Ostream&, const entry&); friend Ostream& operator<<(Ostream& os, const entry& e);
}; };

View File

@ -106,7 +106,7 @@ bool Foam::entry::getKeyword(keyType& keyword, Istream& is)
bool Foam::entry::New(dictionary& parentDict, Istream& is) bool Foam::entry::New(dictionary& parentDict, Istream& is)
{ {
is.fatalCheck("entry::New(const dictionary& parentDict, Istream&)"); is.fatalCheck(FUNCTION_NAME);
keyType keyword; keyType keyword;
token keyToken; token keyToken;
@ -324,7 +324,7 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
Foam::autoPtr<Foam::entry> Foam::entry::New(Istream& is) Foam::autoPtr<Foam::entry> Foam::entry::New(Istream& is)
{ {
is.fatalCheck("entry::New(Istream&)"); is.fatalCheck(FUNCTION_NAME);
keyType keyword; keyType keyword;

View File

@ -34,6 +34,8 @@ namespace Foam
int labelRange::debug(debug::debugSwitch("labelRange", 0)); int labelRange::debug(debug::debugSwitch("labelRange", 0));
} }
const Foam::labelRange Foam::labelRange::null;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -35,6 +35,7 @@ SourceFiles
#define labelRange_H #define labelRange_H
#include "label.H" #include "label.H"
#include <iterator>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -63,26 +64,32 @@ class labelRange
public: public:
// Static Data Members
static int debug; static int debug;
//- An empty range with start=0, size=0.
static const labelRange null;
// STL type definitions similar to what UList has // STL type definitions similar to what UList has
//- Type of values the range contains //- Type of values the range contains
typedef label value_type; typedef label value_type;
//- The type that can represent the difference between two iterators
typedef label difference_type;
//- The type that can represent the size of the range //- The type that can represent the size of the range
typedef label size_type; typedef label size_type;
// Forward declaration
class const_iterator;
// Constructors // Constructors
//- An empty range with zero for start/size. //- An empty range with zero for start/size.
inline labelRange(); inline labelRange();
//- Construct a range from start and size, enforcing non-negative size. //- Construct a range from start/size, enforcing non-negative size.
// Optionally adjust the start to avoid any negative indices. // Optionally adjust the start to avoid any negative indices.
inline labelRange inline labelRange
( (
@ -95,6 +102,12 @@ public:
labelRange(Istream& is); labelRange(Istream& is);
// Static Member Functions
//- An identity range with range[i] == i.
inline static labelRange identity(const label len);
// Member Functions // Member Functions
//- Adjust start position //- Adjust start position
@ -184,6 +197,9 @@ public:
//- Return element in the range, no bounds checking //- Return element in the range, no bounds checking
inline label operator[](const label localIndex) const; inline label operator[](const label localIndex) const;
//- Return const_iterator to element in the range
inline const_iterator operator()(const label localIndex) const;
//- Increase the size by 1. //- Increase the size by 1.
inline label operator++(); inline label operator++();
inline label operator++(int); inline label operator++(int);
@ -197,21 +213,30 @@ public:
//- Forward iterator with const access //- Forward iterator with const access
class const_iterator class const_iterator
:
public std::iterator
<
std::input_iterator_tag,
label,
label,
const label*,
const label&
>
{ {
//- The current label (not the local index) //- The current (global) value
label index_; label value_;
public: public:
// Constructors // Constructors
//- Construct from range at given local index. //- Construct from range at given local index.
// A negative index signals the 'end' position // A negative index is invalid and corresponds to the 'end'
inline const_iterator(const labelRange* range, const label i = 0); inline const_iterator(const labelRange* range, const label i=0);
// Member operators // Member operators
//- Return the current label //- Return the current (global) value
inline label operator*() const; inline label operator*() const;
inline const_iterator& operator++(); inline const_iterator& operator++();

View File

@ -64,7 +64,7 @@ inline Foam::labelRange::const_iterator::const_iterator
const label i const label i
) )
: :
index_ value_
( (
range->start() range->start()
+ ((i < 0 || i > range->size()) ? range->size() : i) + ((i < 0 || i > range->size()) ? range->size() : i)
@ -74,14 +74,14 @@ inline Foam::labelRange::const_iterator::const_iterator
inline Foam::label Foam::labelRange::const_iterator::operator*() const inline Foam::label Foam::labelRange::const_iterator::operator*() const
{ {
return index_; return value_;
} }
inline Foam::labelRange::const_iterator& inline Foam::labelRange::const_iterator&
Foam::labelRange::const_iterator::operator++() Foam::labelRange::const_iterator::operator++()
{ {
++index_; ++value_;
return *this; return *this;
} }
@ -90,7 +90,7 @@ inline Foam::labelRange::const_iterator
Foam::labelRange::const_iterator::operator++(int) Foam::labelRange::const_iterator::operator++(int)
{ {
const_iterator old = *this; const_iterator old = *this;
++index_; ++value_;
return old; return old;
} }
@ -100,7 +100,7 @@ inline bool Foam::labelRange::const_iterator::operator==
const const_iterator& iter const const_iterator& iter
) const ) const
{ {
return (this->index_ == iter.index_); return (this->value_ == iter.value_);
} }
@ -109,7 +109,7 @@ inline bool Foam::labelRange::const_iterator::operator!=
const const_iterator& iter const const_iterator& iter
) const ) const
{ {
return (this->index_ != iter.index_); return (this->value_ != iter.value_);
} }
@ -139,6 +139,12 @@ inline const Foam::labelRange::const_iterator Foam::labelRange::cend() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::labelRange Foam::labelRange::identity(const label len)
{
return labelRange(0, len);
}
inline void Foam::labelRange::setStart(const label i) inline void Foam::labelRange::setStart(const label i)
{ {
start_ = i; start_ = i;
@ -264,6 +270,13 @@ inline Foam::label Foam::labelRange::operator[](const label localIndex) const
} }
inline Foam::labelRange::const_iterator
Foam::labelRange::operator()(const label localIndex) const
{
return const_iterator(this, localIndex);
}
inline Foam::label Foam::labelRange::operator++() inline Foam::label Foam::labelRange::operator++()
{ {
return ++size_; return ++size_;