Author Topic: IsKindOf doesn't work for reliably?  (Read 2789 times)

Offline MadBoat

  • Multiple posting newcomer
  • *
  • Posts: 11
IsKindOf doesn't work for reliably?
« on: August 08, 2015, 01:35:12 am »
As an experiment I ran the following code today

Code

            if (Manager::Get()->GetEditorManager()->GetEditor(ii)->GetClassInfo()->IsKindOf(CLASSINFO(cbEditor)))   
                    yea_or_nay = _T("yea");
            else yea_or_nay = _T("nay");
            DEBUG_LOG(F(_T("cbEditor: %s "), yea_or_nay.wx_str()));

            if (Manager::Get()->GetEditorManager()->GetEditor(ii)->GetClassInfo()->IsKindOf(CLASSINFO(EditorBase)))
                   yea_or_nay = _T("yea");
            else yea_or_nay = _T("nay");
            DEBUG_LOG(F(_T("EditorBase: %s "), yea_or_nay.wx_str()));

            if (Manager::Get()->GetEditorManager()->GetEditor(ii)->GetClassInfo()->IsKindOf(CLASSINFO(StartHerePage)))
                    yea_or_nay = _T("yea");
            else yea_or_nay = _T("nay");
            DEBUG_LOG(F(_T("StartHerePage: %s "), yea_or_nay.wx_str()));

            if (Manager::Get()->GetEditorManager()->GetEditor(ii)->GetClassInfo()->IsKindOf(CLASSINFO(wxTextCtrl)))
                    yea_or_nay = _T("yea");
            else yea_or_nay = _T("nay");
            DEBUG_LOG(F(_T("wxTextCtrl: %s "), yea_or_nay.wx_str()));


And this was the result
Code
cbEditor: yea                 //could be right; cbEditors are commonly handled by the EditorManager
EditorBase: yea             //reveals no new information; cbEditor is derived from EditorBase
StartHerePage: yea      //Bullshit. StartHerePage is derived from EditorBase, not cbEditor.
wxTextCtrl: nay             //sanity check

I note also that in established source, IsKindOf is only ever used with a widgets class... I conclude that isKindOf is not supported by code blocks classes.

Is there some other way of determining one codeblocks class from another? Or did I cock this up somehow?


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13152
    • Travis build status
Re: IsKindOf doesn't work for reliably?
« Reply #1 on: August 08, 2015, 01:57:43 am »
What do you need to do?
You can distinguish source editors from the other kind of editors.
Also there is a chance that dynamic_cast could work, but it is known to fail for dlopened shared objects on linux.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MadBoat

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: IsKindOf doesn't work for reliably?
« Reply #2 on: August 08, 2015, 02:17:55 am »
What do you need to do?
You can distinguish source editors from the other kind of editors.
Also there is a chance that dynamic_cast could work, but it is known to fail for dlopened shared objects on linux.

I modify margin widths on every open document when I initialize my plugin... this is done by accessing the cbEditor's getControl() object. have to make sure that member is valid.

The dynamic cast does seem to work... dynamic cast was not in my vocabulary, so thanks for that. :D

As far as .so's on linux are concerned, I think it doesn't apply in this case... all three class variants I mentioned are built-in, yeah? So long as I'm not tying to use dynamic cast with classes I pull in via plugin, I got no problems?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13152
    • Travis build status
Re: IsKindOf doesn't work for reliably?
« Reply #3 on: August 08, 2015, 02:23:08 am »
The is EditorBase::IsBuiltinEditor for this. It is better to use it instead of dynamic_cast.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MadBoat

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: IsKindOf doesn't work for reliably?
« Reply #4 on: August 08, 2015, 02:45:30 am »
The is EditorBase::IsBuiltinEditor for this. It is better to use it instead of dynamic_cast.
...ah. Yes, quite so. Only applicable in this particular case, but useful anyway. Thanks.