The Sparta Modeling Framework
|
PhasedObject which can hold 0 or 1 Resource pointers to an associatedresource. Contains logic for setting and getting the associated Resource. More...
#include <ResourceContainer.hpp>
Public Member Functions | |
ResourceContainer () | |
Consturct with a null, unlocked resource. | |
ResourceContainer (const ResourceContainer &)=delete | |
Copy construction disbled. | |
ResourceContainer (ResourceContainer &&)=default | |
Move constructor. | |
virtual | ~ResourceContainer () |
Destructor. | |
Resource * | getResource () |
Gets the resource contained by this node if any. May only be called after finalization begins or during teardown. | |
const Resource * | getResource () const |
Const variant of getResource. | |
bool | hasResource () const |
Determines if this node has a resource. This method exists in case the TreeNode is being explored by a tool or interactive UI. Typical TreeNode clients (such as Resources) will assume that there is a resource if they are expecting one. | |
template<class T , typename = typename std::enable_if<std::is_pointer<T>::value>::type> | |
const T | getResourceAs () const |
Gets the resource contained by this node (if any) as the given type. | |
template<class T , typename = typename std::enable_if<!std::is_pointer<T>::value>::type> | |
const T * | getResourceAs () const |
Overload of getResourceAs for const access with a non-pointer template type. | |
template<class T , typename = typename std::enable_if<std::is_pointer<T>::value>::type> | |
T | getResourceAs () |
Non-const overload of getResourceAs. | |
template<class T , typename = typename std::enable_if<!std::is_pointer<T>::value>::type> | |
T * | getResourceAs () |
Non-const overload of getResourceAs. | |
virtual std::string | getResourceType () const |
Gets the typename of the resource that this node will eventually contain. | |
virtual std::string | getResourceTypeRaw () const |
Gets the typename of the resource that this node will eventually contain. | |
virtual const Clock * | getClock ()=0 |
Gets the clock associated with this ResourceContainer, if any. | |
Public Member Functions inherited from sparta::PhasedObject | |
PhasedObject (PhasedObject &&)=default | |
virtual const std::string & | getName () const =0 |
Gets the name of this node. | |
virtual std::string | getLocation () const =0 |
Returns the location of this node in device tree which can be used to navigate the device tree in methods such as getChild if this is fully attached to the device tree. | |
TreePhase | getPhase () const |
Gets the trees current phase. | |
virtual bool | isBuilding () const |
Is this node (and thus the entire tree above and below it) currently in the TREE_BUILDING phase. | |
virtual bool | isBuilt () const |
Is this node (and thus the entire tree above it) "built". Checks that getPhase has passed TREE_BUILDING. | |
virtual bool | isConfigured () const |
Is this node (and thus the entire tree above it) "configured". Checks that getPhase has passed TREE_CONFIGURING (i.e. FINALIZED, FINALIZING, TEARDOWN, etc). | |
virtual bool | isConfiguring () const |
Is this node (and thus the entire tree above it) currently in the TREE_CONFIGURING phase. | |
virtual bool | isFinalizing () const |
Is this node (and thus the entire tree above it) "finalized". | |
virtual bool | isFinalized () const |
Is this node (and thus the entire tree above it) "finalized". | |
virtual bool | isTearingDown () const |
Is this node (and thus the entire tree above it) in the "teardown" phase. | |
Protected Member Functions | |
std::string | getResourceTypeName_ () const |
Gets the rtti type name (demangled) of the resource type held by this container. If there is no resource held, returns empty string. | |
void | setResource_ (Resource *r) |
Allows subclasses to assign the resource associated with this node. | |
void | unsetResource_ () |
Allows a resource to unset the resource set with setResource_. | |
void | lockResource_ () |
Allows subclasses to assign the resource associated with this node. | |
Resource * | getResource_ () noexcept |
Returns the currently held resource of this node (if any). This method can be called at any time. | |
const Resource * | getResource_ () const noexcept |
Const variant of getResource_. | |
Protected Member Functions inherited from sparta::PhasedObject | |
void | setPhase_ (TreePhase phase) |
Sets the current phase. | |
Friends | |
class | Resource |
Allow resource to invoke setResource_ and unsetResource_. | |
Additional Inherited Members | |
Public Types inherited from sparta::PhasedObject | |
enum | TreePhase { TREE_BUILDING = 0 , TREE_CONFIGURING = 1 , TREE_FINALIZING = 2 , TREE_FINALIZED = 3 , TREE_TEARDOWN = 4 } |
Current phase of tree construction (applies to node and entire tree). More... | |
PhasedObject which can hold 0 or 1 Resource pointers to an associatedresource. Contains logic for setting and getting the associated Resource.
The main motivation for decoupling this from TreeNode is to break a dependency loop with Resource, which attaches and detaches itself with a ResourceContainer at construction and destruction respectively.
Has the concept of a locked resource, which means it cannot be unset until the TEARDOWN phase. This prohibits the premature destruction of Resources.
Definition at line 33 of file ResourceContainer.hpp.
|
inline |
Consturct with a null, unlocked resource.
Definition at line 45 of file ResourceContainer.hpp.
|
inlinevirtual |
|
pure virtual |
Gets the clock associated with this ResourceContainer, if any.
Implemented in sparta::TreeNode.
|
inline |
Gets the resource contained by this node if any. May only be called after finalization begins or during teardown.
SpartaException | if called before finalizing or finalized or tearing down. Throws if node does not have a resource. |
The goal of phase-limited access of a ResourceContainer's resource is to prevent public clients of ResourceContainer from attempting to access a resource before finalization because most resources are not created until finalization. Attempting to get the resource before this point is almost always a misuse.
This method throws if the node has no resource because its intended use is by clients who expect certain nodes to have certain resources available. This usage should not require extra null-checks by the developer. So, to keep such code concise, getResource will throw if the node has no resource. Do not call this unless the node is expected to have a resource.
The hasResource method is available to determine if the node has a resource before querying it
Definition at line 96 of file ResourceContainer.hpp.
|
inline |
Const variant of getResource.
Definition at line 122 of file ResourceContainer.hpp.
|
inlineprotectednoexcept |
Const variant of getResource_.
Definition at line 343 of file ResourceContainer.hpp.
|
inlineprotectednoexcept |
Returns the currently held resource of this node (if any). This method can be called at any time.
Note that this is different from the public getResource in that it can be called at any time without the possibility of throwing an exception.
Definition at line 335 of file ResourceContainer.hpp.
|
inline |
Non-const overload of getResourceAs.
Definition at line 204 of file ResourceContainer.hpp.
|
inline |
Non-const overload of getResourceAs.
Definition at line 229 of file ResourceContainer.hpp.
|
inline |
Gets the resource contained by this node (if any) as the given type.
T | Type of resource to cast to. Should be sparta::Resource or a subclass |
SpartaException | if called before finalizing or finalized or tearing down |
Definition at line 169 of file ResourceContainer.hpp.
|
inline |
Overload of getResourceAs for const access with a non-pointer template type.
Definition at line 194 of file ResourceContainer.hpp.
|
virtual |
Gets the typename of the resource that this node will eventually contain.
Returns a demangled typeid of the internal resource type
Reimplemented in sparta::ResourceTreeNode.
|
virtual |
Gets the typename of the resource that this node will eventually contain.
Returns a raw typeid of the internal resource type
Reimplemented in sparta::ResourceTreeNode.
|
inline |
Determines if this node has a resource. This method exists in case the TreeNode is being explored by a tool or interactive UI. Typical TreeNode clients (such as Resources) will assume that there is a resource if they are expecting one.
SpartaException | if called before finalizing or finalized or tearing down. |
Definition at line 147 of file ResourceContainer.hpp.
|
inlineprotected |
Allows subclasses to assign the resource associated with this node.
Definition at line 323 of file ResourceContainer.hpp.
|
inlineprotected |
Allows subclasses to assign the resource associated with this node.
r | Resource pointer to store internally. Must not be nullptr. Caller owns this resource. This class method just stores a reference to be accessed through getResource_ |
Definition at line 276 of file ResourceContainer.hpp.
|
inlineprotected |
Allows a resource to unset the resource set with setResource_.
r | Resource pointer to store internally. Must not be nullptr. |
Definition at line 305 of file ResourceContainer.hpp.
|
friend |
Allow resource to invoke setResource_ and unsetResource_.
Definition at line 40 of file ResourceContainer.hpp.