Improved Host interface by including const parameters and assertions
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Tue, 22 Feb 2011 16:12:40 +0000 (17:12 +0100)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Tue, 22 Feb 2011 16:12:40 +0000 (17:12 +0100)
src/ping/host.cpp
src/ping/host.h

index 1bdadb3..89773c1 100644 (file)
@@ -1,3 +1,6 @@
+#include <boost/assert.hpp>
+#include <climits>
+
 #include "host.h"
 
 //-----------------------------------------------------------------------------
@@ -21,8 +24,10 @@ std::string Host::get_address() const
     return address;
 }
 
-void Host::set_address( std::string address )
+void Host::set_address( const std::string& address )
 {
+    BOOST_ASSERT( !address.empty() );
+
     this->address = address;
 }
 
@@ -31,8 +36,10 @@ uint16_t Host::get_port() const
     return port;
 }
 
-void Host::set_port( uint16_t port )
+void Host::set_port( const uint16_t port )
 {
+    BOOST_ASSERT( ( 0 < port ) && ( port < USHRT_MAX ) );
+
     this->port = port;
 }
 
@@ -41,8 +48,10 @@ uint32_t Host::get_interval() const
     return interval;
 }
 
-void Host::set_interval( uint32_t interval )
+void Host::set_interval( const uint32_t interval )
 {
+    BOOST_ASSERT( ( 0 < interval ) && ( interval < UINT_MAX ) );
+
     this->interval = interval;
 }
 
@@ -51,7 +60,7 @@ std::vector<std::string> Host::get_options() const
     return options;
 }
 
-void Host::set_options( std::vector<std::string> options )
+void Host::set_options( const std::vector<std::string>& options )
 {
     this->options = options;
 }
index e9ec04f..7ba9cbd 100644 (file)
@@ -17,16 +17,16 @@ public:
     virtual ~Host();
 
     std::string get_address() const;
-    void set_address( std::string address );
+    void set_address( const std::string& address );
 
     uint16_t get_port() const;
-    void set_port( uint16_t port );
+    void set_port( const uint16_t port );
 
     uint32_t get_interval() const;
-    void set_interval( uint32_t interval );
+    void set_interval( const uint32_t interval );
 
     std::vector<std::string> get_options() const;
-    void set_options( std::vector<std::string> options );
+    void set_options( const std::vector<std::string>& options );
 
 private:
     std::string address;