Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: tools/gn/value_extractors.h

Issue 26537002: Add a UniqueVector class to GN (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: REview comments, remove npos Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/unique_vector_unittest.cc ('k') | tools/gn/value_extractors.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef TOOLS_GN_VALUE_EXTRACTORS_H_ 5 #ifndef TOOLS_GN_VALUE_EXTRACTORS_H_
6 #define TOOLS_GN_VALUE_EXTRACTORS_H_ 6 #define TOOLS_GN_VALUE_EXTRACTORS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "tools/gn/target.h" 11 #include "tools/gn/label_ptr.h"
12 #include "tools/gn/value.h" 12 #include "tools/gn/unique_vector.h"
13 13
14 class BuildSettings; 14 class BuildSettings;
15 class Err; 15 class Err;
16 class Label; 16 class Label;
17 class SourceDir; 17 class SourceDir;
18 class SourceFile; 18 class SourceFile;
19 19 class Value;
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 20
36 // On failure, returns false and sets the error. 21 // On failure, returns false and sets the error.
37 bool ExtractListOfStringValues(const Value& value, 22 bool ExtractListOfStringValues(const Value& value,
38 std::vector<std::string>* dest, 23 std::vector<std::string>* dest,
39 Err* err); 24 Err* err);
40 25
41 // Looks for a list of source files relative to a given current dir. 26 // Looks for a list of source files relative to a given current dir.
42 bool ExtractListOfRelativeFiles(const BuildSettings* build_settings, 27 bool ExtractListOfRelativeFiles(const BuildSettings* build_settings,
43 const Value& value, 28 const Value& value,
44 const SourceDir& current_dir, 29 const SourceDir& current_dir,
45 std::vector<SourceFile>* files, 30 std::vector<SourceFile>* files,
46 Err* err); 31 Err* err);
47 32
48 // Looks for a list of source directories relative to a given current dir. 33 // Looks for a list of source directories relative to a given current dir.
49 bool ExtractListOfRelativeDirs(const BuildSettings* build_settings, 34 bool ExtractListOfRelativeDirs(const BuildSettings* build_settings,
50 const Value& value, 35 const Value& value,
51 const SourceDir& current_dir, 36 const SourceDir& current_dir,
52 std::vector<SourceDir>* dest, 37 std::vector<SourceDir>* dest,
53 Err* err); 38 Err* err);
54 39
55 // Extracts the list of labels and their origins to the given vector. Only the 40 // 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. 41 // labels are filled in, the ptr for each pair in the vector will be null.
57 bool ExtractListOfLabels(const Value& value, 42 bool ExtractListOfLabels(const Value& value,
58 const SourceDir& current_dir, 43 const SourceDir& current_dir,
59 const Label& current_toolchain, 44 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, 45 LabelTargetVector* dest,
66 Err* err); 46 Err* err);
67 47
48 // Extracts the list of labels and their origins to the given vector. Only the
49 // labels are filled in, the ptr for each pair in the vector will be null. Sets
50 // an error and returns false if a label is maformed or there are duplicates.
51 bool ExtractListOfUniqueLabels(const Value& value,
52 const SourceDir& current_dir,
53 const Label& current_toolchain,
54 UniqueVector<LabelConfigPair>* dest,
55 Err* err);
56 bool ExtractListOfUniqueLabels(const Value& value,
57 const SourceDir& current_dir,
58 const Label& current_toolchain,
59 UniqueVector<LabelTargetPair>* dest,
60 Err* err);
61
68 bool ExtractRelativeFile(const BuildSettings* build_settings, 62 bool ExtractRelativeFile(const BuildSettings* build_settings,
69 const Value& value, 63 const Value& value,
70 const SourceDir& current_dir, 64 const SourceDir& current_dir,
71 SourceFile* file, 65 SourceFile* file,
72 Err* err); 66 Err* err);
73 67
74 #endif // TOOLS_GN_VALUE_EXTRACTORS_H_ 68 #endif // TOOLS_GN_VALUE_EXTRACTORS_H_
OLDNEW
« no previous file with comments | « tools/gn/unique_vector_unittest.cc ('k') | tools/gn/value_extractors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698