ColPack
Utilities/command_line_parameter_processor.h
Go to the documentation of this file.
00001 /************************************************************************************
00002     Copyright (C) 2005-2008 Assefaw H. Gebremedhin, Arijit Tarafdar, Duc Nguyen,
00003     Alex Pothen
00004 
00005     This file is part of ColPack.
00006 
00007     ColPack is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU Lesser General Public License as published
00009     by the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     ColPack is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public License
00018     along with ColPack.  If not, see <http://www.gnu.org/licenses/>.
00019 ************************************************************************************/
00020 
00021 #include<iostream>
00022 #include<string>
00023 #include<vector>
00024 
00025 using namespace std;
00026 
00027 /*Convert command line parameters to vector arg for easiness
00028 Input: argc, argv
00029 Output: arg
00030 Precondition: arg is empty
00031 */
00032 void createArgs(int argc, const char* argv[], vector<string>& arg);
00033 
00034 //find argument in vector arg
00035 int findArg(string argument, vector<string>& arg);
00036 
00037 //SAMPLE main.cpp
00038 /*
00039 #include "command_line_parameter_processor.h"
00040 
00041 using namespace std;
00042 
00043 int commandLineProcessing(vector<string>& arg);
00044 
00045 int main(int argc, const char* argv[] ) {
00046         vector<string> arg;
00047 
00048         //get the list of arguments
00049         createArgs(argc, argv, arg);
00050 
00051         //process those arguments
00052         commandLineProcessing(arg);
00053 
00054         //...
00055 
00056         return 0;
00057 }
00058 
00059 int commandLineProcessing(vector<string>& arg) {
00060 
00061         int num=findArg("-r", arg);
00062         if (num!=-1) //argument is found, do something
00063         {
00064                 //...
00065         }
00066 
00067         if (findArg("-append", arg) != -1 || findArg("-app", arg) != -1) //append output to the existing file
00068         {
00069                 output_append = true;
00070         }
00071 
00072         //"-suffix" has priority over "-suf", i.e., if both "-suffix" and "-suf" are specified, "-suffix <output_suffix>" will be used
00073         int result;
00074         result = findArg("-suffix", arg);
00075         if (result == -1) result = findArg("-suf", arg);
00076         if (result != -1) //suffix is specified
00077         {
00078                 output_suffix = arg[result+1];
00079         }
00080 
00081         return 0;
00082 }
00083 //*/
00084 
00085 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines