The patch look fine and I like the idea. But could you add an error message to each of this functions if the types don't match. I'm afraid here that c++ picks up the wrong function and we get some bugs that will be hard to localize. With a error message we will at least know what to look for.
Dennis Am Dienstag 24 Februar 2009 15:18:47 schrieb Joel Bosveld: > Adds conversion operators to CompOption::Value so we can just write > option->value (), rather than e.g. option->value (). s() > > Assuming that such a change would be commited, I am not sure if the > CompAction* is correct. I added this while testing the changes with the > move plugin, as this was the only way I could get it to work - apart from > the 'old' way - otherwise it would complain about invalid conversion from > int or invalid conversion from CompValue*, depending on how I changed that > part in move. > > Joel. > > ------ > > From ba9be143d61644c8db0b6161f4c3f8db6510d96c Mon Sep 17 00:00:00 2001 > From: Joel Bosveld <[email protected]> > Date: Tue, 24 Feb 2009 22:43:50 +0900 > Subject: [PATCH] Add conversion operators to CompOption::Value > > --- > include/core/option.h | 11 +++++++++ > src/option.cpp | 58 > +++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 69 insertions(+), 0 deletions(-) > > diff --git a/include/core/option.h b/include/core/option.h > index 0ee362e..b9f47c5 100644 > --- a/include/core/option.h > +++ b/include/core/option.h > @@ -98,6 +98,17 @@ class CompOption { > bool operator!= (const Value& val); > Value & operator= (const Value &val); > > + operator bool (); > + operator int (); > + operator float(); > + operator unsigned short * (); > + operator CompString (); > + operator CompMatch & (); > + operator CompAction & (); > + operator CompAction * (); > + operator Type (); > + operator Vector & (); > + > private: > PrivateValue *priv; > }; > diff --git a/src/option.cpp b/src/option.cpp > index 66b76cb..4705746 100644 > --- a/src/option.cpp > +++ b/src/option.cpp > @@ -250,6 +250,64 @@ CompOption::Value::list () > return priv->list; > } > > +CompOption::Value::operator bool () > +{ > + if (priv->type != CompOption::TypeBool) > + return false; > + return priv->value.b; > +} > + > +CompOption::Value::operator int () > +{ > + if (priv->type != CompOption::TypeInt) > + return 0; > + return priv->value.i; > +} > + > +CompOption::Value::operator float() > +{ > + if (priv->type != CompOption::TypeFloat) > + return 0.0; > + return priv->value.f; > +} > + > +CompOption::Value::operator unsigned short * () > +{ > + if (priv->type != CompOption::TypeColor) > + return reinterpret_cast<unsigned short *> (&defaultColor); > + return priv->value.c; > +} > + > +CompOption::Value::operator CompString () > +{ > + return priv->string; > +} > + > +CompOption::Value::operator CompMatch & () > +{ > + return priv->match; > +} > + > +CompOption::Value::operator CompAction & () > +{ > + return priv->action; > +} > + > +CompOption::Value::operator CompAction * () > +{ > + return &priv->action; > +} > + > +CompOption::Value::operator Type () > +{ > + return priv->listType; > +} > + > +CompOption::Value::operator Vector & () > +{ > + return priv->list; > +} > + > bool > CompOption::Value::operator== (const CompOption::Value &val) > {
_______________________________________________ Dev mailing list [email protected] http://lists.compiz-fusion.org/mailman/listinfo/dev
