20#include <xrpl/beast/utility/PropertyStream.h>
21#include <xrpl/beast/utility/instrumentation.h>
63 : m_map(&map), m_key(key)
68 : m_map(other.m_map), m_key(other.m_key)
82 return m_ostream << manip;
101 : m_stream(map.stream())
132 return Proxy(*
this, key);
142 : m_stream(map.stream())
155 m_stream.array_end();
177 : m_name(name), item_(this), parent_(nullptr)
184 if (parent_ !=
nullptr)
185 parent_->remove(*
this);
204 "beast::PropertyStream::Source::add : null source parent");
205 children_.push_back(source.
item_);
217 child.parent_ ==
this,
218 "beast::PropertyStream::Source::remove : child parent match");
219 children_.erase(children_.iterator_to(child.item_));
220 child.parent_ =
nullptr;
227 for (
auto iter = children_.begin(); iter != children_.end();)
239 Map map(m_name, stream);
246 Map map(m_name, stream);
251 for (
auto& child : children_)
252 child.source().write(stream);
260 if (result.
first ==
nullptr)
264 result.
first->write(stream);
266 result.
first->write_one(stream);
272 bool const deep(peel_trailing_slashstar(&path));
273 bool const rooted(peel_leading_slash(&path));
280 source = find_one_deep(name);
281 if (source ==
nullptr)
292 if (!path->empty() && path->front() ==
'/')
294 *path =
std::string(path->begin() + 1, path->end());
306 if (path->back() ==
'*')
311 if (!path->empty() && path->back() ==
'/')
322 std::string::const_iterator first = (*path).
begin();
323 std::string::const_iterator last = (*path).end();
324 std::string::const_iterator pos =
std::find(first, last,
'/');
339 Source* found = find_one(name);
340 if (found !=
nullptr)
344 for (
auto& s : children_)
347 if (found !=
nullptr)
365 }
while (source !=
nullptr);
375 for (
auto& s : children_)
377 if (s.source().m_name == name)
Source & operator*() const
Source * operator->() const
PropertyStream & m_stream
Map(PropertyStream &stream)
Proxy operator[](std::string const &key)
PropertyStream & stream()
Proxy(Map const &map, std::string const &key)
std::ostream & operator<<(std::ostream &manip(std::ostream &)) const
PropertyStream & stream()
PropertyStream & m_stream
Set(std::string const &key, Map &map)
Subclasses can be called to write to a stream and have children.
static bool peel_leading_slash(std::string *path)
PropertyStream::Source * find_one(std::string const &name)
void removeAll()
Remove all child sources from this Source.
Source(std::string const &name)
std::recursive_mutex lock_
std::pair< Source *, bool > find(std::string path)
Parse the dot-delimited Source path and return the result.
void remove(Source &child)
Remove a child source from this Source.
std::string const & name() const
Returns the name of this source.
void add(Source &source)
Add a child source.
PropertyStream::Source * find_path(std::string path)
void write_one(PropertyStream &stream)
Write only this Source to the stream.
Source * find_one_deep(std::string const &name)
void write(PropertyStream &stream)
write this source and all its children recursively to the stream.
static std::string peel_name(std::string *path)
static bool peel_trailing_slashstar(std::string *path)
virtual void onWrite(Map &)
Subclass override.
Abstract stream with RAII containers that produce a property tree.
virtual void add(std::string const &key, std::string const &value)=0
virtual void map_begin()=0
virtual void array_begin()=0
void lexical_add(std::string const &key, Value value)