Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

hk_utilities.h

00001 // ****************************************************************************
00002 // copyright (c) 2000-2005 Horst Knorr <hk_classes@knoda.org>  
00003 // This file is part of the hk_classes library.
00004 // This file may be distributed and/or modified under the terms of the
00005 // GNU Library Public License version 2 as published by the Free Software
00006 // Foundation and appearing in the file COPYING included in the
00007 // packaging of this file.
00008 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00009 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00010 // ****************************************************************************
00011 #ifndef HK_UTILITIES
00012 #define HK_UTILITIES
00013 #ifdef HAVE_ARGP
00014 #include <argp.h>
00015 #endif
00016 #include <cassert>
00017 #include "hk_drivermanager.h"
00018 #include "hk_connection.h"
00019 #include "hk_database.h"
00020 #include "hk_string.h"
00021 #include "config.h"
00022 #include <cassert>
00023 #include <unistd.h>
00024 #include <sys/types.h>
00025 #include <sys/stat.h>
00026 
00027 #define DEFAULTPARAMETER {"driver",'d',"DRIVERNAME",0,"Name of the database driver"},{"list",'l',0,1,"List available database drivers"},{"host",'h',"HOST",0,"IP-number or name of hosts"},{"port",'r',"PORT",0,"TCP-port on host"},{"user",'u',"USERNAME",0,"user name"},{"password",'p',"PASSWORD",0,"user password"},{"database",'b',"DATABASE",0,"database name"},{"version",10,0,1,"version and author of hk_classes"}
00028 
00034 class argumentclass
00035 {
00036     public:
00037         hk_string driver,host,port,user,password,database,filter;
00038 };
00039 #ifdef HAVE_ARGP
00040 
00043 inline static  error_t parse_generaloptions (int key,char* arg, struct argp_state* state)
00044 {
00045     struct argumentclass* arguments=(argumentclass*)state->input;
00046     assert(arguments);
00047     switch (key)
00048     {
00049 
00050         case 10     :                             //version
00051             cout <<"Version "<<VERSION<<"\nAuthor: Horst Knorr <hk_classes@knoda.org>\nhttp://hk-classes.sourceforge.net"<<endl;
00052             exit(0);
00053             break;
00054         case 'l'        :
00055         {
00056             vector<hk_string>* l = hk_drivermanager::driverlist();
00057             vector<hk_string>::iterator it=l->begin();
00058             while (it!=l->end())
00059             {
00060                 cout <<*it<<endl;
00061                 ++it;
00062             }
00063             exit(0);
00064         }
00065 
00066         break;
00067         case 'd'    : arguments->driver=arg;
00068         break;
00069         case 'h'    : arguments->host=arg;
00070         break;
00071         case 'r'    : arguments->port=arg;
00072         break;
00073         case 'u'    : arguments->user=arg;
00074         break;
00075         case 'p'    : arguments->password=arg;
00076         break;
00077         case 'f'    : arguments->filter=arg;
00078         break;
00079         case 'b'    : arguments->database=arg;
00080         break;
00081         default :  return ARGP_ERR_UNKNOWN;
00082     }
00083     return 0;
00084 }
00085 
00086 
00087 bool verify_generalarguments(argumentclass& arguments)
00088 {
00089     if (arguments.driver.size()==0)
00090     {
00091         cerr << "No driver selected"<<endl;
00092         return false;
00093     }
00094     if (arguments.database.size()==0)
00095     {
00096         cerr << "No database selected"<<endl;
00097         return false;
00098     }
00099 
00100     return true;
00101 }
00102 #endif //HAVE_ARGP
00103 
00104 bool is_localfile(const hk_string& file)
00105 {
00106     return (file.find('/')!=hk_string::npos);
00107 }
00108 
00109 
00110 bool load_file(const hk_string &name,hk_string &file)
00111 {
00112     if (name.size()==0) return false;
00113     ifstream ifs(name.c_str(),ios::in);
00114     if (ifs)
00115     {
00116         char c;
00117         file="";
00118         while (ifs.get(c))
00119             file+=c;
00120     }
00121     else return false;
00122     return true;
00123 
00124 }
00125 #endif

Generated on Tue Sep 13 00:58:20 2005 for Databaseconnectionclasses by  doxygen 1.4.4