35#ifndef _OPENLCB_CONFIGRENDERER_HXX_
36#define _OPENLCB_CONFIGRENDERER_HXX_
59 Hints, SkipInit, Offset>;
86 void render_cdi(std::string *r)
const
90 *r += StringPrintf(
"<name>%s</name>\n", name());
95 StringPrintf(
"<description>%s</description>\n", description());
99 *r += StringPrintf(
"<map>%s</map>\n", mapvalues());
103 *r += StringPrintf(
"<hints>%s</hints>\n", hints());
114 SKIP_SIZE = 0xffffffff,
125 template <
typename... Args>
void render_cdi(
string *s, Args... args)
const
127 *s += StringPrintf(
"<%s",
tag_);
128 if (
size_ != SKIP_SIZE)
130 *s += StringPrintf(
" size=\'%u\'",
size_);
135 *s += StringPrintf(
" offset=\'%d\'", ofs);
139 *s += StringPrintf(
"</%s>\n",
tag_);
153 using AtomConfigDefs::check_arguments_are_valid;
158 Hints, Min, Max, Default, SkipInit, Offset>;
183 void render_cdi(std::string *r)
const
187 *r += StringPrintf(
"<name>%s</name>\n", name());
192 StringPrintf(
"<description>%s</description>\n", description());
196 *r += StringPrintf(
"<hints>%s</hints>\n", hints());
198 if (minvalue() != INT_MAX)
200 *r += StringPrintf(
"<min>%d</min>\n", minvalue());
202 if (maxvalue() != INT_MAX)
204 *r += StringPrintf(
"<max>%d</max>\n", maxvalue());
206 if (defaultvalue() != INT_MAX)
208 *r += StringPrintf(
"<default>%d</default>\n", defaultvalue());
212 *r += StringPrintf(
"<map>%s</map>\n", mapvalues());
216 int clip(
int value) {
217 if (has_minvalue() && (value < minvalue())) {
220 if (has_maxvalue() && (value > maxvalue())) {
233 SKIP_SIZE = 0xffffffff,
244 template <
typename... Args>
void render_cdi(
string *s, Args... args)
const
246 *s += StringPrintf(
"<%s",
tag_);
247 if (
size_ != SKIP_SIZE)
249 *s += StringPrintf(
" size=\'%u\'",
size_);
254 *s += StringPrintf(
" offset=\'%d\'", ofs);
258 *s += StringPrintf(
"</%s>\n",
tag_);
274 using AtomConfigDefs::check_arguments_are_valid;
283 Hints, LinkRef, LinkText, Offset, RepName,
352 return segment() == -2;
360 return segment() >= 0;
369 return offset() == INT_MAX ? 0 : offset();
372 void render_cdi(std::string *r)
const
376 *r += StringPrintf(
"<name>%s</name>\n", name());
381 StringPrintf(
"<description>%s</description>\n", description());
385 *r += StringPrintf(
"<hints>%s</hints>\n", hints());
390 StringPrintf(
"<repname>%s</repname>\n", repname());
395 StringPrintf(
"<link ref=\"%s\">%s</link>\n", linkref(),
396 has_linktext() ? linktext() : linkref());
407 SKIP_SIZE = 0xffffffff,
417 template <
typename... Args>
void render_cdi(
string *s, Args... args)
const
419 *s += StringPrintf(
"<group offset='%d'/>\n",
size_);
441 template <
typename... Args>
void render_cdi(
string *s, Args... args)
453 const char *tag =
nullptr;
457 *s +=
"?xml version=\"1.0\" encoding=\"utf-8\"?>\n<";
460 *s +=
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
461 "xsi:noNamespaceSchemaLocation=\"http://openlcb.org/schema/"
464 HASSERT(opts.name() ==
nullptr && opts.description() ==
nullptr);
466 else if (opts.segment() == -1)
475 int ofs = opts.offset();
478 *s += StringPrintf(
" offset=\'%d\'", ofs);
486 *s += StringPrintf(
" space='%d'", opts.segment());
495 body_.render_content_cdi(s);
496 if (opts.fixed_size() && (
body_.end_buffer_length() > 0)) {
498 "<group offset='%u'/>\n",
body_.end_buffer_length());
500 *s += StringPrintf(
"</%s>\n", tag);
526 HwVersion, SwVersion, LinkRef, LinkText>;
544 constexpr int skip_init()
const
549 constexpr int offset()
const
565 static void render_tag(
const char *tag,
const char *value,
string *s)
567 *s += StringPrintf(
"<%s>%s</%s>\n", tag, value, tag);
570 static const char *alt(
const char *opt,
const char *def)
577 template <
typename... Args>
void render_cdi(
string *s, Args... args)
const
581 *s +=
"<identification>\n";
582 render_tag(
"manufacturer",
585 render_tag(
"hardwareVersion",
587 render_tag(
"softwareVersion",
592 StringPrintf(
"<link ref=\"%s\">%s</link>\n", opts.linkref(),
593 alt(opts.linktext(), opts.linkref()));
595 *s +=
"</identification>\n";
609 void render_cdi(
string *s)
const
611 s->append(
"<acdi/>\n");
#define DEFINE_OPTIONALARG(SpecName, function_name, DataType)
Use this macro in the final optionalargs structure.
#define DECLARE_OPTIONALARG(SpecName, function_name, DataType, N, DEF)
Use this macro in the Defs structure of an optional args instance to add an optional argument.
Declares that a recursive class template is coming.
Helper class for rendering the "<acdi>" tag.
Configuration implementation class for CDI Atom elements (strings, events and numbers).
DEFINE_OPTIONALARG(Name, name, const char *)
Represent the value enclosed in the "<name>" tag of the data element.
DEFINE_OPTIONALARG(MapValues, mapvalues, const char *)
Represent the value enclosed in the "<map>" tag of the data element.
DEFINE_OPTIONALARG(SkipInit, skip_init, int)
When set to true, the event initializers will be skipped in this event or group.
DEFINE_OPTIONALARG(Hints, hints, const char *)
Represent the value enclosed in the "<hints>" tag of the data element.
DEFINE_OPTIONALARG(Offset, offset, int)
Represents the 'offset' attribute for groups and elements and the 'origin' attribute for segments.
DEFINE_OPTIONALARG(Description, description, const char *)
Represent the value enclosed in the "<description>" tag of the data element.
Helper class for rendering an atom data element into the cdi.xml.
const char * tag_
XML tag for this atom.
unsigned size_
The size attribute of the configuration atom.
Helper class for rendering an empty group of a given size into the cdi.xml.
int size_
The number of bytes this group has to skip.
Implementation class for the condifuration options of a CDI group element.
DEFINE_OPTIONALARG(Hidden, hidden, int)
If non-zero, the group contents will not be rendered in the CDI, effectively hiding hte settings from...
DEFINE_OPTIONALARG(Hints, hints, const char *)
Represent the value enclosed in the <hints> tag of the data element.
DEFINE_OPTIONALARG(LinkRef, linkref, const char *)
Represent the <link ref=..>> value.
constexpr bool is_segment() const
constexpr unsigned get_segment_offset() const
constexpr bool is_cdi() const
DEFINE_OPTIONALARG(Description, description, const char *)
Represent the value enclosed in the tag of the data element.
DEFINE_OPTIONALARG(LinkText, linktext, const char *)
Represent the value enclosed in the <link> tag of the data element.
DEFINE_OPTIONALARG(FixedSize, fixed_size, int)
Specifies that the size of this group should be fixed to this many bytes, even if the contents are sm...
DEFINE_OPTIONALARG(Offset, offset, int)
Represents the 'offset' attribute for groups and the 'origin' attribute for segments.
DEFINE_OPTIONALARG(RepName, repname, const char *)
Specifies for the UI what the repetitions of this group should be called.
DEFINE_OPTIONALARG(Segment, segment, int)
Declares that the group is a segment (and thus may be used in the toplevel CDI.
constexpr int skip_init() const
Declares that this group is a toplevel CDI.
Helper class for rendering the cdi.xml of groups, segments and the toplevel CDI node.
unsigned replication_
For regular groups, the count of replicas.
Body body_
Object representing the contents of this group.
Configuration implementation options for rendering CDI (identification) data elements.
Helper class for rendering the "<identification>" tag.
Definitions for the options for numeric CDI entries.
DEFINE_OPTIONALARG(Description, description, const char *)
Represent the value enclosed in the tag of the data element.
DEFINE_OPTIONALARG(Hints, hints, const char *)
Represent the value enclosed in the <hints> tag of the data element.
DEFINE_OPTIONALARG(MapValues, mapvalues, const char *)
Represent the value enclosed in the <map> tag of the data element.
DEFINE_OPTIONALARG(Name, name, const char *)
Represent the value enclosed in the "<name>" tag of the data element.
Helper class for rendering a numeric data element into the cdi.xml.
unsigned size_
The size attribute of the configuration atom.
const char * tag_
XML tag for this atom.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define INHERIT_CONSTEXPR_CONSTRUCTOR(CURRENT_CLASS, BASE_CLASS)
Adds a constexpr constructor to the current class that proxies every argument to the base constructor...
const SimpleNodeStaticValues SNIP_STATIC_DATA
This static data will be exported as the first block of SNIP.
Configuration options for rendering CDI (atom) data elements.
Configuration options for the CDI group element, as well as representing and distinguishing alternate...
Configuration options for rendering CDI (identification) data elements.
Declarations for the options for numeric CDI entries.
Structure representing the layout of the memory space for Simple Node Identification manufacturer-spe...