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

Proposed by Paul J. Lucas
Status: Merged
Approved by: Matthias Brantner
Approved revision: no longer in the source branch.
Merged at revision: 10942
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 254 lines (+79/-23)
2 files modified
src/util/fs_util.cpp (+3/-5)
src/util/fs_util.h (+76/-18)
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+115222@code.launchpad.net

Commit message

Now using enable_if for more functions to make overload resolution work better.

Description of the change

Now using enable_if for more functions to make overload resolution work better.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
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-07-16T23-19-59.948Z is finished. The final status was:

All tests succeeded!

lp:~paul-lucas/zorba/pjl-misc updated
10942. By Paul J. Lucas

Now using enable_if for more functions to make overload resolution work better. Approved: Matthias Brantner, Paul J. Lucas

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/util/fs_util.cpp'
2--- src/util/fs_util.cpp 2012-07-13 14:44:56 +0000
3+++ src/util/fs_util.cpp 2012-07-16 20:35:25 +0000
4@@ -331,13 +331,11 @@
5 #ifndef WIN32
6 if ( (ent_ = ::readdir( dir_ )) ) {
7 switch ( ent_->d_type ) {
8- case DT_DIR: {
9- char const *const name = ent_->d_name;
10- if ( is_dots( name ) )
11+ case DT_DIR:
12+ if ( is_dots( ent_->d_name ) )
13 continue; // skip "." and ".." entries
14 ent_type_ = directory;
15 break;
16- }
17 case DT_LNK:
18 ent_type_ = link;
19 break;
20@@ -353,7 +351,7 @@
21 // This check fixes bug #1023862.
22 //
23 zstring ent_path( dir_path_ );
24- fs::append( ent_path, static_cast<char const*>( ent_->d_name ) );
25+ fs::append( ent_path, ent_->d_name );
26 ent_type_ = get_type( ent_path );
27 if ( ent_type_ == directory && is_dots( ent_->d_name ) )
28 continue; // skip "." and ".." entries
29
30=== modified file 'src/util/fs_util.h'
31--- src/util/fs_util.h 2012-07-12 17:29:55 +0000
32+++ src/util/fs_util.h 2012-07-16 20:35:25 +0000
33@@ -31,6 +31,7 @@
34 #include "ascii_util.h"
35 #include "cxx_util.h"
36 #include "error_util.h"
37+#include "string_util.h"
38 #include "zorbatypes/zstring.h"
39
40 #ifndef MAX_PATH
41@@ -78,6 +79,13 @@
42 };
43 extern char const *const type_string[];
44
45+/**
46+ * Emits the string representation of a file type to the given ostream.
47+ *
48+ * @param o The ostream to emit to.
49+ * @param t The file type to emit.
50+ * @return Returns \a o.
51+ */
52 inline std::ostream& operator<<( std::ostream &o, type t ) {
53 return o << type_string[ t ];
54 }
55@@ -115,7 +123,10 @@
56 * @param path The full path of the directory to change to.
57 */
58 template<class PathStringType> inline
59-void chdir( PathStringType const &path ) {
60+typename std::enable_if<ztd::has_c_str<PathStringType,
61+ char const* (PathStringType::*)() const>::value,
62+ void>::type
63+chdir( PathStringType const &path ) {
64 chdir( path.c_str() );
65 }
66
67@@ -147,7 +158,10 @@
68 * @throws fs::exception if the creation fails.
69 */
70 template<class PathStringType> inline
71-void mkdir( PathStringType const &path ) {
72+typename std::enable_if<ztd::has_c_str<PathStringType,
73+ char const* (PathStringType::*)() const>::value,
74+ void>::type
75+mkdir( PathStringType const &path ) {
76 mkdir( path.c_str() );
77 }
78
79@@ -257,7 +271,10 @@
80 * @throws fs::exception if the creation failed.
81 */
82 template<class PathStringType> inline
83-void create( PathStringType const &path ) {
84+typename std::enable_if<ztd::has_c_str<PathStringType,
85+ char const* (PathStringType::*)() const>::value,
86+ void>::type
87+create( PathStringType const &path ) {
88 create( path.c_str() );
89 }
90
91@@ -283,7 +300,10 @@
92 * @return Returns \c true only if the file or directory was removed.
93 */
94 template<class PathStringType> inline
95-bool remove( PathStringType const &path ) {
96+typename std::enable_if<ztd::has_c_str<PathStringType,
97+ char const* (PathStringType::*)() const>::value,
98+ bool>::type
99+remove( PathStringType const &path ) {
100 return remove( path.c_str() );
101 }
102
103@@ -467,7 +487,10 @@
104 * @return Returns said type.
105 */
106 template<class PathStringType> inline
107-type get_type( PathStringType const &path, size_type *size = nullptr ) {
108+typename std::enable_if<ztd::has_c_str<PathStringType,
109+ char const* (PathStringType::*)() const>::value,
110+ type>::type
111+get_type( PathStringType const &path, size_type *size = nullptr ) {
112 return get_type( path.c_str(), size );
113 }
114
115@@ -499,7 +522,10 @@
116 * @return Returns \c true only if the path is absolute.
117 */
118 template<class PathStringType> inline
119-bool is_absolute( PathStringType const &path ) {
120+typename std::enable_if<ztd::has_c_str<PathStringType,
121+ char const* (PathStringType::*)() const>::value,
122+ bool>::type
123+is_absolute( PathStringType const &path ) {
124 return is_absolute( path.c_str() );
125 }
126
127@@ -525,7 +551,10 @@
128 * @throws fs::exception if the rename fails.
129 */
130 template<class FromStringType> inline
131-void rename( FromStringType const &from, char const *to ) {
132+typename std::enable_if<ztd::has_c_str<FromStringType,
133+ char const* (FromStringType::*)() const>::value,
134+ void>::type
135+rename( FromStringType const &from, char const *to ) {
136 rename( from.c_str(), to );
137 }
138
139@@ -538,7 +567,10 @@
140 * @throws fs::exception if the rename fails.
141 */
142 template<class ToStringType> inline
143-void rename( char const *from, ToStringType const &to ) {
144+typename std::enable_if<ztd::has_c_str<ToStringType,
145+ char const* (ToStringType::*)() const>::value,
146+ void>::type
147+rename( char const *from, ToStringType const &to ) {
148 rename( from, to.c_str() );
149 }
150
151@@ -552,7 +584,12 @@
152 * @throws fs::exception if the rename fails.
153 */
154 template<class FromStringType,class ToStringType> inline
155-void rename( FromStringType const &from, ToStringType const &to ) {
156+typename std::enable_if<ztd::has_c_str<FromStringType,
157+ char const* (FromStringType::*)() const>::value
158+ && ztd::has_c_str<ToStringType,
159+ char const* (ToStringType::*)() const>::value,
160+ void>::type
161+rename( FromStringType const &from, ToStringType const &to ) {
162 rename( from.c_str(), to.c_str() );
163 }
164
165@@ -573,14 +610,17 @@
166 /**
167 * Gets the normalized path of the given path.
168 *
169- * @tparam PathStringType The path string type.
170+ * @tparam PathStringType The \a path string type.
171 * @param path The path to normalize.
172 * @param base The base path, if any.
173 * @return Returns the normalized path.
174 * @throws XQueryException err::XPTY0004 for malformed paths.
175 */
176 template<class PathStringType> inline
177-zstring get_normalized_path( PathStringType const &path,
178+typename std::enable_if<ztd::has_c_str<PathStringType,
179+ char const* (PathStringType::*)() const>::value,
180+ zstring>::type
181+get_normalized_path( PathStringType const &path,
182 PathStringType const &base = "" ) {
183 return get_normalized_path( path.c_str(), base.c_str() );
184 }
185@@ -595,7 +635,10 @@
186 * @throws XQueryException err::XPTY0004 for malformed paths.
187 */
188 template<class PathStringType> inline
189-void normalize_path( PathStringType &path, PathStringType const &base = "" ) {
190+typename std::enable_if<ztd::has_c_str<PathStringType,
191+ char const* (PathStringType::*)() const>::value,
192+ void>::type
193+normalize_path( PathStringType &path, PathStringType const &base = "" ) {
194 path = get_normalized_path( path, base );
195 }
196
197@@ -605,11 +648,15 @@
198 * Appends a path component onto another path ensuring that exactly one
199 * separator is used.
200 *
201+ * @tparam PathStringType1 The \a path1 string type.
202 * @param path1 The path to append to.
203 * @param path2 The path to append.
204 */
205-template<class PathStringType1>
206-inline void append( PathStringType1 &path1, char const *path2 ) {
207+template<class PathStringType1> inline
208+typename std::enable_if<ztd::has_c_str<PathStringType1,
209+ char const* (PathStringType1::*)() const>::value,
210+ void>::type
211+append( PathStringType1 &path1, char const *path2 ) {
212 if ( !ascii::ends_with( path1, dir_separator ) )
213 path1 += dir_separator;
214 path1 += path2;
215@@ -623,8 +670,13 @@
216 * @param path1 The path to append to.
217 * @param path2 The path to append.
218 */
219-template<class PathStringType1,class PathStringType2>
220-inline void append( PathStringType1 &path1, PathStringType2 const &path2 ) {
221+template<class PathStringType1,class PathStringType2> inline
222+typename std::enable_if<ztd::has_c_str<PathStringType1,
223+ char const* (PathStringType1::*)() const>::value
224+ && ztd::has_c_str<PathStringType2,
225+ char const* (PathStringType2::*)() const>::value,
226+ void>::type
227+append( PathStringType1 &path1, PathStringType2 const &path2 ) {
228 append( path1, path2.c_str() );
229 }
230
231@@ -635,7 +687,10 @@
232 * @param path The path to make absolute.
233 */
234 template<class PathStringType> inline
235-void make_absolute( PathStringType &path ) {
236+typename std::enable_if<ztd::has_c_str<PathStringType,
237+ char const* (PathStringType::*)() const>::value,
238+ void>::type
239+make_absolute( PathStringType &path ) {
240 if ( !is_absolute( path ) ) {
241 #ifndef WIN32
242 typedef typename PathStringType::size_type size_type;
243@@ -670,7 +725,10 @@
244 * @throws fs::exception if the operation fails.
245 */
246 template<class PathStringType> inline
247-void get_temp_file( PathStringType *path ) {
248+typename std::enable_if<ztd::has_c_str<PathStringType,
249+ char const* (PathStringType::*)() const>::value,
250+ void>::type
251+get_temp_file( PathStringType *path ) {
252 char path_buf[ MAX_PATH ];
253 get_temp_file( path_buf );
254 *path = path_buf;

Subscribers

People subscribed via source and target branches