All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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
12
13#include "pxr/pxr.h"
14
15#include "pxr/base/trace/api.h"
17#include "pxr/base/trace/stringHash.h"
18
19#include <cstdint>
20#include <map>
21#include <string>
22#include <vector>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
27using TraceCategoryId = uint32_t;
28
38public:
40 template <int N>
42 const char (&str)[N]) {
43 return TraceStringHash::Hash(str);
44 }
45
48 enum : TraceCategoryId { Default = 0 };
49
52 TRACE_API void RegisterCategory(TraceCategoryId id, const std::string& name);
53
55 TRACE_API std::vector<std::string> GetCategories(TraceCategoryId id) const;
56
58 TRACE_API static TraceCategory& GetInstance();
59
60private:
61 friend class TfSingleton<TraceCategory>;
62
64
65 // Mapping of ids to names.
66 std::multimap<TraceCategoryId, std::string> _idToNames;
67};
68
69TRACE_API_TEMPLATE_CLASS(TfSingleton<TraceCategory>);
70
71PXR_NAMESPACE_CLOSE_SCOPE
72
73#endif // PXR_BASE_TRACE_CATEGORY_H
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:27
Manage a single instance of an object (see.
Definition: singleton.h:105
This singleton class provides a way to mark TraceEvent instances with category Ids which can be used ...
Definition: category.h:37
static constexpr TraceCategoryId CreateTraceCategoryId(const char(&str)[N])
Computes an id for the given a string literal str.
Definition: category.h:41
static TRACE_API TraceCategory & GetInstance()
Singleton accessor.
TRACE_API void RegisterCategory(TraceCategoryId id, const std::string &name)
Associates the id with name.
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:29
Manage a single instance of an object.