Code::Blocks

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Compiler Framework Redesign => Topic started by: rickg22 on December 30, 2005, 01:23:36 am

Title: cbVariant class - update: discarded
Post by: rickg22 on December 30, 2005, 01:23:36 am
OK, before we reinvent the wheel here, I'm asking:

How many c++ "variant" classes are out there? Has anyone used them? (They MUST NOT use templates)

This is a basic draft of what I came up with:

Code: [Select]
union cbtypes_t {
  char c;
  int i;
  bool b;
  float f;
} cbtypes;

class cbVariant
{
  public:
    bool is_undefined() { return m_type=='u'; }
    char QueryType();
    operator==(int intval);
    operator==(bool bool);
    ...
    operator_the_last_operator_used(last_type_used blah);
  private:
    char m_type;
    cbtypes m_v;
    wxString m_s;
};

Is there anything like this on the net?
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: 280Z28 on December 30, 2005, 01:26:54 am
Can you add a brief explanation to the first post that explains 1) how such a class relates compiler framework and 2) why templates are bad. It'll stop some off-topic questions before they are asked. :)

Also, are you sure this should be in the compiler framework and not a part of the Code::Blocks SDK (where we just use it in the compiler framework)?
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: 280Z28 on December 30, 2005, 01:31:03 am
Actually, if you think this is more of an SDK concept than a compiler framework concept (I'm thinking it probably is), then the way it relates to the compiler framework is unrelated to the discussion of implementation, but you might want to move this thread to the Development forum in that case. :) But you still might include why templates are bad. I'll remove these posts once you edit and/or move the thread. :)

Edit: Actually I'm going to dinner now. You can definitely delete them yourself once you read them. :)
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: rickg22 on December 30, 2005, 01:37:32 am
OK...

1) this variant class is required because:

The most important part of the framework consists of a map of variants. Actually, a class which holds a map of variants. *ALL* the configurations will be stored in a tree, where the nodes hold these.

2) And it needs to be template-free, because:

I don't want to impose the burden of templates for a simple thing which can be defined with a union of POD (plain-old-data) types and a string.

3) Finally, this belongs in the compiler framework forum, because:

The compiler framework is ALREADY in the SDK. The compiler plugin is based on this framework (see CompilerOptionsBase, CompilerTargetBase classes defined in the SDK)
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: 280Z28 on December 30, 2005, 01:44:44 am
The idea of a cbVariant seems useful (to me) as a global C::B SDK general utility class so any CB plugin can make use of it for storing preferences or internal data. Having it as a compiler plugin specific class could unnecessarily limit its use to other plugin developers.
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: rickg22 on December 30, 2005, 01:47:49 am
The idea of a cbVariant seems useful (to me) as a global C::B SDK general utility class so any CB plugin can make use of it for storing preferences or internal data. Having it as a compiler plugin specific class could unnecessarily limit its use to other plugin developers.

Yes, the cbVariant and cbProperty (to be defined elsewhere in this forum) will be part of the SDK, but the new compiler framework REQUIRES these classes.

So, *ahem* hello? Anyone?
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: byo on December 30, 2005, 02:09:11 am
How about wxVariant ? http://www.wxwidgets.org/manuals/2.6.2/wx_wxvariant.html#wxvariant
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: rickg22 on December 30, 2005, 04:24:31 am
How about wxVariant ? http://www.wxwidgets.org/manuals/2.6.2/wx_wxvariant.html#wxvariant

Um... eew?

(I read the docs). I don't think we'll be needing all those types... Anyway, I researched more, and the Microsoft VARIANT type is even worse  :shock: . I think it'll be cheaper to implement it ourselves.
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: tiwag on December 30, 2005, 04:25:55 am
OK, before we reinvent the wheel here...
  :)
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: takeshi miya on December 30, 2005, 04:35:33 am
I know you said no templates, but you can still look at boost.variant.

But, a version with little (almost none) templatization, very simmilar class is boost.any.
Perhaps that's what you're looking for.  :)

http://boost.org/doc/html/variant/misc.html#variant.versus-any
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: rickg22 on December 30, 2005, 06:44:41 am
Hmmm....

Interesting. Anyway I think i made up my mind, we'll use a very basic version (mine :P ) of variant. For storing the configs we shouldn't use advanced types other than wxString. Arrays should be handled with cbProperty classes.
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: takeshi miya on December 30, 2005, 06:49:46 am
Good enough for the purpose I think.
If you have any design concerns look at the boost.any.
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: killerbot on December 30, 2005, 09:41:45 am
to quote Thomas ... ***shudders***
Storing a type in the class and using unions.
Last month in Vegas several Gurus were flaming against those kind of things.
I'd say templates (I don't consider them a burden), leave the work up to the compiler.

Just another 'little' remark, when talking about the new features, maybe it's better to not think about implementation details yet (like using a tree) ??

Anyway, time to think and think ... ;-)

Lieven
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: thomas on December 30, 2005, 10:27:43 am
to quote Thomas ...
Hey, don't use my name in the same thread as the word variant... I am not involved in this :P
But yes, you are right, Lieven.
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: TDragon on December 30, 2005, 03:46:40 pm
Personall, I'm not clear on what exactly your map/tree of variants does in the compiler framework. The only things I can envision requiring something like that would be handled more gracefully by inheritance and polymorphism. (But then, I've never sat down and designed a compiler framework before, so I'm probably missing something.)
Title: Re: cbVariant class - REQUIRED! Need implementation
Post by: rickg22 on December 31, 2005, 08:31:26 am
Storing a type in the class and using unions.
Last month in Vegas several Gurus were flaming against those kind of things.

Mind giving us an example? See, the question with the variant type... is that we need it to be:

a) Compact - to use the least possible memory, because we'll be using THOUSANDS of these.
b) Easily serializable. For me, using a char to define the type fits this.
Title: Re: cbVariant class - update: disposed
Post by: rickg22 on January 02, 2006, 08:28:20 pm
Anyway, after thinking it for a while, maybe the use of variants isn't such a good idea. At least not for the compiler framework (it might prove useful in some config-related business). Thanks all for your feedback! :)