[vlc-commits] cxx helpers: Add an url helper

Hugo Beauzée-Luyssen git at videolan.org
Mon Jun 22 15:24:11 CEST 2020


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Mar  3 09:42:50 2020 +0100| [1b64ac0e2ea5662e2bff93021d926091965c9720] | committer: Hugo Beauzée-Luyssen

cxx helpers: Add an url helper

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1b64ac0e2ea5662e2bff93021d926091965c9720
---

 include/vlc_cxx_helpers.hpp | 62 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/include/vlc_cxx_helpers.hpp b/include/vlc_cxx_helpers.hpp
index 5c55ff01b3..0194e37a35 100644
--- a/include/vlc_cxx_helpers.hpp
+++ b/include/vlc_cxx_helpers.hpp
@@ -32,6 +32,8 @@
 #include <memory>
 #include <utility>
 #include <type_traits>
+#include <string>
+#include <stdexcept>
 
 #ifdef VLC_THREADS_H_
 // Ensure we can use vlc_sem_wait_i11e. We can't declare different versions
@@ -397,6 +399,66 @@ private:
 
 #endif // VLC_THREADS_H_
 
+#ifdef VLC_URL_H
+
+class url : public vlc_url_t
+{
+public:
+    class invalid : public std::runtime_error
+    {
+    public:
+        invalid( const char* url )
+            : std::runtime_error( std::string{ "Invalid url: " } + url )
+        {
+        }
+    };
+
+    url()
+    {
+        psz_buffer = nullptr;
+        psz_pathbuffer = nullptr;
+        psz_host = nullptr;
+    }
+
+    url( const char* str )
+    {
+        if ( vlc_UrlParse( this, str ) )
+            throw invalid( str );
+    }
+
+    url( const std::string& str )
+        : url( str.c_str() )
+    {
+    }
+
+    ~url()
+    {
+        vlc_UrlClean(this);
+    }
+
+    url( const url& ) = delete;
+    url& operator=( const url& ) = delete;
+
+    url( url&& u ) noexcept
+        : vlc_url_t( u )
+    {
+        u.psz_buffer = nullptr;
+        u.psz_pathbuffer = nullptr;
+        u.psz_host = nullptr;
+    }
+
+    url& operator=( url&& u ) noexcept
+    {
+        *(static_cast<vlc_url_t*>( this )) = u;
+        u.psz_buffer = nullptr;
+        u.psz_pathbuffer = nullptr;
+        u.psz_host = nullptr;
+        return *this;
+    }
+};
+
+#endif
+
 } // namespace vlc
 
 #endif



More information about the vlc-commits mailing list