diff --git a/src/OpenFOAM/containers/Bits/bitSet/bitSet.H b/src/OpenFOAM/containers/Bits/bitSet/bitSet.H index 1ed379e172..b6f11d469c 100644 --- a/src/OpenFOAM/containers/Bits/bitSet/bitSet.H +++ b/src/OpenFOAM/containers/Bits/bitSet/bitSet.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -260,15 +260,17 @@ public: // \note Method name compatibility with boost::dynamic_bitset bool intersects(const bitSet& other) const; - //- Test value at specified position, never auto-vivify entries. + //- Test for \em True value at specified position, + //- never auto-vivify entries. // // \note Method name compatibility with std::bitset - inline bool test(const label pos) const; + bool test(const label pos) const { return this->get(pos); } - //- Test value at specified position, never auto-vivify entries. + //- Test for \em True value at specified position, + //- never auto-vivify entries. // // \note Method name compatibility with HashSet - inline bool found(const label pos) const; + bool contains(const label pos) const { return this->get(pos); } //- Locate the first bit that is set. // \return the location or -1 if there are no bits set. @@ -611,6 +613,9 @@ public: // Housekeeping + //- Same as contains() + bool found(const label pos) const { return this->contains(pos); } + //- Deprecated(2020-11) use fill() // \deprecated(2020-11) use fill() void assign(const unsigned int val) { this->fill(val); } diff --git a/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H b/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H index a32f68db8b..11c03310f9 100644 --- a/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H +++ b/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H @@ -518,18 +518,6 @@ inline unsigned int Foam::bitSet::count(const bool on) const } -inline bool Foam::bitSet::test(const label pos) const -{ - return get(pos); -} - - -inline bool Foam::bitSet::found(const label pos) const -{ - return get(pos); -} - - inline Foam::labelList Foam::bitSet::sortedToc() const { return toc(); diff --git a/src/OpenFOAM/containers/Buffers/CircularBuffer.H b/src/OpenFOAM/containers/Buffers/CircularBuffer.H index dcee40e2cd..a9605714b9 100644 --- a/src/OpenFOAM/containers/Buffers/CircularBuffer.H +++ b/src/OpenFOAM/containers/Buffers/CircularBuffer.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022 OpenCFD Ltd. + Copyright (C) 2022-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -288,11 +288,11 @@ public: // \return position in list or -1 if not found. label find(const T& val, label pos = 0) const; - //- True if the value if found in the list. + //- Is the value contained in the list? + // Linear search from start pos until the end of the list. // Any occurrences before the start pos are ignored. - // Linear search. // \return true if found. - inline bool found(const T& val, label pos = 0) const; + inline bool contains(const T& val, label pos = 0) const; // Stack-like Operations @@ -480,6 +480,12 @@ public: // Housekeeping + //- Same as contains() + bool found(const T& val, label pos = 0) const + { + return contains(val, pos); + } + //- Access the first element (front). Requires !empty(). //FOAM_DEPRECATED_FOR(2022-10, "front()") T& first() { return front(); } diff --git a/src/OpenFOAM/containers/Buffers/CircularBufferI.H b/src/OpenFOAM/containers/Buffers/CircularBufferI.H index af2c29d794..d6ffa2ec81 100644 --- a/src/OpenFOAM/containers/Buffers/CircularBufferI.H +++ b/src/OpenFOAM/containers/Buffers/CircularBufferI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022 OpenCFD Ltd. + Copyright (C) 2022-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -256,7 +256,7 @@ inline void Foam::CircularBuffer::reserve_nocopy(const label len) template -inline bool Foam::CircularBuffer::found(const T& val, label pos) const +inline bool Foam::CircularBuffer::contains(const T& val, label pos) const { return (this->find(val, pos) >= 0); } @@ -395,7 +395,7 @@ inline void Foam::CircularBuffer::pop_back(label n) template inline Foam::label Foam::CircularBuffer::push_uniq(const T& val) { - if (this->found(val)) + if (this->contains(val)) { return 0; } diff --git a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C index d49a3c82cb..79c4b8f43c 100644 --- a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C +++ b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2022 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -87,9 +87,9 @@ Foam::DictionaryBase::DictionaryBase(Istream& is) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -bool Foam::DictionaryBase::found(const word& keyword) const +bool Foam::DictionaryBase::contains(const word& keyword) const { - return hashedTs_.found(keyword); + return hashedTs_.contains(keyword); } @@ -217,7 +217,7 @@ T* Foam::DictionaryBase::remove(const word& keyword) if (iter.found()) { - T* ptr = IDLListType::remove(iter()); + T* ptr = IDLListType::remove(iter.val()); hashedTs_.erase(iter); return ptr; } diff --git a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H index e94927e374..6d14d85d04 100644 --- a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H +++ b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020-2022 OpenCFD Ltd. + Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -114,7 +114,7 @@ public: // Search and lookup //- Search for given keyword - bool found(const word& keyword) const; + bool contains(const word& keyword) const; //- Find and return an entry, nullptr on failure. const T* cfind(const word& keyword) const; @@ -188,6 +188,9 @@ public: // Housekeeping + //- Same as contains() + bool found(const word& key) const { return this->contains(key); } + //- Deprecated(2020-03) use cfind() // \deprecated(2020-03) - use cfind() method FOAM_DEPRECATED_FOR(2020-03, "cfind() method") diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableI.H b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableI.H index 50f29c4415..682d24c8f6 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableI.H +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableI.H @@ -87,7 +87,7 @@ inline bool Foam::HashPtrTable::emplace // Use insertion semantics return ( - !parent_type::found(key) + !parent_type::contains(key) && this->parent_type::set(key, new T(std::forward(args)...)) ); } diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C index 1315f1ee9f..02d2390f66 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C @@ -237,14 +237,14 @@ inline Foam::label Foam::HashSet::unset template inline bool Foam::HashSet::operator()(const Key& key) const noexcept { - return this->found(key); + return this->contains(key); } template inline bool Foam::HashSet::operator[](const Key& key) const noexcept { - return this->found(key); + return this->contains(key); } @@ -281,7 +281,7 @@ bool Foam::HashSet::operator==(const HashSet& rhs) const for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) { - if (!this->found(iter.key())) + if (!this->contains(iter.key())) { return false; } @@ -328,7 +328,7 @@ Foam::HashSet::operator^=(const HashSet& rhs) // Add missed rhs elements, remove duplicate elements for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter) { - if (this->found(iter.key())) + if (this->contains(iter.key())) { this->erase(iter.key()); } @@ -395,7 +395,7 @@ Foam::HashSet Foam::operator& for (const Key& k : a) { - if (b.found(k)) + if (b.contains(k)) { result.insert(k); } @@ -429,7 +429,7 @@ Foam::HashSet Foam::operator- for (const Key& k : a) { - if (!b.found(k)) + if (!b.contains(k)) { result.insert(k); } diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H index 042211fc19..141fad2696 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -176,11 +176,11 @@ public: // Member Functions - //- Same as found() - return true if key exists in the set. + //- Same as contains() - return true if key exists in the set. // Method name compatibility with bitSet and boolList. bool test(const Key& key) const { - return this->found(key); + return this->contains(key); } @@ -322,11 +322,11 @@ public: // Member Operators - //- Return true if the entry exists, same as found() + //- Return true if the entry exists, same as contains() // \note this allows use of HashSet as a predicate test inline bool operator()(const Key& key) const noexcept; - //- Return true if the entry exists, same as found(). + //- Return true if the entry exists, same as contains(). inline bool operator[](const Key& key) const noexcept; //- Copy assign diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C index ef58ea00ca..94d91e5d80 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C @@ -553,7 +553,7 @@ Foam::label Foam::HashTable::erase ++iter ) { - if (other.found(iter.key()) && erase(iter)) + if (other.contains(iter.key()) && erase(iter)) { ++changed; } @@ -586,7 +586,7 @@ Foam::label Foam::HashTable::retain for (iterator iter = begin(); iter != end(); ++iter) { - if (!other.found(iter.key()) && erase(iter)) + if (!other.contains(iter.key()) && erase(iter)) { ++changed; } diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index d46dd8eae6..dcec3f00fa 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -57,7 +57,7 @@ Note forAllConstIters(table, iter) { Info<< "val:" << *iter << nl - << "key:" << iter.key() << nl; + << "key:" << iter.key() << nl << "val:" << iter.val() << nl; } \endcode @@ -213,18 +213,6 @@ private: Ostream& writeTable(Ostream& os) const; -protected: - - //- Internally used base for iterator and const_iterator - template class Iterator; - - //- An iterator with const access to HashTable internals. - friend class Iterator; - - //- An iterator with non-const access to HashTable internals. - friend class Iterator; - - public: // Constructors @@ -272,8 +260,8 @@ public: //- Find and return a hashed entry. FatalError if it does not exist. inline const T& at(const Key& key) const; - //- True if hashed key is found in table - inline bool found(const Key& key) const; + //- True if hashed key is contained (found) in table + inline bool contains(const Key& key) const; //- Find and return an iterator set at the hashed entry // If not found iterator = end() @@ -548,9 +536,11 @@ public: // Member Operators //- Find and return a hashed entry. FatalError if it does not exist. + // Same as at(). inline T& operator[](const Key& key); //- Find and return a hashed entry. FatalError if it does not exist. + // Same as at(). inline const T& operator[](const Key& key) const; //- Return existing entry or create a new entry. @@ -586,6 +576,15 @@ protected: // Iterators and helpers + //- Internally used base for iterator and const_iterator + template class Iterator; + + //- Allow iterator access to HashTable internals. + friend class Iterator; + + //- Allow iterator access to HashTable internals. + friend class Iterator; + //- The iterator base for HashTable (internal use only). // Note: data and functions are protected, to allow reuse by iterator // and prevent most external usage. @@ -908,13 +907,13 @@ public: reference operator*() const { return this->key(); } reference operator()() const { return this->key(); } - inline key_iterator_base& operator++() + key_iterator_base& operator++() { this->increment(); return *this; } - inline key_iterator_base operator++(int) + key_iterator_base operator++(int) { key_iterator_base iter(*this); this->increment(); @@ -981,6 +980,12 @@ public: Ostream&, const HashTable& tbl ); + + + // Housekeeping + + //- Same as contains() + bool found(const Key& key) const { return this->contains(key); } }; diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H index 86fd95a488..4fa30d87f0 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,7 +76,7 @@ inline const T& Foam::HashTable::at(const Key& key) const template -inline bool Foam::HashTable::found(const Key& key) const +inline bool Foam::HashTable::contains(const Key& key) const { if (size_) { diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H index 16b4d2c81a..873c43051a 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -191,10 +191,11 @@ public: // \return -1 if not found. label rfind(const T& val, label pos = -1) const; - //- True if the value if found in the list. + //- Is the value contained in the list? + // Linear search from start pos until the end of the list. // Any occurrences before the start pos are ignored. - // Linear search. - inline bool found(const T& val, label pos=0) const; + // \return true if found. + inline bool contains(const T& val, label pos = 0) const; // Member Operators @@ -382,6 +383,12 @@ public: //- Access last element of the list, position [size()-1] //FOAM_DEPRECATED_FOR(2022-10, "back()") const T& last() const { return back(); }; + + //- Same as contains() + bool found(const T& val, label pos = 0) const + { + return this->contains(val, pos); + } }; diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H index 45afc104ce..f682f0c8bc 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -99,7 +99,7 @@ inline bool Foam::IndirectListBase::uniform() const template -inline bool Foam::IndirectListBase::found +inline bool Foam::IndirectListBase::contains ( const T& val, label pos diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 12ea3ac670..27d3209987 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -661,7 +661,7 @@ inline void Foam::DynamicList::push_back template inline Foam::label Foam::DynamicList::push_uniq(const T& val) { - if (this->found(val)) + if (this->contains(val)) { return 0; } diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 6d172d0df4..28ed899ba4 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -293,10 +293,11 @@ public: // \return position in list or -1 if not found. label rfind(const T& val, label pos = -1) const; - //- True if the value if found in the list. + //- Is the value contained in the list? + // Linear search from start pos until the end of the list. // Any occurrences before the start pos are ignored. - // Linear search. - inline bool found(const T& val, label pos = 0) const; + // \return true if found. + inline bool contains(const T& val, label pos = 0) const; // Edit @@ -522,6 +523,12 @@ public: //- Access last element of the list, position [N-1] - back() const T& last() const noexcept { return back(); } + + //- Same as contains() + bool found(const T& val, label pos = 0) const + { + return this->contains(val, pos); + } }; diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index c2718e2aba..25874664b5 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -345,11 +345,7 @@ inline bool Foam::FixedList::uniform() const template -inline bool Foam::FixedList::found -( - const T& val, - label pos -) const +inline bool Foam::FixedList::contains(const T& val, label pos) const { return (this->find(val, pos) >= 0); } diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index e50b8fc18f..0ae68fbf20 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -248,7 +248,7 @@ inline void Foam::List::push_back(const IndirectListBase& list) template inline Foam::label Foam::List::push_uniq(const T& val) { - if (this->found(val)) + if (this->contains(val)) { return 0; } diff --git a/src/OpenFOAM/containers/Lists/List/UList.H b/src/OpenFOAM/containers/Lists/List/UList.H index ac241aef9a..2c6339e1c9 100644 --- a/src/OpenFOAM/containers/Lists/List/UList.H +++ b/src/OpenFOAM/containers/Lists/List/UList.H @@ -325,11 +325,11 @@ public: // \return position in list or -1 if not found. label rfind(const T& val, label pos = -1) const; - //- True if the value if found in the list. + //- Is the value contained in the list? + // Linear search from start pos until the end of the list. // Any occurrences before the start pos are ignored. - // Linear search. // \return true if found. - inline bool found(const T& val, label pos = 0) const; + inline bool contains(const T& val, label pos = 0) const; // Edit @@ -611,6 +611,12 @@ public: //- Access last element of the list, position [size()-1] //FOAM_DEPRECATED_FOR(2022-10, "back()") const T& last() const { return back(); }; + + //- Same as contains() + bool found(const T& val, label pos = 0) const + { + return this->contains(val, pos); + } }; diff --git a/src/OpenFOAM/containers/Lists/List/UListI.H b/src/OpenFOAM/containers/Lists/List/UListI.H index 6d9519fb8b..93f6a1788c 100644 --- a/src/OpenFOAM/containers/Lists/List/UListI.H +++ b/src/OpenFOAM/containers/Lists/List/UListI.H @@ -262,7 +262,7 @@ inline std::streamsize Foam::UList::size_bytes() const noexcept template -inline bool Foam::UList::found(const T& val, label pos) const +inline bool Foam::UList::contains(const T& val, label pos) const { return (this->find(val, pos) >= 0); } diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C index cb0c0db8ce..7cb9e521ae 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2022 OpenCFD Ltd. + Copyright (C) 2015-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1095,7 +1095,8 @@ void Foam::ListOps::uniqueEqOp::operator() { for (const T& val : y) { - if (!x.found(val)) + // --> x.push_uniq(val) + if (!x.contains(val)) { x.push_back(val); } diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index 044d6c92c7..af4e2b6f12 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -450,7 +450,7 @@ const Foam::regIOobject* Foam::objectRegistry::cfindIOobject } -bool Foam::objectRegistry::found +bool Foam::objectRegistry::contains ( const word& name, const bool recursive diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index 00145b1ee1..d8a56712bb 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -413,11 +413,11 @@ public: const bool recursive = false ) const; - //- Can the regIOobject object be found (by name). + //- Does the registry contain the regIOobject object (by name). // + // \param name the object name // \param recursive search parent registries - bool found(const word& name, const bool recursive = false) const; - + bool contains(const word& name, const bool recursive = false) const; //- Is the named Type found? // @@ -591,6 +591,12 @@ public: // Housekeeping + //- Same as contains() + bool found(const word& name, bool recursive = false) const + { + return this->contains(name, recursive); + } + //- Deprecated(2018-10) find object // \deprecated(2018-10) - use findObject() method template diff --git a/src/OpenFOAM/interpolations/interpolationLookUpTable/interpolationLookUpTable.C b/src/OpenFOAM/interpolations/interpolationLookUpTable/interpolationLookUpTable.C index afb4f37542..d1fb03cc0f 100644 --- a/src/OpenFOAM/interpolations/interpolationLookUpTable/interpolationLookUpTable.C +++ b/src/OpenFOAM/interpolations/interpolationLookUpTable/interpolationLookUpTable.C @@ -424,9 +424,9 @@ Foam::interpolationLookUpTable::operator[](const label i) const template -bool Foam::interpolationLookUpTable::found(const word& fieldName) const +bool Foam::interpolationLookUpTable::contains(const word& fieldName) const { - return fieldIndices_.found(fieldName); + return fieldIndices_.contains(fieldName); } diff --git a/src/OpenFOAM/interpolations/interpolationLookUpTable/interpolationLookUpTable.H b/src/OpenFOAM/interpolations/interpolationLookUpTable/interpolationLookUpTable.H index fd9f0c3cf4..e3f142daf8 100644 --- a/src/OpenFOAM/interpolations/interpolationLookUpTable/interpolationLookUpTable.H +++ b/src/OpenFOAM/interpolations/interpolationLookUpTable/interpolationLookUpTable.H @@ -39,8 +39,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef interpolationLookUpTable_H -#define interpolationLookUpTable_H +#ifndef Foam_interpolationLookUpTable_H +#define Foam_interpolationLookUpTable_H #include "List.H" #include "ListOps.H" @@ -162,7 +162,7 @@ public: // Member Functions //- Return true if the field exists in the table - bool found(const word& fieldName) const; + bool contains(const word& fieldName) const; //- Return the output list given a single input scalar const List& lookUp(const scalar); @@ -212,6 +212,14 @@ public: //- Return an element of List scalarField& operator[](const label); + + // Housekeeping + + //- Same as contains() + bool found(const word& fieldName) const + { + return this->contains(fieldName); + } }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edge.H b/src/OpenFOAM/meshes/meshShapes/edge/edge.H index bc653b49c9..5557ce4045 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edge.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edge.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -153,9 +153,9 @@ public: //- True if the vertices are unique and non-negative. bool valid() const noexcept { return good(); } - //- Return true if point label is found in edge. + //- Return true if the point label is contained in the edge. // Always false for a negative label. - inline bool found(const label pointLabel) const; + inline bool contains(const label pointLabel) const; //- Return local index (0,1) of point label in edge -1 on failure // Always return -1 for a negative label. @@ -321,6 +321,12 @@ public: } }; + + // Housekeeping + + //- Same as contains() + bool found(label vertex) const { return contains(vertex); } + //- Deprecated(2021-04) hashing functor. Use hasher() // \deprecated(2021-04) - use hasher() functor template diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H index 761948e2d0..879a413de1 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H @@ -110,7 +110,7 @@ inline bool Foam::edge::good() const noexcept } -inline bool Foam::edge::found(const label pointLabel) const +inline bool Foam::edge::contains(const label pointLabel) const { // -1: always false return @@ -142,17 +142,17 @@ inline Foam::label Foam::edge::which(const label pointLabel) const inline bool Foam::edge::connected(const edge& other) const { - return (other.found(first()) || other.found(second())); + return (other.contains(first()) || other.contains(second())); } inline Foam::label Foam::edge::commonVertex(const edge& other) const { - if (other.found(first())) + if (other.contains(first())) { return first(); } - if (other.found(second())) + if (other.contains(second())) { return second(); } diff --git a/src/OpenFOAM/meshes/meshShapes/face/faceI.H b/src/OpenFOAM/meshes/meshShapes/face/faceI.H index f54203a27e..fee4a2049c 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/faceI.H +++ b/src/OpenFOAM/meshes/meshShapes/face/faceI.H @@ -209,7 +209,7 @@ inline bool Foam::face::connected(const labelUList& other) const { for (const label pointi : *this) { - if (other.found(pointi)) + if (other.contains(pointi)) { return true; } @@ -223,7 +223,7 @@ inline bool Foam::face::connected(const FixedList& other) const { for (const label pointi : *this) { - if (other.found(pointi)) + if (other.contains(pointi)) { return true; } diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.C b/src/OpenFOAM/primitives/bools/Switch/Switch.C index 36a4647b3d..8e3528e048 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.C +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -154,7 +154,7 @@ Foam::Switch Foam::Switch::find(const std::string& str) } -bool Foam::Switch::found(const std::string& str) +bool Foam::Switch::contains(const std::string& str) { return (switchType::INVALID != parse(str, false)); // failOnError=false } diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.H b/src/OpenFOAM/primitives/bools/Switch/Switch.H index b6e44fe89b..a420eaddd8 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.H +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -209,13 +209,13 @@ public: //- A string representation of bool as "false" / "true" static const char* name(const bool b) noexcept; + //- True if there is a switch type corresponding to the given string. + static bool contains(const std::string& str); + //- Find switchType for the given string, returning as a Switch that //- can be tested for good() or bad(). static Switch find(const std::string& str); - //- Test if there is a switch type corresponding to the given string. - static bool found(const std::string& str); - // Member Functions @@ -271,6 +271,9 @@ public: // Housekeeping + //- Same as contains() + static bool found(const std::string& str) { return contains(str); } + //- Deprecated(2020-01) From string with/without bad input test // \deprecated(2020-01) - confusing syntax, use static find() method FOAM_DEPRECATED_FOR(2019-02, "static find() method") @@ -281,13 +284,10 @@ public: FOAM_DEPRECATED_FOR(2019-02, "static find() method") Switch(const char* str, bool allowBad); - //- Deprecated(2020-01) Use good() method, or static found() method - // \deprecated(2020-01) Use good() method, or static found() method - FOAM_DEPRECATED_FOR(2019-02, "good() or static found() method") - bool valid() const noexcept - { - return good(); - } + //- Deprecated(2020-01) Use good() method, or static contains() method + // \deprecated(2020-01) Use good() method, or static contains() method + FOAM_DEPRECATED_FOR(2019-02, "good() or static contains() method") + bool valid() const noexcept { return good(); } //- Same as getOrAddToDict() static Switch lookupOrAddToDict diff --git a/src/OpenFOAM/primitives/enums/Enum.H b/src/OpenFOAM/primitives/enums/Enum.H index 7427062310..321e2ec4a1 100644 --- a/src/OpenFOAM/primitives/enums/Enum.H +++ b/src/OpenFOAM/primitives/enums/Enum.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -139,6 +139,12 @@ public: // Query + //- True if there is an enumeration corresponding to the given name. + inline bool contains(const word& enumName) const; + + //- True if there is a name corresponding to the given enumeration. + inline bool contains(const EnumType e) const; + //- Find the index of the given name. // \return position in list or -1 if not found. inline label find(const word& enumName) const; @@ -147,12 +153,6 @@ public: // \return position in list or -1 if not found. inline label find(const EnumType e) const; - //- True if there is an enumeration corresponding to the given name. - inline bool found(const word& enumName) const; - - //- True if there is a name corresponding to the given enumeration. - inline bool found(const EnumType e) const; - //- The enumeration corresponding to the given name. // FatalError if not found. EnumType get(const word& enumName) const; @@ -319,7 +319,6 @@ public: return getOrDefault(key, dict, deflt, failsafe); } - //- Deprecated(2020-11) use get() method // \deprecated(2020-11) - use get() method FOAM_DEPRECATED_FOR(2020-11, "get() method") @@ -361,6 +360,12 @@ public: { push_back(list); } + + //- Same as contains() + bool found(const word& enumName) const { return contains(enumName); } + + //- Same as contains() + bool found(const EnumType e) const { return contains(e); } }; diff --git a/src/OpenFOAM/primitives/enums/EnumI.H b/src/OpenFOAM/primitives/enums/EnumI.H index c011692dd2..4a8a3d0086 100644 --- a/src/OpenFOAM/primitives/enums/EnumI.H +++ b/src/OpenFOAM/primitives/enums/EnumI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -100,16 +100,16 @@ inline Foam::label Foam::Enum::find(const EnumType e) const template -inline bool Foam::Enum::found(const word& enumName) const +inline bool Foam::Enum::contains(const word& enumName) const { - return keys_.found(enumName); + return keys_.contains(enumName); } template -inline bool Foam::Enum::found(const EnumType e) const +inline bool Foam::Enum::contains(const EnumType e) const { - return vals_.found(int(e)); + return vals_.contains(int(e)); } diff --git a/src/OpenFOAM/primitives/predicates/scalar/scalarPredicates.H b/src/OpenFOAM/primitives/predicates/scalar/scalarPredicates.H index 0f8d1315cf..3107efe1c4 100644 --- a/src/OpenFOAM/primitives/predicates/scalar/scalarPredicates.H +++ b/src/OpenFOAM/primitives/predicates/scalar/scalarPredicates.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -270,7 +270,7 @@ public: // Search - //- Index of the first match for the value. + //- Index of the first matching test for the value. // Any occurrences before the start pos are ignored. // Linear search. // \return position in list or -1 if not found. @@ -282,23 +282,23 @@ public: // \return position in list or -1 if not found. label rfind(const scalar value, label pos = -1) const; - //- True if the value matches any in the list. + //- True if the value matches in the list. + // Linear search from start pos until the end of the list. // Any occurrences before the start pos are ignored. - // Linear search. // \return true if found. - inline bool found(const scalar value, label pos=0) const; + inline bool contains(const scalar value, label pos = 0) const; - //- Match any condition in the list. + //- Match \em any condition in the list. // // \return True if the value matches any condition in the list. inline bool match(const scalar value) const; - //- Match any condition in the list. + //- Match \em any condition in the list. // // \return True if the value matches any condition in the list. inline bool matchAny(const scalar value) const; - //- Match all conditions in the list. + //- Match \em all conditions in the list. // // \return True if the value matches all conditions in the list. inline bool matchAll(const scalar value) const; @@ -324,8 +324,17 @@ public: // Member Operators - //- Identical to found(), match(), for use as a predicate. + //- Identical to contains(), match(), for use as a predicate. inline bool operator()(const scalar value) const; + + + // Housekeeping + + //- Same as contains() + bool found(const scalar value, label pos = 0) const + { + return this->contains(value, pos); + } }; diff --git a/src/OpenFOAM/primitives/predicates/scalar/scalarPredicatesI.H b/src/OpenFOAM/primitives/predicates/scalar/scalarPredicatesI.H index 2275d29cdc..3f6fcf4b9e 100644 --- a/src/OpenFOAM/primitives/predicates/scalar/scalarPredicatesI.H +++ b/src/OpenFOAM/primitives/predicates/scalar/scalarPredicatesI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -60,7 +60,7 @@ inline Foam::predicates::scalars::unary Foam::predicates::scalars::operation // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline bool Foam::predicates::scalars::found +inline bool Foam::predicates::scalars::contains ( const scalar value, label pos diff --git a/src/OpenFOAM/primitives/strings/lists/hashedWordList.H b/src/OpenFOAM/primitives/strings/lists/hashedWordList.H index 1e2cc0c27a..7be6f41e0b 100644 --- a/src/OpenFOAM/primitives/strings/lists/hashedWordList.H +++ b/src/OpenFOAM/primitives/strings/lists/hashedWordList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -142,8 +142,8 @@ public: // \return position in list or -1 if not found. inline label find(const word& val) const; - //- True if the value if found in the list (searches the hash). - inline bool found(const word& val) const; + //- Is the value contained in the list (searches the hash). + inline bool contains(const word& val) const; // Member Operators @@ -156,7 +156,7 @@ public: // \return position in list or -1 if not found. inline label operator[](const word& val) const; - //- Check hashed values for the specified name - same as found(). + //- Check hashed values for the specified name - same as contains(). // Can be used as a unary predicate. inline bool operator()(const word& val) const; @@ -181,6 +181,9 @@ public: // Housekeeping + //- Same as contains(), searches the hash. + bool found(const word& val) const { return this->contains(val); } + //- Append an element if not already in the list. FOAM_DEPRECATED_FOR(2022-05, "push_uniq method") void append(const word& val) { this->push_uniq(val); } @@ -192,11 +195,6 @@ public: //- Append an element if not already in the list. //FOAM_DEPRECATED_FOR(2022-10, "push_uniq method") label appendUniq(const word& val) { return this->push_uniq(val); } - - //- Deprecated(2019-01) Is the specified name found in the list? - // \deprecated(2019-01) - use found() method - FOAM_DEPRECATED_FOR(2019-01, "found() method") - bool contains(const word& val) const { return this->found(val); } }; diff --git a/src/OpenFOAM/primitives/strings/lists/hashedWordListI.H b/src/OpenFOAM/primitives/strings/lists/hashedWordListI.H index efb69f77dd..0c2b520cd7 100644 --- a/src/OpenFOAM/primitives/strings/lists/hashedWordListI.H +++ b/src/OpenFOAM/primitives/strings/lists/hashedWordListI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -130,9 +130,9 @@ inline Foam::label Foam::hashedWordList::find(const word& val) const } -inline bool Foam::hashedWordList::found(const word& val) const +inline bool Foam::hashedWordList::contains(const word& val) const { - return lookup().found(val); + return lookup().contains(val); } @@ -201,7 +201,7 @@ inline Foam::label Foam::hashedWordList::operator[](const word& val) const inline bool Foam::hashedWordList::operator()(const word& val) const { - return lookup_.found(val); + return lookup_.contains(val); }