WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Resource Class Reference

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

#include <Resource.h>

Inheritance diagram for Resource:
ErrorBase

Public Member Functions

 Resource (const Resource &)=delete
 
Resourceoperator= (const Resource &)=delete
 
 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 ErrorBase
 ErrorBase (const ErrorBase &)=delete
 
ErrorBaseoperator= (const ErrorBase &)=delete
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t 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, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (llvm::StringRef errorMessage, Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
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 ErrorBase
static void SetGlobalError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber)
 
static void SetGlobalWPIError (llvm::StringRef errorMessage, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 Retrieve the current global error.
 

Additional Inherited Members

- Protected Attributes inherited from ErrorBase
Error m_error
 
- Static Protected Attributes inherited from ErrorBase
static priority_mutex _globalErrorMutex
 
static Error _globalError
 

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

Resource::Resource ( uint32_t  elements)
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 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 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.

void Resource::CreateResourceObject ( std::unique_ptr< Resource > &  r,
uint32_t  elements 
)
static

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

Parameters
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 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 files: