Changeset 2248 for trunk/yat/utility/utility.h
- Timestamp:
- Apr 22, 2010, 2:57:13 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/utility.h
r2210 r2248 149 149 150 150 \note Requirement on T: utility::convert<T> must be supported 151 (from yat 0.7 T=string is also supported) 151 152 152 153 \since New in yat 0.6 … … 173 174 174 175 \note Requirement on T: utility::convert<T> must be supported 176 (from yat 0.7 T=string is also supported) 175 177 176 178 \since New in yat 0.6 … … 179 181 void load(std::istream& is, std::vector<T>& vec, char sep='\0'); 180 182 183 // private namespace 184 namespace detail { 185 /** 186 Functor used in load function 187 */ 188 template<typename T> 189 struct VectorPusher 190 { 191 /** 192 convert element to T and push on vec's back 193 194 \internal 195 */ 196 void operator()(const std::string& element, std::vector<T>& vec) 197 { 198 if (!element.size()) 199 vec.push_back(std::numeric_limits<T>::quiet_NaN()); 200 else { 201 vec.push_back(theplu::yat::utility::convert<T>(element)); 202 } 203 } 204 }; 205 206 /** 207 specialization for string 208 209 \internal 210 */ 211 template<> 212 struct VectorPusher<std::string> 213 { 214 /** 215 push element on vec's back 216 */ 217 void operator()(const std::string& element, std::vector<std::string>& vec) 218 { 219 vec.push_back(element); 220 } 221 }; 222 223 } // end of namespace detail 224 225 181 226 // template implementations 182 227 … … 287 332 void load(std::istream& is, std::vector<T>& vec, char sep='\0') 288 333 { 334 detail::VectorPusher<T> pusher; 289 335 std::string element; 290 336 bool ok=true; 291 while( ok) {337 while(true) { 292 338 if(sep=='\0') 293 339 ok=(is>>element); … … 297 343 break; 298 344 299 if (!element.size()) 300 vec.push_back(std::numeric_limits<T>::quiet_NaN()); 301 else { 302 vec.push_back(convert<T>(element)); 303 } 345 pusher(element, vec); 304 346 } 305 347 }
Note: See TracChangeset
for help on using the changeset viewer.