mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Add format script which invokes clang-format on the C++ source code (#41)
On Windows machines, clang-format.exe must be in the PATH environment variable.
This commit is contained in:
committed by
Peter Johnson
parent
68690643d2
commit
e14e45da76
@@ -7,23 +7,22 @@
|
||||
|
||||
#include "Commands/Scheduler.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include "Buttons/ButtonScheduler.h"
|
||||
#include "Commands/Subsystem.h"
|
||||
#include "HLUsageReporting.h"
|
||||
#include "WPIErrors.h"
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
Scheduler::Scheduler() {
|
||||
HLUsageReporting::ReportScheduler();
|
||||
}
|
||||
Scheduler::Scheduler() { HLUsageReporting::ReportScheduler(); }
|
||||
|
||||
/**
|
||||
* Returns the {@link Scheduler}, creating it if one does not exist.
|
||||
*
|
||||
* @return the {@link Scheduler}
|
||||
*/
|
||||
Scheduler *Scheduler::GetInstance() {
|
||||
Scheduler* Scheduler::GetInstance() {
|
||||
static Scheduler instance;
|
||||
return &instance;
|
||||
}
|
||||
@@ -32,12 +31,13 @@ void Scheduler::SetEnabled(bool enabled) { m_enabled = enabled; }
|
||||
|
||||
/**
|
||||
* Add a command to be scheduled later.
|
||||
*
|
||||
* In any pass through the scheduler, all commands are added to the additions
|
||||
* list, then
|
||||
* at the end of the pass, they are all scheduled.
|
||||
* list, then at the end of the pass, they are all scheduled.
|
||||
*
|
||||
* @param command The command to be scheduled
|
||||
*/
|
||||
void Scheduler::AddCommand(Command *command) {
|
||||
void Scheduler::AddCommand(Command* command) {
|
||||
std::lock_guard<priority_mutex> sync(m_additionsLock);
|
||||
if (std::find(m_additions.begin(), m_additions.end(), command) !=
|
||||
m_additions.end())
|
||||
@@ -45,12 +45,12 @@ void Scheduler::AddCommand(Command *command) {
|
||||
m_additions.push_back(command);
|
||||
}
|
||||
|
||||
void Scheduler::AddButton(ButtonScheduler *button) {
|
||||
void Scheduler::AddButton(ButtonScheduler* button) {
|
||||
std::lock_guard<priority_mutex> sync(m_buttonsLock);
|
||||
m_buttons.push_back(button);
|
||||
}
|
||||
|
||||
void Scheduler::ProcessCommandAddition(Command *command) {
|
||||
void Scheduler::ProcessCommandAddition(Command* command) {
|
||||
if (command == nullptr) return;
|
||||
|
||||
// Check to make sure no adding during adding
|
||||
@@ -67,7 +67,7 @@ void Scheduler::ProcessCommandAddition(Command *command) {
|
||||
Command::SubsystemSet requirements = command->GetRequirements();
|
||||
Command::SubsystemSet::iterator iter;
|
||||
for (iter = requirements.begin(); iter != requirements.end(); iter++) {
|
||||
Subsystem *lock = *iter;
|
||||
Subsystem* lock = *iter;
|
||||
if (lock->GetCurrentCommand() != nullptr &&
|
||||
!lock->GetCurrentCommand()->IsInterruptible())
|
||||
return;
|
||||
@@ -76,7 +76,7 @@ void Scheduler::ProcessCommandAddition(Command *command) {
|
||||
// Give it the requirements
|
||||
m_adding = true;
|
||||
for (iter = requirements.begin(); iter != requirements.end(); iter++) {
|
||||
Subsystem *lock = *iter;
|
||||
Subsystem* lock = *iter;
|
||||
if (lock->GetCurrentCommand() != nullptr) {
|
||||
lock->GetCurrentCommand()->Cancel();
|
||||
Remove(lock->GetCurrentCommand());
|
||||
@@ -93,8 +93,9 @@ void Scheduler::ProcessCommandAddition(Command *command) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a single iteration of the loop. This method should be called often in
|
||||
* order to have a functioning
|
||||
* Runs a single iteration of the loop.
|
||||
*
|
||||
* This method should be called often in order to have a functioning
|
||||
* {@link Command} system. The loop has five stages:
|
||||
*
|
||||
* <ol>
|
||||
@@ -122,7 +123,7 @@ void Scheduler::Run() {
|
||||
// Loop through the commands
|
||||
auto commandIter = m_commands.begin();
|
||||
for (; commandIter != m_commands.end();) {
|
||||
Command *command = *commandIter;
|
||||
Command* command = *commandIter;
|
||||
// Increment before potentially removing to keep the iterator valid
|
||||
commandIter++;
|
||||
if (!command->Run()) {
|
||||
@@ -144,7 +145,7 @@ void Scheduler::Run() {
|
||||
// Add in the defaults
|
||||
auto subsystemIter = m_subsystems.begin();
|
||||
for (; subsystemIter != m_subsystems.end(); subsystemIter++) {
|
||||
Subsystem *lock = *subsystemIter;
|
||||
Subsystem* lock = *subsystemIter;
|
||||
if (lock->GetCurrentCommand() == nullptr) {
|
||||
ProcessCommandAddition(lock->GetDefaultCommand());
|
||||
}
|
||||
@@ -156,12 +157,13 @@ void Scheduler::Run() {
|
||||
|
||||
/**
|
||||
* Registers a {@link Subsystem} to this {@link Scheduler}, so that the {@link
|
||||
* Scheduler} might know
|
||||
* if a default {@link Command} needs to be run. All {@link Subsystem
|
||||
* Subsystems} should call this.
|
||||
* Scheduler} might know if a default {@link Command} needs to be run.
|
||||
*
|
||||
* All {@link Subsystem Subsystems} should call this.
|
||||
*
|
||||
* @param system the system
|
||||
*/
|
||||
void Scheduler::RegisterSubsystem(Subsystem *subsystem) {
|
||||
void Scheduler::RegisterSubsystem(Subsystem* subsystem) {
|
||||
if (subsystem == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "subsystem");
|
||||
return;
|
||||
@@ -171,9 +173,10 @@ void Scheduler::RegisterSubsystem(Subsystem *subsystem) {
|
||||
|
||||
/**
|
||||
* Removes the {@link Command} from the {@link Scheduler}.
|
||||
*
|
||||
* @param command the command to remove
|
||||
*/
|
||||
void Scheduler::Remove(Command *command) {
|
||||
void Scheduler::Remove(Command* command) {
|
||||
if (command == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "command");
|
||||
return;
|
||||
@@ -184,7 +187,7 @@ void Scheduler::Remove(Command *command) {
|
||||
Command::SubsystemSet requirements = command->GetRequirements();
|
||||
auto iter = requirements.begin();
|
||||
for (; iter != requirements.end(); iter++) {
|
||||
Subsystem *lock = *iter;
|
||||
Subsystem* lock = *iter;
|
||||
lock->SetCurrentCommand(nullptr);
|
||||
}
|
||||
|
||||
@@ -211,7 +214,7 @@ void Scheduler::ResetAll() {
|
||||
|
||||
/**
|
||||
* Update the network tables associated with the Scheduler object on the
|
||||
* SmartDashboard
|
||||
* SmartDashboard.
|
||||
*/
|
||||
void Scheduler::UpdateTable() {
|
||||
CommandSet::iterator commandIter;
|
||||
@@ -230,7 +233,7 @@ void Scheduler::UpdateTable() {
|
||||
for (commandIter = m_commands.begin(); commandIter != m_commands.end();
|
||||
++commandIter) {
|
||||
for (unsigned i = 0; i < toCancel.size(); i++) {
|
||||
Command *c = *commandIter;
|
||||
Command* c = *commandIter;
|
||||
if (c->GetID() == toCancel[i]) {
|
||||
c->Cancel();
|
||||
}
|
||||
@@ -246,7 +249,7 @@ void Scheduler::UpdateTable() {
|
||||
ids.resize(0);
|
||||
for (commandIter = m_commands.begin(); commandIter != m_commands.end();
|
||||
++commandIter) {
|
||||
Command *c = *commandIter;
|
||||
Command* c = *commandIter;
|
||||
commands.push_back(c->GetName());
|
||||
ids.push_back(c->GetID());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user