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, software
13   distributed under the License is distributed on an "AS IS" BASIS,
14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   See the License for the specific language governing permissions and
16   limitations under the License.
17 */
18 //////////////////////////////////////////////////////////////////////////////////////////////
19 // Public interface for creating all values.
20 //
21 //
22 #pragma once
23 
24 #include <string>
25 #include <vector>
26 
27 #include "ts/ts.h"
28 
29 #include "resources.h"
30 #include "statement.h"
31 #include "condition.h"
32 
33 ///////////////////////////////////////////////////////////////////////////////
34 // Base class for all Values (this is also the interface).
35 //
36 // TODO: This is very incomplete, we need to support linked lists of these,
37 // which evaluate each component and create a "joined" final string.
38 //
39 class Value : Statement
40 {
41 public:
Value()42   Value() { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Value"); }
43 
44   ~Value() override;
45 
46   // noncopyable
47   Value(const Value &) = delete;
48   void operator=(const Value &) = delete;
49 
50   void set_value(const std::string &val);
51 
52   void
append_value(std::string & s,const Resources & res)53   append_value(std::string &s, const Resources &res) const
54   {
55     if (!_cond_vals.empty()) {
56       for (auto _cond_val : _cond_vals) {
57         _cond_val->append_value(s, res);
58       }
59     } else {
60       s += _value;
61     }
62   }
63 
64   const std::string &
get_value()65   get_value() const
66   {
67     return _value;
68   }
69 
70   size_t
size()71   size() const
72   {
73     return _value.size();
74   }
75 
76   int
get_int_value()77   get_int_value() const
78   {
79     return _int_value;
80   }
81 
82   double
get_float_value()83   get_float_value() const
84   {
85     return _float_value;
86   }
87 
88   bool
empty()89   empty() const
90   {
91     return _value.empty();
92   }
93 
94 private:
95   int _int_value      = 0;
96   double _float_value = 0.0;
97   std::string _value;
98   std::vector<Condition *> _cond_vals;
99 };
100