All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eventData.h
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 TRACE_DATA_H
26 #define TRACE_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 <boost/variant.hpp>
34 #include <string>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
38 class JsWriter;
46 public:
48  TraceEventData() : _data(_NoData()) {}
49 
51  explicit TraceEventData(bool b) : _data(b) {}
52 
54  explicit TraceEventData(int64_t i) : _data(i) {}
55 
57  explicit TraceEventData(uint64_t i) : _data(i) {}
58 
60  explicit TraceEventData(double d) : _data(d) {}
61 
63  explicit TraceEventData(const std::string& s) : _data(s) {}
64 
66  TRACE_API TraceEvent::DataType GetType() const;
67 
69  TRACE_API const int64_t* GetInt() const;
70 
72  TRACE_API const uint64_t* GetUInt() const;
73 
75  TRACE_API const double* GetFloat() const;
76 
78  TRACE_API const bool* GetBool() const;
79 
81  TRACE_API const std::string* GetString() const;
82 
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  boost::variant<_NoData, std::string, bool, int64_t, uint64_t, double>;
92  Variant _data;
93 };
94 
95 PXR_NAMESPACE_CLOSE_SCOPE
96 
97 #endif // TRACE_DATA_H
TraceEventData(const std::string &s)
Ctor for String type.
Definition: eventData.h:63
TRACE_API TraceEvent::DataType GetType() const
Returns the Type of the data stored.
TraceEventData(double d)
Ctor for Float type.
Definition: eventData.h:60
TraceEventData()
Ctor for Invalid type.
Definition: eventData.h:48
TraceEventData(uint64_t i)
Ctor for UInt type.
Definition: eventData.h:57
TRACE_API const std::string * GetString() const
Returns a pointer to the data or nullptr if the type is not String.
TRACE_API const uint64_t * GetUInt() const
Returns a pointer to the data or nullptr if the type is not UInt.
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.
This class holds data that can be stored in TraceEvents.
Definition: eventData.h:45
TRACE_API const bool * GetBool() const
Returns a pointer to the data or nullptr if the type is not Bool.
DataType
The different types of data that can be stored in a TraceEvent instance.
Definition: event.h:78
TraceEventData(int64_t i)
Ctor for Int type.
Definition: eventData.h:54
TraceEventData(bool b)
Ctor for Bool type.
Definition: eventData.h:51
TRACE_API const int64_t * GetInt() const
Returns a pointer to the data or nullptr if the type is not Int.
This class provides an interface to writing json values directly to a stream.
Definition: json.h:76