mx::mxArgs Class Reference

List of all members.

Public Member Functions

 mxArgs (int &argc, char **argv)
bool testForSwitchAndRemove (string what)
bool testForSwitchAndLeave (string what)
string testForItem (string what)


Detailed Description

proccess arguments passed on the command line

Definition at line 27 of file args.h.


Constructor & Destructor Documentation

mx::mxArgs::mxArgs ( int &  argc,
char **  argv 
) [explicit]

mxArgs explicit constructor, is required to init this class

Parameters:
argc the argc ( int ) first parameter from the main function
argv the argv ( char ** ) second parameter from the main function

Definition at line 22 of file args.cpp.

00023         {
00024 
00025 
00026                 try
00027                 {
00028 
00029                         int i;
00030                         for(i = 1; i < argc; i++)
00031                         {
00032                                 arglist.push_back(argv[i]);
00033                         }
00034 
00035                 }
00036                 catch (std::bad_alloc &bad)
00037                 {
00038 
00039                         std::cerr << "error allocating memory: " << bad.what() << "\n";
00040 
00041                 }
00042                 catch (...)
00043                 {
00044                         std::cerr << "error unknown exception\n";
00045                 }
00046         }


Member Function Documentation

string mx::mxArgs::testForItem ( string  what  ) 

testForItem tests internal object for a special type of identifier which has a string right after or a assignment statement

Parameters:
what variable for value to be assigned to
Returns:
the string value, empty string if not found

Definition at line 77 of file args.cpp.

00078         {
00079                 std::vector<std::string>::iterator i;
00080 
00081                 for(i = arglist.begin(); i!=arglist.end(); i++)
00082                 {
00083                         int position = 0;
00084                         std::string temp = *i;
00085                         position = i->find("=");
00086 
00087                         if(position != -1)
00088                         temp = i->substr(0, position );
00089 
00090 
00091                         if(what == temp)
00092                         {
00093 
00094                                 if(position == -1)
00095                                 {
00096 
00097                                         if(i+1 != arglist.end())
00098                                         {
00099                                                 std::vector<std::string>::iterator z = i+1;
00100                                                 if(z->at(0) != '-')
00101                                                         return *z;
00102                                         }
00103                                 }
00104                                 else
00105                                 {
00106 
00107                                         std::string leftOf = i->substr(position+1, i->length()-position );
00108                                         return leftOf;
00109                                 }
00110 
00111                         }
00112 
00113                 }
00114 
00115                 return string("");
00116 
00117         }

bool mx::mxArgs::testForSwitchAndLeave ( string  what  ) 

testForSwitchAndLeave test internal object created for a specific string and leave it there

Parameters:
what string to search for
Returns:
boolean value for if string was found

Definition at line 65 of file args.cpp.

00066         {
00067 
00068                 std::vector<std::string>::iterator i;
00069                 for(i = arglist.begin(); i!=arglist.end(); i++)
00070                 {
00071                         if(what == *i)
00072                                 return true;
00073                 }
00074                 return false;
00075         }

bool mx::mxArgs::testForSwitchAndRemove ( string  what  ) 

testForSwitchAndRemove test internal object created for a specific string and remove it from the object so it cannot be found again

Parameters:
what string to search for
Returns:
boolean value specifying whether string exists

Definition at line 49 of file args.cpp.

00050         {
00051 
00052                 std::vector<std::string>::iterator i;
00053                 for(i = arglist.begin(); i!=arglist.end(); i++)
00054                 {
00055                         if(what == *i)
00056                         {
00057                                 arglist.erase(i);
00058                                 return true;
00059                         }
00060 
00061                 }
00062                 return false;
00063         }


The documentation for this class was generated from the following files:

Generated on Wed Jun 10 14:52:02 2009 for libmx by  doxygen 1.5.8