OpenMS
Loading...
Searching...
No Matches
XMLAttributes Class Reference

Non-owning attribute view for an XML start-element callback. More...

#include <OpenMS/FORMAT/HANDLERS/XMLAttributes.h>

Classes

class  NativeStore
 Reusable UTF-8 attribute storage of an XML parser adapter. More...
 

Public Types

using Values = std::vector< std::pair< std::u16string, std::u16string > >
 

Public Member Functions

 XMLAttributes (const Values &attributes) noexcept
 
 XMLAttributes (const NativeStore &attributes) noexcept
 
 XMLAttributes (Values &&)=delete
 
 XMLAttributes (const Values &&)=delete
 
 XMLAttributes (NativeStore &&)=delete
 
 XMLAttributes (const NativeStore &&)=delete
 
Size size () const noexcept
 Number of attributes.
 
const char16_t * value (const char16_t *qname) const
 UTF-16 value by name, or nullptr if absent.
 
const char16_t * value (const char *qname) const
 UTF-16 value by UTF-8 name, or nullptr if absent.
 
SignedSize index (const char16_t *qname) const
 Index by UTF-16 name, or a negative value if absent.
 
const char16_t * valueByIndex (Size i) const
 UTF-16 value by index, or nullptr if out of range.
 
bool valueUTF8 (const char16_t *qname, std::string &value) const
 Assigns the UTF-8 value of the attribute named qname to value. Returns false (leaving value untouched) if absent.
 
bool valueUTF8 (const char *qname, std::string &value) const
 Assigns the UTF-8 value of the attribute with UTF-8 name qname to value. Returns false (leaving value untouched) if absent.
 

Private Member Functions

SignedSize indexUTF8_ (const char *qname) const
 Index by UTF-8 name, or a negative value if absent.
 
void valueUTF8ByIndex_ (Size i, std::string &value) const
 UTF-8 value at index i (which must be valid)
 

Private Attributes

const Values * attributes_ = nullptr
 
const NativeStore * native_ = nullptr
 

Detailed Description

Non-owning attribute view for an XML start-element callback.

The view refers either to UTF-16 name/value pairs or to a parser-owned NativeStore of UTF-8 slices. The latter converts a value to UTF-16 only when it is requested through value() or valueByIndex(); valueUTF8() copies it without conversion. This view and the pointers it returns must not outlive the callback that receives them.

Member Typedef Documentation

◆ Values

using Values = std::vector<std::pair<std::u16string, std::u16string> >

Constructor & Destructor Documentation

◆ XMLAttributes() [1/6]

XMLAttributes ( const Values &  attributes)
inlineexplicitnoexcept

◆ XMLAttributes() [2/6]

XMLAttributes ( const NativeStore &  attributes)
inlineexplicitnoexcept

◆ XMLAttributes() [3/6]

XMLAttributes ( Values &&  )
delete

◆ XMLAttributes() [4/6]

XMLAttributes ( const Values &&  )
delete

◆ XMLAttributes() [5/6]

XMLAttributes ( NativeStore &&  )
delete

◆ XMLAttributes() [6/6]

XMLAttributes ( const NativeStore &&  )
delete

Member Function Documentation

◆ index()

SignedSize index ( const char16_t *  qname) const

Index by UTF-16 name, or a negative value if absent.

◆ indexUTF8_()

SignedSize indexUTF8_ ( const char *  qname) const
private

Index by UTF-8 name, or a negative value if absent.

◆ size()

Size size ( ) const
noexcept

Number of attributes.

◆ value() [1/2]

const char16_t * value ( const char *  qname) const

UTF-16 value by UTF-8 name, or nullptr if absent.

◆ value() [2/2]

◆ valueByIndex()

const char16_t * valueByIndex ( Size  i) const

UTF-16 value by index, or nullptr if out of range.

◆ valueUTF8() [1/2]

bool valueUTF8 ( const char *  qname,
std::string &  value 
) const

Assigns the UTF-8 value of the attribute with UTF-8 name qname to value. Returns false (leaving value untouched) if absent.

◆ valueUTF8() [2/2]

◆ valueUTF8ByIndex_()

void valueUTF8ByIndex_ ( Size  i,
std::string &  value 
) const
private

UTF-8 value at index i (which must be valid)

Member Data Documentation

◆ attributes_

const Values* attributes_ = nullptr
private

◆ native_

const NativeStore* native_ = nullptr
private