Replaced uint by int.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Fri, 18 Mar 2011 16:50:04 +0000 (17:50 +0100)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Fri, 18 Mar 2011 16:50:04 +0000 (17:50 +0100)
- documented that a integer is non-negative using assertions, not unsigned int (uint).

15 files changed:
Readme
src/config/configuration.cpp
src/config/configuration.h
src/config/configurationreader.cpp
src/config/configurationreader.h
src/config/host.cpp
src/config/host.h
src/dns/dnsresolver.cpp
src/dns/hostaddress.cpp
src/dns/hostaddress.h
src/main.cpp
src/ping/boostpinger.cpp
src/ping/boostpinger.h
src/ping/pingscheduler.cpp
src/ping/pingscheduler.h

diff --git a/Readme b/Readme
index e4cfe76..909dd46 100644 (file)
--- a/Readme
+++ b/Readme
@@ -62,8 +62,9 @@ improve code reradability.
   variable has the given number of bits. This states clear the intent of the
   original programmer and avoids improper modifications.
 
-- Use int or uint for regular integer numbers that do not require any specific
-  size.
+- Use only int for regular integer numbers that do not require any specific
+  size. And document that a variable is non-negative using assertions. Do not
+  use unsigned types to say a number will never be negative.
 
 - Use std::size_t for integers that represent sizes of vectors, objects or
   buffers. Thus leaving the size difinition to the platform.
index 78cf351..b20681f 100644 (file)
@@ -33,12 +33,12 @@ void Configuration::set_config_file_name( const std::string &config_file_name )
     this->ConfigFileName = config_file_name;
 }
 
-uint Configuration::get_limit_to_notify() const
+int Configuration::get_limit_to_notify() const
 {
     return LimitToNotify;
 }
 
-void Configuration::set_limit_to_notify( const uint limit_to_notify )
+void Configuration::set_limit_to_notify( const int limit_to_notify )
 {
     BOOST_ASSERT( ( MinLimitToNotify <= limit_to_notify ) && ( limit_to_notify <= MaxLimitToNotify) );
 
index d294b9c..d4f30ee 100644 (file)
@@ -21,19 +21,19 @@ public:
     std::string get_config_file_name() const;
     void set_config_file_name( const std::string &config_file_name );
 
-    uint get_limit_to_notify() const;
-    void set_limit_to_notify( const uint limit_to_notify );
+    int get_limit_to_notify() const;
+    void set_limit_to_notify( const int limit_to_notify );
 
     std::vector<HostItem> get_hosts() const;
     void set_hosts( const std::vector<HostItem> &hosts_list );
 
 private:
     std::string ConfigFileName;
-    uint LimitToNotify;
+    int LimitToNotify;
     std::vector<HostItem> Hosts;
 
-    const uint MinLimitToNotify;
-    const uint MaxLimitToNotify;
+    const int MinLimitToNotify;
+    const int MaxLimitToNotify;
 
 };
 
index 5ee9a12..07e1e53 100644 (file)
@@ -109,9 +109,9 @@ options_description ConfigurationReader::get_configuration_options() const
 {
     options_description options( "Configuration" );
     options.add_options()
-        ( LimitToNotifyCmdStr.c_str(), value<uint>()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() )
+        ( LimitToNotifyCmdStr.c_str(), value<int>()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() )
         ( HostNameCmdStr.c_str(), value< vector<string> >(), HostNameCmdDesc.c_str() )
-        ( HostIntervalCmdStr.c_str(), value< vector<uint> >(), HostIntervalCmdDesc.c_str() )
+        ( HostIntervalCmdStr.c_str(), value< vector<int> >(), HostIntervalCmdDesc.c_str() )
     ;
 
     return options;
@@ -129,13 +129,13 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm )
 
     if ( vm.count( LimitToNotifyCmdStr ) )
     {
-        uint limit_to_notify = vm[ LimitToNotifyCmdStr ].as<uint> ();
+        int limit_to_notify = vm[ LimitToNotifyCmdStr ].as<int> ();
         Config.set_limit_to_notify( limit_to_notify );
 
         cout << LimitToNotifyCmdStr << "=" << limit_to_notify << endl;
     }
 
-    uint hosts_names_total = 0;
+    int hosts_names_total = 0;
     if ( vm.count( HostNameCmdStr ) )
     {
         vector<HostItem> hosts_list;
@@ -154,14 +154,14 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm )
         hosts_names_total = hosts_names.size();
     }
 
-    uint hosts_interval_total = 0;
+    int hosts_interval_total = 0;
     if ( vm.count( HostIntervalCmdStr ) )
     {
         vector<HostItem> hosts_list = Config.get_hosts();
         vector<HostItem>::iterator hosts_it = hosts_list.begin();
 
-        vector<uint> hosts_intervals = vm[ HostIntervalCmdStr ].as< vector<uint> > ();
-        BOOST_FOREACH( uint host_interval, hosts_intervals )
+        vector<int> hosts_intervals = vm[ HostIntervalCmdStr ].as< vector<int> > ();
+        BOOST_FOREACH( int host_interval, hosts_intervals )
         {
             HostItem host_item = *hosts_it;
             host_item->set_interval( host_interval );
index 378faf6..2c5bd3e 100644 (file)
@@ -61,12 +61,12 @@ private:
     const std::string DefaultConfigFileName;
     const std::string ConfigFileCmdStr;
     const std::string ConfigFileCmdDesc;
-    const uint DefaultLimitToNotify;
+    const int DefaultLimitToNotify;
     const std::string LimitToNotifyCmdStr;
     const std::string LimitToNotifyCmdDesc;
     const std::string HostNameCmdStr;
     const std::string HostNameCmdDesc;
-    const uint DefaultHostInterval;
+    const int DefaultHostInterval;
     const std::string HostIntervalCmdStr;
     const std::string HostIntervalCmdDesc;
 
index dbd0fa3..a92ffd0 100644 (file)
@@ -44,14 +44,14 @@ void Host::set_port( const uint16_t port )
     this->Port = port;
 }
 
-uint Host::get_interval() const
+int Host::get_interval() const
 {
     return Interval;
 }
 
-void Host::set_interval( const uint interval )
+void Host::set_interval( const int interval )
 {
-    BOOST_ASSERT( ( 0 < interval ) && ( interval < std::numeric_limits<uint>::max() ) );
+    BOOST_ASSERT( ( 0 < interval ) && ( interval < std::numeric_limits<int>::max() ) );
 
     this->Interval = interval;
 }
index 75f41bf..2485e04 100644 (file)
@@ -24,8 +24,8 @@ public:
     uint16_t get_port() const;
     void set_port( const uint16_t port );
 
-    uint get_interval() const;
-    void set_interval( const uint interval );
+    int get_interval() const;
+    void set_interval( const int interval );
 
     std::vector<std::string> get_options() const;
     void set_options( const std::vector<std::string> &options );
@@ -33,7 +33,7 @@ public:
 private:
     std::string Address;
     uint16_t Port;
-    uint Interval;
+    int Interval;
     std::vector<std::string> Options;
 
 };
index eaf8370..7c7672e 100644 (file)
@@ -85,14 +85,14 @@ int DnsResolver::get_resolved_ip_count()
  */
 string DnsResolver::get_next_ip()
 {
-    uint list_size_before = ResolvedHostAddressList.size();
+    int list_size_before = ResolvedHostAddressList.size();
 
     HostAddress host_address = ResolvedHostAddressList.front();
     ResolvedHostAddressList.pop_front();
     string destination_ip = host_address.get_ip();
     ResolvedHostAddressList.push_back( host_address );
 
-    uint list_size_after = ResolvedHostAddressList.size();
+    int list_size_after = ResolvedHostAddressList.size();
 
     BOOST_ASSERT( list_size_before == list_size_after );
 
index 253b3c2..46a60ca 100644 (file)
@@ -26,12 +26,12 @@ string HostAddress::get_ip() const
     return Ip;
 }
 
-uint HostAddress::get_ttl() const
+int HostAddress::get_ttl() const
 {
     return Ttl;
 }
 
-void HostAddress::set_ttl( uint ttl )
+void HostAddress::set_ttl( int ttl )
 {
     this->Ttl = ttl;
 }
index 63df852..525761b 100644 (file)
@@ -18,12 +18,12 @@ public:
     std::string get_ip() const;
     void set_ip( std::string ip );
 
-    uint get_ttl() const;
-    void set_ttl( uint ttl );
+    int get_ttl() const;
+    void set_ttl( int ttl );
 
 private:
     std::string Ip;
-    uint Ttl;
+    int Ttl;
 
 };
 
index f4c83fc..ae4d889 100644 (file)
@@ -25,7 +25,7 @@ int main( int argc, char* argv[] )
         BOOST_FOREACH( HostItem host, hosts )
         {
             string ping_address = (*host).get_address();
-            uint ping_interval = (*host).get_interval();
+            int ping_interval = (*host).get_interval();
             PingSchedulerItem scheduler(
                     new PingScheduler(
                             io_service, ping_address, ping_interval
index a61f1ea..b40df03 100644 (file)
@@ -23,7 +23,7 @@ using namespace boost::posix_time;
 
 BoostPinger::BoostPinger(
         boost::asio::io_service &io_service,
-        const uint echo_reply_timeout_in_sec
+        const int echo_reply_timeout_in_sec
 ) :
     IoService( io_service ),
     Resolver( io_service ),
@@ -157,7 +157,7 @@ void BoostPinger::handle_timeout_echo_reply()
 void BoostPinger::schedule_next_echo_request()
 {
     // Requests must be sent no less than one second apart.
-    const uint echo_request_interval_in_sec = 1;
+    const int echo_request_interval_in_sec = 1;
     Timer.expires_at( TimeSent + seconds( echo_request_interval_in_sec ) );
     Timer.async_wait( boost::bind( &BoostPinger::start_send, this ) );
 }
@@ -216,10 +216,10 @@ void BoostPinger::print_echo_reply(
 
     size_t bytes_received = bytes_transferred - ipv4_hdr.get_header_length();
     string source_address = ipv4_hdr.get_source_address().to_string();
-    uint sequence_number = icmp_hdr.get_sequence_number();
-    uint ttl = ipv4_hdr.get_time_to_live();
+    int sequence_number = icmp_hdr.get_sequence_number();
+    int ttl = ipv4_hdr.get_time_to_live();
     ptime now = microsec_clock::universal_time();
-    uint time = (now - TimeSent).total_milliseconds();
+    int time = (now - TimeSent).total_milliseconds();
 
     cout << bytes_received << " bytes "
          << "from " << source_address
index f72fac5..b8b840b 100644 (file)
@@ -16,7 +16,7 @@ class BoostPinger : public Pinger
 public:
     BoostPinger(
             boost::asio::io_service &io_service,
-            const uint echo_reply_timeout_in_sec
+            const int echo_reply_timeout_in_sec
     );
     virtual ~BoostPinger();
 
@@ -60,8 +60,8 @@ private:
     uint16_t SequenceNumber;
     boost::posix_time::ptime TimeSent;
     boost::asio::streambuf ReplyBuffer;
-    uint RepliesCount;
-    uint EchoReplyTimeoutInSec;
+    int RepliesCount;
+    int EchoReplyTimeoutInSec;
     BoostPinger::PingStatus PingerStatus;
 
 };
index ee320e7..499751d 100644 (file)
@@ -19,7 +19,7 @@ using namespace boost::posix_time;
 PingScheduler::PingScheduler(
         boost::asio::io_service &io_service,
         const string &ping_address,
-        const uint ping_interval_in_sec
+        const int ping_interval_in_sec
 ) :
     IoService( io_service ),
     Timer( io_service ),
@@ -79,7 +79,7 @@ bool PingScheduler::ping( const string &destination )
     BOOST_ASSERT( !destination.empty() );
 
     io_service io_service;
-    uint echo_reply_timeout_in_sec = 5; // TODO configurable: this is the timeout to WAIT FOR the ping before considering a timeout
+    int echo_reply_timeout_in_sec = 5; // TODO configurable: this is the timeout to WAIT FOR the ping before considering a timeout
     BoostPinger pinger( io_service, echo_reply_timeout_in_sec );
 
     return pinger.ping( destination );
index f4bc992..1060477 100644 (file)
@@ -19,7 +19,7 @@ public:
     PingScheduler(
             boost::asio::io_service &io_service,
             const std::string &ping_address,
-            const uint ping_interval_in_sec
+            const int ping_interval_in_sec
     );
     virtual ~PingScheduler();
 
@@ -39,7 +39,7 @@ private:
     boost::asio::deadline_timer Timer;
     boost::posix_time::ptime TimeSentLastPing;
     DnsResolver IpList;
-    const uint PingIntervalInSec;
+    const int PingIntervalInSec;
     PingAnalyzer Analyzer;
 
 };