Merge "add missing packages requires" into tizen
[profile/ivi/ico-uxf-homescreen.git] / lib / misc / state-machine / CicoBlockParser.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 #ifndef CICOBLOCKPARSER_H
19 #define CICOBLOCKPARSER_H
20 #include <iostream>
21 #include <sstream>
22 #include <string>
23 #include <vector>
24 #include "picojson.h"
25
26 /**
27  * Part head string define
28  */
29 #define D_PTF1      "\"stateMachine\""
30 #define D_PTS1      "\"state\""
31 #define D_PTS2      "\"finalState\""
32 #define D_PTS3      "\"historyState\""
33 #define D_PTS4      "\"event\""
34
35
36 /**
37  * Perform a block classification defined string.
38  * perform a json parse
39  * @author m.kamoshida
40  * @version 0.1
41  */
42
43 /**
44  * @brief The CicoBlockParser class
45  */
46 class CicoBlockParser{
47 public:
48     enum E_PARTSKIND{
49         UNKNOWN = 0,                    // unknown
50         STTMAC = 1,                     // state machine
51         STT,                            // state
52         HSTT,                           // history state
53         FSTT,                           // final state
54         EV                              // event
55     };
56                 CicoBlockParser();
57     virtual     ~CicoBlockParser();
58
59
60     bool        getStateMachineParts(const char* tmpstr);
61     const std::string& getError();
62     int         spaceLess(char* d, const char* s) const;
63     void*       getVoid() const;
64     void        setVoid(void* v);
65     bool        jsonParse(const char* objectname);
66     bool        isJsonParse() const;
67     void        getErrorHead(std::string& errhead, const char* strtop);
68 public:
69     E_PARTSKIND m_kind;
70     std::string m_parts;
71     std::vector<CicoBlockParser*> m_childs;
72     picojson::value m_v;
73
74 protected:
75     const char* getBrackets(char* tmpstr, const char* tmpend);
76
77 private:
78     static std::string m_err;
79     void*       m_void;
80     char*       m_jsonTmp;
81 };
82
83 /**
84  * @brief get error message
85  * @return error message
86  */
87 inline const std::string& CicoBlockParser::getError()
88 {
89     return m_err;
90 }
91
92 /**
93  * @brief get void pointer
94  * @return void pointer
95  */
96 inline void* CicoBlockParser::getVoid() const
97 {
98     return m_void;
99 }
100
101 /**
102  * @brief set void pointer
103  * @param v register void pointer
104  */
105 inline void CicoBlockParser::setVoid(void* v)
106 {
107     m_void = v;
108 }
109
110 /**
111  * @brief json parse condhition
112  * @return treu:parse / false:not parse
113  */
114 inline bool CicoBlockParser::isJsonParse() const
115 {
116     if ((char*)0 != m_jsonTmp) {
117         return true;
118     }
119     return false;
120 }
121
122 #endif // CICOBLOCKPARSER_H