[#158] Autogenerated SE types?
Summary Autogenerated SE types?
Queue gloox
Queue Version SVN
Type Enhancement
State Unconfirmed
Priority 2. Medium
Requester euroelessar (at) gmail (dot) com
Created 10/18/2009 (4027 days ago)
Updated 10/22/2009 (4023 days ago)

10/22/2009 11:19:55 AM euroelessar (at) gmail (dot) com Comment #3
New Attachment: regse[1].diff
Reply to this comment
a new patch with a little better code style. Added new file: 
stanzaextension.cpp, don't forget to add it to files list
10/21/2009 05:49:13 PM euroelessar (at) gmail (dot) com Comment #2
New Attachment: regse.diff
Reply to this comment
And the patch: source compatibility is provided
10/18/2009 02:15:19 PM euroelessar (at) gmail (dot) com Comment #1
State ⇒ Unconfirmed
Queue ⇒ gloox
Summary ⇒ Autogenerated SE types?
Type ⇒ Enhancement
Priority ⇒ 2. Medium
Reply to this comment
Now we have enum of possible gloox's StanzaExtensions (enum 
StanzaExtensionType), but it's boring and hard to use them, i.e. 
"const VCardUpdate *vcard_update = 
I tell to method info about SE both by template and enum. But just 
imagine how simpler become our source if we will give to method all 
info just by template!
"const VCardUpdate *vcard_update = 
presence.findExtension<VCardUpdate>();" is easier, isn't it?
So, what are the ways for it?..
I think, it's possible to create some macro, like this one:
template <> \
int stanzaExensionType<SEClass>(SEClass *t = 0) \
{ \
   static int type = -1; \
   if(type == -1) \
     type = registerStanzaExtension(#SEClass); \
   return type; \
both with functions:
template <typename T> int stanzaExensionType(T *t = 0) { return -1; }
GLOOX_API int registerStanzaExtension(const char *name);
second one should return positive unique integer value for different 
name's and the same for equal ones. Invoking of method 
stanzaExensionType<T>() is equal to guessing of correct enum. Also 
macro should be used in this way:
REGISTER_STANZA_EXTENSION(gloox::VCardUpdate), namespace mustn't be skiped.

What do you think about it?..