Tuple::toGVariant() consumes the input
[platform/core/context/context-common.git] / include / Tuple.h
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You hay obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __CONTEXT_TUPLE_H__
18 #define __CONTEXT_TUPLE_H__
19
20 #include <vector>
21 #include <string>
22 #include <ContextTypes.h>
23
24 namespace ctx {
25
26         class EXPORT_API Tuple {
27         public:
28                 ~Tuple();
29
30                 bool getAt(unsigned int idx, int64_t* val);
31                 bool getAt(unsigned int idx, double* val);
32                 bool getAt(unsigned int idx, std::string* val);
33
34                 static Tuple* duplicate(Tuple& tuple);
35
36                 static GVariant* toGVariant(Tuple* tuple);
37                 static GVariant* toGVariant(std::vector<Tuple*>& tuples);
38
39                 static std::vector<Tuple*> buildFrom(GVariant* gVar);
40
41         private:
42                 Tuple(GVariant* gVar);
43
44                 bool __parse();
45                 bool __verify(unsigned int idx, const GVariantType* type);
46
47                 GVariant* __gVar;
48                 GVariant** __elements;
49                 gsize __numElements;
50
51         public:
52                 class Builder {
53                 public:
54                         Builder();
55                         ~Builder();
56
57                         Builder& add(int64_t val);
58                         Builder& add(double val);
59                         Builder& add(const std::string& val);
60
61                         Tuple* build();
62
63                 private:
64                         bool __init();
65
66                         GVariantBuilder* __gvBuilder;
67                 };
68         };
69
70 }
71
72 #endif