diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-11-18 10:46:55 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-11-18 18:22:16 +0000 |
commit | 37822a5c2ecf566bac41ea8a8c94226115ac370f (patch) | |
tree | 2266cd8bdbc8675892c74dafeab2c7317142dd77 /vespalib | |
parent | b2d2d0053d16ca15c9298f3e8312b494e246c5e9 (diff) |
Hide the modifiable TraceNode root inside the Trace object
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/trace/trace.cpp | 2 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/trace/trace.h | 33 |
2 files changed, 28 insertions, 7 deletions
diff --git a/vespalib/src/tests/trace/trace.cpp b/vespalib/src/tests/trace/trace.cpp index 92bee3231b0..9e9318bf4b8 100644 --- a/vespalib/src/tests/trace/trace.cpp +++ b/vespalib/src/tests/trace/trace.cpp @@ -261,7 +261,7 @@ TEST("testTraceDump") b1.addChild(b2); } for (int i = 0; i < 10; ++i) { - big.getRoot().addChild(b1); + big.addChild(b1); } string normal = big.toString(); string full = big.getRoot().toString(); diff --git a/vespalib/src/vespa/vespalib/trace/trace.h b/vespalib/src/vespa/vespalib/trace/trace.h index 6676be4a81e..bad89bf6646 100644 --- a/vespalib/src/vespa/vespalib/trace/trace.h +++ b/vespalib/src/vespa/vespalib/trace/trace.h @@ -18,9 +18,6 @@ namespace vespalib { * information will be traced. */ class Trace { -private: - TraceNode _root; - uint32_t _level; public: /** @@ -100,12 +97,28 @@ public: */ bool trace(uint32_t level, const string ¬e, bool addTime = true); + void normalize() { + _root.normalize(); + } + /** - * Returns the root of the trace tree. + * Adds a child node to this. * - * @return The root. + * @param child The child to add. + * @return This, to allow chaining. */ - TraceNode &getRoot() { return _root; } + void addChild(TraceNode child) { + ensureRoot().addChild(std::move(child)); + } + + void setStrict(bool strict) { + ensureRoot().setStrict(strict); + } + void addChild(Trace && child) { + if (!child.isEmpty()) { + addChild(std::move(child._root)); + } + } /** * Returns a const reference to the root of the trace tree. @@ -116,6 +129,9 @@ public: bool isEmpty() const { return _root.isEmpty(); } + uint32_t getNumChildren() const { return _root.getNumChildren(); } + const TraceNode & getChild(uint32_t child) const { return getRoot().getChild(child); } + /** * Returns a string representation of the contained trace tree. This is a * readable, non-parseable string. @@ -123,6 +139,11 @@ public: * @return Readable trace string. */ string toString() const { return _root.toString(31337); } +private: + TraceNode &ensureRoot() { return _root; } + + TraceNode _root; + uint32_t _level; }; #define VESPALIB_TRACE2(ttrace, level, note, addTime) \ |