[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / tools / gn / config.h
blob20cfe7e40dc208eac3d2509edbcca93a7338d4ac
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_CONFIG_H_
6 #define TOOLS_GN_CONFIG_H_
8 #include "base/logging.h"
9 #include "base/macros.h"
10 #include "tools/gn/config_values.h"
11 #include "tools/gn/item.h"
12 #include "tools/gn/label_ptr.h"
13 #include "tools/gn/unique_vector.h"
15 // Represents a named config in the dependency graph.
17 // A config can list other configs. We track both the data assigned directly
18 // on the config, this list of sub-configs, and (when the config is resolved)
19 // the resulting values of everything merged together. The flatten step
20 // means we can avoid doing a recursive config walk for every target to compute
21 // flags.
22 class Config : public Item {
23 public:
24 Config(const Settings* settings, const Label& label);
25 ~Config() override;
27 // Item implementation.
28 Config* AsConfig() override;
29 const Config* AsConfig() const override;
30 bool OnResolved(Err* err) override;
32 // The values set directly on this config. This will not contain data from
33 // sub-configs.
34 ConfigValues& own_values() { return own_values_; }
35 const ConfigValues& own_values() const { return own_values_; }
37 // The values that represent this config and all sub-configs combined into
38 // one. This is only valid after the config is resolved (when we know the
39 // contents of the sub-configs).
40 const ConfigValues& resolved_values() const {
41 DCHECK(resolved_);
42 if (configs_.empty()) // No sub configs, just use the regular values.
43 return own_values_;
44 return composite_values_;
47 // List of sub-configs.
48 const UniqueVector<LabelConfigPair>& configs() const { return configs_; }
49 UniqueVector<LabelConfigPair>& configs() { return configs_; }
51 private:
52 ConfigValues own_values_;
54 // Contains the own_values combined with sub-configs. Most configs don't have
55 // sub-configs. So as an optimization, this is not populated if there are no
56 // items in configs_. The resolved_values() getter handles this.
57 bool resolved_;
58 ConfigValues composite_values_;
60 UniqueVector<LabelConfigPair> configs_;
62 DISALLOW_COPY_AND_ASSIGN(Config);
65 #endif // TOOLS_GN_CONFIG_H_