ksycocafactory.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "ksycoca.h"
00020 #include "ksycocatype.h"
00021 #include "ksycocafactory.h"
00022 #include "ksycocaentry.h"
00023 #include "ksycocadict.h"
00024 #include <qstringlist.h>
00025 #include <qdict.h>
00026 #include <kdebug.h>
00027
00028 template class QDict<KSycocaEntry>;
00029 template class QDict<KSharedPtr<KSycocaEntry> >;
00030
00031 KSycocaFactory::KSycocaFactory(KSycocaFactoryId factory_id)
00032 : m_resourceList(0), m_entryDict(0), m_sycocaDict(0)
00033 {
00034 if (!KSycoca::self()->isBuilding())
00035 {
00036 m_str = KSycoca::self()->findFactory( factory_id );
00037
00038 if (m_str)
00039 {
00040
00041 Q_INT32 i;
00042 (*m_str) >> i;
00043 m_sycocaDictOffset = i;
00044 (*m_str) >> i;
00045 m_beginEntryOffset = i;
00046 (*m_str) >> i;
00047 m_endEntryOffset = i;
00048
00049 int saveOffset = m_str->device()->at();
00050
00051 m_sycocaDict = new KSycocaDict(m_str, m_sycocaDictOffset);
00052 saveOffset = m_str->device()->at(saveOffset);
00053 }
00054 }
00055 else
00056 {
00057
00058 m_str = 0;
00059 m_resourceList = 0;
00060 m_entryDict = new KSycocaEntryDict(977);
00061 m_entryDict->setAutoDelete(true);
00062 m_sycocaDict = new KSycocaDict();
00063 m_beginEntryOffset = 0;
00064 m_endEntryOffset = 0;
00065
00066
00067 }
00068 KSycoca::self()->addFactory(this);
00069 }
00070
00071 KSycocaFactory::~KSycocaFactory()
00072 {
00073 delete m_entryDict;
00074 delete m_sycocaDict;
00075 }
00076
00077 void
00078 KSycocaFactory::saveHeader(QDataStream &str)
00079 {
00080
00081 str.device()->at(mOffset);
00082 str << (Q_INT32) m_sycocaDictOffset;
00083 str << (Q_INT32) m_beginEntryOffset;
00084 str << (Q_INT32) m_endEntryOffset;
00085 }
00086
00087 void
00088 KSycocaFactory::save(QDataStream &str)
00089 {
00090 if (!m_entryDict) return;
00091
00092 if (!m_sycocaDict) return;
00093
00094 mOffset = str.device()->at();
00095 m_sycocaDictOffset = 0;
00096
00097
00098 saveHeader(str);
00099
00100 m_beginEntryOffset = str.device()->at();
00101
00102
00103 int entryCount = 0;
00104 for(QDictIterator<KSycocaEntry::Ptr> it ( *m_entryDict );
00105 it.current();
00106 ++it)
00107 {
00108 KSycocaEntry *entry = (*it.current());
00109 entry->save(str);
00110 entryCount++;
00111 }
00112
00113 m_endEntryOffset = str.device()->at();
00114
00115
00116
00117 str << (Q_INT32) entryCount;
00118 for(QDictIterator<KSycocaEntry::Ptr> it ( *m_entryDict );
00119 it.current();
00120 ++it)
00121 {
00122 KSycocaEntry *entry = (*it.current());
00123 str << (Q_INT32) entry->offset();
00124 }
00125
00126
00127 m_sycocaDictOffset = str.device()->at();
00128 m_sycocaDict->save(str);
00129
00130 int endOfFactoryData = str.device()->at();
00131
00132
00133 saveHeader(str);
00134
00135
00136 str.device()->at(endOfFactoryData);
00137 }
00138
00139 void
00140 KSycocaFactory::addEntry(KSycocaEntry *newEntry, const char *)
00141 {
00142 if (!m_entryDict) return;
00143
00144
00145 if (!m_sycocaDict) return;
00146
00147 QString name = newEntry->name();
00148 m_entryDict->insert( name, new KSycocaEntry::Ptr(newEntry) );
00149 m_sycocaDict->add( name, newEntry );
00150 }
00151
00152 KSycocaEntry::List KSycocaFactory::allEntries()
00153 {
00154 KSycocaEntry::List list;
00155 if (!m_str) return list;
00156
00157
00158
00159 m_str->device()->at(m_endEntryOffset);
00160 Q_INT32 entryCount;
00161 (*m_str) >> entryCount;
00162
00163 if (entryCount > 8192)
00164 {
00165 KSycoca::flagError();
00166 return list;
00167 }
00168
00169 Q_INT32 *offsetList = new Q_INT32[entryCount];
00170 for(int i = 0; i < entryCount; i++)
00171 {
00172 (*m_str) >> offsetList[i];
00173 }
00174
00175 for(int i = 0; i < entryCount; i++)
00176 {
00177 KSycocaEntry *newEntry = createEntry(offsetList[i]);
00178 if (newEntry)
00179 {
00180 list.append( KSycocaEntry::Ptr( newEntry ) );
00181 }
00182 }
00183 delete [] offsetList;
00184 return list;
00185 }
00186
00187 void KSycocaFactory::virtual_hook( int, void* )
00188 { }
00189
This file is part of the documentation for kdelibs Version 3.1.0.