From 82357e8ed6adf7058d84be1e9b438057f50e31c5 Mon Sep 17 00:00:00 2001 From: Daniel M <daniel.q.mueller@stud.h-da.de> Date: Fri, 21 May 2021 15:44:52 +0200 Subject: [PATCH] Wrap everything in namespace - Put the whole library in namespace netlib --- example/example.cpp | 2 ++ inc/ipaddr.hpp | 7 +++++++ inc/resolver.hpp | 6 ++++++ inc/sockaddr.hpp | 7 +++++++ inc/tcplistener.hpp | 7 +++++++ inc/tcpstream.hpp | 6 ++++++ inc/udpsocket.hpp | 7 +++++++ src/ipaddr.cpp | 2 ++ src/resolver.cpp | 1 + src/sockaddr.cpp | 2 ++ src/tcplistener.cpp | 2 ++ src/tcpstream.cpp | 2 ++ src/udpsocket.cpp | 1 + test/test.cpp | 1 + 14 files changed, 53 insertions(+) diff --git a/example/example.cpp b/example/example.cpp index 9a575f7..313f5f3 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -5,6 +5,8 @@ // Include the all-in-one headerfile. This will include all other headers #include "netlib.hpp" +using namespace netlib; + void example_IpAddr() { // IpAddr takes an address as string and automatically detects if it is diff --git a/inc/ipaddr.hpp b/inc/ipaddr.hpp index 53c1f33..10b6678 100644 --- a/inc/ipaddr.hpp +++ b/inc/ipaddr.hpp @@ -4,6 +4,10 @@ #include <string> #include <netinet/in.h> +namespace netlib +{ + + /** * @brief The IpAddr class represents an ip address that can either be of type * Ipv4 or of type Ipv6. @@ -129,4 +133,7 @@ public: }; + +} // namespace netlib + #endif // _IPADDR_HPP \ No newline at end of file diff --git a/inc/resolver.hpp b/inc/resolver.hpp index 21cc1a3..2d763e7 100644 --- a/inc/resolver.hpp +++ b/inc/resolver.hpp @@ -5,6 +5,10 @@ #include "ipaddr.hpp" +namespace netlib +{ + + /** * @brief Provide multiple ways to resolve hostnames to Ipv4 and/or Ipv6 * addresses. @@ -112,4 +116,6 @@ public: }; +} // namespace netlib + #endif // _RESOLVER_HPP \ No newline at end of file diff --git a/inc/sockaddr.hpp b/inc/sockaddr.hpp index 7b67336..7ad3be2 100644 --- a/inc/sockaddr.hpp +++ b/inc/sockaddr.hpp @@ -6,6 +6,10 @@ #include "ipaddr.hpp" +namespace netlib +{ + + /** * @brief SockAddr represents the combination of an ip address and a port number. * @@ -134,4 +138,7 @@ public: }; + +} // namespace netlib + #endif // _SOCKADDR_HPP \ No newline at end of file diff --git a/inc/tcplistener.hpp b/inc/tcplistener.hpp index a9e8846..8a2e803 100644 --- a/inc/tcplistener.hpp +++ b/inc/tcplistener.hpp @@ -6,6 +6,10 @@ #include <filesystem> +namespace netlib +{ + + /** * @brief Listen to a local ip address + port and accept incomming connections * as TcpStreams. @@ -113,4 +117,7 @@ public: }; + +} // namespace netlib + #endif // _TCPLISTENER_HPP \ No newline at end of file diff --git a/inc/tcpstream.hpp b/inc/tcpstream.hpp index fb3c5f4..6374870 100644 --- a/inc/tcpstream.hpp +++ b/inc/tcpstream.hpp @@ -5,6 +5,10 @@ #include "sockaddr.hpp" +namespace netlib +{ + + /** * @brief The TcpStream represents tcp a connection with another endpoint and is * used to send and receive data through that connection. @@ -227,4 +231,6 @@ public: }; +} // namespace netlib + #endif // _TCPSTREAM_HPP \ No newline at end of file diff --git a/inc/udpsocket.hpp b/inc/udpsocket.hpp index 8e0a364..62126ff 100644 --- a/inc/udpsocket.hpp +++ b/inc/udpsocket.hpp @@ -3,6 +3,10 @@ #include "sockaddr.hpp" +namespace netlib +{ + + /** * @brief The UdpSocket can be used to receive UDP packets from and send UDP * packets to any target address. @@ -209,4 +213,7 @@ public: }; + +} // namespace netlib + #endif // _UDPSOCKET_HPP \ No newline at end of file diff --git a/src/ipaddr.cpp b/src/ipaddr.cpp index dcef1eb..0b52518 100644 --- a/src/ipaddr.cpp +++ b/src/ipaddr.cpp @@ -5,6 +5,8 @@ #include <cstring> #include <arpa/inet.h> +using namespace netlib; + IpAddr::IpAddr() : IpAddr("0.0.0.0") { } diff --git a/src/resolver.cpp b/src/resolver.cpp index c3103d1..7e2b178 100644 --- a/src/resolver.cpp +++ b/src/resolver.cpp @@ -8,6 +8,7 @@ #include <netdb.h> #include <arpa/inet.h> +using namespace netlib; IpAddr Resolver::resolveHostnameAF(const std::string &hostname, int af) { diff --git a/src/sockaddr.cpp b/src/sockaddr.cpp index 7977198..a07ce0e 100644 --- a/src/sockaddr.cpp +++ b/src/sockaddr.cpp @@ -5,6 +5,8 @@ #include <arpa/inet.h> +using namespace netlib; + SockAddr::SockAddr() : SockAddr{IpAddr::V4("0.0.0.0"), 0} { } diff --git a/src/tcplistener.cpp b/src/tcplistener.cpp index 54f07fb..fd4b879 100644 --- a/src/tcplistener.cpp +++ b/src/tcplistener.cpp @@ -5,6 +5,8 @@ #include <unistd.h> #include <sys/socket.h> +using namespace netlib; + // TODO: More and better error handling TcpListener::TcpListener(SockAddr _local) diff --git a/src/tcpstream.cpp b/src/tcpstream.cpp index c08d403..f95afbe 100644 --- a/src/tcpstream.cpp +++ b/src/tcpstream.cpp @@ -7,6 +7,8 @@ #include <netinet/in.h> #include <poll.h> +using namespace netlib; + TcpStream::TcpStream(SockAddr _remote) : remote{_remote}, sockfd{0} { } diff --git a/src/udpsocket.cpp b/src/udpsocket.cpp index 89234e4..1f6a323 100644 --- a/src/udpsocket.cpp +++ b/src/udpsocket.cpp @@ -6,6 +6,7 @@ #include <sys/socket.h> #include <poll.h> +using namespace netlib; UdpSocket::UdpSocket() : UdpSocket{"0.0.0.0", 0} diff --git a/test/test.cpp b/test/test.cpp index 2fe4d83..994ff63 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -7,6 +7,7 @@ #include "netlib.hpp" +using namespace netlib; TEST_CASE("Test IpAddr::V4") { -- GitLab