- add sources.
[platform/framework/web/crosswalk.git] / src / tools / gn / value_extractors.h
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_VALUE_EXTRACTORS_H_
6 #define TOOLS_GN_VALUE_EXTRACTORS_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "tools/gn/target.h"
12 #include "tools/gn/value.h"
13
14 class BuildSettings;
15 class Err;
16 class Label;
17 class SourceDir;
18 class SourceFile;
19
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,
23                         Err* err,
24                         const Converter& converter) {
25   if (!value.VerifyTypeIs(Value::LIST, err))
26     return false;
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))
31       return false;
32   }
33   return true;
34 }
35
36 // On failure, returns false and sets the error.
37 bool ExtractListOfStringValues(const Value& value,
38                                std::vector<std::string>* dest,
39                                Err* err);
40
41 // Looks for a list of source files relative to a given current dir.
42 bool ExtractListOfRelativeFiles(const BuildSettings* build_settings,
43                                 const Value& value,
44                                 const SourceDir& current_dir,
45                                 std::vector<SourceFile>* files,
46                                 Err* err);
47
48 // Looks for a list of source directories relative to a given current dir.
49 bool ExtractListOfRelativeDirs(const BuildSettings* build_settings,
50                                const Value& value,
51                                const SourceDir& current_dir,
52                                std::vector<SourceDir>* dest,
53                                Err* err);
54
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,
61                          Err* err);
62 bool ExtractListOfLabels(const Value& value,
63                          const SourceDir& current_dir,
64                          const Label& current_toolchain,
65                          LabelTargetVector* dest,
66                          Err* err);
67
68 #endif  // TOOLS_GN_VALUE_EXTRACTORS_H_