WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
frc::Resource Class Reference

The Resource class is a convenient way to track allocated resources. More...

#include <Resource.h>

Inheritance diagram for frc::Resource:
frc::ErrorBase

Public Member Functions

 Resource (Resource &&)=default
 
Resourceoperator= (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...
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (ErrorBase &&)=default
 
ErrorBaseoperator= (ErrorBase &&)=default
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () 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 Public Member Functions inherited from frc::ErrorBase
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 ErrorGetGlobalError ()
 Retrieve the current global error.
 

Additional Inherited Members

- Protected Attributes inherited from frc::ErrorBase
Error m_error
 

Detailed Description

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.

Constructor & Destructor Documentation

frc::Resource::Resource ( uint32_t  size)
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].

Member Function Documentation

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 void frc::Resource::CreateResourceObject ( std::unique_ptr< Resource > &  r,
uint32_t  elements 
)
static

Factory method to create a Resource allocation-tracker if needed.

Parameters
raddress 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.
elementsthe 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.


The documentation for this class was generated from the following file: