From 24d1e19f1dfb0b6ef02681bc61b0041e057a137a Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Tue, 22 Feb 2011 17:12:40 +0100 Subject: [PATCH] Improved Host interface by including const parameters and assertions --- src/ping/host.cpp | 17 +++++++++++++---- src/ping/host.h | 8 ++++---- 2 files changed, 17 insertions(+), 8 deletions(-) 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; -- 1.7.1