PLaSK library
Loading...
Searching...
No Matches
plask::GeometryReader Class Reference

Allow to read geometry from XML. More...

#include <plask/geometry/reader.hpp>

Collaboration diagram for plask::GeometryReader:
[legend]

Classes

struct  RegisterChangerReader
 Helper which call registerChangerReader in constructor. More...
 
struct  RegisterObjectReader
 Helper which call registerObjectReader in constructor. More...
 
struct  RevertMaterialsAreRequired
 Revert materialsAreRequired flag in destructor. More...
 
struct  SetExpectedSuffix
 Store current expectedSuffix, set new one, and restore old when out of the scope (in destructor). More...
 

Public Types

typedef shared_ptr< GeometryObjectobject_read_f(GeometryReader &reader)
 Create new geometry object with parameters reading from XML source.
 
typedef std::function< GeometryObject::Changer *(GeometryReader &reader)> changer_read_f
 Create new copy transform with parameters reading from XML source.
 

Public Member Functions

const AxisNamesgetAxisNames () const
 
std::string getAxisName (std::size_t axis_index)
 Get current axis name.
 
std::string getAxisLongName ()
 Get current lon direction axis name.
 
std::string getAxisTranName ()
 Get current tran direction axis name.
 
std::string getAxisVertName ()
 Get current up direction axis name.
 
shared_ptr< MaterialgetMaterial (const std::string &material_full_name) const
 Get material from material source (typically material database) connected with this reader.
 
shared_ptr< MaterialsDB::MixedCompositionFactorygetMixedCompositionFactory (const std::string &material1_full_name, const std::string &material2_full_name, double shape=1.) const
 
shared_ptr< MaterialrequireMaterial () const
 Read material from XML source (from attribute with name XML_MATERIAL_ATTR).
 
SolidOrGradientMaterial requireSolidOrGradientMaterial () const
 Read material or gradient material factory from XML source.
 
 GeometryReader (Manager &manager, XMLReader &source, const MaterialsDB &materialsDB=MaterialsDB::getDefault())
 
shared_ptr< GeometryObjectreadObject ()
 Read geometry object from source and add it Manager structures.
 
shared_ptr< GeometryObjectreadExactlyOneChild ()
 Helper function to read objects which have exactly one child (typically: transform).
 
template<typename RequiredObjectType >
shared_ptr< RequiredObjectTypereadObject ()
 Call readObject() and try dynamic cast it to RequiredObjectType.
 
template<typename RequiredObjectType >
shared_ptr< RequiredObjectTypereadExactlyOneChild ()
 Call readExactlyOneChild() and try dynamic cast it to RequiredObjectType.
 
shared_ptr< GeometryreadGeometry ()
 Try reading calculation space.
 
shared_ptr< GeometryObjectrequireObjectWithName (const std::string &name) const
 Get named objects.
 
shared_ptr< GeometryObjectrequireObjectFromAttribute (const std::string &attr) const
 Get objects from attribute.
 
void registerObjectName (const std::string &name, shared_ptr< GeometryObject > object)
 Add name of object to register.
 
void registerObjectName (const plask::optional< std::string > &name, shared_ptr< GeometryObject > object)
 Add name of object to register.
 
void registerObjectName (const plask::optional< const std::string > &name, shared_ptr< GeometryObject > object)
 Add name of object to register.
 
void registerObjectNameFromCurrentNode (shared_ptr< GeometryObject > object)
 Add name of object to register.
 
template<>
shared_ptr< GeometryObjectreadObject ()
 
template<>
shared_ptr< GeometryObjectreadExactlyOneChild ()
 

Static Public Member Functions

static std::map< std::string, object_read_f * > & objectReaders ()
 
static void registerObjectReader (const std::string &tag_name, object_read_f *reader)
 Add reader to objectReaders.
 
static std::map< std::string, changer_read_f > & changerReaders ()
 
static void registerChangerReader (const std::string &tag_name, changer_read_f reader)
 Add reader to changerReaders.
 

Public Attributes

bool materialsAreRequired
 true if materials in leafs are required, false if we read only shape
 
const charexpectedSuffix
 Currently expected suffix for names of geometry objects types, can have one of the following values:
 
Managermanager
 Geometry manager which stores reading results.
 
XMLReadersource
 XML data source.
 
const MaterialsDBmaterialsDB
 Source of materials, typically use material database.
 

Static Public Attributes

static constexpr const char *const XML_NAME_ATTR = "name"
 name of the object's/geometry's name attribute in XML
 
static constexpr const char *const XML_MATERIAL_ATTR = "material"
 name of the material attribute in XML
 
static constexpr const char *const XML_MATERIAL_TOP_ATTR = "material-top"
 name of the top material attribute in XML
 
static constexpr const char *const XML_MATERIAL_BOTTOM_ATTR = "material-bottom"
 name of the bottom material attribute in XML
 
static constexpr const char *const XML_MATERIAL_GRADING_ATTR = "material-shape"
 name of the shape exponent attribute in XML
 

Detailed Description

Allow to read geometry from XML.

Have references to both: XML data source reader and geometry manager. Manage names of axis while reading.

Definition at line 34 of file reader.hpp.

Member Typedef Documentation

◆ changer_read_f

Create new copy transform with parameters reading from XML source.

After return reader should point to end of tag of this object. Can call managers methods to read children (GeometryReader::readObject). Should throw exception if can't create object.

Definition at line 98 of file reader.hpp.

◆ object_read_f

typedef shared_ptr< GeometryObject > plask::GeometryReader::object_read_f(GeometryReader &reader)

Create new geometry object with parameters reading from XML source.

After return reader should point to end of tag of this object. Can call managers methods to read children (GeometryReader::readObject). Should throw exception if can't create object.

Definition at line 57 of file reader.hpp.

Constructor & Destructor Documentation

◆ GeometryReader()

plask::GeometryReader::GeometryReader ( plask::Manager manager,
plask::XMLReader source,
const MaterialsDB materialsDB = MaterialsDB::getDefault() 
)
Parameters
manager
sourcexml data source from which object data should be read
materialsDBmaterials database used to set leafs materials

Definition at line 118 of file reader.cpp.

Member Function Documentation

◆ changerReaders()

std::map< std::string, GeometryReader::changer_read_f > & plask::GeometryReader::changerReaders ( )
static
Returns
Global changer readers register. Map: xml tag name -> changer reader function.

Definition at line 91 of file reader.cpp.

◆ getAxisLongName()

std::string plask::GeometryReader::getAxisLongName ( )
inline

Get current lon direction axis name.

Returns
name of lon axis

Definition at line 137 of file reader.hpp.

◆ getAxisName()

std::string plask::GeometryReader::getAxisName ( std::size_t  axis_index)

Get current axis name.

Parameters
axis_indexaxis index
Returns
name of axis which have an axis_index

Definition at line 102 of file reader.cpp.

◆ getAxisNames()

const AxisNames & plask::GeometryReader::getAxisNames ( ) const

Definition at line 100 of file reader.cpp.

◆ getAxisTranName()

std::string plask::GeometryReader::getAxisTranName ( )
inline

Get current tran direction axis name.

Returns
name of tran axis

Definition at line 143 of file reader.hpp.

◆ getAxisVertName()

std::string plask::GeometryReader::getAxisVertName ( )
inline

Get current up direction axis name.

Returns
name of up axis

Definition at line 149 of file reader.hpp.

◆ getMaterial()

shared_ptr< Material > plask::GeometryReader::getMaterial ( const std::string &  material_full_name) const

Get material from material source (typically material database) connected with this reader.

Throw exception if can't get material (no material with given name, etc.).

Parameters
material_full_namefull material name to get
Returns
material with name material_full_name

Definition at line 26 of file reader.cpp.

◆ getMixedCompositionFactory()

shared_ptr< MaterialsDB::MixedCompositionFactory > plask::GeometryReader::getMixedCompositionFactory ( const std::string &  material1_full_name,
const std::string &  material2_full_name,
double  shape = 1. 
) const

Definition at line 38 of file reader.cpp.

◆ objectReaders()

std::map< std::string, GeometryReader::object_read_f * > & plask::GeometryReader::objectReaders ( )
static
Returns
Global objects readers register. Map: xml tag name -> object reader function.

Definition at line 82 of file reader.cpp.

◆ readExactlyOneChild() [1/3]

shared_ptr< GeometryObject > plask::GeometryReader::readExactlyOneChild ( )

Helper function to read objects which have exactly one child (typically: transform).

Before call source reader should point to parent object tag (typically transform object) and after call it will be point to end of parent object tag.

Returns
child object which was read and create or to which reference was read, or an empty pointer if there is no child and required is true

Definition at line 255 of file reader.cpp.

◆ readExactlyOneChild() [2/3]

shared_ptr< RequiredObjectType > plask::GeometryReader::readExactlyOneChild ( )
inline

Call readExactlyOneChild() and try dynamic cast it to RequiredObjectType.

Returns
object (casted to RequiredObjectType) which was return by readExactlyOneChild(), or an empty pointer if there is no child and required is true
Template Parameters
RequiredObjectTyperequired type of object

Definition at line 359 of file reader.hpp.

◆ readExactlyOneChild() [3/3]

template<>
shared_ptr< GeometryObject > plask::GeometryReader::readExactlyOneChild ( )
inline

Definition at line 359 of file reader.hpp.

◆ readGeometry()

shared_ptr< Geometry > plask::GeometryReader::readGeometry ( )

Try reading calculation space.

Throw exception if can't.

Returns
calculation space which was read

Definition at line 267 of file reader.cpp.

◆ readObject() [1/3]

shared_ptr< GeometryObject > plask::GeometryReader::readObject ( )

Read geometry object from source and add it Manager structures.

Typically it creates new geometry object using objectReaders, but it also support references and can return existing objects.

After call source reader point to end of tag which represent read object.

Returns
object which was read and create or to which reference was read
Exceptions
NamesConflictExceptionif object with read name already exists
NoSuchGeometryObjectif 'again' object references to object which does not exists
NoAttrExceptionif XML tag has no required attributes

Definition at line 126 of file reader.cpp.

◆ readObject() [2/3]

shared_ptr< RequiredObjectType > plask::GeometryReader::readObject ( )
inline

Call readObject() and try dynamic cast it to RequiredObjectType.

Returns
object (casted to RequiredObjectType) which was read and create or to which reference was read
Template Parameters
RequiredObjectTyperequired type of object
Exceptions
UnexpectedGeometryObjectTypeExceptionif requested object is not of type RequiredObjectType
NamesConflictExceptionif object with read name already exists
NoSuchGeometryObjectif 'again' object references to object which does not exists
NoAttrExceptionif XML tag has no required attributes

Definition at line 345 of file reader.hpp.

◆ readObject() [3/3]

template<>
shared_ptr< GeometryObject > plask::GeometryReader::readObject ( )
inline

Definition at line 345 of file reader.hpp.

◆ registerChangerReader()

void plask::GeometryReader::registerChangerReader ( const std::string &  tag_name,
changer_read_f  reader 
)
static

Add reader to changerReaders.

Parameters
tag_nameXML tag name
readerchanger reader function

Definition at line 96 of file reader.cpp.

◆ registerObjectName() [1/3]

void plask::GeometryReader::registerObjectName ( const plask::optional< const std::string > &  name,
shared_ptr< GeometryObject object 
)
inline

Add name of object to register.

Do nothing if name has no value.

It throws exception in case of names conflict.

Parameters
namename of given object (can be auto-generated: in form '#'+number)
objectgeometry object which should be available by given name

Definition at line 321 of file reader.hpp.

◆ registerObjectName() [2/3]

void plask::GeometryReader::registerObjectName ( const plask::optional< std::string > &  name,
shared_ptr< GeometryObject object 
)
inline

Add name of object to register.

Do nothing if name has no value.

It throws exception in case of names conflict.

Parameters
namename of given object (can be auto-generated: in form '#'+number)
objectgeometry object which should be available by given name

Definition at line 310 of file reader.hpp.

◆ registerObjectName() [3/3]

void plask::GeometryReader::registerObjectName ( const std::string &  name,
shared_ptr< GeometryObject object 
)

Add name of object to register.

It throws exception in case of names conflict.

Parameters
namename of given object (can be auto-generated: in form '#'+number)
objectgeometry object which should be available by given name

Definition at line 369 of file reader.cpp.

◆ registerObjectNameFromCurrentNode()

void plask::GeometryReader::registerObjectNameFromCurrentNode ( shared_ptr< GeometryObject object)
inline

Add name of object to register.

Read name from current, XML source tag. Do nothing if name attribute is not available.

It throws exception in case of names conflict.

Parameters
objectgeometry object which should be available by name which was read from current tag

Definition at line 333 of file reader.hpp.

◆ registerObjectReader()

void plask::GeometryReader::registerObjectReader ( const std::string &  tag_name,
object_read_f reader 
)
static

Add reader to objectReaders.

Parameters
tag_nameXML tag name
readerobject reader function

Definition at line 87 of file reader.cpp.

◆ requireMaterial()

shared_ptr< Material > plask::GeometryReader::requireMaterial ( ) const
inline

Read material from XML source (from attribute with name XML_MATERIAL_ATTR).

Throw exception if there is no XML_MATERIAL_ATTR attribute or can't get material (no material with given name, etc.).

Returns
material which was read

Definition at line 201 of file reader.hpp.

◆ requireObjectFromAttribute()

shared_ptr< GeometryObject > plask::GeometryReader::requireObjectFromAttribute ( const std::string &  attr) const
inline

Get objects from attribute.

It support both: named objects (from manager) and auto-named objects.

Parameters
attrattribute holding object name
Returns
object with given name
Exceptions
NoSuchGeometryObjectif object was not found

Definition at line 285 of file reader.hpp.

◆ requireObjectWithName()

shared_ptr< GeometryObject > plask::GeometryReader::requireObjectWithName ( const std::string &  name) const

Get named objects.

It support both: named objects (from manager) and auto-named objects.

Parameters
nameobject name (can be auto-generated: in form '#'+number)
Returns
object with given name
Exceptions
NoSuchGeometryObjectif object was not found

Definition at line 351 of file reader.cpp.

◆ requireSolidOrGradientMaterial()

SolidOrGradientMaterial plask::GeometryReader::requireSolidOrGradientMaterial ( ) const

Read material or gradient material factory from XML source.

Definition at line 52 of file reader.cpp.

Member Data Documentation

◆ expectedSuffix

const char* plask::GeometryReader::expectedSuffix

Currently expected suffix for names of geometry objects types, can have one of the following values:

  • 0 dimensions of children space can't be deduced (initial value),
  • PLASK_GEOMETRY_TYPE_NAME_SUFFIX_2D if 2d children are expected,
  • PLASK_GEOMETRY_TYPE_NAME_SUFFIX_3D if 3d children are expected.

Definition at line 89 of file reader.hpp.

◆ manager

Manager& plask::GeometryReader::manager

Geometry manager which stores reading results.

Definition at line 174 of file reader.hpp.

◆ materialsAreRequired

bool plask::GeometryReader::materialsAreRequired

true if materials in leafs are required, false if we read only shape

Definition at line 48 of file reader.hpp.

◆ materialsDB

const MaterialsDB* plask::GeometryReader::materialsDB

Source of materials, typically use material database.

Definition at line 180 of file reader.hpp.

◆ source

XMLReader& plask::GeometryReader::source

XML data source.

Definition at line 177 of file reader.hpp.

◆ XML_MATERIAL_ATTR

constexpr const char *const plask::GeometryReader::XML_MATERIAL_ATTR = "material"
staticconstexpr

name of the material attribute in XML

Definition at line 42 of file reader.hpp.

◆ XML_MATERIAL_BOTTOM_ATTR

constexpr const char *const plask::GeometryReader::XML_MATERIAL_BOTTOM_ATTR = "material-bottom"
staticconstexpr

name of the bottom material attribute in XML

Definition at line 44 of file reader.hpp.

◆ XML_MATERIAL_GRADING_ATTR

constexpr const char *const plask::GeometryReader::XML_MATERIAL_GRADING_ATTR = "material-shape"
staticconstexpr

name of the shape exponent attribute in XML

Definition at line 45 of file reader.hpp.

◆ XML_MATERIAL_TOP_ATTR

constexpr const char *const plask::GeometryReader::XML_MATERIAL_TOP_ATTR = "material-top"
staticconstexpr

name of the top material attribute in XML

Definition at line 43 of file reader.hpp.

◆ XML_NAME_ATTR

constexpr const char *const plask::GeometryReader::XML_NAME_ATTR = "name"
staticconstexpr

name of the object's/geometry's name attribute in XML

Definition at line 41 of file reader.hpp.


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