Ignore:
Timestamp:
Jun 6, 2010, 1:24:05 AM (11 years ago)
Author:
Peter Johansson
Message:

sort options alphabetically. refs #307

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/yat/CommandLine.h

    r1058 r1064  
    22#define _theplu_yat_utility_commandline_
    33
    4 //$Id: CommandLine.h 2247 2010-04-22 00:54:34Z peter $
     4//$Id: CommandLine.h 2265 2010-06-05 23:12:10Z peter $
    55
    66/*
     
    2323*/
    2424
     25#include <algorithm>
    2526#include <cctype>
    2627#include <map>
     
    157158
    158159    /**
     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    /**
    159184       \return something like "Try `<program_name()> --help` for
    160185       more information."
     
    176201    bool parsed_;
    177202    std::string program_name_;
     203
     204    struct OptionCompare
     205    {
     206      bool operator()(const Option*, const Option*) const;
     207    };
     208
    178209  };
    179210
     
    198229  std::ostream& operator<<(std::ostream&, const CommandLine&);
    199230
     231  template<class Compare>
     232  void CommandLine::sort(Compare compare)
     233  {
     234    std::sort(options_.begin(), options_.end(), compare);
     235  }
     236
    200237}}} // end of namespace utility, yat, and theplu
    201238
Note: See TracChangeset for help on using the changeset viewer.