diff --git a/examples/FileUpload/FileUpload.ino b/examples/FileUpload/FileUpload.ino index 8552a41..6bc4c48 100644 --- a/examples/FileUpload/FileUpload.ino +++ b/examples/FileUpload/FileUpload.ino @@ -115,8 +115,7 @@ String postUpload(AutoConnectAux& aux, PageArgument& args) { String content; // Explicitly cast to the desired element to correctly extract // the element using the operator []. -// AutoConnectAux& root_page = *portal.aux("/"); - AutoConnectFile& filename = static_cast(auxUpload["filename"]); + AutoConnectFile& filename = (AutoConnectFile&)auxUpload["filename"]; AutoConnectText& aux_filename = (AutoConnectText&)aux["filename"]; AutoConnectText& aux_size = (AutoConnectText&)aux["size"]; AutoConnectText& aux_contentType = (AutoConnectText&)aux["content_type"]; diff --git a/mkdocs/achandling.md b/mkdocs/achandling.md index a8bda6a..6c3a8eb 100644 --- a/mkdocs/achandling.md +++ b/mkdocs/achandling.md @@ -101,14 +101,19 @@ AutoConenctText& text = aux->getElement("caption"); // Cast to Serial.println(text.value); ``` -You can also use the operator **`[]`** as another way to get the desired element. An operator **`[]`** is a shortcut for [getElement](apiaux.me#getelement) function with the reference casting and makes simplify the code. Its argument is the name of the element to be acquired similarly to getElement function. For example, the following sketch code returns the same as reference of AutoConnectText element as `caption`. +You can also use the [operator **`[]`** of AutoConnectAux](apiaux.md#operator) as another way to get the desired element. An operator **`[]`** is a shortcut for [getElement](apiaux.me#getelement) function with the reference casting and makes simplify the code. Its argument is the name of the element to be acquired similarly to getElement function. For example, the following sketch code returns the same as reference of AutoConnectText element as `caption`. -```cpp -AutoConnectAux& aux = *portal.aux("/page1"); +```cpp hl_lines="4 5" +AutoConnect portal; +portal.load(auxJson); +AutoConnectAux& aux = *portal.aux("/page1"); AutoConnectText& text1 = aux.getElement("caption"); AutoConnectText& text2 = (AutoConnectText&)aux["caption"]; ``` +!!! note "Need cast to convert to the actual type" + An operator `[]` returns a referene of an AutoConnectElement. It is necessary to convert the type according to the actual element type. + To get all the AutoConnectElements in an AutoConnectAux object use the [**getElements**](apiaux.md#getelements) function. This function returns the vector of the reference wrapper as **AutoConnectElementVT** to all AutoConnectElements registered in the AutoConnectAux. ```cpp diff --git a/mkdocs/apiaux.md b/mkdocs/apiaux.md index f1a4853..bc30842 100644 --- a/mkdocs/apiaux.md +++ b/mkdocs/apiaux.md @@ -15,6 +15,18 @@ AutoConnectAux(const String& uri = String(""), const String& title = String(""), ## Public member functions +### operator [ ] + +```cpp +AutoConnectElement& operator[](const String& name) +``` +Returns a reference to the element specified by **name**. An operator `[]` is a shortcut for [getElement](apiaux.md#getelement) function with the reference casting. Unlike getElement, which returns a pointer to that element, an operator `[]` returns a reference to that element. You also need to cast the return value to the actual type, just like the getElement function. +
+
**Parameters**
+
nameName of the AutoConnectElements to be retrieved.
+
**Return value**
A reference to AutoConnectElement. It is different from the actual element type.
+
+ ### add ```cpp