[nemiver/follow-fork-mode: 20/35] Clean up Address type and adjust client code



commit 21e1079d583f2072aa4d580a670bf3bebc2024ec
Author: Dodji Seketeli <dodji redhat com>
Date:   Sun Apr 25 13:42:22 2010 +0200

    Clean up Address type and adjust client code
    
    	* src/common/nmv-address.h
    	(Address::operator const std::string& () const): Remove.
    	(Address::to_string() const): New fn.
    	(Address::operator<< (Stream &a_os, const Address &a)): New
    	stream operator template.
    	(Address::Address(const std::string&)): Make this explicit to avoid
    	ambiguity when streaming a string to an ostream.
    	* src/common/nmv-address.cc: Adjust.
    	* src/dbgengine/nmv-gdbmi-parser.cc (GDBMIParser::parse_frame,
    	GDBMIParser::parse_breakpoint, GDBMIParser::parse_call_stack):
    	Adjust to the Address changes.
    	* src/dbgengine/nmv-i-debugger.h (IDebugger::Breakpoint): Make
    	the m_address member be of Address type.
    	(IDebugger::Breakpoint::address, IDebugger::Frame::address): Add a
    	non-const fn overload.
    	(IDebugger::Frame::has_empty_address): Adjust to the Address
    	change.
    	* src/persp/dbgperspective/nmv-breakpoints-view.cc
    	(BreakpointsView::Priv::update_breakpoint): Likewise.
    	* src/persp/dbgperspective/nmv-call-stack.cc
    	(CallStack::Priv::append_frames_to_tree_view): Likewise.
    	* src/persp/dbgperspective/nmv-dbg-perspective.cc
    	(DBGPerspective::get_frame_breakpoints_address_range,
    	DBGPerspective::set_where, DBGPerspective::create_source_editor,
    	DBGPerspective::apply_decorations_to_asm): Likewise.
    	* src/uicommon/nmv-source-editor.cc
    	(SourceEditor::Priv::address_2_line): Likewise.

 src/common/nmv-address.cc                        |    3 ++-
 src/common/nmv-address.h                         |   12 ++++++++++--
 src/dbgengine/nmv-gdbmi-parser.cc                |    7 ++++---
 src/dbgengine/nmv-i-debugger.h                   |    8 +++++---
 src/persp/dbgperspective/nmv-breakpoints-view.cc |    2 +-
 src/persp/dbgperspective/nmv-call-stack.cc       |    2 +-
 src/persp/dbgperspective/nmv-dbg-perspective.cc  |    9 +++++----
 src/uicommon/nmv-source-editor.cc                |    2 +-
 8 files changed, 29 insertions(+), 16 deletions(-)
---
diff --git a/src/common/nmv-address.cc b/src/common/nmv-address.cc
index 16bc499..bcab3a7 100644
--- a/src/common/nmv-address.cc
+++ b/src/common/nmv-address.cc
@@ -49,7 +49,8 @@ Address::empty () const
     return m_addr.empty ();
 }
 
-Address::operator const std::string& () const
+const std::string&
+Address::to_string () const
 {
     return m_addr;
 }
diff --git a/src/common/nmv-address.h b/src/common/nmv-address.h
index 2552477..94562aa 100644
--- a/src/common/nmv-address.h
+++ b/src/common/nmv-address.h
@@ -37,10 +37,10 @@ class NEMIVER_API Address
 
 public:
     Address ();
-    Address (const std::string &a_addr);
+    explicit Address (const std::string &a_addr);
     Address (const Address &);
     bool empty () const;
-    operator const std::string& () const;
+    const std::string& to_string () const;
     operator size_t () const;
     size_t size () const;
     size_t string_size () const;
@@ -51,6 +51,14 @@ public:
     void clear ();
 };// end class Address
 
+template<class Stream>
+Stream&
+operator<< (Stream &a_os, const Address &a)
+{
+    a_os << a.to_string ();
+    return a_os;
+}
+
 NEMIVER_END_NAMESPACE (common)
 NEMIVER_END_NAMESPACE (nemiver)
 
diff --git a/src/dbgengine/nmv-gdbmi-parser.cc b/src/dbgengine/nmv-gdbmi-parser.cc
index cce676a..ff39fd5 100644
--- a/src/dbgengine/nmv-gdbmi-parser.cc
+++ b/src/dbgengine/nmv-gdbmi-parser.cc
@@ -1525,7 +1525,7 @@ GDBMIParser::parse_frame (UString::size_type a_from,
         if (name == "level") {
             frame.level (atoi (value.c_str ()));
         } else if (name == "addr") {
-            frame.address (value.raw ());
+            frame.address () = value.raw ();
         } else if (name == "func") {
             frame.function_name (value.raw ());
         } else if (name == "file") {
@@ -2139,7 +2139,8 @@ GDBMIParser::parse_breakpoint (Glib::ustring::size_type a_from,
     } else {
         a_bkpt.enabled (false);
     }
-    a_bkpt.address (attrs["addr"]);
+    if (str_utils::string_is_hexa_number (attrs["addr"]))
+        a_bkpt.address () = attrs["addr"];
     if (!attrs["func"].empty ()) {
         a_bkpt.function (attrs["func"]);
     }
@@ -2584,7 +2585,7 @@ GDBMIParser::parse_call_stack (const UString::size_type a_from,
             THROW_IF_FAIL ((*frame_part_iter)->value ());
             value = (*frame_part_iter)->value ()->get_string_content ();
             if ((*frame_part_iter)->variable () == "addr") {
-                frame.address (value.raw ());
+                frame.address () = value.raw ();
             } else if ((*frame_part_iter)->variable () == "func") {
                 frame.function_name (value.raw ());
             } else if ((*frame_part_iter)->variable () == "file") {
diff --git a/src/dbgengine/nmv-i-debugger.h b/src/dbgengine/nmv-i-debugger.h
index db9c41d..9b1c9c6 100644
--- a/src/dbgengine/nmv-i-debugger.h
+++ b/src/dbgengine/nmv-i-debugger.h
@@ -91,7 +91,7 @@ public:
     private:
         int m_number;
         bool m_enabled;
-        string m_address;
+        Address m_address;
         string m_function;
         string m_expression;
         UString m_file_name;
@@ -116,7 +116,8 @@ public:
         bool enabled () const {return m_enabled;}
         void enabled (bool a_in) {m_enabled = a_in;}
 
-        const string& address () const {return m_address;}
+        const Address& address () const {return m_address;}
+        Address& address () {return m_address;}
         void address (const string &a_in) {m_address = a_in;}
 
         const string& function () const {return m_function;}
@@ -273,10 +274,11 @@ public:
 
         /// @{
         const Address& address () const {return m_address;}
+        Address& address () {return m_address;}
         void address (const Address &a_in) {m_address = a_in;}
         bool has_empty_address () const
         {
-            return static_cast<std::string> (m_address).empty ();
+            return m_address.to_string ().empty ();
         }
 
         const string& function_name () const {return m_function_name;}
diff --git a/src/persp/dbgperspective/nmv-breakpoints-view.cc b/src/persp/dbgperspective/nmv-breakpoints-view.cc
index 1b08599..34263a4 100644
--- a/src/persp/dbgperspective/nmv-breakpoints-view.cc
+++ b/src/persp/dbgperspective/nmv-breakpoints-view.cc
@@ -274,7 +274,7 @@ public:
         (*a_iter)[get_bp_cols ().enabled] = a_breakpoint.enabled ();
         (*a_iter)[get_bp_cols ().id] = a_breakpoint.number ();
         (*a_iter)[get_bp_cols ().function] = a_breakpoint.function ();
-        (*a_iter)[get_bp_cols ().address] = a_breakpoint.address ();
+        (*a_iter)[get_bp_cols ().address] = a_breakpoint.address ().to_string ();
         (*a_iter)[get_bp_cols ().filename] = a_breakpoint.file_name ();
         (*a_iter)[get_bp_cols ().line] = a_breakpoint.line ();
         (*a_iter)[get_bp_cols ().condition] = a_breakpoint.condition ();
diff --git a/src/persp/dbgperspective/nmv-call-stack.cc b/src/persp/dbgperspective/nmv-call-stack.cc
index 44d1eaf..3620b98 100644
--- a/src/persp/dbgperspective/nmv-call-stack.cc
+++ b/src/persp/dbgperspective/nmv-call-stack.cc
@@ -665,7 +665,7 @@ struct CallStack::Priv {
                     + UString::from_int (a_frames[i].line ());
             } else {
                 (*store_iter)[columns ().location] =
-                    static_cast<std::string> (a_frames[i].address ());
+                    a_frames[i].address ().to_string ();
             }
 
             (*store_iter)[columns ().frame_index] = a_frames[i].level ();
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index 588a654..ab1230b 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.cc
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.cc
@@ -4271,7 +4271,7 @@ DBGPerspective::get_frame_breakpoints_address_range
          it != m_priv->breakpoints.end ();
          ++it) {
         if (breakpoint_and_frame_have_same_file (it->second, a_frame)) {
-            range.extend (str_utils::hexa_to_int (it->second.address ()));
+            range.extend (it->second.address ());
             result = true;
         }
     }
@@ -4515,7 +4515,7 @@ DBGPerspective::set_where (SourceEditor *a_editor,
             return true;
         } else {
             LOG_ERROR ("Fail to get line for address: "
-                       << static_cast<string> (a_address));
+                       << a_address.to_string ());
             return false;
         }
     }
@@ -5515,7 +5515,8 @@ DBGPerspective::create_source_editor (Glib::RefPtr<SourceBuffer> &a_source_buf,
                                                        true));
         if (!a_current_address.empty ()) {
             source_editor->assembly_buf_addr_to_line
-                                    (a_current_address.raw (), current_line);
+                                (Address (a_current_address.raw ()),
+                                 current_line);
         }
     } else {
         source_editor = Gtk::manage (new SourceEditor (plugin_path (),
@@ -7067,7 +7068,7 @@ DBGPerspective::apply_decorations_to_asm (SourceEditor *a_editor,
             if (!append_visual_breakpoint (a_editor, addr,
                                            it->second.enabled ())) {
                 LOG_ERROR ("Could'nt find line for address: "
-                           << static_cast<string> (addr)
+                           << addr.to_string ()
                            << " for file: "
                            << a_editor->get_path ());
             }
diff --git a/src/uicommon/nmv-source-editor.cc b/src/uicommon/nmv-source-editor.cc
index d728c4b..92ab648 100644
--- a/src/uicommon/nmv-source-editor.cc
+++ b/src/uicommon/nmv-source-editor.cc
@@ -299,7 +299,7 @@ struct SourceEditor::Priv {
                  ++it, ++i) {
                 addr += it.get_char ();
             }
-            bool match = (addr == static_cast<std::string> (an_addr));
+            bool match = (addr == an_addr.to_string ());
             if (match) {
                 a_line = it.get_line () + 1;
                 a_prev_addr = prev_addr;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]