How to use parameters to initialize global classes

General information about brain-computer interfaces
Posts: 4
Joined: 02 Sep 2012, 08:43

How to use parameters to initialize global classes

Post by aro_slo » 23 Sep 2012, 05:18

Hi everyone,

I am using an Input Logger to acquire a secondary signal; to do so I need to initialize a global class which is so accessible by any blocks in the file . I declare my class just below my header files inclusions and everything works.

As development, I want my class constructor (called with class declaration) to use a bci2000-parameter for class initialization-passing it as argument.
The problem is that I can only access to bci2000-parameter after a Preflight phase and inside subsequent blocks in which a class declaration would make it local and not global.

Thanks for helping me.

Posts: 1207
Joined: 12 Feb 2003, 11:06

Re: How to use parameters to initialize global classes

Post by mellinger » 25 Sep 2012, 13:36


it is difficult to understand what you are trying to do. Generally, there is no need for you to create global objects in order to implement a BCI2000 logger. Your desire to do so suggests a misunderstanding.

Is it that you need to create an instance of a certain class C, and that you need to access that instance from inside your logger thread's main loop? If so, then add a member declaration to your logger class:

C mC;

This way, an instance of class C will be created with your logger, and may be accessed by the logger at any time. At the time when your logger is instantiated, parameters will be available to it, so parameter information can be passed to the constructor of C (use a ctor initializer to pass arguments to the constructor of a class member).

If creation of the class instance depends on BCI2000 parameters that may change whenever the user clicks SetConfig, use a pointer to an instance instead:

C* mpC;

Don't forget to initialize it to NULL in your logger's constructor, and don't forget to call delete on it inside your logger's destructor. Then, create the class instance from your logger's Initialize() function, using BCI2000 parameters as appropriate.



Who is online

Users browsing this forum: No registered users and 1 guest