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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef PXR_BASE_TRACE_EVENT_DATA_H
26 #define PXR_BASE_TRACE_EVENT_DATA_H
27 
28 #include "pxr/pxr.h"
29 
30 #include "pxr/base/trace/api.h"
31 #include "pxr/base/trace/event.h"
32 
33 #include <string>
34 #include <variant>
35 
37 
38 class JsWriter;
39 ////////////////////////////////////////////////////////////////////////////////
40 ///
41 /// \class TraceEventData
42 ///
43 /// This class holds data that can be stored in TraceEvents.
44 ///
46 public:
47  /// Ctor for Invalid type.
48  TraceEventData() : _data(_NoData()) {}
49 
50  /// Ctor for Bool type.
51  explicit TraceEventData(bool b) : _data(b) {}
52 
53  /// Ctor for Int type.
54  explicit TraceEventData(int64_t i) : _data(i) {}
55 
56  /// Ctor for UInt type.
57  explicit TraceEventData(uint64_t i) : _data(i) {}
58 
59  /// Ctor for Float type.
60  explicit TraceEventData(double d) : _data(d) {}
61 
62  /// Ctor for String type.
63  explicit TraceEventData(const std::string& s) : _data(s) {}
64 
65  /// Returns the Type of the data stored.
67 
68  /// Returns a pointer to the data or nullptr if the type is not Int.
69  TRACE_API const int64_t* GetInt() const;
70 
71  /// Returns a pointer to the data or nullptr if the type is not UInt.
72  TRACE_API const uint64_t* GetUInt() const;
73 
74  /// Returns a pointer to the data or nullptr if the type is not Float.
75  TRACE_API const double* GetFloat() const;
76 
77  /// Returns a pointer to the data or nullptr if the type is not Bool.
78  TRACE_API const bool* GetBool() const;
79 
80  /// Returns a pointer to the data or nullptr if the type is not String.
81  TRACE_API const std::string* GetString() const;
82 
83  /// Writes a json representation of the data.
84  TRACE_API void WriteJson(JsWriter&) const;
85 
86 private:
87  // Type that represents no data was stored in an event.
88  struct _NoData {};
89 
90  using Variant =
91  std::variant<_NoData, std::string, bool, int64_t, uint64_t, double>;
92  Variant _data;
93 };
94 
96 
97 #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:51
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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:63
TraceEventData()
Ctor for Invalid type.
Definition: eventData.h:48
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
TraceEventData(uint64_t i)
Ctor for UInt type.
Definition: eventData.h:57
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:1432
DataType
The different types of data that can be stored in a TraceEvent instance.
Definition: event.h:78
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:91
TraceEventData(double d)
Ctor for Float type.
Definition: eventData.h:60
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:76
TraceEventData(int64_t i)
Ctor for Int type.
Definition: eventData.h:54
#define TRACE_API
Definition: api.h:40