2 * Copyright (c) 2013 TOYOTA MOTOR CORPORATION.
6 * Licensed under the Apache License, Version 2.0 (the License){}
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include "CicoStateCore.h"
23 #include "CicoHistoryState.h"
26 * history state object class
33 * @brief CicoHistoryState::CicoHistoryState
34 * @param parent parent object
36 CicoHistoryState::CicoHistoryState(CicoState* parent):
37 CicoStateCore(EHistoryState, (CicoStateCore*)parent)
42 * @brief CicoHistoryState::CicoHistoryState
43 * @param name Identification name
44 * @param parent parent object
46 CicoHistoryState::CicoHistoryState(const std::string& name, CicoState* parent):
47 CicoStateCore(EHistoryState, name, (CicoStateCore*)parent)
52 * @brief CicoHistoryState::CicoHistoryState
53 * @param value Identification number
54 * @param parent parent object
56 CicoHistoryState::CicoHistoryState(int value, CicoState* parent):
57 CicoStateCore(EHistoryState, value, (CicoStateCore*)parent)
62 * @brief CicoHistoryState::CicoHistoryState
63 * @param name Identification name
64 * @param value Identification number
65 * @param parent parent object
67 CicoHistoryState::CicoHistoryState(const std::string& name, int value,
69 CicoStateCore(EHistoryState, name, value, (CicoStateCore*)parent)
74 * @brief CicoHistoryState::CicoHistoryState
75 * @param parent parent object
77 CicoHistoryState::CicoHistoryState(CicoStateMachine* parent):
78 CicoStateCore(EHistoryState, (CicoStateCore*)parent)
83 * @brief CicoHistoryState::CicoHistoryState
84 * @param name Identification name
85 * @param parent parent object
87 CicoHistoryState::CicoHistoryState(const std::string& name,
88 CicoStateMachine* parent):
89 CicoStateCore(EHistoryState, name, (CicoStateCore*)parent)
94 * @brief CicoHistoryState::CicoHistoryState
95 * @param value Identification number
96 * @param parent parent object
98 CicoHistoryState::CicoHistoryState(int value, CicoStateMachine* parent):
99 CicoStateCore(EHistoryState, value, (CicoStateCore*)parent)
104 * @brief CicoHistoryState::CicoHistoryState
105 * @param name Identification name
106 * @param value Identification number
107 * @param parent parent object
109 CicoHistoryState::CicoHistoryState(const std::string& name, int value,
110 CicoStateMachine* parent):
111 CicoStateCore(EHistoryState, name, value, (CicoStateCore*)parent)
116 * @brief CicoHistoryState::~CicoHistoryState
118 CicoHistoryState::~CicoHistoryState()
125 * @brief CicoHistoryState::addDefaultState
126 * @param stts default state object
128 void CicoHistoryState::addDefaultState(std::vector<CicoState*> stts)
130 int sz = stts.size();
131 for (int i = 0; i < sz; i++) {
132 m_vDState.push_back(stts[i]);
137 * @brief CicoHistoryState::addDefaultState
138 * @param stts default state object
140 void CicoHistoryState::addDefaultState(CicoState* stt)
142 m_vDState.push_back(stt);
146 * @brief CicoHistoryState::holdHistory
148 void CicoHistoryState::holdHistory()
151 if ((CicoStateCore*)0 != m_parent) { // exist is parent
152 // Discard the previous history
154 std::vector<const CicoState*> t;
155 // Stores the new history
156 if (Deep == m_historyType) { // deep history ?
160 bR = getCurrentStateF(m_parent, t, CicoStateCore::ELvlBttm);
166 bR = getCurrentStateF(m_parent, t, CicoStateCore::ELvlTop);
175 for (int i = 0; i < sz; i++) {
176 m_vHState.push_back((CicoState*)t[i]);
188 * @brief CicoHistoryState::start
189 * @param ev trigger event data
192 bool CicoHistoryState::start(const CicoEvent& ev, bool)
198 int szH = m_vHState.size();
199 int szD = m_vDState.size();
201 for (int i = 0; i < szH; i++) {
202 CicoStateCore* t = (CicoStateCore*)m_vHState[i];
203 startF(t, ev, false);
207 for (int i = 0; i < szD; i++) {
208 CicoStateCore* t =(CicoStateCore*)m_vDState[i];
216 startF(m_parent, ev, true);
222 * @brief getCurrentStateF
224 * @param states store active state objects area
225 * @param policy get poicy
226 * @return true:get success false:get fail
228 bool getCurrentStateF(CicoStateCore* stt,
229 std::vector<const CicoState*>& states,
230 CicoStateCore::E_GetPolicy policy)
232 return stt->getCurrentState(states, policy);
236 * @brief CicoHistoryState::setParent
237 * @param parent parent object
239 void CicoHistoryState::setParent(CicoState* parent)
241 CicoStateCore::setParent((CicoStateCore*)parent);
245 * @brief CicoHistoryState::setParent
246 * @param parent parent object
248 void CicoHistoryState::setParent(CicoStateMachine* parent)
250 CicoStateCore::setParent((CicoStateCore*)parent);