NCBI C++ ToolKit
Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
xml::attributes Class Reference

Search Toolkit Book for xml::attributes

The xml::attributes class is used to access all the attributes of one xml::node. More...

#include <misc/xmlwrapp/attributes.hpp>

+ Collaboration diagram for xml::attributes:

Classes

class  attr
 The xml::attributes::attr class is used to hold information about one attribute. More...
 
class  const_iterator
 Const Iterator class for accessing attribute pairs. More...
 
class  iterator
 Iterator class for accessing attribute pairs. More...
 
struct  pimpl
 

Public Types

typedef std::size_t size_type
 size type More...
 

Public Member Functions

 attributes (void)
 Create a new xml::attributes object with no attributes. More...
 
 attributes (const attributes &other)
 Copy construct a xml::attributes object. More...
 
attributesoperator= (const attributes &other)
 Copy the given xml::attributes object into this one. More...
 
 attributes (attributes &&other)
 Moving constructor. More...
 
attributesoperator= (attributes &&other)
 Moving assignment. More...
 
void swap (attributes &other)
 Swap this xml::attributes object with another one. More...
 
virtual ~attributes (void)
 Clean up after a xml::attributes object. More...
 
iterator begin (void)
 Get an iterator that points to the first attribute. More...
 
const_iterator begin (void) const
 Get a const_iterator that points to the first attribute. More...
 
iterator end (void)
 Get an iterator that points one past the the last attribute. More...
 
const_iterator end (void) const
 Get a const_iterator that points one past the last attribute. More...
 
void insert (const char *name, const char *value, const ns *nspace=NULL)
 Add an attribute to the attributes list. More...
 
iterator find (const char *name, const ns *nspace=NULL)
 Find the attribute with the given name and namespace. More...
 
const_iterator find (const char *name, const ns *nspace=NULL) const
 Find the attribute with the given name and namespace. More...
 
iterator erase (iterator to_erase)
 Erase the attribute that is pointed to by the given iterator. More...
 
size_type erase (const char *name, const ns *nspace=NULL)
 Erase the attribute with the given name. More...
 
bool empty (void) const
 Find out if there are any attributes in this xml::attributes object. More...
 
size_type size (void) const
 Find out how many attributes there are in this xml::attributes object. More...
 
void sort (void)
 Sorts the attributes in place. More...
 

Private Member Functions

 attributes (int)
 
void set_data (void *node)
 
void * get_data (void)
 

Static Private Member Functions

static xml::ns createUnsafeNamespace (void *libxml2RawNamespace)
 
static void * getUnsafeNamespacePointer (const xml::ns &name_space)
 

Private Attributes

pimplpimpl_
 

Friends

struct impl::node_impl
 
class node
 

Detailed Description

The xml::attributes class is used to access all the attributes of one xml::node.

You can add, find and erase attributes by name, and for some member functions, use the provided iterator classes.

The iterator classes allow you to access one XML attribute. This is done using the xml::attributes::attr class interface.

Definition at line 78 of file attributes.hpp.

Member Typedef Documentation

◆ size_type

typedef std::size_t xml::attributes::size_type

size type

Definition at line 80 of file attributes.hpp.

Constructor & Destructor Documentation

◆ attributes() [1/4]

xml::attributes::attributes ( void  )

Create a new xml::attributes object with no attributes.

Author
Peter Jones

Definition at line 97 of file attributes.cpp.

◆ attributes() [2/4]

xml::attributes::attributes ( const attributes other)

Copy construct a xml::attributes object.

Parameters
otherThe xml::attributes object to copy from.
Author
Peter Jones

Definition at line 105 of file attributes.cpp.

References pimpl_.

◆ attributes() [3/4]

xml::attributes::attributes ( attributes &&  other)

Moving constructor.

Parameters
otherThe other attributes.

Definition at line 124 of file attributes.cpp.

References NULL.

◆ ~attributes()

xml::attributes::~attributes ( void  )
virtual

Clean up after a xml::attributes object.

Author
Peter Jones

Definition at line 119 of file attributes.cpp.

References NULL.

◆ attributes() [4/4]

xml::attributes::attributes ( int  )
explicitprivate

Definition at line 101 of file attributes.cpp.

Member Function Documentation

◆ begin() [1/2]

xml::attributes::iterator xml::attributes::begin ( void  )

Get an iterator that points to the first attribute.

Returns
An iterator that points to the first attribute.
An iterator equal to end() if there are no attributes.
See also
xml::attributes::iterator
xml::attributes::attr
Author
Peter Jones

Definition at line 160 of file attributes.cpp.

Referenced by GetBioSampleStatusFromNode(), and ProcessBiosampleStatusNode().

◆ begin() [2/2]

xml::attributes::const_iterator xml::attributes::begin ( void  ) const

Get a const_iterator that points to the first attribute.

Returns
A const_iterator that points to the first attribute.
A const_iterator equal to end() if there are no attributes.
See also
xml::attributes::const_iterator
xml::attributes::attr
Author
Peter Jones

Definition at line 167 of file attributes.cpp.

◆ createUnsafeNamespace()

xml::ns xml::attributes::createUnsafeNamespace ( void *  libxml2RawNamespace)
staticprivate

◆ empty()

bool xml::attributes::empty ( void  ) const

Find out if there are any attributes in this xml::attributes object.

Returns
True if there are no attributes.
False if there is at least one attribute.
Author
Peter Jones

Definition at line 413 of file attributes.cpp.

◆ end() [1/2]

xml::attributes::iterator xml::attributes::end ( void  )

Get an iterator that points one past the the last attribute.

Returns
An "end" iterator.
Author
Peter Jones

Definition at line 174 of file attributes.cpp.

References NULL.

Referenced by GetBioSampleStatusFromNode(), CEntrezDB::GetUidAttr(), and ProcessBiosampleStatusNode().

◆ end() [2/2]

xml::attributes::const_iterator xml::attributes::end ( void  ) const

Get a const_iterator that points one past the last attribute.

Returns
An "end" const_iterator.
Author
Peter Jones

Definition at line 181 of file attributes.cpp.

References NULL.

◆ erase() [1/2]

xml::attributes::size_type xml::attributes::erase ( const char *  name,
const ns nspace = NULL 
)

Erase the attribute with the given name.

This will invalidate any iterators that are pointing to that attribute, as well as any pointers or references to that attribute.

This function does not throw any exceptions.

Parameters
nameThe name of the attribute to erase. The name may be qualified. If it is qualified then the namespace parameter must be NULL.
nspaceThe namespace of the atrribute to erase:
  • NULL matches any namespace
  • Void namespace matches attributes without a namespace set
  • Unsafe namespace is used as it is
  • A safe namespace is resolved basing on the uri only
Returns
The number of erased attributes.
Author
Peter Jones, Sergey Satskiy

Definition at line 336 of file attributes.cpp.

References column, count, xml::impl::find_prop(), xml::ns::get_uri(), xml::ns::is_safe(), xml::ns::is_void(), NULL, string, and xml::ns::unsafe_ns_.

◆ erase() [2/2]

xml::attributes::iterator xml::attributes::erase ( iterator  to_erase)

Erase the attribute that is pointed to by the given iterator.

This will invalidate any iterators for this attribute, as well as any pointers or references to it.

Parameters
to_eraseAn iterator that points to the attribute to erased.
Returns
An iterator that points to the attribute after the one to be erased.
See also
xml::attributes::iterator
xml::attributes::attr
Author
Peter Jones

Definition at line 314 of file attributes.cpp.

References xml::impl::ait_impl::get(), xml::attributes::attr::is_default(), next(), xml::attributes::iterator::pimpl_, xml::attributes::attr::prop_, and xml::attributes::attr::xmlnode_.

◆ find() [1/2]

xml::attributes::iterator xml::attributes::find ( const char *  name,
const ns nspace = NULL 
)

Find the attribute with the given name and namespace.

If the attribute is not found on the current node, the DTD will be searched for a default value. This is, of course, if there was a DTD parsed with the XML document. If the search comes to DTD and the namespace is provided then the only namespace prefix is taken into account.

Parameters
nameThe name of the attribute to find. The name could be given as a qualified name, e.g. 'prefix:attr_name'. If the name is qualified then the nspace argument must be NULL (otherwise an exception is generated) and the attribute search is namespace aware with an effective namespace identified by the given prefix.
nspaceThe namespace of the atrribute to find:
  • NULL matches any namespace
  • Void namespace matches attributes without a namespace set
  • Unsafe namespace is used as it is
  • A safe namespace is resolved basing on the uri only
Returns
An iterator that points to the attribute with the given name.
If the attribute was not found, find will return end().
See also
xml::attributes::iterator
xml::attributes::attr
Author
Peter Jones; Sergey Satskiy, NCBI

Definition at line 288 of file attributes.cpp.

References xml::impl::find_default_prop(), xml::impl::find_prop(), and NULL.

◆ find() [2/2]

xml::attributes::const_iterator xml::attributes::find ( const char *  name,
const ns nspace = NULL 
) const

Find the attribute with the given name and namespace.

If the attribute is not found on the current node, the DTD will be searched for a default value. This is, of course, if there was a DTD parsed with the XML document. If the search comes to DTD and the namespace is provided then the only namespace prefix is taken into account.

Parameters
nameThe name of the attribute to find. The name could be given as a qualified name, e.g. 'prefix:attr_name'. If the name is qualified then the nspace argument must be NULL (otherwise an exception is generated) and the attribute search is namespace aware with an effective namespace identified by the given prefix.
nspaceThe namespace of the atrribute to find:
  • NULL matches any namespace
  • Void namespace matches attributes without a namespace set
  • Unsafe namespace is used as it is
  • A safe namespace is resolved basing on the uri only
Returns
A const_iterator that points to the attribute with the given name.
If the attribute was not found, find will return end().
See also
xml::attributes::const_iterator
xml::attributes::attr
Author
Peter Jones; Sergey Satskiy, NCBI

Definition at line 301 of file attributes.cpp.

References xml::impl::find_default_prop(), xml::impl::find_prop(), and NULL.

◆ get_data()

void * xml::attributes::get_data ( void  )
private

Definition at line 140 of file attributes.cpp.

◆ getUnsafeNamespacePointer()

void * xml::attributes::getUnsafeNamespacePointer ( const xml::ns name_space)
staticprivate

Definition at line 148 of file attributes.cpp.

References xml::ns::unsafe_ns_.

Referenced by xml::attributes::attr::set_namespace().

◆ insert()

void xml::attributes::insert ( const char *  name,
const char *  value,
const ns nspace = NULL 
)

Add an attribute to the attributes list.

If there is another attribute with the same name, it will be replaced with this one.

Parameters
nameThe name of the attribute to add. The name could be qualified. If it is qualified then the namespace parameter must be NULL.
valueThe value of the attribute to add.
nspaceThe namespace of the atrribute to insert:
  • NULL or void namespace insert an attribute without a namespace.
  • default namespace causes an exception because attributes may not have default namespace.
  • Unsafe namespace is used as it is.
  • A safe namespace is resolved basing on the uri only
Exceptions
Throwsexceptions in case of problems.
Author
Peter Jones, Sergey Satskiy

Definition at line 188 of file attributes.cpp.

References column, xml::ns::get_prefix(), xml::ns::get_uri(), xml::ns::is_safe(), xml::ns::is_void(), kInsertError, NULL, string, xml::ns::unsafe_ns_, and rapidjson::value.

Referenced by CTabDelimitedValidator::_ReportXML(), AddContact(), AddStructuredCommentToAttributes(), xml::node::convert_to_nset(), PrintBioseqXML(), CFormatGuessApp::Run(), s_AddSamplePair(), CGapStatsApplication::x_PrintHistogram(), CGapStatsApplication::x_PrintSeqsForGapLengths(), and CGapStatsApplication::x_PrintSummaryView().

◆ operator=() [1/2]

xml::attributes & xml::attributes::operator= ( attributes &&  other)

Moving assignment.

Parameters
otherThe other attributes.

Definition at line 130 of file attributes.cpp.

References NULL, and pimpl_.

◆ operator=() [2/2]

xml::attributes & xml::attributes::operator= ( const attributes other)

Copy the given xml::attributes object into this one.

Parameters
otherThe xml::attributes object to copy from.
Returns
*this.
Author
Peter Jones

Definition at line 109 of file attributes.cpp.

References swap(), and tmp.

◆ set_data()

void xml::attributes::set_data ( void *  node)
private

Definition at line 152 of file attributes.cpp.

◆ size()

xml::attributes::size_type xml::attributes::size ( void  ) const

Find out how many attributes there are in this xml::attributes object.

Returns
The number of attributes in this xml::attributes object.
Author
Peter Jones

Definition at line 417 of file attributes.cpp.

References count.

◆ sort()

void xml::attributes::sort ( void  )

Sorts the attributes in place.

Definition at line 432 of file attributes.cpp.

References NULL, and prev().

◆ swap()

void xml::attributes::swap ( attributes other)

Swap this xml::attributes object with another one.

Parameters
otherThe other xml::attributes object to swap with.
Author
Peter Jones

Definition at line 115 of file attributes.cpp.

References pimpl_, and swap().

Referenced by xml::attributes::attr::operator=().

Friends And Related Function Documentation

◆ impl::node_impl

friend struct impl::node_impl
friend

Definition at line 563 of file attributes.hpp.

◆ node

friend class node
friend

Definition at line 564 of file attributes.hpp.

Referenced by xml::attributes::attr::set_data().

Member Data Documentation

◆ pimpl_

pimpl* xml::attributes::pimpl_
private

Definition at line 547 of file attributes.hpp.

Referenced by attributes(), operator=(), and swap().


The documentation for this class was generated from the following files:
Modified on Fri Sep 20 14:57:37 2024 by modify_doxy.py rev. 669887