diff --git a/src/simplnx/DataStructure/DataStructure.hpp b/src/simplnx/DataStructure/DataStructure.hpp index 76391fee19..10197d7d29 100644 --- a/src/simplnx/DataStructure/DataStructure.hpp +++ b/src/simplnx/DataStructure/DataStructure.hpp @@ -144,6 +144,21 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + T* getDataAsUnsafe(DataObject::IdType identifier) + { + static_assert(std::is_base_of_v); + return static_cast(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. @@ -166,6 +181,22 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + T* getDataAsUnsafe(const std::optional& identifier) + { + static_assert(std::is_base_of_v); + auto* object = getData(identifier); + return static_cast(object); + } + /** * @brief Returns a pointer to the DataObject at the given DataPath. If no * DataObject is found, this method returns nullptr. @@ -203,6 +234,21 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + T* getDataAsUnsafe(const DataPath& path) + { + static_assert(std::is_base_of_v); + return static_cast(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. @@ -216,6 +262,21 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + T& getDataRefAsUnsafe(const DataPath& path) + { + static_assert(std::is_base_of_v); + return static_cast(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. @@ -229,6 +290,21 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + T& getDataRefAsUnsafe(DataObject::IdType identifier) + { + static_assert(std::is_base_of_v); + return static_cast(getDataRef(identifier)); + } + /** * @brief Returns a pointer to the DataObject found at the specified * LinkedPath. If no such DataObject is found, this method returns nullptr. @@ -250,6 +326,21 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + T* getDataAsUnsafe(const LinkedPath& path) + { + static_assert(std::is_base_of_v); + return static_cast(getData(path)); + } + /** * @brief Returns a pointer to the DataObject with the specified IdType. * If no such object exists, this method returns nullptr. @@ -271,6 +362,21 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + const T* getDataAsUnsafe(DataObject::IdType identifier) const + { + static_assert(std::is_base_of_v); + return static_cast(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. @@ -292,6 +398,21 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + const T* getDataAsUnsafe(const std::optional& identifier) const + { + static_assert(std::is_base_of_v); + return static_cast(getData(identifier)); + } + /** * @brief Returns a pointer to the DataObject at the given DataPath. If no * DataObject is found, this method returns nullptr. @@ -332,6 +453,20 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + const T* getDataAsUnsafe(const DataPath& path) const + { + static_assert(std::is_base_of_v); + return static_cast(getData(path)); + } + /** * @brief Returns a reference to the DataObject at the given DataPath. * @@ -348,6 +483,21 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + const T& getDataRefAsUnsafe(const DataPath& path) const + { + static_assert(std::is_base_of_v); + return static_cast(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. @@ -361,6 +511,21 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + const T& getDataRefAsUnsafe(DataObject::IdType identifier) const + { + static_assert(std::is_base_of_v); + return static_cast(getDataRef(identifier)); + } + /** * @brief Returns a pointer to the DataObject found at the specified * LinkedPath. If no such DataObject is found, this method returns nullptr. @@ -382,6 +547,21 @@ class SIMPLNX_EXPORT DataStructure return dynamic_cast(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 + const T* getDataAsUnsafe(const LinkedPath& path) const + { + static_assert(std::is_base_of_v); + return static_cast(getData(path)); + } + /** * @brief Returns the shared pointer for the specified DataObject. * Returns nullptr if no DataObject is found.