TSDuck v3.43-4509
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::xml::Attribute Class Reference

Attribute of an XML element. More...

#include <tsxmlAttribute.h>

Public Member Functions

 Attribute ()
 Default constructor.
 
 Attribute (const UString &name, const UString &value=UString(), size_t line=0)
 Full constructor.
 
void expandEnvironment ()
 Expand all environment variables in the attribute value.
 
const UString formattedValue (const Tweaks &tweaks) const
 Get the formatted attribute value with quotes and escaped characters.
 
bool ignoreNamespace () const
 Check if namespace is ignored by default when comparing attribute names.
 
bool isValid () const
 Check if the attribute is valid.
 
size_t lineNumber () const
 Get the line number in input document.
 
const UStringname () const
 Get the attribute name.
 
bool nameMatch (const UChar *str) const
 Check if the name of the attribute matches a given value, case-insensitive.
 
bool nameMatch (const UChar *str, bool ignore_namespace) const
 Check if the name of the attribute matches a given value, case-insensitive.
 
bool nameMatch (const UString &str) const
 Check if the name of the attribute matches a given value, case-insensitive.
 
bool nameMatch (const UString &str, bool ignore_namespace) const
 Check if the name of the attribute matches a given value, case-insensitive.
 
size_t sequence () const
 Get the update sequence number.
 
void setBool (bool value)
 Set a bool attribute to a node.
 
void setDate (const Time &value)
 Set a date (without hours) attribute of an XML element.
 
void setDateTime (const Time &value)
 Set a date/time attribute of an XML element.
 
template<typename INT >
requires ts::int_enum<INT>
void setEnum (const Names &definition, INT value)
 Set an enumeration attribute of a node.
 
template<typename FLT >
requires std::floating_point<FLT>
void setFloat (FLT value, size_t width=0, size_t precision=6, bool force_sign=false)
 Set an attribute with a floating point value to a node.
 
void setIignoreNamespace (bool ignore)
 Specify if namespace is ignored by default when comparing attribute names.
 
template<typename INT >
requires std::integral<INT>
void setInteger (INT value, bool hexa=false)
 Set an attribute with an integer value to a node.
 
void setString (const UString &value)
 Set a string attribute.
 
template<class Rep , class Period >
void setTime (const cn::duration< Rep, Period > &value)
 Set a time attribute of an XML element in "hh:mm:ss" format.
 
const UStringvalue () const
 Get the attribute value.
 

Static Public Member Functions

static bool DateFromString (Time &value, const UString &str)
 Convert a string into a date (without hours), as required in attributes.
 
static bool DateTimeFromString (Time &value, const UString &str)
 Convert a string into a date/time, as required in attributes.
 
static UString DateTimeToString (const Time &value)
 Convert a date/time into a string, as required in attributes.
 
static UString DateToString (const Time &value)
 Convert a date (without time) into a string, as required in attributes.
 
static const AttributeINVALID ()
 A constant static invalid instance.
 
template<class Rep , class Period >
static bool TimeFromString (cn::duration< Rep, Period > &value, const UString &str)
 Convert a string into a time, as required in attributes.
 
template<class Rep , class Period >
static UString TimeToString (const cn::duration< Rep, Period > &value)
 Convert a time (without date) into a string, as required in attributes.
 

Detailed Description

Attribute of an XML element.

Constructor & Destructor Documentation

◆ Attribute() [1/2]

ts::xml::Attribute::Attribute ( )

Default constructor.

The argument is initially invalid, everything will fail.

◆ Attribute() [2/2]

ts::xml::Attribute::Attribute ( const UString name,
const UString value = UString(),
size_t  line = 0 
)
explicit

Full constructor.

Parameters
[in]nameAttribute name.
[in]valueAttribute value.
[in]lineLine number in input document.

Member Function Documentation

◆ isValid()

bool ts::xml::Attribute::isValid ( ) const
inline

Check if the attribute is valid.

Returns
True if the attribute is valid.

◆ lineNumber()

size_t ts::xml::Attribute::lineNumber ( ) const
inline

Get the line number in input document.

Returns
The line number in input document, zero if the attribute was built programmatically.

◆ name()

const UString & ts::xml::Attribute::name ( ) const
inline

Get the attribute name.

Returns
A constant reference to the attribute name.

◆ nameMatch() [1/4]

bool ts::xml::Attribute::nameMatch ( const UChar str) const
inline

Check if the name of the attribute matches a given value, case-insensitive.

Parameters
[in]strThe string value to compare.
Returns
True is the name of this object matches str.

◆ nameMatch() [2/4]

bool ts::xml::Attribute::nameMatch ( const UString str) const
inline

Check if the name of the attribute matches a given value, case-insensitive.

Parameters
[in]strThe string value to compare.
Returns
True is the name of this object matches str.

◆ nameMatch() [3/4]

bool ts::xml::Attribute::nameMatch ( const UChar str,
bool  ignore_namespace 
) const

Check if the name of the attribute matches a given value, case-insensitive.

Parameters
[in]strThe string value to compare.
[in]ignore_namespaceIf true, ignore namespaces in the comparison.
Returns
True is the name of this object matches str.

◆ nameMatch() [4/4]

bool ts::xml::Attribute::nameMatch ( const UString str,
bool  ignore_namespace 
) const
inline

Check if the name of the attribute matches a given value, case-insensitive.

Parameters
[in]strThe string value to compare.
[in]ignore_namespaceIf true, ignore namespaces in the comparison.
Returns
True is the name of this object matches str.

◆ ignoreNamespace()

bool ts::xml::Attribute::ignoreNamespace ( ) const
inline

Check if namespace is ignored by default when comparing attribute names.

Returns
True if namespace is ignored by default.

◆ setIignoreNamespace()

void ts::xml::Attribute::setIignoreNamespace ( bool  ignore)
inline

Specify if namespace is ignored by default when comparing attribute names.

Parameters
[in]ignoreIt true, namespace is ignored by default.

◆ value()

const UString & ts::xml::Attribute::value ( ) const
inline

Get the attribute value.

Returns
A constant reference to the attribute value.

◆ formattedValue()

const UString ts::xml::Attribute::formattedValue ( const Tweaks tweaks) const

Get the formatted attribute value with quotes and escaped characters.

Parameters
[in]tweaksFormatting tweaks.
Returns
The formatted value of the attribute.

◆ sequence()

size_t ts::xml::Attribute::sequence ( ) const
inline

Get the update sequence number.

Each time an attribute is updated, a global (non-thread-safe) index is incremented. The method returns the value of the global index the last time the attribute was modified. This is a way to rebuild the list of attributes in their order of modification.

Returns
The update sequence number.

◆ setString()

void ts::xml::Attribute::setString ( const UString value)

Set a string attribute.

Parameters
[in]valueAttribute value.

◆ setBool()

void ts::xml::Attribute::setBool ( bool  value)

Set a bool attribute to a node.

Parameters
[in]valueAttribute value.

◆ setInteger()

template<typename INT >
requires std::integral<INT>
void ts::xml::Attribute::setInteger ( INT  value,
bool  hexa = false 
)
inline

Set an attribute with an integer value to a node.

Template Parameters
INTAn integer type.
Parameters
[in]valueAttribute value.
[in]hexaIf true, use an hexadecimal representation. When decimal is used, a comma is used as thousands separator. When hexadecimal is used, a 0x prefix is added.

◆ setEnum()

template<typename INT >
requires ts::int_enum<INT>
void ts::xml::Attribute::setEnum ( const Names definition,
INT  value 
)
inline

Set an enumeration attribute of a node.

Template Parameters
INTAn integer or enum type.
Parameters
[in]definitionThe definition of enumeration values.
[in]valueAttribute value.

◆ setFloat()

template<typename FLT >
requires std::floating_point<FLT>
void ts::xml::Attribute::setFloat ( FLT  value,
size_t  width = 0,
size_t  precision = 6,
bool  force_sign = false 
)
inline

Set an attribute with a floating point value to a node.

Template Parameters
FLTa floating point type.
Parameters
[in]valueAttribute value.
[in]widthWidth of the formatted number, not including the optional prefix and separator.
[in]precisionPrecision to use after the decimal point. Default is 6 digits.
[in]force_signIf true, force a '+' sign for positive values.

◆ setDateTime()

void ts::xml::Attribute::setDateTime ( const Time value)

Set a date/time attribute of an XML element.

Parameters
[in]valueAttribute value.

◆ setDate()

void ts::xml::Attribute::setDate ( const Time value)

Set a date (without hours) attribute of an XML element.

Parameters
[in]valueAttribute value.

◆ setTime()

template<class Rep , class Period >
void ts::xml::Attribute::setTime ( const cn::duration< Rep, Period > &  value)
inline

Set a time attribute of an XML element in "hh:mm:ss" format.

Parameters
[in]valueAttribute value.

◆ DateTimeToString()

static UString ts::xml::Attribute::DateTimeToString ( const Time value)
static

Convert a date/time into a string, as required in attributes.

Parameters
[in]valueTime value.
Returns
The corresponding string.

◆ DateToString()

static UString ts::xml::Attribute::DateToString ( const Time value)
static

Convert a date (without time) into a string, as required in attributes.

Parameters
[in]valueTime value.
Returns
The corresponding string.

◆ TimeToString()

template<class Rep , class Period >
static UString ts::xml::Attribute::TimeToString ( const cn::duration< Rep, Period > &  value)
static

Convert a time (without date) into a string, as required in attributes.

Parameters
[in]valueTime value.
Returns
The corresponding string.

◆ DateTimeFromString()

static bool ts::xml::Attribute::DateTimeFromString ( Time value,
const UString str 
)
static

Convert a string into a date/time, as required in attributes.

Parameters
[in,out]valueTime value. Unmodified in case of error.
[in]strTime value as a string.
Returns
True on success, false on error.

◆ DateFromString()

static bool ts::xml::Attribute::DateFromString ( Time value,
const UString str 
)
static

Convert a string into a date (without hours), as required in attributes.

Parameters
[in,out]valueDate value. Unmodified in case of error.
[in]strDate value as a string.
Returns
True on success, false on error.

◆ TimeFromString()

template<class Rep , class Period >
bool ts::xml::Attribute::TimeFromString ( cn::duration< Rep, Period > &  value,
const UString str 
)
static

Convert a string into a time, as required in attributes.

Parameters
[in,out]valueTime value. Unmodified in case of error.
[in]strTime value as a string.
Returns
True on success, false on error.

◆ expandEnvironment()

void ts::xml::Attribute::expandEnvironment ( )

Expand all environment variables in the attribute value.

Environment variables are referenced using '${varname}' in text, attributes, names.

◆ INVALID()

static const Attribute & ts::xml::Attribute::INVALID ( )
static

A constant static invalid instance.

Used as universal invalid attribute.

Returns
A constant reference to the universal invalid attribute.

The documentation for this class was generated from the following file: