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(IO_ReadOnly)) {
00046                 excFileOpenFailed ( errno );
00047                 qError (errorString(),EXC_FILEOPENFAILED);
00048         }
00049         }
00050 }
00051 
00052 //====================================
00053 // readDict...
00054 //------------------------------------
00055 QDict<QString> SaXFile::readDict (void) {
00056         // .../
00060         // ----
00061         if (! mHandle -> isOpen()) {
00062                 return QDict<QString>();
00063         }
00064         QString line;
00065         while ((mHandle->readLine(line,MAX_LINE_LENGTH)) != 0) {
00066                 line.truncate(line.length()-1);
00067                 if ((line[0] == '#') || (line.isEmpty())) {
00068                         if (mHandle->atEnd()) {
00069                                 break;
00070                         }
00071                         continue;
00072                 }
00073                 QString key;
00074                 QString* val = new QString();
00075                 QStringList tokens = QStringList::split ( ":", line );
00076                 key = tokens.first();
00077                 *val = tokens.last();
00078                 *val = val->stripWhiteSpace();
00079                 key = key.stripWhiteSpace();
00080                 mDict.insert (key,val);
00081                 if (mHandle->atEnd()) {
00082                         break;
00083                 }
00084         }
00085         mHandle->close();
00086         return (mDict);
00087 }
00088 
00089 //====================================
00090 // SaXFile return dictionary...
00091 //------------------------------------
00092 QDict<QString> SaXFile::getDataDict (void) {
00093         // .../
00096         // ----
00097         return (mDict);
00098 }
00099 } // end namespace

Generated on Mon Jan 7 17:25:36 2008 for libsax by  doxygen 1.4.6