SVG for C++
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SVG::Element Class Referenceabstract

Abstract base class for all SVG elements. More...

#include <svg.hpp>

Inherits SVG::AttributeMap.

Inherited by SVG::Group, SVG::Polygon, SVG::Shape, SVG::SVG::Style, and SVG::Text.

Classes

class  BoundingBox
 Represents the top left and bottom right corners of a bounding rectangle. More...
 

Public Types

using ChildList = std::vector< Element * >
 
using ChildMap = std::map< std::string, ChildList >
 

Public Member Functions

 Element (const Element &other)=delete
 
 Element (Element &&other)=default
 
 Element (const char *id)
 
 operator std::string ()
 
template<typename T , typename... Args>
T * add_child (Args &&... args)
 
template<typename T >
Elementoperator<< (T &&node)
 
template<typename T >
std::vector< T * > get_children ()
 
template<typename T >
std::vector< T * > get_immediate_children ()
 
Elementget_element_by_id (const std::string &id)
 
std::vector< Element * > get_elements_by_class (const std::string &clsname)
 
void autoscale (const Margins &margins=DEFAULT_MARGINS)
 
void autoscale (const double margin)
 
virtual BoundingBox get_bbox ()
 
ChildMap get_children ()
 
template<>
Element::ChildList get_immediate_children ()
 
- Public Member Functions inherited from SVG::AttributeMap
 AttributeMap (SVGAttrib _attr)
 
template<typename T >
AttributeMapset_attr (const std::string key, T value)
 
template<>
AttributeMapset_attr (const std::string key, const double value)
 
template<>
AttributeMapset_attr (const std::string key, const char *value)
 
template<>
AttributeMapset_attr (const std::string key, const std::string value)
 

Protected Member Functions

std::vector< Element * > get_children_helper ()
 
void get_bbox (Element::BoundingBox &)
 
virtual std::string svg_to_string (const size_t indent_level)
 
virtual std::string tag ()=0
 
double find_numeric (const std::string &key)
 

Protected Attributes

std::vector< std::unique_ptr< Element > > children
 

Additional Inherited Members

- Public Attributes inherited from SVG::AttributeMap
SVGAttrib attr
 

Detailed Description

Abstract base class for all SVG elements.

Member Function Documentation

◆ add_child()

template<typename T , typename... Args>
T* SVG::Element::add_child ( Args &&...  args)
inline

Add an SVG element as a child and return a pointer to the element added

◆ autoscale() [1/2]

void SVG::Element::autoscale ( const Margins margins = DEFAULT_MARGINS)
inline

Automatically set the width, height, and viewBox attribute of this item so that it can contain all of its children without clipping

Parameters
[in]marginsExtra margins for the sides

◆ autoscale() [2/2]

void SVG::Element::autoscale ( const double  margin)
inline

Like other autoscale() but accepts margin as a percentage

◆ find_numeric()

double SVG::Element::find_numeric ( const std::string &  key)
inlineprotected

The SVG tag of this element

Return the numeric attribute (if it exists) or NAN

Parameters
[in]keyName of the attribute

◆ get_bbox() [1/2]

Element::BoundingBox SVG::Element::get_bbox ( )
inlinevirtual

Compute the bounding box necessary to contain this element

◆ get_bbox() [2/2]

void SVG::Element::get_bbox ( Element::BoundingBox box)
inlineprotected

Recursively compute a bounding box

◆ get_children() [1/2]

template<typename T >
std::vector<T*> SVG::Element::get_children ( )
inline

Return all children of type T

◆ get_children() [2/2]

Element::ChildMap SVG::Element::get_children ( )
inline

Recursively compute all of the children of an SVG element

◆ get_children_helper()

std::vector< Element * > SVG::Element::get_children_helper ( )
inlineprotected

Smart pointers to child elements

Helper function which populates a std::deque with all of an Element's children

◆ get_element_by_id()

Element * SVG::Element::get_element_by_id ( const std::string &  id)
inline

Return the SVG element that has a certain id

◆ get_elements_by_class()

std::vector< Element * > SVG::Element::get_elements_by_class ( const std::string &  clsname)
inline

Return all SVG elements with a certain class name

◆ get_immediate_children() [1/2]

template<typename T >
std::vector<T*> SVG::Element::get_immediate_children ( )
inline

Return all immediate children of type T

◆ get_immediate_children() [2/2]

template<>
Element::ChildList SVG::Element::get_immediate_children ( )
inline

Return all immediate children, regardless of type, as Element pointers

◆ operator<<()

template<typename T >
Element& SVG::Element::operator<< ( T &&  node)
inline

Move an SVG element into this container

◆ svg_to_string()

std::string SVG::Element::svg_to_string ( const size_t  indent_level)
inlineprotectedvirtual

Return the string representation of an SVG element

Parameters
[out]indent_levelThe current level of indentation

Reimplemented in SVG::SVG::Style.

◆ tag()

virtual std::string SVG::Element::tag ( )
protectedpure virtual

SVG string corresponding to this element

Implemented in SVG::Polygon, SVG::Circle, SVG::Rect, SVG::Line, SVG::Group, SVG::Text, SVG::Path, SVG::SVG, and SVG::SVG::Style.


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