IPB

Welcome Guest ( Log In | Register )

> foobar2000 Development Forum Rules

This forum is for developer discussions only. If you have a problem / bug report / idea / feature request that isn't related to foobar2000 SDK, post it in an appropiate forum instead - tech support questions go to support forum, everything else goes to general forum.
All non-developer posts on this forum will be removed. Continued abuse of this forum will result in admin actions (warnings, account suspension).

 
Reply to this topicStart new topic
how to access the instantiation of my component?
vroomvroom
post Jan 17 2012, 08:51
Post #1





Group: Members
Posts: 6
Joined: 15-June 11
Member No.: 91531



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

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..
Go to the top of the page
+Quote Post
foosion
post Feb 20 2012, 13:33
Post #2





Group: FB2K Moderator (Donating)
Posts: 4336
Joined: 24-February 03
Member No.: 5153



QUOTE (vroomvroom @ Jan 17 2012, 08:51) *
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. wink.gif


--------------------
http://foosion.foobar2000.org/ - my components for foobar2000
Go to the top of the page
+Quote Post
vroomvroom
post Feb 29 2012, 08:49
Post #3





Group: Members
Posts: 6
Joined: 15-June 11
Member No.: 91531



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.



Go to the top of the page
+Quote Post
foosion
post Feb 29 2012, 11:17
Post #4





Group: FB2K Moderator (Donating)
Posts: 4336
Joined: 24-February 03
Member No.: 5153



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
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 20th April 2014 - 19:55