Welcome to %s forums

BrainModular Users Forum

Login Register

PCHAR question

Create your own modules in C++
Post Reply
Gizzeta
Member
Posts: 42
Location: Paris
Contact:

Unread post by Gizzeta » 20 Jan 2010, 00:59

Hi
I would like to do an object whit N out.
To do this I define the number of output in the .h like this

Code: Select all

#define NUM_OF_OUT 24
then I allocate an array of TEVT*

Code: Select all

TEVT*	pOut[NUM_OF_OUT];
in the .cpp I write

Code: Select all

void GetParamInfo (void* pModule,int n, TParamInfo* pParamInfo) {
	if&#40;n < NUM_OF_OUT&#41;&#123;
		pParamInfo->ParamType		= ptArray;
		pParamInfo->Caption			= "Out";
		pParamInfo->IsInput			= false;
		pParamInfo->IsOutput		= true;
	&#125;
and

Code: Select all

void SetEventAddress &#40;void* pModule, int n, TEVT* pEvent&#41; &#123;
	TMyModule* pMyModule = &#40;&#40;TMyModule*&#41;pModule&#41;;
	if&#40;n < NUM_OF_OUT&#41;&#123;
		pMyModule->pOut&#91;n&#93;   = pEvent;
	&#125;
it works, no problem.

Now I would like to change the Caption of each out like this: Out1, Out2, ..., Out24.
How can I do it?
pParamInfo->Caption is a PCHAR type, how can I manipulate a string like this?

Thanks for help

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 20 Jan 2010, 13:25

Hi Gizzeta,

PCHAR is a plain old pointer to char (char*)

so you can do something like this :

in your module class member definition

Code: Select all

PCHAR OutNames&#91;NUM_OF_OUT&#93;;
in your module constructor

Code: Select all

for &#40;int n=0;  n < NUM_OF_OUT; n++&#41;
&#123; 
    OutNames&#91;n&#93; = new char&#91;STRING_BUFF_SIZE&#93;;
    sprintf_s&#40; OutNames&#91;n&#93;, STRING_BUFF_SIZE, "Out%i", &#40;n +1&#41;&#41;;
&#125;
in GetParamInfo

Code: Select all

void GetParamInfo &#40;void* pModule,int n, TParamInfo* pParamInfo&#41;
&#123;

	if&#40;n < NUM_OF_OUT&#41;
	&#123;        
        pParamInfo->ParamType   = ptArray;
        pParamInfo->Caption     = &#40;&#40;YourModule*&#41;pModule&#41;->OutNames&#91;n&#93;;
        pParamInfo->IsInput     = false;
        pParamInfo->IsOutput    = true;
	&#125;
&#125;
in your module destructor

Code: Select all

	
for &#40;int n=0;  n < NUM_OF_OUT; n++&#41;
&#123;        
    if &#40;OutNames&#91;n&#93; != NULL&#41;
    &#123;
        delete&#91;&#93; OutNames&#91;n&#93;;
    &#125;
&#125;
not tested, but it should do the trick
Martin FLEURENT - Usine Developer - SDK maintainer

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 20 Jan 2010, 15:51

or even more simpler/safer with the use of the STL :)

in yourmodule.h

add includes

Code: Select all

#include <string>
#include <vector>
and a vector in your module class

Code: Select all

class TYourModule &#58; public TUserModule
&#123;
    ...
    std&#58;&#58;vector<std&#58;&#58;string> m_vectOutCaptions;
    ...
&#125;
in yourmodule.cpp

add includes and namespace use

Code: Select all

#include <string>
#include <sstream>
#include <vector>

using namespace std;
and in GetParamInfo()

Code: Select all

void GetParamInfo &#40;void* pModule,int n, TParamInfo* pParamInfo&#41;
&#123;
    // make convenient pointer to the module
    TYourModule* pYourModule = &#40;&#40;TYourModule*&#41;pModule&#41;;
        
    // the param name
    stringstream Stream; 
    Stream << &#40;n + 1&#41;;
    pYourModule ->m_vectOutCaptions.push_back&#40;string&#40;"Out "&#41; + Stream.str&#40;&#41;&#41;;

    if&#40;n < NUM_OF_OUT&#41;
    &#123;        
        pParamInfo->ParamType   = ptArray;
        pParamInfo->Caption     = &#40;PCHAR&#41;&#40;pYourModule ->m_vectOutCaptions&#91;n&#93;.c_str&#40;&#41;&#41;;
        pParamInfo->IsInput     = false;
        pParamInfo->IsOutput    = true;
    &#125;
&#125;
Martin FLEURENT - Usine Developer - SDK maintainer

Gizzeta
Member
Posts: 42
Location: Paris
Contact:

Unread post by Gizzeta » 06 Feb 2010, 13:04

It Works,
Thanks!

anbd
New member
Posts: 5
Location: Lyon
Contact:

Unread post by anbd » 23 Mar 2010, 15:23

Thanks

Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests