BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes
GMAD::Published< C > Class Template Reference

Class that provides introspection to its members. More...

#include <published.h>

Collaboration diagram for GMAD::Published< C >:
Collaboration graph

Public Member Functions

bool NameExists (const std::string &name) const
 
template<typename T >
Published< C >::template AttributeMap< T > & attribute_map () const
 

Protected Types

template<typename T >
using AttributeMap = typename std::unordered_map< std::string, T C::* >
 Define AttributeMap of string and class member pointer.
 

Protected Member Functions

template<typename T >
void publish (const std::string &name, T C::*mp)
 Make pointer to member from class C and type T with accessible with a name.
 
void set (C *instance, const C *instance2, const std::string &name)
 Set member with name of class instance to value of second instance.
 
template<typename T >
AttributeMap< T > & attribute_map () const
 Access method to static map for type T and class C.
 
template<typename T >
get (const C *instance, const std::string &name) const
 Get method for class C.
 
void set (C *instance, const std::string &name, double value)
 
void set (C *instance, const std::string &name, GMAD::Array *const &value)
 
template<typename T >
void set (C *instance, const std::string &name, const T &value)
 

Private Member Functions

template<typename T >
T C::* member (const std::string &name) const
 Access to member pointer.
 

Private Attributes

std::set< std::string > allNames
 A cache of all names defined through publish().
 

Detailed Description

template<typename C>
class GMAD::Published< C >

Class that provides introspection to its members.

In the parser the keywords in the ASCII files need to be matched to the correct member variable. However, C++ has no introspection ability. This class provides this artificially.

All members need to be added explicitly to a hash table (unordered_map) with the method publish. Note that the name can be different from the actual member name

adapted into a class from http://stackoverflow.com/questions/19557881/convert-string-character-to-class-member-method-in-c

Author
Jochem Snuverink

Definition at line 46 of file published.h.

Member Typedef Documentation

◆ AttributeMap

template<typename C >
template<typename T >
using GMAD::Published< C >::AttributeMap = typename std::unordered_map<std::string, T C::*>
protected

Define AttributeMap of string and class member pointer.

Definition at line 69 of file published.h.

Member Function Documentation

◆ attribute_map()

template<typename C >
template<typename T >
Published< C >::template AttributeMap< T > & GMAD::Published< C >::attribute_map ( ) const

Definition at line 254 of file published.h.

◆ get()

template<typename C >
template<typename T >
T GMAD::Published< C >::get ( const C *  instance,
const std::string &  name 
) const
protected

Get method for class C.

Definition at line 231 of file published.h.

◆ member()

template<typename C >
template<typename T >
T C::* GMAD::Published< C >::member ( const std::string &  name) const
private

Access to member pointer.

Definition at line 240 of file published.h.

◆ NameExists()

template<typename C >
bool GMAD::Published< C >::NameExists ( const std::string &  name) const
inline

Definition at line 49 of file published.h.

◆ publish()

template<typename C >
template<typename T >
void GMAD::Published< C >::publish ( const std::string &  name,
T C::*  mp 
)
protected

Make pointer to member from class C and type T with accessible with a name.

Definition at line 92 of file published.h.

◆ set() [1/4]

template<typename C >
void GMAD::Published< C >::set ( C *  instance,
const C *  instance2,
const std::string &  name 
)
protected

Set member with name of class instance to value of second instance.

Definition at line 172 of file published.h.

◆ set() [2/4]

template<typename C >
template<typename T >
void GMAD::Published< C >::set ( C *  instance,
const std::string &  name,
const T &  value 
)
protected

Set member with name of class instance to value. Throws std::runtime_error if not found

Definition at line 135 of file published.h.

◆ set() [3/4]

template<typename C >
void GMAD::Published< C >::set ( C *  instance,
const std::string &  name,
double  value 
)
protected

Set member with name of class instance to value. Throws std::runtime_error if not found

Definition at line 99 of file published.h.

Referenced by GMAD::Parameters::inherit_properties(), GMAD::Element::set(), GMAD::Element::set_value(), and GMAD::Parameters::set_value().

Here is the caller graph for this function:

◆ set() [4/4]

template<typename C >
void GMAD::Published< C >::set ( C *  instance,
const std::string &  name,
GMAD::Array *const &  value 
)
protected

Set member with name of class instance to value. Throws std::runtime_error if not found

Definition at line 147 of file published.h.

Field Documentation

◆ allNames

template<typename C >
std::set<std::string> GMAD::Published< C >::allNames
private

A cache of all names defined through publish().

Definition at line 85 of file published.h.


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