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

tdecore

  • tdecore
kgenericfactory.h
1 /* This file is part of the KDE project
2  * Copyright (C) 2001 Simon Hausmann <hausmann@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 as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #ifndef __kgenericfactory_h__
20 #define __kgenericfactory_h__
21 
22 #include <klibloader.h>
23 #include <ktypelist.h>
24 #include <kinstance.h>
25 #include <kgenericfactory.tcc>
26 #include <tdeglobal.h>
27 #include <tdelocale.h>
28 #include <kdebug.h>
29 
30 /* @internal */
31 template <class T>
32 class KGenericFactoryBase
33 {
34 public:
35  KGenericFactoryBase( const char *instanceName )
36  : m_instanceName( instanceName )
37  {
38  m_aboutData=0L;
39  s_self = this;
40  m_catalogueInitialized = false;
41  }
42  KGenericFactoryBase( const TDEAboutData *data )
43  : m_aboutData(data)
44  {
45  s_self = this;
46  m_catalogueInitialized = false;
47  }
48 
49  virtual ~KGenericFactoryBase()
50  {
51  if ( s_instance )
52  TDEGlobal::locale()->removeCatalogue( TQString::fromAscii( s_instance->instanceName() ) );
53  delete s_instance;
54  s_instance = 0;
55  s_self = 0;
56  }
57 
58  static TDEInstance *instance();
59 
60 protected:
61  virtual TDEInstance *createInstance()
62  {
63  if ( m_aboutData )
64  return new TDEInstance( m_aboutData );
65  if ( m_instanceName.isEmpty() ) {
66  kdWarning() << "KGenericFactory: instance requested but no instance name or about data passed to the constructor!" << endl;
67  return 0;
68  }
69  return new TDEInstance( m_instanceName );
70  }
71 
72  virtual void setupTranslations( void )
73  {
74  if ( instance() )
75  TDEGlobal::locale()->insertCatalogue( TQString::fromAscii( instance()->instanceName() ) );
76  }
77 
78  void initializeMessageCatalogue()
79  {
80  if ( !m_catalogueInitialized )
81  {
82  m_catalogueInitialized = true;
83  setupTranslations();
84  }
85  }
86 
87 private:
88  TQCString m_instanceName;
89  const TDEAboutData *m_aboutData;
90  bool m_catalogueInitialized;
91 
92  static TDEInstance *s_instance;
93  static KGenericFactoryBase<T> *s_self;
94 };
95 
96 /* @internal */
97 template <class T>
98 TDEInstance *KGenericFactoryBase<T>::s_instance = 0;
99 
100 /* @internal */
101 template <class T>
102 KGenericFactoryBase<T> *KGenericFactoryBase<T>::s_self = 0;
103 
104 /* @internal */
105 template <class T>
106 TDEInstance *KGenericFactoryBase<T>::instance()
107 {
108  if ( !s_instance && s_self )
109  s_instance = s_self->createInstance();
110  return s_instance;
111 }
112 
172 template <class Product, class ParentType = TQObject>
173 class KGenericFactory : public KLibFactory, public KGenericFactoryBase<Product>
174 {
175 public:
176  KGenericFactory( const char *instanceName = 0 )
177  : KGenericFactoryBase<Product>( instanceName )
178  {}
179 
183  KGenericFactory( const TDEAboutData *data )
184  : KGenericFactoryBase<Product>( data )
185  {}
186 
187 
188 protected:
189  virtual TQObject *createObject( TQObject *parent, const char *name,
190  const char *className, const TQStringList &args )
191  {
192  KGenericFactoryBase<Product>::initializeMessageCatalogue();
193  return (KDEPrivate::ConcreteFactory<Product, ParentType>
194  ::create( 0, 0, parent, name, className, args ));
195  }
196 };
197 
265 template <class Product, class ProductListTail>
266 class KGenericFactory< KTypeList<Product, ProductListTail>, TQObject >
267  : public KLibFactory,
268  public KGenericFactoryBase< KTypeList<Product, ProductListTail> >
269 {
270 public:
271  KGenericFactory( const char *instanceName = 0 )
272  : KGenericFactoryBase< KTypeList<Product, ProductListTail> >( instanceName )
273  {}
274 
278  KGenericFactory( const TDEAboutData *data )
279  : KGenericFactoryBase< KTypeList<Product, ProductListTail> >( data )
280  {}
281 
282 
283 protected:
284  virtual TQObject *createObject( TQObject *parent, const char *name,
285  const char *className, const TQStringList &args )
286  {
287  this->initializeMessageCatalogue();
288  return KDEPrivate::MultiFactory< KTypeList< Product, ProductListTail > >
289  ::create( 0, 0, parent, name, className, args );
290  }
291 };
292 
360 template <class Product, class ProductListTail,
361  class ParentType, class ParentTypeListTail>
362 class KGenericFactory< KTypeList<Product, ProductListTail>,
363  KTypeList<ParentType, ParentTypeListTail> >
364  : public KLibFactory,
365  public KGenericFactoryBase< KTypeList<Product, ProductListTail> >
366 {
367 public:
368  KGenericFactory( const char *instanceName = 0 )
369  : KGenericFactoryBase< KTypeList<Product, ProductListTail> >( instanceName )
370  {}
374  KGenericFactory( const TDEAboutData *data )
375  : KGenericFactoryBase< KTypeList<Product, ProductListTail> >( data )
376  {}
377 
378 
379 protected:
380  virtual TQObject *createObject( TQObject *parent, const char *name,
381  const char *className, const TQStringList &args )
382  {
383  this->initializeMessageCatalogue();
384  return KDEPrivate::MultiFactory< KTypeList< Product, ProductListTail >,
385  KTypeList< ParentType, ParentTypeListTail > >
386  ::create( 0, 0, parent, name,
387  className, args );
388  }
389 };
390 
391 #endif
KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >::KGenericFactory
KGenericFactory(const TDEAboutData *data)
Definition: kgenericfactory.h:374
KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >::createObject
virtual TQObject * createObject(TQObject *parent, const char *name, const char *className, const TQStringList &args)
Creates a new object.
Definition: kgenericfactory.h:380
KGenericFactory< KTypeList< Product, ProductListTail >, TQObject >::createObject
virtual TQObject * createObject(TQObject *parent, const char *name, const char *className, const TQStringList &args)
Creates a new object.
Definition: kgenericfactory.h:284
KGenericFactory< KTypeList< Product, ProductListTail >, TQObject >::KGenericFactory
KGenericFactory(const TDEAboutData *data)
Definition: kgenericfactory.h:278
KGenericFactory
This template provides a generic implementation of a KLibFactory , for use with shared library compon...
Definition: kgenericfactory.h:174
KGenericFactory::KGenericFactory
KGenericFactory(const TDEAboutData *data)
Definition: kgenericfactory.h:183
KGenericFactory::createObject
virtual TQObject * createObject(TQObject *parent, const char *name, const char *className, const TQStringList &args)
Creates a new object.
Definition: kgenericfactory.h:189
KLibFactory
If you develop a library that is to be loaded dynamically at runtime, then you should return a pointe...
Definition: klibloader.h:334
KLibFactory::create
TQObject * create(TQObject *parent=0, const char *name=0, const char *classname="TQObject", const TQStringList &args=TQStringList())
Creates a new object.
Definition: klibloader.cpp:83
TDEAboutData
This class is used to store information about a program.
Definition: tdeaboutdata.h:183
TDEGlobal::locale
static TDELocale * locale()
Returns the global locale object.
Definition: tdeglobal.cpp:108
TDEInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:48
TDELocale::removeCatalogue
void removeCatalogue(const TQString &catalog)
Removes a catalog for translation lookup.
Definition: tdelocale.cpp:693
TDELocale::insertCatalogue
void insertCatalogue(const TQString &catalog)
Adds another catalog to search for translation lookup.
Definition: tdelocale.cpp:644
endl
kndbgstream & endl(kndbgstream &s)
Does nothing.
Definition: kdebug.h:583
KNotifyClient::instance
TDEInstance * instance()
Shortcut to KNotifyClient::Instance::current() :)
Definition: knotifyclient.cpp:280
KTypeList
The building block of typelists of any length.
Definition: ktypelist.h:363
tdelocale.h

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.1
This website is maintained by Timothy Pearson.