Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GUPI::Suite Class Reference

#include <GUPI.hpp>

Inheritance diagram for GUPI::Suite:

Public Types

typedef std::vector< Entry * > Entries
typedef Entries::iterator iterator
typedef Entries::const_iterator const_iterator

Public Member Functions

 Suite (std::string const &a_keyName)
 Suite (std::string const &a_moniker, std::string const &a_keyName)
 Suite (HAPI::Node const &a_node, std::string const &a_keyName, GUPI_parseSuite a_parseSuite)
 ~Suite ()
std::string const & keyName () const
std::size_t size () const
std::size_t operator[] (std::string const &a_label) const
iterator begin ()
const_iterator begin () const
iterator end ()
const_iterator end () const
template<typename T>
T * get (std::size_t a_Index)
template<typename T>
T const * get (std::size_t a_Index) const
template<typename T>
T * get (std::string const &a_label)
template<typename T>
T const * get (std::string const &a_label) const
void parse (HAPI::Node const &a_node, GUPI_parseSuite a_parseSuite)
void add (Entry *a_entry)
iterator find (std::string const &a_label)
const_iterator find (std::string const &a_label) const
bool has (std::string const &a_label) const
AncestryfindInAncestry3 (std::string const &a_item)
Ancestry const * findInAncestry3 (std::string const &a_item) const
std::vector< iteratorfindAllOfMoniker (std::string const &a_moniker)
std::vector< const_iteratorfindAllOfMoniker (std::string const &a_moniker) const
void toXMLList (WriteInfo &a_writeInfo, std::string const &a_indent="") const
void printEntryLabels (std::string const &a_header) const
Public Member Functions inherited from GUPI::Ancestry
 Ancestry (std::string const &a_moniker, std::string const &a_attribute="")
virtual ~Ancestry ()
Ancestryoperator= (Ancestry const &a_ancestry)
std::string const & moniker () const
void setMoniker (std::string const &a_moniker)
Ancestryancestor ()
Ancestry const * ancestor () const
void setAncestor (Ancestry *a_ancestor)
std::string attribute () const
Ancestryroot ()
Ancestry const * root () const
bool isChild (Ancestry *a_instance)
bool isParent (Ancestry *a_parent)
bool isRoot () const
AncestryfindInAncestry (std::string const &a_href)
Ancestry const * findInAncestry (std::string const &a_href) const
virtual LUPI_HOST void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
virtual std::string xlinkItemKey () const
std::string toXLink () const
void printXML () const

Additional Inherited Members

Static Public Member Functions inherited from GUPI::Ancestry
static std::string buildXLinkItemKey (std::string const &a_name, std::string const &a_key)

Detailed Description

This class is used to store a list (i.e., suite) of similar type GNDS nodes.

Definition at line 244 of file GUPI.hpp.

Member Typedef Documentation

◆ const_iterator

typedef Entries::const_iterator GUPI::Suite::const_iterator

Definition at line 267 of file GUPI.hpp.

◆ Entries

typedef std::vector<Entry *> GUPI::Suite::Entries

The typedef the the m_entries member.

Definition at line 247 of file GUPI.hpp.

◆ iterator

typedef Entries::iterator GUPI::Suite::iterator

Definition at line 266 of file GUPI.hpp.

Constructor & Destructor Documentation

◆ Suite() [1/3]

GUPI::Suite::Suite ( std::string const & a_keyName)

Definition at line 21 of file GUPI_suite.cc.

21 :
22 Ancestry( "" ),
23 m_keyName( a_keyName ) {
24
25}
Ancestry(std::string const &a_moniker, std::string const &a_attribute="")

◆ Suite() [2/3]

GUPI::Suite::Suite ( std::string const & a_moniker,
std::string const & a_keyName )
Parameters
a_moniker[in] The GNDS moniker for the Suite instance.
a_keyName[in] The name of the key for elements of this.

Definition at line 32 of file GUPI_suite.cc.

32 :
33 Ancestry( a_moniker ),
34 m_keyName( a_keyName ) {
35
36}

◆ Suite() [3/3]

GUPI::Suite::Suite ( HAPI::Node const & a_node,
std::string const & a_keyName,
GUPI_parseSuite a_parseSuite )
Parameters
a_node[in] The HAPI::Node to be parsed and used to construct the Product.
a_keyName[in] The name of the key for referencing up child nodes.
a_parseSuite[in] This function to call to parse each sub-node.

Definition at line 44 of file GUPI_suite.cc.

44 :
45 Ancestry( a_node.name( ) ),
46 m_keyName( a_keyName ) {
47
48 parse( a_node, a_parseSuite );
49}
void parse(HAPI::Node const &a_node, GUPI_parseSuite a_parseSuite)
Definition GUPI_suite.cc:66

◆ ~Suite()

GUPI::Suite::~Suite ( )

Definition at line 54 of file GUPI_suite.cc.

54 {
55
56 for( std::vector<Entry *>::const_iterator iter = m_entries.begin( ); iter < m_entries.end( ); ++iter ) delete *iter;
57}

Member Function Documentation

◆ add()

void GUPI::Suite::add ( Entry * a_form)

Adds the node a_form to this.

Parameters
a_form[in] The form to add.

Definition at line 96 of file GUPI_suite.cc.

96 {
97
98 std::size_t i1 = 0;
99
100 for( Suite::iterator iter = m_entries.begin( ); iter != m_entries.end( ); ++iter, ++i1 ) {
101 if( (*iter)->keyValue( ) == a_form->keyValue( ) ) {
102 m_entries[i1] = a_form;
103 a_form->setAncestor( this );
104 return;
105 }
106 }
107 m_map[a_form->keyValue( )] = m_entries.size( );
108 m_entries.push_back( a_form );
109 a_form->setAncestor( this );
110}
Entries::iterator iterator
Definition GUPI.hpp:266

Referenced by parse().

◆ begin() [1/2]

iterator GUPI::Suite::begin ( )
inline

The C++ begin iterator for this.

Definition at line 268 of file GUPI.hpp.

◆ begin() [2/2]

const_iterator GUPI::Suite::begin ( ) const
inline

The C++ const begin iterator for this.

Definition at line 269 of file GUPI.hpp.

◆ end() [1/2]

iterator GUPI::Suite::end ( )
inline

The C++ end iterator for this.

Definition at line 270 of file GUPI.hpp.

◆ end() [2/2]

const_iterator GUPI::Suite::end ( ) const
inline

The C++ const end iterator for this.

Definition at line 271 of file GUPI.hpp.

◆ find() [1/2]

Suite::iterator GUPI::Suite::find ( std::string const & a_keyValue)

Returns the iterator to the node with keyValue a_keyValue.

Parameters
a_keyValue[in] The keyValue of the node to find.
Returns
The iterator to the node with keyValue a_keyValue.

Definition at line 120 of file GUPI_suite.cc.

120 {
121
122 for( Suite::iterator iter = m_entries.begin( ); iter != m_entries.end( ); ++iter ) {
123 if( (*iter)->keyName( ) == a_keyValue ) return( iter );
124 }
125
126 return( m_entries.end( ) );
127}

Referenced by has().

◆ find() [2/2]

Suite::const_iterator GUPI::Suite::find ( std::string const & a_keyValue) const

Returns the iterator to the node with keyValue a_keyValue.

Parameters
a_keyValue[in] The keyValue of the node to find.
Returns
The iterator to the node with keyValue a_keyValue.

Definition at line 137 of file GUPI_suite.cc.

137 {
138
139 for( Suite::const_iterator iter = m_entries.begin( ); iter != m_entries.end( ); ++iter ) {
140 if( (*iter)->keyValue( ) == a_keyValue ) return( iter );
141 }
142
143 return( m_entries.end( ) );
144}
Entries::const_iterator const_iterator
Definition GUPI.hpp:267

◆ findAllOfMoniker() [1/2]

std::vector< Suite::iterator > GUPI::Suite::findAllOfMoniker ( std::string const & a_moniker)

Returns a list of iterators to the nodes in this that have GNDS moniker a_moniker.

Parameters
a_moniker[in] The moniker to search for.
Returns
List of iterators to the nodes in this that have moniker a_moniker.

Definition at line 154 of file GUPI_suite.cc.

154 {
155
156 std::vector<Suite::iterator> iters;
157
158 for( Suite::iterator iter = m_entries.begin( ); iter != m_entries.end( ); ++iter ) {
159 if( (*iter)->moniker( ) == a_moniker ) iters.push_back( iter );
160 }
161
162 return( iters );
163}

◆ findAllOfMoniker() [2/2]

std::vector< Suite::const_iterator > GUPI::Suite::findAllOfMoniker ( std::string const & a_moniker) const

Returns a list of iterators to the nodes in this that have GNDS moniker a_moniker.

Parameters
a_moniker[in] The moniker to search for.
Returns
List of iterators to the nodes in this that have moniker a_moniker.

Definition at line 173 of file GUPI_suite.cc.

173 {
174
175 std::vector<Suite::const_iterator> iters;
176
177 for( Suite::const_iterator iter = m_entries.begin( ); iter != m_entries.end( ); ++iter ) {
178 if( (*iter)->moniker( ) == a_moniker ) iters.push_back( iter );
179 }
180
181 return( iters );
182}

◆ findInAncestry3() [1/2]

Ancestry * GUPI::Suite::findInAncestry3 ( std::string const & a_item)
virtual

Used by Ancestry to tranverse GNDS nodes. This method returns a pointer to a derived class' a_item member or nullptr if none exists.

Parameters
a_item[in] The name of the class member whose pointer is to be return.
Returns
The pointer to the class member or nullptr if class does not have a member named a_item.

Implements GUPI::Ancestry.

Definition at line 191 of file GUPI_suite.cc.

191 {
192
193 std::size_t index( a_item.find( '=' ) ), lastQuote = a_item.size( ) - 2;
194
195 if( index == std::string::npos ) return( nullptr );
196 ++index;
197 if( index > lastQuote ) throw LUPI::Exception( "Suite::findInAncestry3: invalide xlink" );
198 if( a_item[index] != '\'' ) throw LUPI::Exception( "Suite::findInAncestry3: invalid xlink, missing '." );
199 ++index;
200 if( a_item[lastQuote] != '\'' ) throw LUPI::Exception( "Suite::findInAncestry3: invalid xlink, missing endl '." );
201
202 std::string keyValue( a_item.substr( index, lastQuote - index ) );
203
204 return( get<Ancestry>( keyValue ) );
205}
T * get(std::size_t a_Index)
Definition GUPI.hpp:301

◆ findInAncestry3() [2/2]

Ancestry const * GUPI::Suite::findInAncestry3 ( std::string const & a_item) const
virtual

Used by Ancestry to tranverse GNDS nodes. This method returns a pointer to a derived class' a_item member or nullptr if none exists.

Parameters
a_item[in] The name of the class member whose pointer is to be return.
Returns
The pointer to the class member or nullptr if class does not have a member named a_item.

Implements GUPI::Ancestry.

Definition at line 214 of file GUPI_suite.cc.

214 {
215
216 std::size_t index( a_item.find( '=' ) ), lastQuote = a_item.size( ) - 2;
217
218 if( index == std::string::npos ) return( nullptr );
219 ++index;
220 if( index > lastQuote ) throw LUPI::Exception( "Suite::findInAncestry3: invalide xlink" );
221 if( a_item[index] != '\'' ) throw LUPI::Exception( "Suite::findInAncestry3: invalid xlink, missing '." );
222 ++index;
223 if( a_item[lastQuote] != '\'' ) throw LUPI::Exception( "Suite::findInAncestry3: invalid xlink, missing endl '." );
224
225 std::string keyValue( a_item.substr( index, lastQuote - index ) );
226
227 return( get<Ancestry>( keyValue ) );
228}

◆ get() [1/4]

template<typename T>
T * GUPI::Suite::get ( std::size_t a_index)

Returns the node at index a_index.

Parameters
a_index[in] The index of the node to return.
Returns
The node at index a_index.

Definition at line 301 of file GUPI.hpp.

301 {
302
303 Entry *entry = m_entries[a_index];
304 T *object = dynamic_cast<T *>( entry );
305
306 if( object == nullptr ) throw LUPI::Exception( "GIDI::Suite::get( std::size_t ): invalid cast" );
307
308 return( object );
309}

Referenced by findInAncestry3(), and findInAncestry3().

◆ get() [2/4]

template<typename T>
T const * GUPI::Suite::get ( std::size_t a_Index) const

◆ get() [3/4]

template<typename T>
T * GUPI::Suite::get ( std::string const & a_label)

Returns the node with label a_label.

Parameters
a_label[in] The label of the node to return.
Returns
The node with label a_label.

Definition at line 337 of file GUPI.hpp.

337 {
338
339 auto index = (*this)[a_label];
340 Entry *entry = m_entries[index];
341 T *object = dynamic_cast<T *>( entry );
342
343 if( object == nullptr ) throw LUPI::Exception( "GIDI::Suite::get( std::string const & ): invalid cast" );
344
345 return( object );
346}

◆ get() [4/4]

template<typename T>
T const * GUPI::Suite::get ( std::string const & a_label) const

◆ has()

bool GUPI::Suite::has ( std::string const & a_label) const
inline

Definition at line 282 of file GUPI.hpp.

282{ return( find( a_label ) != m_entries.end( ) ); }
iterator find(std::string const &a_label)

◆ keyName()

std::string const & GUPI::Suite::keyName ( ) const
inline

Returns a const reference to the m_keyName member.

Definition at line 262 of file GUPI.hpp.

◆ operator[]()

std::size_t GUPI::Suite::operator[] ( std::string const & a_keyValue) const

Returns the index of the node in this that has keyValue a_keyValue.

Returns
[in] The index of the node with keyValue a_keyValue in this.

Definition at line 80 of file GUPI_suite.cc.

80 {
81
82 auto const iter = m_map.find( a_keyValue );
83 if( iter == m_map.end( ) ) {
84 throw LUPI::Exception( "form '" + a_keyValue + "' not in database." );
85 }
86
87 return( iter->second );
88}

◆ parse()

void GUPI::Suite::parse ( HAPI::Node const & a_node,
GUPI_parseSuite a_parseSuite )

This methods parses all the child nodes of a_node.

Parameters
a_node[in] The HAPI::Node to be parsed and used to construct the Product.
a_parseSuite[in] This function to call to parse each sub-node.

Definition at line 66 of file GUPI_suite.cc.

66 {
67
68 for( HAPI::Node child = a_node.first_child( ); !child.empty( ); child.to_next_sibling( ) ) {
69 Entry *form = a_parseSuite( this, child );
70 if( form != nullptr ) add( form );
71 }
72}
void add(Entry *a_entry)
Definition GUPI_suite.cc:96

Referenced by Suite().

◆ printEntryLabels()

void GUPI::Suite::printEntryLabels ( std::string const & a_header) const

Prints the list of node keyValues to std::cout.

Parameters
a_header[in] A string printed before the list of keyValues is printed.

Definition at line 257 of file GUPI_suite.cc.

257 {
258
259 std::cout << a_header << ": size = " << size( ) << std::endl;
260
261 for( Suite::const_iterator iter = m_entries.begin( ); iter != m_entries.end( ); ++iter )
262 std::cout << " " << (*iter)->keyValue( ) << std::endl;
263}
std::size_t size() const
Definition GUPI.hpp:263

◆ size()

std::size_t GUPI::Suite::size ( ) const
inline

Returns the number of node contained by this.

Definition at line 263 of file GUPI.hpp.

Referenced by printEntryLabels(), and toXMLList().

◆ toXMLList()

void GUPI::Suite::toXMLList ( WriteInfo & a_writeInfo,
std::string const & a_indent = "" ) const
virtual

Fills the argument a_writeInfo with the XML lines that represent this. Recursively enters each sub-node.

Parameters
a_writeInfo[in/out] Instance containing incremental indentation and other information and stores the appended lines.
a_indent[in] The amount to indent this node.

Reimplemented from GUPI::Ancestry.

Definition at line 237 of file GUPI_suite.cc.

237 {
238
239 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
240
241 if( size( ) == 0 ) return;
242
243 std::string XMLLine( a_indent + "<" + moniker( ) + ">" );
244 a_writeInfo.push_back( XMLLine );
245
246 for( Suite::const_iterator iter = m_entries.begin( ); iter != m_entries.end( ); ++iter ) (*iter)->toXMLList( a_writeInfo, indent2 );
247
248 a_writeInfo.addNodeEnder( moniker( ) );
249}
std::string const & moniker() const
Definition GUPI.hpp:102

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