Merge lp:~michihenning/unity-api/defines-ptrs into lp:unity-api

Proposed by Michi Henning
Status: Merged
Approved by: Michi Henning
Approved revision: 78
Merged at revision: 78
Proposed branch: lp:~michihenning/unity-api/defines-ptrs
Merge into: lp:unity-api
Diff against target: 148 lines (+39/-47)
3 files modified
include/unity/util/Daemon.h (+5/-1)
include/unity/util/DefinesPtrs.h (+12/-43)
test/gtest/unity/util/DefinesPtrs/DefinesPtrs_test.cpp (+22/-3)
To merge this branch: bzr merge lp:~michihenning/unity-api/defines-ptrs
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Unity Team Pending
Review via email: mp+176307@code.launchpad.net

Commit message

Changed DefinesPtrs to a macro. That way, we don't need a virtual destructor, and the generated typedefs can be used with POD types. The macro also prevents ambiguous names that were caused by the template for classes in a derivation hierarchy.

Description of the change

Changed DefinesPtrs to a macro. That way, we don't need a virtual destructor, and the generated typedefs can be used with POD types. The macro also prevents ambiguous names that were caused by the template for classes in a derivation hierarchy.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michi Henning (michihenning) wrote :

Top-approving this because Jussi and I discussed this change previously. Jussi, when you are back, please raise any issues you see that I've missed!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/unity/util/Daemon.h'
2--- include/unity/util/Daemon.h 2013-06-26 23:47:34 +0000
3+++ include/unity/util/Daemon.h 2013-07-23 00:55:32 +0000
4@@ -63,9 +63,13 @@
5 Note: This class is not async signal-safe. Do not call daemonize_me() from a a signal handler.
6 */
7
8-class UNITY_API Daemon final : public util::DefinesPtrs<Daemon>, private NonCopyable
9+class UNITY_API Daemon final : private NonCopyable
10 {
11 public:
12+ /// @cond
13+ UNITY_DEFINES_PTRS(Daemon);
14+ /// @endcond
15+
16 /**
17 \brief Create a Daemon instance.
18 \return A <code>unique_ptr</code> to the instance.
19
20=== modified file 'include/unity/util/DefinesPtrs.h'
21--- include/unity/util/DefinesPtrs.h 2013-06-26 23:47:34 +0000
22+++ include/unity/util/DefinesPtrs.h 2013-07-23 00:55:32 +0000
23@@ -21,25 +21,21 @@
24
25 #include <memory>
26
27-namespace unity
28-{
29-
30-namespace util
31-{
32-
33 /**
34-\brief Helper template to inject smart pointer definitions into a class.
35+\file DefinesPtrs.h
36+\def UNITY_DEFINES_PTRS(classname)
37+\brief Macro to add smart pointer definitions to a class.
38
39-This template injects type definitions for smart pointer types into a class. It is useful to
40+This macro injects type definitions for smart pointer types into a class. It is useful to
41 establish a common naming convention for smart pointers across a project.
42
43-You can use the template as follows. Note that the template parameter is the name of the class
44-being defined ("curiously recurring template pattern").
45+You can use the macro as follows. Note that the macro argument is the name of the class being defined.
46
47 ~~~
48-* class MyClass : public util::DefinesPtrs<MyClass>
49+* class MyClass
50 * {
51 * public:
52+* UNITY_DEFINES_PTRS(MyClass);
53 * // MyClass now provides public typedefs for SPtr, SCPtr, UPtr, and UCPtr.
54 * // ...
55 * };
56@@ -53,37 +49,10 @@
57
58 */
59
60-template <typename T>
61-class DefinesPtrs
62-{
63-public:
64- /**
65- A <code>std::shared_ptr</code> to a non-constant instance.
66- */
67- typedef std::shared_ptr<T> SPtr;
68-
69- /**
70- A <code>std::shared_ptr</code> to a constant instance.
71- */
72- typedef std::shared_ptr<T const> SCPtr;
73-
74- /**
75- A <code>std::unique_ptr</code> to a non-constant instance.
76- */
77- typedef std::unique_ptr<T> UPtr;
78-
79- /**
80- A <code>std::unique_ptr</code> to a constant instance.
81- */
82- typedef std::unique_ptr<T const> UCPtr;
83-
84-protected: // Not meant to be instantiated stand-alone
85- DefinesPtrs() = default;
86- virtual ~DefinesPtrs() = default;
87-};
88-
89-} // namespace util
90-
91-} // namespace unity
92+#define UNITY_DEFINES_PTRS(classname) \
93+ typedef std::shared_ptr<classname> SPtr; \
94+ typedef std::shared_ptr<classname const> SCPtr; \
95+ typedef std::unique_ptr<classname> UPtr; \
96+ typedef std::unique_ptr<classname const> UCPtr
97
98 #endif
99
100=== modified file 'test/gtest/unity/util/DefinesPtrs/DefinesPtrs_test.cpp'
101--- test/gtest/unity/util/DefinesPtrs/DefinesPtrs_test.cpp 2013-06-26 23:47:34 +0000
102+++ test/gtest/unity/util/DefinesPtrs/DefinesPtrs_test.cpp 2013-07-23 00:55:32 +0000
103@@ -23,23 +23,42 @@
104
105 using namespace unity::util;
106
107-class MyClass : public DefinesPtrs<MyClass>, private NonCopyable
108+class MyClass : private NonCopyable
109 {
110 public:
111+ UNITY_DEFINES_PTRS(MyClass);
112+
113 static SPtr create()
114 {
115 return SPtr(new MyClass);
116 }
117
118-private:
119+protected:
120 MyClass()
121 {
122 }
123 };
124
125+class MyDerivedClass : public MyClass
126+{
127+public:
128+ UNITY_DEFINES_PTRS(MyDerivedClass);
129+
130+ static UPtr create()
131+ {
132+ return UPtr(new MyDerivedClass);
133+ }
134+
135+protected:
136+ MyDerivedClass()
137+ {
138+ }
139+};
140+
141 TEST(DefinesPtrs, basic)
142 {
143- // No real test here. This is just so we get function coverage for the coverage tests.
144+ // No real test here. This is just so we check that things compile.
145
146 MyClass::SPtr p = MyClass::create();
147+ MyDerivedClass::UPtr q = MyDerivedClass::create();
148 }

Subscribers

People subscribed via source and target branches

to all changes: