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 <sstream>
16
#include "
ers/ers.hpp
"
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
OksSystem::StringMemoryArea::add
(
const
char
*str) {
29
ERS_PRECONDITION
(str);
30
const
size_t
l = strlen(str);
31
const
offset_t
offset
=
last_string
();
32
const
offset_t
start =
offset
+1;
33
const
offset_t
end = start + l ;
34
35
ERS_RANGE_CHECK
(1, end,
string_area_size
());
36
char
*data =
string_area_write
();
37
char
*current = &data[start];
38
strcpy(current,str);
39
last_string
(end);
40
return
start;
41
}
// add
42
47
48
size_t
OksSystem::StringMemoryArea::clear
(
offset_t
offset
) {
49
char
*data =
string_area_write
();
50
size_t
count = 0;
51
while
(data[count+
offset
]) {
52
data[count+
offset
] =
'\0'
;
53
count++;
54
}
// while
55
return
count;
56
}
// clear_string
57
63
64
const
char
*
OksSystem::StringMemoryArea::get_string
(
offset_t
offset
)
const
{
65
if
(
offset
==0)
return
0;
66
ERS_RANGE_CHECK
(1,
offset
,
string_area_size
());
67
const
char
* str =
string_area_read
();
68
if
(str == NULL){
69
return
0;
70
}
71
return
&(str[
offset
]);
72
}
// get_string
73
82
83
OksSystem::StringMemoryArea::offset_t
OksSystem::StringMemoryArea::insert
(
offset_t
offset
,
const
char
* str) {
84
ERS_PRECONDITION
(str);
85
if
(
offset
==0)
return
add
(str);
86
ERS_RANGE_CHECK
(1,
offset
,
string_area_size
());
87
size_t
available =
clear
(
offset
);
88
if
(available>=strlen(str)) {
89
char
*data =
string_area_write
();
90
char
*dest = &data[
offset
];
91
strcpy(dest,str);
92
return
offset
;
93
}
// if
94
return
add
(str);
95
}
// insert_string
96
102
103
void
OksSystem::StringMemoryArea::insert
(
offset_t
*
offset
,
const
char
* str) {
104
ERS_PRECONDITION
(
offset
);
105
const
offset_t
n_offset =
insert
(*
offset
,str);
106
*
offset
= n_offset;
107
}
// insert
108
113
114
OksSystem::StringMemoryArea::str_vector
OksSystem::StringMemoryArea::get_vector
(
offset_t
offset
)
const
{
115
116
OksSystem::StringMemoryArea::str_vector
vector;
117
const
char
*str =
get_string
(
offset
);
118
119
if
(str != 0) {
120
121
const
std::string text(str);
122
123
std::string::size_type start_p = 0;
124
std::string::size_type end_p = 0;
125
126
while
(start_p < text.size()) {
127
end_p = text.find(
STRING_SEPARATOR
,start_p);
128
if
(end_p == std::string::npos) {
129
end_p = text.length();
130
}
131
std::string extract = text.substr(start_p, end_p - start_p);
132
if
(extract.size() > 0) {
133
vector.push_back(extract);
134
}
135
start_p = end_p + 1;
136
}
// while
137
138
}
// if
139
140
return
vector;
141
142
}
// get_vector
143
149
150
OksSystem::StringMemoryArea::offset_t
OksSystem::StringMemoryArea::insert
(
offset_t
offset
,
const
str_vector
&vect) {
151
// ERS_RANGE_CHECK(0, offset, string_area_size());
152
str_vector::const_iterator pos;
153
std::ostringstream stream;
154
for
(pos=vect.begin();pos!=vect.end();pos++) {
155
if
(vect.begin()!=pos) {
156
stream <<
STRING_SEPARATOR
;
157
}
// if first
158
stream << (*pos);
159
}
// for
160
return
insert
(
offset
,stream.str().c_str());
161
}
// insert
162
169
170
void
OksSystem::StringMemoryArea::insert
(
offset_t
*
offset
,
const
str_vector
&vect) {
171
ERS_PRECONDITION
(
offset
);
172
const
offset_t
n_offset =
insert
(*
offset
,vect);
173
*
offset
= n_offset;
174
}
// insert
175
180
181
OksSystem::StringMemoryArea::str_map
OksSystem::StringMemoryArea::get_map
(
offset_t
offset
)
const
{
182
183
ERS_RANGE_CHECK
(1,
offset
,
string_area_size
());
184
OksSystem::StringMemoryArea::str_map
map;
185
const
char
* str =
get_string
(
offset
);
186
187
if
(str != 0) {
188
189
const
std::string text(str);
190
std::string::size_type start_p = 0;
191
std::string::size_type end_p = 0;
192
193
while
(start_p < text.size()) {
194
end_p = text.find(
MAP_ENTRY_SEPARATOR
,start_p);
195
if
(end_p == std::string::npos) {
196
end_p = text.length();
197
}
198
const
std::string entry(text.substr(start_p, end_p - start_p));
199
const
std::string::size_type entrySize = entry.size();
200
if
(entrySize > 0) {
201
const
std::string::size_type separator_p = entry.find(
STRING_SEPARATOR
);
202
if
(separator_p != std::string::npos) {
203
if
((separator_p + 1) < entrySize) {
204
map[entry.substr(0, separator_p)] = entry.substr(separator_p + 1);
205
}
else
{
206
map[entry.substr(0, separator_p)] =
""
;
207
}
208
}
209
}
210
start_p = end_p + 1;
211
}
// while
212
213
}
// if
214
215
return
map;
216
217
}
// get_map
218
225
226
OksSystem::StringMemoryArea::offset_t
OksSystem::StringMemoryArea::insert
(
offset_t
offset
,
const
str_map
&map) {
227
// ERS_RANGE_CHECK(0, offset, string_area_size());
228
str_map::const_iterator pos;
229
std::ostringstream stream;
230
for
(pos=map.begin();pos!=map.end();pos++) {
231
if
(map.begin()!=pos) {
232
stream <<
MAP_ENTRY_SEPARATOR
;
233
}
// if first
234
stream << (pos->first);
235
stream <<
STRING_SEPARATOR
;
236
stream << (pos->second);
237
}
// for
238
return
insert
(
offset
,stream.str().c_str());
239
}
// insert
240
247
248
void
OksSystem::StringMemoryArea::insert
(
offset_t
*
offset
,
const
str_map
&map) {
249
ERS_PRECONDITION
(
offset
);
250
const
offset_t
n_offset =
insert
(*
offset
,map);
251
*
offset
= n_offset;
252
}
// insert
253
254
255
256
257
258
259
260
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:39
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:48
OksSystem::StringMemoryArea::get_string
const char * get_string(offset_t offset) const
Definition
StringMemoryArea.cpp:64
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:41
OksSystem::StringMemoryArea::offset_t
unsigned int offset_t
Definition
StringMemoryArea.hpp:37
OksSystem::StringMemoryArea::MAP_ENTRY_SEPARATOR
static const char MAP_ENTRY_SEPARATOR
character used to separate map entries
Definition
StringMemoryArea.hpp:42
OksSystem::StringMemoryArea::get_vector
str_vector get_vector(offset_t offset) const
Definition
StringMemoryArea.cpp:114
OksSystem::StringMemoryArea::insert
offset_t insert(offset_t offset, const char *str)
Definition
StringMemoryArea.cpp:83
OksSystem::StringMemoryArea::get_map
str_map get_map(offset_t offset) const
Definition
StringMemoryArea.cpp:181
OksSystem::StringMemoryArea::add
offset_t add(const char *str)
Definition
StringMemoryArea.cpp:28
OksSystem::StringMemoryArea::str_vector
std::vector< std::string > str_vector
Definition
StringMemoryArea.hpp:38
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.17.0