From: Guilherme Maciel Ferreira Date: Tue, 22 Feb 2011 16:12:40 +0000 (+0100) Subject: Improved Host interface by including const parameters and assertions X-Git-Tag: v1.0~190 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=24d1e19f1dfb0b6ef02681bc61b0041e057a137a;p=pingcheck Improved Host interface by including const parameters and assertions --- diff --git a/src/ping/host.cpp b/src/ping/host.cpp index 1bdadb3..89773c1 100644 --- a/src/ping/host.cpp +++ b/src/ping/host.cpp @@ -1,3 +1,6 @@ +#include +#include + #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 Host::get_options() const return options; } -void Host::set_options( std::vector options ) +void Host::set_options( const std::vector& options ) { this->options = options; } diff --git a/src/ping/host.h b/src/ping/host.h index e9ec04f..7ba9cbd 100644 --- a/src/ping/host.h +++ b/src/ping/host.h @@ -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 get_options() const; - void set_options( std::vector options ); + void set_options( const std::vector& options ); private: std::string address;