xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
beast
utility
PropertyStream.h
1
#pragma once
2
3
#include <xrpl/beast/core/List.h>
4
5
#include <
mutex
>
6
#include <
ostream
>
7
#include <
sstream
>
8
#include <
string
>
9
#include <
utility
>
10
11
namespace
beast
{
12
13
//------------------------------------------------------------------------------
14
18
class
PropertyStream
19
{
20
public
:
21
class
Map
;
22
class
Set
;
23
class
Source
;
24
25
PropertyStream
() =
default
;
26
virtual
~PropertyStream
() =
default
;
27
28
protected
:
29
virtual
void
30
mapBegin
() = 0;
31
virtual
void
32
mapBegin
(
std::string
const
& key) = 0;
33
virtual
void
34
mapEnd
() = 0;
35
36
virtual
void
37
add
(
std::string
const
& key,
std::string
const
& value) = 0;
38
39
void
40
add
(
std::string
const
& key,
char
const
* value)
41
{
42
add
(key,
std::string
(value));
43
}
44
45
template
<
typename
Value>
46
void
47
lexicalAdd
(
std::string
const
& key, Value value)
48
{
49
std::stringstream
ss;
50
ss << value;
51
add
(key, ss.
str
());
52
}
53
54
virtual
void
55
add
(
std::string
const
& key,
bool
value);
56
virtual
void
57
add
(
std::string
const
& key,
char
value);
58
virtual
void
59
add
(
std::string
const
& key,
signed
char
value);
60
virtual
void
61
add
(
std::string
const
& key,
unsigned
char
value);
62
virtual
void
63
add
(
std::string
const
& key,
short
value);
64
virtual
void
65
add
(
std::string
const
& key,
unsigned
short
value);
66
virtual
void
67
add
(
std::string
const
& key,
int
value);
68
virtual
void
69
add
(
std::string
const
& key,
unsigned
int
value);
70
virtual
void
71
add
(
std::string
const
& key,
long
value);
72
virtual
void
73
add
(
std::string
const
& key,
unsigned
long
value);
74
virtual
void
75
add
(
std::string
const
& key,
long
long
value);
76
virtual
void
77
add
(
std::string
const
& key,
unsigned
long
long
value);
78
virtual
void
79
add
(
std::string
const
& key,
float
value);
80
virtual
void
81
add
(
std::string
const
& key,
double
value);
82
virtual
void
83
add
(
std::string
const
& key,
long
double
value);
84
85
virtual
void
86
arrayBegin
() = 0;
87
virtual
void
88
arrayBegin
(
std::string
const
& key) = 0;
89
virtual
void
90
arrayEnd
() = 0;
91
92
virtual
void
93
add
(
std::string
const
& value) = 0;
94
95
void
96
add
(
char
const
* value)
97
{
98
add
(
std::string
(value));
99
}
100
101
template
<
typename
Value>
102
void
103
lexicalAdd
(Value value)
104
{
105
std::stringstream
ss;
106
ss << value;
107
add
(ss.
str
());
108
}
109
110
virtual
void
111
add
(
bool
value);
112
virtual
void
113
add
(
char
value);
114
virtual
void
115
add
(
signed
char
value);
116
virtual
void
117
add
(
unsigned
char
value);
118
virtual
void
119
add
(
short
value);
120
virtual
void
121
add
(
unsigned
short
value);
122
virtual
void
123
add
(
int
value);
124
virtual
void
125
add
(
unsigned
int
value);
126
virtual
void
127
add
(
long
value);
128
virtual
void
129
add
(
unsigned
long
value);
130
virtual
void
131
add
(
long
long
value);
132
virtual
void
133
add
(
unsigned
long
long
value);
134
virtual
void
135
add
(
float
value);
136
virtual
void
137
add
(
double
value);
138
virtual
void
139
add
(
long
double
value);
140
141
private
:
142
class
Item;
143
class
Proxy;
144
};
145
146
//------------------------------------------------------------------------------
147
//
148
// Item
149
//
150
//------------------------------------------------------------------------------
151
152
class
PropertyStream::Item
:
public
List
<Item>::Node
153
{
154
public
:
155
explicit
Item
(
Source
*
source
);
156
[[nodiscard]]
Source
&
157
source
()
const
;
158
Source
*
159
operator->
()
const
;
160
Source
&
161
operator*
()
const
;
162
163
private
:
164
Source
*
source_
;
165
};
166
167
//------------------------------------------------------------------------------
168
//
169
// Proxy
170
//
171
//------------------------------------------------------------------------------
172
173
class
PropertyStream::Proxy
174
{
175
private
:
176
Map
const
*
map_
;
177
std::string
key_
;
178
std::ostringstream
mutable
ostream_
;
179
180
public
:
181
Proxy
(
Map
const
& map,
std::string
key);
182
Proxy
(
Proxy
const
& other);
183
~Proxy
();
184
185
template
<
typename
Value>
186
Proxy
&
187
operator=
(Value value);
188
189
std::ostream
&
190
operator<<
(
std::ostream
& manip(
std::ostream
&))
const
;
191
192
template
<
typename
T>
193
std::ostream
&
194
operator<<
(T
const
& t)
const
195
{
196
return
ostream_
<< t;
197
}
198
};
199
200
//------------------------------------------------------------------------------
201
//
202
// Map
203
//
204
//------------------------------------------------------------------------------
205
206
class
PropertyStream::Map
207
{
208
private
:
209
PropertyStream
&
stream_
;
210
211
public
:
212
explicit
Map
(
PropertyStream
&
stream
);
213
explicit
Map
(
Set
& parent);
214
Map
(
std::string
const
& key,
Map
& parent);
215
Map
(
std::string
const
& key,
PropertyStream
&
stream
);
216
~Map
();
217
218
Map
(
Map
const
&) =
delete
;
219
Map
&
220
operator=
(
Map
const
&) =
delete
;
221
222
PropertyStream
&
223
stream
();
224
[[nodiscard]]
PropertyStream
const
&
225
stream
()
const
;
226
227
template
<
typename
Value>
228
void
229
add
(
std::string
const
& key, Value value)
const
230
{
231
stream_
.add(key, value);
232
}
233
234
template
<
typename
Key,
typename
Value>
235
void
236
add
(Key key, Value value)
const
237
{
238
std::stringstream
ss;
239
ss << key;
240
add
(ss.
str
(), value);
241
}
242
243
Proxy
244
operator[]
(
std::string
const
& key);
245
246
Proxy
247
operator[]
(
char
const
* key)
248
{
249
return
Proxy
(*
this
, key);
250
}
251
252
template
<
typename
Key>
253
Proxy
254
operator[]
(Key key)
const
255
{
256
std::stringstream
ss;
257
ss << key;
258
return
Proxy
(*
this
, ss.
str
());
259
}
260
};
261
262
//--------------------------------------------------------------------------
263
264
template
<
typename
Value>
265
PropertyStream::Proxy
&
266
PropertyStream::Proxy::operator=
(Value value)
267
{
268
map_
->add(
key_
, value);
269
return
*
this
;
270
}
271
272
//--------------------------------------------------------------------------
273
//
274
// Set
275
//
276
//------------------------------------------------------------------------------
277
278
class
PropertyStream::Set
279
{
280
private
:
281
PropertyStream
&
stream_
;
282
283
public
:
284
Set
(
std::string
const
& key,
Map
& map);
285
Set
(
std::string
const
& key,
PropertyStream
&
stream
);
286
~Set
();
287
288
Set
(
Set
const
&) =
delete
;
289
Set
&
290
operator=
(
Set
const
&) =
delete
;
291
292
PropertyStream
&
293
stream
();
294
[[nodiscard]]
PropertyStream
const
&
295
stream
()
const
;
296
297
template
<
typename
Value>
298
void
299
add
(Value value)
const
300
{
301
stream_
.add(value);
302
}
303
};
304
305
//------------------------------------------------------------------------------
306
//
307
// Source
308
//
309
//------------------------------------------------------------------------------
310
314
class
PropertyStream::Source
315
{
316
private
:
317
std::string
const
name_
;
318
std::recursive_mutex
lock_
;
319
Item
item_
;
320
Source
*
parent_
{
nullptr
};
321
List<Item>
children_
;
322
323
public
:
324
explicit
Source
(
std::string
name
);
325
virtual
~Source
();
326
327
Source
(
Source
const
&) =
delete
;
328
Source
&
329
operator=
(
Source
const
&) =
delete
;
330
334
[[nodiscard]]
std::string
const
&
335
name
()
const
;
336
340
void
341
add
(
Source
& source);
342
347
template
<
class
Derived>
348
Derived*
349
add
(Derived* child)
350
{
351
add
(*
static_cast<
Source
*
>
(child));
352
return
child;
353
}
354
358
void
359
remove(
Source
& child);
360
364
void
365
removeAll();
366
370
void
371
writeOne(
PropertyStream
& stream);
372
376
void
377
write(
PropertyStream
& stream);
378
385
void
386
write(
PropertyStream
& stream,
std::string
const
& path);
387
404
std::pair<Source*, bool>
405
find(
std::string
path);
406
407
Source
*
408
findOneDeep(
std::string
const
& name);
409
PropertyStream::Source
*
410
findPath(
std::string
path);
411
PropertyStream::Source
*
412
findOne(
std::string
const
& name);
413
414
static
bool
415
peelLeadingSlash(
std::string
* path);
416
static
bool
417
peelTrailingSlashstar(
std::string
* path);
418
static
std::string
419
peelName(
std::string
* path);
420
421
//--------------------------------------------------------------------------
422
427
virtual
void
428
onWrite(
Map
&);
429
};
430
431
}
// namespace beast
std::ostream
std::ostringstream
std::string
std::stringstream
beast::List
Intrusive doubly linked list.
Definition
List.h:258
beast::PropertyStream::Item
Definition
PropertyStream.h:153
beast::PropertyStream::Item::source_
Source * source_
Definition
PropertyStream.h:164
beast::PropertyStream::Item::operator*
Source & operator*() const
Definition
beast_PropertyStream.cpp:36
beast::PropertyStream::Item::Item
Item(Source *source)
Definition
beast_PropertyStream.cpp:19
beast::PropertyStream::Item::source
Source & source() const
Definition
beast_PropertyStream.cpp:24
beast::PropertyStream::Item::operator->
Source * operator->() const
Definition
beast_PropertyStream.cpp:30
beast::PropertyStream::Map
Definition
PropertyStream.h:207
beast::PropertyStream::Map::Map
Map(Map const &)=delete
beast::PropertyStream::Map::~Map
~Map()
Definition
beast_PropertyStream.cpp:93
beast::PropertyStream::Map::operator[]
Proxy operator[](Key key) const
Definition
PropertyStream.h:254
beast::PropertyStream::Map::Map
Map(PropertyStream &stream)
Definition
beast_PropertyStream.cpp:74
beast::PropertyStream::Map::operator[]
Proxy operator[](std::string const &key)
Definition
beast_PropertyStream.cpp:111
beast::PropertyStream::Map::add
void add(Key key, Value value) const
Definition
PropertyStream.h:236
beast::PropertyStream::Map::add
void add(std::string const &key, Value value) const
Definition
PropertyStream.h:229
beast::PropertyStream::Map::operator=
Map & operator=(Map const &)=delete
beast::PropertyStream::Map::operator[]
Proxy operator[](char const *key)
Definition
PropertyStream.h:247
beast::PropertyStream::Map::stream
PropertyStream & stream()
Definition
beast_PropertyStream.cpp:99
beast::PropertyStream::Map::stream_
PropertyStream & stream_
Definition
PropertyStream.h:209
beast::PropertyStream::Proxy
Definition
PropertyStream.h:174
beast::PropertyStream::Proxy::Proxy
Proxy(Map const &map, std::string key)
Definition
beast_PropertyStream.cpp:47
beast::PropertyStream::Proxy::ostream_
std::ostringstream ostream_
Definition
PropertyStream.h:178
beast::PropertyStream::Proxy::operator<<
std::ostream & operator<<(std::ostream &manip(std::ostream &)) const
Definition
beast_PropertyStream.cpp:63
beast::PropertyStream::Proxy::~Proxy
~Proxy()
Definition
beast_PropertyStream.cpp:55
beast::PropertyStream::Proxy::key_
std::string key_
Definition
PropertyStream.h:177
beast::PropertyStream::Proxy::operator=
Proxy & operator=(Value value)
beast::PropertyStream::Proxy::map_
Map const * map_
Definition
PropertyStream.h:176
beast::PropertyStream::Set
Definition
PropertyStream.h:279
beast::PropertyStream::Set::stream_
PropertyStream & stream_
Definition
PropertyStream.h:281
beast::PropertyStream::Set::stream
PropertyStream & stream()
Definition
beast_PropertyStream.cpp:138
beast::PropertyStream::Set::Set
Set(Set const &)=delete
beast::PropertyStream::Set::add
void add(Value value) const
Definition
PropertyStream.h:299
beast::PropertyStream::Set::Set
Set(std::string const &key, Map &map)
Definition
beast_PropertyStream.cpp:122
beast::PropertyStream::Set::operator=
Set & operator=(Set const &)=delete
beast::PropertyStream::Source
Subclasses can be called to write to a stream and have children.
Definition
PropertyStream.h:315
beast::PropertyStream::Source::children_
List< Item > children_
Definition
PropertyStream.h:321
beast::PropertyStream::Source::lock_
std::recursive_mutex lock_
Definition
PropertyStream.h:318
beast::PropertyStream::Source::name_
std::string const name_
Definition
PropertyStream.h:317
beast::PropertyStream::Source::name
std::string const & name() const
Returns the name of this source.
Definition
beast_PropertyStream.cpp:168
beast::PropertyStream::Source::add
void add(Source &source)
Add a child source.
Definition
beast_PropertyStream.cpp:174
beast::PropertyStream::Source::Source
Source(std::string name)
Definition
beast_PropertyStream.cpp:155
beast::PropertyStream::Source::add
Derived * add(Derived *child)
Add a child source by pointer.
Definition
PropertyStream.h:349
beast::PropertyStream::Source::parent_
Source * parent_
Definition
PropertyStream.h:320
beast::PropertyStream::Source::Source
Source(Source const &)=delete
beast::PropertyStream::Source::item_
Item item_
Definition
PropertyStream.h:319
beast::PropertyStream::Source::operator=
Source & operator=(Source const &)=delete
beast::PropertyStream::lexicalAdd
void lexicalAdd(Value value)
Definition
PropertyStream.h:103
beast::PropertyStream::add
void add(std::string const &key, char const *value)
Definition
PropertyStream.h:40
beast::PropertyStream::mapEnd
virtual void mapEnd()=0
beast::PropertyStream::add
virtual void add(std::string const &key, std::string const &value)=0
beast::PropertyStream::add
virtual void add(std::string const &value)=0
beast::PropertyStream::arrayEnd
virtual void arrayEnd()=0
beast::PropertyStream::mapBegin
virtual void mapBegin()=0
beast::PropertyStream::PropertyStream
PropertyStream()=default
beast::PropertyStream::~PropertyStream
virtual ~PropertyStream()=default
beast::PropertyStream::lexicalAdd
void lexicalAdd(std::string const &key, Value value)
Definition
PropertyStream.h:47
beast::PropertyStream::arrayBegin
virtual void arrayBegin(std::string const &key)=0
beast::PropertyStream::arrayBegin
virtual void arrayBegin()=0
beast::PropertyStream::add
void add(char const *value)
Definition
PropertyStream.h:96
beast::PropertyStream::mapBegin
virtual void mapBegin(std::string const &key)=0
mutex
beast
Definition
base_uint.h:697
ostream
std::pair
std::recursive_mutex
sstream
std::stringstream::str
T str(T... args)
string
utility
Generated by
1.17.0