glibmm: Glib::Markup::Parser Class Reference

glibmm 2.66.8

Public Types | Public Member Functions | Protected Member Functions | List of all members
Glib::Markup::Parser Class Referenceabstract
Simple XML Subset Parser

The abstract markup parser base class. More...

`#include <glibmm/markup.h>`

Inheritance diagram for Glib::Markup::Parser:
[legend]

## Public Types
typedef std::map< Glib::ustring, Glib::ustring, Glib::Markup::AttributeKeyLess > | AttributeMap
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify

## Public Member Functions
virtual | ~Parser ()=0
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src)
| ~trackable ()
void | add_destroy_notify_callback (void *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src)
void | remove_destroy_notify_callback (void *data) const

## Protected Member Functions
| Parser ()
| Constructs a Parser object.
| Parser (const Parser &)=delete
Parser & | operator= (const Parser &)=delete
| Parser (Parser && other) noexcept
Parser & | operator= (Parser && other) noexcept
virtual void | on_start_element (ParseContext & context, const Glib::ustring & element_name, const AttributeMap & attributes)
| Called for open tags <foo bar="baz">.
virtual void | on_end_element (ParseContext & context, const Glib::ustring & element_name)
| Called for close tags </foo>.
virtual void | on_text (ParseContext & context, const Glib::ustring & text)
| Called for character data.
virtual void | on_passthrough (ParseContext & context, const Glib::ustring & passthrough_text)
| Called for strings that should be re-saved verbatim in this same position, but are not otherwise interpretable.
virtual void | on_error (ParseContext & context, const MarkupError & error)
| Called on error, including one thrown by an overridden virtual method.

## Detailed Description

The abstract markup parser base class.

To implement a parser for your markup format, derive from Glib::Markup::Parser and implement the virtual methods.

You don't have to override all of the virtual methods. If a particular method is not implement the data passed to it will be ignored. Except for the error method, any of these callbacks can throw an error exception; in particular the MarkupError::UNKNOWN_ELEMENT, MarkupError::UNKNOWN_ATTRIBUTE, and MarkupError::INVALID_CONTENT errors are intended to be thrown from these overridden methods. If you throw an error from a method, Glib::Markup::ParseContext::parse() will report that error back to its caller.

## Member Typedef Documentation

## ◆ AttributeMap

typedef std::map<Glib::ustring, Glib::ustring, Glib::Markup::AttributeKeyLess> Glib::Markup::Parser::AttributeMap

## Constructor & Destructor Documentation

## ◆ ~Parser()

virtual Glib::Markup::Parser::~Parser | ( |  | ) |
| pure virtual

## ◆ Parser() [1/3]

Glib::Markup::Parser::Parser | ( |  | ) |
| protected

Constructs a Parser object.

Note that Markup::Parser is an abstract class which can't be instantiated directly. To implement the parser for your markup format, derive from Markup::Parser and implement the virtual methods.

## ◆ Parser() [2/3]

Glib::Markup::Parser::Parser | ( | const Parser & |  | ) |
| protecteddelete

## ◆ Parser() [3/3]

Glib::Markup::Parser::Parser | ( | Parser && | other | ) |
| protectednoexcept

## Member Function Documentation

## ◆ on_end_element()

virtual void Glib::Markup::Parser::on_end_element | ( | ParseContext & | context,
|  | const Glib::ustring & | element_name )
| protectedvirtual

Called for close tags </foo>.

This virtual method is invoked when the closing tag of an element is seen.

Parameters

  context | The Markup::ParseContext object the parsed data belongs to.
  element_name | The name of the element.

Exceptions

  Glib::MarkupError | An exception you should throw if something went wrong, for instance if an unknown attribute name was encountered. In particular the MarkupError::UNKNOWN_ELEMENT, MarkupError::UNKNOWN_ATTRIBUTE, and MarkupError::INVALID_CONTENT errors are intended to be thrown from user-implemented methods.

## ◆ on_error()

virtual void Glib::Markup::Parser::on_error | ( | ParseContext & | context,
|  | const MarkupError & | error )
| protectedvirtual

Called on error, including one thrown by an overridden virtual method.

Parameters

  context | The Markup::ParseContext object the parsed data belongs to.
  error | A MarkupError object with detailed information about the error.

## ◆ on_passthrough()

virtual void Glib::Markup::Parser::on_passthrough | ( | ParseContext & | context,
|  | const Glib::ustring & | passthrough_text )
| protectedvirtual

Called for strings that should be re-saved verbatim in this same position, but are not otherwise interpretable.

This virtual method is invoked for comments, processing instructions and doctype declarations; if you're re-writing the parsed document, write the passthrough text back out in the same position.

Parameters

  context | The Markup::ParseContext object the parsed data belongs to.
  passthrough_text | The text that should be passed through.

Exceptions

  Glib::MarkupError | An exception you should throw if something went wrong, for instance if an unknown attribute name was encountered. In particular the MarkupError::UNKNOWN_ELEMENT, MarkupError::UNKNOWN_ATTRIBUTE, and MarkupError::INVALID_CONTENT errors are intended to be thrown from user-implemented methods.

## ◆ on_start_element()

virtual void Glib::Markup::Parser::on_start_element | ( | ParseContext & | context,
|  | const Glib::ustring & | element_name,
|  | const AttributeMap & | attributes )
| protectedvirtual

Called for open tags <foo bar="baz">.

This virtual method is invoked when the opening tag of an element is seen.

Parameters

  context | The Markup::ParseContext object the parsed data belongs to.
  element_name | The name of the element.
  attributes | A map of attribute name/value pairs.

Exceptions

  Glib::MarkupError | An exception you should throw if something went wrong, for instance if an unknown attribute name was encountered. In particular the MarkupError::UNKNOWN_ELEMENT, MarkupError::UNKNOWN_ATTRIBUTE, and MarkupError::INVALID_CONTENT errors are intended to be thrown from user-implemented methods.

## ◆ on_text()

virtual void Glib::Markup::Parser::on_text | ( | ParseContext & | context,
|  | const Glib::ustring & | text )
| protectedvirtual

Called for character data.

This virtual method is invoked when some text is seen (text is always inside an element).

Parameters

  context | The Markup::ParseContext object the parsed data belongs to.
  text | The parsed text in UTF-8 encoding.

Exceptions

  Glib::MarkupError | An exception you should throw if something went wrong, for instance if an unknown attribute name was encountered. In particular the MarkupError::UNKNOWN_ELEMENT, MarkupError::UNKNOWN_ATTRIBUTE, and MarkupError::INVALID_CONTENT errors are intended to be thrown from user-implemented methods.

## ◆ operator=() [1/2]

Parser & Glib::Markup::Parser::operator= | ( | const Parser & |  | ) |
| protecteddelete

## ◆ operator=() [2/2]

Parser & Glib::Markup::Parser::operator= | ( | Parser && | other | ) |
| protectednoexcept