Correct blacklist entry message
[chromium-blink-merge.git] / tools / gn / value.h
blob952f52a7c93f80435c357b20343bb4defa213ad4
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_H_
6 #define TOOLS_GN_VALUE_H_
8 #include "base/basictypes.h"
9 #include "base/logging.h"
10 #include "base/strings/string_piece.h"
11 #include "tools/gn/err.h"
13 class ParseNode;
15 // Represents a variable value in the interpreter.
16 class Value {
17 public:
18 enum Type {
19 NONE = 0,
20 BOOLEAN,
21 INTEGER,
22 STRING,
23 LIST
26 Value();
27 Value(const ParseNode* origin, Type t);
28 Value(const ParseNode* origin, bool bool_val);
29 Value(const ParseNode* origin, int64 int_val);
30 Value(const ParseNode* origin, std::string str_val);
31 Value(const ParseNode* origin, const char* str_val);
32 ~Value();
34 Type type() const { return type_; }
36 // Returns a string describing the given type.
37 static const char* DescribeType(Type t);
39 // Returns the node that made this. May be NULL.
40 const ParseNode* origin() const { return origin_; }
41 void set_origin(const ParseNode* o) { origin_ = o; }
43 bool& boolean_value() {
44 DCHECK(type_ == BOOLEAN);
45 return boolean_value_;
47 const bool& boolean_value() const {
48 DCHECK(type_ == BOOLEAN);
49 return boolean_value_;
52 int64& int_value() {
53 DCHECK(type_ == INTEGER);
54 return int_value_;
56 const int64& int_value() const {
57 DCHECK(type_ == INTEGER);
58 return int_value_;
61 std::string& string_value() {
62 DCHECK(type_ == STRING);
63 return string_value_;
65 const std::string& string_value() const {
66 DCHECK(type_ == STRING);
67 return string_value_;
70 std::vector<Value>& list_value() {
71 DCHECK(type_ == LIST);
72 return list_value_;
74 const std::vector<Value>& list_value() const {
75 DCHECK(type_ == LIST);
76 return list_value_;
79 // Converts the given value to a string. Returns true if strings should be
80 // quoted or the ToString of a string should be the string itself.
81 std::string ToString(bool quote_strings) const;
83 // Verifies that the value is of the given type. If it isn't, returns
84 // false and sets the error.
85 bool VerifyTypeIs(Type t, Err* err) const;
87 // Compares values. Only the "value" is compared, not the origin.
88 bool operator==(const Value& other) const;
89 bool operator!=(const Value& other) const;
91 private:
92 Type type_;
93 std::string string_value_;
94 bool boolean_value_;
95 int64 int_value_;
96 std::vector<Value> list_value_;
97 const ParseNode* origin_;
100 #endif // TOOLS_GN_VALUE_H_