All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
eventData.h
1//
2// Copyright 2018 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8#ifndef PXR_BASE_TRACE_EVENT_DATA_H
9#define PXR_BASE_TRACE_EVENT_DATA_H
10
11#include "pxr/pxr.h"
12
13#include "pxr/base/trace/api.h"
14#include "pxr/base/trace/event.h"
15
16#include <string>
17#include <variant>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
21class JsWriter;
29public:
31 TraceEventData() : _data(_NoData()) {}
32
34 explicit TraceEventData(bool b) : _data(b) {}
35
37 explicit TraceEventData(int64_t i) : _data(i) {}
38
40 explicit TraceEventData(uint64_t i) : _data(i) {}
41
43 explicit TraceEventData(double d) : _data(d) {}
44
46 explicit TraceEventData(const std::string& s) : _data(s) {}
47
49 TRACE_API TraceEvent::DataType GetType() const;
50
52 TRACE_API const int64_t* GetInt() const;
53
55 TRACE_API const uint64_t* GetUInt() const;
56
58 TRACE_API const double* GetFloat() const;
59
61 TRACE_API const bool* GetBool() const;
62
64 TRACE_API const std::string* GetString() const;
65
67 TRACE_API void WriteJson(JsWriter&) const;
68
69private:
70 // Type that represents no data was stored in an event.
71 struct _NoData {};
72
73 using Variant =
74 std::variant<_NoData, std::string, bool, int64_t, uint64_t, double>;
75 Variant _data;
76};
77
78PXR_NAMESPACE_CLOSE_SCOPE
79
80#endif // PXR_BASE_TRACE_EVENT_DATA_H
This class provides an interface to writing json values directly to a stream.
Definition: json.h:59
This class holds data that can be stored in TraceEvents.
Definition: eventData.h:28
TRACE_API const double * GetFloat() const
Returns a pointer to the data or nullptr if the type is not Float.
TraceEventData(uint64_t i)
Ctor for UInt type.
Definition: eventData.h:40
TRACE_API TraceEvent::DataType GetType() const
Returns the Type of the data stored.
TRACE_API const bool * GetBool() const
Returns a pointer to the data or nullptr if the type is not Bool.
TRACE_API const std::string * GetString() const
Returns a pointer to the data or nullptr if the type is not String.
TRACE_API void WriteJson(JsWriter &) const
Writes a json representation of the data.
TraceEventData(int64_t i)
Ctor for Int type.
Definition: eventData.h:37
TRACE_API const int64_t * GetInt() const
Returns a pointer to the data or nullptr if the type is not Int.
TRACE_API const uint64_t * GetUInt() const
Returns a pointer to the data or nullptr if the type is not UInt.
TraceEventData()
Ctor for Invalid type.
Definition: eventData.h:31
TraceEventData(const std::string &s)
Ctor for String type.
Definition: eventData.h:46
TraceEventData(bool b)
Ctor for Bool type.
Definition: eventData.h:34
TraceEventData(double d)
Ctor for Float type.
Definition: eventData.h:43
DataType
The different types of data that can be stored in a TraceEvent instance.
Definition: event.h:61