Removed all namespace's "using" from header files (check C++ Coding Standards #59)
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 3 Mar 2011 16:33:11 +0000 (17:33 +0100)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 3 Mar 2011 16:33:11 +0000 (17:33 +0100)
- writing headers with full namespace qualifiers to avoid type collision
- writing "using" only in implementation files to save namespace qualifier writing

src/ping/boostpinger.cpp
src/ping/boostpinger.h
src/ping/pingcheck.cpp

index 5e09a67..79fce87 100644 (file)
 #include "ipv4header.h"
 #include "boostpinger.h"
 
-namespace posix_time = boost::posix_time;
+using namespace std;
+using namespace boost::asio;
+using namespace boost::asio::ip;
+using namespace boost::posix_time;
 
 //-----------------------------------------------------------------------------
 // BoostPinger
@@ -28,12 +31,12 @@ BoostPinger::BoostPinger(
     Socket( io_service, icmp::v4() ),
     Timer( io_service ),
     SequenceNumber( 0 ),
-    TimeSent( posix_time::microsec_clock::universal_time() ),
+    TimeSent( microsec_clock::universal_time() ),
     ReplyBuffer(),
     RepliesCount( 0 ),
     TimesToPingTotal( 0 ),
     MinTimesToPing( 0 ),
-    MaxTimesToPing( std::numeric_limits<std::size_t>::max() )
+    MaxTimesToPing( numeric_limits<size_t>::max() )
 {
 }
 
@@ -42,8 +45,8 @@ BoostPinger::~BoostPinger()
 }
 
 void BoostPinger::ping(
-        const std::string &destination,
-        const std::size_t times_to_ping
+        const string &destination,
+        const size_t times_to_ping
 )
 {
     BOOST_ASSERT( !destination.empty() );
@@ -74,7 +77,7 @@ void BoostPinger::start_send()
 {
     IcmpPacket icmp_echo_request_packet = create_echo_request_packet();
 
-    std::size_t times_already_pinged = SequenceNumber;
+    size_t times_already_pinged = SequenceNumber;
     if ( times_already_pinged <= TimesToPingTotal )
     {
         send_echo_request( icmp_echo_request_packet );
@@ -105,26 +108,26 @@ IcmpPacket BoostPinger::create_echo_request_packet()
 void BoostPinger::send_echo_request( const IcmpPacket &icmp_packet )
 {
     boost::asio::streambuf request_buffer;
-    std::ostream os( &request_buffer );
+    ostream os( &request_buffer );
     os << icmp_packet;
 
     // Send the request.
-    TimeSent = posix_time::microsec_clock::universal_time();
+    TimeSent = microsec_clock::universal_time();
     Socket.send_to( request_buffer.data(), DestinationEndpoint );
 
     // Wait up to five seconds for a reply.
     RepliesCount = 0;
-    Timer.expires_at( TimeSent + posix_time::seconds( 5 ) );
+    Timer.expires_at( TimeSent + seconds( 5 ) );
     Timer.async_wait( boost::bind( &BoostPinger::handle_timeout, this ) );
 }
 
 void BoostPinger::handle_timeout()
 {
     if ( RepliesCount == 0 )
-        std::cout << "Request timed out" << std::endl;
+        cout << "Request timed out" << endl;
 
     // Requests must be sent no less than one second apart.
-    Timer.expires_at( TimeSent + posix_time::seconds( 1 ) );
+    Timer.expires_at( TimeSent + seconds( 1 ) );
     Timer.async_wait( boost::bind( &BoostPinger::start_send, this ) );
 }
 
@@ -140,14 +143,14 @@ void BoostPinger::start_receive()
     );
 }
 
-void BoostPinger::handle_receive( const std::size_t &length )
+void BoostPinger::handle_receive( const size_t &length )
 {
     // The actual number of bytes received is committed to the buffer so that we
     // can extract it using a std::istream object.
     ReplyBuffer.commit( length );
 
     // Decode the reply packet.
-    std::istream is( &ReplyBuffer );
+    istream is( &ReplyBuffer );
     IcmpPacket icmp_packet;
     is >> icmp_packet;
 
@@ -171,24 +174,24 @@ void BoostPinger::handle_receive( const std::size_t &length )
 
 void BoostPinger::print_echo_reply(
         const IcmpPacket &icmp_packet,
-        const std::size_t &length
+        const size_t &length
 )
 {
     Ipv4Header ipv4_hdr = icmp_packet.get_ip_header();
     IcmpHeader icmp_hdr = icmp_packet.get_icmp_header();
 
-    std::size_t bytes_received = length - ipv4_hdr.get_header_length();
-    std::string source_address = ipv4_hdr.get_source_address().to_string();
-    std::size_t sequence_number = icmp_hdr.get_sequence_number();
-    std::size_t ttl = ipv4_hdr.get_time_to_live();
-    posix_time::ptime now = posix_time::microsec_clock::universal_time();
-    std::size_t time = (now - TimeSent).total_milliseconds();
+    size_t bytes_received = length - ipv4_hdr.get_header_length();
+    string source_address = ipv4_hdr.get_source_address().to_string();
+    size_t sequence_number = icmp_hdr.get_sequence_number();
+    size_t ttl = ipv4_hdr.get_time_to_live();
+    ptime now = microsec_clock::universal_time();
+    size_t time = (now - TimeSent).total_milliseconds();
 
-    std::cout << bytes_received << " bytes "
+    cout << bytes_received << " bytes "
             << "from " << source_address
             << ": icmp_seq=" << sequence_number
             << " ttl=" << ttl
-            << " time=" << time << " ms" << std::endl;
+            << " time=" << time << " ms" << endl;
 }
 
 uint16_t BoostPinger::get_identifier()
index ecd35d9..635c430 100644 (file)
@@ -6,10 +6,6 @@
 #include "icmppacket.h"
 #include "pinger.h"
 
-using boost::asio::ip::address;
-using boost::asio::ip::icmp;
-using boost::asio::deadline_timer;
-
 //-----------------------------------------------------------------------------
 // BoostPinger
 //-----------------------------------------------------------------------------
@@ -45,10 +41,10 @@ private:
 
 private:
     boost::asio::io_service &io_service;
-    icmp::resolver Resolver;
-    icmp::endpoint DestinationEndpoint;
-    icmp::socket Socket;
-    deadline_timer Timer;
+    boost::asio::ip::icmp::resolver Resolver;
+    boost::asio::ip::icmp::endpoint DestinationEndpoint;
+    boost::asio::ip::icmp::socket Socket;
+    boost::asio::deadline_timer Timer;
     uint16_t SequenceNumber;
     boost::posix_time::ptime TimeSent;
     boost::asio::streambuf ReplyBuffer;
index 5994669..6f1d0a8 100644 (file)
@@ -5,6 +5,9 @@
 
 #include "pingcheck.h"
 
+using namespace std;
+using namespace boost::asio;
+
 //-----------------------------------------------------------------------------
 // PingCheck
 //-----------------------------------------------------------------------------
@@ -20,11 +23,9 @@ PingCheck::~PingCheck()
 
 void PingCheck::start_pinging()
 {
-    std::cout << "[start_pinging]" << std::endl;
-
-    std::string destination = Host_.get_address();
-    std::size_t ping_set_total = 3; // TODO configurable:
-    std::size_t ping_set_count = 0;
+    string destination = Host_.get_address();
+    size_t ping_set_total = 3; // TODO configurable:
+    size_t ping_set_count = 0;
     while ( ping_set_count < ping_set_total )
     {
         ping_and_wait( destination );
@@ -33,28 +34,24 @@ void PingCheck::start_pinging()
     }
 }
 
-void PingCheck::ping_and_wait( const std::string &destination )
+void PingCheck::ping_and_wait( const string &destination )
 {
-    std::cout << "[ping_and_wait]" << std::endl;
-
     try
     {
         ping( destination );
 
         wait();
     }
-    catch ( std::exception& e )
+    catch ( exception& e )
     {
-        std::cerr << "Exception: " << e.what() << std::endl;
+        cerr << "Exception: " << e.what() << endl;
         return;
     }
 }
 
-void PingCheck::ping( const std::string &destination ) throw ( std::exception& )
+void PingCheck::ping( const string &destination ) throw ( exception& )
 {
-    std::cout << "[ping]" << std::endl;
-
-    std::size_t times_to_ping = 3; // TODO configurable: this must be automatically selected
+    size_t times_to_ping = 3; // TODO configurable: this must be automatically selected
     boost::asio::io_service io_service;
     BoostPinger pinger( io_service );
     pinger.ping( destination, times_to_ping );
@@ -62,11 +59,9 @@ void PingCheck::ping( const std::string &destination ) throw ( std::exception& )
 
 void PingCheck::wait()
 {
-    std::cout << "[wait]" << std::endl;
-
     boost::asio::io_service io_service;
     deadline_timer timer( io_service );
-    std::size_t interval = Host_.get_interval(); // TODO configurable:
+    size_t interval = Host_.get_interval(); // TODO configurable:
     timer.expires_from_now( boost::posix_time::seconds( interval ) );
     timer.wait();
 }