Pagina Principale   Moduli   Lista dei namespaces   Gerarchia delle classi   Lista in ordine alfabetico   Lista dei composti   Lista dei files   Membri dei namespaces   Membri dei composti   Membri dei files   Esempi  

/home/fbassi/devel/projects/reti/utils/Prefs.cc

Vai alla documentazione di questo file.
00001 /*
00002  *    FBFS Distributed Object Repository
00003  *    Copyright (C) 2001 Francesco V. Bassi
00004  *
00005  *    This program is free software; you can redistribute it and/or modify
00006  *    it under the terms of the GNU General Public License as published by
00007  *    the Free Software Foundation; either version 2 of the License, or
00008  *    (at your option) any later version.
00009  *
00010  *    This program is distributed in the hope that it will be useful,
00011  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *    GNU General Public License for more details.
00014  *
00015  *    You should have received a copy of the GNU General Public License
00016  *    along with this program; if not, write to the Free Software
00017  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #include "Prefs.h"
00021 
00022 #include <string.h>
00023 
00029 utils::Prefs::Prefs(int &argc, char **&argv, string filename = "") {
00030     char **nargv = (char **) calloc(argc+2, sizeof(char*));
00031     nargv[0]=argv[0];
00032     int i=1,j=1;
00033 
00034     while(i<argc) {
00035         if(strcmp(argv[i],"-config")==0 && i<argc-1) {
00036             filename = argv[i+1];
00037             i += 2;
00038         } else {
00039             nargv[j++] = argv[i++];
00040         };
00041     };
00042     nargv[j+1] = NULL;
00043     argc = j;
00044     argv = nargv;
00045     
00046     accessible = Prefs::access(filename);
00047 };
00048 
00049 utils::Prefs::Prefs(string filename) {
00050     accessible = Prefs::access(filename);
00051 };
00052 
00053 bool utils::Prefs::access(string filename) {
00054     file.open(filename.c_str());
00055     return file.is_open();
00056 };
00057     
00058 string utils::Prefs::get(const string &tag, const string defvalue = "") const {
00059     if(!accessible)
00060         return defvalue;
00061     char buf[80];
00062     string key;
00063     string value;
00064     file.seekg(0, ios::beg);
00065     do {
00066         file.getline(buf,80);
00067         string s(buf);
00068         int i = s.find(" ");
00069         key = s.substr(0,i);
00070         value = s.substr(i+1,s.length()-i-1);
00071         if(key.compare(tag)==0)
00072             return value;
00073     } while (!file.eof());
00074     return defvalue;
00075 };

Generato il Thu Feb 15 13:24:57 2001 per A Simple Distributed Object Repository with CORBA & C++. da doxygen1.2.3 scritto da Dimitri van Heesch, © 1997-2000