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

Attribute of an XML element. More...

#include <tsxmlAttribute.h>

Collaboration diagram for ts::xml::Attribute:

Public Member Functions

 Attribute ()
 Default constructor.
 
 Attribute (const UString &name, const UString &value=UString(), size_t line=0)
 Full constructor.
 
const UString formattedValue (const Tweaks &tweaks) const
 Get the formatted attribute value with quotes and escaped characters.
 
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 with original case sensitivity.
 
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.
 
void setEnum (const Enumeration &definition, int value)
 Set an enumeration attribute of a node.
 
template<typename FLT , typename std::enable_if< std::is_floating_point< FLT >::value >::type * = nullptr>
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.
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void setInteger (INT value, bool hexa=false)
 Set an attribute with an integer value to a node.
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void setIntEnum (const Enumeration &definition, INT value)
 Set an enumeration attribute of 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.
 
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.
 

Static Public Attributes

static const Attribute INVALID
 A constant static invalid instance.
 

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 with original case sensitivity.
[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 with original case sensitivity.

Returns
A constant reference to the attribute name with original case sensitivity.

◆ 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 , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
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()

void ts::xml::Attribute::setEnum ( const Enumeration definition,
int  value 
)

Set an enumeration attribute of a node.

Parameters
[in]definitionThe definition of enumeration values.
[in]valueAttribute value.

◆ setIntEnum()

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void ts::xml::Attribute::setIntEnum ( const Enumeration definition,
INT  value 
)
inline

Set an enumeration attribute of a node.

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

◆ setFloat()

template<typename FLT , typename std::enable_if< std::is_floating_point< FLT >::value >::type * = nullptr>
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.

Member Data Documentation

◆ INVALID

const Attribute ts::xml::Attribute::INVALID
static

A constant static invalid instance.

Used as universal invalid attribute.


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