|
My approach is to do all model editing in the FSM editor. Anything related to state transitions, testing whether a transition is legal, possible transfer to an error state etc. etc.
When the general FSM logic has done its job identifying a transition to be taken, there frequently is a set of updates to state variables, beyond the ID of the new state - it could be things like starting a timer, zeroing a buffer or setting flags that are tested by future state transitions. These are all specified in a general way in the FSM - think of it as quite formalized pseudocode. This is where code editing comes it: For that specific set of state variable updates, the coder writes a "real" implementation. This usually goes little beyond simple assignment statements.
Then a transition may have side effects - generally: raising events in other FSMs. Sending a message is an example. Even this is specified in formalized pseudocode in the FSM, and the developer translates that logic to some real code.
The FSM is edited as a state table - a set of squares in the crosspoint between current state and event. Each square identifies a condition for the transition to be legal (as a logic expression on a restricted set of bool functions). Then comes the ID of the next state if the transition is taken, followed by the ID of the function updating the state variables (which also is usually a limited set), and the ID of the function taking care of the side effects. Clicking on either of these four fields to take you to the details of the function.
One thing I picked up from rather complex OSI protocol state machines: If the test on the state variables shows that a transition is not legal, maybe some other transition is legal. (The very trivial case: If a state variable x is true, make this transition, otherwise make that transition.) Purists say that this should be treated as two completely indepenent states, but allowing tests on other variables than just the current state is essential to avoid an explosion of states.
The general FSM editing is independent of programming language. From the tables, a code skeleton can be genereated, calling those functions for testing and updating state variables and causing side effects that the programmer wrote. So you may have one common FSM model for different languages, provided that you have written a skeleton generator for each relevant language.
One remaining "problem" (if it is): My generator will produce a complete set of source files that may be set up e.g. as a Visual Studio project for complilation. What happens when the compiler reports a syntax error? Or debugging reports a logic error in one of the functions? As is is now, the developer must go back to the FSM editor to make the correction there, generate a new set of files, and recompile / rerun. This is not acceptable in the long run. I plan to learn how to write VS plugins, to attach the FSM editor to VS, let the user edit each function and then, based on coded comments in the source, bring the edits back into the FSM model. If the problem is not in a single function, but in the FSM logic, then you skip into the FSM editor, doing the changes there. This is certainly some way from being completed...
If you have been thinking along simlar paths, feel free to present an introduction.
|
|
|
|
|
Your project might move along faster if you targeted your FSM editor to my session processing framework in the Robust Services Core sb[^] directory. I've yet to write any CP articles about it, because the lower level parts of that code base are useful to a much wider audience. But there's a fair amount of documentation[^] and examples; scroll to the bottom of that page. It's essentially the framework used in a GSM MSC that evolved to LTE and is still seeing development. It has run-time support, TLV messaging, state machines that can observe and override the behavior of others, and even overload controls. A tool would be very useful even if it simply generated the C++ boilerplate needed when deriving from the classes defined by that framework.
|
|
|
|
|
I am trying to get comfortable using "vector".
I have a function "returning" hardware parameters I need to process further "upstream" -
including "main".
I can pass a vector <string> by reference or have been told to define "local vector" and "return" if from the function.
I am not sure how "return vector" really works and have not tried it yet.
The function returning "vector <string> " syntax is scary...
Could I return pointer to locally defined vector ?
( Or is is even feasible ?)
Is there a specific resource I could read ?
Something similar to this example , but with "return * vector - string "?
<pre>
#include<bits/stdc++.h>
using namespace std;
void func(vector<int> &vect)
{
vect.push_back(30);
}
int main()
{
vector<int> vect;
vect.push_back(10);
vect.push_back(20);
func(vect);
for (int i=0; i<vect.size(); i++)
cout << vect[i] << " ";
return 0;
}
|
|
|
|
|
Your code looks good to me.
If you want func to return a vector, it should allocate it on the heap, and returning it in a unique_ptr would be better than just returning a raw pointer. But it looks like you want to update a vector that might already have entries, so passing it by reference makes sense.
EDIT: func isn't a function template; it simply takes a vector argument. The term function template refers to a function defined by template <typename T> func ...
modified 12-Jan-21 18:30pm.
|
|
|
|
|
You function is OK as it stands.
Quote: can pass a vector <string> by reference or have been told to define "local vector" and "return" if from the function.
That is fine whenever you have code similar to
vector <int> get_rand_vect(size_t size)
{
vector <int> v;
while (size--)
{
v.push_back(rand());
}
return v; }
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
That would not work in my function which retrieves unknown "size" of (string) data.
As I said, I want to learn about vector , but more I look into it the more I like "old fashioned way " to pass a pointer to the function and let the calling code process the pointer afterwards. Seems much simpler.
|
|
|
|
|
Vectors are quite simple, but very powerful. But the usage will depend on what you are actually trying to do. In your example your func method does nothing useful, so it is not clear what actual problem you are trying to solve.
|
|
|
|
|
Quote: That would not work in my function which retrieves unknown "size" of (string) data. That's not a problem.
It would work as well. Try, for instance
#include <iostream>
#include <vector>
using namespace std;
vector <int> get_a_fresh_vector_with_unknown_size()
{
vector <int> v;
int N = rand() % 128;
for (int n = 0; n < N; ++n)
v.push_back( rand() );
return v;
}
int main()
{
auto v = get_a_fresh_vector_with_unknown_size();
for (auto x : v)
cout << x << " ";
cout << endl;
}
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Hi Guys,
I have an app which does not use latest common control library. This app have Combo box which is in old style (like 3d style) but now we need to modernize the combo control like Flat (new window 10 style) without using latest common control library.
Can anybody help?
|
|
|
|
|
That is a contradiction in terms. You cannot have the modern style and still use the old library. However, it may be possible if you implement the OwnerDraw property.
|
|
|
|
|
There are many examples of CMFCRibbonComboBox that display simple text. I am actually looking for a CMFCRibbonComboBox example that display image or something like graphic, or say is ownerdraw.
Unless I mistake, I think CMFCRibbonComboBox class and inherited classes have ownerdraw capabilities since in afxribboncombobox.cpp there is a Draw and OnDrawLabelAndImage and others functions with CDC arguments.
Unfortunately, without step by step example, it is very difficult to implement such a class.
Any links or suggestions are welcomed
Pierre
|
|
|
|
|
There are plenty of examples of using OwnerDraw on controls. Adding it to this class will be no different.
|
|
|
|
|
|
|
These are derived from CComboBox, not from CMFCRibbonComboBox.
We are in a C++ MFC thread
|
|
|
|
|
But the main principle of the owner drawing is still the same! You implement it in both edit (or static) box and in the listbox.
|
|
|
|
|
|
Sorry for the cryptic nature of this question just trying to condense as much as I can.
I am trying to write a program in "C" which has a twist on the normal echo command in XPSP3
XP echo does not allow you to remove EOL characters when you redirect into text file with the >
I think they call it CRLF. However in my wanderings I have come across some "C" code that I think could compile a useful program. Here is some background info to illustrate:
The program that I hope to use would be called ECO.COM would be commandline for usage in CMD
ECO would be furnished with a flag (-X) that would give the user the choice to include the CRLF removal or would just be used just like echo command in XP without the -X flag. The ECO.COM file would be restricted to one line (80 Chars) long so the following could take place. The user could type for example
ECO.COM -X SET VARIABLE= (the ECO.COM would have with the -X flag to strip out the end CRLF so once the
SET VARIABLE= line was ridected to text file could easily be appended (>>) with a second ECO command or text file all on the same line. The resultant Text file could then be renamed to a .CMD file & called from another batch file thus setting the given %Variable%
I think they call it backticks or command substitution or some call it back quotes anyway here is the code which I have sought & tried to compile to create ECO.COM/EXE but it is not working can someone assist to make it work Please I think it would be very useful alternative to SET/P option in XPCMD?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 'x':
printf("flag a was called\n");
break;
}
}
}
int echo()
{
char input[80];
while(fgets(input, 80, STDIN)){
printf("%s\n", input);
memset(input, 0, strlen(input));
return 1;
}
if (*char == -x) {
goto remit;
else
if (*char == " ") {
goto exit;
}
Best Regards
JacknGill 
modified 12-Jan-21 15:57pm.
|
|
|
|
|
jackngill wrote: ...tried to compile to create ECO.COM/EXE but it is not working... What exactly does that mean?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi David,
Many thanks for responding to my posting & yes I should of explained with more clarity in respect of my failure. This will be my first program written in "C" I usually write small batch programs in XP and/or sometimes in Win9x. I have found that CMD (although) is very good sometimes I could do with some assistance programs to ease XP's CMD. So I am trying to write small helper programs in "C" to facilitate this, just some background info which may or may not be relevant.
I have been to an online site which compiles my code as a check & a series of errors are reported which lead me to believe my code has errors & is not right I will display the output below from "https://www.onlinegdb.com/online_c_compiler"
The Compilation failed due to following error(s).
main.c:7:1: error: expected identifier or ‘(’ before ‘for’
for (i = 1; i < argc; i++) {
^~~
main.c:7:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
for (i = 1; i < argc; i++) {
^
main.c:7:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘++’ token
for (i = 1; i < argc; i++) {
^~
main.c: In function ‘echo’:
main.c:29:28: error: ‘STDIN’ undeclared (first use in this function)
while(fgets(input, 80, STDIN)){
^~~~~
main.c:29:28: note: each undeclared identifier is reported only once for each function it appears in
main.c: At top level:
main.c:38:7: error: expected identifier or ‘(’ before ‘if’
if (*char == -x) {
^~
main.c:42:7: error: expected identifier or ‘(’ before ‘else’
else
^~~~
main.c:47:14: error: unterminated comment
I am unclear as to what these errors messages mean really. Hope this gives you a rough idea as to where my failure is. I am concerned also about the structure of my potential program as I am not sure if it is right? any guidance would be appreciated? Also just as a tag-on due to the fact I am writing very small programs could you advise as to a small .com .EXE builder that I could use Please?
Best Regards
modified 12-Jan-21 4:38am.
|
|
|
|
|
You cannot have lines of code outside of functions in that way. Line 7 is a for statement but it cannot exist stand-alone like that, it needs to be part of some function. If you look below at function main, you can see the correct structure. I suggest you get hold of a copy of The C Programming Language - Wikipedia[^] and learn from the beginning.
|
|
|
|
|
Hi Richard,
Reading between the lines I think you are saying my code is way off base & is fundamentally wrong. would the following correct the For section like so I have removed the int main() as I am assuming only one int main() is required. your advice is duly noted in respect of ground up code writing many thanks?
int main()
{
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 'x':
printf("flag a was called\n");
break;
}
}
}
|
|
|
|
|
Yes, all code must be contained in a function. you can put it all in main for a simple program, but for more complex problems you should create other functions that can be called with different parameter values. The documentation explains it clearly.
|
|
|
|
|
Thanks Richard,
I have edited/amended my first post to reflect what you have said. Yes small programs are a good place to start
many thanks!
|
|
|
|
|
You have another function inside main, which is also wrong:
int echo(){
char input[80];
Each function must stand alone in the main part of the source file:
int echo()
{
}
int main()
{
}
And get rid of those goto statements, that is really bad practice in modern programming. As I suggested above, get a copy of K & R and spend time learning the language properly. Trying to learn by questions here will take ten times as long, and not be comprehensive.
|
|
|
|