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_VALUE_EXTRACTORS_H_
6 #define TOOLS_GN_VALUE_EXTRACTORS_H_
11 #include "tools/gn/target.h"
12 #include "tools/gn/value.h"
20 // Sets the error and returns false on failure.
21 template<typename T
, class Converter
>
22 bool ListValueExtractor(const Value
& value
, std::vector
<T
>* dest
,
24 const Converter
& converter
) {
25 if (!value
.VerifyTypeIs(Value::LIST
, err
))
27 const std::vector
<Value
>& input_list
= value
.list_value();
28 dest
->resize(input_list
.size());
29 for (size_t i
= 0; i
< input_list
.size(); i
++) {
30 if (!converter(input_list
[i
], &(*dest
)[i
], err
))
36 // On failure, returns false and sets the error.
37 bool ExtractListOfStringValues(const Value
& value
,
38 std::vector
<std::string
>* dest
,
41 // Looks for a list of source files relative to a given current dir.
42 bool ExtractListOfRelativeFiles(const BuildSettings
* build_settings
,
44 const SourceDir
& current_dir
,
45 std::vector
<SourceFile
>* files
,
48 // Looks for a list of source directories relative to a given current dir.
49 bool ExtractListOfRelativeDirs(const BuildSettings
* build_settings
,
51 const SourceDir
& current_dir
,
52 std::vector
<SourceDir
>* dest
,
55 // Extracts the list of labels and their origins to the given vector. Only the
56 // labels are filled in, the ptr for each pair in the vector will be null.
57 bool ExtractListOfLabels(const Value
& value
,
58 const SourceDir
& current_dir
,
59 const Label
& current_toolchain
,
60 LabelConfigVector
* dest
,
62 bool ExtractListOfLabels(const Value
& value
,
63 const SourceDir
& current_dir
,
64 const Label
& current_toolchain
,
65 LabelTargetVector
* dest
,
68 #endif // TOOLS_GN_VALUE_EXTRACTORS_H_