Bug Summary

File:cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/boost/algorithm/string/detail/classification.hpp
Warning:line 141, column 17
Potential memory leak

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name AlignmentGeneratorModule.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/data/b2soft/buildbot/development/build -fcoverage-compilation-dir=/data/b2soft/buildbot/development/build -resource-dir /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++ -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/x86_64-redhat-linux -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/backward -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/python3.12 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/CLHEP -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/Geant4 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/root -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/belle_legacy -I include/ -D _PACKAGE_="alignment" -D G4UI_USE_TCSH -D RaveDllExport= -D HAS_SQLITE -D HAS_CALLGRIND -I include -I /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/libxml2 -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++ -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/x86_64-redhat-linux -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/backward -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-missing-braces -Wno-unused-command-line-argument -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /scan_build/2026-05-31-004316-385593-1 -x c++ alignment/modules/AlignmentGenerator/src/AlignmentGeneratorModule.cc

alignment/modules/AlignmentGenerator/src/AlignmentGeneratorModule.cc

1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <alignment/modules/AlignmentGenerator/AlignmentGeneratorModule.h>
10
11#include <alignment/dbobjects/VXDAlignment.h>
12#include <framework/database/Database.h>
13#include <vxd/dataobjects/VxdID.h>
14#include <vxd/geometry/GeoCache.h>
15
16#include <TRandom.h>
17
18#include <boost/algorithm/string.hpp>
19
20using namespace Belle2;
21
22//-----------------------------------------------------------------
23// Register the Module
24//-----------------------------------------------------------------
25REG_MODULE(AlignmentGenerator)namespace { struct ModuleProxyAlignmentGenerator: public ModuleProxyBase
{ ModuleProxyAlignmentGenerator(): ModuleProxyBase("AlignmentGenerator"
, "" "alignment") {} virtual ::Belle2::Module* createInstance
() const override final { return new AlignmentGeneratorModule
(); } } proxyAlignmentGeneratorModule; }
;
26
27//-----------------------------------------------------------------
28// Implementation
29//-----------------------------------------------------------------
30
31AlignmentGeneratorModule::AlignmentGeneratorModule() : Module()
32{
33 std::vector<std::string> emptyData;
34 std::vector<int> infiniteIov{0, 0, -1, -1};
35
36 setPropertyFlags(c_ParallelProcessingCertified);
37 // Set module properties
38 setDescription("Generates VXD alignment."
39 "Generated alignment overrides any existing one in reconstruction if done with this module. "
40 "The generated object can also be stored as payload in the (local) DB, to keep track of it."
41 );
42
43 // Parameter definitions
44 addParam("payloadIov", m_payloadIov, "IoV of the payload to be created. List "
45 "of four numbers: first experiment, first run, last experiment, "
46 "last run", infiniteIov);
47 addParam("createPayload", m_createPayload, "Store the generated alignment as payload in DB?", bool(false));
48 addParam("data", m_data,
49 "Data for alignment in format ['layer.ladder.sensor, parameter_no, distribution=fix|gaus|uniform, value', ...]",
50 emptyData);
51 addParam("payloadName", m_payloadName, "Name of generated alignment payload in database. If empty, default is used",
52 std::string(""));
53
54}
55
56void AlignmentGeneratorModule::initialize()
57{
58 auto data = new VXDAlignment();
59
60 for (auto& id : VXD::GeoCache::getInstance().getListOfSensors()) {
61 for (auto paramData : m_data) {
62 std::vector<std::string> paramDataParts;
63 boost::algorithm::split(paramDataParts, paramData, boost::is_any_of(","));
7
Calling 'split<std::vector<std::basic_string<char>>, std::basic_string<char> &, boost::algorithm::detail::is_any_ofF<char>>'
64 if (paramDataParts.size() != 4)
1
Assuming the condition is false
2
Taking false branch
65 B2FATAL("Error parsing alignment data.")do { { LogVariableStream varStream; varStream << "Error parsing alignment data."
; Belle2::LogSystem::Instance().sendMessage(Belle2::LogMessage
(Belle2::LogConfig::c_Fatal, std::move(varStream), "alignment"
, __PRETTY_FUNCTION__, "alignment/modules/AlignmentGenerator/src/AlignmentGeneratorModule.cc"
, 65, 0)); }; exit(1); } while(false)
;
66
67 boost::trim(paramDataParts[0]);
68 boost::trim(paramDataParts[1]);
69 boost::trim(paramDataParts[2]);
70 boost::trim(paramDataParts[3]);
71
72 VxdID idMask(paramDataParts[0]);
73 int paramID = std::stoi(paramDataParts[1]);
74 std::string distro = paramDataParts[2];
75 double value = std::stod(paramDataParts[3]);
76
77 double generatedValue = 0.;
78 if (distro == "fix") generatedValue = value;
3
Taking true branch
79 else if (distro == "gaus") generatedValue = gRandom->Gaus(0., value);
80 else if (distro == "uniform") generatedValue = gRandom->Uniform(-value, value);
81 else B2FATAL("Unknown distribution for parameter generation: " << distro << " Valid options are fix|gaus|uniform")do { { LogVariableStream varStream; varStream << "Unknown distribution for parameter generation: "
<< distro << " Valid options are fix|gaus|uniform"
; Belle2::LogSystem::Instance().sendMessage(Belle2::LogMessage
(Belle2::LogConfig::c_Fatal, std::move(varStream), "alignment"
, __PRETTY_FUNCTION__, "alignment/modules/AlignmentGenerator/src/AlignmentGeneratorModule.cc"
, 81, 0)); }; exit(1); } while(false)
;
82
83 if (idMask.getLayerNumber() && id.getLayerNumber() != idMask.getLayerNumber()) continue;
4
Assuming the condition is false
84 if (idMask.getLadderNumber() && id.getLadderNumber() != idMask.getLadderNumber()) continue;
5
Assuming the condition is false
85 if (idMask.getSensorNumber() && id.getSensorNumber() != idMask.getSensorNumber()) continue;
6
Assuming the condition is false
86
87 data->set(id, paramID, generatedValue);
88 }
89 }
90
91 std::string name = (m_payloadName == "") ? DBStore::objectName<VXDAlignment>("") : m_payloadName;
92
93 B2WARNING("Overriding VXDAlignment in DBStore with new object. This will affect reconstruction if done in this job.")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Warning, 0, "alignment")) { { LogVariableStream varStream
; varStream << "Overriding VXDAlignment in DBStore with new object. This will affect reconstruction if done in this job."
; Belle2::LogSystem::Instance().sendMessage(Belle2::LogMessage
(Belle2::LogConfig::c_Warning, std::move(varStream), "alignment"
, __PRETTY_FUNCTION__, "alignment/modules/AlignmentGenerator/src/AlignmentGeneratorModule.cc"
, 93, 0)); }; } } while(false)
;
94 DBStore::Instance().addConstantOverride(name, new VXDAlignment(*data));
95
96 if (m_createPayload) {
97 if (m_payloadIov.size() != 4)
98 B2FATAL("Payload IoV incorrect. Should be list of four numbers.")do { { LogVariableStream varStream; varStream << "Payload IoV incorrect. Should be list of four numbers."
; Belle2::LogSystem::Instance().sendMessage(Belle2::LogMessage
(Belle2::LogConfig::c_Fatal, std::move(varStream), "alignment"
, __PRETTY_FUNCTION__, "alignment/modules/AlignmentGenerator/src/AlignmentGeneratorModule.cc"
, 98, 0)); }; exit(1); } while(false)
;
99
100 B2INFO("Storing VXDAlignment payload in DB.")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "alignment")) { { LogVariableStream varStream
; varStream << "Storing VXDAlignment payload in DB."; Belle2
::LogSystem::Instance().sendMessage(Belle2::LogMessage(Belle2
::LogConfig::c_Info, std::move(varStream), "alignment", __PRETTY_FUNCTION__
, "alignment/modules/AlignmentGenerator/src/AlignmentGeneratorModule.cc"
, 100, 0)); }; } } while(false)
;
101 IntervalOfValidity iov(m_payloadIov[0], m_payloadIov[1], m_payloadIov[2], m_payloadIov[3]);
102 Database::Instance().storeData(name, data, iov);
103 }
104
105}
106
107

/cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/boost/algorithm/string/trim.hpp

1// Boost string_algo library trim.hpp header file ---------------------------//
2
3// Copyright Pavol Droba 2002-2003.
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9// See http://www.boost.org/ for updates, documentation, and revision history.
10
11#ifndef BOOST_STRING_TRIM_HPP
12#define BOOST_STRING_TRIM_HPP
13
14#include <boost/algorithm/string/config.hpp>
15
16#include <boost/range/begin.hpp>
17#include <boost/range/end.hpp>
18#include <boost/range/const_iterator.hpp>
19#include <boost/range/as_literal.hpp>
20#include <boost/range/iterator_range_core.hpp>
21
22#include <boost/algorithm/string/detail/trim.hpp>
23#include <boost/algorithm/string/classification.hpp>
24#include <locale>
25
26/*! \file
27 Defines trim algorithms.
28 Trim algorithms are used to remove trailing and leading spaces from a
29 sequence (string). Space is recognized using given locales.
30
31 Parametric (\c _if) variants use a predicate (functor) to select which characters
32 are to be trimmed..
33 Functions take a selection predicate as a parameter, which is used to determine
34 whether a character is a space. Common predicates are provided in classification.hpp header.
35
36*/
37
38namespace boost {
39 namespace algorithm {
40
41 // left trim -----------------------------------------------//
42
43
44 //! Left trim - parametric
45 /*!
46 Remove all leading spaces from the input.
47 The supplied predicate is used to determine which characters are considered spaces.
48 The result is a trimmed copy of the input. It is returned as a sequence
49 or copied to the output iterator
50
51 \param Output An output iterator to which the result will be copied
52 \param Input An input range
53 \param IsSpace A unary predicate identifying spaces
54 \return
55 An output iterator pointing just after the last inserted character or
56 a copy of the input
57
58 \note The second variant of this function provides the strong exception-safety guarantee
59 */
60 template<typename OutputIteratorT, typename RangeT, typename PredicateT>
61 inline OutputIteratorT trim_left_copy_if(
62 OutputIteratorT Output,
63 const RangeT& Input,
64 PredicateT IsSpace)
65 {
66 iterator_range<BOOST_STRING_TYPENAMEtypename range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input));
67
68 std::copy(
69 ::boost::algorithm::detail::trim_begin(
70 ::boost::begin(lit_range),
71 ::boost::end(lit_range),
72 IsSpace ),
73 ::boost::end(lit_range),
74 Output);
75
76 return Output;
77 }
78
79 //! Left trim - parametric
80 /*!
81 \overload
82 */
83 template<typename SequenceT, typename PredicateT>
84 inline SequenceT trim_left_copy_if(const SequenceT& Input, PredicateT IsSpace)
85 {
86 return SequenceT(
87 ::boost::algorithm::detail::trim_begin(
88 ::boost::begin(Input),
89 ::boost::end(Input),
90 IsSpace ),
91 ::boost::end(Input));
92 }
93
94 //! Left trim - parametric
95 /*!
96 Remove all leading spaces from the input.
97 The result is a trimmed copy of the input.
98
99 \param Input An input sequence
100 \param Loc a locale used for 'space' classification
101 \return A trimmed copy of the input
102
103 \note This function provides the strong exception-safety guarantee
104 */
105 template<typename SequenceT>
106 inline SequenceT trim_left_copy(const SequenceT& Input, const std::locale& Loc=std::locale())
107 {
108 return
109 ::boost::algorithm::trim_left_copy_if(
110 Input,
111 is_space(Loc));
112 }
113
114 //! Left trim
115 /*!
116 Remove all leading spaces from the input. The supplied predicate is
117 used to determine which characters are considered spaces.
118 The input sequence is modified in-place.
119
120 \param Input An input sequence
121 \param IsSpace A unary predicate identifying spaces
122 */
123 template<typename SequenceT, typename PredicateT>
124 inline void trim_left_if(SequenceT& Input, PredicateT IsSpace)
125 {
126 Input.erase(
127 ::boost::begin(Input),
128 ::boost::algorithm::detail::trim_begin(
129 ::boost::begin(Input),
130 ::boost::end(Input),
131 IsSpace));
132 }
133
134 //! Left trim
135 /*!
136 Remove all leading spaces from the input.
137 The Input sequence is modified in-place.
138
139 \param Input An input sequence
140 \param Loc A locale used for 'space' classification
141 */
142 template<typename SequenceT>
143 inline void trim_left(SequenceT& Input, const std::locale& Loc=std::locale())
144 {
145 ::boost::algorithm::trim_left_if(
146 Input,
147 is_space(Loc));
148 }
149
150 // right trim -----------------------------------------------//
151
152 //! Right trim - parametric
153 /*!
154 Remove all trailing spaces from the input.
155 The supplied predicate is used to determine which characters are considered spaces.
156 The result is a trimmed copy of the input. It is returned as a sequence
157 or copied to the output iterator
158
159 \param Output An output iterator to which the result will be copied
160 \param Input An input range
161 \param IsSpace A unary predicate identifying spaces
162 \return
163 An output iterator pointing just after the last inserted character or
164 a copy of the input
165
166 \note The second variant of this function provides the strong exception-safety guarantee
167 */
168 template<typename OutputIteratorT, typename RangeT, typename PredicateT>
169 inline OutputIteratorT trim_right_copy_if(
170 OutputIteratorT Output,
171 const RangeT& Input,
172 PredicateT IsSpace )
173 {
174 iterator_range<BOOST_STRING_TYPENAMEtypename range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input));
175
176 std::copy(
177 ::boost::begin(lit_range),
178 ::boost::algorithm::detail::trim_end(
179 ::boost::begin(lit_range),
180 ::boost::end(lit_range),
181 IsSpace ),
182 Output );
183
184 return Output;
185 }
186
187 //! Right trim - parametric
188 /*!
189 \overload
190 */
191 template<typename SequenceT, typename PredicateT>
192 inline SequenceT trim_right_copy_if(const SequenceT& Input, PredicateT IsSpace)
193 {
194 return SequenceT(
195 ::boost::begin(Input),
196 ::boost::algorithm::detail::trim_end(
197 ::boost::begin(Input),
198 ::boost::end(Input),
199 IsSpace)
200 );
201 }
202
203 //! Right trim
204 /*!
205 Remove all trailing spaces from the input.
206 The result is a trimmed copy of the input
207
208 \param Input An input sequence
209 \param Loc A locale used for 'space' classification
210 \return A trimmed copy of the input
211
212 \note This function provides the strong exception-safety guarantee
213 */
214 template<typename SequenceT>
215 inline SequenceT trim_right_copy(const SequenceT& Input, const std::locale& Loc=std::locale())
216 {
217 return
218 ::boost::algorithm::trim_right_copy_if(
219 Input,
220 is_space(Loc));
221 }
222
223
224 //! Right trim - parametric
225 /*!
226 Remove all trailing spaces from the input.
227 The supplied predicate is used to determine which characters are considered spaces.
228 The input sequence is modified in-place.
229
230 \param Input An input sequence
231 \param IsSpace A unary predicate identifying spaces
232 */
233 template<typename SequenceT, typename PredicateT>
234 inline void trim_right_if(SequenceT& Input, PredicateT IsSpace)
235 {
236 Input.erase(
237 ::boost::algorithm::detail::trim_end(
238 ::boost::begin(Input),
239 ::boost::end(Input),
240 IsSpace ),
241 ::boost::end(Input)
242 );
243 }
244
245
246 //! Right trim
247 /*!
248 Remove all trailing spaces from the input.
249 The input sequence is modified in-place.
250
251 \param Input An input sequence
252 \param Loc A locale used for 'space' classification
253 */
254 template<typename SequenceT>
255 inline void trim_right(SequenceT& Input, const std::locale& Loc=std::locale())
256 {
257 ::boost::algorithm::trim_right_if(
258 Input,
259 is_space(Loc) );
260 }
261
262 // both side trim -----------------------------------------------//
263
264 //! Trim - parametric
265 /*!
266 Remove all trailing and leading spaces from the input.
267 The supplied predicate is used to determine which characters are considered spaces.
268 The result is a trimmed copy of the input. It is returned as a sequence
269 or copied to the output iterator
270
271 \param Output An output iterator to which the result will be copied
272 \param Input An input range
273 \param IsSpace A unary predicate identifying spaces
274 \return
275 An output iterator pointing just after the last inserted character or
276 a copy of the input
277
278 \note The second variant of this function provides the strong exception-safety guarantee
279 */
280 template<typename OutputIteratorT, typename RangeT, typename PredicateT>
281 inline OutputIteratorT trim_copy_if(
282 OutputIteratorT Output,
283 const RangeT& Input,
284 PredicateT IsSpace)
285 {
286 iterator_range<BOOST_STRING_TYPENAMEtypename range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input));
287
288 BOOST_STRING_TYPENAMEtypename
289 range_const_iterator<RangeT>::type TrimEnd=
290 ::boost::algorithm::detail::trim_end(
291 ::boost::begin(lit_range),
292 ::boost::end(lit_range),
293 IsSpace);
294
295 std::copy(
296 detail::trim_begin(
297 ::boost::begin(lit_range), TrimEnd, IsSpace),
298 TrimEnd,
299 Output
300 );
301
302 return Output;
303 }
304
305 //! Trim - parametric
306 /*!
307 \overload
308 */
309 template<typename SequenceT, typename PredicateT>
310 inline SequenceT trim_copy_if(const SequenceT& Input, PredicateT IsSpace)
311 {
312 BOOST_STRING_TYPENAMEtypename
313 range_const_iterator<SequenceT>::type TrimEnd=
314 ::boost::algorithm::detail::trim_end(
315 ::boost::begin(Input),
316 ::boost::end(Input),
317 IsSpace);
318
319 return SequenceT(
320 detail::trim_begin(
321 ::boost::begin(Input),
322 TrimEnd,
323 IsSpace),
324 TrimEnd
325 );
326 }
327
328 //! Trim
329 /*!
330 Remove all leading and trailing spaces from the input.
331 The result is a trimmed copy of the input
332
333 \param Input An input sequence
334 \param Loc A locale used for 'space' classification
335 \return A trimmed copy of the input
336
337 \note This function provides the strong exception-safety guarantee
338 */
339 template<typename SequenceT>
340 inline SequenceT trim_copy( const SequenceT& Input, const std::locale& Loc=std::locale() )
341 {
342 return
343 ::boost::algorithm::trim_copy_if(
344 Input,
345 is_space(Loc) );
346 }
347
348 //! Trim
349 /*!
350 Remove all leading and trailing spaces from the input.
351 The supplied predicate is used to determine which characters are considered spaces.
352 The input sequence is modified in-place.
353
354 \param Input An input sequence
355 \param IsSpace A unary predicate identifying spaces
356 */
357 template<typename SequenceT, typename PredicateT>
358 inline void trim_if(SequenceT& Input, PredicateT IsSpace)
359 {
360 ::boost::algorithm::trim_right_if( Input, IsSpace );
361 ::boost::algorithm::trim_left_if( Input, IsSpace );
362 }
363
364 //! Trim
365 /*!
366 Remove all leading and trailing spaces from the input.
367 The input sequence is modified in-place.
368
369 \param Input An input sequence
370 \param Loc A locale used for 'space' classification
371 */
372 template<typename SequenceT>
373 inline void trim(SequenceT& Input, const std::locale& Loc=std::locale())
374 {
375 ::boost::algorithm::trim_if(
376 Input,
377 is_space( Loc ) );
378 }
379
380 } // namespace algorithm
381
382 // pull names to the boost namespace
383 using algorithm::trim_left;
384 using algorithm::trim_left_if;
385 using algorithm::trim_left_copy;
386 using algorithm::trim_left_copy_if;
387 using algorithm::trim_right;
388 using algorithm::trim_right_if;
389 using algorithm::trim_right_copy;
390 using algorithm::trim_right_copy_if;
391 using algorithm::trim;
392 using algorithm::trim_if;
393 using algorithm::trim_copy;
394 using algorithm::trim_copy_if;
395
396} // namespace boost
397
398#endif // BOOST_STRING_TRIM_HPP

/cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/boost/algorithm/string/split.hpp

1// Boost string_algo library split.hpp header file ---------------------------//
2
3// Copyright Pavol Droba 2002-2006.
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9// See http://www.boost.org/ for updates, documentation, and revision history.
10
11#ifndef BOOST_STRING_SPLIT_HPP
12#define BOOST_STRING_SPLIT_HPP
13
14#include <boost/algorithm/string/config.hpp>
15
16#include <boost/algorithm/string/iter_find.hpp>
17#include <boost/algorithm/string/finder.hpp>
18#include <boost/algorithm/string/compare.hpp>
19
20/*! \file
21 Defines basic split algorithms.
22 Split algorithms can be used to divide a string
23 into several parts according to given criteria.
24
25 Each part is copied and added as a new element to the
26 output container.
27 Thus the result container must be able to hold copies
28 of the matches (in a compatible structure like std::string) or
29 a reference to it (e.g. using the iterator range class).
30 Examples of such a container are \c std::vector<std::string>
31 or \c std::list<boost::iterator_range<std::string::iterator>>
32*/
33
34namespace boost {
35 namespace algorithm {
36
37// find_all ------------------------------------------------------------//
38
39 //! Find all algorithm
40 /*!
41 This algorithm finds all occurrences of the search string
42 in the input.
43
44 Each part is copied and added as a new element to the
45 output container.
46 Thus the result container must be able to hold copies
47 of the matches (in a compatible structure like std::string) or
48 a reference to it (e.g. using the iterator range class).
49 Examples of such a container are \c std::vector<std::string>
50 or \c std::list<boost::iterator_range<std::string::iterator>>
51
52 \param Result A container that can hold copies of references to the substrings
53 \param Input A container which will be searched.
54 \param Search A substring to be searched for.
55 \return A reference the result
56
57 \note Prior content of the result will be overwritten.
58
59 \note This function provides the strong exception-safety guarantee
60 */
61 template< typename SequenceSequenceT, typename Range1T, typename Range2T >
62 inline SequenceSequenceT& find_all(
63 SequenceSequenceT& Result,
64#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
65 Range1T&& Input,
66#else
67 Range1T& Input,
68#endif
69 const Range2T& Search)
70 {
71 return ::boost::algorithm::iter_find(
72 Result,
73 Input,
74 ::boost::algorithm::first_finder(Search) );
75 }
76
77 //! Find all algorithm ( case insensitive )
78 /*!
79 This algorithm finds all occurrences of the search string
80 in the input.
81 Each part is copied and added as a new element to the
82 output container. Thus the result container must be able to hold copies
83 of the matches (in a compatible structure like std::string) or
84 a reference to it (e.g. using the iterator range class).
85 Examples of such a container are \c std::vector<std::string>
86 or \c std::list<boost::iterator_range<std::string::iterator>>
87
88 Searching is case insensitive.
89
90 \param Result A container that can hold copies of references to the substrings
91 \param Input A container which will be searched.
92 \param Search A substring to be searched for.
93 \param Loc A locale used for case insensitive comparison
94 \return A reference the result
95
96 \note Prior content of the result will be overwritten.
97
98 \note This function provides the strong exception-safety guarantee
99 */
100 template< typename SequenceSequenceT, typename Range1T, typename Range2T >
101 inline SequenceSequenceT& ifind_all(
102 SequenceSequenceT& Result,
103#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
104 Range1T&& Input,
105#else
106 Range1T& Input,
107#endif
108 const Range2T& Search,
109 const std::locale& Loc=std::locale() )
110 {
111 return ::boost::algorithm::iter_find(
112 Result,
113 Input,
114 ::boost::algorithm::first_finder(Search, is_iequal(Loc) ) );
115 }
116
117
118// tokenize -------------------------------------------------------------//
119
120 //! Split algorithm
121 /*!
122 Tokenize expression. This function is equivalent to C strtok. Input
123 sequence is split into tokens, separated by separators. Separators
124 are given by means of the predicate.
125
126 Each part is copied and added as a new element to the
127 output container.
128 Thus the result container must be able to hold copies
129 of the matches (in a compatible structure like std::string) or
130 a reference to it (e.g. using the iterator range class).
131 Examples of such a container are \c std::vector<std::string>
132 or \c std::list<boost::iterator_range<std::string::iterator>>
133
134 \param Result A container that can hold copies of references to the substrings
135 \param Input A container which will be searched.
136 \param Pred A predicate to identify separators. This predicate is
137 supposed to return true if a given element is a separator.
138 \param eCompress If eCompress argument is set to token_compress_on, adjacent
139 separators are merged together. Otherwise, every two separators
140 delimit a token.
141 \return A reference the result
142
143 \note Prior content of the result will be overwritten.
144
145 \note This function provides the strong exception-safety guarantee
146 */
147 template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
148 inline SequenceSequenceT& split(
149 SequenceSequenceT& Result,
150#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
151 RangeT&& Input,
152#else
153 RangeT& Input,
154#endif
155 PredicateT Pred,
156 token_compress_mode_type eCompress=token_compress_off )
157 {
158 return ::boost::algorithm::iter_split(
159 Result,
160 Input,
161 ::boost::algorithm::token_finder( Pred, eCompress ) );
8
Calling copy constructor for 'is_any_ofF<char>'
11
Returning from copy constructor for 'is_any_ofF<char>'
12
Calling '~is_any_ofF'
162 }
163
164 } // namespace algorithm
165
166 // pull names to the boost namespace
167 using algorithm::find_all;
168 using algorithm::ifind_all;
169 using algorithm::split;
170
171} // namespace boost
172
173
174#endif // BOOST_STRING_SPLIT_HPP
175

/cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/boost/algorithm/string/detail/classification.hpp

1// Boost string_algo library classification.hpp header file ---------------------------//
2
3// Copyright Pavol Droba 2002-2003.
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9// See http://www.boost.org/ for updates, documentation, and revision history.
10
11#ifndef BOOST_STRING_CLASSIFICATION_DETAIL_HPP
12#define BOOST_STRING_CLASSIFICATION_DETAIL_HPP
13
14#include <boost/algorithm/string/config.hpp>
15#include <algorithm>
16#include <cstring>
17#include <functional>
18#include <locale>
19
20#include <boost/range/begin.hpp>
21#include <boost/range/distance.hpp>
22#include <boost/range/end.hpp>
23
24#include <boost/algorithm/string/predicate_facade.hpp>
25#include <boost/type_traits/remove_const.hpp>
26
27namespace boost {
28 namespace algorithm {
29 namespace detail {
30
31// classification functors -----------------------------------------------//
32
33 // is_classified functor
34 struct is_classifiedF :
35 public predicate_facade<is_classifiedF>
36 {
37 // Boost.ResultOf support
38 typedef bool result_type;
39
40 // Constructor from a locale
41 is_classifiedF(std::ctype_base::mask Type, std::locale const & Loc = std::locale()) :
42 m_Type(Type), m_Locale(Loc) {}
43 // Operation
44 template<typename CharT>
45 bool operator()( CharT Ch ) const
46 {
47 return std::use_facet< std::ctype<CharT> >(m_Locale).is( m_Type, Ch );
48 }
49
50 #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x582) && !defined(_USE_OLD_RW_STL)
51 template<>
52 bool operator()( char const Ch ) const
53 {
54 return std::use_facet< std::ctype<char> >(m_Locale).is( m_Type, Ch );
55 }
56 #endif
57
58 private:
59 std::ctype_base::mask m_Type;
60 std::locale m_Locale;
61 };
62
63
64 // is_any_of functor
65 /*
66 returns true if the value is from the specified set
67 */
68 template<typename CharT>
69 struct is_any_ofF :
70 public predicate_facade<is_any_ofF<CharT> >
71 {
72 private:
73 // set cannot operate on const value-type
74 typedef typename ::boost::remove_const<CharT>::type set_value_type;
75
76 public:
77 // Boost.ResultOf support
78 typedef bool result_type;
79
80 // Constructor
81 template<typename RangeT>
82 is_any_ofF( const RangeT& Range ) : m_Size(0)
83 {
84 // Prepare storage
85 m_Storage.m_dynSet=0;
86
87 std::size_t Size=::boost::distance(Range);
88 m_Size=Size;
89 set_value_type* Storage=0;
90
91 if(use_fixed_storage(m_Size))
92 {
93 // Use fixed storage
94 Storage=&m_Storage.m_fixSet[0];
95 }
96 else
97 {
98 // Use dynamic storage
99 m_Storage.m_dynSet=new set_value_type[m_Size];
100 Storage=m_Storage.m_dynSet;
101 }
102
103 // Use fixed storage
104 ::std::copy(::boost::begin(Range), ::boost::end(Range), Storage);
105 ::std::sort(Storage, Storage+m_Size);
106 }
107
108 // Copy constructor
109 is_any_ofF(const is_any_ofF& Other) : m_Size(Other.m_Size)
110 {
111 // Prepare storage
112 m_Storage.m_dynSet=0;
113 const set_value_type* SrcStorage=0;
114 set_value_type* DestStorage=0;
115
116 if(use_fixed_storage(m_Size))
9
Taking false branch
117 {
118 // Use fixed storage
119 DestStorage=&m_Storage.m_fixSet[0];
120 SrcStorage=&Other.m_Storage.m_fixSet[0];
121 }
122 else
123 {
124 // Use dynamic storage
125 m_Storage.m_dynSet=new set_value_type[m_Size];
10
Memory is allocated
126 DestStorage=m_Storage.m_dynSet;
127 SrcStorage=Other.m_Storage.m_dynSet;
128 }
129
130 // Use fixed storage
131 ::std::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size);
132 }
133
134 // Destructor
135 ~is_any_ofF()
136 {
137 if(!use_fixed_storage(m_Size) && m_Storage.m_dynSet!=0)
138 {
139 delete [] m_Storage.m_dynSet;
140 }
141 }
13
Potential memory leak
142
143 // Assignment
144 is_any_ofF& operator=(const is_any_ofF& Other)
145 {
146 // Handle self assignment
147 if(this==&Other) return *this;
148
149 // Prepare storage
150 const set_value_type* SrcStorage;
151 set_value_type* DestStorage;
152
153 if(use_fixed_storage(Other.m_Size))
154 {
155 // Use fixed storage
156 DestStorage=&m_Storage.m_fixSet[0];
157 SrcStorage=&Other.m_Storage.m_fixSet[0];
158
159 // Delete old storage if was present
160 if(!use_fixed_storage(m_Size) && m_Storage.m_dynSet!=0)
161 {
162 delete [] m_Storage.m_dynSet;
163 }
164
165 // Set new size
166 m_Size=Other.m_Size;
167 }
168 else
169 {
170 // Other uses dynamic storage
171 SrcStorage=Other.m_Storage.m_dynSet;
172
173 // Check what kind of storage are we using right now
174 if(use_fixed_storage(m_Size))
175 {
176 // Using fixed storage, allocate new
177 set_value_type* pTemp=new set_value_type[Other.m_Size];
178 DestStorage=pTemp;
179 m_Storage.m_dynSet=pTemp;
180 m_Size=Other.m_Size;
181 }
182 else
183 {
184 // Using dynamic storage, check if can reuse
185 if(m_Storage.m_dynSet!=0 && m_Size>=Other.m_Size && m_Size<Other.m_Size*2)
186 {
187 // Reuse the current storage
188 DestStorage=m_Storage.m_dynSet;
189 m_Size=Other.m_Size;
190 }
191 else
192 {
193 // Allocate the new one
194 set_value_type* pTemp=new set_value_type[Other.m_Size];
195 DestStorage=pTemp;
196
197 // Delete old storage if necessary
198 if(m_Storage.m_dynSet!=0)
199 {
200 delete [] m_Storage.m_dynSet;
201 }
202 // Store the new storage
203 m_Storage.m_dynSet=pTemp;
204 // Set new size
205 m_Size=Other.m_Size;
206 }
207 }
208 }
209
210 // Copy the data
211 ::std::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size);
212
213 return *this;
214 }
215
216 // Operation
217 template<typename Char2T>
218 bool operator()( Char2T Ch ) const
219 {
220 const set_value_type* Storage=
221 (use_fixed_storage(m_Size))
222 ? &m_Storage.m_fixSet[0]
223 : m_Storage.m_dynSet;
224
225 return ::std::binary_search(Storage, Storage+m_Size, Ch);
226 }
227 private:
228 // check if the size is eligible for fixed storage
229 static bool use_fixed_storage(std::size_t size)
230 {
231 return size<=sizeof(set_value_type*)*2;
232 }
233
234
235 private:
236 // storage
237 // The actual used storage is selected on the type
238 union
239 {
240 set_value_type* m_dynSet;
241 set_value_type m_fixSet[sizeof(set_value_type*)*2];
242 }
243 m_Storage;
244
245 // storage size
246 ::std::size_t m_Size;
247 };
248
249 // is_from_range functor
250 /*
251 returns true if the value is from the specified range.
252 (i.e. x>=From && x>=To)
253 */
254 template<typename CharT>
255 struct is_from_rangeF :
256 public predicate_facade< is_from_rangeF<CharT> >
257 {
258 // Boost.ResultOf support
259 typedef bool result_type;
260
261 // Constructor
262 is_from_rangeF( CharT From, CharT To ) : m_From(From), m_To(To) {}
263
264 // Operation
265 template<typename Char2T>
266 bool operator()( Char2T Ch ) const
267 {
268 return ( m_From <= Ch ) && ( Ch <= m_To );
269 }
270
271 private:
272 CharT m_From;
273 CharT m_To;
274 };
275
276 // class_and composition predicate
277 template<typename Pred1T, typename Pred2T>
278 struct pred_andF :
279 public predicate_facade< pred_andF<Pred1T,Pred2T> >
280 {
281 public:
282
283 // Boost.ResultOf support
284 typedef bool result_type;
285
286 // Constructor
287 pred_andF( Pred1T Pred1, Pred2T Pred2 ) :
288 m_Pred1(Pred1), m_Pred2(Pred2) {}
289
290 // Operation
291 template<typename CharT>
292 bool operator()( CharT Ch ) const
293 {
294 return m_Pred1(Ch) && m_Pred2(Ch);
295 }
296
297 private:
298 Pred1T m_Pred1;
299 Pred2T m_Pred2;
300 };
301
302 // class_or composition predicate
303 template<typename Pred1T, typename Pred2T>
304 struct pred_orF :
305 public predicate_facade< pred_orF<Pred1T,Pred2T> >
306 {
307 public:
308 // Boost.ResultOf support
309 typedef bool result_type;
310
311 // Constructor
312 pred_orF( Pred1T Pred1, Pred2T Pred2 ) :
313 m_Pred1(Pred1), m_Pred2(Pred2) {}
314
315 // Operation
316 template<typename CharT>
317 bool operator()( CharT Ch ) const
318 {
319 return m_Pred1(Ch) || m_Pred2(Ch);
320 }
321
322 private:
323 Pred1T m_Pred1;
324 Pred2T m_Pred2;
325 };
326
327 // class_not composition predicate
328 template< typename PredT >
329 struct pred_notF :
330 public predicate_facade< pred_notF<PredT> >
331 {
332 public:
333 // Boost.ResultOf support
334 typedef bool result_type;
335
336 // Constructor
337 pred_notF( PredT Pred ) : m_Pred(Pred) {}
338
339 // Operation
340 template<typename CharT>
341 bool operator()( CharT Ch ) const
342 {
343 return !m_Pred(Ch);
344 }
345
346 private:
347 PredT m_Pred;
348 };
349
350 } // namespace detail
351 } // namespace algorithm
352} // namespace boost
353
354
355#endif // BOOST_STRING_CLASSIFICATION_DETAIL_HPP