jp-embedded / scxmlcc

The SCXML state machine to C++ compiler
GNU General Public License v3.0
140 stars 34 forks source link

datamodel does not support custom structures "natively" (but some workaround is available) #63

Closed valioiv closed 5 years ago

valioiv commented 6 years ago

It seems impossible to put your own type for the entries - float, std::vector, some custom structure (#include "custom_struct.h" prior to), etc. Data in SCXML like that:

  <!--  trivial 5 second microwave oven example -->
  <datamodel>
    <data id="cook_time" expr="5"/>
    <data id="door_closed" expr="true"/>
    <data id="timer" expr="0"/>
  </datamodel>

produce the following snippet:

//...
  int cook_time;
  int door_closed;
  int timer;
  data_model() : cook_time(5), door_closed(true), timer(0) {}
//...

Is it known to fixing it or how to workaround it in a different way?

For example if have something like that:

  <!--  trivial 5 second microwave oven example -->
  <datamodel>
    <data id="CustomStruct1 cust" expr=""/>
    <data id="float flt" expr="0.5"/>
  </datamodel>

how the output will become (or anything compilable close to):

//...
  #include "<path_to_my_custom_header.h>"
  CustomStruct1 cust;
  float flt;
  data_model() : cust(), flt(0.5) {}
//...
jp-embedded commented 6 years ago

well, your proposed example should work already exactly as is ;-) except for the inclusion of custom types. The include part is not supported yet, but I will try if I can priorotize that.

An obvious workaround is to include the files before you include your state machine.

The documentation regarding this is also missing.

valioiv commented 6 years ago

Yep, the float is OK, I agree. Sorry for the confusion... I wrote the following XML:

<data id="#include &quot;<path_to_my_custom_header>/cust_header.h&quot;" src=""/>
<data id="float flt" expr="0.5"/>
<data id="my::custom::name::space::CustomStruct1 cust" src=""/>

and managed to produce the following code, which seems OK for my needs at that moment:

  #include "<path_to_my_custom_header>/cust_header.h";
  float flt;
  my::custom::name::space::CustomStruct1 cust;
  data_model() : flt(0.5) {}

Thanks for confirmation!

jp-embedded commented 6 years ago

You are welcome. It's hard to know, when the documentation is not complete ;-)