Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SSMCore / src / QueryProcessor / CQLParser.h
1 /******************************************************************
2 *
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
4 *
5 *
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************/
20 #ifndef _CQLParser_H_
21 #define _CQLParser_H_
22
23 #include "SSMInterface/SSMCore.h"
24 #include "Common/PlatformLayer.h"
25 #include "EvaluationEngine.h"
26
27 #define TYPETEXT 0
28 #define TYPEINTEGER 1
29 #define TYPEREAL 2
30 #define INDEX_ALL 9999
31 #define INDEX_THIS -2
32
33 enum SORT {Command, Context, Property, And_or, Condi, Value};
34
35 class Token
36 {
37     public:
38         Token();
39
40         enum SORT type;
41         enum ModelCondition::Predicate condition;
42         std::string name;
43         int number;
44         std::vector<Token> child_token;
45         ModelProperty model_property;
46 };
47
48 /**
49 * @class    CCQLParser
50 * @brief    CQLParser Interface
51 *            This class parses ContextQuery Language.
52 *
53 * @see
54 *           string contextQuery;
55 *           CQLParser tokenizer;
56 *           tokenizer.Parser(contextQuery, &token);
57 *
58 * Copyright 2013 by Samsung Electronics, Inc.,
59 *
60 * This software is the confidential and proprietary information
61 * of Samsung Electronics, Inc. ("Confidential Information").  You
62 * shall not disclose such Confidential Information and shall use
63 * it only in accordance with the terms of the license agreement
64 * you entered into with Samsung.
65 */
66 class CCQLParser
67 {
68
69     public:
70         /**
71         * @fn parse
72         * @brief parse ContextQuery
73         *
74         * @param [in] std::string input - Entered ContetxQuery
75         * @param [out] Token* root - parsed result
76         * @return bool
77         * @warning
78         * @exception
79         * @see
80         */
81         bool parse(std::string input, Token *root);
82
83         /**
84         * @fn tolower
85         * @brief convert lowercase
86         *
87         * @param [in] std::string str - Entered string
88         * @return std::string
89         * @warning
90         * @exception
91         * @see
92         */
93         static std::string tolower(std::string str);
94
95         /**
96         * @fn check_Query_grammer
97         * @brief check grammer
98         *
99         * @param [in] Token* token - parsed token
100         * @return boolean
101         * @warning
102         * @exception
103         * @see
104         */
105         bool check_grammer(Token *token);
106
107     private:
108         /**
109         * @fn tokenize
110         * @brief split sentence
111         *
112         * @param [in] const std::string& input - Entered ContetxQuery
113         * @return std::vector<std::string>
114         * @warning
115         * @exception
116         * @see
117         */
118         std::vector<std::string> tokenize(const std::string &input);
119
120         /**
121         * @fn getTokens
122         * @brief this function divides string into tokens based on a delimiter
123         *
124         * @param [in] const std::string& str - entered string
125         * @param [in] const std::string& delimiters = " " - token delimiter , default = " "
126         * @return std::vector<std::string>
127         * @warning
128         * @exception
129         * @see
130         */
131         static std::vector<std::string> getTokens(const std::string &str,
132                 const std::string &delimiters = " ");
133
134         /**
135         * @fn check_index
136         * @brief this function checks the index.
137         *
138         * @param [in] const std::string input - entered string
139         * @param [out] Token* token - if index exists, The index has been entered into the token.
140         * @return none
141         * @warning
142         * @exception
143         * @see
144         */
145         void check_index(std::string input, Token *token);
146
147         /**
148         * @fn split
149         * @brief this function splits the token to the smaller elements.
150         *
151         * @param [in] std::string input - entered string
152         * @param [in] Token* root - root token
153         * @param [in] bool flag - flag to distinguish token
154         * @param [in] std::string arg1 - next token, default = ""
155         * @param [in] std::string arg2 - next two token, default = ""
156         * @return bool
157         * @warning
158         * @exception
159         * @see
160         */
161         bool split(std::string input, Token *root, bool flag, std::string arg1 = "",
162                    std::string arg2 = "");
163
164         /**
165         * @fn check_number
166         * @brief this function distinguishes string type
167         *
168         * @param [in] std::string & str - entered string
169         * @return int
170         * @warning
171         * @exception
172         * @see
173         */
174         int check_number(std::string &str);
175
176         /**
177         * @fn check_Predicate
178         * @brief this function checks predicate
179         *
180         * @param [in] std::string input - entered string
181         * @return std::string
182         * @warning
183         * @exception
184         * @see
185         */
186         std::string check_Predicate(std::string input);
187 };
188
189 #endif /*_CQLParser_H_*/