ATLAS Offline Software
Tools
LWHists
src
LWStrUtils.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
7
// //
8
// Header file for class LWStrUtils //
9
// //
10
// Description: Utilities for handling c-style char strings, //
11
// allocating with LWPools. //
12
// //
13
// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
14
// Initial version: May 2009 //
15
// //
17
18
#ifndef LWSTRUTILS_H
19
#define LWSTRUTILS_H
20
21
#include "
LWPools.h
"
22
#include <cassert>
23
#include <cstring>
24
#include <iostream>
25
26
class
LWStrUtils
{
27
public
:
28
static
const
unsigned
maxStringLength
= 1023;
//We don't want any crazy long strings...
29
static
uint16_t
strLength
(
const
char
*
c
);
30
static
void
setStringFromInput
(
const
char
*
input
,
char
*&
target
);
31
static
void
releaseString
(
char
*&
c
);
32
static
bool
stringsEqual
(
const
char
*
c1
,
const
char
*
c2
);
33
34
private
:
35
LWStrUtils
();
36
~LWStrUtils
();
37
};
38
40
// Inlines //
42
43
inline
uint16_t
LWStrUtils::strLength
(
const
char
*
c
) {
44
if
(!
c
)
45
return
0;
46
uint16_t
i
(0);
47
for
(;
i
<
maxStringLength
;++
i
) {
48
if
(
c
[
i
]==
'\0'
)
49
return
i
;
50
}
51
if
(
c
[
maxStringLength
]!=
'\0'
) {
52
std::cout<<
"LWHist::WARNING: String longer than "
<<
maxStringLength
<<
". Truncating."
<<std::endl;
53
std::cout<<
"LWHist::WARNING: String was:"
<<
c
<<std::endl;
54
}
55
return
maxStringLength
;
56
}
57
58
inline
void
LWStrUtils::setStringFromInput
(
const
char
*
input
,
char
*&
target
) {
59
if
(
target
)
60
releaseString
(
target
);
61
const
uint16_t
l
=
strLength
(
input
);
62
63
assert((
target
-
input
<0?-(
target
-
input
):
target
-
input
)>
l
+1);
64
target
=
LWPools::acquire
(
l
+1);
65
66
memcpy(
target
,
input
,
l
);
67
target
[
l
]=
'\0'
;
68
}
69
70
inline
void
LWStrUtils::releaseString
(
char
*&
c
)
71
{
72
if
(
c
) {
73
const
uint16_t
prevL =
strLength
(
c
);
74
LWPools::release
(
c
,prevL+1);
75
c
= 0;
76
}
77
}
78
79
inline
bool
LWStrUtils::stringsEqual
(
const
char
*
c1
,
const
char
*
c2
) {
80
return
c1
==
c2
|| (
c1
&&
c2
&&strncmp(
c1
,
c2
,
maxStringLength
)==0);
81
}
82
83
84
#endif
LWPools.h
LWStrUtils::releaseString
static void releaseString(char *&c)
Definition:
LWStrUtils.h:70
extractSporadic.c1
c1
Definition:
extractSporadic.py:134
LWStrUtils::stringsEqual
static bool stringsEqual(const char *c1, const char *c2)
Definition:
LWStrUtils.h:79
UploadAMITag.l
list l
Definition:
UploadAMITag.larcaf.py:158
LWPools::release
static void release(char *, unsigned length)
LWStrUtils::~LWStrUtils
~LWStrUtils()
LWStrUtils
Definition:
LWStrUtils.h:26
xAOD::uint16_t
setWord1 uint16_t
Definition:
eFexEMRoI_v1.cxx:88
lumiFormat.i
int i
Definition:
lumiFormat.py:92
LWPools::acquire
static char * acquire()
Definition:
LWPools.h:40
PlotPulseshapeFromCool.input
input
Definition:
PlotPulseshapeFromCool.py:106
LWStrUtils::setStringFromInput
static void setStringFromInput(const char *input, char *&target)
Definition:
LWStrUtils.h:58
LWStrUtils::strLength
static uint16_t strLength(const char *c)
Definition:
LWStrUtils.h:43
compileRPVLLRates.c2
c2
Definition:
compileRPVLLRates.py:361
LWStrUtils::LWStrUtils
LWStrUtils()
COOLRates.target
target
Definition:
COOLRates.py:1106
LWStrUtils::maxStringLength
static const unsigned maxStringLength
Definition:
LWStrUtils.h:28
python.compressB64.c
def c
Definition:
compressB64.py:93
Generated on Tue Jul 2 2024 21:20:58 for ATLAS Offline Software by
1.8.18