[nemiver/follow-fork-mode: 12/35] Update the Address type
- From: Dodji Seketeli <dodji src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nemiver/follow-fork-mode: 12/35] Update the Address type
- Date: Thu, 6 May 2010 10:17:06 +0000 (UTC)
commit 264b49607b1b0310b7d246116adbbdbe1ba60b54
Author: Dodji Seketeli <dodji redhat com>
Date: Sat Apr 10 15:47:23 2010 +0200
Update the Address type
* src/common/nmv-address.h (Address::empty,
Address::operator size_t () const, Address::string_size,
operator==(const Address&, const std::string&),
operator==(const Address&, size_t), operator[](size_t),
Address::clear):
Declare new functions.
* src/common/nmv-address.cc (Address::empty,
Address::operator size_t () const, Address::string_size,
operator==(const Address&, const std::string&),
operator==(const Address&, size_t), operator[](size_t)):
Define new functions.
(Address::Address (const std::string &a)): Chomp the address
string.
(Address::operator= (const std::string &a_addr)): Chomp the
newly assigned string.
(Address::size): Make this
src/common/nmv-address.cc | 56 ++++++++++++++++++++++++++++++++++++++++++++-
src/common/nmv-address.h | 10 +++++++-
2 files changed, 64 insertions(+), 2 deletions(-)
---
diff --git a/src/common/nmv-address.cc b/src/common/nmv-address.cc
index 059de7d..16bc499 100644
--- a/src/common/nmv-address.cc
+++ b/src/common/nmv-address.cc
@@ -23,6 +23,7 @@
*See COPYRIGHT file copyright information.
*/
#include "nmv-address.h"
+#include "nmv-str-utils.h"
NEMIVER_BEGIN_NAMESPACE (nemiver)
NEMIVER_BEGIN_NAMESPACE (common)
@@ -34,6 +35,18 @@ Address::Address ()
Address::Address (const std::string &a) :
m_addr (a)
{
+ str_utils::chomp (m_addr);
+}
+
+Address::Address (const Address &a_other) :
+ m_addr (a_other.m_addr)
+{
+}
+
+bool
+Address::empty () const
+{
+ return m_addr.empty ();
}
Address::operator const std::string& () const
@@ -41,7 +54,15 @@ Address::operator const std::string& () const
return m_addr;
}
-int
+Address::operator size_t () const
+{
+ if (m_addr.empty ())
+ return 0;
+ return str_utils::hexa_to_int (m_addr);
+}
+
+
+size_t
Address::size () const
{
if (m_addr.empty ())
@@ -52,12 +73,45 @@ Address::size () const
return m_addr.size () - suffix_len;
}
+size_t
+Address::string_size () const
+{
+ return m_addr.size ();
+}
+
Address&
Address::operator= (const std::string &a_addr)
{
m_addr = a_addr;
+ str_utils::chomp (m_addr);
return *this;
}
+const char&
+Address::operator[] (size_t a_index) const
+{
+ return m_addr[a_index];
+}
+
+void
+Address::clear ()
+{
+ m_addr.clear ();
+}
+
+bool
+operator== (const Address &a_address,
+ const std::string &a_addr)
+{
+ return a_address.m_addr == a_addr;
+}
+
+bool
+operator== (const Address &a_address,
+ size_t a_addr)
+{
+ return (size_t) a_address == a_addr;
+}
+
NEMIVER_END_NAMESPACE (common)
NEMIVER_END_NAMESPACE (nemiver)
diff --git a/src/common/nmv-address.h b/src/common/nmv-address.h
index 56ad91a..2552477 100644
--- a/src/common/nmv-address.h
+++ b/src/common/nmv-address.h
@@ -34,13 +34,21 @@ NEMIVER_BEGIN_NAMESPACE (common)
class NEMIVER_API Address
{
std::string m_addr;
+
public:
Address ();
Address (const std::string &a_addr);
Address (const Address &);
+ bool empty () const;
operator const std::string& () const;
- int size () const;
+ operator size_t () const;
+ size_t size () const;
+ size_t string_size () const;
Address& operator= (const std::string &);
+ friend bool operator== (const Address&, const std::string &);
+ friend bool operator== (const Address&, size_t);
+ const char& operator[] (size_t) const;
+ void clear ();
};// end class Address
NEMIVER_END_NAMESPACE (common)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]