• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
tdesycocafactory.cpp
1/* This file is part of the KDE libraries
2 * Copyright (C) 1999 David Faure <faure@kde.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License version 2 as published by the Free Software Foundation;
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU Library General Public License
14 * along with this library; see the file COPYING.LIB. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 **/
18
19#include "tdesycoca.h"
20#include "tdesycocatype.h"
21#include "tdesycocafactory.h"
22#include "tdesycocaentry.h"
23#include "tdesycocadict.h"
24#include <tqstringlist.h>
25#include <tqdict.h>
26#include <kdebug.h>
27
28template class TQDict<KSycocaEntry>;
29template class TQDict<TDESharedPtr<KSycocaEntry> >;
30
31KSycocaFactory::KSycocaFactory(KSycocaFactoryId factory_id)
32 : m_resourceList(0), m_entryDict(0), m_sycocaDict(0)
33{
34 if (!KSycoca::self()->isBuilding()) // read-only database ?
35 {
36 m_str = KSycoca::self()->findFactory( factory_id );
37 // can't call factoryId() here since the constructor can't call inherited methods
38 if (m_str) // Can be 0 in case of errors
39 {
40 // Read position of index tables....
41 TQ_INT32 i;
42 (*m_str) >> i;
43 m_sycocaDictOffset = i;
44 (*m_str) >> i;
45 m_beginEntryOffset = i;
46 (*m_str) >> i;
47 m_endEntryOffset = i;
48
49 int saveOffset = m_str->device()->at();
50 // Init index tables
51 m_sycocaDict = new KSycocaDict(m_str, m_sycocaDictOffset);
52 saveOffset = m_str->device()->at(saveOffset);
53 }
54 }
55 else
56 {
57 // Build new database!
58 m_str = 0;
59 m_resourceList = 0;
60 m_entryDict = new KSycocaEntryDict(977);
61 m_entryDict->setAutoDelete(true);
62 m_sycocaDict = new KSycocaDict();
63 m_beginEntryOffset = 0;
64 m_endEntryOffset = 0;
65
66 // m_resourceList will be filled in by inherited constructors
67 }
68 KSycoca::self()->addFactory(this);
69}
70
71KSycocaFactory::~KSycocaFactory()
72{
73 delete m_entryDict;
74 delete m_sycocaDict;
75}
76
77void
78KSycocaFactory::saveHeader(TQDataStream &str)
79{
80 // Write header
81 str.device()->at(mOffset);
82 str << (TQ_INT32) m_sycocaDictOffset;
83 str << (TQ_INT32) m_beginEntryOffset;
84 str << (TQ_INT32) m_endEntryOffset;
85}
86
87void
88KSycocaFactory::save(TQDataStream &str)
89{
90 if (!m_entryDict) return; // Error! Function should only be called when
91 // building database
92 if (!m_sycocaDict) return; // Error!
93
94 mOffset = str.device()->at(); // store position in member variable
95 m_sycocaDictOffset = 0;
96
97 // Write header (pass #1)
98 saveHeader(str);
99
100 m_beginEntryOffset = str.device()->at();
101
102 // Write all entries.
103 int entryCount = 0;
104 for(TQDictIterator<KSycocaEntry::Ptr> it ( *m_entryDict );
105 it.current();
106 ++it)
107 {
108 KSycocaEntry *entry = (*it.current());
109 entry->save(str);
110 entryCount++;
111 }
112
113 m_endEntryOffset = str.device()->at();
114
115 // Write indices...
116 // Linear index
117 str << (TQ_INT32) entryCount;
118 for(TQDictIterator<KSycocaEntry::Ptr> it ( *m_entryDict );
119 it.current();
120 ++it)
121 {
122 KSycocaEntry *entry = (*it.current());
123 str << (TQ_INT32) entry->offset();
124 }
125
126 // Dictionary index
127 m_sycocaDictOffset = str.device()->at();
128 m_sycocaDict->save(str);
129
130 int endOfFactoryData = str.device()->at();
131
132 // Update header (pass #2)
133 saveHeader(str);
134
135 // Seek to end.
136 str.device()->at(endOfFactoryData);
137}
138
139void
140KSycocaFactory::addEntry(KSycocaEntry *newEntry, const char *)
141{
142 if (!m_entryDict) return; // Error! Function should only be called when
143 // building database
144
145 if (!m_sycocaDict) return; // Error!
146
147 TQString name = newEntry->name();
148 m_entryDict->insert( name, new KSycocaEntry::Ptr(newEntry) );
149 m_sycocaDict->add( name, newEntry );
150}
151
152void
153KSycocaFactory::removeEntry(KSycocaEntry *newEntry)
154{
155 if (!m_entryDict) return; // Error! Function should only be called when
156 // building database
157
158 if (!m_sycocaDict) return; // Error!
159
160 TQString name = newEntry->name();
161 m_entryDict->remove( name );
162 m_sycocaDict->remove( name );
163}
164
165KSycocaEntry::List KSycocaFactory::allEntries()
166{
167 KSycocaEntry::List list;
168 if (!m_str) return list;
169
170 // Assume we're NOT building a database
171
172 m_str->device()->at(m_endEntryOffset);
173 TQ_INT32 entryCount;
174 (*m_str) >> entryCount;
175
176 if (entryCount > 8192)
177 {
178 KSycoca::flagError();
179 return list;
180 }
181
182 TQ_INT32 *offsetList = new TQ_INT32[entryCount];
183 for(int i = 0; i < entryCount; i++)
184 {
185 (*m_str) >> offsetList[i];
186 }
187
188 for(int i = 0; i < entryCount; i++)
189 {
190 KSycocaEntry *newEntry = createEntry(offsetList[i]);
191 if (newEntry)
192 {
193 list.append( KSycocaEntry::Ptr( newEntry ) );
194 }
195 }
196 delete [] offsetList;
197 return list;
198}
199
200void KSycocaFactory::virtual_hook( int /*id*/, void* /*data*/)
201{ /*BASE::virtual_hook( id, data );*/ }
202
KSycocaEntry
Base class for all Sycoca entries.
Definition: tdesycocaentry.h:38
KSycocaEntry::name
virtual TQString name() const =0
TDESharedPtr
Can be used to control the lifetime of an object that has derived TDEShared.
Definition: ksharedptr.h:101
KStdAction::name
const char * name(StdAction id)

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.