📄 smcheadergenerator.java
字号:
} _source.println(");"); if (Smc.isDebug() == true) { _source.print(_indent); _source.println( " setTransition(NULL);"); } _source.print(_indent); _source.println(" };"); } } // v. 2.2.0: If we are supporting serialization, then // declare the valueOf static method. if (Smc.isSerial() == true) { _source.println(); _source.print(_indent); _source.print(" static "); _source.print(context); _source.println("State& valueOf(int stateId);"); } // Member data. _source.println(); _source.print(_indent); _source.println("private:"); _source.println(); _source.print(_indent); _source.print(" "); _source.print(context); _source.println("& _owner;"); // v. 2.2.0: If we are supporting serialization, then // declare the min and max indices. if (Smc.isSerial() == true) { _source.println(); _source.print(_indent); _source.println("private:"); _source.println(); _source.print(_indent); _source.println(" const static int MIN_INDEX;"); _source.print(_indent); _source.println(" const static int MAX_INDEX;"); _source.print(_indent); _source.print(" static "); _source.print(context); _source.println("State* _States[];"); } // Put the closing brace on the context class. _source.print(_indent); _source.println("};"); // If necessary, place an end brace for the namespace. if (packageName != null && packageName.length() > 0) { int i; int j; for (i = (packageDepth - 1); i >= 0; --i) { // Output the proper indent. for (j = 0; j < i; ++j) { _source.print(" "); } _source.println("}"); _source.println(); } } else { _source.println(); } _source.print("#endif // _H_"); _source.print(srcfileCaps); _source.println("_SM"); return; } // end of visit(SmcFSM) // Generate the map class declaration and then the state // classes: // // class <map name> // { // public: // // static <map name>_<state name> <state name>; // }; public void visit(SmcMap map) { String context = map.getFSM().getContext(); String mapName = map.getName(); String stateName; // Forward declare the map. _source.print(_indent); _source.print("class "); _source.println(mapName); _source.print(_indent); _source.println("{"); _source.print(_indent); _source.println("public:"); _source.println(); // Iterate over the map's states and declare the static, // singleton state instances for (SmcState state: map.getStates()) { stateName = state.getClassName(); _source.print(_indent); _source.print(" static "); _source.print(mapName); _source.print("_"); _source.print(stateName); _source.print(" "); _source.print(stateName); _source.println(";"); } // The map class is now defined. _source.print(_indent); _source.println("};"); _source.println(); // Declare the map's default state class. // // class <map name>_Default : // public <context>State // { // public: // // <map name>_Default(const char *name, int stateId) // : <context>State(name, stateId) // {}; // // (user-defined Default state transitions.) // }; _source.print(_indent); _source.print("class "); _source.print(mapName); _source.println("_Default :"); _source.print(_indent); _source.print(" public "); _source.print(context); _source.println("State"); _source.print(_indent); _source.println("{"); _source.print(_indent); _source.println("public:"); _source.println(); // Default state's constructor. _source.print(_indent); _source.print(" "); _source.print(mapName); _source.println( "_Default(const char *name, int stateId)"); _source.print(_indent); _source.print(" : "); _source.print(context); _source.println("State(name, stateId)"); _source.print(_indent); _source.println(" {};"); _source.println(); // Declare the user-defined default transitions first. if (map.hasDefaultState() == true) { SmcState defaultState = map.getDefaultState(); for (SmcTransition transition: defaultState.getTransitions()) { transition.accept(this); } } // The map's default state class is now defined. _source.print(_indent); _source.println("};"); _source.println(); // Now output the state class declarations. for (SmcState state: map.getStates()) { state.accept(this); } return; } // end of visit(SmcMap) // Generate the state's class declaration. // // class <map name>_<state name> : // public <map name>_Default // { // public: // // <map name>_<state name>(const char *name, int stateId) // : <map name>_Default(name, stateId) // {}; // // (declare the transition methods.) // void <transition name>(<context>& context, <args>); // }; public void visit(SmcState state) { SmcMap map = state.getMap(); String context = map.getFSM().getContext(); String mapName = map.getName(); String stateName = state.getClassName(); List<SmcAction> actions; _source.print(_indent); _source.print("class "); _source.print(mapName); _source.print('_'); _source.print(stateName); _source.println(" :"); _source.print(_indent); _source.print(" public "); _source.print(mapName); _source.println("_Default"); _source.print(_indent); _source.println("{"); _source.print(_indent); _source.print("public:"); _source.println(); _source.print(_indent); _source.print(" "); _source.print(mapName); _source.print('_'); _source.print(stateName); _source.println("(const char *name, int stateId)"); _source.print(_indent); _source.print(" : "); _source.print(mapName); _source.println("_Default(name, stateId)"); _source.print(_indent); _source.println(" {};"); _source.println(); // Add the Entry() and Exit() methods if this state // defines them. actions = state.getEntryActions(); if (actions != null && actions.size() > 0) { _source.print(_indent); _source.print(" void Entry("); _source.print(context); _source.println("Context&);"); } actions = state.getExitActions(); if (actions != null && actions.size() > 0) { _source.print(_indent); _source.print(" void Exit("); _source.print(context); _source.println("Context&);"); } // Now generate the transition methods. for (SmcTransition transition: state.getTransitions()) { transition.accept(this); } // End of the state class declaration. _source.print(_indent); _source.println("};"); _source.println(); return; } // end of visit(SmcState) // Generate the transition method declaration. // // void <transition name>(<context>Context& context, <args>); public void visit(SmcTransition transition) { SmcState state = transition.getState(); String stateName = state.getClassName(); String virtual = ""; // If this transition is in the default state, then // precede the method with "virtual". if (stateName.equals("Default") == true) { virtual = "virtual "; } _source.print(_indent); _source.print(" "); _source.print(virtual); _source.print("void "); _source.print(transition.getName()); _source.print("("); _source.print( state.getMap().getFSM().getContext()); _source.print("Context& context"); // Add user-defined parameters. for (SmcParameter param: transition.getParameters()) { _source.print(", "); param.accept(this); } // End of transition method declaration. _source.println(");"); return; } // end of visit(SmcTransition) public void visit(SmcParameter parameter) { _source.print(parameter.getType()); _source.print(" "); _source.print(parameter.getName()); return; } // end of visit(SmcParameter)//---------------------------------------------------------------// Member data//} // end of class SmcHeaderGenerator//// CHANGE LOG// $Log: SmcHeaderGenerator.java,v $// Revision 1.9 2008/03/21 14:03:16 fperrad// refactor : move from the main file Smc.java to each language generator the following data :// - the default file name suffix,// - the file name format for the generated SMC files//// Revision 1.8 2007/02/21 13:55:20 cwrapp// Moved Java code to release 1.5.0//// Revision 1.7 2007/01/15 00:23:51 cwrapp// Release 4.4.0 initial commit.//// Revision 1.6 2006/09/16 15:04:29 cwrapp// Initial v. 4.3.3 check-in.//// Revision 1.5 2006/07/11 18:14:38 cwrapp// Changed method getCastType() to castType().//// Revision 1.4 2005/11/07 19:34:54 cwrapp// Changes in release 4.3.0:// New features://// + Added -reflect option for Java, C#, VB.Net and Tcl code// generation. When used, allows applications to query a state// about its supported transitions. Returns a list of transition// names. This feature is useful to GUI developers who want to// enable/disable features based on the current state. See// Programmer's Manual section 11: On Reflection for more// information.//// + Updated LICENSE.txt with a missing final paragraph which allows// MPL 1.1 covered code to work with the GNU GPL.//// + Added a Maven plug-in and an ant task to a new tools directory.// Added Eiten Suez's SMC tutorial (in PDF) to a new docs// directory.//// Fixed the following bugs://// + (GraphViz) DOT file generation did not properly escape// double quotes appearing in transition guards. This has been// corrected.//// + A note: the SMC FAQ incorrectly stated that C/C++ generated// code is thread safe. This is wrong. C/C++ generated is// certainly *not* thread safe. Multi-threaded C/C++ applications// are required to synchronize access to the FSM to allow for// correct performance.//// + (Java) The generated getState() method is now public.//// Revision 1.3 2005/06/18 18:28:42 cwrapp// SMC v. 4.0.1//// New Features://// (No new features.)//// Bug Fixes://// + (C++) When the .sm is in a subdirectory the forward- or// backslashes in the file name are kept in the "#ifndef" in the// generated header file. This is syntactically wrong. SMC now// replaces the slashes with underscores.//// + (Java) If %package is specified in the .sm file, then the// generated *Context.java class will have package-level access.//// + The Programmer's Manual had incorrect HTML which prevented the// pages from rendering correctly on Internet Explorer.//// + Rewrote the Programmer's Manual section 1 to make it more// useful.//// Revision 1.2 2005/06/08 11:09:15 cwrapp// + Updated Python code generator to place "pass" in methods with empty// bodies.// + Corrected FSM errors in Python example 7.// + Removed unnecessary includes from C++ examples.// + Corrected errors in top-level makefile's distribution build.//// Revision 1.1 2005/05/28 19:28:42 cwrapp// Moved to visitor pattern.//// Revision 1.1 2005/02/21 15:35:32 charlesr// Added Francois Perrad to Contributors section for Python work.//// Revision 1.0 2005/02/03 17:11:12 charlesr// Initial revision//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -