From: John P. F. <jf...@ov...> - 2008-10-23 22:42:09
|
Glyn Matthews wrote: > Hi Kim, > > 2008/10/23 Kim Gräsman <kim...@gm... > <mailto:kim...@gm...>> > > Glyn, > > On Tue, Oct 21, 2008 at 14:23, Glyn Matthews > <gly...@gm... <mailto:gly...@gm...>> wrote: > > > > Do you still intend to keep the host/port in the fusion map? > How do you > > intend to deal with URIs like this: > > > > file:///home/user/myfile.txt > > mailto:som...@ex... <mailto:som...@ex...> > > I just checked briefly how .NET's System.Uri class handles this, and > it treats them all the same. > > > file:///home/user/myfile.txt > > No host + port here, only a scheme and a path > > > mailto:som...@ex... <mailto:som...@ex...> > > No path info, just a user prefix (some.dude) and a host > (example.com <http://example.com>) > > I suppose that makes sense in a way... Thoughts? > > > so we'd have something like: > > template <class Tags> > class basic_uri { > public: > typename string<Tags>::type scheme() const; > typename string<Tags>::type host() const; > int host() const; > typename string<Tags>::type user_info() const; > typename string<Tags>::type authority() const; > // etc. > }; > > and the member functions return empty strings for the components that > don't apply? That's not a problem. > > If you want to compare with other languages, the documentation for > Java's URI class is good: > > http://java.sun.com/j2se/1.5.0/docs/api/java/net/URI.html > > Do you have time to do a lot with this? Could we target a 0.4 release > with a URI class? I can help with what I can, but I'm really busy at > work. > > G > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > ------------------------------------------------------------------------ > > _______________________________________________ > Cpp-netlib-devel mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cpp-netlib-devel > I implemented this in a similar network client project some time ago: namespace rfc3986 { template < typename ParserInput = std::string, typename Scheme = std::string, typename Authority = std::string, typename Path = std::string, typename Query = std::string, typename Fragment =std::string > class URI { public: ///Public type access typedef Scheme scheme_type; typedef Authority authority_type; typedef Path path_type; typedef Query query_type; typedef Fragment fragment_type; Scheme getScheme() const { return m_scheme; } Authority getAuthority() const { return m_auth; } Path getPath() const { return m_path; } Query getQuery() const { return m_query; } Fragment getFragment() const { return m_fragment; } private: typedef URI< ParserInput, Scheme, Authority, Path, Query, Fragment> Output; friend Output* parse< ParserInput, Output> (std::stack<std::string>& errors, const ParserInput& input); URI(Scheme scheme, Authority auth, Path path, Query query, Fragment fragment) : m_scheme(scheme), m_auth(auth), m_path(path), m_query(query), m_fragment(fragment) {} const Scheme m_scheme; const Authority m_auth; const Path m_path; const Query m_query; const Fragment m_fragment; }; }; The advantage of this is: 1) The relationship between the parser and the validated URI object is explicit. 2) This is a flexible class with a precise interface. IE: typedef URI< URI<>, std::string, HostConnection, std::string, std::string > HTTP; class HostConnection { public: std::string getName() const; const int* getPort() const; HostConnection(const HostConnection& other); ~HostConnection(); private: friend HostConnection* parse<std::string, HostConnection> (std::stack<std::string>& errors, const std::string& input); HostConnection(const std::string& name, const int* port); const std::string m_name; const int* m_port; }; I will provide full sources with parser if requested. John |