From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QCY1V-0002Ww-S4 for garchives@archives.gentoo.org; Wed, 20 Apr 2011 14:04:54 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C5FF01C097; Wed, 20 Apr 2011 14:04:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 7172F1C096 for ; Wed, 20 Apr 2011 14:04:15 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id A4C931B4044 for ; Wed, 20 Apr 2011 14:04:14 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id AB8258024A for ; Wed, 20 Apr 2011 14:04:13 +0000 (UTC) From: "Petteri Räty" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Petteri Räty" Message-ID: Subject: [gentoo-commits] proj/libbash:master commit in: src/core/ X-VCS-Repository: proj/libbash X-VCS-Files: src/core/interpreter.cpp src/core/interpreter.h X-VCS-Directories: src/core/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: d508b94013714beb82a73b854d1a082754b7e999 Date: Wed, 20 Apr 2011 14:04:13 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: c71ebaa9adb0630e4d46492de9f37806 commit: d508b94013714beb82a73b854d1a082754b7e999 Author: Mu Qiao gentoo org> AuthorDate: Thu Apr 14 05:16:57 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Wed Apr 20 12:48:43 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3Dd508b940 Core: add const modifier to some methods These methods should have been declared as const methods. After having the hash table stored inside the interpreter class, it's easier to do it. --- src/core/interpreter.cpp | 6 +++--- src/core/interpreter.h | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/core/interpreter.cpp b/src/core/interpreter.cpp index c723173..d9004e8 100644 --- a/src/core/interpreter.cpp +++ b/src/core/interpreter.cpp @@ -28,7 +28,7 @@ =20 void interpreter::get_all_elements_joined(const std::string& name, const std::string& delim, - std::string& result) + std::string& result) const { std::vector source; =20 @@ -45,13 +45,13 @@ void interpreter::get_all_elements_joined(const std::= string& name, } =20 void interpreter::get_all_elements(const std::string& name, - std::string& result) + std::string& result) const { get_all_elements_joined(name, " ", result); } =20 void interpreter::get_all_elements_IFS_joined(const std::string& name, - std::string& result) + std::string& result) const { get_all_elements_joined(name, resolve("IFS").substr(0, 1), diff --git a/src/core/interpreter.h b/src/core/interpreter.h index e61748a..6385e6e 100644 --- a/src/core/interpreter.h +++ b/src/core/interpreter.h @@ -52,7 +52,7 @@ class interpreter{ /// \param[in,out] a value/result argument referring to offset /// \param[in] the original string /// \return whether the real offset is in legal range - bool get_real_offset(int& offset, const std::string& str) + bool get_real_offset(int& offset, const std::string& str) const { offset =3D (offset >=3D 0? offset : str.size() + offset); return !(offset < 0 || offset >=3D static_cast(str.size())); @@ -60,7 +60,7 @@ class interpreter{ =20 void get_all_elements_joined(const std::string& name, const std::string& delim, - std::string& result); + std::string& result) const; =20 public: =20 @@ -72,7 +72,7 @@ public: /// /// \brief return the number of variables /// \return the number of variables - scope::size_type size() + scope::size_type size() const { return members.size(); } @@ -378,7 +378,7 @@ public: /// \return the value of the variable, call default constructor if /// it's undefined template - T resolve(const std::string& name, const unsigned index=3D0) + T resolve(const std::string& name, const unsigned index=3D0) const { auto i =3D members.find(name); if(i =3D=3D members.end()) @@ -390,7 +390,7 @@ public: /// \param variable name /// \param[out] vector that stores all array values template - void resolve_array(const std::string& name, std::vector& values) + void resolve_array(const std::string& name, std::vector& values) co= nst { auto i =3D members.find(name); if(i =3D=3D members.end()) @@ -403,7 +403,7 @@ public: /// if the variable is undefined /// \param variable name /// \return whether the value of the variable is null - bool is_unset_or_null(const std::string& name, const unsigned index) + bool is_unset_or_null(const std::string& name, const unsigned index) c= onst { auto i =3D members.find(name); if(i =3D=3D members.end()) @@ -415,7 +415,7 @@ public: /// \brief check whether the value of the variable is unset /// \param variable name /// \return whether the value of the variable is unset - bool is_unset(const std::string& name) + bool is_unset(const std::string& name) const { return members.find(name) =3D=3D members.end(); } @@ -463,7 +463,7 @@ public: /// \return the expansion result const std::string do_default_expansion(const std::string& name, const std::string& value, - const unsigned index) + const unsigned index) const { return (is_unset_or_null(name, index)? value : resolve(name, index)); @@ -487,7 +487,7 @@ public: /// \return the expansion result const std::string do_alternate_expansion(const std::string& name, const std::string& value, - const unsigned index) + const unsigned index) const { return (is_unset_or_null(name, index)? "" : value); } @@ -497,7 +497,7 @@ public: /// \return the expansion result const std::string do_substring_expansion(const std::string& name, int offset, - const unsigned index) + const unsigned index) const { std::string value =3D resolve(name, index); if(!get_real_offset(offset, value)) @@ -512,7 +512,7 @@ public: const std::string do_substring_expansion(const std::string& name, int offset, int length, - const unsigned index) + const unsigned index) const { if(length < 0) throw interpreter_exception("length of substring expression should= be greater or equal to zero"); @@ -525,7 +525,7 @@ public: /// \brief get the length of a string variable /// \param the name of the variable /// \return the length - unsigned get_length(const std::string& name, const unsigned index=3D0) + unsigned get_length(const std::string& name, const unsigned index=3D0)= const { auto i =3D members.find(name); if(i =3D=3D members.end()) @@ -536,7 +536,7 @@ public: /// \brief get the length of an array /// \param the name of the array /// \return the length of the array - unsigned get_array_length(const std::string& name) + unsigned get_array_length(const std::string& name) const { auto i =3D members.find(name); if(i =3D=3D members.end()) @@ -545,8 +545,8 @@ public: return i->second->get_array_length(); } =20 - void get_all_elements(const std::string&, std::string&); + void get_all_elements(const std::string&, std::string&) const; =20 - void get_all_elements_IFS_joined(const std::string&, std::string&); + void get_all_elements_IFS_joined(const std::string&, std::string&) con= st; }; #endif