@@ -59,30 +59,35 @@ base class, and looks like this (methods omitted)::
59
59
60
60
``flashLength_ `` must not be accessed directly; use the ``length() `` method instead.
61
61
62
- Data structures are created like this::
62
+ Data structures are created using, for example, ``DEFINE_FSTR(helloData, "hello") ``.
63
+ This generates the following layout::
63
64
64
65
constexpr const struct {
65
- ObjectBase object;
66
+ FSTR::String object;
66
67
char data[8];
67
- } flashHelloData PROGMEM = {
68
+ } __fstr__helloData PROGMEM = {
68
69
{5},
69
70
"hello"
70
71
};
72
+ const FSTR::String& helloData PROGMEM = __fstr__helloData.object;
71
73
72
- The `` object `` field may then be cast to a reference of the required type, like this ::
74
+ .. note ::
73
75
74
- auto& str = flashHelloData.object.as<FSTR::String>();
76
+ The ``__fstr__ `` prefix ensures that these structures are stored in flash memory on the esp8266.
77
+ When templates are involved the ``PROGMEM `` segment attribute gets discarded.
75
78
76
- If you want to access it as an array, do this::
77
-
78
- auto& arr = str.as<FSTR::Array<char>>();
79
+ Do not access ``__fstr__helloData `` directly, it may change in future library versions.
79
80
80
81
References are an efficient and convenient way to access an Object, and should not consume
81
- any memory themselves as the compiler/linker resolve them to the actual object.
82
+ any memory themselves as the compiler/linker resolves them to the actual object.
82
83
83
84
However, in practice the Espressif compiler stores a full pointer to most things to support
84
85
relative addressing, and if the references aren't declared PROGMEM they'll consume RAM.
85
86
87
+ Objects may be cast to a reference of another required type, like this::
88
+
89
+ auto& arr = helloData.as<FSTR::Array<char>>();
90
+
86
91
87
92
Copy behaviour
88
93
--------------
@@ -105,16 +110,7 @@ This means classes cannot have:
105
110
- virtual functions
106
111
- base classes (until C++17)
107
112
108
- This is why :cpp:class: `FSTR::ObjectBase ` is used to define data structures.
109
-
110
- Classes created using the :cpp:class: `FSTR::Object ` template ensures the necessary constructors
111
- are available to do this::
112
-
113
- auto myCopy = flashHelloData.object.as<FSTR::String>();
114
- Serial.print("myCopy.length() = ");
115
- Serial.println(myCopy.length());
116
-
117
- The macros create an appropriate Object& reference for you.
113
+ This is why objects have no constructors or assignment operators.
118
114
119
115
120
116
Structure checks
@@ -129,12 +125,10 @@ You may encounter one of the following errors during compilation:
129
125
- FSTR structure not POD
130
126
131
127
This generally means one or more of the arguments in the initialisation data is not ``constexpr ``.
132
- Most compilers are quite relaxed about this but ``GCC 4.8.5 `` is particularly thick.
133
128
134
129
In testing, this happens with references for global Objects, which of course cannot be constexpr.
135
- To fix it, the offending Object either needs to be redefined LOCAL, or if the Object data is in
136
- scope (i.e. defined in the same source file) then you can get a direct pointer to it using
137
- the :c:func: `FSTR_PTR ` macro.
130
+ To fix it, the offending Object needs to be redefined LOCAL.
131
+
138
132
139
133
Macros
140
134
------
0 commit comments