Commit d62aefc2 by amir

first working version with smart pointers

parent 18669a33
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/seh.iml" filepath="$PROJECT_DIR$/.idea/seh.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/defs/enums.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/defs/constants.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/defs/seh_types.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/defs/seh_types.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/defs/retstat.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/JsonCallFlowBuilder.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/seh_engine.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/JsonCallFlowBuilder.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/XMLCallFlowBuilder.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/seh_engine.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/XMLCallFlowBuilder.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/test_seh.cpp" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="Header Search Paths">
<CLASSES>
<root url="file:///usr/include" />
<root url="file:///usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed" />
<root url="file:///usr/lib/gcc/x86_64-linux-gnu/4.9/include" />
<root url="file:///usr/local/include" />
<root url="file://$MODULE_DIR$/../3party/rapidjson-0.11/include/rapidjson" />
</CLASSES>
<SOURCES>
<root url="file:///usr/include" />
<root url="file:///usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed" />
<root url="file:///usr/lib/gcc/x86_64-linux-gnu/4.9/include" />
<root url="file:///usr/local/include" />
<root url="file://$MODULE_DIR$/../3party/rapidjson-0.11/include/rapidjson" />
</SOURCES>
</library>
</orderEntry>
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
...@@ -12,7 +12,7 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData, ...@@ -12,7 +12,7 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData,
{ {
int iNumOfActions = eventData.getNumOfActions(); int iNumOfActions = eventData.getNumOfActions();
for (EventAction* p_eventAction : eventData.actions) for (shared_ptr<EventAction> & p_eventAction : eventData.actions)
{ {
/* /*
* activating the action * activating the action
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <bits/unique_ptr.h>
#include <list> #include <list>
#include <memory>
#include "constants.h" #include "constants.h"
#include "retstat.h" #include "retstat.h"
...@@ -182,6 +182,8 @@ struct EventAction ...@@ -182,6 +182,8 @@ struct EventAction
actionType = eActionType_Regular; actionType = eActionType_Regular;
} }
virtual ~EventAction() = default;
void Reset() void Reset()
{ {
name.clear(); name.clear();
...@@ -287,9 +289,7 @@ struct NextState ...@@ -287,9 +289,7 @@ struct NextState
*/ */
struct EventData struct EventData
{ {
// vector < tEventAction*> ta_Actions; list<shared_ptr<EventAction>> actions;
// test - amir
list<EventAction*> actions;
NextState nextState; NextState nextState;
string eventName; string eventName;
...@@ -316,7 +316,7 @@ struct EventData ...@@ -316,7 +316,7 @@ struct EventData
{ {
SEH_METHOD_LOG("copy"); SEH_METHOD_LOG("copy");
if (!eventData.actions.empty()) if (!eventData.actions.empty())
this->actions = eventData.actions; this->actions = move(eventData.actions);
this->nextState = eventData.nextState; this->nextState = eventData.nextState;
this->eventName.assign(eventData.eventName); this->eventName.assign(eventData.eventName);
return *this; return *this;
...@@ -331,9 +331,10 @@ struct EventData ...@@ -331,9 +331,10 @@ struct EventData
// this->eventName = move(eventData.eventName); // this->eventName = move(eventData.eventName);
// return *this; // return *this;
// } // }
void AddAction(EventAction* p_action) void AddAction(shared_ptr<EventAction>& ptr)
{ {
actions.push_back(p_action); //auto ptr = make_shared<EventAction>(*p_action);
actions.push_back(ptr);
} }
const NextState& GetNextState() const { const NextState& GetNextState() const {
...@@ -471,14 +472,14 @@ struct State ...@@ -471,14 +472,14 @@ struct State
struct CallFlow struct CallFlow
{ {
int flowIndex = 0; int flowIndex = 0;
vector<State*> stateArray; vector<shared_ptr<State>> stateArray;
int iNumOfStates; int iNumOfStates;
string flowFileName; string flowFileName;
IBaseSEH* p_baseSEHObject; IBaseSEH* p_baseSEHObject;
virtual ~CallFlow() { virtual ~CallFlow() {
for(State* p_state: stateArray) // for(State* p_state: stateArray)
delete(p_state); // delete(p_state);
Reset(); Reset();
} }
...@@ -498,6 +499,10 @@ struct CallFlow ...@@ -498,6 +499,10 @@ struct CallFlow
return flowFileName; return flowFileName;
} }
void AddState(shared_ptr<State>& p_state)
{
stateArray.push_back(p_state);
}
const char* GetFlowFileName() const char* GetFlowFileName()
{ {
return flowFileName.c_str(); return flowFileName.c_str();
...@@ -506,7 +511,7 @@ struct CallFlow ...@@ -506,7 +511,7 @@ struct CallFlow
CallFlow& operator = (const CallFlow& callFlow){ CallFlow& operator = (const CallFlow& callFlow){
SEH_METHOD_LOG("copy"); SEH_METHOD_LOG("copy");
flowIndex = callFlow.flowIndex; flowIndex = callFlow.flowIndex;
stateArray = callFlow.stateArray; stateArray = move(callFlow.stateArray);
flowFileName = callFlow.flowFileName; flowFileName = callFlow.flowFileName;
iNumOfStates = callFlow.iNumOfStates; iNumOfStates = callFlow.iNumOfStates;
p_baseSEHObject = callFlow.p_baseSEHObject; p_baseSEHObject = callFlow.p_baseSEHObject;
......
...@@ -111,7 +111,7 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt ...@@ -111,7 +111,7 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt
{ {
Document* p_currentStateNode = (Document*)itr; //stateNode; Document* p_currentStateNode = (Document*)itr; //stateNode;
//State state; //State state;
p_state = new State(); //&state;//p_callFlow_->stateArray[iCurrentState]; shared_ptr<State> p_state = make_shared<State>();//new State(); //&state;//p_callFlow_->stateArray[iCurrentState];
//p_currentStateNode = stateNode; //p_currentStateNode = stateNode;
/* /*
* Getting the <Name> tag - first child * Getting the <Name> tag - first child
...@@ -137,7 +137,7 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt ...@@ -137,7 +137,7 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt
/********************* /*********************
* pushing the state * pushing the state
*******************/ *******************/
p_callFlow_->stateArray.push_back(p_state); p_callFlow_->AddState(p_state);
} }
} }
else else
...@@ -147,7 +147,7 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt ...@@ -147,7 +147,7 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt
return retStat; return retStat;
} }
RetStat JsonCallFlowBuilder::GetState(Document &stateNode, State *p_State) { RetStat JsonCallFlowBuilder::GetState(Document &stateNode, shared_ptr<State> p_State) {
RetStat retStat; RetStat retStat;
/*************************** /***************************
* Getting the State Events * Getting the State Events
...@@ -263,7 +263,7 @@ RetStat JsonCallFlowBuilder::GetEventActions(Document &eventActionsNode) { ...@@ -263,7 +263,7 @@ RetStat JsonCallFlowBuilder::GetEventActions(Document &eventActionsNode) {
for (auto actionNodePtr = eventActionsNode.Begin(); actionNodePtr != eventActionsNode.End(); ++actionNodePtr) for (auto actionNodePtr = eventActionsNode.Begin(); actionNodePtr != eventActionsNode.End(); ++actionNodePtr)
{ {
Document& actionNode = *(Document*)actionNodePtr; Document& actionNode = *(Document*)actionNodePtr;
EventAction* p_eventAction = nullptr; shared_ptr<EventAction> p_eventAction;
/******************************* /*******************************
* Resolving the action * Resolving the action
*******************************/ *******************************/
...@@ -298,7 +298,7 @@ RetStat JsonCallFlowBuilder::GetEventActions(Document &eventActionsNode) { ...@@ -298,7 +298,7 @@ RetStat JsonCallFlowBuilder::GetEventActions(Document &eventActionsNode) {
* @param actionNode * @param actionNode
* @return * @return
*/ */
RetStat JsonCallFlowBuilder::GetAction(Document &actionNode, EventAction **pp_eventAction) { RetStat JsonCallFlowBuilder::GetAction(Document &actionNode, shared_ptr<EventAction> *pp_eventAction) {
RetStat retStat; RetStat retStat;
/* /*
...@@ -313,33 +313,33 @@ RetStat JsonCallFlowBuilder::GetAction(Document &actionNode, EventAction **pp_ev ...@@ -313,33 +313,33 @@ RetStat JsonCallFlowBuilder::GetAction(Document &actionNode, EventAction **pp_ev
switch (eventActonType) { switch (eventActonType) {
case eActionType_Regular: case eActionType_Regular:
// Handle action // Handle action
*pp_eventAction = new EventAction(); *pp_eventAction = make_shared<EventAction>();//new EventAction();
(*pp_eventAction)->Reset(); (*pp_eventAction)->Reset();
retStat = ResolveSimpleAction(*pp_eventAction, actionNode ); retStat = ResolveSimpleAction((*pp_eventAction).get(), actionNode );
break; break;
case eActionType_If: case eActionType_If:
*pp_eventAction = new EventIfAction(); *pp_eventAction = make_shared<EventIfAction>();//new EventIfAction();
(*pp_eventAction)->Reset(); (*pp_eventAction)->Reset();
/******************************* /*******************************
* Getting the condition action * Getting the condition action
********************************/ ********************************/
retStat = HandleEventIfAction((EventIfAction*) *pp_eventAction,actionNode ); retStat = HandleEventIfAction((EventIfAction*) (*pp_eventAction).get(),actionNode );
break; break;
case eActionType_Switch: case eActionType_Switch:
*pp_eventAction = new EventSwitchAction(); *pp_eventAction = make_shared<EventSwitchAction>(); //new EventSwitchAction();
(*pp_eventAction)->Reset(); (*pp_eventAction)->Reset();
/******************************* /*******************************
* Getting the condition action * Getting the condition action
********************************/ ********************************/
retStat = HandleEventSwitchAction((EventSwitchAction*) *pp_eventAction, actionNode); retStat = HandleEventSwitchAction((EventSwitchAction*) (*pp_eventAction).get(), actionNode);
break; break;
case eActionType_While: case eActionType_While:
*pp_eventAction = new EventWhileAction(); *pp_eventAction = make_shared<EventWhileAction>();//new EventWhileAction();
(*pp_eventAction)->Reset(); (*pp_eventAction)->Reset();
/******************************* /*******************************
* Getting the condition action * Getting the condition action
********************************/ ********************************/
retStat = HandleEventWhileAction((EventWhileAction*) *pp_eventAction, actionNode); retStat = HandleEventWhileAction((EventWhileAction*) (*pp_eventAction).get(), actionNode);
break; break;
default: default:
break; break;
...@@ -712,9 +712,9 @@ RetStat JsonCallFlowBuilder::GetEventData(EventData &eventData, Document &eventN ...@@ -712,9 +712,9 @@ RetStat JsonCallFlowBuilder::GetEventData(EventData &eventData, Document &eventN
/******************************* /*******************************
* Resolving the action * Resolving the action
*******************************/ *******************************/
EventAction* p_eventAction = new EventAction(); shared_ptr<EventAction> p_eventAction = make_shared<EventAction>();//new EventAction();
p_eventAction->Reset(); p_eventAction->Reset();
retStat = ResolveSimpleAction(p_eventAction, (Document&)*actionNodeIterator); retStat = ResolveSimpleAction(p_eventAction.get(), (Document&)*actionNodeIterator);
if (retStat.Fail()) if (retStat.Fail())
{ {
//p_eventAction = nullptr; //p_eventAction = nullptr;
......
...@@ -29,13 +29,13 @@ public: ...@@ -29,13 +29,13 @@ public:
RetStat CreateCallFlow(string &basic_string, int iCurrentState); RetStat CreateCallFlow(string &basic_string, int iCurrentState);
RetStat GetState(Document &stateNode, State *p_State); RetStat GetState(Document &stateNode, shared_ptr<State> p_State);
RetStat GetEvent(Document &eventNode); RetStat GetEvent(Document &eventNode);
RetStat GetEventActions(Document &eventActionsNode); RetStat GetEventActions(Document &eventActionsNode);
RetStat GetAction(Document &actionNode, EventAction **pp_eventAction); RetStat GetAction(Document &actionNode, shared_ptr<EventAction> *pp_eventAction);
RetStat ResolveSimpleAction(EventAction *p_eventAction, Document &actionNode); RetStat ResolveSimpleAction(EventAction *p_eventAction, Document &actionNode);
......
...@@ -149,7 +149,7 @@ RetStat SehEngine::ResolveNextStateIndex(NextState& nextState) { ...@@ -149,7 +149,7 @@ RetStat SehEngine::ResolveNextStateIndex(NextState& nextState) {
if (p_callFlow->iNumOfStates > 0 && !p_callFlow->stateArray.empty()) if (p_callFlow->iNumOfStates > 0 && !p_callFlow->stateArray.empty())
{ {
int iStateIndex = 0; int iStateIndex = 0;
for (State* p_state : p_callFlow->stateArray) for (auto&& p_state : p_callFlow->stateArray)
{ {
if (p_state->stateName.compare(nextState.stateName) == 0) if (p_state->stateName.compare(nextState.stateName) == 0)
{ {
...@@ -180,7 +180,7 @@ RetStat SehEngine::ResolveNextStateIndexes() { ...@@ -180,7 +180,7 @@ RetStat SehEngine::ResolveNextStateIndexes() {
/***************************** /*****************************
* going over the flow states * going over the flow states
*****************************/ *****************************/
for (State* p_state : p_callFlow->stateArray) for (auto&& p_state : p_callFlow->stateArray)
{ {
/************************** /**************************
* Scanning the map events * Scanning the map events
...@@ -196,9 +196,9 @@ RetStat SehEngine::ResolveNextStateIndexes() { ...@@ -196,9 +196,9 @@ RetStat SehEngine::ResolveNextStateIndexes() {
/******************************************** /********************************************
* Resolve complex actions next state if any * Resolve complex actions next state if any
*******************************************/ *******************************************/
for (EventAction* p_action : p_eventData->actions) for (shared_ptr<EventAction> & p_action : p_eventData->actions)
{ {
retStat = ResolveComplexActionNextState(p_action); retStat = ResolveComplexActionNextState(p_action.get());
if (retStat.Fail()) if (retStat.Fail())
return retStat; return retStat;
} }
...@@ -331,9 +331,9 @@ RetStat SehEngine::ActivateActions(StateIndex& nextStateIndex) { ...@@ -331,9 +331,9 @@ RetStat SehEngine::ActivateActions(StateIndex& nextStateIndex) {
this->activateActionData_.p_nextStateIndex = &nextStateIndex; this->activateActionData_.p_nextStateIndex = &nextStateIndex;
this->activateActionData_.boolWasStateChanged = false; this->activateActionData_.boolWasStateChanged = false;
for (EventAction* p_eventAction : this->p_eventData_->actions) for (shared_ptr<EventAction> & p_eventAction : this->p_eventData_->actions)
{ {
this->p_eventAction_ = p_eventAction; this->p_eventAction_ = p_eventAction.get();
/************************************************************ /************************************************************
* activating the action. checking if the last action failed, if so * activating the action. checking if the last action failed, if so
* then activating only mandatory actions * then activating only mandatory actions
...@@ -502,7 +502,7 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) { ...@@ -502,7 +502,7 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) {
* Getting the EventData from State/Event/Party * Getting the EventData from State/Event/Party
* and setting the BaseSEH object * and setting the BaseSEH object
***********************************************/ ***********************************************/
this->p_state_ = p_callFlow->stateArray[this->p_stateIndex_->uiStateIndex]; this->p_state_ = p_callFlow->stateArray[this->p_stateIndex_->uiStateIndex].get();
p_eventData_ = (EventData*)GetFromMap(this->p_state_->eventsMap,eventStr); p_eventData_ = (EventData*)GetFromMap(this->p_state_->eventsMap,eventStr);
this->p_baseSEHObject_ = p_callFlow->p_baseSEHObject; this->p_baseSEHObject_ = p_callFlow->p_baseSEHObject;
//this->activateActionData_.object = p_callFlow->baseSEHObject;; //this->activateActionData_.object = p_callFlow->baseSEHObject;;
...@@ -519,7 +519,7 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) { ...@@ -519,7 +519,7 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) {
&& (this->p_state_->baseState.IsValid())) && (this->p_state_->baseState.IsValid()))
{ {
this->p_stateIndex_ = &this->p_state_->baseState.stateIndex; this->p_stateIndex_ = &this->p_state_->baseState.stateIndex;
this->p_state_ = p_callFlow->stateArray[this->p_stateIndex_->uiStateIndex]; this->p_state_ = p_callFlow->stateArray[this->p_stateIndex_->uiStateIndex].get();
this->p_eventData_ = (EventData *) GetFromMap(this->p_state_->eventsMap, eventStr); // eventCellsArray[iEvent]; this->p_eventData_ = (EventData *) GetFromMap(this->p_state_->eventsMap, eventStr); // eventCellsArray[iEvent];
} }
...@@ -582,7 +582,7 @@ RetStat SehEngine::GetStateIndex(StateIndex &stateIndex, string &stateName) { ...@@ -582,7 +582,7 @@ RetStat SehEngine::GetStateIndex(StateIndex &stateIndex, string &stateName) {
/************************** /**************************
* finding the state * finding the state
*************************/ *************************/
for (State* p_state : callFlowEntry.second->stateArray) for (auto&& p_state : callFlowEntry.second->stateArray)
{ {
if (p_state->stateName.compare(stateName) == 0) if (p_state->stateName.compare(stateName) == 0)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment