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,
{
int iNumOfActions = eventData.getNumOfActions();
for (EventAction* p_eventAction : eventData.actions)
for (shared_ptr<EventAction> & p_eventAction : eventData.actions)
{
/*
* activating the action
......
......@@ -9,8 +9,8 @@
#include <vector>
#include <iostream>
#include <map>
#include <bits/unique_ptr.h>
#include <list>
#include <memory>
#include "constants.h"
#include "retstat.h"
......@@ -182,6 +182,8 @@ struct EventAction
actionType = eActionType_Regular;
}
virtual ~EventAction() = default;
void Reset()
{
name.clear();
......@@ -287,9 +289,7 @@ struct NextState
*/
struct EventData
{
// vector < tEventAction*> ta_Actions;
// test - amir
list<EventAction*> actions;
list<shared_ptr<EventAction>> actions;
NextState nextState;
string eventName;
......@@ -316,7 +316,7 @@ struct EventData
{
SEH_METHOD_LOG("copy");
if (!eventData.actions.empty())
this->actions = eventData.actions;
this->actions = move(eventData.actions);
this->nextState = eventData.nextState;
this->eventName.assign(eventData.eventName);
return *this;
......@@ -331,9 +331,10 @@ struct EventData
// this->eventName = move(eventData.eventName);
// 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 {
......@@ -471,14 +472,14 @@ struct State
struct CallFlow
{
int flowIndex = 0;
vector<State*> stateArray;
vector<shared_ptr<State>> stateArray;
int iNumOfStates;
string flowFileName;
IBaseSEH* p_baseSEHObject;
virtual ~CallFlow() {
for(State* p_state: stateArray)
delete(p_state);
// for(State* p_state: stateArray)
// delete(p_state);
Reset();
}
......@@ -498,6 +499,10 @@ struct CallFlow
return flowFileName;
}
void AddState(shared_ptr<State>& p_state)
{
stateArray.push_back(p_state);
}
const char* GetFlowFileName()
{
return flowFileName.c_str();
......@@ -506,7 +511,7 @@ struct CallFlow
CallFlow& operator = (const CallFlow& callFlow){
SEH_METHOD_LOG("copy");
flowIndex = callFlow.flowIndex;
stateArray = callFlow.stateArray;
stateArray = move(callFlow.stateArray);
flowFileName = callFlow.flowFileName;
iNumOfStates = callFlow.iNumOfStates;
p_baseSEHObject = callFlow.p_baseSEHObject;
......
......@@ -111,7 +111,7 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt
{
Document* p_currentStateNode = (Document*)itr; //stateNode;
//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;
/*
* Getting the <Name> tag - first child
......@@ -137,7 +137,7 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt
/*********************
* pushing the state
*******************/
p_callFlow_->stateArray.push_back(p_state);
p_callFlow_->AddState(p_state);
}
}
else
......@@ -147,7 +147,7 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt
return retStat;
}
RetStat JsonCallFlowBuilder::GetState(Document &stateNode, State *p_State) {
RetStat JsonCallFlowBuilder::GetState(Document &stateNode, shared_ptr<State> p_State) {
RetStat retStat;
/***************************
* Getting the State Events
......@@ -263,7 +263,7 @@ RetStat JsonCallFlowBuilder::GetEventActions(Document &eventActionsNode) {
for (auto actionNodePtr = eventActionsNode.Begin(); actionNodePtr != eventActionsNode.End(); ++actionNodePtr)
{
Document& actionNode = *(Document*)actionNodePtr;
EventAction* p_eventAction = nullptr;
shared_ptr<EventAction> p_eventAction;
/*******************************
* Resolving the action
*******************************/
......@@ -298,7 +298,7 @@ RetStat JsonCallFlowBuilder::GetEventActions(Document &eventActionsNode) {
* @param actionNode
* @return
*/
RetStat JsonCallFlowBuilder::GetAction(Document &actionNode, EventAction **pp_eventAction) {
RetStat JsonCallFlowBuilder::GetAction(Document &actionNode, shared_ptr<EventAction> *pp_eventAction) {
RetStat retStat;
/*
......@@ -313,33 +313,33 @@ RetStat JsonCallFlowBuilder::GetAction(Document &actionNode, EventAction **pp_ev
switch (eventActonType) {
case eActionType_Regular:
// Handle action
*pp_eventAction = new EventAction();
*pp_eventAction = make_shared<EventAction>();//new EventAction();
(*pp_eventAction)->Reset();
retStat = ResolveSimpleAction(*pp_eventAction, actionNode );
retStat = ResolveSimpleAction((*pp_eventAction).get(), actionNode );
break;
case eActionType_If:
*pp_eventAction = new EventIfAction();
*pp_eventAction = make_shared<EventIfAction>();//new EventIfAction();
(*pp_eventAction)->Reset();
/*******************************
* Getting the condition action
********************************/
retStat = HandleEventIfAction((EventIfAction*) *pp_eventAction,actionNode );
retStat = HandleEventIfAction((EventIfAction*) (*pp_eventAction).get(),actionNode );
break;
case eActionType_Switch:
*pp_eventAction = new EventSwitchAction();
*pp_eventAction = make_shared<EventSwitchAction>(); //new EventSwitchAction();
(*pp_eventAction)->Reset();
/*******************************
* Getting the condition action
********************************/
retStat = HandleEventSwitchAction((EventSwitchAction*) *pp_eventAction, actionNode);
retStat = HandleEventSwitchAction((EventSwitchAction*) (*pp_eventAction).get(), actionNode);
break;
case eActionType_While:
*pp_eventAction = new EventWhileAction();
*pp_eventAction = make_shared<EventWhileAction>();//new EventWhileAction();
(*pp_eventAction)->Reset();
/*******************************
* Getting the condition action
********************************/
retStat = HandleEventWhileAction((EventWhileAction*) *pp_eventAction, actionNode);
retStat = HandleEventWhileAction((EventWhileAction*) (*pp_eventAction).get(), actionNode);
break;
default:
break;
......@@ -712,9 +712,9 @@ RetStat JsonCallFlowBuilder::GetEventData(EventData &eventData, Document &eventN
/*******************************
* Resolving the action
*******************************/
EventAction* p_eventAction = new EventAction();
shared_ptr<EventAction> p_eventAction = make_shared<EventAction>();//new EventAction();
p_eventAction->Reset();
retStat = ResolveSimpleAction(p_eventAction, (Document&)*actionNodeIterator);
retStat = ResolveSimpleAction(p_eventAction.get(), (Document&)*actionNodeIterator);
if (retStat.Fail())
{
//p_eventAction = nullptr;
......
......@@ -29,13 +29,13 @@ public:
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 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);
......
......@@ -149,7 +149,7 @@ RetStat SehEngine::ResolveNextStateIndex(NextState& nextState) {
if (p_callFlow->iNumOfStates > 0 && !p_callFlow->stateArray.empty())
{
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)
{
......@@ -180,7 +180,7 @@ RetStat SehEngine::ResolveNextStateIndexes() {
/*****************************
* going over the flow states
*****************************/
for (State* p_state : p_callFlow->stateArray)
for (auto&& p_state : p_callFlow->stateArray)
{
/**************************
* Scanning the map events
......@@ -196,9 +196,9 @@ RetStat SehEngine::ResolveNextStateIndexes() {
/********************************************
* 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())
return retStat;
}
......@@ -331,9 +331,9 @@ RetStat SehEngine::ActivateActions(StateIndex& nextStateIndex) {
this->activateActionData_.p_nextStateIndex = &nextStateIndex;
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
* then activating only mandatory actions
......@@ -502,7 +502,7 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) {
* Getting the EventData from State/Event/Party
* 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);
this->p_baseSEHObject_ = p_callFlow->p_baseSEHObject;
//this->activateActionData_.object = p_callFlow->baseSEHObject;;
......@@ -519,7 +519,7 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) {
&& (this->p_state_->baseState.IsValid()))
{
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];
}
......@@ -582,7 +582,7 @@ RetStat SehEngine::GetStateIndex(StateIndex &stateIndex, string &stateName) {
/**************************
* finding the state
*************************/
for (State* p_state : callFlowEntry.second->stateArray)
for (auto&& p_state : callFlowEntry.second->stateArray)
{
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