Hi, I have a question about the use of QM.
I created a state machine class named VMod. VMod mod[N] is created as needed in the user program. Therefore, I need to define the VMod structure in vmod.h, but there is no need to declare the internal state functions of VMod. However, using $declare {VMod} will generate all methods of the class by default. Is there a solution?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Andrew,
Yes, the directive $declare {VMod} generates the whole class VMod, which includes all class members: both data members and member functions. State-handler functions are member functions (they need the me instance pointer), so they are included. This is exactly as in C++, where a valid class declaration requires all members.
But your problem is really not about the class declaration, but about encapsulation and information hiding. It seems to me that you're trying to go about it in the traditional "C way", where you expose the VMod struct (the data members) in a header file, but want to hide the member functions from this header file.
All provided examples for QP/C illustrate a different approach--with a much better encapsulation. Specifically, the DPP (Dining Philosophers Problem) application also contains an array of the Philo active objects. But this array is statically allocated in the philo.c implementation file:
Please study the DPP examples and the structure of the QM model file (dpp.qm), which are provided many times over in the qpc\examples directory. I hope you will like the "opaque pointer" pattern.
--MMS
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Dr Samek! Thank you for your help!
The essence of my purpose is to have the number of user-maintainable instances, which can be achieved entirely by controlling the macro like N without having to expose the structure definition itself, thank you very much.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I have a question about the use of QM.
I created a state machine class named
VMod.VMod mod[N]is created as needed in the user program. Therefore, I need to define theVModstructure invmod.h, but there is no need to declare the internal state functions ofVMod. However, using$declare {VMod}will generate all methods of the class by default. Is there a solution?Hi Andrew,
Yes, the directive
$declare {VMod}generates the whole classVMod, which includes all class members: both data members and member functions. State-handler functions are member functions (they need themeinstance pointer), so they are included. This is exactly as in C++, where a valid class declaration requires all members.But your problem is really not about the class declaration, but about encapsulation and information hiding. It seems to me that you're trying to go about it in the traditional "C way", where you expose the
VModstruct (the data members) in a header file, but want to hide the member functions from this header file.All provided examples for QP/C illustrate a different approach--with a much better encapsulation. Specifically, the DPP (Dining Philosophers Problem) application also contains an array of the
Philoactive objects. But this array is statically allocated in the philo.c implementation file:As you can see, the whole
$declare${AOs::Philo}directive is inside the C file, and specifically is not exposed in any header file.Instead, the dpp.h header file only exposes the "opaque pointers" to the
PhiloAOs (as well as theTableAO)Please study the DPP examples and the structure of the QM model file (
dpp.qm), which are provided many times over in theqpc\examplesdirectory. I hope you will like the "opaque pointer" pattern.--MMS
Hi Dr Samek! Thank you for your help!
The essence of my purpose is to have the number of user-maintainable instances, which can be achieved entirely by controlling the macro like
Nwithout having to expose the structure definition itself, thank you very much.Last edit: andrew frank 2025-12-05