11 Commits

2 changed files with 27 additions and 7 deletions

View File

@@ -2,7 +2,15 @@
In uLib the context is meant to hold a set of objects and their hierarchy. In addition ObjectFactory is used to create objects from a predefined registry.
Object context can be thouught as a collection of uLib::Object instances. And there exists nested collection of objects if a context is added to another context. A nested context is a Group of elements that appears like a single object in the parent context and a hierarchy of objects inside the tree structure.
Object context can be thought as a collection of uLib::Object instances. And there exists nested collection of objects if a context is added to another context. A nested context is a Group of elements that appears like a single object in the parent context and a hierarchy of objects inside the tree structure.
## SmartPointer access
SmartPointer is a class that is used to hold a reference to another object. It is a template class that can be used to hold a reference to any object that is derived from uLib::Object. It is a smart pointer because it will automatically delete the object when it is no longer needed. It is also a smart pointer because it will automatically update the object when it is no longer needed.
The ObjectContext is responsible to keep track of all the objects that are added to it and to provide a way to access them, but also it holds the SmartPointer instances that point to the objects that are added to it. In this way Objects added to a Context are disposed only when the context is destroyed.
For this reason the access to a object context for a Object via Get/Set is done using the SmartPointer instances.
## SmartPointer access

View File

@@ -60,8 +60,7 @@ private:
/**
* @brief A smart pointer implementation inspired by std::shared_ptr.
*/
template <typename T>
class SmartPointer {
template <typename T> class SmartPointer {
public:
using element_type = T;
@@ -234,13 +233,26 @@ private:
}
};
template <typename T, typename U> SmartPointer<T> static_pointer_cast(const SmartPointer<U>& r) noexcept { return SmartPointer<T>(r, static_cast<T*>(r.get())); }
template <typename T, typename U> SmartPointer<T> dynamic_pointer_cast(const SmartPointer<U>& r) noexcept {
template <typename T, typename U>
SmartPointer<T> static_pointer_cast(const SmartPointer<U>& r) noexcept {
return SmartPointer<T>(r, static_cast<T*>(r.get()));
}
template <typename T, typename U>
SmartPointer<T> dynamic_pointer_cast(const SmartPointer<U>& r) noexcept {
if (auto p = dynamic_cast<T*>(r.get())) return SmartPointer<T>(r, p);
return SmartPointer<T>(nullptr);
}
template <typename T, typename U> SmartPointer<T> const_pointer_cast(const SmartPointer<U>& r) noexcept { return SmartPointer<T>(r, const_cast<T*>(r.get())); }
template <typename T, typename U> SmartPointer<T> reinterpret_pointer_cast(const SmartPointer<U>& r) noexcept { return SmartPointer<T>(r, reinterpret_cast<T*>(r.get())); }
template <typename T, typename U>
SmartPointer<T> const_pointer_cast(const SmartPointer<U>& r) noexcept {
return SmartPointer<T>(r, const_cast<T*>(r.get()));
}
template <typename T, typename U>
SmartPointer<T> reinterpret_pointer_cast(const SmartPointer<U>& r) noexcept {
return SmartPointer<T>(r, reinterpret_cast<T*>(r.get()));
}
} // namespace uLib