Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cargo-gvariant.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Pawel Kubik (p.kubik@samsung.com)
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 
26 #ifndef CARGO_GVARIANT_CARGO_GVARIANT_HPP
27 #define CARGO_GVARIANT_CARGO_GVARIANT_HPP
28 
31 
32 namespace cargo {
33 
42 template <class Cargo>
43 void loadFromGVariant(GVariant* gvariant, Cargo& visitable)
44 {
45  static_assert(isVisitable<Cargo>::value, "Use CARGO_REGISTER macro");
46  static_assert(!isUnion<Cargo>::value, "Don't use CARGO_DECLARE_UNION in top level visitable");
47 
48  FromGVariantVisitor visitor(gvariant);
49  visitable.accept(visitor);
50 }
51 
57 template <class Cargo>
58 GVariant* saveToGVariant(const Cargo& visitable)
59 {
60  static_assert(isVisitable<Cargo>::value, "Use CARGO_REGISTER macro");
61  static_assert(!isUnion<Cargo>::value, "Don't use CARGO_DECLARE_UNION in top level visitable");
62 
63  ToGVariantVisitor visitor;
64  visitable.accept(visitor);
65  return visitor.toVariant();
66 }
67 
68 } // namespace cargo
69 
72 #endif // CARGO_GVARIANT_CARGO_GVARIANT_HPP
Definition: is-union.hpp:60
Definition: to-gvariant-visitor.hpp:43
void loadFromGVariant(GVariant *gvariant, Cargo &visitable)
Fills the cargo structure with data stored in the GVariant.
Definition: cargo-gvariant.hpp:43
Definition: from-gvariant-visitor.hpp:47
GVariant * saveToGVariant(const Cargo &visitable)
Saves the visitable in a GVariant.
Definition: cargo-gvariant.hpp:58
Helper for compile-time checking against existance of template method 'accept'.
Definition: is-visitable.hpp:49
GVariant visitor.
GVariant visitor.
GVariant * toVariant()
Definition: to-gvariant-visitor.hpp:65