Package edu.wpi.first.wpilibj
Class Resource
java.lang.Object
edu.wpi.first.wpilibj.Resource
Deprecated, for removal: This API element is subject to removal in a future version.
Will be removed with no replacement.
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 indices that have a 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
ConstructorDescriptionResource
(int size) Deprecated, for removal: This API element is subject to removal in a future version.Allocate storage for a new instance of Resource. -
Method Summary
Modifier and TypeMethodDescriptionint
allocate()
Deprecated, for removal: This API element is subject to removal in a future version.Allocate a resource.int
allocate
(int index) Deprecated, for removal: This API element is subject to removal in a future version.Allocate a specific resource value.void
free
(int index) Deprecated, for removal: This API element is subject to removal in a future version.Free an allocated resource.static void
Deprecated, for removal: This API element is subject to removal in a future version.Clears all allocated resources.
-
Constructor Details
-
Resource
Deprecated, for removal: This API element is subject to removal in a future version.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 indices of the resources are 0..size-1.- Parameters:
size
- The number of blocks to allocate
-
-
Method Details
-
restartProgram
Deprecated, for removal: This API element is subject to removal in a future version.Clears all allocated resources. -
allocate
Deprecated, for removal: This API element is subject to removal in a future version.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.- Returns:
- The index of the allocated block.
- Throws:
CheckedAllocationException
- If there are no resources available to be allocated.
-
allocate
Deprecated, for removal: This API element is subject to removal in a future version.Allocate a specific resource value. The user requests a specific resource value, i.e. channel number, and it is verified unallocated, then returned.- Parameters:
index
- The resource to allocate- Returns:
- The index of the allocated block
- Throws:
CheckedAllocationException
- If there are no resources available to be allocated.
-
free
Deprecated, for removal: This API element is subject to removal in a future version.Free an allocated resource. After a resource is no longer needed, for example a destructor is called for a channel assignment class, this method will release the resource value, so it can be reused somewhere else in the program.- Parameters:
index
- The index of the resource to free.
-