|
" 2013 FRC Java API " |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.wpi.first.wpilibj.Resource
public class Resource
Track resources in the program. The Resource class is a convenient way of keeping track of allocated arbitrary resources in the program. Resources are just indicies that have an lower and upper bound that are tracked by this class. In the library they are used for tracking allocation of hardware channels but this is purely arbitrary. The resource class does not do any actual allocation, but simply tracks if a given index is currently in use. WARNING: this should only be statically allocated. When the program loads into memory all the static constructors are called. At that time a linked list of all the "Resources" is created. Then when the program actually starts - in the Robot constructor, all resources are initialized. This ensures that the program is restartable in memory without having to unload/reload.
Constructor Summary | |
---|---|
Resource(int size)
Allocate storage for a new instance of Resource. |
Method Summary | |
---|---|
int |
allocate()
Allocate a resource. |
int |
allocate(int index)
Allocate a specific resource value. |
void |
free(int index)
Free an allocated resource. |
static void |
restartProgram()
Clears all allocated resources |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Resource(int size)
size
- The number of blocks to allocateMethod Detail |
---|
public static void restartProgram()
public int allocate() throws CheckedAllocationException
CheckedAllocationException
- If there are no resources available to be allocated.public int allocate(int index) throws CheckedAllocationException
index
- The resource to allocate
CheckedAllocationException
- If there are no resources available to be allocated.public void free(int index)
index
- The index of the resource to free.
|
" 2013 FRC Java API " |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |