Skip to content

Commit 1ecd02b

Browse files
committed
Starting the API changes. This will spread to the entire code base...
Signed-off-by: Michael Jackson <[email protected]>
1 parent 130622f commit 1ecd02b

File tree

9 files changed

+32
-26
lines changed

9 files changed

+32
-26
lines changed

src/simplnx/Common/Result.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ using ResultBaseT = std::conditional_t<std::is_same_v<T, void>, detail::ResultVo
7272

7373
/**
7474
* @brief Result is meant for reporting errors/warnings from a function with an optional contained type.
75-
* Functions similiarly to std::optional. Warnings are always accessible, and either the contained type or errors is accessible at a time.
75+
* Functions similarly to std::optional. Warnings are always accessible, and either the contained type or errors is accessible at a time.
7676
* @tparam T Contained type. May be void.
7777
*/
7878
template <class T = void>

src/simplnx/DataStructure/AttributeMatrix.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,19 @@ std::string AttributeMatrix::getTypeName() const
7878
return k_TypeName;
7979
}
8080

81-
bool AttributeMatrix::canInsert(const DataObject* obj) const
81+
Result<bool> AttributeMatrix::canInsert(const DataObject* obj) const
8282
{
83-
if(!BaseGroup::canInsert(obj))
83+
auto result = BaseGroup::canInsert(obj);
84+
if(result.invalid())
8485
{
85-
return false;
86+
return result;
8687
}
8788

8889
const auto* arrayObjectPtr = dynamic_cast<const IArray*>(obj);
8990

9091
if(arrayObjectPtr == nullptr)
9192
{
92-
return false;
93+
return MakeErrorResult<bool>(-1673, "BaseGroup::canInsert() Error: DataObject being inserted is null");
9394
}
9495

9596
const IArray::ShapeType arrayTupleShape = arrayObjectPtr->getTupleShape();
@@ -98,9 +99,9 @@ bool AttributeMatrix::canInsert(const DataObject* obj) const
9899
const usize incomingTupleCount = std::accumulate(arrayTupleShape.cbegin(), arrayTupleShape.cend(), static_cast<usize>(1), std::multiplies<>());
99100
if(totalTuples != incomingTupleCount)
100101
{
101-
std::cout << "AttributeMatrix: CanInsert() Failed with object " << obj->getName() << ". totalTuples=" << totalTuples << " incomingTupleCount=" << incomingTupleCount << "\n";
102+
return MakeErrorResult<bool>(-1674, fmt::format("AttributeMatrix: CanInsert() Failed with object {}. totalTuples={} incomingTupleCount={}", obj->getName(), totalTuples, incomingTupleCount));
102103
}
103-
return (totalTuples == incomingTupleCount);
104+
return {true};
104105
}
105106

106107
const AttributeMatrix::ShapeType& AttributeMatrix::getShape() const

src/simplnx/DataStructure/AttributeMatrix.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class SIMPLNX_EXPORT AttributeMatrix : public BaseGroup
171171
* @param obj
172172
* @return bool
173173
*/
174-
bool canInsert(const DataObject* obj) const override;
174+
Result<bool> canInsert(const DataObject* obj) const override;
175175

176176
private:
177177
ShapeType m_TupleShape;

src/simplnx/DataStructure/BaseGroup.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "BaseGroup.hpp"
2+
#include <simplnx/Common/Result.hpp>
23

34
#include "simplnx/DataStructure/DataPath.hpp"
45
#include "simplnx/Utilities/StringUtilities.hpp"
@@ -99,21 +100,22 @@ const DataObject& BaseGroup::at(const std::string& name) const
99100
return m_DataMap.at(name);
100101
}
101102

102-
bool BaseGroup::canInsert(const DataObject* obj) const
103+
Result<bool> BaseGroup::canInsert(const DataObject* obj) const
103104
{
104105
if(obj == nullptr)
105106
{
106-
return false;
107+
return MakeErrorResult<bool>(-1663, "BaseGroup::canInsert() Error: DataObject being inserted is null");
107108
}
108109
if(contains(obj) || contains(obj->getName()))
109110
{
110-
return false;
111+
return MakeErrorResult<bool>(-1664, fmt::format("BaseGroup::canInsert() Error: DataObject with name='{}' and type='{}' already exists in the DataMap", obj->getName(), obj->getTypeName()));
111112
}
112113
if(const auto* objGroup = dynamic_cast<const BaseGroup*>(obj); objGroup != nullptr && objGroup->isParentOf(this))
113114
{
114-
return false;
115+
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.",
116+
obj->getName(), obj->getTypeName()));
115117
}
116-
return true;
118+
return {true};
117119
}
118120

119121
void BaseGroup::setDataStructure(DataStructure* dataStructure)
@@ -138,19 +140,21 @@ bool BaseGroup::isParentOf(const DataObject* dataObj) const
138140
return std::find_if(origDataPaths.begin(), origDataPaths.end(), [dataObj](const DataPath& path) { return dataObj->hasParent(path); }) != origDataPaths.end();
139141
}
140142

141-
bool BaseGroup::insert(const std::weak_ptr<DataObject>& obj)
143+
Result<bool> BaseGroup::insert(const std::weak_ptr<DataObject>& obj)
142144
{
143145
auto ptr = obj.lock();
144-
if(!canInsert(ptr.get()))
146+
auto result = canInsert(ptr.get());
147+
if(result.invalid())
145148
{
146-
return false;
149+
return result;
147150
}
148151
if(m_DataMap.insert(ptr))
149152
{
150153
ptr->addParent(this);
151-
return true;
154+
return {true};
152155
}
153-
return false;
156+
return MakeErrorResult<bool>(
157+
-1666, fmt::format("BaseGroup::insert() Error: DataObject with name='{}' and type='{}' could not be inserted into the DataMap.", obj.lock()->getName(), obj.lock()->getTypeName()));
154158
}
155159

156160
bool BaseGroup::remove(DataObject* obj)
@@ -255,4 +259,4 @@ void BaseGroup::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, IdType>>
255259
std::vector<DataObject::IdType> BaseGroup::GetChildrenIds()
256260
{
257261
return m_DataMap.getKeys();
258-
}
262+
}

src/simplnx/DataStructure/BaseGroup.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "simplnx/Common/Result.hpp"
34
#include "simplnx/DataStructure/DataMap.hpp"
45
#include "simplnx/DataStructure/DataObject.hpp"
56
#include "simplnx/simplnx_export.hpp"
@@ -251,7 +252,7 @@ class SIMPLNX_EXPORT BaseGroup : public DataObject
251252
* @param obj
252253
* @return bool
253254
*/
254-
bool insert(const std::weak_ptr<DataObject>& obj);
255+
Result<bool> insert(const std::weak_ptr<DataObject>& obj);
255256

256257
/**
257258
* Attempts to remove the specified DataObject from the container. Returns
@@ -373,7 +374,7 @@ class SIMPLNX_EXPORT BaseGroup : public DataObject
373374
* @param obj
374375
* @return bool
375376
*/
376-
virtual bool canInsert(const DataObject* obj) const;
377+
virtual Result<bool> canInsert(const DataObject* obj) const;
377378

378379
/**
379380
* @brief Sets a new DataStructure for the BaseGroup. Updates the DataMap

src/simplnx/DataStructure/DataGroup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ std::string DataGroup::getTypeName() const
7979
return k_TypeName;
8080
}
8181

82-
bool DataGroup::canInsert(const DataObject* obj) const
82+
Result<bool> DataGroup::canInsert(const DataObject* obj) const
8383
{
8484
return BaseGroup::canInsert(obj);
8585
}

src/simplnx/DataStructure/DataGroup.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,6 @@ class SIMPLNX_EXPORT DataGroup : public BaseGroup
126126
* @param obj
127127
* @return bool
128128
*/
129-
bool canInsert(const DataObject* obj) const override;
129+
Result<bool> canInsert(const DataObject* obj) const override;
130130
};
131131
} // namespace nx::core

src/simplnx/DataStructure/Montage/AbstractMontage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ const AbstractMontage::CollectionType& AbstractMontage::getCollection() const
102102
return m_Collection;
103103
}
104104

105-
bool AbstractMontage::canInsert(const DataObject* obj) const
105+
Result<bool> AbstractMontage::canInsert(const DataObject* obj) const
106106
{
107107
if(!dynamic_cast<const IGeometry*>(obj))
108108
{
109-
return false;
109+
return MakeErrorResult<bool>(-1676, fmt::format("AbstractMontage::canInsert() Error: DataObject with name='{}' and type='{}' is not subclass of IGeometry", obj->getName(), obj->getTypeName()));
110110
}
111111
return BaseGroup::canInsert(obj);
112112
}

src/simplnx/DataStructure/Montage/AbstractMontage.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class SIMPLNX_EXPORT AbstractMontage : public BaseGroup
162162
* @param obj
163163
* @return bool
164164
*/
165-
bool canInsert(const DataObject* obj) const override;
165+
Result<bool> canInsert(const DataObject* obj) const override;
166166

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

0 commit comments

Comments
 (0)