Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::FakeElement Class Reference

A test fake for a type that satisfies the ElementLike concept. More...

#include "donner/base/element/tests/FakeElement.h"

Classes

struct  DeferredPrinter
 Helper class to change how this element is printed as a tree. More...
 

Public Member Functions

 FakeElement (const XMLQualifiedNameRef &tagName="unknown")
 Construct a fake element with the given tag name.
 
DeferredPrinter printAsTree () const
 When used in an ostream output stream, prints the element's and all children instead of just the element.
 
bool operator< (const FakeElement &other) const
 Comparison operator, uses pointer comparison for simplicity.
 
Core API that satisfies the \ref ElementLike concept
bool operator== (const FakeElement &other) const
 Equality operator.
 
XMLQualifiedNameRef tagName () const
 Get the XML tag name string for this element.
 
bool isKnownType () const
 Returns true if this is a known element type. For FakeElement, returns false for "unknown" elements.
 
RcString id () const
 Gets the element id, the value of the "id" attribute.
 
RcString className () const
 Gets the element class name, the value of the "class" attribute.
 
std::optional< RcStringgetAttribute (const XMLQualifiedNameRef &name) const
 Get the value of an attribute, if it exists.
 
SmallVector< XMLQualifiedNameRef, 1 > findMatchingAttributes (const XMLQualifiedNameRef &matcher) const
 Find attributes matching the given name matcher.
 
std::optional< FakeElementparentElement () const
 Get this element's parent, if it exists.
 
std::optional< FakeElementfirstChild () const
 Get the first child of this element, if it exists.
 
std::optional< FakeElementlastChild () const
 Get the last child of this element, if it exists.
 
std::optional< FakeElementpreviousSibling () const
 Get the previous sibling of this element, if it exists.
 
std::optional< FakeElementnextSibling () const
 Get the next sibling of this element, if it exists.
 
Mutator methods
void setId (const RcString &id)
 Sets the element id, the value of the "id" attribute.
 
void setClassName (const RcString &className)
 Sets the element class name, the value of the "class" attribute.
 
void setAttribute (const XMLQualifiedNameRef &name, const RcString &value)
 Sets the value of an attribute.
 
void appendChild (const FakeElement &child)
 Appends a new child to this element's child list.
 

Friends

std::ostream & operator<< (std::ostream &os, const FakeElement &elem)
 Ostream output operator, which outputs the element's tag name, id, class name, and attributes like a CSS selector.
 

Detailed Description

A test fake for a type that satisfies the ElementLike concept.

This is used for testing purposes, and has simple implementations for each API.

Examples
custom_css_parser.cc.

Constructor & Destructor Documentation

◆ FakeElement()

donner::FakeElement::FakeElement ( const XMLQualifiedNameRef & tagName = "unknown")
inlineexplicit

Construct a fake element with the given tag name.

Parameters
tagNameThe XML tag name for this element.

Member Function Documentation

◆ findMatchingAttributes()

SmallVector< XMLQualifiedNameRef, 1 > donner::FakeElement::findMatchingAttributes ( const XMLQualifiedNameRef & matcher) const
inline

Find attributes matching the given name matcher.

Parameters
matcherMatcher to use to find attributes. If XMLQualifiedNameRef::namespacePrefix is "*", the matcher will match any namespace with the given attribute name.
Returns
A vector of attributes matching the given name matcher.

◆ firstChild()

std::optional< FakeElement > donner::FakeElement::firstChild ( ) const
inline

Get the first child of this element, if it exists.

Returns
The first child element, or std::nullopt if the element has no children.

◆ getAttribute()

std::optional< RcString > donner::FakeElement::getAttribute ( const XMLQualifiedNameRef & name) const
inline

Get the value of an attribute, if it exists.

Parameters
nameName of the attribute to get.
Returns
The value of the attribute, or std::nullopt if the attribute does not exist.

◆ lastChild()

std::optional< FakeElement > donner::FakeElement::lastChild ( ) const
inline

Get the last child of this element, if it exists.

Returns
The last child element, or std::nullopt if the element has no children.

◆ nextSibling()

std::optional< FakeElement > donner::FakeElement::nextSibling ( ) const
inline

Get the next sibling of this element, if it exists.

Returns
The next sibling element, or std::nullopt if the element has no next sibling.

◆ parentElement()

std::optional< FakeElement > donner::FakeElement::parentElement ( ) const
inline

Get this element's parent, if it exists.

If the parent is not set, this document is either the root element or has not been inserted into the document tree.

Returns
The parent element, or std::nullopt if the parent is not set.

◆ previousSibling()

std::optional< FakeElement > donner::FakeElement::previousSibling ( ) const
inline

Get the previous sibling of this element, if it exists.

Returns
The previous sibling element, or std::nullopt if the element has no previous sibling.

◆ printAsTree()

DeferredPrinter donner::FakeElement::printAsTree ( ) const
inline

When used in an ostream output stream, prints the element's and all children instead of just the element.

Example usage:

FakeElement element;
std::cout << element.printAsTree() << "\n";
A test fake for a type that satisfies the ElementLike concept.
Definition FakeElement.h:23
DeferredPrinter printAsTree() const
When used in an ostream output stream, prints the element's and all children instead of just the elem...
Definition FakeElement.h:247
Examples
custom_css_parser.cc.

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