Using C++ Boost libraries for KDevelop

Alexander Neundorf neundorf at kde.org
Thu Nov 17 11:09:05 UTC 2005


On Thursday 17 November 2005 10:44, Vladimir Prus wrote:
> Hi,
> the more I work on debugger, the more I think that using some libraries
> from C++ Boost would simplify the code quite a bit.
>
> For example, I send a command to debugger and want to be notified when that
> command finished. Currently, there's no such way, at all. All possible
> solutions are pretty clumsy.
>
> With C++ Boost, specifically with Boost.Function and Boost.Bind libraries,
> things will be improved a lot, I'll be able to write this:
>
>     class GDBController {
>     public:
>         void queueCmd(const QString& command,
>                       boost::function<void ()> callback);
>     };
>
>     class SomeOtherClass {
>     public:
>         void do_operation()
>         {
>                 controller->queueCmd(
>                    "whatever",
>    				boost::bind(&SomeOtherClass::step_2, this));
>         }
>         void step_2()
>         {
> 			// Continue with the operation.
>         }
>     };
>
> Here:
> - boost::function<void ()> is a generic functional object taking
>   no arguments and returning nothing
> - boost::bind in the above example takes method pointer, and this,
>   and binds them together. The resulting class instance can be
>   called with zero arguments.

How about something like this:

controller->queueCmd("whatever", this, SLOT(step_2()); 
with 
void Controller::queueCmd(const char* cmd, QObject* recv, const char* slot)
{
   //this can also be done conditionally:
   connect(this, SIGNAL(cmdDone()), recv, slot);
   //I guess there's also a way to invoke a slot more directly 
   // with some more low-level Qt stuff, QMetaObject or something
   //so you wouldn't need to emit the signal
}

From my experience, when I tried to use boost signals, I had to include large 
parts of boost. So, for now, I wouldn't be overly happy if kdevelop would 
require boost.

Alex
-- 
Work: alexander.neundorf at jenoptik.com - http://www.jenoptik-los.de
Home: neundorf at kde.org                - http://www.kde.org
      alex at neundorf.net               - http://www.neundorf.net




More information about the KDevelop-devel mailing list