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

pandatool/src/progbase/programBase.h

Go to the documentation of this file.
00001 // Filename: programBase.h
00002 // Created by:  drose (13Feb00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef PROGRAMBASE_H
00020 #define PROGRAMBASE_H
00021 
00022 #include "pandatoolbase.h"
00023 
00024 #include "distanceUnit.h"
00025 #include "pathReplace.h"
00026 #include "pathStore.h"
00027 #include "filename.h"
00028 #include "pointerTo.h"
00029 #include "vector_string.h"
00030 #include "pvector.h"
00031 #include "pdeque.h"
00032 #include "pmap.h"
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //       Class : ProgramBase
00036 // Description : This is intended to be the base class for most
00037 //               general-purpose utility programs in the PANDATOOL
00038 //               tree.  It automatically handles things like
00039 //               command-line arguments in a portable way.
00040 ////////////////////////////////////////////////////////////////////
00041 class ProgramBase {
00042 public:
00043   ProgramBase();
00044   virtual ~ProgramBase();
00045 
00046   void show_description();
00047   void show_usage();
00048   void show_options();
00049 
00050   INLINE void show_text(const string &text);
00051   void show_text(const string &prefix, int indent_width, string text);
00052 
00053   virtual void parse_command_line(int argc, char *argv[]);
00054 
00055   string get_exec_command() const;
00056 
00057   typedef pdeque<string> Args;
00058   Filename _program_name;
00059   Args _program_args;
00060 
00061 protected:
00062   typedef bool (*OptionDispatchFunction)(const string &opt, const string &parm, void *data);
00063   typedef bool (*OptionDispatchMethod)(ProgramBase *self, const string &opt, const string &parm, void *data);
00064 
00065   virtual bool handle_args(Args &args);
00066   virtual bool post_command_line();
00067 
00068   void set_program_description(const string &description);
00069   void clear_runlines();
00070   void add_runline(const string &runline);
00071   void clear_options();
00072   void add_option(const string &option, const string &parm_name,
00073                   int index_group, const string &description,
00074                   OptionDispatchFunction option_function,
00075                   bool *bool_var = (bool *)NULL,
00076                   void *option_data = (void *)NULL);
00077   void add_option(const string &option, const string &parm_name,
00078                   int index_group, const string &description,
00079                   OptionDispatchMethod option_method,
00080                   bool *bool_var = (bool *)NULL,
00081                   void *option_data = (void *)NULL);
00082   bool redescribe_option(const string &option, const string &description);
00083   bool remove_option(const string &option);
00084 
00085   void add_path_replace_options();
00086   void add_path_store_options();
00087 
00088   static bool dispatch_none(const string &opt, const string &arg, void *);
00089   static bool dispatch_true(const string &opt, const string &arg, void *var);
00090   static bool dispatch_false(const string &opt, const string &arg, void *var);
00091   static bool dispatch_count(const string &opt, const string &arg, void *var);
00092   static bool dispatch_int(const string &opt, const string &arg, void *var);
00093   static bool dispatch_int_pair(const string &opt, const string &arg, void *var);
00094   static bool dispatch_double(const string &opt, const string &arg, void *var);
00095   static bool dispatch_double_pair(const string &opt, const string &arg, void *var);
00096   static bool dispatch_double_triple(const string &opt, const string &arg, void *var);
00097   static bool dispatch_double_quad(const string &opt, const string &arg, void *var);
00098   static bool dispatch_color(const string &opt, const string &arg, void *var);
00099   static bool dispatch_string(const string &opt, const string &arg, void *var);
00100   static bool dispatch_filename(const string &opt, const string &arg, void *var);
00101   static bool dispatch_search_path(const string &opt, const string &arg, void *var);
00102   static bool dispatch_coordinate_system(const string &opt, const string &arg, void *var);
00103   static bool dispatch_units(const string &opt, const string &arg, void *var);
00104   static bool dispatch_image_type(const string &opt, const string &arg, void *var);
00105   static bool dispatch_path_replace(const string &opt, const string &arg, void *var);
00106   static bool dispatch_path_store(const string &opt, const string &arg, void *var);
00107 
00108   static bool handle_help_option(const string &opt, const string &arg, void *);
00109 
00110   static void format_text(ostream &out, bool &last_newline,
00111                           const string &prefix, int indent_width,
00112                           const string &text, int line_width);
00113 
00114   PT(PathReplace) _path_replace;
00115   bool _got_path_store;
00116   bool _got_path_directory;
00117 
00118 
00119 private:
00120   void sort_options();
00121   void get_terminal_width();
00122 
00123   class Option {
00124   public:
00125     string _option;
00126     string _parm_name;
00127     int _index_group;
00128     int _sequence;
00129     string _description;
00130     OptionDispatchFunction _option_function;
00131     OptionDispatchMethod _option_method;
00132     bool *_bool_var;
00133     void *_option_data;
00134   };
00135 
00136   class SortOptionsByIndex {
00137   public:
00138     bool operator () (const Option *a, const Option *b) const;
00139   };
00140 
00141   string _description;
00142   typedef vector_string Runlines;
00143   Runlines _runlines;
00144 
00145   typedef pmap<string, Option> OptionsByName;
00146   typedef pvector<const Option *> OptionsByIndex;
00147   OptionsByName _options_by_name;
00148   OptionsByIndex _options_by_index;
00149   int _next_sequence;
00150   bool _sorted_options;
00151 
00152   typedef pmap<string, string> GotOptions;
00153   GotOptions _got_options;
00154 
00155   bool _last_newline;
00156   int _terminal_width;
00157   bool _got_terminal_width;
00158   int _option_indent;
00159   bool _got_option_indent;
00160 };
00161 
00162 #include "programBase.I"
00163 
00164 #endif
00165 
00166 

Generated on Fri May 2 03:21:31 2003 for Panda-Tool by doxygen1.3