Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches

An associated array based on adobe::token_range_t. A utility class for the xml_parser_t. More...

#include <adobe/xml_parser.hpp>

Inheritance diagram for attribute_set_t:

Classes

struct  less_key_only_t
struct  less_t

Public Types

typedef token_range_t key_type
typedef token_range_t mapped_type
typedef std::pair< key_type, mapped_typevalue_type
typedef std::vector< value_typeset_type
typedef set_type::size_type size_type
typedef set_type::const_iterator const_iterator
typedef const_iterator iterator

Public Member Functions

bool lower_bound (const value_type &attribute, set_type::iterator &result)
bool lower_bound (const key_type &key, set_type::iterator &result)
bool lower_bound (const value_type &attribute, set_type::const_iterator &result) const
bool lower_bound (const key_type &key, set_type::const_iterator &result) const
mapped_type operator[] (const key_type &key) const
attribute_set_t merge (const attribute_set_t &other_set) const
void insert (const value_type &attribute)
template<typename I>
void insert (I first, I last)
void insert (const key_type &key, const mapped_type &value)
std::size_t count_same (const attribute_set_t &other_set, bool mapped_matters=true) const
bool has_collisions (const attribute_set_t &other_set) const
std::size_t count_collisions (const attribute_set_t &other_set) const
bool empty () const
size_type size () const
const_iterator begin () const
const_iterator end () const
void clear ()

Friends

bool operator== (const attribute_set_t &x, const attribute_set_t &y)
std::ostream & operator<< (std::ostream &s, const attribute_set_t &attribute_set)

(Note that these are not member symbols.)

bool operator== (const attribute_set_t &x, const attribute_set_t &y)
std::ostream & operator<< (std::ostream &s, const attribute_set_t &attribute_set)

Detailed Description

Model Of
Introduction
One of the key advantages to the adobe::xml_parser_t class is its performance in parsing documents. It is able to achieve fast parsing speeds by eliminating the copying of the original data during the parse, and only copying information to the output streams as the client of the parser sees fit. This mandates a host of accomodations given that the source data becomes deeply shared during a parse.
The adobe::attribute_set_t class is a collection point for attributes that are found while parsing elements found within an xml-based document. These attributes are then handed back to the xml_parser_t client via the client callback mechanism. The attribute_set_t storage implementation is copy-on-modify, so it is inexpensive to pass by value.

Definition at line 42 of file xml_parser.hpp.

Member Typedef Documentation

◆ key_type

typedef token_range_t key_type

Definition at line 43 of file xml_parser.hpp.

◆ mapped_type

typedef token_range_t mapped_type

Definition at line 44 of file xml_parser.hpp.

◆ value_type

typedef std::pair<key_type, mapped_type> value_type

Definition at line 45 of file xml_parser.hpp.

◆ set_type

typedef std::vector<value_type> set_type

Definition at line 46 of file xml_parser.hpp.

◆ size_type

typedef set_type::size_type size_type

Definition at line 47 of file xml_parser.hpp.

◆ const_iterator

typedef set_type::const_iterator const_iterator

Definition at line 48 of file xml_parser.hpp.

◆ iterator

Definition at line 49 of file xml_parser.hpp.

Member Function Documentation

◆ lower_bound() [1/4]

bool lower_bound ( const value_type & attribute,
set_type::iterator & result )

Same logical result as std::lower_bound as it applies to attribute_set_t. Note that the value of the attribute is not used in the search; only the key is looked up.

Parameters
attributethe attribute whose key is to be searched for in the attribute_set_t
resultthe resultant position to which the attribute key fits
Returns
true if the attribute key exists within the attribute_set_t. false otherwise.

Definition at line 86 of file xml_parser.hpp.

◆ lower_bound() [2/4]

bool lower_bound ( const key_type & key,
set_type::iterator & result )

Same logical result as std::lower_bound as it applies to attribute_set_t. For this particular implementation only the attribute key is necessary as a parameter.

Parameters
keythe key that is to be searched for in the attribute_set_t
resultthe resultant position to which the key fits
Returns
true if an attribute with this key exists within the attribute_set_t. false otherwise.

Definition at line 103 of file xml_parser.hpp.

◆ lower_bound() [3/4]

bool lower_bound ( const value_type & attribute,
set_type::const_iterator & result ) const

const-equivalent of lower_bound for attribute_set_t.

Definition at line 110 of file xml_parser.hpp.

◆ lower_bound() [4/4]

bool lower_bound ( const key_type & key,
set_type::const_iterator & result ) const

const-equivalent of lower_bound for attribute_set_t.

Definition at line 119 of file xml_parser.hpp.

◆ operator[]()

mapped_type operator[] ( const key_type & key) const

Fetches an unmodifiable value from an attribute_set_t stored under a given key.

Parameters
keythe key under which the corresponding value should be found
Returns
the value if one exists; otherwise the NULL-token (See token_range_t).

Definition at line 132 of file xml_parser.hpp.

◆ merge()

attribute_set_t merge ( const attribute_set_t & other_set) const

This merges two attribute sets together and places the union into dst. In the case where both attribute sets have an element with the same name, the value in the union will be from *this. The values are not compared when performing the union. This means the "override" attribute set should be the first source when you call this function.

Parameters
other_setthe second attribute_set_t with which this one will be merged.
Returns
an attribute_set_t that is the result of merging this attribute_set_t with the one passed in. This attribute_set_t is left unchanged.

Definition at line 155 of file xml_parser.hpp.

◆ insert() [1/3]

void insert ( const value_type & attribute)

Inserts a key-value pair into the current attribute set. If there are more than one references to the internal instance of this attribute set, then a copy will be spun off before the insertion is made.

In the case when a value is already stored under the key specified in the attribute to be inserted, that value is replaced.

Parameters
attributethe key-value pair to be inserted.

Definition at line 176 of file xml_parser.hpp.

◆ insert() [2/3]

template<typename I>
void insert ( I first,
I last )

Inserts a range of key-value pairs into the current attribute set. Equivalent to invoking insert() over each element in the range.

Precondition
last must be reachable from first.
Parameters
firstA pointer to the first key-value pair in the range.
lastA pointer to one-past the last key-value pair in the range.

Definition at line 196 of file xml_parser.hpp.

◆ insert() [3/3]

void insert ( const key_type & key,
const mapped_type & value )

Inserts a key-value pair into the current attribute set. This is a helper implementation, allowing the client to specify the key and the value to be inserted as separate parameters.

Parameters
keythe key under which the value is to be inserted
valuethe value to be inserted into the attribute set

Definition at line 209 of file xml_parser.hpp.

◆ count_same()

std::size_t count_same ( const attribute_set_t & other_set,
bool mapped_matters = true ) const

Counts the number of attributes two attribute sets hold in similarity. When making the comparison the value of the attributes can be optionally omitted.

Parameters
other_setthe other attribute set used for comparison
mapped_matterstoggles whether or not to consider the values found under the respective keys. If false, only the existence of the keys are required for the two sets to be considered 'sharing' that key.

Definition at line 345 of file xml_parser.hpp.

◆ has_collisions()

bool has_collisions ( const attribute_set_t & other_set) const

A collision is defined as a key existing in both attribute sets but having different values. This routine searches two attribute sets looking to see if any collisions exist between them.

This routine is no slower (and is often faster than) the expression count_collisions() != 0.

Parameters
other_setthe other attribute set used for comparison
Returns
Whether or not there is at least one collision between the two attribute sets.

Definition at line 370 of file xml_parser.hpp.

◆ count_collisions()

std::size_t count_collisions ( const attribute_set_t & other_set) const

A collision is defined as a key existing in both attribute sets but having different values. This routine searches two attribute sets and counts the number of collisions that exist between them.

Parameters
other_setthe other attribute set used for comparison
Returns
The number of collisions that exist between two sets.

Definition at line 387 of file xml_parser.hpp.

◆ empty()

bool empty ( ) const
Returns
Specifies whether or not this attribute set is empty

Definition at line 254 of file xml_parser.hpp.

◆ size()

size_type size ( ) const
Returns
Specifies the number of key-value pairs stored in this attribute set

Definition at line 260 of file xml_parser.hpp.

◆ begin()

const_iterator begin ( ) const
Returns
An unmodifiable (but dereferenceable) iterator to the first key-value pair in the attribute set

Definition at line 266 of file xml_parser.hpp.

◆ end()

const_iterator end ( ) const
Returns
An iterator to one-past-the last key-value pair in the attribute set

Definition at line 272 of file xml_parser.hpp.

◆ clear()

void clear ( )

Erases the entire contents of the attribute set.

Postcondition
empty() == true

Definition at line 280 of file xml_parser.hpp.

◆ operator== [1/2]

bool operator== ( const attribute_set_t & x,
const attribute_set_t & y )
friend

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & s,
const attribute_set_t & attribute_set )
friend

◆ operator==() [2/2]

bool operator== ( const attribute_set_t & x,
const attribute_set_t & y )
related

Defines equality comparisons between two attribute sets. Equivalent to calling count_same over the attribute sets and arriving at the size of both sets (which, by implication, must be the same.)

Parameters
xthe first attribute set
ythe second attribute set
Returns
true if the two attribute sets are equal. false otherwise.

Definition at line 303 of file xml_parser.hpp.

◆ operator<<() [2/2]

std::ostream & operator<< ( std::ostream & s,
const attribute_set_t & attribute_set )
related

Defines serialization functionality for an attribute set. Output format is similar to the format required for attribute sets in xml documents.

Parameters
sthe stream to receive the output
attribute_setthe attribute set to be serialized to the stream
Returns
the output stream

Definition at line 320 of file xml_parser.hpp.