Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
art
art
Framework
IO
detail
FileNameComponents.cc
Go to the documentation of this file.
1
#include "
art/Framework/IO/detail/FileNameComponents.h
"
2
#include "boost/regex.hpp"
3
4
#include <cassert>
5
#include <iomanip>
6
#include <sstream>
7
8
namespace
art::detail
{
9
10
void
11
FileNameComponents::add
(
std::string
const
&
prefix
,
12
std::string
const
& digitFormat)
13
{
14
components_
.emplace_back(prefix, digitFormat);
15
}
16
17
void
18
FileNameComponents::setSuffix
(
std::string
suffix)
19
{
20
suffix_
=
move
(suffix);
21
}
22
23
bool
24
FileNameComponents::operator<
(
FileNameComponents
const
& fnc)
const
25
{
26
if
(
components_
.size() < fnc.
components_
.size()) {
27
return
true
;
28
}
29
if
(
components_
.size() > fnc.
components_
.size()) {
30
return
false
;
31
}
32
33
assert(
components_
.size() == fnc.
components_
.size());
34
auto
b1 =
cbegin
(
components_
), e1 =
cend
(
components_
);
35
auto
b2 =
cbegin
(fnc.
components_
);
36
for
(; b1 != e1; ++b1, ++b2) {
37
if
(b1->first < b2->first)
38
return
true
;
39
}
40
assert(b2 ==
cend
(fnc.
components_
));
41
return
false
;
42
}
43
44
std::string
45
FileNameComponents::fileNameWithIndex
(std::size_t
const
index
)
const
46
{
47
std::ostringstream num_str;
48
for
(
auto
const
& pr :
components_
) {
49
auto
const
&
prefix
= pr.first;
50
auto
const
& specifier = pr.second;
51
num_str <<
prefix
;
52
if
(!specifier.empty()) {
// Zero-filling.
53
num_str <<
std::setfill
(
'0'
) <<
std::setw
(std::stoul(specifier));
54
}
55
num_str <<
index
;
56
}
57
num_str <<
suffix_
;
58
return
num_str.str();
59
}
60
61
FileNameComponents
62
componentsFromPattern
(
std::string
const
&
pattern
)
63
{
64
FileNameComponents
result
;
65
66
boost::smatch match;
67
auto
sid =
cbegin
(pattern),
se
=
cend
(pattern);
68
while
(boost::regex_search(
69
sid,
70
se
,
71
match,
72
boost::regex{
"%(\\d+)?#"
, boost::regex_constants::ECMAScript})) {
73
assert(match.size() == 2);
74
// Subexpressions:
75
// 0. Entire matched expression
76
// 1. Possible fill format digits for numeric substitution.
77
result.
add
(match.prefix(), match[1].str());
78
sid = match[0].second;
79
}
80
// Get remaining characters of filename
81
result.
setSuffix
(
std::string
(sid,
se
));
82
return
result
;
83
}
84
}
art::detail::FileNameComponents
Definition:
FileNameComponents.h:28
util::cend
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition:
StdUtils.h:87
result
static QCString result
Definition:
fortranscanner.cpp:56614
FileNameComponents.h
submit_ppfxjobs.prefix
string prefix
Definition:
submit_ppfxjobs.py:128
string
std::string string
Definition:
nybbler.cc:12
art::detail
Definition:
AllowedConfiguration.h:76
art::detail::FileNameComponents::operator<
bool operator<(FileNameComponents const &fnc) const
Definition:
FileNameComponents.cc:24
art::detail::FileNameComponents::setSuffix
void setSuffix(std::string suffix)
Definition:
FileNameComponents.cc:18
wirecell.gen.depos.move
def move(depos, offset)
Definition:
depos.py:107
art::detail::componentsFromPattern
FileNameComponents componentsFromPattern(std::string const &pattern)
Definition:
FileNameComponents.cc:62
setw
Q_EXPORT QTSManip setw(int w)
Definition:
qtextstream.h:331
art::detail::FileNameComponents::fileNameWithIndex
std::string fileNameWithIndex(std::size_t index) const
Definition:
FileNameComponents.cc:45
art::detail::FileNameComponents::add
void add(std::string const &prefix, std::string const &digitFormat)
Definition:
FileNameComponents.cc:11
pattern
std::string pattern
Definition:
regex_t.cc:35
ValidateOpDetReco.index
index
Definition:
ValidateOpDetReco.py:379
util::cbegin
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
Definition:
StdUtils.h:82
art::detail::FileNameComponents::components_
std::vector< std::pair< std::string, std::string > > components_
Definition:
FileNameComponents.h:39
art::detail::FileNameComponents::suffix_
std::string suffix_
Definition:
FileNameComponents.h:40
setfill
Q_EXPORT QTSManip setfill(int f)
Definition:
qtextstream.h:337
se
Definition:
se.py:1
Generated by
1.8.11