blob: 1e8f30240e8e9c3563c18b235debf4da66a6b089 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2019 The Chromium Authors
Chris Hamilton77da59d2019-06-04 15:59:322// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Sigurdur Asgeirsson51d9d242019-10-07 20:38:345#ifndef COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_NODE_H_
6#define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_NODE_H_
Chris Hamilton77da59d2019-06-04 15:59:327
8#include <cstdint>
9
Patrick Monette0564af7c2024-06-05 16:19:4810#include "base/check_op.h"
Chris Hamiltonf86f6342021-03-30 16:42:3411#include "components/performance_manager/public/graph/node_state.h"
Patrick Monette0564af7c2024-06-05 16:19:4812#include "components/performance_manager/public/graph/node_type.h"
Chris Hamilton77da59d2019-06-04 15:59:3213
14namespace performance_manager {
15
16class Graph;
17
18// Interface that all nodes must implement.
Chris Hamilton77da59d2019-06-04 15:59:3219class Node {
20 public:
21 Node();
Peter Boström09c01822021-09-20 22:43:2722
23 Node(const Node&) = delete;
24 Node& operator=(const Node&) = delete;
25
Chris Hamilton77da59d2019-06-04 15:59:3226 virtual ~Node();
27
Patrick Monette0564af7c2024-06-05 16:19:4828 // Returns the type of this node.
29 virtual NodeTypeEnum GetNodeType() const = 0;
30
Chris Hamilton77da59d2019-06-04 15:59:3231 // Returns the graph to which this node belongs.
32 virtual Graph* GetGraph() const = 0;
33
34 // The following functions are implementation detail and should not need to be
35 // used by external clients. They provide the ability to safely downcast to
36 // the underlying implementation.
37 virtual uintptr_t GetImplType() const = 0;
38 virtual const void* GetImpl() const = 0;
Chris Hamilton77da59d2019-06-04 15:59:3239};
40
Patrick Monette0564af7c2024-06-05 16:19:4841template <class PublicNodeClass>
42class TypedNode : public Node {
43 public:
44 TypedNode() = default;
45 ~TypedNode() override = default;
46
47 NodeTypeEnum GetNodeType() const override { return PublicNodeClass::Type(); }
48
49 // Helper function for casting from the generic Node type to its underlying
50 // public node type. This CHECKs that the cast is valid.
51 static const PublicNodeClass* FromNode(const Node* node) {
52 CHECK_EQ(node->GetNodeType(), PublicNodeClass::Type());
53 return reinterpret_cast<const PublicNodeClass*>(node);
54 }
55};
56
Chris Hamilton77da59d2019-06-04 15:59:3257} // namespace performance_manager
58
Sigurdur Asgeirsson51d9d242019-10-07 20:38:3459#endif // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_NODE_H_