Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Paul J. Lucas
Approved revision: 10972
Merged at revision: 10993
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 254 lines (+111/-24)
5 files modified
include/zorba/internal/unique_ptr.h (+4/-5)
include/zorba/internal/ztd.h (+50/-0)
src/util/stl_util.h (+31/-5)
src/zorbaserialization/serialize_zorba_types.cpp (+2/-2)
src/zorbatypes/integer.h (+24/-12)
To merge this branch: bzr merge lp:~paul-lucas/zorba/pjl-misc
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+119730@code.launchpad.net

Commit message

Miscellaneous changes, some a prerequisite for LLVM that should be done anyway and not have to wait for the far-in-the-future LLVM branch merge.

Description of the change

Miscellaneous changes, some a prerequisite for LLVM that should be done anyway and not have to wait for the far-in-the-future LLVM branch merge.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
lp:~paul-lucas/zorba/pjl-misc updated
10972. By Paul J. Lucas

Merge from trunk.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job pjl-misc-2012-08-21T00-19-58.093Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/zorba/internal/unique_ptr.h'
2--- include/zorba/internal/unique_ptr.h 2012-08-16 18:31:02 +0000
3+++ include/zorba/internal/unique_ptr.h 2012-08-20 23:56:27 +0000
4@@ -26,6 +26,7 @@
5
6 #include <algorithm> /* for swap() */
7 #include "type_traits.h"
8+#include "ztd.h"
9
10 namespace std {
11
12@@ -205,9 +206,7 @@
13 typedef typename ZORBA_TR1_NS::add_reference<D const>::type
14 deleter_const_reference;
15
16- // see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2333.html
17- struct pointer_conversion { int valid; };
18- typedef int pointer_conversion::*explicit_bool;
19+ typedef zorba::internal::ztd::explicit_bool explicit_bool;
20
21 public:
22 typedef T element_type;
23@@ -408,8 +407,8 @@
24 * @return Returns \c true only if the pointer is not null; \c false only if
25 * the pointer is null.
26 */
27- operator explicit_bool() const throw() {
28- return get() ? &pointer_conversion::valid : 0;
29+ operator explicit_bool::type() const throw() {
30+ return explicit_bool::value_of( get() );
31 }
32
33 private:
34
35=== modified file 'include/zorba/internal/ztd.h'
36--- include/zorba/internal/ztd.h 2012-08-16 18:31:02 +0000
37+++ include/zorba/internal/ztd.h 2012-08-20 23:56:27 +0000
38@@ -370,6 +370,56 @@
39 return s ? s : "<null>";
40 }
41
42+////////// misc ///////////////////////////////////////////////////////////////
43+
44+/**
45+ * Helper class for implementing a solution to the "explicit bool conversion"
46+ * problem. The canonical use is of the form:
47+ * \code
48+ * class your_class {
49+ * // ...
50+ * operator explicit_bool::type() const {
51+ * return explicit_bool::value_of( some_expression );
52+ * }
53+ * };
54+ * \endcode
55+ *
56+ * See: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2333.html
57+ */
58+class explicit_bool {
59+ struct pointer_conversion { int valid; };
60+public:
61+ typedef int pointer_conversion::*type;
62+
63+ /**
64+ * Gets the explicit \c bool value for \c false.
65+ *
66+ * @return Returns said value.
67+ */
68+ static type false_value() {
69+ return 0;
70+ }
71+
72+ /**
73+ * Gets the explicit \c bool value for \c true.
74+ *
75+ * @return Returns said value.
76+ */
77+ static type true_value() {
78+ return &pointer_conversion::valid;
79+ }
80+
81+ /**
82+ * Converts the the built-in \c bool value to an explicit \c bool value.
83+ *
84+ * @param value The \c bool value to convert.
85+ * @return Return said value.
86+ */
87+ static type value_of( bool value ) {
88+ return value ? true_value() : false_value();
89+ }
90+};
91+
92 ///////////////////////////////////////////////////////////////////////////////
93
94 } // namespace ztd
95
96=== modified file 'src/util/stl_util.h'
97--- src/util/stl_util.h 2012-08-16 18:31:02 +0000
98+++ src/util/stl_util.h 2012-08-20 23:56:27 +0000
99@@ -155,11 +155,13 @@
100 ///////////////////////////////////////////////////////////////////////////////
101
102 /**
103- * A less-verbose way to determine whether the given set<T> contains a
104+ * A less-verbose way to determine whether the given map or set contains a
105 * particular element.
106 */
107-template<typename T> inline
108-bool contains( std::set<T> const &s, typename call_traits<T>::arg_type v ) {
109+template<class ContainerType> inline
110+bool contains(
111+ ContainerType const &s,
112+ typename call_traits<typename ContainerType::key_type>::arg_type v ) {
113 return s.find( v ) != s.end();
114 }
115
116@@ -200,8 +202,32 @@
117 }
118
119 /**
120- * Erases the first element in the given sequence for which the given predicate
121- * is \c true.
122+ * Erases all elements in the given container for which the given predicate is
123+ * \c true.
124+ *
125+ * @tparam SequenceType The sequence type.
126+ * @tparam PredicateType The predicate type.
127+ * @param seq The sequence to modify.
128+ * @param pred The predicate to use.
129+ * @return Returns the number of elements erased.
130+ */
131+template<class SequenceType,class PredicateType> inline
132+typename SequenceType::size_type erase_if( SequenceType &seq,
133+ PredicateType pred ) {
134+ typename SequenceType::size_type erased = 0;
135+ for ( typename SequenceType::iterator i = seq.begin(); i != seq.end(); ) {
136+ if ( pred( *i ) ) {
137+ i = seq.erase( i );
138+ ++erased;
139+ } else
140+ ++i;
141+ }
142+ return erased;
143+}
144+
145+/**
146+ * Erases only the first element in the given sequence for which the given
147+ * predicate is \c true.
148 *
149 * @tparam SequenceType The sequence type.
150 * @tparam PredicateType The predicate type.
151
152=== modified file 'src/zorbaserialization/serialize_zorba_types.cpp'
153--- src/zorbaserialization/serialize_zorba_types.cpp 2012-08-16 18:31:02 +0000
154+++ src/zorbaserialization/serialize_zorba_types.cpp 2012-08-20 23:56:27 +0000
155@@ -92,12 +92,12 @@
156
157 void operator&(serialization::Archiver& ar, IntegerImpl<long long>& obj)
158 {
159- ar & obj.get_value();
160+ ar & obj.value();
161 }
162
163 void operator&(serialization::Archiver& ar, IntegerImpl<unsigned long long>& obj)
164 {
165- ar & obj.get_value();
166+ ar & obj.value();
167 }
168
169 #endif
170
171=== modified file 'src/zorbatypes/integer.h'
172--- src/zorbatypes/integer.h 2012-08-16 18:31:02 +0000
173+++ src/zorbatypes/integer.h 2012-08-20 23:56:27 +0000
174@@ -32,11 +32,13 @@
175 #include "zstring.h"
176
177 #ifdef ZORBA_WITH_BIG_INTEGER
178-# define TEMPLATE_DECL(I) /* nothing */
179-# define INTEGER_IMPL(I) IntegerImpl
180+# define TEMPLATE_DECL(I) /* nothing */
181+# define INTEGER_IMPL(I) IntegerImpl
182+# define TEMPLATE_TYPENAME /* nothing */
183 #else
184-# define TEMPLATE_DECL(I) template<typename I> /* spacer */
185-# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */
186+# define TEMPLATE_DECL(I) template<typename I> /* spacer */
187+# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */
188+# define TEMPLATE_TYPENAME typename
189 #endif /* ZORBA_WITH_BIG_INTEGER */
190 #define INTEGER_IMPL_LL INTEGER_IMPL(long long)
191 #define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
192@@ -58,6 +60,11 @@
193 class IntegerImpl
194 {
195 public:
196+#ifdef ZORBA_WITH_BIG_INTEGER
197+ typedef MAPM value_type;
198+#else
199+ typedef IntType value_type;
200+#endif /* ZORBA_WITH_BIG_INTEGER */
201
202 ////////// constructors /////////////////////////////////////////////////////
203
204@@ -114,12 +121,6 @@
205 TEMPLATE_DECL(IntType2)
206 IntegerImpl( INTEGER_IMPL(IntType2) const &i );
207
208- /////////////////////////////////////////////////////////////////////////////
209-
210- #ifndef ZORBA_WITH_BIG_INTEGER
211- IntType& get_value() { return value_; }
212- #endif
213-
214 ////////// assignment operators /////////////////////////////////////////////
215
216 /**
217@@ -458,6 +459,8 @@
218 bool is_xs_unsignedShort() const;
219 int sign() const;
220 zstring toString() const;
221+ value_type& value();
222+ value_type const& value() const;
223 static IntegerImpl const& one();
224 static IntegerImpl const& zero();
225
226@@ -465,10 +468,8 @@
227
228 private:
229 #ifdef ZORBA_WITH_BIG_INTEGER
230- typedef MAPM value_type;
231 typedef long int_cast_type;
232 #else
233- typedef IntType value_type;
234 typedef IntType int_cast_type;
235 #endif /* ZORBA_WITH_BIG_INTEGER */
236
237@@ -1121,6 +1122,17 @@
238
239 #endif /* ZORBA_WITH_BIG_INTEGER */
240
241+TEMPLATE_DECL(I) inline
242+TEMPLATE_TYPENAME INTEGER_IMPL(I)::value_type& INTEGER_IMPL(I)::value() {
243+ return value_;
244+}
245+
246+TEMPLATE_DECL(I) inline
247+TEMPLATE_TYPENAME INTEGER_IMPL(I)::value_type const&
248+INTEGER_IMPL(I)::value() const {
249+ return value_;
250+}
251+
252 TEMPLATE_DECL(I)
253 inline std::ostream& operator<<( std::ostream &os, INTEGER_IMPL(I) const &i ) {
254 return os << i.toString();

Subscribers

People subscribed via source and target branches