1// Copyright 2016 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_TRACING_TRACED_VALUE_H_
6#define V8_TRACING_TRACED_VALUE_H_
7
8#include <stddef.h>
9#include <memory>
10#include <string>
11#include <vector>
12
13#include "include/v8-platform.h"
14#include "src/base/macros.h"
15
16namespace v8 {
17namespace tracing {
18
19class V8_EXPORT_PRIVATE TracedValue : public ConvertableToTraceFormat {
20 public:
21 ~TracedValue() override;
22
23 static std::unique_ptr<TracedValue> Create();
24
25 void EndDictionary();
26 void EndArray();
27
28 // These methods assume that |name| is a long lived "quoted" string.
29 void SetInteger(const char* name, int value);
30 void SetDouble(const char* name, double value);
31 void SetBoolean(const char* name, bool value);
32 void SetString(const char* name, const char* value);
33 void SetString(const char* name, const std::string& value) {
34 SetString(name, value.c_str());
35 }
36 void SetString(const char* name, std::unique_ptr<char[]> value) {
37 SetString(name, value.get());
38 }
39 void SetValue(const char* name, TracedValue* value);
40 void SetValue(const char* name, std::unique_ptr<TracedValue> value) {
41 SetValue(name, value.get());
42 }
43 void BeginDictionary(const char* name);
44 void BeginArray(const char* name);
45
46 void AppendInteger(int);
47 void AppendDouble(double);
48 void AppendBoolean(bool);
49 void AppendString(const char*);
50 void AppendString(const std::string& value) { AppendString(value.c_str()); }
51 void BeginArray();
52 void BeginDictionary();
53
54 // ConvertableToTraceFormat implementation.
55 void AppendAsTraceFormat(std::string* out) const override;
56
57 private:
58 TracedValue();
59
60 void WriteComma();
61 void WriteName(const char* name);
62
63#ifdef DEBUG
64 // In debug builds checks the pairings of {Begin,End}{Dictionary,Array}
65 std::vector<bool> nesting_stack_;
66#endif
67
68 std::string data_;
69 bool first_item_;
70
71 DISALLOW_COPY_AND_ASSIGN(TracedValue);
72};
73
74} // namespace tracing
75} // namespace v8
76
77#endif // V8_TRACING_TRACED_VALUE_H_
78