Skip to content

Commit 0dfb0d7

Browse files
committed
Revise documentation with doxygen information
Move into groups and add API information section to pages
1 parent 98fda8b commit 0dfb0d7

29 files changed

+436
-249
lines changed

README.rst

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
FlashString Library
2-
===================
1+
FlashString
2+
===========
33

44
.. highlight:: C++
55

@@ -15,7 +15,7 @@ but could be ported to other platforms relatively easily.
1515
Perhaps the most common use for PROGMEM data is passing strings around, usually as a
1616
pointer to a 'C' NUL-terminated char array. There are a couple of problems with this:
1717

18-
1. If we need to know how long the string is, we need to call *strlen_P*, which is
18+
1. If we need to know how long the string is, we need to call :c:func:`strlen_P`, which is
1919
*really* expensive computationally.
2020
2. We can't include NUL characters in the string.
2121

@@ -26,37 +26,41 @@ Both of these are easily solved by passing the length along with the string, lik
2626

2727
Of course, passing two parameters instead of one gets tiresome and is not very C++, is it?
2828

29-
30-
The library
31-
-----------
32-
3329
This library implements C++ objects stored in flash memory, using macros to create the
3430
data structures. The object interfaces are implemented using class templates for
3531
performance and flexibility.
3632

3733
The classes are all in the ``FSTR`` namespace.
3834

39-
The Sming framework provides several aliases to provide compatibility with existing code:
40-
41-
- ``FlashString`` -> ``FSTR::String``
42-
- ``FlashMemoryStream`` -> ``FSTR::Stream``
43-
- ``TemplateFlashMemoryStream`` -> ``FSTR::TemplateStream``
44-
45-
Only ``FlashString`` is provided by default as it integrates with Wiring Strings.
46-
If you wish to use any of the other object types, #include the appropriate header::
47-
48-
#include <FlashString/Array.hpp>
49-
50-
You can find more detail in the following sections.
51-
5235
.. toctree::
53-
36+
:maxdepth: 1
37+
5438
object
5539
string
5640
array
41+
table
5742
vector
5843
map
44+
streams
5945
utility
46+
47+
48+
Sming Integration
49+
-----------------
50+
51+
Sming provides several aliases to provide compatibility with existing code:
52+
53+
- :cpp:type:`FlashString` -> :cpp:class:`FSTR::String`
54+
- :cpp:class:`FlashMemoryStream` -> :cpp:class:`FSTR::Stream`
55+
- :cpp:class:`TemplateFlashMemoryStream` -> :cpp:class:`FSTR::TemplateStream`
56+
57+
58+
Other pages
59+
-----------
60+
61+
.. toctree::
62+
:maxdepth: 1
63+
6064
upgrade
6165
changelog
6266
technical

about.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,32 @@ I created it as a one-file solution to address these specific issues:
1313
FlashString classes as if they were just stored in flash so I wouldn't have to wrap
1414
everything in a macro, like F() does.
1515

16-
Solution: The FlashString class.
16+
Solution: The :cpp:class:`FlashString` class.
1717

1818
2. Using PROGMEM directly for data is cumbersome, slow and fraught with danger: It's inherently unsafe
1919
because of the alignment issues. Some smart cookie came up with a compiler patch so it could
2020
insert the correct instructions and thus avoid alignment exceptions. However, that still causes
2121
execution of inefficient code since the hardware requires we perform aligned accesses.
2222
Generating the structures correctly in the first place felt the best way forward.
2323

24-
Solution: DEFINE_FSTR
24+
Solution: :c:func:`DEFINE_FSTR`
2525

2626
3. Sharing flash data structures globally
2727

28-
Solution: DECLARE_FSTR
28+
Solution: :c:func:`DECLARE_FSTR`
2929

3030
4. How to get content into PROGMEM without having to manually convert everything into
3131
C structures. One solution to this is using external tools but that complicates the build
3232
process and felt un-necessary.
3333

34-
Solution: IMPORT_FSTR
34+
Solution: :c:func:`IMPORT_FSTR`
3535

3636
5. Relying on SPIFFS for serving fixed content is inefficient and problematic if/when the
3737
filesystem gets corrupted. I needed a solution which allowed large content to be
3838
served up without requiring a filesystem. The long term solution to this is, of course,
3939
a read-only filesystem but that is a complex thing indeed to do properly.
4040

41-
Solution: FlashMemoryStream
41+
Solution: :cpp:class:`FlashMemoryStream`
4242

4343

4444
Embedded microsystems

array.rst

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Introduction
88

99
Supports arrays of simple types, such as char, int, double, or POD structures (i.e. basic C structures).
1010

11-
The ``Array`` is a class template, so requires an additional ``ElementType`` parameter::
11+
:cpp:class:`FSTR::Array` is a class template, so requires an additional ``ElementType`` parameter::
1212

1313
#include <FlashString/Array.hpp>
1414

@@ -39,45 +39,13 @@ You can share Arrays between translation units by declaring it in a header::
3939
DECLARE_FSTR_ARRAY(table);
4040

4141

42-
Tables
42+
Macros
4343
------
4444

45-
Simple tables can be implemented using Arrays, like this::
46-
47-
struct TableRow {
48-
float columns[3];
49-
50-
int operator[](size_t index) const
51-
{
52-
return columns[index];
53-
}
54-
};
55-
DEFINE_FSTR_ARRAY(table, TableRow,
56-
{0.1, 0.2, 0.3},
57-
{0.6, 0.7, 0.8}
58-
);
59-
for(auto row: table) {
60-
Serial.printf("%f, %f, %f\n", row[0], row[1], row[2]);
61-
}
62-
63-
Each row is a fixed size. The ``TableRow`` class template is provided to simplify this::
64-
65-
#include <FlashString/Table.hpp>
66-
67-
using FloatRow = FSTR::TableRow<float, 3>;
68-
DEFINE_FSTR_ARRAY(table, FloatRow,
69-
{0.1, 0.2, 0.3},
70-
{0.6, 0.7, 0.8}
71-
);
72-
table.printTo(Serial);
73-
table.println();
74-
75-
76-
If you want to create a table with rows of different sizes or types, use a :doc:`Vector <vector>`.
77-
45+
.. doxygengroup:: fstr_array
46+
:content-only:
7847

79-
Additional Macros
80-
-----------------
48+
Classes
49+
-------
8150

82-
DEFINE_FSTR_ARRAY_DATA(name, ...)
83-
Define the data structure without an associated reference.
51+
.. doxygenclass:: FSTR::Array

component.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
COMPONENT_INCDIRS := src/include
22
COMPONENT_SRCDIRS := src
3+
COMPONENT_DOXYGEN_INPUT := src/include
4+
COMPONENT_DOXYGEN_INCLUDE_PATH := src/include/config.hpp
5+
COMPONENT_DOXYGEN_PREDEFINED := \
6+
FSTR_INLINE= \
7+
FSTR_PACKED=

map.rst

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
Associative Maps
2-
================
1+
Maps
2+
====
33

44
.. highlight:: C++
55

66
Introduction
77
------------
88

9-
A ``Map`` is analogous to the Wiring HashMap class, allowing content to be indexed using
9+
A :cpp:class:`FSTR::Map` is analogous to the Wiring :cpp:class:`HashMap` class, allowing content to be indexed using
1010
a key value.
1111

12-
The Map contains an array of ``MapPair`` structures::
12+
The Map contains an array of :cpp:class:`FSTR::MapPair` structures::
1313

1414
struct MapPair<KeyType, ContentType> {
1515
KeyType key_;
@@ -22,8 +22,10 @@ It may also be a ``String`` Object (or, more precisely, ``String*``).
2222
``ContentType`` can be any Object type (String, Array, Vector or Map).
2323
This allows hierarchical structures to be created.
2424

25-
Example: int => String
26-
----------------------
25+
.. |rArr| unicode:: 0x21D2 .. => arrow
26+
27+
Example: int |rArr| String
28+
--------------------------
2729

2830
Here's a basic example using integer keys::
2931

@@ -51,8 +53,8 @@ We can now do this::
5153
}
5254

5355

54-
Example: String => String
55-
-------------------------
56+
Example: String |rArr| String
57+
-----------------------------
5658

5759
Both the key and the content are stored as Strings::
5860

@@ -111,9 +113,16 @@ Note: ``FSTR::`` namespace qualifier omitted for clarity.
111113
Usually, each MapPair is 8 bytes, but if the key is a double or int64 it would be 12 bytes.
112114

113115

114-
Additional Macros
115-
-----------------
116+
Macros
117+
------
118+
119+
.. doxygengroup:: fstr_map
120+
:content-only:
121+
122+
123+
Class Templates
124+
---------------
116125

117-
DEFINE_FSTR_MAP_DATA(name, KeyType, ContentType, ...)
118-
Define the map structure without an associated reference.
126+
.. doxygenclass:: FSTR::Map
119127

128+
.. doxygenclass:: FSTR::MapPair

object.rst

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ Objects
66
Introduction
77
------------
88

9-
An ``Object`` is a class template with array-like behaviour, though it is not used directly.
9+
An :cpp:class:`FSTR::Object` is a class template with array-like behaviour, though it is not used directly.
1010

1111
Instead, use one of the four classes in the library:
1212

13-
- String
14-
- Array
15-
- Vector
16-
- Map
13+
- :doc:`String <string>`
14+
- :doc:`Array <array>`
15+
- :doc:`Vector <vector>`
16+
- :doc:`Map <map>`
1717

1818
Each type has its own set of macros for easy data construction, and creation of the
1919
appropriate Object class which may then be used directly.
2020

2121
Macros follow the same pattern:
2222

23-
DEFINE_FSTR_\*
23+
``DEFINE_FSTR_*``
2424
Creates a static data structure with an associated Object reference.
2525
The _LOCAL variant makes the reference static.
2626

27-
DECLARE_FSTR_\*
27+
``DECLARE_FSTR_*``
2828
Use this in a header to declare Object reference so it can be used across
2929
translation units.
3030

@@ -34,10 +34,10 @@ Created symbols are C++ and adopt any enclosing namespaced.
3434
Reading Object content
3535
----------------------
3636

37-
To read parts of an Object, use the ``read()`` method.
37+
To read parts of an Object, use the :cpp:func:`FSTR::Object::read` method.
3838

39-
If the data isn't used very often, use the ``readFlash()`` method instead as it avoids
40-
disrupting the cache. The ``Stream`` class (alias FlashMemoryStream) does this by default.
39+
If the data isn't used very often, use the :cpp:func:`FSTR::Object::readFlash` method instead as it avoids
40+
disrupting the cache. The :cpp:class:`FSTR::Stream` class (alias :cpp:class:`FlashMemoryStream`) does this by default.
4141

4242

4343
Object Internals
@@ -46,7 +46,7 @@ Object Internals
4646
This section provides some examples of how structures are created, but in normal use you
4747
should use the provided macros as they simplify the task and include structure validity checks.
4848

49-
``ObjectBase`` is a non-template
49+
:cpp:class:`FSTR::ObjectBase` is a non-template
5050
`POD <https://stackoverflow.com/questions/4178175/what-are-aggregates-and-pods-and-how-why-are-they-special/7189821>`__
5151
base class, and looks like this (methods omitted)::
5252

@@ -80,8 +80,8 @@ If you want to access it as an array, do this::
8080
References are an efficient and convenient way to access an Object, and should not consume
8181
any memory themselves as the compiler/linker resolve them to the actual object.
8282

83-
However, in practice the Espressif compiler stores a full pointer to most things and if
84-
the references aren't declared PROGMEM they'll consume RAM.
83+
However, in practice the Espressif compiler stores a full pointer to most things to support
84+
relative addressing, and if the references aren't declared PROGMEM they'll consume RAM.
8585

8686

8787
Copy behaviour
@@ -123,14 +123,16 @@ This means classes cannot have:
123123
- virtual functions
124124
- base classes (until C++17)
125125

126-
This is why ObjectBase is used for data structures.
127-
We work using an ``Object`` class template as it provides the necessary constructors::
126+
This is why :cpp:class:`FSTR::ObjectBase` is used to define data structures.
127+
128+
Classes created using the :cpp:class:`FSTR::Object` template ensures the necessary constructors
129+
are available to do this::
128130

129131
auto myCopy = flashHelloData.object.as<FSTR::String>();
130132
Serial.print("myCopy.length() = ");
131133
Serial.println(myCopy.length());
132134

133-
The macros create an appropriate Object reference for you.
135+
The macros create an appropriate Object& reference for you.
134136

135137

136138
Structure checks
@@ -150,4 +152,15 @@ Most compilers are quite relaxed about this but ``GCC 4.8.5`` is particularly th
150152
In testing, this happens with references for global Objects, which of course cannot be constexpr.
151153
To fix it, the offending Object either needs to be redefined LOCAL, or if the Object data is in
152154
scope (i.e. defined in the same source file) then you can get a direct pointer to it using
153-
the ``FSTR_PTR`` macro.
155+
the :c:func:`FSTR_PTR` macro.
156+
157+
Macros
158+
------
159+
160+
.. doxygengroup:: fstr_object
161+
:content-only:
162+
163+
Class Template
164+
--------------
165+
166+
.. doxygenclass:: FSTR::Object

src/include/FlashString/Array.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/****
22
* Array.hpp - Defines the Array class and associated macros
33
*
44
* Copyright 2019 mikee47 <[email protected]>
@@ -24,6 +24,12 @@
2424
#include "Object.hpp"
2525
#include "ArrayPrinter.hpp"
2626

27+
/**
28+
* @defgroup fstr_array Arrays
29+
* @ingroup FlashString
30+
* @{
31+
*/
32+
2733
/**
2834
* @brief Declare a global Array& reference
2935
* @param name
@@ -90,6 +96,7 @@
9096
/**
9197
* @brief Define an Array containing data from an external file
9298
* @param name Name for the object
99+
* @param ElementType
93100
* @param file Absolute path to the file containing the content
94101
*/
95102
#define IMPORT_FSTR_ARRAY(name, ElementType, file) \
@@ -100,6 +107,7 @@ namespace FSTR
100107
{
101108
/**
102109
* @brief Class to access an array of integral values stored in flash
110+
* @tparam ElementType
103111
*/
104112
template <typename ElementType> class Array : public Object<Array<ElementType>, ElementType>
105113
{
@@ -122,3 +130,5 @@ template <typename ElementType> class Array : public Object<Array<ElementType>,
122130
};
123131

124132
} // namespace FSTR
133+
134+
/** @} */

src/include/FlashString/ArrayPrinter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/****
22
* ArrayPrinter.cpp - Print support for arrays
33
*
44
* Copyright 2019 mikee47 <[email protected]>

0 commit comments

Comments
 (0)