// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_NODE_ATTACHED_DATA_H_ #define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_NODE_ATTACHED_DATA_H_ #include <memory> #include "base/check_op.h" namespace performance_manager { class Node; // NodeAttachedData allows external observers of the graph to store data that is // associated with a graph node, providing lifetime management as a service. // // External (to performance_manager) implementations of NodeAttachedData should // derive from ExternalNodeAttachedDataImpl. For internal implementations refer // to NodeAttachedDataImpl and see node_attached_data_impl.h. class NodeAttachedData { … }; // Implements NodeAttachedData for a given UserDataType. // // In order for a UserDataType to be attached to a node of type |NodeType| it // must have a constructor of the form "UserDataType(const NodeType* node)". template <typename UserDataType> class ExternalNodeAttachedDataImpl : public NodeAttachedData { … }; // Everything below this point is pure implementation detail. // Provides access for setting/getting data in the map based storage. Not // intended to be used directly, but rather by (External)NodeAttachedDataImpl. class NodeAttachedDataMapHelper { … }; // Implementation of ExternalNodeAttachedDataImpl, which is declared in the // corresponding public header. This helps keep the public headers as clean as // possible. // static template <typename UserDataType> constexpr int ExternalNodeAttachedDataImpl<UserDataType>::kUserDataKey; template <typename UserDataType> template <typename NodeType> UserDataType* ExternalNodeAttachedDataImpl<UserDataType>::GetOrCreate( const NodeType* node) { … } template <typename UserDataType> template <typename NodeType> UserDataType* ExternalNodeAttachedDataImpl<UserDataType>::Get( const NodeType* node) { … } template <typename UserDataType> template <typename NodeType> bool ExternalNodeAttachedDataImpl<UserDataType>::Destroy(const NodeType* node) { … } } // namespace performance_manager #endif // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_NODE_ATTACHED_DATA_H_