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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_BASE_TRACE_CATEGORY_H
9 #define PXR_BASE_TRACE_CATEGORY_H
10 
11 /// \file trace/category.h
12 
13 #include "pxr/pxr.h"
14 
15 #include "pxr/base/trace/api.h"
16 #include "pxr/base/tf/singleton.h"
18 
19 #include <cstdint>
20 #include <map>
21 #include <string>
22 #include <vector>
23 
25 
26 /// Categories that a TraceReporter can use to filter events.
27 using TraceCategoryId = uint32_t;
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 ///
31 /// \class TraceCategory
32 ///
33 /// This singleton class provides a way to mark TraceEvent instances with
34 /// category Ids which can be used to filter them. This class also provides a
35 /// way to associate TraceCategoryId values with human readable names.
36 ///
38 public:
39  /// Computes an id for the given a string literal \p str.
40  template <int N>
42  const char (&str)[N]) {
43  return TraceStringHash::Hash(str);
44  }
45 
46  /// Default category if none are explicitly specified when creating a
47  /// TraceEvent.
48  enum : TraceCategoryId { Default = 0 };
49 
50  /// Associates the \p id with \p name. These associates are not necessarily
51  /// unique.
52  TRACE_API void RegisterCategory(TraceCategoryId id, const std::string& name);
53 
54  /// Returns all names associated with the \p id.
55  TRACE_API std::vector<std::string> GetCategories(TraceCategoryId id) const;
56 
57  /// Singleton accessor.
59 
60 private:
61  friend class TfSingleton<TraceCategory>;
62 
63  TraceCategory();
64 
65  // Mapping of ids to names.
66  std::multimap<TraceCategoryId, std::string> _idToNames;
67 };
68 
70 
72 
73 #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:29
TRACE_API void RegisterCategory(TraceCategoryId id, const std::string &name)
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 >)
GLuint const GLchar * name
Definition: glcorearb.h:786
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GA_API const UT_StringHolder N
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:27
static constexpr TraceCategoryId CreateTraceCategoryId(const char(&str)[N])
Computes an id for the given a string literal str.
Definition: category.h:41
#define TRACE_API
Definition: api.h:23