Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ProgramOptions.ih

Go to the documentation of this file.
00001 // $Id: ProgramOptions.ih 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef IH_SENF_Scheduler_Console_ProgramOptions_
00027 #define IH_SENF_Scheduler_Console_ProgramOptions_ 1
00028 
00029 // Custom includes
00030 #include <boost/scoped_ptr.hpp>
00031 #include "Parse.hh"
00032 
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 
00035 namespace senf {
00036 namespace console {
00037 namespace detail {
00038 
00039 #ifndef DOXYGEN
00040 
00041     class ProgramOptionsSource : public ConfigSource
00042     {
00043     public:
00044         typedef boost::intrusive_ptr<ProgramOptionsSource> ptr;
00045 
00046         static ptr create(int argc, char const ** argv);
00047 
00048         template <class Container>
00049         ProgramOptionsSource & nonOptions(Container & container);
00050         ProgramOptionsSource & alias(char letter, std::string const & longOpt, bool withArg=false);
00051 
00052     private:
00053         ProgramOptionsSource(int argc, char const ** argv);
00054 
00055         virtual void v_parse(RestrictedExecutor & executor);
00056 
00057         void parseLongOption(std::string const & arg, RestrictedExecutor & executor);
00058         void parseNonOption(std::string const & arg, RestrictedExecutor & executor);
00059 
00060         struct NonOptionContainer
00061         {
00062             virtual ~NonOptionContainer();
00063             virtual void clear() = 0;
00064             virtual void push_back(std::string const & value) = 0;
00065         };
00066 
00067         template <class Container>
00068         struct NonOptionContainerImpl
00069             : public NonOptionContainer
00070         {
00071             NonOptionContainerImpl(Container & c);
00072 
00073             void clear();
00074             void push_back(std::string const & value);
00075 
00076             Container & c_;
00077         };
00078 
00079         struct ShortOption
00080         {
00081             ShortOption(bool withArg, std::string const & longOpt);
00082             bool withArg;
00083             std::string longOpt;
00084         };
00085 
00086         typedef std::map<char, ShortOption> ShortOptions;
00087 
00088         int argc_;
00089         char const ** argv_;
00090         CommandParser parser_;
00091         ShortOptions shortOptions_;
00092         boost::scoped_ptr<NonOptionContainer> nonOptions_;
00093     };
00094 
00095 #endif
00096 
00097 }}}
00098 
00099 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00100 #endif
00101 
00102 
00103 // Local Variables:
00104 // mode: c++
00105 // fill-column: 100
00106 // comment-column: 40
00107 // c-file-style: "senf"
00108 // indent-tabs-mode: nil
00109 // ispell-local-dictionary: "american"
00110 // compile-command: "scons -u test"
00111 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research