Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

parser.hpp

Go to the documentation of this file.
00001 /*
00002 This is an abstract base class for parsers.
00003     
00004     Copyright (C) 2002 Ross A. Beyer
00005 
00006         Contact Author: Ross A. Beyer, rbeyer@rossbeyer.net
00007 
00008     CVS $Id: parser.hpp,v 1.5 2003/03/25 23:53:36 rbeyer Exp $
00009 
00010 
00011   License & Copyright Information
00012   -------------------------------
00013 
00014     This file is part of the commandl package, 
00015     $Name: commandl_Beta-1 $.
00016 
00017     The commandl packge is free software; you can redistribute it
00018     and/or modify it under the terms of the GNU General Public License
00019     as published by the Free Software Foundation; either version 2 of the 
00020     License, or (at your option) any later version.
00021 
00022     The commandl package is distributed in the hope that it will be useful,
00023     but WITHOUT ANY WARRANTY; without even the implied warranty of
00024     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025     GNU General Public License for more details.
00026 
00027     You should have received a copy of the GNU General Public License
00028     along with this program; if not, write to the Free Software
00029     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00030 
00031 */
00032 
00033 #ifndef BASIC_PARSER_HEADER // Begin the Header Guard to
00034 #define BASIC_PARSER_HEADER // prevent multiple inclusions.
00035 
00036 #include "argument.hpp"
00037 #include "matcher.hpp"
00038 #include "whole_matcher.hpp"
00039 #include "policy.hpp"
00040 #include <iostream>
00041 #include <map>
00042 #include <string>
00043 #include <utility>
00044 #include <vector>
00045 
00046 namespace commandl
00047 {
00048 
00061 //template <typename matcherT>
00062 class parser
00063 {
00064 
00065 // ==================== Constructors & Destructor ===================== //
00066 public:
00067 
00068     /*
00069     parser
00070         (
00071         matcher,                        // matcher
00072         policy = policy()       // policy
00073         );
00074     */
00075 
00076     parser
00077         (
00078         const std::vector<argument*>&,  // arguments
00079         const matcher&,                 // matcher
00080         const policy&                       // policy
00081         );
00082 
00083     parser
00084         (
00085         const std::vector<argument*>&,  // arguments
00086         const matcher&                  // matcher
00087         );
00088 
00089     parser
00090         (
00091         const std::vector<argument*>&       // arguments
00092         );
00093 
00094     parser( const parser& );
00095         
00096 
00097     virtual ~parser();
00098 
00099 // =========================== Accessors ============================== //
00100 public:
00101 
00102     virtual std::string
00103     name() const;
00104 
00105     virtual unsigned long
00106     stop_position() const;
00107 
00108     virtual std::map<unsigned long, std::string>
00109     elements_without_prefixes() const;
00110 
00111     virtual std::map<unsigned long, std::string>
00112     elements_without_keys() const;
00113 
00114     virtual std::map<unsigned long, std::string>
00115     elements_after_stop() const;
00116 
00117     virtual std::ostream&
00118     usage( std::ostream& = std::cout ) const;
00119 
00120     virtual std::ostream&
00121     usage( argument*, std::ostream& = std::cout ) const;
00122 
00123     virtual std::ostream&
00124     short_usage( std::ostream& = std::cout ) const;
00125 
00126     virtual std::ostream&
00127     short_usage( argument*, std::ostream& = std::cout ) const;
00128 
00129 // =========================== Methods ================================ //
00130 public:
00131 
00132     virtual void set_name( const std::string& );
00133     virtual void exceptions( bool = true );
00134 
00135     virtual bool parse( int, char**, std::ostream& = std::cout );
00136     virtual bool parse( std::vector<std::string>, std::ostream& = std::cout );
00137     /*virtual void parse    (
00138                         std::vector<std::string>::iterator,
00139                         std::vector<std::string>::iterator
00140                         );
00141     */
00142 
00143     virtual parser& operator=( const parser& );
00144 
00145 // --------------------------- Protected Methods ---------------------- //
00146 protected:
00147 
00148     virtual std::pair<std::string, std::string>
00149     separate_prefix_from( std::string );
00150 
00151     virtual std::pair<std::string::size_type, std::string>
00152     find_assignment_in( std::string );
00153 
00154     virtual void
00155     identify_prefix_and_key( std::string );
00156 
00157     virtual void
00158     parse_required_values   (
00159                             std::string,
00160                             std::string,
00161                             std::string,
00162                             std::string,
00163                             commandl::argument*,
00164                             std::vector<std::string>::iterator&,
00165                             std::vector<std::string>::iterator
00166                             );
00167     virtual void
00168     parse_optional_values   (
00169                             std::string,
00170                             std::string,
00171                             std::string,
00172                             std::string,
00173                             commandl::argument*,
00174                             std::vector<std::string>::iterator&,
00175                             std::vector<std::string>::iterator
00176                             );
00177     virtual void
00178     parse_character_keys    (
00179                             std::string,
00180                             std::string,
00181                             std::vector<std::string>::iterator&,
00182                             std::vector<std::string>::iterator,
00183                             bool = false
00184                             );
00185 
00186 
00187 // --------------------------- Private Methods ------------------------ //
00188 private:
00189     
00190 
00191 // =========================== Member Variables ======================= //
00192 protected:
00193 
00195     std::vector<argument*>                  Arguments;
00196 
00198     matcher*                                Matcher_ptr;
00199 
00201     policy                                  Policy;
00202 
00204     bool                                    Throws_Exceptions;
00205 
00209     std::string                             Name;
00210 
00212     unsigned long int                       Position;
00213 
00215     unsigned long int                       Stop_Position;
00216 
00218     std::vector<std::string>                Elements;
00219 
00224     std::map<unsigned long, std::string>    Elements_without_prefixes;
00225 
00230     std::map<unsigned long, std::string>    Elements_without_keys;
00231 
00236     std::map<unsigned long, std::string>    Elements_after_stop;
00237 
00238 }; // End of the class declaration
00239 
00240 } // End of the namespace declaration
00241 
00242 #endif  // End the Header Guard
00243 

Generated on Sat Apr 5 21:17:27 2003 for commandl Library by doxygen1.2.15