PLaSK library
Loading...
Searching...
No Matches
plask::GeometryObject::WriteXMLCallback Class Reference

Base class for callbacks used by save() method to get names of objects and paths. More...

#include <plask/geometry/object.hpp>

Public Member Functions

 WriteXMLCallback ()
 
void prerareToAutonaming (const GeometryObject &subtree_root)
 Calling of this method allows for automatic name generation when saving some subtrees using this.
 
virtual std::string getName (const GeometryObject &object, AxisNames &axesNames) const
 Get name of given object.
 
virtual std::vector< std::string > getPathNames (const GeometryObject &parent, const GeometryObject &child, std::size_t index_of_child_in_parent) const
 Get names of path fragment from parent to child.
 
XMLWriter::Element makeTag (XMLElement &parent_tag, const GeometryObject &object, AxisNames &axesNames)
 Append to XML tag, with optional name (obtain by getName), and axes attribute.
 
XMLElement makeChildTag (XMLElement &container_tag, const GeometryObject &container, std::size_t index_of_child_in_parent) const
 

Static Public Member Functions

static bool isRef (const XMLElement &el)
 Check if given XML object represents a reference to another geometry object.
 

Detailed Description

Base class for callbacks used by save() method to get names of objects and paths.

Default implementation just returns empty names and list of names. It is enough to save geometry tree without any names or with all names auto-generated (see prerareToAutonaming).

Example (save vector of objects to dest XML in "geometry" section):

// std::vector<const plask::GeomtryObject*> to_save; //root of trees to save
// XMLWriter dest; // destination, output XML
WriteXMLCallback namer; // or subclass of WriteXMLCallback
// this is required only if elements should have auto-generated names:
// writting:
XMLWriter::Element geom_section(dest, "geometry"); // section tag
for (auto e: to_save) // all roots

Definition at line 479 of file object.hpp.

Constructor & Destructor Documentation

◆ WriteXMLCallback()

plask::GeometryObject::WriteXMLCallback::WriteXMLCallback ( )
inline

Definition at line 492 of file object.hpp.

Member Function Documentation

◆ getName()

std::string plask::GeometryObject::WriteXMLCallback::getName ( const GeometryObject object,
AxisNames axesNames 
) const
virtual

Get name of given object.

Parameters
[in]object
[in,out]axesNamesaxes names which was used when saved parent of object, this can assign to it new value to use in branch rooted by object
Returns
name of object or empty string if object has no name

Definition at line 67 of file object.cpp.

◆ getPathNames()

std::vector< std::string > plask::GeometryObject::WriteXMLCallback::getPathNames ( const GeometryObject parent,
const GeometryObject child,
std::size_t  index_of_child_in_parent 
) const
virtual

Get names of path fragment from parent to child.

Parameters
[in]parentcontainer which contains child
[in]childobject from a parent container
[in]index_of_child_in_parentindex of child in parent real childrent list
Returns
names of path fragment from parent to child (can be empty)

Definition at line 71 of file object.cpp.

◆ isRef()

static bool plask::GeometryObject::WriteXMLCallback::isRef ( const XMLElement el)
inlinestatic

Check if given XML object represents a reference to another geometry object.

Parameters
elXML object
Returns
true only if el represents a reference

Definition at line 544 of file object.hpp.

◆ makeChildTag()

XMLElement plask::GeometryObject::WriteXMLCallback::makeChildTag ( XMLElement container_tag,
const GeometryObject container,
std::size_t  index_of_child_in_parent 
) const

Definition at line 107 of file object.cpp.

◆ makeTag()

XMLWriter::Element plask::GeometryObject::WriteXMLCallback::makeTag ( XMLElement parent_tag,
const GeometryObject object,
AxisNames axesNames 
)

Append to XML tag, with optional name (obtain by getName), and axes attribute.

It is also possible that this creates a reference tag, and this case should be checked by isRef method.

Parameters
parent_tagparent XML tag
objectobject to write
[in,out]axesNamesaxis names which was used when saved parent of object, this can assign to it new value to use in branch rooted by object (assigned pointer must be valid while branch will be saved, typically it is a pointer to object in register)
Returns
opened XML tag ready to add extra atribiutes of object or reference tag.

Definition at line 75 of file object.cpp.

◆ prerareToAutonaming()

void plask::GeometryObject::WriteXMLCallback::prerareToAutonaming ( const GeometryObject subtree_root)

Calling of this method allows for automatic name generation when saving some subtrees using this.

This method must be called exactly once for root of each subtree which will be write to XML before any writes.

Definition at line 63 of file object.cpp.


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