Commit 3d591980 authored by T.J. Corona's avatar T.J. Corona
Browse files

In keeping with C++ standards, use 'contains' in favor of 'has'

parent 6be03923
......@@ -168,23 +168,23 @@ struct tuple_index<T, std::tuple<U, Types...> >
/// not the type is in the tuple.
///
/// Examples:
/// tuple_has<bool, std::tuple<int, bool, float>>() == true
/// tuple_has<bool, std::tuple<int, float>>() == false
/// tuple_contains<bool, std::tuple<int, bool, float>>() == true
/// tuple_contains<bool, std::tuple<int, float>>() == false
template <typename T, typename Tuple>
struct tuple_has;
struct tuple_contains;
template <typename T>
struct tuple_has<T, std::tuple<> > : std::false_type
struct tuple_contains<T, std::tuple<> > : std::false_type
{
};
template <typename T, typename U, typename... Ts>
struct tuple_has<T, std::tuple<U, Ts...> > : tuple_has<T, std::tuple<Ts...> >
struct tuple_contains<T, std::tuple<U, Ts...> > : tuple_contains<T, std::tuple<Ts...> >
{
};
template <typename T, typename... Ts>
struct tuple_has<T, std::tuple<T, Ts...> > : std::true_type
struct tuple_contains<T, std::tuple<T, Ts...> > : std::true_type
{
};
......
......@@ -357,12 +357,12 @@ bool Attribute::removeExpungedEntities(const smtk::model::EntityRefs& expungedEn
bool Attribute::isObjectAssociated(const smtk::common::UUID& entity) const
{
return m_associatedObjects ? m_associatedObjects->has(entity) : false;
return m_associatedObjects ? m_associatedObjects->contains(entity) : false;
}
bool Attribute::isObjectAssociated(const smtk::resource::PersistentObjectPtr& comp) const
{
return m_associatedObjects ? m_associatedObjects->has(comp) : false;
return m_associatedObjects ? m_associatedObjects->contains(comp) : false;
}
/**\brief Is the model \a entity associated with this attribute?
......@@ -379,7 +379,7 @@ bool Attribute::isEntityAssociated(const smtk::common::UUID& entity) const
bool Attribute::isEntityAssociated(const smtk::model::EntityRef& entityref) const
{
auto comp = entityref.component();
return (comp && m_associatedObjects) ? m_associatedObjects->has(comp) : false;
return (comp && m_associatedObjects) ? m_associatedObjects->contains(comp) : false;
}
/**\brief Return the associated model entities as a set of UUIDs.
......
......@@ -72,7 +72,7 @@ bool ModelEntityItem::appendValue(const smtk::model::EntityRef& val)
/**\brief
*
*/
bool ModelEntityItem::has(const smtk::model::EntityRef& entity) const
bool ModelEntityItem::contains(const smtk::model::EntityRef& entity) const
{
return this->find(entity.entityRecord()) >= 0;
}
......
......@@ -65,7 +65,7 @@ public:
bool appendValue(const smtk::model::EntityRef& val);
bool has(const smtk::model::EntityRef& entity) const;
bool contains(const smtk::model::EntityRef& entity) const;
std::ptrdiff_t find(const smtk::model::EntityRef& entity) const;
......
......@@ -321,18 +321,14 @@ std::size_t ReferenceItem::maxNumberOfValues() const
return def->maxNumberOfValues();
}
bool ReferenceItem::contains(const smtk::resource::PersistentObjectPtr& obj) const
bool ReferenceItem::contains(const smtk::common::UUID& entity) const
{
bool doesContain = false;
this->visit([&](const PersistentObjectPtr& other) {
if (other == obj)
{
doesContain = true;
return false; // stop iterating
}
return true; // keep iterating
});
return doesContain;
return this->find(entity) >= 0;
}
bool ReferenceItem::contains(const PersistentObjectPtr& entity) const
{
return this->find(entity) >= 0;
}
void ReferenceItem::visit(std::function<bool(const PersistentObjectPtr&)> visitor) const
......@@ -581,16 +577,6 @@ bool ReferenceItem::isExtensible() const
return def->isExtensible();
}
bool ReferenceItem::has(const smtk::common::UUID& entity) const
{
return this->find(entity) >= 0;
}
bool ReferenceItem::has(const PersistentObjectPtr& entity) const
{
return this->find(entity) >= 0;
}
ReferenceItem::const_iterator ReferenceItem::begin() const
{
this->resolve();
......
......@@ -145,6 +145,9 @@ public:
/// Return true if the ReferenceItem contains a reference to the given object.
bool contains(const smtk::resource::PersistentObjectPtr& obj) const;
/// Return true if the component is contained in this item; false otherwise.
bool contains(const smtk::common::UUID& compId) const;
/**\brief Invoke a method on each value of this item.
*
* If the lambda returns false, iteration will terminate immediately.
......@@ -273,11 +276,6 @@ public:
/// A convenience method returning whether the item's definition is extensible.
bool isExtensible() const;
/// Return true if the component is contained in this item; false otherwise.
bool has(const smtk::common::UUID& compId) const;
/// Return true if \a obj is contained in this item; false otherwise.
bool has(const PersistentObjectPtr& obj) const;
/**\brief Return an iterator to the first model-entity value in this item.
*
*/
......
......@@ -55,7 +55,7 @@ public:
bool remove(const std::string& value) { return m_values.erase(value) > 0; }
bool has(const std::string& value) const { return m_values.find(value) != m_values.end(); }
bool contains(const std::string& value) const { return m_values.find(value) != m_values.end(); }
bool operator<(const Tag& rhs) const { return m_name < rhs.m_name; }
......
......@@ -31,12 +31,12 @@ PySharedPtrClass< smtk::attribute::ComponentItem, smtk::attribute::ReferenceItem
.def("appendValue", &smtk::attribute::ComponentItem::appendValue, py::arg("val"))
.def("assign", &smtk::attribute::ComponentItem::assign, py::arg("sourceItem"), py::arg("options") = 0)
.def("begin", &smtk::attribute::ComponentItem::begin)
.def("contains", (bool (smtk::attribute::ComponentItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ComponentItem::contains, py::arg("compId"))
.def("contains", (bool (smtk::attribute::ComponentItem::*)(const ::smtk::resource::PersistentObjectPtr&) const) &smtk::attribute::ComponentItem::contains, py::arg("comp"))
.def("definition", &smtk::attribute::ComponentItem::definition)
.def("end", &smtk::attribute::ComponentItem::end)
.def("find", (ptrdiff_t (smtk::attribute::ComponentItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ComponentItem::find, py::arg("compId"))
.def("find", (ptrdiff_t (smtk::attribute::ComponentItem::*)(const ::smtk::resource::PersistentObjectPtr&) const) &smtk::attribute::ComponentItem::find, py::arg("component"))
.def("has", (bool (smtk::attribute::ComponentItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ComponentItem::has, py::arg("compId"))
.def("has", (bool (smtk::attribute::ComponentItem::*)(const ::smtk::resource::PersistentObjectPtr&) const) &smtk::attribute::ComponentItem::has, py::arg("comp"))
.def("isExtensible", &smtk::attribute::ComponentItem::isExtensible)
.def("isSet", &smtk::attribute::ComponentItem::isSet, py::arg("i") = 0)
.def("isValueValid", (bool (smtk::attribute::ComponentItem::*)(const ::smtk::resource::ComponentPtr) const) &smtk::attribute::ComponentItem::isValueValid, py::arg("val"))
......
......@@ -34,8 +34,8 @@ PySharedPtrClass< smtk::attribute::ModelEntityItem, smtk::attribute::ComponentIt
.def("end", &smtk::attribute::ModelEntityItem::end)
.def("find", (ptrdiff_t (smtk::attribute::ModelEntityItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ModelEntityItem::find, py::arg("entity"))
.def("find", (ptrdiff_t (smtk::attribute::ModelEntityItem::*)(::smtk::model::EntityRef const &) const) &smtk::attribute::ModelEntityItem::find, py::arg("entity"))
.def("has", (bool (smtk::attribute::ModelEntityItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ModelEntityItem::has, py::arg("entity"))
.def("has", (bool (smtk::attribute::ModelEntityItem::*)(::smtk::model::EntityRef const &) const) &smtk::attribute::ModelEntityItem::has, py::arg("entity"))
.def("contains", (bool (smtk::attribute::ModelEntityItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ModelEntityItem::contains, py::arg("entity"))
.def("contains", (bool (smtk::attribute::ModelEntityItem::*)(::smtk::model::EntityRef const &) const) &smtk::attribute::ModelEntityItem::contains, py::arg("entity"))
.def("isExtensible", &smtk::attribute::ModelEntityItem::isExtensible)
.def("isSet", &smtk::attribute::ModelEntityItem::isSet, py::arg("element") = 0)
.def("numberOfRequiredValues", &smtk::attribute::ModelEntityItem::numberOfRequiredValues)
......
......@@ -26,12 +26,12 @@ PySharedPtrClass< smtk::attribute::ReferenceItem, smtk::attribute::Item > pybind
.def("appendObjectValue", &smtk::attribute::ReferenceItem::appendObjectValue, py::arg("val"))
.def("assign", &smtk::attribute::ReferenceItem::assign, py::arg("sourceItem"), py::arg("options") = 0)
.def("begin", &smtk::attribute::ReferenceItem::begin)
.def("contains", (bool (smtk::attribute::ReferenceItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ReferenceItem::contains, py::arg("compId"))
.def("contains", (bool (smtk::attribute::ReferenceItem::*)(const ::smtk::resource::PersistentObjectPtr&) const) &smtk::attribute::ReferenceItem::contains, py::arg("obj"))
.def("definition", &smtk::attribute::ReferenceItem::definition)
.def("end", &smtk::attribute::ReferenceItem::end)
.def("find", (ptrdiff_t (smtk::attribute::ReferenceItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ReferenceItem::find, py::arg("compId"))
.def("find", (ptrdiff_t (smtk::attribute::ReferenceItem::*)(const ::smtk::resource::PersistentObjectPtr&) const) &smtk::attribute::ReferenceItem::find, py::arg("component"))
.def("has", (bool (smtk::attribute::ReferenceItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ReferenceItem::has, py::arg("compId"))
.def("has", (bool (smtk::attribute::ReferenceItem::*)(const ::smtk::resource::PersistentObjectPtr&) const) &smtk::attribute::ReferenceItem::has, py::arg("obj"))
.def("isExtensible", &smtk::attribute::ReferenceItem::isExtensible)
.def("isSet", &smtk::attribute::ReferenceItem::isSet, py::arg("i") = 0)
.def("lockType", &smtk::attribute::ReferenceItem::lockType)
......
......@@ -35,8 +35,8 @@ PySharedPtrClass< smtk::attribute::ResourceItem, smtk::attribute::ReferenceItem
.def("end", &smtk::attribute::ResourceItem::end)
.def("find", (ptrdiff_t (smtk::attribute::ResourceItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ResourceItem::find, py::arg("rsrcId"))
.def("find", (ptrdiff_t (smtk::attribute::ResourceItem::*)(const ::smtk::resource::PersistentObjectPtr&) const) &smtk::attribute::ResourceItem::find, py::arg("resource"))
.def("has", (bool (smtk::attribute::ResourceItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ResourceItem::has, py::arg("rsrcId"))
.def("has", (bool (smtk::attribute::ResourceItem::*)(const ::smtk::resource::PersistentObjectPtr&) const) &smtk::attribute::ResourceItem::has, py::arg("rsrc"))
.def("contains", (bool (smtk::attribute::ResourceItem::*)(::smtk::common::UUID const &) const) &smtk::attribute::ResourceItem::contains, py::arg("rsrcId"))
.def("contains", (bool (smtk::attribute::ResourceItem::*)(const ::smtk::resource::PersistentObjectPtr&) const) &smtk::attribute::ResourceItem::contains, py::arg("rsrc"))
.def("isExtensible", &smtk::attribute::ResourceItem::isExtensible)
.def("isSet", &smtk::attribute::ResourceItem::isSet, py::arg("i") = 0)
.def("numberOfRequiredValues", &smtk::attribute::ResourceItem::numberOfRequiredValues)
......
......@@ -118,7 +118,7 @@ int main()
for (std::size_t i = 0; i < 3; i++)
{
if (!tag->has(value[i]))
if (!tag->contains(value[i]))
{
std::cerr << "Expected tag value not found: \"" << value[i] << "\"\n";
std::cerr << logger.convertToString();
......
......@@ -74,7 +74,7 @@ void testLoadedAttributeResource(attribute::ResourcePtr& attRes, const std::stri
smtkTest(result == Definition::AssociationResultType::Conflict, prefix
<< "- A1 did not return conflict");
smtkTest(probAtt == attA, prefix << "- A1 did not return attA as conflicting");
smtkTest(attC->associations()->has(attTest), prefix
smtkTest(attC->associations()->contains(attTest), prefix
<< "- C does not think it is associated with attTest")
}
......
......@@ -231,12 +231,12 @@ public:
}
/// Check if a link with the input id exists.
bool has(const id_type& key) const { return this->find(key) != this->end(); }
bool contains(const id_type& key) const { return this->find(key) != this->end(); }
/// Check if a link with the input value matching the tagged search criterion
/// exists.
template <typename tag>
bool has(const typename LinkTraits<tag>::type&) const;
bool contains(const typename LinkTraits<tag>::type&) const;
/// Return the number of links with the input value matching the tagged search
/// criterion.
......@@ -316,7 +316,7 @@ Links<id_type, left_type, right_type, role_type, base_type>::insert(base_type&&
template <typename id_type, typename left_type, typename right_type, typename role_type,
typename base_type>
template <typename tag>
bool Links<id_type, left_type, right_type, role_type, base_type>::has(
bool Links<id_type, left_type, right_type, role_type, base_type>::contains(
const typename detail::LinkTraits<id_type, left_type, right_type, role_type, base_type,
tag>::type& value) const
{
......
......@@ -69,7 +69,7 @@ public:
PropertiesOfType& operator=(PropertiesOfType&&) = delete;
/// Check whether a property associated with <key> is present.
bool has(const std::string& key) const { return (m_data.find(key) != m_data.end()); }
bool contains(const std::string& key) const { return (m_data.find(key) != m_data.end()); }
/// Insert (<key>, <value>) into the container.
bool insert(const std::string& key, const Type& value)
......@@ -147,7 +147,7 @@ public:
/// On average, this method has constant complexity and can therefore be used
/// in conjunction with at() for conditional queries.
template <typename Type>
bool has(const std::string& key) const
bool contains(const std::string& key) const
{
auto it = m_data.find(smtk::common::typeName<Type>());
if (it == m_data.end())
......@@ -155,7 +155,7 @@ public:
return false;
}
return static_cast<const PropertiesOfType<Type>&>(*it->second).has(key);
return static_cast<const PropertiesOfType<Type>&>(*it->second).contains(key);
}
/// Insert (<Type>, <key>, <value>) into the container.
......@@ -182,7 +182,7 @@ public:
/// Access property of type <Type> indexed by <key>.
/// On average, this method has constant complexity and can therefore be used
/// in conjunction with has() for conditional queries.
/// in conjunction with contains() for conditional queries.
template <typename Type>
Type& at(const std::string& key)
{
......@@ -191,7 +191,7 @@ public:
/// Access property of type <Type> indexed by <key>.
/// On average, this method has constant complexity and can therefore be used
/// in conjunction with has() for conditional queries.
/// in conjunction with contains() for conditional queries.
template <typename Type>
const Type& at(const std::string& key) const
{
......
......@@ -124,7 +124,7 @@ public:
virtual ~MaybeRegister() {}
template <typename M>
bool has(const std::shared_ptr<M>&) const
bool contains(const std::shared_ptr<M>&) const
{
return false;
}
......@@ -153,12 +153,12 @@ public:
}
template <typename M>
bool has(const std::shared_ptr<M>&) const
bool contains(const std::shared_ptr<M>&) const
{
return false;
}
bool has(const std::shared_ptr<Manager>& manager) const
bool contains(const std::shared_ptr<Manager>& manager) const
{
auto m = m_Manager.lock();
return m && m == manager;
......@@ -309,11 +309,11 @@ public:
}
template <typename M>
bool has(const std::shared_ptr<M>& m)
bool contains(const std::shared_ptr<M>& m)
{
auto tmp = dynamic_cast<
detail::MaybeRegister<Registrar, M, typename detail::RegistersTo<Registrar, M>::type>*>(this);
return tmp != nullptr && tmp->has(m);
return tmp != nullptr && tmp->contains(m);
}
virtual ~Registry() {}
......@@ -376,11 +376,11 @@ public:
virtual ~Registry() {}
template <typename M>
bool has(const std::shared_ptr<M>& m)
bool contains(const std::shared_ptr<M>& m)
{
auto tmp = dynamic_cast<
detail::MaybeRegister<Registrar, M, typename detail::RegistersTo<Registrar, M>::type>*>(this);
return tmp != nullptr && tmp->has(m);
return tmp != nullptr && tmp->contains(m);
}
Registry(int, const std::shared_ptr<Manager>& manager, const std::shared_ptr<T>&... managers)
......
......@@ -92,7 +92,7 @@ public:
template <typename T>
struct is_pod
{
using type = typename smtk::tuple_has<T, PODs>::type;
using type = typename smtk::tuple_contains<T, PODs>::type;
};
// A compile-time test to check whether or not a class has a create() method.
......
......@@ -116,9 +116,9 @@ void UnitTest()
smtkTest(links.size() == 3, "Should have 3 links.");
smtkTest(links.size<MyLinks::Role>(100) == 2, "Should have 2 links.");
smtkTest(links.has<MyLinks::Left>(4) == true, "Should have a left value of 4.");
smtkTest(links.has<MyLinks::Right>(1) == false, "Should not have a right value of 1.");
smtkTest(links.has(7) == true, "Should have an id value of 7.");
smtkTest(links.contains<MyLinks::Left>(4) == true, "Should have a left value of 4.");
smtkTest(links.contains<MyLinks::Right>(1) == false, "Should not have a right value of 1.");
smtkTest(links.contains(7) == true, "Should have an id value of 7.");
// Erase all links associated with a "right" value of 5
bool erased = links.erase_all<MyLinks::Right>(5);
......@@ -231,9 +231,9 @@ void MoveOnlyTest()
smtkTest(links.size() == 3, "Should have 3 links.");
smtkTest(links.size<MyLinks::Role>(100) == 2, "Should have 2 links.");
smtkTest(links.has<MyLinks::Left>(4) == true, "Should have a left value of 4.");
smtkTest(links.has<MyLinks::Right>(1) == false, "Should not have a right value of 1.");
smtkTest(links.has(7) == true, "Should have an id value of 7.");
smtkTest(links.contains<MyLinks::Left>(4) == true, "Should have a left value of 4.");
smtkTest(links.contains<MyLinks::Right>(1) == false, "Should not have a right value of 1.");
smtkTest(links.contains(7) == true, "Should have an id value of 7.");
// Erase all links associated with a "right" value of 5
bool erased = links.erase_all<MyLinks::Right>(5);
......
......@@ -52,7 +52,7 @@ int UnitTestProperties(int, char** const)
{
Properties properties;
test(properties.has<int>("foo") == false, "New instance should contain no values.");
test(properties.contains<int>("foo") == false, "New instance should contain no values.");
try
{
......
......@@ -245,7 +245,7 @@ void pqSMTKRegisterImportersBehavior::constructImporters(pqSMTKWrapper* wrapper,
if (groupName == smtk::operation::ImporterGroup::type_name)
{
auto importerGroup = smtk::operation::ImporterGroup(operationManager);
assert(importerGroup.has(index));
assert(importerGroup.contains(index));
auto fileItemDef = importerGroup.fileItemDefinitionForOperation(index);
registerSMTKImporter(
server, importerGroup.resourceForOperation(index), fileItemDef->getFileFilters());
......@@ -271,7 +271,7 @@ void pqSMTKRegisterImportersBehavior::constructImporters(pqSMTKWrapper* wrapper,
if (groupName == smtk::operation::ImporterGroup::type_name)
{
auto importerGroup = smtk::operation::ImporterGroup(operationManager);
assert(importerGroup.has(index));
assert(importerGroup.contains(index));
auto fileItemDef = importerGroup.fileItemDefinitionForOperation(index);
unregisterSMTKImporter(server, importerGroup.resourceForOperation(index),
fileItemDef->getFileFilters());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment