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).

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
 
Start new topic
Replies
vroomvroom
post Feb 29 2012, 08:49
Post #2





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

Posts in this topic


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: 23rd October 2014 - 02:38