Changeset 2265
- Timestamp:
- Jun 6, 2010, 1:12:10 AM (13 years ago)
- Location:
- trunk/yat/utility
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/CommandLine.cc
r2210 r2265 32 32 33 33 #include <algorithm> 34 #include <cassert> 34 35 #include <functional> 35 36 #include <fstream> … … 197 198 198 199 200 void CommandLine::sort(void) 201 { 202 sort(OptionCompare()); 203 } 204 205 199 206 std::vector<std::string> CommandLine::split(std::string str, char del) const 200 207 { … … 237 244 238 245 246 bool CommandLine::OptionCompare::operator()(const Option* lhs, 247 const Option* rhs) const 248 { 249 assert(lhs); 250 assert(rhs); 251 std::string lhs_str = lhs->long_name(); 252 if (lhs_str.empty()) 253 lhs_str = lhs->short_name(); 254 std::string rhs_str = rhs->long_name(); 255 if (rhs_str.empty()) 256 rhs_str = rhs->short_name(); 257 return lhs_str < rhs_str; 258 } 259 260 239 261 }}} // of namespace utility, yat, and theplu -
trunk/yat/utility/CommandLine.h
r2247 r2265 23 23 */ 24 24 25 #include <algorithm> 25 26 #include <cctype> 26 27 #include <map> … … 157 158 158 159 /** 160 \brief Sort Options how they will appear in (help) output. 161 162 This function will sort the Options in alphabetical order. If 163 the Option has a long_name, it is used for the sorting; 164 otherwise, the short_name is used. 165 166 \since New in yat 0.7 167 */ 168 void sort(void); 169 170 /** 171 Like sort(void) but using \a compare to sort Options. 172 173 The functor Compare must be a <a 174 href="http://www.sgi.com/tech/stl/BinaryFunction.html">Binary 175 Function</a> with both argument types \c const \c Option* and 176 return type \c bool. 177 178 \since New in yat 0.7 179 */ 180 template<class Compare> 181 void sort(Compare compare); 182 183 /** 159 184 \return something like "Try `<program_name()> --help` for 160 185 more information." … … 176 201 bool parsed_; 177 202 std::string program_name_; 203 204 struct OptionCompare 205 { 206 bool operator()(const Option*, const Option*) const; 207 }; 208 178 209 }; 179 210 … … 198 229 std::ostream& operator<<(std::ostream&, const CommandLine&); 199 230 231 template<class Compare> 232 void CommandLine::sort(Compare compare) 233 { 234 std::sort(options_.begin(), options_.end(), compare); 235 } 236 200 237 }}} // end of namespace utility, yat, and theplu 201 238
Note: See TracChangeset
for help on using the changeset viewer.