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

cmd_args.hpp

Go to the documentation of this file.
00001 /*
00002  * Equation Cruncher
00003  * Copyright (C) 2004  Dhruv Matani(dhruvbird@yahoo.com)
00004  * 
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00019  * USA
00020  */
00021 
00022 #if !defined EC_CMD_ARGS_HPP
00023 #define EC_CMD_ARGS_HPP
00024 
00025 #include <vector>
00026 #include <string>
00027 #include <istream>
00028 #include <sstream>
00029 #include <assert.h>
00030 
00031 namespace eqn_cruncher
00032 {
00033   // None of the member functions are intended to be thread safe /
00034   // reentrant.
00035   class arg_stream
00036   {
00037     std::vector<std::string> arg_list;
00038     int index;
00039 
00040   public:
00041     arg_stream(int nargs, char** args)
00042       : arg_list(args + 1, args + nargs)
00043     { }
00044 
00045     int
00046     num_args() const { return arg_list.size(); }
00047 
00048     void
00049     set_index(int i)
00050     {
00051       assert(i < (int)arg_list.size());
00052       this->index = i;
00053     }
00054 
00055     int
00056     contains(std::string const& sarg) const;
00057 
00058     friend
00059     arg_stream&
00060     operator>>(arg_stream& in, int& i);
00061 
00062     friend
00063     arg_stream&
00064     operator>>(arg_stream& in, unsigned int& i);
00065 
00066     friend
00067     arg_stream&
00068     operator>>(arg_stream& in, char& ch);
00069 
00070     friend
00071     arg_stream&
00072     operator>>(arg_stream& in, std::string& str);
00073   };
00074 }
00075 
00076 
00077 #endif // EC_CMD_ARGS_HPP

Generated on Mon Oct 11 13:09:25 2004 for Equation Cruncher by doxygen1.2.18