Skip to content

Commit

Permalink
Classchooser avoid copies by reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Ultrawipf committed May 7, 2024
1 parent 0fba1a6 commit dfd867c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Firmware/FFBoard/Inc/ClassChooser.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ClassChooser {
*/
T* Create(uint16_t id){
T* cls = nullptr;
for(class_entry<T> e : *class_registry){
for(const class_entry<T>& e : *class_registry){

if(e.selectionId == id && e.isCreatable()){
cls = e.create();
Expand All @@ -114,7 +114,7 @@ class ClassChooser {
* Checks the isCreatable() function
*/
bool isCreatable(uint16_t id){
for(class_entry<T> e : *class_registry){
for(const class_entry<T>& e : *class_registry){
if(e.selectionId == id && e.isCreatable()){
return true;
}
Expand All @@ -127,18 +127,18 @@ class ClassChooser {
* Generates replies for the command system listing selectable classes
*/
void replyAvailableClasses(std::vector<CommandReply>& replies,int16_t ignoredCreatableId = 255){
for(class_entry<T> cls : *class_registry){
for(const class_entry<T>& cls : *class_registry){
if(cls.info.visibility == ClassVisibility::hidden || (cls.info.visibility == ClassVisibility::debug && !SystemCommands::debugMode)){
if(ignoredCreatableId != cls.selectionId)
continue;
}
std::string ret;
// std::string ret;
CommandReply replyObj;
ret+= std::to_string(cls.selectionId);
ret+= ":";
ret+= (cls.isCreatable() || ignoredCreatableId == cls.selectionId) ? "1" : "0";
ret+= ":";
ret+= cls.info.name;
replyObj.reply+= std::to_string(cls.selectionId);
replyObj.reply+= ":";
replyObj.reply+= (cls.isCreatable() || ignoredCreatableId == cls.selectionId) ? "1" : "0";
replyObj.reply+= ":";
replyObj.reply+= cls.info.name;

if(cls.isCreatable()){
replyObj.type = CommandReplyType::STRING_OR_DOUBLEINT;
Expand All @@ -147,7 +147,7 @@ class ClassChooser {
}else{
replyObj.type = CommandReplyType::STRING;
}
replyObj.reply = ret;
// replyObj.reply = ret;
replies.push_back(replyObj);
}
}
Expand All @@ -157,7 +157,7 @@ class ClassChooser {
* Returns if this id is actually in the list of possible classes
*/
bool isValidClassId(uint16_t id){
for(class_entry<T> cls : *class_registry){
for(const class_entry<T>& cls : *class_registry){
if(cls.selectionId == id){
return true;
}
Expand Down

0 comments on commit dfd867c

Please sign in to comment.