AuboCaps  0.6.0
class_forward.h
Go to the documentation of this file.
1 #ifndef AUBO_SCOPE_CLASS_FORWARD_H
2 #define AUBO_SCOPE_CLASS_FORWARD_H
3 
4 #include <memory>
5 
6 #if defined(ARCS_ABI_EXPORT)
7 #elif defined(ARCS_PLATFORM_WINDOWS)
8 #define ARCS_ABI_EXPORT __declspec(dllexport)
9 #define ARCS_ABI_IMPORT __declspec(dllimport)
10 #define ARCS_ABI_LOCAL
11 #elif defined(ARCS_HAVE_VISIBILITY_ATTRIBUTE)
12 #define ARCS_ABI_EXPORT __attribute__((visibility("default")))
13 #define ARCS_ABI_IMPORT __attribute__((visibility("default")))
14 #define ARCS_ABI_LOCAL __attribute__((visibility("hidden")))
15 #else
16 #define ARCS_ABI_EXPORT
17 #define ARCS_ABI_IMPORT
18 #define ARCS_ABI_LOCAL
19 #endif
20 
21 /**
22  * @def ARCS_DELCARE_PTR
23  * Macro that given a Name and a Type declares the following types:
24  * - ${Name}Ptr = shared_ptr<${Type}>
25  * - ${Name}ConstPtr = shared_ptr<const ${Type}>
26  * - ${Name}WeakPtr = weak_ptr<${Type}>
27  * - ${Name}ConstWeakPtr = weak_ptr<const ${Type}>
28  * - ${Name}UniquePtr = unique_ptr<${Type}>
29  * - ${Name}ConstUniquePtr = unique_ptr<const ${Type}>
30  *
31  * For best portability the exact type of shared_ptr declared by the macro
32  * should be considered to be an implementation detail, liable to change in
33  * future releases.
34  */
35 
36 #define ARCS_DECLARE_PTR(Name, Type) \
37  typedef std::shared_ptr<Type> Name##Ptr; \
38  typedef std::shared_ptr<const Type> Name##ConstPtr; \
39  typedef std::weak_ptr<Type> Name##WeakPtr; \
40  typedef std::weak_ptr<const Type> Name##ConstWeakPtr; \
41  typedef std::unique_ptr<Type> Name##UniquePtr; \
42  typedef std::unique_ptr<const Type> Name##ConstUniquePtr
43 
44 /**
45  * @def ARCS_DELCARE_PTR_MEMBER
46  * The macro defines the same typedefs as ARCS_DECLARE_PTR, but shortens the
47  * new names to their suffix.
48  *
49  * This can be used to create `Classname::Ptr` style names, but in most
50  * situations in ARCS's codebase, ARCS_CLASS_FORWARD and ARCS_DECLARE_PTR
51  * should be preferred.
52  */
53 
54 #define ARCS_DECLARE_PTR_MEMBER(Type) \
55  typedef std::shared_ptr<Type> Ptr; \
56  typedef std::shared_ptr<const Type> ConstPtr; \
57  typedef std::weak_ptr<Type> WeakPtr; \
58  typedef std::weak_ptr<const Type> ConstWeakPtr; \
59  typedef std::unique_ptr<Type> UniquePtr; \
60  typedef std::unique_ptr<const Type> ConstUniquePtr
61 
62 /**
63  * @def ARCS_CLASS_FORWARD
64  * Macro that forward declares a class and defines the respective smartpointers
65  * through ARCS_DECLARE_PTR.
66  */
67 
68 #define ARCS_CLASS_FORWARD(C) \
69  class C; \
70  ARCS_DECLARE_PTR(C, C)
71 
72 /**
73  * @def ARCS_STRUCT_FORWARD
74  * Like ARCS_CLASS_FORWARD, but forward declares the type as a struct
75  * instead of a class.
76  */
77 #define ARCS_STRUCT_FORWARD(C) \
78  struct C; \
79  ARCS_DECLARE_PTR(C, C)
80 
81 #endif