Hauptseite | Liste aller Namensbereiche | Klassenhierarchie | Übersicht | Auflistung der Dateien | Elemente eines Namensbereiches | Datenstruktur-Elemente | Datei-Elemente

Config.cpp

gehe zur Dokumentation dieser Datei
00001 // Copyright (C) 2004 Bernhard Assmann <bernie@tuxomania.net>
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //  
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //  
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 //  
00017 
00018 #include <iostream>
00019 
00020 #include "psfa/Config.hpp"
00021 #include "psfa/Sax2Parser.hpp"
00022 #include "psfa/ConfigSax2ContentHandler.hpp"
00023 #include "psfa/ConfigSax2ErrorHandler.hpp"
00024 
00025 
00026 
00027 psfa::Config* psfa::Config::config_ = 0;
00028 
00029 psfa::Config::Config()
00030 {
00031 
00032 }
00033 
00034 
00035 
00036 psfa::Config::~Config()
00037 {
00038   delete config_;
00039 }
00040 
00041 
00042 
00043 psfa::Config* 
00044 psfa::Config::getConfig() 
00045 {
00046   if ( !config_ ) {
00047     config_ = new Config;
00048     return config_;
00049   }
00050   return config_;
00051 }
00052 
00053 
00054 
00055 bool
00056 psfa::Config::parseConfig( const std::string file ) 
00057 {
00058   xercesc::SAX2XMLReader* parser = Sax2Parser::getSax2Parser();
00059   ConfigSax2ContentHandler cH( configData_ );
00060   ConfigSax2ErrorHandler eH;
00061   parser->setContentHandler( &cH );
00062   parser->setErrorHandler(   &eH );
00063   parser->parse( file.c_str() );
00064   const int error = parser->getErrorCount();
00065   if ( error > 0 ) {
00066     return false;
00067   }
00068   return true;
00069 }
00070 
00071 
00072 
00073 const std::string
00074 psfa::Config::getConfigValue( const std::string pool,
00075                const std::string key ) const
00076 {
00077   using std::string;
00078   typedef std::map< string, string > cMap;
00079   const string mapKey = pool + "_" + key;
00080   cMap::const_iterator i = configData_.find(mapKey);
00081   if( i == configData_.end() ) {
00082     std::cerr << "Warnung: es wurde versucht auf einen nicht vorhandenen Wert "
00083          << "in der Konfiguration zuzugreifen.\n"
00084          << "Pool:      " << pool << "\n"
00085          << "Schlüssel: " << key
00086          << std::endl;
00087     return "";
00088   }
00089   return i->second;
00090 }
00091 
00092 
00093 
00094 void
00095 psfa::Config::showConfig() const
00096 {
00097   using std::cout;
00098   using std::endl;
00099   typedef std::map< std::string, std::string > cMap;
00100   
00101   cMap::const_iterator i = configData_.begin();
00102   cMap::const_iterator iEnd = configData_.end(); 
00103   
00104   for( ; i != iEnd; ++i ) {
00105     cout << i->first << ": "
00106     << i->second << " "
00107     << endl;
00108   }
00109   return;
00110 }

Erzeugt am Mon Jul 12 11:45:04 2004 für PSFA von doxygen 1.3.4