Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_table.cc
Go to the documentation of this file.
1/*
2# <<BEGIN-copyright>>
3# Copyright 2019, Lawrence Livermore National Security, LLC.
4# This file is part of the gidiplus package (https://github.com/LLNL/gidiplus).
5# gidiplus is licensed under the MIT license (see https://opensource.org/licenses/MIT).
6# SPDX-License-Identifier: MIT
7# <<END-copyright>>
8*/
9
10#include <GIDI.hpp>
11
12namespace GIDI {
13
14namespace Table {
15
16/*! \class Table
17 * Class for the GNDS **table** node.
18 */
19
20/* *********************************************************************************************************//**
21 * @param a_construction [in] Used to pass user options to the constructor.
22 * @param a_node [in] The **HAPI::Node** to be parsed and used to construct the XYs2d.
23 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
24 ***********************************************************************************************************/
25
26Table::Table( Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo ) :
27 Form( a_node, a_setupInfo, FormType::table ),
28 m_rows( static_cast<std::size_t>( a_node.attribute_as_int( GIDI_rowsChars ) ) ),
29 m_columns( static_cast<std::size_t>( a_node.attribute_as_int( GIDI_columnsChars ) ) ),
30 m_storageOrder( a_node.attribute_as_string( GIDI_storageOrderChars ) ),
31 m_columnHeaders( a_construction, GIDI_columnHeadersChars, GIDI_indexChars, a_node, a_setupInfo, PoPI::Database( ), PoPI::Database( ), parseColumnHeaders, nullptr ),
32 m_data( a_construction, a_node.child( GIDI_dataChars ), a_setupInfo ) {
33
34 if( m_storageOrder == "" ) m_storageOrder = GIDI_rowMajorChars;
35
36 m_columnHeaders.setAncestor( this );
37 m_data.setAncestor( this );
38}
39
40/* *********************************************************************************************************//**
41 ***********************************************************************************************************/
42
44
45}
46
47/* *********************************************************************************************************//**
48 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
49 *
50 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
51 * @param a_indent [in] The amount to indent *this* node.
52 ***********************************************************************************************************/
53
54void Table::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
55
56 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
57
58 std::string attributes;
59 attributes += a_writeInfo.addAttribute( GIDI_rowsChars, intToString( static_cast<int>( m_rows ) ) );
60 attributes += a_writeInfo.addAttribute( GIDI_columnsChars, intToString( static_cast<int>( m_columns ) ) );
61 if( m_storageOrder != GIDI_rowMajorChars ) attributes += a_writeInfo.addAttribute( GIDI_storageOrderChars, m_storageOrder );
62 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
63
64 m_columnHeaders.toXMLList( a_writeInfo, indent2 );
65 m_data.toXMLList( a_writeInfo, indent2 );
66
67 a_writeInfo.addNodeEnder( moniker( ) );
68}
69
70/*! \class Column
71 * Class for the GNDS **column** node that is a child of the **columnHeaders** node.
72 */
73
74/* *********************************************************************************************************//**
75 * @param a_construction [in] Used to pass user options to the constructor.
76 * @param a_node [in] The **HAPI::Node** to be parsed and used to construct the XYs2d.
77 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
78 * @param a_parent [in] The parent GIDI::Suite.
79 ***********************************************************************************************************/
80
81Column::Column( LUPI_maybeUnused Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent ) :
82 Form( a_node, a_setupInfo, FormType::column, a_parent ),
83 m_index( a_node.attribute_as_string( GIDI_indexChars ) ),
84 m_name( a_node.attribute_as_string( GIDI_nameChars ) ),
85 m_unit( a_node.attribute_as_string( GIDI_unitChars ) ),
86 m_types( a_node.attribute_as_string( GIDI_typesChars ) ) {
87
88}
89
90/* *********************************************************************************************************//**
91 ***********************************************************************************************************/
92
94
95}
96
97/* *********************************************************************************************************//**
98 * Set the *m_keyValue* per the *a_keyName* name. This method assumes that *a_keyName* is "label". Otherwise, it executes a throw.
99 *
100 * @param a_keyName [in] The name of the key whose value is set.
101 ***********************************************************************************************************/
102
103void Column::setKeyValue( std::string const &a_keyName ) const {
104
105 if( a_keyName != GIDI_indexChars ) throw Exception( "Form::setKeyValue: unsupported keyname \"" + a_keyName + "\"." );
106
107 m_keyValue = m_index;
108}
109
110/* *********************************************************************************************************//**
111 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
112 *
113 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
114 * @param a_indent [in] The amount to indent *this* node.
115 ***********************************************************************************************************/
116
117void Column::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
118
119 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
120
121 std::string attributes;
122 attributes += a_writeInfo.addAttribute( GIDI_indexChars, m_index );
123 attributes += a_writeInfo.addAttribute( GIDI_nameChars, m_name );
124 if( m_unit != "" ) attributes += a_writeInfo.addAttribute( GIDI_unitChars, m_unit );
125 if( m_types != "" ) attributes += a_writeInfo.addAttribute( GIDI_typesChars, m_types );
126 a_writeInfo.addNodeStarterEnder( a_indent, moniker( ), attributes );
127}
128
129/*! \class Data
130 * Class for the GNDS **data** node that is a child of the **table** node.
131 */
132
133/* *********************************************************************************************************//**
134 * @param a_construction [in] Used to pass user options to the constructor.
135 * @param a_node [in] The **HAPI::Node** to be parsed and used to construct the XYs2d.
136 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
137 ***********************************************************************************************************/
138
139Data::Data( LUPI_maybeUnused Construction::Settings const &a_construction, HAPI::Node const &a_node, LUPI_maybeUnused SetupInfo &a_setupInfo ) :
140 GUPI::Ancestry( GIDI_dataChars ),
141 m_sep( a_node.attribute_as_string( GIDI_sepChars ) ),
142 m_body( a_node.text().get() ) {
143
144 if( m_sep == "" ) m_sep = " ";
145}
146
147/* *********************************************************************************************************//**
148 ***********************************************************************************************************/
149
151
152}
153
154/* *********************************************************************************************************//**
155 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
156 *
157 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
158 * @param a_indent [in] The amount to indent *this* node.
159 ***********************************************************************************************************/
160
161void Data::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
162
163 std::string attributes;
164 if( m_sep != " " ) attributes += a_writeInfo.addAttribute( GIDI_sepChars, m_sep );
165 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
166
167 a_writeInfo.push_back( m_body );
168
169 a_writeInfo.addNodeEnder( moniker( ) );
170}
171
172} // End namespace Table.
173
174} // End namespace GIDI.
#define GIDI_columnHeadersChars
Definition GIDI.hpp:193
#define GIDI_rowsChars
Definition GIDI.hpp:191
#define GIDI_sepChars
Definition GIDI.hpp:198
#define GIDI_unitChars
Definition GIDI.hpp:439
#define GIDI_storageOrderChars
Definition GIDI.hpp:279
#define GIDI_columnsChars
Definition GIDI.hpp:192
#define GIDI_indexChars
Definition GIDI.hpp:437
#define GIDI_typesChars
Definition GIDI.hpp:196
#define GIDI_dataChars
Definition GIDI.hpp:197
#define GIDI_rowMajorChars
Definition GIDI.hpp:280
#define GIDI_nameChars
Definition GIDI.hpp:195
#define LUPI_maybeUnused
friend class Table::Column
Definition GIDI.hpp:639
Form(FormType a_type)
Definition GIDI_form.cc:25
void setKeyValue(std::string const &a_keyName) const
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
Data(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo)
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
Definition GIDI_table.cc:54
Table(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo)
Definition GIDI_table.cc:26
std::string const & moniker() const
Definition GUPI.hpp:102
void addNodeStarterEnder(std::string const &indent, std::string const &a_moniker, std::string const &a_attributes="")
Definition GUPI.hpp:57
void push_back(std::string const &a_line)
Definition GUPI.hpp:53
void addNodeEnder(std::string const &a_moniker)
Definition GUPI.hpp:59
std::string incrementalIndent(std::string const &indent)
Definition GUPI.hpp:52
void addNodeStarter(std::string const &indent, std::string const &a_moniker, std::string const &a_attributes="")
Definition GUPI.hpp:55
std::string addAttribute(std::string const &a_name, std::string const &a_value) const
Definition GUPI.hpp:60
Definition GIDI.hpp:32
FormType
Definition GIDI.hpp:118
Form * parseColumnHeaders(Construction::Settings const &a_construction, Suite *a_parent, HAPI::Node const &a_node, SetupInfo &a_setupInfo, PoPI::Database const &a_pops, PoPI::Database const &a_internalPoPs, std::string const &a_name, Styles::Suite const *a_styles)
std::string intToString(int a_value)
Definition GIDI_misc.cc:415
Definition GUPI.hpp:20
Definition PoPI.hpp:28