Skip to content

Commit

Permalink
Do not use Result<bool>
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Jul 30, 2024
1 parent 1ecd02b commit da2e463
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/simplnx/DataStructure/AttributeMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ std::string AttributeMatrix::getTypeName() const
return k_TypeName;
}

Result<bool> AttributeMatrix::canInsert(const DataObject* obj) const
Result<> AttributeMatrix::canInsert(const DataObject* obj) const
{
auto result = BaseGroup::canInsert(obj);
if(result.invalid())
Expand All @@ -90,7 +90,7 @@ Result<bool> AttributeMatrix::canInsert(const DataObject* obj) const

if(arrayObjectPtr == nullptr)
{
return MakeErrorResult<bool>(-1673, "BaseGroup::canInsert() Error: DataObject being inserted is null");
return MakeErrorResult<>(-1673, "BaseGroup::canInsert() Error: DataObject being inserted is null");
}

const IArray::ShapeType arrayTupleShape = arrayObjectPtr->getTupleShape();
Expand All @@ -99,9 +99,9 @@ Result<bool> AttributeMatrix::canInsert(const DataObject* obj) const
const usize incomingTupleCount = std::accumulate(arrayTupleShape.cbegin(), arrayTupleShape.cend(), static_cast<usize>(1), std::multiplies<>());
if(totalTuples != incomingTupleCount)
{
return MakeErrorResult<bool>(-1674, fmt::format("AttributeMatrix: CanInsert() Failed with object {}. totalTuples={} incomingTupleCount={}", obj->getName(), totalTuples, incomingTupleCount));
return MakeErrorResult<>(-1674, fmt::format("AttributeMatrix: CanInsert() Failed with object {}. totalTuples={} incomingTupleCount={}", obj->getName(), totalTuples, incomingTupleCount));
}
return {true};
return {};
}

const AttributeMatrix::ShapeType& AttributeMatrix::getShape() const
Expand Down
2 changes: 1 addition & 1 deletion src/simplnx/DataStructure/AttributeMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class SIMPLNX_EXPORT AttributeMatrix : public BaseGroup
* @param obj
* @return bool
*/
Result<bool> canInsert(const DataObject* obj) const override;
Result<> canInsert(const DataObject* obj) const override;

private:
ShapeType m_TupleShape;
Expand Down
20 changes: 10 additions & 10 deletions src/simplnx/DataStructure/BaseGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,22 @@ const DataObject& BaseGroup::at(const std::string& name) const
return m_DataMap.at(name);
}

Result<bool> BaseGroup::canInsert(const DataObject* obj) const
Result<> BaseGroup::canInsert(const DataObject* obj) const
{
if(obj == nullptr)
{
return MakeErrorResult<bool>(-1663, "BaseGroup::canInsert() Error: DataObject being inserted is null");
return MakeErrorResult<>(-1663, "BaseGroup::canInsert() Error: DataObject being inserted is null");
}
if(contains(obj) || contains(obj->getName()))
{
return MakeErrorResult<bool>(-1664, fmt::format("BaseGroup::canInsert() Error: DataObject with name='{}' and type='{}' already exists in the DataMap", obj->getName(), obj->getTypeName()));
return MakeErrorResult<>(-1664, fmt::format("BaseGroup::canInsert() Error: DataObject with name='{}' and type='{}' already exists in the DataMap", obj->getName(), obj->getTypeName()));
}
if(const auto* objGroup = dynamic_cast<const BaseGroup*>(obj); objGroup != nullptr && objGroup->isParentOf(this))
{
return MakeErrorResult<bool>(-1665, fmt::format("BaseGroup::canInsert() Error: DataObject with name='{}' and type='{}' is a parent of the current DataObject. A circular reference would occur.",
obj->getName(), obj->getTypeName()));
return MakeErrorResult<>(-1665, fmt::format("BaseGroup::canInsert() Error: DataObject with name='{}' and type='{}' is a parent of the current DataObject. A circular reference would occur.",
obj->getName(), obj->getTypeName()));
}
return {true};
return {};
}

void BaseGroup::setDataStructure(DataStructure* dataStructure)
Expand All @@ -140,7 +140,7 @@ bool BaseGroup::isParentOf(const DataObject* dataObj) const
return std::find_if(origDataPaths.begin(), origDataPaths.end(), [dataObj](const DataPath& path) { return dataObj->hasParent(path); }) != origDataPaths.end();
}

Result<bool> BaseGroup::insert(const std::weak_ptr<DataObject>& obj)
Result<> BaseGroup::insert(const std::weak_ptr<DataObject>& obj)
{
auto ptr = obj.lock();
auto result = canInsert(ptr.get());
Expand All @@ -151,10 +151,10 @@ Result<bool> BaseGroup::insert(const std::weak_ptr<DataObject>& obj)
if(m_DataMap.insert(ptr))
{
ptr->addParent(this);
return {true};
return {};
}
return MakeErrorResult<bool>(
-1666, fmt::format("BaseGroup::insert() Error: DataObject with name='{}' and type='{}' could not be inserted into the DataMap.", obj.lock()->getName(), obj.lock()->getTypeName()));
return MakeErrorResult<>(-1666,
fmt::format("BaseGroup::insert() Error: DataObject with name='{}' and type='{}' could not be inserted into the DataMap.", obj.lock()->getName(), obj.lock()->getTypeName()));
}

bool BaseGroup::remove(DataObject* obj)
Expand Down
4 changes: 2 additions & 2 deletions src/simplnx/DataStructure/BaseGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class SIMPLNX_EXPORT BaseGroup : public DataObject
* @param obj
* @return bool
*/
Result<bool> insert(const std::weak_ptr<DataObject>& obj);
Result<> insert(const std::weak_ptr<DataObject>& obj);

/**
* Attempts to remove the specified DataObject from the container. Returns
Expand Down Expand Up @@ -374,7 +374,7 @@ class SIMPLNX_EXPORT BaseGroup : public DataObject
* @param obj
* @return bool
*/
virtual Result<bool> canInsert(const DataObject* obj) const;
virtual Result<> canInsert(const DataObject* obj) const;

/**
* @brief Sets a new DataStructure for the BaseGroup. Updates the DataMap
Expand Down
2 changes: 1 addition & 1 deletion src/simplnx/DataStructure/DataGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ std::string DataGroup::getTypeName() const
return k_TypeName;
}

Result<bool> DataGroup::canInsert(const DataObject* obj) const
Result<> DataGroup::canInsert(const DataObject* obj) const
{
return BaseGroup::canInsert(obj);
}
2 changes: 1 addition & 1 deletion src/simplnx/DataStructure/DataGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ class SIMPLNX_EXPORT DataGroup : public BaseGroup
* @param obj
* @return bool
*/
Result<bool> canInsert(const DataObject* obj) const override;
Result<> canInsert(const DataObject* obj) const override;
};
} // namespace nx::core
6 changes: 3 additions & 3 deletions src/simplnx/DataStructure/DataStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ bool DataStructure::finishAddingObject(const std::shared_ptr<DataObject>& dataOb
{
return false;
}
if(!parentContainer->insert(dataObject))
if(parentContainer->insert(dataObject).invalid())
{
return false;
}
Expand Down Expand Up @@ -658,7 +658,7 @@ bool DataStructure::insertIntoParent(const std::shared_ptr<DataObject>& dataObje
return false;
}

if(!parentGroup->insert(dataObject))
if(parentGroup->insert(dataObject).invalid())
{
return false;
}
Expand Down Expand Up @@ -692,7 +692,7 @@ bool DataStructure::setAdditionalParent(DataObject::IdType targetId, DataObject:
return false;
}

if(!newParent->insert(target))
if(newParent->insert(target).invalid())
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/simplnx/DataStructure/Montage/AbstractMontage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ const AbstractMontage::CollectionType& AbstractMontage::getCollection() const
return m_Collection;
}

Result<bool> AbstractMontage::canInsert(const DataObject* obj) const
Result<> AbstractMontage::canInsert(const DataObject* obj) const
{
if(!dynamic_cast<const IGeometry*>(obj))
{
return MakeErrorResult<bool>(-1676, fmt::format("AbstractMontage::canInsert() Error: DataObject with name='{}' and type='{}' is not subclass of IGeometry", obj->getName(), obj->getTypeName()));
return MakeErrorResult<>(-1676, fmt::format("AbstractMontage::canInsert() Error: DataObject with name='{}' and type='{}' is not subclass of IGeometry", obj->getName(), obj->getTypeName()));
}
return BaseGroup::canInsert(obj);
}
2 changes: 1 addition & 1 deletion src/simplnx/DataStructure/Montage/AbstractMontage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class SIMPLNX_EXPORT AbstractMontage : public BaseGroup
* @param obj
* @return bool
*/
Result<bool> canInsert(const DataObject* obj) const override;
Result<> canInsert(const DataObject* obj) const override;

/**
* @brief Returns a reference of the collection for use in derived classes.
Expand Down

0 comments on commit da2e463

Please sign in to comment.