anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | [%- State = TemplateInputVar %] |
| 2 | [%- USE String %] |
| 3 | [%- MACRO CLASSNAME(str) BLOCK %] |
| 4 | [%- className = String.new %] |
| 5 | [%- strList = String.new(str).lower.split("_") %] |
| 6 | [%- FOREACH str = strList %] |
| 7 | [%- token = className.append(String.new(str).capital.text()) %] |
| 8 | [%- END %] |
| 9 | [%- className %] |
| 10 | [%- END %] |
| 11 | [%- MACRO FILENAME(str) BLOCK %] |
| 12 | [%- fileName = String.new %] |
| 13 | [%- str = CLASSNAME(str) %] |
| 14 | [%- fileName = fileName.append(str.substr(0,1)).lower %] |
| 15 | [%- fileName = fileName.append(str.substr(1)) %] |
| 16 | [%- fileName %] |
| 17 | [%- END %] |
| 18 | [%- stateClassName = CLASSNAME(State.Name) %] |
| 19 | /* |
| 20 | * Copyright 2019-present Infosys Limited |
| 21 | * |
| 22 | * SPDX-License-Identifier: Apache-2.0 |
| 23 | */ |
| 24 | |
| 25 | /************************************** |
| 26 | * [% FILENAME(State.Name) %].cpp |
| 27 | * This is an auto generated file. |
| 28 | * Please do not edit this file. |
| 29 | * All edits to be made through template source file |
| 30 | * <TOP-DIR/scripts/SMCodeGen/templates/stateMachineTmpls/state.cpp.tt> |
| 31 | **************************************/ |
| 32 | |
| 33 | #include "smEnumTypes.h" |
| 34 | #include "actionTable.h" |
| 35 | #include "actionHandlers/actionHandlers.h" |
| 36 | |
| 37 | #include "mmeStates/[% FILENAME(State.Name) %].h" |
| 38 | [%- FOREACH Event = State.Events %] |
| 39 | [%- IF Event.NextState != "end_state" %] |
| 40 | #include "mmeStates/[% FILENAME(Event.NextState) %].h" |
| 41 | [%- END %] |
| 42 | [%- END %] |
| 43 | |
| 44 | using namespace mme; |
| 45 | using namespace SM; |
| 46 | |
| 47 | /****************************************************************************** |
| 48 | * Constructor |
| 49 | ******************************************************************************/ |
| 50 | [% stateClassName %]::[% stateClassName %]():State(State_e::[% State.Name %]) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | /****************************************************************************** |
| 55 | * Destructor |
| 56 | ******************************************************************************/ |
| 57 | [% stateClassName %]::~[% stateClassName %]() |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | /****************************************************************************** |
| 62 | * creates and returns static instance |
| 63 | ******************************************************************************/ |
| 64 | [% stateClassName %]* [% stateClassName %]::Instance() |
| 65 | { |
| 66 | static [% stateClassName %] state; |
| 67 | return &state; |
| 68 | } |
| 69 | |
| 70 | /****************************************************************************** |
| 71 | * initializes eventToActionsMap |
| 72 | ******************************************************************************/ |
| 73 | void [% stateClassName %]::initialize() |
| 74 | { |
| 75 | [%- FOREACH Event = State.Events %] |
| 76 | { |
| 77 | ActionTable actionTable; |
| 78 | [%- FOREACH Action = Event.Actions %] |
| 79 | actionTable.addAction(&ActionHandlers::[% String.new(Action).lower %]); |
| 80 | [%- END %] |
| 81 | [%- IF Event.NextState != "end_state" %] |
| 82 | actionTable.setNextState([% CLASSNAME(Event.NextState) %]::Instance()); |
| 83 | [%- END %] |
| 84 | eventToActionsMap.insert(pair<Event_e, ActionTable>(Event_e::[% Event.Name %], actionTable)); |
| 85 | } |
| 86 | [%- END %] |
| 87 | } |