config_values_extractors.h revision 3551c9c881056c480085172ff9840cab31610854
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. 4 5#ifndef TOOLS_GN_CONFIG_VALUES_EXTRACTORS_H_ 6#define TOOLS_GN_CONFIG_VALUES_EXTRACTORS_H_ 7 8#include <ostream> 9#include <string> 10#include <vector> 11 12#include "tools/gn/config.h" 13#include "tools/gn/config_values.h" 14#include "tools/gn/target.h" 15 16struct EscapeOptions; 17 18template<typename T, class Writer> 19inline void ConfigValuesToStream( 20 const ConfigValues& values, 21 const std::vector<T>& (ConfigValues::* getter)() const, 22 const Writer& writer, 23 std::ostream& out) { 24 const std::vector<T>& v = (values.*getter)(); 25 for (size_t i = 0; i < v.size(); i++) 26 writer(v[i], out); 27}; 28 29// Writes a given config value that applies to a given target. This collects 30// all values from the target itself and all configs that apply, and writes 31// then in order. 32template<typename T, class Writer> 33inline void RecursiveTargetConfigToStream( 34 const Target* target, 35 const std::vector<T>& (ConfigValues::* getter)() const, 36 const Writer& writer, 37 std::ostream& out) { 38 // Note: if you make any changes to this, also change the writer in the 39 // implementation of the "desc" command. 40 41 // First write the values from the config itself. 42 ConfigValuesToStream(target->config_values(), getter, writer, out); 43 44 // Then write the configs in order. 45 for (size_t i = 0; i < target->configs().size(); i++) { 46 ConfigValuesToStream(target->configs()[i]->config_values(), getter, 47 writer, out); 48 } 49} 50 51// Writes the values out as strings with no transformation. 52void RecursiveTargetConfigStringsToStream( 53 const Target* target, 54 const std::vector<std::string>& (ConfigValues::* getter)() const, 55 const EscapeOptions& escape_options, 56 std::ostream& out); 57 58#endif // TOOLS_GN_CONFIG_VALUES_EXTRACTORS_H_ 59