Improved execution efficiency

pull/41/head
Hieromon Ikasamo 6 years ago
parent e1815b82b6
commit b13b7db3d3
  1. 16
      src/AutoConnect.cpp
  2. 4
      src/AutoConnect.h
  3. 16
      src/AutoConnectAux.cpp
  4. 12
      src/AutoConnectElementBasisImpl.h

@ -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<std::reference_wrapper<AutoConnectAux>> 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<AutoConnectAux> 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]);

@ -161,6 +161,8 @@ class AutoConnectConfig {
IPAddress dns2; /**< Secondary DNS server */
};
typedef std::vector<std::reference_wrapper<AutoConnectAux>> AutoConnectAuxVT;
class AutoConnect {
public:
AutoConnect();
@ -177,7 +179,7 @@ class AutoConnect {
void handleRequest();
WebServerClass& host();
void join(AutoConnectAux& aux);
void join(std::vector<std::reference_wrapper<AutoConnectAux>> aux);
void join(AutoConnectAuxVT auxVector);
bool on(const String& uri, const AuxHandlerFunctionT handler, AutoConnectExitOrder_t order = AC_EXIT_AHEAD);
/** For AutoConnectAux described in JSON */

@ -6,6 +6,7 @@
* @date 2018-11-17
* @copyright MIT license.
*/
#include <algorithm>
#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<AutoConnectElement> const elm) {
return elm.get().name.equalsIgnoreCase(name);
});
return _addonElm.erase(itr, _addonElm.end()) != _addonElm.end();
}
/**

@ -102,8 +102,9 @@ const String AutoConnectRadioBasis::toHTML(void) const {
if (order == AC_Vertical)
html += String("<br>");
}
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("<input type=\"radio\" name=\"")) + name + String(FPSTR("\" id=\"")) + id + String(FPSTR("\" value=\"")) + value + String("\"");
if (n == checked - 1)
@ -142,11 +143,8 @@ const String AutoConnectSelectBasis::toHTML(void) const {
if (label.length())
html = String(FPSTR("<label for=\"")) + name + String("\">") + label + String(FPSTR("</label>"));
html += String(FPSTR("<select name=\"")) + name + String("\" id=\"") + name + String("\">");
std::size_t n = _options.size();
if (n) {
for (std::size_t n = 0; n < _options.size(); n++)
html += String(FPSTR("<option value=\"")) + _options[n] + "\">" + _options[n] + String(FPSTR("</option>"));
}
for (const String option : _options)
html += String(FPSTR("<option value=\"")) + option + "\">" + option + String(FPSTR("</option>"));
html += String(FPSTR("</select>"));
return html;
}

Loading…
Cancel
Save