From: Glyn M. <gly...@gm...> - 2007-07-17 19:43:40
|
Guys, I've been giving a little thought to something Dean mentioned in his last message about using std::string in the network library. The first thing I thought of was that Dean stated that "everything is a template". Apart of course from std::string. I have created a branch in SVN named gxm) which replaces all references to std::string with an extra template parameter. Happily, this passes all the original tests (with an additional template specialization so that const char * is converted to a std::string). However, this creates a problem (certainly with GCC) because the wchar_t typedef is the same as char and its not possible to overload const wchar_t * in the same way. So the following code will not compile: wmessage wmsg; wmsg << header(L"wide characters"); Another thing I see is that boost filesystem and boost program_options have dealt with a very similar problem to this. But if we use the same approach (see the file "boost/detail/utf8_codecvt_facet.hpp" ) then we'd have to accept the use of a cpp source file, meaning we will no longer have a header only library. What do others think about this? G |
From: Matt G. <mgr...@in...> - 2007-07-17 21:42:46
|
Glyn Matthews wrote: > Another thing I see is that boost filesystem and boost program_options > have > dealt with a very similar problem to this. But if we use the same > approach > (see the file "boost/detail/utf8_codecvt_facet.hpp" ) then we'd have to > accept the use of a cpp source file, meaning we will no longer have a > header > only library. Why is that so bad? More to the point, why would it be a requirement for something as big as a network protocol library to be header-only? Matt |
From: Glyn M. <gly...@gm...> - 2007-07-18 07:34:05
|
Matt, On 17/07/07, Matt Gruenke <mgr...@in...> wrote: > > Glyn Matthews wrote: > > > Another thing I see is that boost filesystem and boost program_options > > have > > dealt with a very similar problem to this. But if we use the same > > approach > > (see the file "boost/detail/utf8_codecvt_facet.hpp" ) then we'd have to > > accept the use of a cpp source file, meaning we will no longer have a > > header > > only library. > > > Why is that so bad? More to the point, why would it be a requirement > for something as big as a network protocol library to be header-only? I don't think this is so bad, but the original rationale document as set out by Dean specifically mentions that he wants this as a header only library. Glyn |
From: <rhy...@gm...> - 2007-07-18 08:13:14
|
Hi, Glyn I am recently working on a binary protocol oriented network framework based on ASIO in my project. So I do care more about a binary protocol oriented message type. so I have once asked Dean a question during a private communication: What's the granularity of the Tag template parameter of basic_message<> template? One tag per message type (I means text/binary here) or one tag per protocol? And Dean replied: The Tag template parameter is meant to differentiate the message types -- for easy extension. That means, to be clear, the message tags I envision are: tags::unicode tags::text (tags::default_) tags::binary tags::stream tags::serializable_text tags::serializable_binary tags::serializable_xml Among many others I haven't thought of yet. :D They are tags, because I don't intend to put the overhead of an abstract message class as the base class for all the message types. That allows us to implement a basic_message<tags::text> and basic_message<tags::binary>, and specialize the implementations without having to rely on inheritance and runtime polymorphism. As Dean stated, with such tags, we can specialize different message types. And I think the message type tags should imply the underlying storage policy of that type of basic_message. Say, tags::text (tags::default_) implies an std::string storage facility, while tags::unicode implies an std::wstring storage facility, and tags::stream may implies a boost::asio::streambuf storage facility (as what I've done in my own project). So I suggest we could include a storage_type in the tags struct: struct tags { struct default_ { typedef std::string storage_type; }; typedef default_::text; struct unicode { typedef std::wstring storage_type; }; struct stream { typedef boost::asio::streambuf storage_type; }; ... }; typedef basic_message<tags::text> message; typedef basic_message<tags::unicode> wmessage; typedef basic_message<tags::stream> smessage; ... Would this be sane? Cheers Cheng Glyn Matthews wrote: > Guys, > > I've been giving a little thought to something Dean mentioned in his > last message about using std::string in the network library. > > The first thing I thought of was that Dean stated that "everything is > a template". Apart of course from std::string. I have created a > branch in SVN named gxm) which replaces all references to std::string > with an extra template parameter. Happily, this passes all the > original tests (with an additional template specialization so that > const char * is converted to a std::string). However, this creates a > problem (certainly with GCC) because the wchar_t typedef is the same > as char and its not possible to overload const wchar_t * in the same > way. So the following code will not compile: > > wmessage wmsg; > wmsg << header(L"wide characters"); > > Another thing I see is that boost filesystem and boost program_options > have dealt with a very similar problem to this. But if we use the > same approach (see the file "boost/detail/utf8_codecvt_facet.hpp" ) > then we'd have to accept the use of a cpp source file, meaning we will > no longer have a header only library. > > What do others think about this? > > G > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > ------------------------------------------------------------------------ > > _______________________________________________ > Cpp-netlib-devel mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cpp-netlib-devel > |
From: Cheng L. <rhy...@gm...> - 2007-07-18 08:19:41
|
By the way, I wish that Dean may explain the seven proposed tags in detail, especially the binary tag and the stream tag which seems may feed my appetite :-D 连城 wrote: > Hi, Glyn > > I am recently working on a binary protocol oriented network framework > based on ASIO in my project. So I do care more about a binary protocol > oriented message type. so I have once asked Dean a question during a > private communication: > > What's the granularity of the Tag template parameter of > basic_message<> template? One tag per message type (I means > text/binary here) or one tag per protocol? > > And Dean replied: > > The Tag template parameter is meant to differentiate the message > types -- for easy extension. That means, to be clear, the message > tags I envision are: > > tags::unicode > tags::text (tags::default_) > tags::binary > tags::stream > tags::serializable_text > tags::serializable_binary > tags::serializable_xml > > Among many others I haven't thought of yet. :D > > They are tags, because I don't intend to put the overhead of an > abstract message class as the base class for all the message > types. That allows us to implement a basic_message<tags::text> > and basic_message<tags::binary>, and specialize the > implementations without having to rely on inheritance and runtime > polymorphism. > > As Dean stated, with such tags, we can specialize different message > types. And I think the message type tags should imply the underlying > storage policy of that type of basic_message. Say, tags::text > (tags::default_) implies an std::string storage facility, while > tags::unicode implies an std::wstring storage facility, and > tags::stream may implies a boost::asio::streambuf storage facility (as > what I've done in my own project). So I suggest we could include a > storage_type in the tags struct: > > struct tags { > struct default_ { > typedef std::string storage_type; > }; > > typedef default_::text; > > struct unicode { > typedef std::wstring storage_type; > }; > > struct stream { > typedef boost::asio::streambuf storage_type; > }; > > ... > }; > > typedef basic_message<tags::text> message; > typedef basic_message<tags::unicode> wmessage; > typedef basic_message<tags::stream> smessage; > ... > > Would this be sane? > > Cheers > Cheng > > > Glyn Matthews wrote: >> Guys, >> >> I've been giving a little thought to something Dean mentioned in his >> last message about using std::string in the network library. >> >> The first thing I thought of was that Dean stated that "everything is >> a template". Apart of course from std::string. I have created a >> branch in SVN named gxm) which replaces all references to std::string >> with an extra template parameter. Happily, this passes all the >> original tests (with an additional template specialization so that >> const char * is converted to a std::string). However, this creates a >> problem (certainly with GCC) because the wchar_t typedef is the same >> as char and its not possible to overload const wchar_t * in the same >> way. So the following code will not compile: >> >> wmessage wmsg; >> wmsg << header(L"wide characters"); >> >> Another thing I see is that boost filesystem and boost >> program_options have dealt with a very similar problem to this. But >> if we use the same approach (see the file >> "boost/detail/utf8_codecvt_facet.hpp" ) then we'd have to accept the >> use of a cpp source file, meaning we will no longer have a header >> only library. >> >> What do others think about this? >> >> G >> >> ------------------------------------------------------------------------ >> >> ------------------------------------------------------------------------- >> >> This SF.net email is sponsored by DB2 Express >> Download DB2 Express C - the FREE version of DB2 express and take >> control of your XML. No limits. Just data. Click to get it now. >> http://sourceforge.net/powerbar/db2/ >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Cpp-netlib-devel mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cpp-netlib-devel >> > > |
From: Dean M. B. <mik...@gm...> - 2007-07-18 09:24:03
|
Hi Glyn! On 7/17/07, Glyn Matthews <gly...@gm...> wrote: > Guys, > > I've been giving a little thought to something Dean mentioned in his last > message about using std::string in the network library. > > The first thing I thought of was that Dean stated that "everything is a > template". Apart of course from std::string. I have created a branch in > SVN named gxm) which replaces all references to std::string with an extra > template parameter. Happily, this passes all the original tests (with an > additional template specialization so that const char * is converted to a > std::string). However, this creates a problem (certainly with GCC) because > the wchar_t typedef is the same as char and its not possible to overload > const wchar_t * in the same way. So the following code will not compile: > > wmessage wmsg; > wmsg << header(L"wide characters"); > > Another thing I see is that boost filesystem and boost program_options have > dealt with a very similar problem to this. But if we use the same approach > (see the file "boost/detail/utf8_codecvt_facet.hpp" ) then > we'd have to accept the use of a cpp source file, meaning we will no longer > have a header only library. > > What do others think about this? > I haven't checked out your code yet, but I'm excited to see how this works (or breaks). :) Our problem primarily here is that header(L"key", L"value") is an inline method which returns a specific instance of type header_directive<tags::default_>. Now if we overloaded that inline method with say something like: inline impl::header_directive<tags::unicode> header(typename tags::unicode::str_type const & header_name, typename tags::unicode::str_type const & header_value) { return impl::header_directive<tags::unicode>(header_name, header_value); }; And then do a typedef such as: typedef basic_message<tags::unicode> message_w ; typedef basic_message<tags::unicode> wide_message ; typedef basic_message<tags::unicode> message_wide ; We'd also like to then have tags::unicode typedef the correct type for the string as 'str_type'. That way we can customize just tags::unicode for different platforms, and have the check for GCC implement the correct type there. Would you think that works? I hope I made sense... :D (Cheng, I will indulge you with that request from the other email... Let me write down my thoughts.) :) -- Dean Michael C. Berris http://cplusplus-soup.blogspot.com/ mikhailberis AT gmail DOT com +63 928 7291459 |
From: Dean M. B. <mik...@gm...> - 2007-07-18 09:49:05
|
SGkgQ2hlbmchCgpPbiA3LzE4LzA3LCDBrLPHIDxyaHl0aG0ubWFpbEBnbWFpbC5jb20+IHdyb3Rl Ogo+IEhpLCBHbHluCj4KPiBJIGFtIHJlY2VudGx5IHdvcmtpbmcgb24gYSBiaW5hcnkgcHJvdG9j b2wgb3JpZW50ZWQgbmV0d29yayBmcmFtZXdvcmsKPiBiYXNlZCBvbiBBU0lPIGluIG15IHByb2pl Y3QuIFNvIEkgZG8gY2FyZSBtb3JlIGFib3V0IGEgYmluYXJ5IHByb3RvY29sCj4gb3JpZW50ZWQg bWVzc2FnZSB0eXBlLiBzbyBJIGhhdmUgb25jZSBhc2tlZCBEZWFuIGEgcXVlc3Rpb24gZHVyaW5n IGEKPiBwcml2YXRlIGNvbW11bmljYXRpb246Cj4KPiAgICAgV2hhdCdzIHRoZSBncmFudWxhcml0 eSBvZiB0aGUgVGFnIHRlbXBsYXRlIHBhcmFtZXRlciBvZgo+ICAgICBiYXNpY19tZXNzYWdlPD4g dGVtcGxhdGU/IE9uZSB0YWcgcGVyIG1lc3NhZ2UgdHlwZSAoSSBtZWFucwo+ICAgICB0ZXh0L2Jp bmFyeSBoZXJlKSBvciBvbmUgdGFnIHBlciBwcm90b2NvbD8KPgo+IEFuZCBEZWFuIHJlcGxpZWQ6 Cj4KPiAgICAgVGhlIFRhZyB0ZW1wbGF0ZSBwYXJhbWV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