diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 1531844..a8b0196 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -350,11 +350,9 @@ void AutoConnect::join(AutoConnectAux& aux) { * @param aux A vector of reference to AutoConnectAux that made up * the auxiliary page to be added. */ -void AutoConnect::join(std::vector> aux) { - for (std::size_t n = 0; n < aux.size(); n++) { - AutoConnectAux& addon = aux[n].get(); - join(addon); - } +void AutoConnect::join(AutoConnectAuxVT auxVector) { + for (std::reference_wrapper aux : auxVector) + join(aux.get()); } /** @@ -650,7 +648,7 @@ String AutoConnect::_induceReset(PageArgument& args) { */ String AutoConnect::_induceDisconnect(PageArgument& args) { _rfDisconnect = true; - return ""; + return String(""); } /** @@ -691,7 +689,7 @@ String AutoConnect::_induceConnect(PageArgument& args) { _webServer->client().stop(); _responsePage->cancel(); - return ""; + return String(""); } /** @@ -705,7 +703,7 @@ String AutoConnect::_invokeResult(PageArgument& args) { _webServer->client().flush(); _webServer->client().stop(); _responsePage->cancel(); - return ""; + return String(""); } /** @@ -794,7 +792,7 @@ bool AutoConnect::_isIP(String ipStr) { * @retval MAC address string in XX:XX:XX:XX:XX:XX format. */ String AutoConnect::_toMACAddressString(const uint8_t mac[]) { - String macAddr = ""; + String macAddr = String(""); for (uint8_t i = 0; i < 6; i++) { char buf[3]; sprintf(buf, "%02X", mac[i]); diff --git a/src/AutoConnect.h b/src/AutoConnect.h index 3d725c4..7d9f91e 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -161,6 +161,8 @@ class AutoConnectConfig { IPAddress dns2; /**< Secondary DNS server */ }; +typedef std::vector> AutoConnectAuxVT; + class AutoConnect { public: AutoConnect(); @@ -177,7 +179,7 @@ class AutoConnect { void handleRequest(); WebServerClass& host(); void join(AutoConnectAux& aux); - void join(std::vector> aux); + void join(AutoConnectAuxVT auxVector); bool on(const String& uri, const AuxHandlerFunctionT handler, AutoConnectExitOrder_t order = AC_EXIT_AHEAD); /** For AutoConnectAux described in JSON */ diff --git a/src/AutoConnectAux.cpp b/src/AutoConnectAux.cpp index 100d8c5..1e138eb 100644 --- a/src/AutoConnectAux.cpp +++ b/src/AutoConnectAux.cpp @@ -6,6 +6,7 @@ * @date 2018-11-17 * @copyright MIT license. */ +#include #include "AutoConnect.h" #include "AutoConnectAux.h" #include "AutoConnectElement.h" @@ -125,16 +126,11 @@ AutoConnectElement* AutoConnectAux::getElement(const String& name) { * @return false The specified AutoConnectElement not found in AutoConnectAux. */ bool AutoConnectAux::release(const String& name) { - bool rc = false; - for (std::size_t n = 0; n < _addonElm.size(); n++) { - String elmName = _addonElm[n].get().name; - if (name.equalsIgnoreCase(elmName)) { - AC_DBG("%s release from %s\n", elmName.c_str(), uri()); - _addonElm.erase(_addonElm.begin() + n); - rc = true; - } - } - return rc; + auto itr = std::remove_if(_addonElm.begin(), _addonElm.end(), + [&](std::reference_wrapper const elm) { + return elm.get().name.equalsIgnoreCase(name); + }); + return _addonElm.erase(itr, _addonElm.end()) != _addonElm.end(); } /** diff --git a/src/AutoConnectElementBasisImpl.h b/src/AutoConnectElementBasisImpl.h index f1f605e..01d3af1 100644 --- a/src/AutoConnectElementBasisImpl.h +++ b/src/AutoConnectElementBasisImpl.h @@ -102,8 +102,9 @@ const String AutoConnectRadioBasis::toHTML(void) const { if (order == AC_Vertical) html += String("
"); } - for (std::size_t n = 0; n < _values.size(); n++) { - String value = at(n); + uint8_t n = 0; + for (const String value : _values) { + n++; String id = name + "_" + String(n); html += String(FPSTR("") + label + String(FPSTR("")); html += String(FPSTR("")); return html; }