Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/libbash:master commit in: src/core/
Date: Wed, 20 Apr 2011 14:04:54
Message-Id: d508b94013714beb82a73b854d1a082754b7e999.betelgeuse@gentoo
1 commit: d508b94013714beb82a73b854d1a082754b7e999
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Thu Apr 14 05:16:57 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Wed Apr 20 12:48:43 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=d508b940
7
8 Core: add const modifier to some methods
9
10 These methods should have been declared as const methods. After
11 having the hash table stored inside the interpreter class, it's
12 easier to do it.
13
14 ---
15 src/core/interpreter.cpp | 6 +++---
16 src/core/interpreter.h | 30 +++++++++++++++---------------
17 2 files changed, 18 insertions(+), 18 deletions(-)
18
19 diff --git a/src/core/interpreter.cpp b/src/core/interpreter.cpp
20 index c723173..d9004e8 100644
21 --- a/src/core/interpreter.cpp
22 +++ b/src/core/interpreter.cpp
23 @@ -28,7 +28,7 @@
24
25 void interpreter::get_all_elements_joined(const std::string& name,
26 const std::string& delim,
27 - std::string& result)
28 + std::string& result) const
29 {
30 std::vector<std::string> source;
31
32 @@ -45,13 +45,13 @@ void interpreter::get_all_elements_joined(const std::string& name,
33 }
34
35 void interpreter::get_all_elements(const std::string& name,
36 - std::string& result)
37 + std::string& result) const
38 {
39 get_all_elements_joined(name, " ", result);
40 }
41
42 void interpreter::get_all_elements_IFS_joined(const std::string& name,
43 - std::string& result)
44 + std::string& result) const
45 {
46 get_all_elements_joined(name,
47 resolve<std::string>("IFS").substr(0, 1),
48
49 diff --git a/src/core/interpreter.h b/src/core/interpreter.h
50 index e61748a..6385e6e 100644
51 --- a/src/core/interpreter.h
52 +++ b/src/core/interpreter.h
53 @@ -52,7 +52,7 @@ class interpreter{
54 /// \param[in,out] a value/result argument referring to offset
55 /// \param[in] the original string
56 /// \return whether the real offset is in legal range
57 - bool get_real_offset(int& offset, const std::string& str)
58 + bool get_real_offset(int& offset, const std::string& str) const
59 {
60 offset = (offset >= 0? offset : str.size() + offset);
61 return !(offset < 0 || offset >= static_cast<int>(str.size()));
62 @@ -60,7 +60,7 @@ class interpreter{
63
64 void get_all_elements_joined(const std::string& name,
65 const std::string& delim,
66 - std::string& result);
67 + std::string& result) const;
68
69 public:
70
71 @@ -72,7 +72,7 @@ public:
72 ///
73 /// \brief return the number of variables
74 /// \return the number of variables
75 - scope::size_type size()
76 + scope::size_type size() const
77 {
78 return members.size();
79 }
80 @@ -378,7 +378,7 @@ public:
81 /// \return the value of the variable, call default constructor if
82 /// it's undefined
83 template <typename T>
84 - T resolve(const std::string& name, const unsigned index=0)
85 + T resolve(const std::string& name, const unsigned index=0) const
86 {
87 auto i = members.find(name);
88 if(i == members.end())
89 @@ -390,7 +390,7 @@ public:
90 /// \param variable name
91 /// \param[out] vector that stores all array values
92 template <typename T>
93 - void resolve_array(const std::string& name, std::vector<T>& values)
94 + void resolve_array(const std::string& name, std::vector<T>& values) const
95 {
96 auto i = members.find(name);
97 if(i == members.end())
98 @@ -403,7 +403,7 @@ public:
99 /// if the variable is undefined
100 /// \param variable name
101 /// \return whether the value of the variable is null
102 - bool is_unset_or_null(const std::string& name, const unsigned index)
103 + bool is_unset_or_null(const std::string& name, const unsigned index) const
104 {
105 auto i = members.find(name);
106 if(i == members.end())
107 @@ -415,7 +415,7 @@ public:
108 /// \brief check whether the value of the variable is unset
109 /// \param variable name
110 /// \return whether the value of the variable is unset
111 - bool is_unset(const std::string& name)
112 + bool is_unset(const std::string& name) const
113 {
114 return members.find(name) == members.end();
115 }
116 @@ -463,7 +463,7 @@ public:
117 /// \return the expansion result
118 const std::string do_default_expansion(const std::string& name,
119 const std::string& value,
120 - const unsigned index)
121 + const unsigned index) const
122 {
123 return (is_unset_or_null(name, index)?
124 value : resolve<std::string>(name, index));
125 @@ -487,7 +487,7 @@ public:
126 /// \return the expansion result
127 const std::string do_alternate_expansion(const std::string& name,
128 const std::string& value,
129 - const unsigned index)
130 + const unsigned index) const
131 {
132 return (is_unset_or_null(name, index)? "" : value);
133 }
134 @@ -497,7 +497,7 @@ public:
135 /// \return the expansion result
136 const std::string do_substring_expansion(const std::string& name,
137 int offset,
138 - const unsigned index)
139 + const unsigned index) const
140 {
141 std::string value = resolve<std::string>(name, index);
142 if(!get_real_offset(offset, value))
143 @@ -512,7 +512,7 @@ public:
144 const std::string do_substring_expansion(const std::string& name,
145 int offset,
146 int length,
147 - const unsigned index)
148 + const unsigned index) const
149 {
150 if(length < 0)
151 throw interpreter_exception("length of substring expression should be greater or equal to zero");
152 @@ -525,7 +525,7 @@ public:
153 /// \brief get the length of a string variable
154 /// \param the name of the variable
155 /// \return the length
156 - unsigned get_length(const std::string& name, const unsigned index=0)
157 + unsigned get_length(const std::string& name, const unsigned index=0) const
158 {
159 auto i = members.find(name);
160 if(i == members.end())
161 @@ -536,7 +536,7 @@ public:
162 /// \brief get the length of an array
163 /// \param the name of the array
164 /// \return the length of the array
165 - unsigned get_array_length(const std::string& name)
166 + unsigned get_array_length(const std::string& name) const
167 {
168 auto i = members.find(name);
169 if(i == members.end())
170 @@ -545,8 +545,8 @@ public:
171 return i->second->get_array_length();
172 }
173
174 - void get_all_elements(const std::string&, std::string&);
175 + void get_all_elements(const std::string&, std::string&) const;
176
177 - void get_all_elements_IFS_joined(const std::string&, std::string&);
178 + void get_all_elements_IFS_joined(const std::string&, std::string&) const;
179 };
180 #endif