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 
29 
30 #include "pxr/pxr.h"
31 
32 #include "pxr/base/trace/api.h"
33 #include "pxr/base/tf/singleton.h"
34 #include "pxr/base/trace/stringHash.h"
35 
36 #include <cstdint>
37 #include <map>
38 #include <string>
39 #include <vector>
40 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
44 using TraceCategoryId = uint32_t;
45 
55 public:
57  template <int N>
59  const char (&str)[N]) {
60  return TraceStringHash::Hash(str);
61  }
62 
65  enum : TraceCategoryId { Default = 0 };
66 
69  TRACE_API void RegisterCategory(TraceCategoryId id, const std::string& name);
70 
72  TRACE_API std::vector<std::string> GetCategories(TraceCategoryId id) const;
73 
75  TRACE_API static TraceCategory& GetInstance();
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 
86 TRACE_API_TEMPLATE_CLASS(TfSingleton<TraceCategory>);
87 
88 PXR_NAMESPACE_CLOSE_SCOPE
89 
90 #endif // PXR_BASE_TRACE_CATEGORY_H
Manage a single instance of an object.
static constexpr TraceCategoryId CreateTraceCategoryId(const char(&str)[N])
Computes an id for the given a string literal str.
Definition: category.h:58
Manage a single instance of an object (see.
Definition: singleton.h:122
static TRACE_API TraceCategory & GetInstance()
Singleton accessor.
TRACE_API void RegisterCategory(TraceCategoryId id, const std::string &name)
Associates the id with name.
This singleton class provides a way to mark TraceEvent instances with category Ids which can be used ...
Definition: category.h:54
TRACE_API std::vector< std::string > GetCategories(TraceCategoryId id) const
Returns all names associated with the id.
static constexpr std::uint32_t Hash(const char(&str)[N])
Computes a compile time hash of str.
Definition: stringHash.h:46
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:44