Subversion Repositories SmartDukaan

Rev

Rev 30 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements. See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership. The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License. You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied. See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
 
20
#ifndef T_CONST_VALUE_H
21
#define T_CONST_VALUE_H
22
 
23
#include "t_const.h"
24
#include <stdint.h>
25
#include <map>
26
#include <vector>
27
 
28
/**
29
 * A const value is something parsed that could be a map, set, list, struct
30
 * or whatever.
31
 *
32
 */
33
class t_const_value {
34
 public:
35
 
36
  enum t_const_value_type {
37
    CV_INTEGER,
38
    CV_DOUBLE,
39
    CV_STRING,
40
    CV_MAP,
41
    CV_LIST
42
  };
43
 
44
  t_const_value() {}
45
 
46
  t_const_value(int64_t val) {
47
    set_integer(val);
48
  }
49
 
50
  t_const_value(std::string val) {
51
    set_string(val);
52
  }
53
 
54
  void set_string(std::string val) {
55
    valType_ = CV_STRING;
56
    stringVal_ = val;
57
  }
58
 
59
  std::string get_string() const {
60
    return stringVal_;
61
  }
62
 
63
  void set_integer(int64_t val) {
64
    valType_ = CV_INTEGER;
65
    intVal_ = val;
66
  }
67
 
68
  int64_t get_integer() const {
69
    return intVal_;
70
  }
71
 
72
  void set_double(double val) {
73
    valType_ = CV_DOUBLE;
74
    doubleVal_ = val;
75
  }
76
 
77
  double get_double() const {
78
    return doubleVal_;
79
  }
80
 
81
  void set_map() {
82
    valType_ = CV_MAP;
83
  }
84
 
85
  void add_map(t_const_value* key, t_const_value* val) {
86
    mapVal_[key] = val;
87
  }
88
 
89
  const std::map<t_const_value*, t_const_value*>& get_map() const {
90
    return mapVal_;
91
  }
92
 
93
  void set_list() {
94
    valType_ = CV_LIST;
95
  }
96
 
97
  void add_list(t_const_value* val) {
98
    listVal_.push_back(val);
99
  }
100
 
101
  const std::vector<t_const_value*>& get_list() const {
102
    return listVal_;
103
  }
104
 
105
  t_const_value_type get_type() const {
106
    return valType_;
107
  }
108
 
109
 private:
110
  std::map<t_const_value*, t_const_value*> mapVal_;
111
  std::vector<t_const_value*> listVal_;
112
  std::string stringVal_;
113
  int64_t intVal_;
114
  double doubleVal_;
115
 
116
  t_const_value_type valType_;
117
 
118
};
119
 
120
#endif
121