Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fields.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Piotr Bartosiewicz (p.bartosiewi@partner.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_FIELDS_HPP
27 #define CARGO_FIELDS_HPP
28 
29 #include <boost/preprocessor/variadic/to_list.hpp>
30 #include <boost/preprocessor/list/for_each.hpp>
31 
32 #include "cargo/types.hpp"
33 
34 #if BOOST_PP_VARIADICS != 1
35 #error variadic macros not supported
36 #endif
37 
42 #define CARGO_REGISTER_EMPTY \
43  template<typename Visitor> \
44  static void accept(Visitor ) { \
45  } \
46 
47 
74 #define CARGO_REGISTER(...) \
75  template<typename Visitor> \
76  void accept(Visitor v) { \
77  GENERATE_ELEMENTS__(__VA_ARGS__) \
78  } \
79  template<typename Visitor> \
80  void accept(Visitor v) const { \
81  GENERATE_ELEMENTS__(__VA_ARGS__) \
82  } \
83 
84 
125 #define CARGO_EXTEND(BASE) \
126  typedef BASE ParentVisitor; \
127  __CARGO_EXTEND \
128 
129 #define __CARGO_EXTEND(...) \
130  template<typename Visitor> \
131  void accept(Visitor v) { \
132  GENERATE_ELEMENTS__(__VA_ARGS__) \
133  ParentVisitor::accept(v); \
134  } \
135  template<typename Visitor> \
136  void accept(Visitor v) const { \
137  GENERATE_ELEMENTS__(__VA_ARGS__) \
138  ParentVisitor::accept(v); \
139  } \
140 
141 #define GENERATE_ELEMENTS__(...) \
142  BOOST_PP_LIST_FOR_EACH(GENERATE_ELEMENT__, \
143  _, \
144  BOOST_PP_VARIADIC_TO_LIST(__VA_ARGS__)) \
145 
146 #define GENERATE_ELEMENT__(r, _, element) \
147  v.visit(#element, element); \
148 
149 #endif // CARGO_FIELDS_HPP
Types declarations.