DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
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
19
22
27
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
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
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
65 if (offset==0) return 0;
67 const char* str = string_area_read();
68 if (str == NULL){
69 return 0;
70 }
71 return &(str[offset]);
72} // get_string
73
82
85 if (offset==0) return add(str);
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
105 const offset_t n_offset = insert(*offset,str);
106 *offset = n_offset;
107} // insert
108
113
115
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
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
172 const offset_t n_offset = insert(*offset,vect);
173 *offset = n_offset;
174} // insert
175
180
182
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
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
250 const offset_t n_offset = insert(*offset,map);
251 *offset = n_offset;
252} // insert
253
254
255
256
257
258
259
260
#define ERS_RANGE_CHECK(min, val, max)
#define ERS_PRECONDITION(expression)
virtual char * string_area_write()=0
write pointer for the string area
std::map< std::string, std::string > str_map
virtual size_t string_area_size() const =0
size of the string area
size_t clear(offset_t offset)
const char * get_string(offset_t offset) const
virtual offset_t last_string() const =0
offset of the end of the last string
static const char STRING_SEPARATOR
character used to separate strings (i.e., to tokenize strings in vectors)
static const char MAP_ENTRY_SEPARATOR
character used to separate map entries
str_vector get_vector(offset_t offset) const
offset_t insert(offset_t offset, const char *str)
str_map get_map(offset_t offset) const
offset_t add(const char *str)
std::vector< std::string > str_vector
virtual const char * string_area_read() const =0
read pointer for the string area
double offset