18 #include "../Format.h" 36 #define SECTION_TEMPLATE_COMMAND_MAP(XX) \ 37 XX(Qas_int, "{!int:A} Output A as integer") \ 38 XX(Qas_float, "{!float:A} Output A as float") \ 39 XX(Qas_string, "{!string:A} Output A as quoted string") \ 40 XX(Qmime_type, "{!mime_type:A} Get MIME type string for a filename") \ 41 XX(Qreplace, "{!replace:A:B:C} Copy of A with all occurrences of B replaced with C") \ 42 XX(Qlength, "{!length:A} Number of characters in A") \ 44 "{!pad:A:B:C} Copy of A padded to at least B characters with C (default is space). Use -ve B to left-pad. C") \ 45 XX(Qrepeat, "{!repeat:A:B} Repeat A, number of iterations is B") \ 46 XX(Qkb, "{!kb:A} Convert A to KB") \ 47 XX(Qifdef, "{!ifdef:A} emit block if A is not zero-length") \ 48 XX(Qifndef, "{!ifdef:A} emit block if A is zero-length") \ 49 XX(Qifeq, "{!ifeq:A:B} emit block if A == B") \ 50 XX(Qifneq, "{!ifneq:A:B} emit block if A != B") \ 51 XX(Qifgt, "{!ifgt:A:B} emit block if A > B") \ 52 XX(Qiflt, "{!iflt:A:B} emit block if A < B") \ 53 XX(Qifge, "{!ifge:A:B} emit block if A >= B") \ 54 XX(Qifle, "{!ifle:A:B} emit block if A <= B") \ 55 XX(Qifbtw, "{!ifbtw:A:B:C} emit block if B <= A <= C") \ 56 XX(Qifin, "{!ifin:A:B} emit block if A contains B") \ 57 XX(Qifnin, "{!ifin:A:B} emit block if A does not contain B") \ 58 XX(Qelse, "{!else}") \ 59 XX(Qendif, "{!endif}") \ 60 XX(Qadd, "{!add:A:B} A + B") \ 61 XX(Qsub, "{!sub:A:B} A - B") \ 62 XX(Qgoto, "{!goto:A} move to section A") \ 63 XX(Qcount, "{!count:A} emit number of records in section A") \ 64 XX(Qindex, "{!index:A} emit current record index for section A") 66 #define SECTION_TEMPLATE_FIELD_MAP(XX) \ 67 XX(section, "{$section} Current section index") \ 68 XX(record, "{$record} Current record index") 78 #define XX(name, comment) name, 85 #define XX(name, comment) name, 110 getValueCallback = callback;
128 return *activeFormatter;
137 return activeFormatter->mimeType();
149 return sectionStream;
158 return sectionStream.sectionIndex();
167 return sectionStream.count();
176 return sectionStream.recordIndex();
193 nextRecordCallback = callback;
206 if(nextRecordCallback) {
207 return nextRecordCallback();
215 String openTag(
bool enable);
225 int8_t newSection{-1};
void onNextRecord(NextRecord callback)
Set a callback to be invoked when a new record is required.
Definition: SectionTemplate.h:191
int recordIndex() const
Get current record index.
Definition: SectionTemplate.h:174
String getValue(const char *name) override
Fetch a templated value.
Command
Definition: SectionTemplate.h:76
bool gotoSection(uint8_t index)
Discard current output and change current section.
Base class for read-only stream.
Definition: DataSourceStream.h:45
#define SECTION_TEMPLATE_FIELD_MAP(XX)
Definition: SectionTemplate.h:66
void onGetValue(GetValue callback)
Set a callback to be invoked.
Definition: SectionTemplate.h:108
void setFormatter(Formatter &formatter)
Associate a text format with this template stream.
Definition: SectionTemplate.h:117
MimeType
Definition: WebConstants.h:53
Delegate< bool()> NextRecord
Application callback to move to next record.
Definition: SectionStream.h:49
The String class.
Definition: WString.h:136
#define SECTION_TEMPLATE_COMMAND_MAP(XX)
Command map.
Definition: SectionTemplate.h:36
Field
Definition: SectionTemplate.h:83
virtual bool nextRecord()
Move to next record.
Definition: SectionTemplate.h:204
Stream which performs variable-value substitution on-the-fly.
Definition: TemplateStream.h:41
uint8_t sectionCount() const
Get number of sections in source stream.
Definition: SectionTemplate.h:165
MimeType getMimeType() const override
Get the MIME type associated with this template stream.
Definition: SectionTemplate.h:135
SectionTemplate(IDataSourceStream *source, uint8_t maxSections=5)
Provides enhanced template tag processing for use with a SectionStream.
Definition: SectionTemplate.h:73
Presents each section within a source stream as a separate stream.
Definition: SectionStream.h:25
int sectionIndex() const
Get the index for the current section.
Definition: SectionTemplate.h:156
const SectionStream & stream() const
Access the underlying section stream.
Definition: SectionTemplate.h:147
Formatter & formatter() const
Get the stream format.
Definition: SectionTemplate.h:126
String evaluate(char *&expr) override
Evaluate a template expression.