UNPKG

2.59 kBtext/x-cView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
10#include <climits>
11#include <memory>
12#include <string>
13#include <vector>
14
15namespace facebook {
16namespace react {
17
18#ifndef NDEBUG
19#define RN_DEBUG_STRING_CONVERTIBLE 1
20#endif
21
22#if RN_DEBUG_STRING_CONVERTIBLE
23
24class DebugStringConvertible;
25
26using SharedDebugStringConvertible =
27 std::shared_ptr<const DebugStringConvertible>;
28using SharedDebugStringConvertibleList =
29 std::vector<SharedDebugStringConvertible>;
30
31struct DebugStringConvertibleOptions {
32 bool format{true};
33 int maximumDepth{INT_MAX};
34};
35
36// Abstract class describes conformance to DebugStringConvertible concept
37// and implements basic recursive debug string assembly algorithm.
38// Use this as a base class for providing a debugging textual representation
39// of your class.
40class DebugStringConvertible {
41 public:
42 virtual ~DebugStringConvertible() = default;
43
44 // Returns a name of the object.
45 // Default implementation returns "Node".
46 virtual std::string getDebugName() const;
47
48 // Returns a value assosiate with the object.
49 // Default implementation returns an empty string.
50 virtual std::string getDebugValue() const;
51
52 // Returns a list of `DebugStringConvertible` objects which can be considered
53 // as *children* of the object.
54 // Default implementation returns an empty list.
55 virtual SharedDebugStringConvertibleList getDebugChildren() const;
56
57 // Returns a list of `DebugStringConvertible` objects which can be considered
58 // as *properties* of the object.
59 // Default implementation returns an empty list.
60 virtual SharedDebugStringConvertibleList getDebugProps() const;
61
62 // Returns a string which represents the object in a human-readable way.
63 // Default implementation returns a description of the subtree
64 // rooted at this node, represented in XML-like format.
65 virtual std::string getDebugDescription(
66 DebugStringConvertibleOptions options = {},
67 int depth = 0) const;
68
69 // Do same as `getDebugDescription` but return only *children* and
70 // *properties* parts (which are used in `getDebugDescription`).
71 virtual std::string getDebugPropsDescription(
72 DebugStringConvertibleOptions options = {},
73 int depth = 0) const;
74 virtual std::string getDebugChildrenDescription(
75 DebugStringConvertibleOptions options = {},
76 int depth = 0) const;
77};
78
79#else
80
81class DebugStringConvertible {};
82
83#endif
84
85} // namespace react
86} // namespace facebook