Skip to content

Commit

Permalink
Added getDataAsUnsafe and getDataRefAsUnsafe
Browse files Browse the repository at this point in the history
Signed-off-by: Jared Duffey <[email protected]>
  • Loading branch information
JDuffeyBQ committed Jun 20, 2024
1 parent a0903ac commit 6b055c5
Showing 1 changed file with 180 additions and 0 deletions.
180 changes: 180 additions & 0 deletions src/simplnx/DataStructure/DataStructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<T*>(getData(identifier));
}

/**
* @brief Returns a pointer to the DataObject with the specified IdType.
* If no such object exists, this method returns nullptr.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @param identifier
* @return T*
*/
template <class T>
T* getDataAsUnsafe(DataObject::IdType identifier)
{
static_assert(std::is_base_of_v<DataObject, T>);
return static_cast<T*>(getData(identifier));
}

/**
* @brief Returns a pointer to the DataObject with the specified IdType.
* If no such object exists, or no ID is provided, this method returns nullptr.
Expand All @@ -166,6 +181,22 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<T*>(object);
}

/**
* @brief Returns a pointer to the DataObject with the specified IdType.
* If no such object exists, or no ID is provided, this method returns nullptr.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @param identifier
* @return T*
*/
template <class T>
T* getDataAsUnsafe(const std::optional<DataObject::IdType>& identifier)
{
static_assert(std::is_base_of_v<DataObject, T>);
auto* object = getData(identifier);
return static_cast<T*>(object);
}

/**
* @brief Returns a pointer to the DataObject at the given DataPath. If no
* DataObject is found, this method returns nullptr.
Expand Down Expand Up @@ -203,6 +234,21 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<T*>(getData(path));
}

/**
* @brief Returns a pointer to the DataObject at the given DataPath. If no
* DataObject is found, this method returns nullptr.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @param path
* @return T*
*/
template <class T>
T* getDataAsUnsafe(const DataPath& path)
{
static_assert(std::is_base_of_v<DataObject, T>);
return static_cast<T*>(getData(path));
}

/**
* @brief Returns a reference to the DataObject at the given DataPath. If no
* DataObject is found, this method throws std::out_of_range.
Expand All @@ -216,6 +262,21 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<T&>(getDataRef(path));
}

/**
* @brief Returns a reference to the DataObject at the given DataPath. If no
* DataObject is found, this method throws std::out_of_range.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @param path
* @return T&
*/
template <class T>
T& getDataRefAsUnsafe(const DataPath& path)
{
static_assert(std::is_base_of_v<DataObject, T>);
return static_cast<T&>(getDataRef(path));
}

/**
* @brief Returns a reference to the DataObject with the given identifier. If no
* DataObject is found, this method throws std::out_of_range.
Expand All @@ -229,6 +290,21 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<T&>(getDataRef(identifier));
}

/**
* @brief Returns a reference to the DataObject with the given identifier. If no
* DataObject is found, this method throws std::out_of_range.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @param identifier
* @return T&
*/
template <class T>
T& getDataRefAsUnsafe(DataObject::IdType identifier)
{
static_assert(std::is_base_of_v<DataObject, T>);
return static_cast<T&>(getDataRef(identifier));
}

/**
* @brief Returns a pointer to the DataObject found at the specified
* LinkedPath. If no such DataObject is found, this method returns nullptr.
Expand All @@ -250,6 +326,21 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<T*>(getData(path));
}

/**
* @brief Returns a pointer to the DataObject found at the specified
* LinkedPath. If no such DataObject is found, this method returns nullptr.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @param path
* @return T*
*/
template <class T>
T* getDataAsUnsafe(const LinkedPath& path)
{
static_assert(std::is_base_of_v<DataObject, T>);
return static_cast<T*>(getData(path));
}

/**
* @brief Returns a pointer to the DataObject with the specified IdType.
* If no such object exists, this method returns nullptr.
Expand All @@ -271,6 +362,21 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<const T*>(getData(identifier));
}

/**
* @brief Returns a pointer to the DataObject with the specified IdType.
* If no such object exists, this method returns nullptr.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @param identifier
* @return const T*
*/
template <class T>
const T* getDataAsUnsafe(DataObject::IdType identifier) const
{
static_assert(std::is_base_of_v<DataObject, T>);
return static_cast<const T*>(getData(identifier));
}

/**
* @brief Returns a pointer to the DataObject with the specified IdType.
* If no such object exists, or no ID is provided, this method returns nullptr.
Expand All @@ -292,6 +398,21 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<const T*>(getData(identifier));
}

/**
* @brief Returns a pointer to the DataObject with the specified IdType.
* If no such object exists, or no ID is provided, this method returns nullptr.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @param identifier
* @return const T*
*/
template <class T>
const T* getDataAsUnsafe(const std::optional<DataObject::IdType>& identifier) const
{
static_assert(std::is_base_of_v<DataObject, T>);
return static_cast<const T*>(getData(identifier));
}

/**
* @brief Returns a pointer to the DataObject at the given DataPath. If no
* DataObject is found, this method returns nullptr.
Expand Down Expand Up @@ -332,6 +453,20 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<const T*>(getData(path));
}

/**
* @brief Returns a pointer to the DataObject at the given DataPath.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @param path
* @return const T*
*/
template <class T>
const T* getDataAsUnsafe(const DataPath& path) const
{
static_assert(std::is_base_of_v<DataObject, T>);
return static_cast<const T*>(getData(path));
}

/**
* @brief Returns a reference to the DataObject at the given DataPath.
*
Expand All @@ -348,6 +483,21 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<const T&>(getDataRef(path));
}

/**
* @brief Returns a reference to the DataObject at the given DataPath.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @throws std::out_of_range if path does not exist
* @param path
* @return const T&
*/
template <class T>
const T& getDataRefAsUnsafe(const DataPath& path) const
{
static_assert(std::is_base_of_v<DataObject, T>);
return static_cast<const T&>(getDataRef(path));
}

/**
* @brief Returns a reference to the DataObject with the given identifier. If no
* DataObject is found, this method throws std::out_of_range.
Expand All @@ -361,6 +511,21 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<const T&>(getDataRef(identifier));
}

/**
* @brief Returns a reference to the DataObject with the given identifier. If no
* DataObject is found, this method throws std::out_of_range.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @param identifier
* @return T&
*/
template <class T>
const T& getDataRefAsUnsafe(DataObject::IdType identifier) const
{
static_assert(std::is_base_of_v<DataObject, T>);
return static_cast<const T&>(getDataRef(identifier));
}

/**
* @brief Returns a pointer to the DataObject found at the specified
* LinkedPath. If no such DataObject is found, this method returns nullptr.
Expand All @@ -382,6 +547,21 @@ class SIMPLNX_EXPORT DataStructure
return dynamic_cast<const T*>(getData(path));
}

/**
* @brief Returns a pointer to the DataObject found at the specified
* LinkedPath. If no such DataObject is found, this method returns nullptr.
* PERFORMS NO CHECKS ON THE TYPE OF DATAOBJECT RETURNED
* ONLY USE WHEN THE TYPE IS ALREADY GUARENTEED TO BE T
* @param path
* @return const T*
*/
template <class T>
const T* getDataAsUnsafe(const LinkedPath& path) const
{
static_assert(std::is_base_of_v<DataObject, T>);
return static_cast<const T*>(getData(path));
}

/**
* @brief Returns the shared pointer for the specified DataObject.
* Returns nullptr if no DataObject is found.
Expand Down

0 comments on commit 6b055c5

Please sign in to comment.