17 class PostRunValidationInfo;
47 resource_locked_(false),
101 <<
getLocation() <<
" because it is not finalizing, finalized, or tearing down";
103 if(
nullptr == resource_){
105 ex <<
getLocation() <<
" which does not have a resource.";
107 ex <<
" TreeNode is finalized, so it cannot possibly have a resource";
109 ex <<
" TreeNode is finalizing, and might not have created its' resource yet."
110 <<
" If this TreeNode is expected to have a resource, it just hasn't been finalized yet."
111 <<
" If this is a DynamicResourceTreeNode, explicitly invoke finalize() on it to"
112 <<
" immediately create the resource";
127 <<
getLocation() <<
" because it is not finalizing, finalized, or tearing down";
129 if(
nullptr == resource_){
131 <<
getLocation() <<
" which does not have a resource";
152 <<
getLocation() <<
" because it is not finalizing, finalized, or tearing down";
168 template <class T, typename = typename std::enable_if<std::is_pointer<T>::value>::type>
174 <<
getLocation() <<
" because it is not finalizing, finalized, or tearing down";
176 if(
nullptr == resource_){
180 const T r =
dynamic_cast<T
>(resource_);
193 template <class T, typename = typename std::enable_if<!std::is_pointer<T>::value>::type>
195 return getResourceAs<T*>();
203 template <class T, typename = typename std::enable_if<std::is_pointer<T>::value>::type>
209 <<
getLocation() <<
" because it is not finalizing, finalized, or tearing down";
211 if(
nullptr == resource_){
212 throw SpartaException(
"Could not get Resource from ResourceTreeNode \"")
213 <<
getLocation() <<
"\" because it was null. Exepcted type: " <<
demangle(
typeid(T).name());
215 T r =
dynamic_cast<T
>(resource_);
217 throw SpartaException(
"Could not get Resource from ResourceTreeNode \"")
228 template <class T, typename = typename std::enable_if<!std::is_pointer<T>::value>::type>
230 return getResourceAs<T*>();
277 if(resource_locked_){
280 <<
" has been locked. It cannot be set");
282 if(resource_ !=
nullptr){
285 <<
" has already been set. It cannot be replaced. ");
290 <<
" cannot be assigned to nullptr. ");
309 <<
" has been locked. It cannot be unset until teardown");
324 resource_locked_ =
true;
336 ++num_resource_gets_;
344 ++num_resource_gets_;
358 bool resource_locked_;
369 mutable uint32_t num_resource_gets_;
Basic Node framework in sparta device tree composite pattern.
Set of macros for Sparta assertions. Caught by the framework.
Exception class for all of Sparta.
#define THROW_IF_NOT_UNWINDING(exclass, msg_construct)
Utility for throwing an exception ONLY if there is not already an uncaught exception causing the stac...
A representation of simulated time.
Object having a specific phase in the sparta construction paradigm.
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 met...
virtual bool isFinalizing() 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.
virtual bool isFinalized() const
Is this node (and thus the entire tree above it) "finalized".
PhasedObject which can hold 0 or 1 Resource pointers to an associatedresource. Contains logic for set...
virtual const Clock * getClock()=0
Gets the clock associated with this ResourceContainer, if any.
ResourceContainer(ResourceContainer &&)=default
Move constructor.
T * getResourceAs()
Non-const overload of getResourceAs.
T getResourceAs()
Non-const overload of getResourceAs.
void lockResource_()
Allows subclasses to assign the resource associated with this node.
void unsetResource_()
Allows a resource to unset the resource set with setResource_.
virtual std::string getResourceType() const
Gets the typename of the resource that this node will eventually contain.
const Resource * getResource_() const noexcept
Const variant of getResource_.
const T * getResourceAs() const
Overload of getResourceAs for const access with a non-pointer template type.
const Resource * getResource() const
Const variant of getResource.
Resource * getResource_() noexcept
Returns the currently held resource of this node (if any). This method can be called at any time.
ResourceContainer()
Consturct with a null, unlocked resource.
const T getResourceAs() const
Gets the resource contained by this node (if any) as the given type.
virtual ~ResourceContainer()
Destructor.
Resource * getResource()
Gets the resource contained by this node if any. May only be called after finalization begins or duri...
bool hasResource() const
Determines if this node has a resource. This method exists in case the TreeNode is being explored by ...
ResourceContainer(const ResourceContainer &)=delete
Copy construction disbled.
virtual std::string getResourceTypeRaw() const
Gets the typename of the resource that this node will eventually contain.
void setResource_(Resource *r)
Allows subclasses to assign the resource associated with this node.
std::string getResourceTypeName_() const
Gets the rtti type name (demangled) of the resource type held by this container. If there is no resou...
The is the base class for all types of resources used by the SPARTA framework.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Macros for handling exponential backoff.
std::string demangle(const std::string &name) noexcept
Demangles a C++ symbol.