Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed May 25, 2024
1 parent d962ce3 commit 5ea52e7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
18 changes: 1 addition & 17 deletions array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,9 @@ Supports arrays of simple types, such as char, int, double, or POD structures (i
DEFINE_FSTR_ARRAY(myDoubleArray, double,
PI, 53.0, 100, 1e8, 47
);
Serial.print("My double array: ");
myDoubleArray.printTo(Serial);
Serial.println();
Serial << F("My double array: ") << myDoubleArray << endl;


.. note::

Objects do not inherit from Printable because it is a virtual base class.

Therefore, statements like ``Serial.println(myDoubleArray)`` are not supported.

This also avoids ambiguity between implicit WString conversions.

There are some Print helper functions in the library you can use::

FSTR::println(Serial, myDoubleArray);

These are templated so will handle both simple data types and Objects.

You can share Arrays between translation units by declaring it in a header::

DECLARE_FSTR_ARRAY(table);
Expand Down
10 changes: 5 additions & 5 deletions map.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ We can now do this::
{
auto value = intmap[key];
if(value) {
Serial.printf("Found '%u' in map, containing %u chars\n", value.key(), value.content().length());
Serial.println(value.printer());
Serial << _F("Found '") << value.key() << _F("' in map, containing ") << value.content.length() << _F(" chars") << endl;
Serial << value << endl;
} else {
Serial.printf("Couldn't find '%u' in map\n", key);
Serial << _F("Couldn't find '") << key << _F("'' in map") << endl;
}
}

Expand Down Expand Up @@ -97,11 +97,11 @@ We can now do this::
auto& value = fileMap[fileName];
if(value) {
// Found
Serial.printf("Found '%s' in fileMap\n", String(value.key()).c_str());
Serial << _F("Found '") << value.key() << _F("' in fileMap") << endl;
auto stream = new FlashMemoryStream(value);
response.sendDataStream(stream, ContentType::fromFullFileName(fileName));
} else {
Serial.printf("File '%s' not found\n", fileName.c_str());
Serial << _F("File '") << fileName << _F("' not found") << endl;
}
}

Expand Down
15 changes: 13 additions & 2 deletions string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Within a function::
DEFINE_FSTR_LOCAL(myFlashString, "This is my flash string");

Serial.println(myFlashString);
Serial.printf("myFlashString has %u chars and occupies %u bytes\n", myFlashString.length(), myFlashString.size());
Serial << F("myFlashString has ") << myFlashString.length() << F(" chars and occupies ") << myFlashString.size() << F(" bytes") << endl;

To use Strings across translation units, we do this in the header::

Expand All @@ -41,6 +41,8 @@ And in a source file::
You can generally use a Flash String anywhere you can use a regular Wiring String as it has
an implicit *::String()* operator. Note that ``WString`` is used within the library for disambiguation.

See also :cpp:class:`CStringArray`.


Inline Strings
--------------
Expand Down Expand Up @@ -73,8 +75,17 @@ This is equivalent to::
FS("A Flash String").printTo(Serial);
Serial.println();

:cpp:func:`FSTR::String::printTo` uses no heap and imposes no restriction on the string length.
.. note::

Sming contains general streaming support via :cpp:class:`Print`, so FlashString objects can
be printed like this::

Serial.println(myFlashString);
Serial << myFlashString << endl;

This is implemented via non-virtual `printTo` overrides.

:cpp:func:`FSTR::String::printTo` uses no heap and imposes no restriction on the string length.


Nested Inline Strings
Expand Down
3 changes: 1 addition & 2 deletions table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ Each row is a fixed size. The :cpp:class:`FSTR::TableRow` class template is prov
{0.1, 0.2, 0.3},
{0.6, 0.7, 0.8}
);
table.printTo(Serial);
table.println();
Serial.println(table);


If you want to create a table with rows of different sizes or types, use a :doc:`Vector <vector>`.
Expand Down

0 comments on commit 5ea52e7

Please sign in to comment.