Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
HAPI_PugiXMLData.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 <stdlib.h>
11
12#include "HAPI.hpp"
13
14#ifdef HAPI_USE_PUGIXML
15namespace HAPI {
16
17/*
18=========================================================
19 *
20 * @return
21 */
23 m_node( pugi::xml_node() ),
24 m_length( 0 ),
25 m_dataRead( false ) {
26
27}
28/*
29=========================================================
30 *
31 * @param a_node
32 * @return
33 */
34PugiXMLData::PugiXMLData( pugi::xml_node a_node ) :
35 m_node( a_node ),
36 m_length( 0 ),
37 m_dataRead( false ) {
38
39}
40/*
41=========================================================
42*/
43PugiXMLData::~PugiXMLData( ) {
44
45}
46
47size_t PugiXMLData::length( ) const {
48
49 if (!m_dataRead)
50 throw "Can't access length until data is read!";
51 return m_length;
52
53}
54
55void PugiXMLData::getDoubles(nf_Buffer<double> &buffer)
56{
57 int64_t numberConverted;
58 char *endCharacter;
59 char const *text = m_node.text( ).get( );
60 double *dValues = nfu_stringToListOfDoubles( NULL, text, ' ', &numberConverted, &endCharacter, 0 );
61 if (dValues == NULL) throw "dValues = NULL";
62 if (*endCharacter != 0) throw "bad values string";
63 m_length = (size_t)numberConverted;
64 m_dataRead = true;
65
66 buffer.resize(m_length);
67 for (size_t i=0; i<m_length; i++)
68 buffer[i] = dValues[i];
69 free( dValues );
70}
71
72void PugiXMLData::getInts(nf_Buffer<int> &buffer)
73{
74 int64_t numberConverted;
75 char *endCharacter;
76 char const *text = m_node.text( ).get( );
77 int *iValues = nfu_stringToListOfInt32s( NULL, text, ' ', &numberConverted, &endCharacter );
78 if (iValues == NULL) throw "dValues = NULL";
79 if (*endCharacter != 0) throw "bad values string";
80 m_length = (size_t)numberConverted;
81 m_dataRead = true;
82
83 buffer.resize(m_length);
84 for (size_t i=0; i<m_length; i++)
85 buffer[i] = iValues[i];
86 free( iValues );
87}
88
89}
90#endif
void free(voidpf ptr)
Definition HAPI.hpp:34
double * nfu_stringToListOfDoubles(statusMessageReporting *smr, char const *str, char sep, int64_t *numberConverted, char **endCharacter, int useSystem_strtod)
int32_t * nfu_stringToListOfInt32s(statusMessageReporting *smr, char const *str, char sep, int64_t *numberConverted, char **endCharacter)