Loading...
Searching...
No Matches
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 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
36PXR_NAMESPACE_OPEN_SCOPE
37
38class JsWriter;
46public:
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
86private:
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
95PXR_NAMESPACE_CLOSE_SCOPE
96
97#endif // PXR_BASE_TRACE_EVENT_DATA_H
This class provides an interface to writing json values directly to a stream.
Definition: json.h:76
This class holds data that can be stored in TraceEvents.
Definition: eventData.h:45
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:57
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:54
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:48
TraceEventData(const std::string &s)
Ctor for String type.
Definition: eventData.h:63
TraceEventData(bool b)
Ctor for Bool type.
Definition: eventData.h:51
TraceEventData(double d)
Ctor for Float type.
Definition: eventData.h:60
DataType
The different types of data that can be stored in a TraceEvent instance.
Definition: event.h:78