From a59844be98125799b426aee59b3e17952a326164 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 11 Mar 2016 13:28:56 +1100 Subject: [PATCH] don't pull in namespace std --- backtrace_execinfo.cpp | 9 +++---- backtrace_null.cpp | 12 ++++----- float.cpp | 48 +++++++++++++-------------------- io.cpp | 1 - ip.cpp.rl | 5 +--- net/address.cpp | 60 +++++++++++++++++++++--------------------- net/except.cpp | 11 ++++---- test/backtrace.cpp | 5 ++-- test/checksum.cpp | 5 +++- test/float.cpp | 25 +++++++++--------- test/random.cpp | 5 ++-- tools/scratch.cpp | 11 ++++++++ 12 files changed, 97 insertions(+), 100 deletions(-) diff --git a/backtrace_execinfo.cpp b/backtrace_execinfo.cpp index 9e7aeb10..ef50b88d 100644 --- a/backtrace_execinfo.cpp +++ b/backtrace_execinfo.cpp @@ -31,10 +31,7 @@ #include -using namespace std; - - -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// debug::backtrace::backtrace (void): m_frames (DEFAULT_DEPTH) { @@ -49,7 +46,7 @@ debug::backtrace::backtrace (void): } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// static std::string addr2line (const void *addr) { @@ -74,7 +71,7 @@ addr2line (const void *addr) } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// ostream& debug::operator <<(ostream &os, const debug::backtrace &rhs) { const auto frames = rhs.frames (); diff --git a/backtrace_null.cpp b/backtrace_null.cpp index 8afab5bc..63f1b723 100644 --- a/backtrace_null.cpp +++ b/backtrace_null.cpp @@ -19,18 +19,18 @@ #include -using namespace std; - +/////////////////////////////////////////////////////////////////////////////// debug::backtrace::backtrace (void): m_frames (DEFAULT_DEPTH) { ; } -ostream& -debug::operator <<(ostream &os, const debug::backtrace&) { - os << "null backtrace"; - return os; +/////////////////////////////////////////////////////////////////////////////// +std::ostream& +debug::operator <<(std::ostream &os, const debug::backtrace&) +{ + return os << "null_backtrace"; } diff --git a/float.cpp b/float.cpp index 7a1574c1..430569cf 100644 --- a/float.cpp +++ b/float.cpp @@ -19,44 +19,48 @@ #include -using namespace std; - - -/* Constructors */ +/////////////////////////////////////////////////////////////////////////////// template ieee_float::ieee_float (void) { ; } +//----------------------------------------------------------------------------- template ieee_float::ieee_float (floating_t _floating): m_floating (_floating) { ; } +//----------------------------------------------------------------------------- template ieee_float::ieee_float (const ieee_float &rhs): m_bits (rhs.m_bits) { ; } -/* Classifiers */ - +/////////////////////////////////////////////////////////////////////////////// template bool -ieee_float::is_zero (void) const { +ieee_float::is_zero (void) const +{ return m_components.exponent == 0 && m_components.significand == 0; } + +//----------------------------------------------------------------------------- template bool -ieee_float::is_subnormal (void) const { +ieee_float::is_subnormal (void) const +{ return m_components.exponent == 0 && m_components.significand != 0; } + +//----------------------------------------------------------------------------- template bool ieee_float::is_inifinity (void) const { @@ -64,6 +68,7 @@ ieee_float::is_inifinity (void) const { m_components.significand == 0; } +//----------------------------------------------------------------------------- template bool ieee_float::is_nan (void) const { @@ -71,6 +76,8 @@ ieee_float::is_nan (void) const { m_components.significand != 0; } + +/////////////////////////////////////////////////////////////////////////////// template bool ieee_float::operator==(floating_t _floating) const { @@ -90,25 +97,7 @@ ieee_float::operator==(floating_t _floating) const { } -#include - - -//template -//bool -//ieee_float::almost_equal (floating_t a, -// floating_t b) { -// // Static cast to avoid integer casting warnings when using uint16_t for half -// static const floating_t epsilon = static_cast (0.001); -// const floating_t diff = static_cast (std::fabs (a - b)); -// -// // * Use an exact equality first so that infinities are not indirectly compared. This would generate NaNs in the diff. -// // * Do not use gte or lte. This stops an infinite from making infinities on both sides of the inequality. -// return exactly_equal (a, b) || -// diff < epsilon * std::fabs (a) || -// diff < epsilon * std::fabs (b); -//} - - +/////////////////////////////////////////////////////////////////////////////// template bool ieee_float::almost_equal (floating_t a, @@ -118,7 +107,8 @@ ieee_float::almost_equal (floating_t a, } -// Based on the cynus `AlmostEqual2sComplement` +//----------------------------------------------------------------------------- +// Based on the Cygnus `AlmostEqual2sComplement` function template bool ieee_float::almost_equal (floating_t _a, @@ -164,7 +154,7 @@ ieee_float::almost_equal (floating_t _a, } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// template class ieee_float< 5, 10>; // ieee_half template class ieee_float< 8, 23>; // ieee_single; template class ieee_float<11, 52>; // ieee_double; diff --git a/io.cpp b/io.cpp index fb159f0c..2ea55a60 100644 --- a/io.cpp +++ b/io.cpp @@ -31,7 +31,6 @@ #include -using namespace std; using namespace util; diff --git a/ip.cpp.rl b/ip.cpp.rl index 5a028159..f9c24e9a 100644 --- a/ip.cpp.rl +++ b/ip.cpp.rl @@ -26,9 +26,6 @@ #include -using namespace std; - - /////////////////////////////////////////////////////////////////////////////// const ipv4::ip ipv4::ip::LOOPBACK (127, 0, 0, 1); const ipv4::ip ipv4::ip::ANY ( 0, 0, 0, 0); @@ -142,6 +139,6 @@ ipv4::ip::ip (const std::string &data) //----------------------------------------------------------------------------- ipv4::ip -ipv4::ip::parse (const string &data) +ipv4::ip::parse (const std::string &data) { return ipv4::ip (data); } diff --git a/net/address.cpp b/net/address.cpp index f2ebaea0..d7e63e2c 100644 --- a/net/address.cpp +++ b/net/address.cpp @@ -29,12 +29,10 @@ #include #endif -//----------------------------------------------------------------------------- -using namespace net; -using namespace std; +using net::address; -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// #ifdef __WIN32 const char* inet_ntop(int af, const void* src, char* dst, int size){ struct sockaddr_in srcaddr; @@ -50,20 +48,22 @@ const char* inet_ntop(int af, const void* src, char* dst, int size){ #endif -//----------------------------------------------------------------------------- -template +/////////////////////////////////////////////////////////////////////////////// +template typename address::port_type address::port (void) const { return m_port; } -template +//----------------------------------------------------------------------------- +template void address::set_port (const port_type &_port) { m_port = _port; } -template +//----------------------------------------------------------------------------- +template typename address::ip_type address::resolve (const std::string &str) { addrinfo hint; @@ -81,19 +81,19 @@ address::resolve (const std::string &str) { } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// namespace net { template <> - address::address (const sockaddr_type &addr): + address::address (const sockaddr_type &addr): m_ip (addr.sin_addr.s_addr), m_mask (0), m_port (ntoh (addr.sin_port)) { - CHECK (addr.sin_family == (int)domain::INET); + CHECK (addr.sin_family == (int)net::domain::INET); } - template + template address::address (const std::string &_addr, port_type _port): m_ip (resolve (_addr)), @@ -103,11 +103,11 @@ namespace net { template <> - address::sockaddr_type - address::to_sockaddr (void) const { + address::sockaddr_type + address::to_sockaddr (void) const { sockaddr_type addr; - addr.sin_family = (int)domain::INET; + addr.sin_family = (int)net::domain::INET; addr.sin_port = hton (m_port); addr.sin_addr.s_addr = m_ip.m_integer; @@ -117,11 +117,11 @@ namespace net { template <> std::string - address::to_string (void) const { + address::to_string (void) const { char dest[INET_ADDRSTRLEN + 1]; sockaddr_type addr = to_sockaddr (); - if (NULL == inet_ntop ((int)domain::INET, &addr.sin_addr, dest, sizeof (dest))) + if (NULL == inet_ntop ((int)net::domain::INET, &addr.sin_addr, dest, sizeof (dest))) net::error::throw_code (); return dest; } @@ -129,7 +129,7 @@ namespace net { template <> bool - address::operator ==(const address &rhs) { + address::operator ==(const address &rhs) { return m_ip == rhs.m_ip && m_mask == rhs.m_mask && m_port == rhs.m_port; @@ -137,7 +137,7 @@ namespace net { } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// std::ostream& net::operator<< (std::ostream &os, const address &addr) { os << addr.to_string () << ":" << addr.port (); @@ -145,23 +145,23 @@ net::operator<< (std::ostream &os, const address &addr) { } -//----------------------------------------------------------------------------- -template <> const address -address::LOOPBACK ("127.0.0.1", 0); +/////////////////////////////////////////////////////////////////////////////// +template <> const address +address::LOOPBACK ("127.0.0.1", 0); -template <> const address -address::ANY ("0.0.0.0", 0); +template <> const address +address::ANY ("0.0.0.0", 0); namespace net { - template class address; + template class address; } //----------------------------------------------------------------------------- -//template <> const address -//address::LOOPBACK ("::1", 0); +//template <> const address +//address::LOOPBACK ("::1", 0); // -//template <> const address -//address::ANY ("::0", 0); +//template <> const address +//address::ANY ("::0", 0); // -//template class address; +//template class address; diff --git a/net/except.cpp b/net/except.cpp index 94911b11..3059f973 100644 --- a/net/except.cpp +++ b/net/except.cpp @@ -20,23 +20,22 @@ #include "../cast.hpp" -//----------------------------------------------------------------------------- -using namespace std; -using namespace net; +using net::error; -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// net::error::error (const std::string &_what): runtime_error (_what) { ; } +//----------------------------------------------------------------------------- net::error::error (int _code): runtime_error (strerror (_code)) { CHECK (_code != 0); } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// std::string net::error::code_to_string (int code) { #ifdef __WIN32 @@ -54,7 +53,7 @@ net::error::code_to_string (int code) { } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// void net::error::throw_code (int code) { #ifdef __WIN32 diff --git a/test/backtrace.cpp b/test/backtrace.cpp index cdd54be1..95db0afe 100644 --- a/test/backtrace.cpp +++ b/test/backtrace.cpp @@ -5,15 +5,14 @@ #include #include -using namespace std; - +/////////////////////////////////////////////////////////////////////////////// int main (int, char **) { util::TAP::logger tap; util::stream::null out; - out << debug::backtrace() << endl; + out << debug::backtrace() << std::endl; tap.noop (); return EXIT_SUCCESS; diff --git a/test/checksum.cpp b/test/checksum.cpp index d929c05d..2c621bf8 100644 --- a/test/checksum.cpp +++ b/test/checksum.cpp @@ -8,10 +8,12 @@ #include #include -using namespace std; +/////////////////////////////////////////////////////////////////////////////// static const char *ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + +//----------------------------------------------------------------------------- static const struct { uint32_t adler; uint16_t bsd; @@ -24,6 +26,7 @@ static const struct { }; +/////////////////////////////////////////////////////////////////////////////// int main (int, char**) { util::TAP::logger tap; diff --git a/test/float.cpp b/test/float.cpp index 8cffad6d..0c32263f 100644 --- a/test/float.cpp +++ b/test/float.cpp @@ -6,9 +6,8 @@ #include -using namespace std; - +/////////////////////////////////////////////////////////////////////////////// void test_double (util::TAP::logger &tap) { @@ -19,17 +18,17 @@ test_double (util::TAP::logger &tap) sized_test tests[] = { { 0x3ff0000000000000, 1.0 }, - { 0x3ff0000000000001, 1.0 + numeric_limits::epsilon () }, - { 0x3ff0000000000002, 1.0 + numeric_limits::epsilon () * 2}, + { 0x3ff0000000000001, 1.0 + std::numeric_limits::epsilon () }, + { 0x3ff0000000000002, 1.0 + std::numeric_limits::epsilon () * 2}, { 0x4000000000000000, 2.0 }, { 0xc000000000000000, -2.0 }, - { 0x0000000000000001, numeric_limits::denorm_min () }, - { 0x0010000000000000, numeric_limits::min () }, // min positive normal - { 0x7fefffffffffffff, numeric_limits::max () }, // max + { 0x0000000000000001, std::numeric_limits::denorm_min () }, + { 0x0010000000000000, std::numeric_limits::min () }, // min positive normal + { 0x7fefffffffffffff, std::numeric_limits::max () }, // max { 0x0000000000000000, 0.0 }, { 0x8000000000000000, -0.0 }, - { 0x7ff0000000000000, numeric_limits::infinity() }, - { 0xfff0000000000000, -numeric_limits::infinity() }, + { 0x7ff0000000000000, std::numeric_limits::infinity() }, + { 0xfff0000000000000, -std::numeric_limits::infinity() }, { 0x3fd5555555555555, 1.0 / 3.0 } }; @@ -46,6 +45,7 @@ test_double (util::TAP::logger &tap) } +/////////////////////////////////////////////////////////////////////////////// void test_single (util::TAP::logger &tap) { @@ -57,13 +57,13 @@ test_single (util::TAP::logger &tap) sized_test tests[] = { { 0x3f800000, 1.0f }, { 0xc0000000, -2.0f }, - { 0x7f7fffff, numeric_limits::max () }, + { 0x7f7fffff, std::numeric_limits::max () }, { 0x00000000, 0.0f }, { 0x80000000, -0.0f }, - { 0x7f800000, numeric_limits::infinity () }, - { 0xff800000, -numeric_limits::infinity () }, + { 0x7f800000, std::numeric_limits::infinity () }, + { 0xff800000, -std::numeric_limits::infinity () }, { 0x3eaaaaab, 1.0f / 3.0f } }; @@ -81,6 +81,7 @@ test_single (util::TAP::logger &tap) } +/////////////////////////////////////////////////////////////////////////////// int main (int, char **) { util::TAP::logger tap; diff --git a/test/random.cpp b/test/random.cpp index be4ab6c1..9e6b93b6 100644 --- a/test/random.cpp +++ b/test/random.cpp @@ -7,9 +7,8 @@ #include #include -using namespace std; - +/////////////////////////////////////////////////////////////////////////////// // TODO: Use a more robust test like Chi-Square void test_bool (util::TAP::logger &tap) @@ -29,6 +28,7 @@ test_bool (util::TAP::logger &tap) } +/////////////////////////////////////////////////////////////////////////////// // TODO: Use a more robust test like Kolmogorov-Smirnov void test_float (util::TAP::logger &tap) @@ -55,6 +55,7 @@ test_float (util::TAP::logger &tap) } +/////////////////////////////////////////////////////////////////////////////// int main (int, char **) { util::TAP::logger tap; diff --git a/tools/scratch.cpp b/tools/scratch.cpp index 8d0cd357..1f7fb571 100644 --- a/tools/scratch.cpp +++ b/tools/scratch.cpp @@ -1,10 +1,21 @@ #include +#include + +#include "coord/iostream.hpp" +#include "extent.hpp" +#include "region.hpp" + int main (int argc, char **argv) { (void)argc; (void)argv; + util::point2u a { 0, 0 }; + util::point2u b { 1, 1 }; + util::region2u v { a, b }; + std::cerr << v << '\n'; + return EXIT_SUCCESS; }