Correct blacklist entry message
[chromium-blink-merge.git] / tools / gn / label_ptr.h
blob9bc3df22eb7780422a898f881e926adbc2479be6
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef TOOLS_GN_LABEL_PTR_H_
6 #define TOOLS_GN_LABEL_PTR_H_
8 #include <functional>
10 class ParseNode;
12 // Structure that holds a labeled "thing". This is used for various places
13 // where we need to store lists of targets or configs. We sometimes populate
14 // the pointers on another thread from where we compute the labels, so this
15 // structure lets us save them separately. This also allows us to store the
16 // location of the thing that added this dependency.
17 template<typename T>
18 struct LabelPtrPair {
19 typedef T DestType;
21 LabelPtrPair() : label(), ptr(NULL), origin(NULL) {}
23 // This contructor is typically used in unit tests, it extracts the label
24 // automatically from a given pointer.
25 explicit LabelPtrPair(const T* p) : label(p->label()), ptr(p), origin(NULL) {
28 ~LabelPtrPair() {}
30 Label label;
31 const T* ptr; // May be NULL.
32 const ParseNode* origin; // May be NULL.
35 typedef LabelPtrPair<Config> LabelConfigPair;
36 typedef LabelPtrPair<Target> LabelTargetPair;
38 typedef std::vector<LabelConfigPair> LabelConfigVector;
39 typedef std::vector<LabelTargetPair> LabelTargetVector;
41 // Comparison and search functions ---------------------------------------------
43 // To do a brute-force search by label:
44 // std::find_if(vect.begin(), vect.end(), LabelPtrLabelEquals<Config>(label));
45 template<typename T>
46 struct LabelPtrLabelEquals : public std::unary_function<Label, bool> {
47 explicit LabelPtrLabelEquals(const Label& l) : label(l) {}
49 bool operator()(const LabelPtrPair<T>& arg) const {
50 return arg.label == label;
53 const Label& label;
56 // To do a brute-force search by object pointer:
57 // std::find_if(vect.begin(), vect.end(), LabelPtrLabelEquals<Config>(config));
58 template<typename T>
59 struct LabelPtrPtrEquals : public std::unary_function<T, bool> {
60 explicit LabelPtrPtrEquals(const T* p) : ptr(p) {}
62 bool operator()(const LabelPtrPair<T>& arg) const {
63 return arg.ptr == ptr;
66 const T* ptr;
69 // To sort by label:
70 // std::sort(vect.begin(), vect.end(), LabelPtrLabelLess<Config>());
71 template<typename T>
72 struct LabelPtrLabelLess : public std::binary_function<LabelPtrPair<T>,
73 LabelPtrPair<T>,
74 bool> {
75 bool operator()(const LabelPtrPair<T>& a, const LabelPtrPair<T>& b) const {
76 return a.label < b.label;
80 #endif // TOOLS_GN_LABEL_PTR_H_