DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
okssystem
src
StringMemoryArea.cpp
Go to the documentation of this file.
1
// DUNE DAQ modification notice:
2
// This file has been modified from the original ATLAS system source for the DUNE DAQ project.
3
// Fork baseline commit: system-00-00-20 (2020-09-25).
4
// Renamed since fork: yes (from src/StringMemoryArea.cxx to src/StringMemoryArea.cpp).
5
6
/*
7
* StringMemoryArea.cxx
8
* OksSystem
9
*
10
* Created by Matthias Wiesmann on 17.02.05.
11
* Copyright 2005 CERN. All rights reserved.
12
*
13
*/
14
15
#include "
ers/ers.hpp
"
16
#include <sstream>
17
18
#include "
okssystem/StringMemoryArea.hpp
"
19
20
const
char
OksSystem::StringMemoryArea::STRING_SEPARATOR
= (char)3;
21
const
char
OksSystem::StringMemoryArea::MAP_ENTRY_SEPARATOR
= (char)4;
22
27
28
OksSystem::StringMemoryArea::offset_t
29
OksSystem::StringMemoryArea::add
(
const
char
* str)
30
{
31
ERS_PRECONDITION
(str);
32
const
size_t
l = strlen(str);
33
const
offset_t
offset
=
last_string
();
34
const
offset_t
start =
offset
+ 1;
35
const
offset_t
end = start + l;
36
37
ERS_RANGE_CHECK
(1, end,
string_area_size
());
38
char
* data =
string_area_write
();
39
char
* current = &data[start];
40
strcpy(current, str);
41
last_string
(end);
42
return
start;
43
}
// add
44
49
50
size_t
51
OksSystem::StringMemoryArea::clear
(
offset_t
offset
)
52
{
53
char
* data =
string_area_write
();
54
size_t
count = 0;
55
while
(data[count +
offset
]) {
56
data[count +
offset
] =
'\0'
;
57
count++;
58
}
// while
59
return
count;
60
}
// clear_string
61
67
68
const
char
*
69
OksSystem::StringMemoryArea::get_string
(
offset_t
offset
)
const
70
{
71
if
(
offset
== 0)
72
return
0;
73
ERS_RANGE_CHECK
(1,
offset
,
string_area_size
());
74
const
char
* str =
string_area_read
();
75
if
(str == NULL) {
76
return
0;
77
}
78
return
&(str[
offset
]);
79
}
// get_string
80
89
90
OksSystem::StringMemoryArea::offset_t
91
OksSystem::StringMemoryArea::insert
(
offset_t
offset
,
const
char
* str)
92
{
93
ERS_PRECONDITION
(str);
94
if
(
offset
== 0)
95
return
add
(str);
96
ERS_RANGE_CHECK
(1,
offset
,
string_area_size
());
97
size_t
available =
clear
(
offset
);
98
if
(available >= strlen(str)) {
99
char
* data =
string_area_write
();
100
char
* dest = &data[
offset
];
101
strcpy(dest, str);
102
return
offset
;
103
}
// if
104
return
add
(str);
105
}
// insert_string
106
112
113
void
114
OksSystem::StringMemoryArea::insert
(
offset_t
*
offset
,
const
char
* str)
115
{
116
ERS_PRECONDITION
(
offset
);
117
const
offset_t
n_offset =
insert
(*
offset
, str);
118
*
offset
= n_offset;
119
}
// insert
120
125
126
OksSystem::StringMemoryArea::str_vector
127
OksSystem::StringMemoryArea::get_vector
(
offset_t
offset
)
const
128
{
129
130
OksSystem::StringMemoryArea::str_vector
vector;
131
const
char
* str =
get_string
(
offset
);
132
133
if
(str != 0) {
134
135
const
std::string text(str);
136
137
std::string::size_type start_p = 0;
138
std::string::size_type end_p = 0;
139
140
while
(start_p < text.size()) {
141
end_p = text.find(
STRING_SEPARATOR
, start_p);
142
if
(end_p == std::string::npos) {
143
end_p = text.length();
144
}
145
std::string extract = text.substr(start_p, end_p - start_p);
146
if
(extract.size() > 0) {
147
vector.push_back(extract);
148
}
149
start_p = end_p + 1;
150
}
// while
151
152
}
// if
153
154
return
vector;
155
156
}
// get_vector
157
163
164
OksSystem::StringMemoryArea::offset_t
165
OksSystem::StringMemoryArea::insert
(
offset_t
offset
,
const
str_vector
& vect)
166
{
167
// ERS_RANGE_CHECK(0, offset, string_area_size());
168
str_vector::const_iterator pos;
169
std::ostringstream stream;
170
for
(pos = vect.begin(); pos != vect.end(); pos++) {
171
if
(vect.begin() != pos) {
172
stream <<
STRING_SEPARATOR
;
173
}
// if first
174
stream << (*pos);
175
}
// for
176
return
insert
(
offset
, stream.str().c_str());
177
}
// insert
178
185
186
void
187
OksSystem::StringMemoryArea::insert
(
offset_t
*
offset
,
const
str_vector
& vect)
188
{
189
ERS_PRECONDITION
(
offset
);
190
const
offset_t
n_offset =
insert
(*
offset
, vect);
191
*
offset
= n_offset;
192
}
// insert
193
198
199
OksSystem::StringMemoryArea::str_map
200
OksSystem::StringMemoryArea::get_map
(
offset_t
offset
)
const
201
{
202
203
ERS_RANGE_CHECK
(1,
offset
,
string_area_size
());
204
OksSystem::StringMemoryArea::str_map
map;
205
const
char
* str =
get_string
(
offset
);
206
207
if
(str != 0) {
208
209
const
std::string text(str);
210
std::string::size_type start_p = 0;
211
std::string::size_type end_p = 0;
212
213
while
(start_p < text.size()) {
214
end_p = text.find(
MAP_ENTRY_SEPARATOR
, start_p);
215
if
(end_p == std::string::npos) {
216
end_p = text.length();
217
}
218
const
std::string entry(text.substr(start_p, end_p - start_p));
219
const
std::string::size_type entrySize = entry.size();
220
if
(entrySize > 0) {
221
const
std::string::size_type separator_p = entry.find(
STRING_SEPARATOR
);
222
if
(separator_p != std::string::npos) {
223
if
((separator_p + 1) < entrySize) {
224
map[entry.substr(0, separator_p)] = entry.substr(separator_p + 1);
225
}
else
{
226
map[entry.substr(0, separator_p)] =
""
;
227
}
228
}
229
}
230
start_p = end_p + 1;
231
}
// while
232
233
}
// if
234
235
return
map;
236
237
}
// get_map
238
245
246
OksSystem::StringMemoryArea::offset_t
247
OksSystem::StringMemoryArea::insert
(
offset_t
offset
,
const
str_map
& map)
248
{
249
// ERS_RANGE_CHECK(0, offset, string_area_size());
250
str_map::const_iterator pos;
251
std::ostringstream stream;
252
for
(pos = map.begin(); pos != map.end(); pos++) {
253
if
(map.begin() != pos) {
254
stream <<
MAP_ENTRY_SEPARATOR
;
255
}
// if first
256
stream << (pos->first);
257
stream <<
STRING_SEPARATOR
;
258
stream << (pos->second);
259
}
// for
260
return
insert
(
offset
, stream.str().c_str());
261
}
// insert
262
269
270
void
271
OksSystem::StringMemoryArea::insert
(
offset_t
*
offset
,
const
str_map
& map)
272
{
273
ERS_PRECONDITION
(
offset
);
274
const
offset_t
n_offset =
insert
(*
offset
, map);
275
*
offset
= n_offset;
276
}
// insert
ERS_RANGE_CHECK
#define ERS_RANGE_CHECK(min, val, max)
ERS_PRECONDITION
#define ERS_PRECONDITION(expression)
StringMemoryArea.hpp
OksSystem::StringMemoryArea::string_area_write
virtual char * string_area_write()=0
write pointer for the string area
OksSystem::StringMemoryArea::str_map
std::map< std::string, std::string > str_map
Definition
StringMemoryArea.hpp:40
OksSystem::StringMemoryArea::string_area_size
virtual size_t string_area_size() const =0
size of the string area
OksSystem::StringMemoryArea::clear
size_t clear(offset_t offset)
Definition
StringMemoryArea.cpp:51
OksSystem::StringMemoryArea::get_string
const char * get_string(offset_t offset) const
Definition
StringMemoryArea.cpp:69
OksSystem::StringMemoryArea::last_string
virtual offset_t last_string() const =0
offset of the end of the last string
OksSystem::StringMemoryArea::STRING_SEPARATOR
static const char STRING_SEPARATOR
character used to separate strings (i.e., to tokenize strings in vectors)
Definition
StringMemoryArea.hpp:44
OksSystem::StringMemoryArea::offset_t
unsigned int offset_t
Definition
StringMemoryArea.hpp:38
OksSystem::StringMemoryArea::MAP_ENTRY_SEPARATOR
static const char MAP_ENTRY_SEPARATOR
character used to separate map entries
Definition
StringMemoryArea.hpp:45
OksSystem::StringMemoryArea::get_vector
str_vector get_vector(offset_t offset) const
Definition
StringMemoryArea.cpp:127
OksSystem::StringMemoryArea::insert
offset_t insert(offset_t offset, const char *str)
Definition
StringMemoryArea.cpp:91
OksSystem::StringMemoryArea::get_map
str_map get_map(offset_t offset) const
Definition
StringMemoryArea.cpp:200
OksSystem::StringMemoryArea::add
offset_t add(const char *str)
Definition
StringMemoryArea.cpp:29
OksSystem::StringMemoryArea::str_vector
std::vector< std::string > str_vector
Definition
StringMemoryArea.hpp:39
OksSystem::StringMemoryArea::string_area_read
virtual const char * string_area_read() const =0
read pointer for the string area
offset
double offset
Definition
conversions-impl.hh:28
ers.hpp
Generated on
for DUNE-DAQ by
1.18.0