HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eventData.h
Go to the documentation of this file.
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 
20 
21 class JsWriter;
22 ////////////////////////////////////////////////////////////////////////////////
23 ///
24 /// \class TraceEventData
25 ///
26 /// This class holds data that can be stored in TraceEvents.
27 ///
29 public:
30  /// Ctor for Invalid type.
31  TraceEventData() : _data(_NoData()) {}
32 
33  /// Ctor for Bool type.
34  explicit TraceEventData(bool b) : _data(b) {}
35 
36  /// Ctor for Int type.
37  explicit TraceEventData(int64_t i) : _data(i) {}
38 
39  /// Ctor for UInt type.
40  explicit TraceEventData(uint64_t i) : _data(i) {}
41 
42  /// Ctor for Float type.
43  explicit TraceEventData(double d) : _data(d) {}
44 
45  /// Ctor for String type.
46  explicit TraceEventData(const std::string& s) : _data(s) {}
47 
48  /// Returns the Type of the data stored.
50 
51  /// Returns a pointer to the data or nullptr if the type is not Int.
52  TRACE_API const int64_t* GetInt() const;
53 
54  /// Returns a pointer to the data or nullptr if the type is not UInt.
55  TRACE_API const uint64_t* GetUInt() const;
56 
57  /// Returns a pointer to the data or nullptr if the type is not Float.
58  TRACE_API const double* GetFloat() const;
59 
60  /// Returns a pointer to the data or nullptr if the type is not Bool.
61  TRACE_API const bool* GetBool() const;
62 
63  /// Returns a pointer to the data or nullptr if the type is not String.
64  TRACE_API const std::string* GetString() const;
65 
66  /// Writes a json representation of the data.
67  TRACE_API void WriteJson(JsWriter&) const;
68 
69 private:
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 
79 
80 #endif // PXR_BASE_TRACE_EVENT_DATA_H
TRACE_API const std::string * GetString() const
Returns a pointer to the data or nullptr if the type is not String.
TraceEventData(bool b)
Ctor for Bool type.
Definition: eventData.h:34
GLdouble s
Definition: glad.h:3009
TRACE_API const bool * GetBool() const
Returns a pointer to the data or nullptr if the type is not Bool.
TRACE_API TraceEvent::DataType GetType() const
Returns the Type of the data stored.
TraceEventData(const std::string &s)
Ctor for String type.
Definition: eventData.h:46
TraceEventData()
Ctor for Invalid type.
Definition: eventData.h:31
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
TraceEventData(uint64_t i)
Ctor for UInt type.
Definition: eventData.h:40
TRACE_API const uint64_t * GetUInt() const
Returns a pointer to the data or nullptr if the type is not UInt.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
DataType
The different types of data that can be stored in a TraceEvent instance.
Definition: event.h:61
TRACE_API const int64_t * GetInt() const
Returns a pointer to the data or nullptr if the type is not Int.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
TraceEventData(double d)
Ctor for Float type.
Definition: eventData.h:43
TRACE_API const double * GetFloat() const
Returns a pointer to the data or nullptr if the type is not Float.
TRACE_API void WriteJson(JsWriter &) const
Writes a json representation of the data.
Definition: json.h:59
TraceEventData(int64_t i)
Ctor for Int type.
Definition: eventData.h:37
#define TRACE_API
Definition: api.h:23