HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
category.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_CATEGORY_H
26 #define PXR_BASE_TRACE_CATEGORY_H
27 
28 /// \file trace/category.h
29 
30 #include "pxr/pxr.h"
31 
32 #include "pxr/base/trace/api.h"
33 #include "pxr/base/tf/singleton.h"
35 
36 #include <cstdint>
37 #include <map>
38 #include <string>
39 #include <vector>
40 
42 
43 /// Categories that a TraceReporter can use to filter events.
44 using TraceCategoryId = uint32_t;
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 ///
48 /// \class TraceCategory
49 ///
50 /// This singleton class provides a way to mark TraceEvent instances with
51 /// category Ids which can be used to filter them. This class also provides a
52 /// way to associate TraceCategoryId values with human readable names.
53 ///
55 public:
56  /// Computes an id for the given a string literal \p str.
57  template <int N>
59  const char (&str)[N]) {
60  return TraceStringHash::Hash(str);
61  }
62 
63  /// Default category if none are explicitly specified when creating a
64  /// TraceEvent.
65  enum : TraceCategoryId { Default = 0 };
66 
67  /// Associates the \p id with \p name. These associates are not necessarily
68  /// unique.
70 
71  /// Returns all names associated with the \p id.
72  TRACE_API std::vector<std::string> GetCategories(TraceCategoryId id) const;
73 
74  /// Singleton accessor.
76 
77 private:
78  friend class TfSingleton<TraceCategory>;
79 
80  TraceCategory();
81 
82  // Mapping of ids to names.
83  std::multimap<TraceCategoryId, std::string> _idToNames;
84 };
85 
87 
89 
90 #endif // PXR_BASE_TRACE_CATEGORY_H
static constexpr std::uint32_t Hash(const char(&str)[N])
Computes a compile time hash of str.
Definition: stringHash.h:46
TRACE_API void RegisterCategory(TraceCategoryId id, const std::string &name)
GLuint const GLchar * name
Definition: glcorearb.h:785
TRACE_API std::vector< std::string > GetCategories(TraceCategoryId id) const
Returns all names associated with the id.
static TRACE_API TraceCategory & GetInstance()
Singleton accessor.
TRACE_API_TEMPLATE_CLASS(TfSingleton< TraceCategory >)
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
GA_API const UT_StringHolder N
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:44
static constexpr TraceCategoryId CreateTraceCategoryId(const char(&str)[N])
Computes an id for the given a string literal str.
Definition: category.h:58
#define TRACE_API
Definition: api.h:40