libsax 7.2

file.cpp

00001 /**************
00002 FILE          : file.cpp
00003 ***************
00004 PROJECT       : SaX2 - library interface
00005               :
00006 AUTHOR        : Marcus Schäfer <ms@suse.de>
00007               :
00008 BELONGS TO    : SaX2 - SuSE advanced X11 configuration 
00009               : 
00010               :
00011 DESCRIPTION   : native C++ class library to access SaX2
00012               : functionality. Easy to use interface for
00013               : //.../
00014               : - importing/exporting X11 configurations
00015               : - modifying/creating X11 configurations 
00016               : ---
00017               :
00018               :
00019 STATUS        : Status: Development
00020 **************/
00021 #include "file.h"
00022 
00023 namespace SaX {
00024 //====================================
00025 // SaXFile constructor...
00026 //------------------------------------
00027 SaXFile::SaXFile (const QString& name) {
00028         // .../
00031         // ----
00032         mHandle = new QFile (name);
00033         fileOpen ();
00034 }
00035 
00036 //====================================
00037 // fileOpen...
00038 //------------------------------------
00039 void SaXFile::fileOpen (void) {
00040         // .../
00043         // ----
00044         if (! mHandle -> isOpen()) {
00045         if (! mHandle -> open(QIODevice::ReadOnly)) {
00046                 excFileOpenFailed ( errno );
00047                 qError (errorString(),EXC_FILEOPENFAILED);
00048         }
00049         }
00050 }
00051 
00052 //====================================
00053 // readDict...
00054 //------------------------------------
00055 Q3Dict<QString> SaXFile::readDict (void) {
00056         // .../
00060         // ----
00061         if (! mHandle -> isOpen()) {
00062                 Q3Dict<QString>* nope = new Q3Dict<QString>;
00063                 return *nope;
00064         }
00065         char line[MAX_LINE_LENGTH];
00066         while ((mHandle->readLine(line,MAX_LINE_LENGTH)) != 0) {
00067                 QString string_line(line);
00068                 string_line.truncate(string_line.length()-1);
00069                 if ((string_line[0] == '#') || (string_line.isEmpty())) {
00070                         if (mHandle->atEnd()) {
00071                                 break;
00072                         }
00073                         continue;
00074                 }
00075                 QString key;
00076                 QString* val = new QString();
00077                 QStringList tokens = QStringList::split ( ":", string_line );
00078                 key = tokens.first();
00079                 *val = tokens.last();
00080                 *val = val->stripWhiteSpace();
00081                 key = key.stripWhiteSpace();
00082                 mDict.insert (key,val);
00083                 if (mHandle->atEnd()) {
00084                         break;
00085                 }
00086         }
00087         mHandle->close();
00088         return (mDict);
00089 }
00090 
00091 //====================================
00092 // SaXFile return dictionary...
00093 //------------------------------------
00094 Q3Dict<QString> SaXFile::getDataDict (void) {
00095         // .../
00098         // ----
00099         return (mDict);
00100 }
00101 } // end namespace