ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tools
XMLCoreParser
src
XMLParserUtilities.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
3
*/
10
11
#ifndef XMLCoreParser_XMLParserUtilities_H
12
#define XMLCoreParser_XMLParserUtilities_H
13
14
#include <expat.h>
15
#include <cstdlib>
//getenv
16
#include <string>
17
#include <source_location>
18
#include <memory>
19
#include <iostream>
20
21
22
namespace
XmlParser
{
24
std::string
25
xmlFileName
(
const
std::string & fname,
const
std::string & prefix=
""
);
26
28
inline
bool
29
debug_enabled
() {
30
static
const
bool
enabled = (std::getenv(
"XMLDEBUG"
) !=
nullptr
);
31
return
enabled;
32
}
33
35
inline
std::string
36
label
(
const
std::source_location loc = std::source_location::current()){
37
return
loc.function_name();
38
}
39
41
struct
XMLParserDeleter
{
42
void
operator()
(XML_Parser p)
const
noexcept
{
43
if
(p) {
44
XML_ParserFree(p);
45
}
46
}
47
};
48
49
using
XMLParserPtr
= std::unique_ptr<std::remove_pointer_t<XML_Parser>,
XMLParserDeleter
>;
50
52
inline
XMLParserPtr
make_parser
(){
53
XML_Parser p = XML_ParserCreate(
nullptr
);
54
if
(!p) {
55
std::cout <<
"ExpatCoreParser::Couldn't allocate memory for parser"
<< std::endl;
56
std::abort();
57
}
58
return
XMLParserPtr
{p};
59
}
60
61
inline
std::string
62
rtrim
(
const
XML_Char* s,
int
len){
63
while
(len > 0 && s[len - 1] ==
'\n'
) {
64
--len;
65
}
66
return
(len > 0) ? std::string{s,
static_cast<
std::size_t
>
(len)} : std::string{};
67
}
68
}
69
70
71
#endif
XmlParser
Definition
XMLParserUtilities.cxx:17
XmlParser::xmlFileName
std::string xmlFileName(const std::string &fname, const std::string &prefix)
find the xml file locally or on the datapath, return the full filename
Definition
XMLParserUtilities.cxx:19
XmlParser::debug_enabled
bool debug_enabled()
true if XML debug mode is enabled in the environment
Definition
XMLParserUtilities.h:29
XmlParser::make_parser
XMLParserPtr make_parser()
Create an RAII XMLParser pointer.
Definition
XMLParserUtilities.h:52
XmlParser::XMLParserPtr
std::unique_ptr< std::remove_pointer_t< XML_Parser >, XMLParserDeleter > XMLParserPtr
RAII XMLParser pointer.
Definition
XMLParserUtilities.h:49
XmlParser::label
std::string label(const std::source_location loc=std::source_location::current())
report function name in a string, for debugging
Definition
XMLParserUtilities.h:36
XmlParser::rtrim
std::string rtrim(const XML_Char *s, int len)
Trim newline from end of a XML_Char * , return the trimmed string as std::string.
Definition
XMLParserUtilities.h:62
XmlParser::XMLParserDeleter
deleter for a unique_ptr<XML_Parser>
Definition
XMLParserUtilities.h:41
XmlParser::XMLParserDeleter::operator()
void operator()(XML_Parser p) const noexcept
Definition
XMLParserUtilities.h:42
Generated on
for ATLAS Offline Software by
1.17.0