d11671ff885f041dc4b162528ae32198956891b5
[profile/ivi/ico-uxf-homescreen.git] / lib / misc / state-machine / CicoHistoryState.h
1 /*
2  * Copyright (c) 2013 TOYOTA MOTOR CORPORATION.
3  *
4  * Contact: 
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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. 
17  */
18
19 #ifndef CICOHISTORYSTATE_H
20 #define CICOHISTORYSTATE_H
21
22 #include <iostream>
23 #include <string>
24 #include <vector>
25 #include "CicoStateCore.h"
26
27 #ifndef CICOSTATE_H
28 class CicoState;
29 #endif
30
31 #ifndef CICOSTATEMACHINE_H
32 class CicoStateMachine;
33 #endif
34
35 /**
36  * history state object class
37  * @author m.kamoshida
38  * @version 0.1
39  */
40
41 /**
42  * @brief The CicoHistoryState class
43  */
44 class  CicoHistoryState : public CicoStateCore
45 {
46 public:
47     // history type
48     enum E_HType {
49         Shallow = 1,                    // Shallow History
50         Deep                            // Deep History
51     };
52     // constructor
53                 CicoHistoryState(CicoState* parent=0);
54                 CicoHistoryState(const std::string& name, CicoState* parent=0);
55                 CicoHistoryState(int value, CicoState* parent=0);
56                 CicoHistoryState(const std::string& name, int value,
57                                  CicoState* parent=0);
58                 CicoHistoryState(CicoStateMachine* parent);
59                 CicoHistoryState(const std::string& name,
60                                  CicoStateMachine* parent);
61                 CicoHistoryState(int value, CicoStateMachine* parent);
62                 CicoHistoryState(const std::string& name, int value,
63                                  CicoStateMachine* parent);
64
65     // destructor
66                 ~CicoHistoryState();
67
68     void        addDefaultState(std::vector<CicoState*> stts);
69     void        addDefaultState(CicoState* stt);
70
71     E_HType     getHistoryType() const;
72     void        setHistoryType(E_HType type);
73
74     void        setParent(CicoState* parent);
75     void        setParent(CicoStateMachine* parent);
76
77     void        addEntryAction(CicoStateAction* action, int addval = 0);
78
79     void        addExitAction(CicoStateAction* action, int addval = 0);
80
81 protected:
82     virtual bool start(const CicoEvent& ev, bool parent=false);
83
84     virtual void holdHistory();
85
86 private:
87     E_HType     m_historyType;          // history type
88     std::vector<CicoState*> m_vDState;  // store default area
89     std::vector<CicoState*> m_vHState;  // store history area
90 };
91
92 /**
93  * @brief CicoHistoryState::getHistoryType
94  * @return history type(Shallow or Deep)
95  */
96 inline CicoHistoryState::E_HType CicoHistoryState::getHistoryType() const
97 {
98     return m_historyType;
99 }
100
101 /**
102  * @brief CicoHistoryState::setHistoryType
103  * @      set history type
104  * @param type history type(Shallow or Deep)
105  */
106 inline void CicoHistoryState::setHistoryType(E_HType type)
107 {
108     m_historyType = type;
109 }
110
111 /**
112  * @brief CicoHistoryState::addEntryAction
113  * @param action register callback action class
114  * @param addval additional value
115  */
116 inline void CicoHistoryState::addEntryAction(CicoStateAction* action, int addval)
117 {
118     CicoStateCore::addEntryAction(action, addval);
119 }
120
121 /**
122  * @brief CicoHistoryState::addExitAction
123  * @param action register callback action class
124  * @param addval additional value
125  */
126 inline void CicoHistoryState::addExitAction(CicoStateAction* action, int addval)
127 {
128     CicoStateCore::addExitAction(action, addval);
129 }
130
131 #endif // CICOHISTORYSTATE_H