Review components files
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
// pages.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <initializer_list>
|
||||
|
||||
@@ -12,7 +11,7 @@ namespace nspanel_ha_blueprint {
|
||||
|
||||
/**
|
||||
* @file pages.h
|
||||
* Defines constants and functions related to page names for "NSPanel HA Blueprint" project.
|
||||
* Defines constants and functions related to page names for the NSPanel HA Blueprint project.
|
||||
*/
|
||||
|
||||
// Constants
|
||||
@@ -59,51 +58,15 @@ namespace nspanel_ha_blueprint {
|
||||
* @return The index of the page_name in the page_names array. If the page_name
|
||||
* is not found, returns UINT8_MAX as an indicator that no matching page was found.
|
||||
*/
|
||||
inline uint8_t get_page_id(const std::string& page_name) {
|
||||
for (uint8_t i = 0; i < page_names.size(); ++i) {
|
||||
if (strcmp(page_names[i], page_name.c_str()) == 0) {
|
||||
return i; // Return the index if found
|
||||
}
|
||||
}
|
||||
return UINT8_MAX; // Return UINT8_MAX if not found
|
||||
}
|
||||
uint8_t get_page_id(const std::string& page_name);
|
||||
|
||||
/**
|
||||
* Checks if a given string is present within a list of strings.
|
||||
*
|
||||
* This function provides a convenient way to search for the presence of a specific string
|
||||
* within a variably sized list of strings. It iterates through each string in the provided
|
||||
* list, comparing it against the target string for an exact match. This utility is particularly
|
||||
* useful for validating if a certain value matches any item from a predefined set of allowed
|
||||
* values.
|
||||
*
|
||||
* @param strToSearch The string to search for within the list. This is the target string
|
||||
* that the function will attempt to find an exact match for within the
|
||||
* provided list of strings.
|
||||
* @param list An initializer list of strings to search within. This list contains the strings
|
||||
* against which the target string will be compared. The list is flexible in size,
|
||||
* allowing for a variable number of strings to be specified.
|
||||
*
|
||||
* @return Returns `true` if the target string is found within the list, indicating an exact
|
||||
* match was encountered. Returns `false` if the target string is not present in the
|
||||
* list, indicating no matches were found.
|
||||
*
|
||||
* Usage Example:
|
||||
* ```cpp
|
||||
* std::string page = "alarm";
|
||||
* bool isPresent = isStringInList(page, {"alarm", "climate", "cover", "fan", "light", "media_player", "confirm", "keyb_num"});
|
||||
* if (!isPresent) {
|
||||
* // The string 'page' was not found in the list
|
||||
* }
|
||||
* ```
|
||||
* @param strToSearch The string to search for within the list.
|
||||
* @param list An initializer list of strings to search within.
|
||||
* @return `true` if the target string is found within the list, `false` otherwise.
|
||||
*/
|
||||
bool isStringInList(const std::string& strToSearch, std::initializer_list<std::string> list) {
|
||||
for (const auto& str : list) {
|
||||
if (strToSearch == str) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool isStringInList(const std::string& strToSearch, std::initializer_list<std::string> list);
|
||||
|
||||
} // namespace nspanel_ha_blueprint
|
||||
|
||||
Reference in New Issue
Block a user