WPILibC++
2019.1.1-beta-4-6-g6593f43
|
The Resource class is a convenient way to track allocated resources. More...
#include <Resource.h>
Public Member Functions | |
Resource (Resource &&)=default | |
Resource & | operator= (Resource &&)=default |
Resource (uint32_t size) | |
Allocate storage for a new instance of Resource. More... | |
uint32_t | Allocate (const std::string &resourceDesc) |
Allocate a resource. More... | |
uint32_t | Allocate (uint32_t index, const std::string &resourceDesc) |
Allocate a specific resource value. More... | |
void | Free (uint32_t index) |
Free an allocated resource. More... | |
![]() | |
ErrorBase (ErrorBase &&)=default | |
ErrorBase & | operator= (ErrorBase &&)=default |
virtual Error & | GetError () |
Retrieve the current error. More... | |
virtual const Error & | GetError () const |
Retrieve the current error. More... | |
virtual void | ClearError () const |
Clear the current error information associated with this sensor. | |
virtual void | SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set error information associated with a C library call that set an error to the "errno" global variable. More... | |
virtual void | SetImaqError (int success, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated from the nivision Imaq API. More... | |
virtual void | SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | CloneError (const ErrorBase &rhs) const |
virtual bool | StatusIsFatal () const |
Check if the current error code represents a fatal error. More... | |
Static Public Member Functions | |
static void | CreateResourceObject (std::unique_ptr< Resource > &r, uint32_t elements) |
Factory method to create a Resource allocation-tracker if needed. More... | |
![]() | |
static void | SetGlobalError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) |
static void | SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) |
static const Error & | GetGlobalError () |
Retrieve the current global error. | |
Additional Inherited Members | |
![]() | |
Error | m_error |
The Resource class is a convenient way to track allocated resources.
It tracks them as indicies in the range [0 .. elements - 1]. E.g. the library uses this to track hardware channel allocation.
The Resource class does not allocate the hardware channels or other resources; it just tracks which indices were marked in use by Allocate and not yet freed by Free.
|
explicit |
Allocate storage for a new instance of Resource.
Allocate a bool array of values that will get initialized to indicate that no resources have been allocated yet. The indicies of the resources are [0 .. elements - 1].
uint32_t frc::Resource::Allocate | ( | const std::string & | resourceDesc | ) |
Allocate a resource.
When a resource is requested, mark it allocated. In this case, a free resource value within the range is located and returned after it is marked allocated.
uint32_t frc::Resource::Allocate | ( | uint32_t | index, |
const std::string & | resourceDesc | ||
) |
Allocate a specific resource value.
The user requests a specific resource value, i.e. channel number and it is verified unallocated, then returned.
|
static |
Factory method to create a Resource allocation-tracker if needed.
r | address of the caller's Resource pointer. If *r == nullptr, this will construct a Resource and make *r point to it. If *r != nullptr, i.e. the caller already has a Resource instance, this won't do anything. |
elements | the number of elements for this Resource allocator to track, that is, it will allocate resource numbers in the range [0 .. elements - 1]. |
void frc::Resource::Free | ( | uint32_t | index | ) |
Free an allocated resource.
After a resource is no longer needed, for example a destructor is called for a channel assignment class, Free will release the resource value so it can be reused somewhere else in the program.