Static access to ICore

Kris Wong wongk at seapine.com
Fri Nov 16 13:23:42 UTC 2007


> Hi! The design of kdevelop currently is, that although there
> is by definition
> only exactly one instance of ICore, it is not possible to access that
> instance statically. It can only be accessed from within IPlugin.
>
> I find this limitation quite annoying again and again,
> because it forces me to
> add useless pointers either to ICore, or to a plugin that has
> access to
> ICore, and create additional(useless) code in many places.
>
> Just for some recent examples:
> 1.
> In project_file_quickopen.cpp, each ProjectFileData item is
> self-contained,
> and needs to trigger the specific actions once it is
> executed. That means
> that it needs access to the document-controller so a file can
> be opened.
> Currently I need to add a pointer to ICore into each of these
> many objects,
> although it would save some memory and some error-prone code
> if ICore::self()
> could be used instead.
>
> 2.
> In the cpp language-support part, there's many places where
> static access to
> ICore is needed. That's why there is a
> CppLanguageSupport::self(), so the
> access is statically possible(Imo just a not nice workaround
> for the fact
> that there is no ICore::self()). Now I've moved
> navigationwidget.cpp to a
> sub-library, but the navigation-widgets still need access to
> ICore, so it can
> jump to a specific file. Now it's getting even worse, because the
> navigation-widget is created from within that
> library(cppduchain), so there
> is noone who can reach a pointer to ICore on creation.
>
> 3. In the teamwork-plugin, similar workarond were needed many times.
>
> Now, instead of adding even more static pointers to ICore to
> workaround the
> problem, I propose simply adding a static ICore::self()
> function to access
> the core from anywhere.

We've discussed this several times now. =]  I thought we came to the conclusion that this should be added?  I agree with David, we're going to continually run into this problem until we actually resolve it The Right Way (tm).  I think we should go back to the ICore::self implementation I originally added way back when.

class Icore
{
   ICore() {
      instance = this;
   }
   ~ICore() {
      instance = 0;
   }
   ICore* self() {
      return instance;
   }
   static ICore* instance;
}

Kris Wong




More information about the KDevelop-devel mailing list