Skip to main content

Topic: how to access the instantiation of my component? (Read 1842 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
how to access the instantiation of my component?
Hi all,

Please bear with me while I ask a possibly dumb question. How do I access the instantiated object of my component? Let's say I'm creating two ui_elements, A and B. I would like A to be able to call B's public functions, without making B's public functions static. In order to do this, A would need access to B's instantiation but I'm unable to figure out how.

For example, taking the SDK's foo_sample's ui_element.cpp:
Code: [Select]
class CMyElemWindow : public ui_element_instance, public CWindowImpl<CMyElemWindow> {
...
}

// ui_element_impl_withpopup autogenerates standalone version of our component and proper menu commands. Use ui_element_impl instead if you don't want that.
class ui_element_myimpl : public ui_element_impl_withpopup<CMyElemWindow> {};

static service_factory_single_t<ui_element_myimpl> g_ui_element_myimpl_factory;

It seems that the last two lines have to do with the instantiation of my class, but I'm unable to figure out how to get access to this instantiation.

I realize I could (or should) just create a single ui_element instead of two, but having two separate ui_elements allows me to arrange them in different spots within foobar.
Any ideas?

Many thanks in advance..

  • foosion
  • [*][*][*][*][*]
  • Moderator
how to access the instantiation of my component?
Reply #1
I realize I could (or should) just create a single ui_element instead of two, but having two separate ui_elements allows me to arrange them in different spots within foobar.
I'm a bit confused by that statement. Can you describe your use case? Do you want communication between two different types of UI elements (i.e. different classes) or between different instances of the same class?

I realise your post is already a month old, so I have no idea if you have solved the problem in the meantime.
http://foosion.foobar2000.org/ - my components for foobar2000

how to access the instantiation of my component?
Reply #2
Thanks for your response. Does it matter whether I want communication between different classes or different instances of the same class? They're still separate instances, and I do not have handles for any of them. By the way, my use case involved two different classes.

In any case, I got around the problem by doing two things: (I had multiple, not just two, classes, so I used two different solutions)
1) merge two classes into one
2) create a global variable that is a pointer to a class A, make class B a friend of class A, and use that pointer from class B (to access members in class A)

I realize 2) is kinda ugly, but it was the best I could do to keep things orderly (i.e. separate classes) while allowing "inter-class" communication.




  • foosion
  • [*][*][*][*][*]
  • Moderator
how to access the instantiation of my component?
Reply #3
It matters whether you want to achieve coupling between two instances from different classes (one-to-one communication) or broadcast to all instances of a given class (one-to-all communication). Note that UI elements should be able to handle multiple instances and not just zero or one. If you want to track your current instances you should use per-class instance lists instead of a single pointer.

I cannot give you more specific advice because your use case is still unclear to me.
http://foosion.foobar2000.org/ - my components for foobar2000