Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
HAPI_Node.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 <HAPI.hpp>
11#include <LUPI.hpp>
12
13namespace HAPI {
14
15/*
16=========================================================
17 *
18 * @return
19 */
21 m_node(NULL) {
22
23}
24/*
25=========================================================
26 *
27 * @param a_node
28 * @return
29 */
31 m_node(a_node) {
32
33}
34
35/* *********************************************************************************************************//**
36 * Copy constructor.
37 *
38 * @param a_node [In] The node to copy.
39 ***********************************************************************************************************/
40
41Node::Node( Node const &a_node ) :
42 m_node( nullptr ) {
43
44#ifdef HAPI_USE_PUGIXML
45 if( a_node.m_node->type( ) == NodeInteralType::pugiXML ) {
46 m_node = new PugiXMLNode( static_cast<PugiXMLNode const &>( *a_node.m_node ) );
47 }
48#endif
49#ifdef HAPI_USE_HDF5
50 if( a_node.m_node->type( ) == NodeInteralType::HDF5 ) {
51 m_node = new HDFNode( static_cast<HDFNode const &>( *a_node.m_node ) );
52 }
53#endif
54 if( m_node == nullptr ) throw LUPI::Exception( "Unsupported m_node type." );
55}
56
57/*
58=========================================================
59*/
61
62 delete m_node;
63
64}
65/*
66============================================================
67===================== get child element ====================
68============================================================
69 *
70 * @return
71 */
72Node Node::child(char const *a_name) const {
73
74 if (NULL == m_node)
75 return Node();
76 return Node( m_node->child( a_name ) );
77
78}
79/*
80=========================================================
81*/
83
84 if (NULL == m_node)
85 return Node();
86 return Node( m_node->first_child( ) );
87
88}
89/*
90============================================================
91===================== get sibling element ==================
92============================================================
93 *
94 * @return
95 */
97
98 if (NULL == m_node)
99 return Node();
100 Node_internal *sibling = m_node->next_sibling( );
101 delete m_node;
102 return Node( sibling );
103
104}
105/*
106============================================================
107============ update self to point to next sibling ==========
108============================================================
109 *
110 * @return
111 */
113
114 m_node->to_next_sibling( );
115
116}
117/*
118============================================================
119===================== assignment operator ==================
120============================================================
121 */
122Node& Node::operator=(const Node &other) {
123
124 if (NULL != other.m_node)
125 this->m_node = other.m_node->copy();
126 return *this;
127
128}
129/*
130============================================================
131===================== get tag name =========================
132============================================================
133 *
134 * @return
135 */
136std::string Node::name() const {
137
138 if (NULL == m_node)
139 return std::string("");
140 return m_node->name();
141
142}
143/*
144============================================================
145================== test for empty node =====================
146============================================================
147 *
148 * @return
149 */
150bool Node::empty() const {
151
152 if (NULL == m_node)
153 return true;
154 return m_node->empty();
155
156}
157/*
158============================================================
159======================= text data ==========================
160============================================================
161 *
162 * @return
163 */
165
166 if (NULL == m_node)
167 return Text();
168 return m_node->text();
169
170}
171/*
172============================================================
173===================== numeric data =========================
174============================================================
175 *
176 * @return
177 */
179
180 if (NULL == m_node)
181 return Data();
182 return Data( m_node->data() );
183
184}
185
186}
NodeInteralType type() const
Definition HAPI.hpp:119
virtual Node_internal * next_sibling()=0
virtual Node_internal * copy()=0
Node next_sibling() const
Definition HAPI_Node.cc:96
std::string name() const
Definition HAPI_Node.cc:136
bool empty() const
Definition HAPI_Node.cc:150
void to_next_sibling() const
Definition HAPI_Node.cc:112
Data data() const
Definition HAPI_Node.cc:178
Node & operator=(const Node &other)
Definition HAPI_Node.cc:122
Node first_child() const
Definition HAPI_Node.cc:82
Node child(const char *name) const
Definition HAPI_Node.cc:72
Text text() const
Definition HAPI_Node.cc:164
Definition HAPI.hpp:34