forked from LLNL/Caliper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttribute.h
123 lines (91 loc) · 3.11 KB
/
Attribute.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright (c) 2015-2022, Lawrence Livermore National Security, LLC.
// See top-level LICENSE file for details.
/**
* \file Attribute.h
* \brief Attribute class declaration
*/
#ifndef CALI_ATTRIBUTE_H
#define CALI_ATTRIBUTE_H
#include "caliper/common/cali_types.h"
#include "caliper/common/Node.h"
#include "caliper/common/Variant.h"
#include <iostream>
#include <string>
namespace cali
{
/// \brief Encapsulate an attribute key.
///
/// All attribute meta-information (e.g., type, property flags, name) is
/// stored in the context tree. An attribute key is a context tree
/// reference to a \a cali.attribute.name node. This class encapsulates
/// an attribute key node and provides access to the attribute's
/// metadata.
class Attribute
{
public:
constexpr static cali_id_t NAME_ATTR_ID = 8;
constexpr static cali_id_t TYPE_ATTR_ID = 9;
constexpr static cali_id_t PROP_ATTR_ID = 10;
constexpr Attribute()
: m_node(nullptr)
{ }
operator bool() const { return m_node != nullptr; }
cali_id_t id() const { return m_node ? m_node->id() : CALI_INV_ID; }
std::string name() const;
const char* name_c_str() const;
cali_attr_type type() const;
int properties() const;
/// \brief Return the context tree node pointer that represents
/// this attribute key.
Node* node() const {
return m_node;
}
Variant get(const Attribute& attr) const;
bool store_as_value() const {
return properties() & CALI_ATTR_ASVALUE;
}
bool is_autocombineable() const {
return !store_as_value() && !(properties() & CALI_ATTR_NOMERGE);
}
bool skip_events() const {
return properties() & CALI_ATTR_SKIP_EVENTS;
}
bool is_hidden() const {
return properties() & CALI_ATTR_HIDDEN;
}
bool is_nested() const {
return properties() & CALI_ATTR_NESTED;
}
bool is_global() const {
return properties() & CALI_ATTR_GLOBAL;
}
int level() const {
return (properties() & CALI_ATTR_LEVEL_MASK) >> 16;
}
static Attribute make_attribute(Node* node);
static bool is_attribute(const Node* node) {
return node && node->attribute() == NAME_ATTR_ID;
}
static const Attribute invalid;
private:
Node* m_node;
Attribute(Node* node)
: m_node(node)
{ }
friend bool operator < (const cali::Attribute& a, const cali::Attribute& b);
friend bool operator == (const cali::Attribute& a, const cali::Attribute& b);
friend bool operator != (const cali::Attribute& a, const cali::Attribute& b);
};
inline bool operator < (const cali::Attribute& a, const cali::Attribute& b) {
return a.id() < b.id();
}
inline bool operator == (const cali::Attribute& a, const cali::Attribute& b) {
// we don't have copies of nodes, so the ptr should be unique
return a.m_node == b.m_node;
}
inline bool operator != (const cali::Attribute& a, const cali::Attribute& b) {
return a.m_node != b.m_node;
}
std::ostream& operator << (std::ostream&, const cali::Attribute&);
} // namespace cali
#endif // CALI_ATTRIBUTE_H