home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / private / qcom_p.h < prev    next >
C/C++ Source or Header  |  2001-09-19  |  9KB  |  320 lines

  1. #ifndef QCOM_H
  2. #define QCOM_H
  3.  
  4. #ifndef QT_H
  5. #include "qstringlist.h"
  6. #include "quuid.h"
  7. #endif // QT_H
  8.  
  9. //
  10. //  W A R N I N G
  11. //  -------------
  12. //
  13. // This file is not part of the Qt API.  It exists for the convenience
  14. // of a number of Qt sources files.  This header file may change from
  15. // version to version without notice, or even be removed.
  16. //
  17. // We mean it.
  18. //
  19. //
  20.  
  21. #ifndef QT_NO_COMPONENT
  22.  
  23. class QObject;
  24. struct QUInterfaceDescription;
  25. struct QUObject;
  26.  
  27. #define QRESULT        unsigned long
  28. #define QS_OK        (QRESULT)0x00000000
  29. #define QS_FALSE    (QRESULT)0x00000001
  30.  
  31. #define QE_NOTIMPL      (QRESULT)0x80000001
  32. #define QE_OUTOFMEMORY  (QRESULT)0x80000002
  33. #define QE_INVALIDARG    (QRESULT)0x80000003
  34. #define QE_NOINTERFACE    (QRESULT)0x80000004
  35. #define QE_NOCOMPONENT    (QRESULT)0x80000005
  36.  
  37.  
  38. // {1D8518CD-E8F5-4366-99E8-879FD7E482DE}
  39. #ifndef IID_QUnknown
  40. #define IID_QUnknown QUuid(0x1d8518cd, 0xe8f5, 0x4366, 0x99, 0xe8, 0x87, 0x9f, 0xd7, 0xe4, 0x82, 0xde)
  41. #endif
  42.  
  43. struct Q_EXPORT QUnknownInterface
  44. {
  45.     virtual QRESULT queryInterface( const QUuid&, QUnknownInterface** ) = 0;
  46.     virtual ulong   addRef() = 0;
  47.     virtual ulong   release() = 0;
  48. };
  49.  
  50. // {FBAC965E-A441-413F-935E-CDF582573FAB} 
  51. #ifndef IID_QDispatch
  52. #define IID_QDispatch QUuid( 0xfbac965e, 0xa441, 0x413f, 0x93, 0x5e, 0xcd, 0xf5, 0x82, 0x57, 0x3f, 0xab)
  53. #endif
  54.  
  55. // the dispatch interface that inherits the unknown interface.. It is
  56. // used to explore interfaces during runtime and to do dynamic calls.
  57. struct Q_EXPORT QDispatchInterface : public QUnknownInterface
  58. {
  59.     // returns the interface description of this dispatch interface.
  60.     virtual const QUInterfaceDescription* interfaceDescription() const = 0;
  61.  
  62.     // returns the event description of this dispatch interface.
  63.     virtual const QUInterfaceDescription* eventsDescription() const = 0;
  64.  
  65.     // invokes method id with parameters V*. Returns some sort of
  66.     // exception code.
  67.     virtual QRESULT invoke( int id, QUObject* o ) = 0;
  68.  
  69.     // installs listener as event listener
  70.     virtual void installListener( QDispatchInterface* listener ) = 0;
  71.  
  72.     // remove listener as event listener
  73.     virtual void removeListener( QDispatchInterface* listener ) = 0;
  74. };
  75.  
  76. template <class T> class Q_EXPORT QInterfacePtr
  77. {
  78. public:
  79.     QInterfacePtr():iface(0){}
  80.  
  81.     QInterfacePtr( T* i) {
  82.     if ( (iface = i) )
  83.         iface->addRef();
  84.     }
  85.  
  86.     QInterfacePtr(const QInterfacePtr<T> &p) {
  87.     if ( (iface = p.iface) )
  88.         iface->addRef();
  89.     }
  90.  
  91.     ~QInterfacePtr() {
  92.     if ( iface )
  93.         iface->release();
  94.     }
  95.  
  96.     QInterfacePtr<T> &operator=(const QInterfacePtr<T> &p) {
  97.     if ( iface != p.iface ) {
  98.         if ( iface )
  99.         iface->release();
  100.         if ( (iface = p.iface) )
  101.         iface->addRef();
  102.     }
  103.     return *this;
  104.     }
  105.  
  106.     QInterfacePtr<T> &operator=(T* i) {
  107.     if (iface != i ) {
  108.         if ( iface )
  109.         iface->release();
  110.         if ( (iface = i) )
  111.         iface->addRef();
  112.     }
  113.     return *this;
  114.     }
  115.  
  116.     bool operator==( const QInterfacePtr<T> &p ) const { return iface == p.iface; }
  117.  
  118.     bool operator!= ( const QInterfacePtr<T>& p ) const {  return !( *this == p ); }
  119.  
  120.     bool isNull() const { return !iface; }
  121.  
  122.     T* operator->() const { return iface; }
  123.  
  124.     T& operator*() const { return *iface; }
  125.  
  126.     operator T*() const { return iface; }
  127.  
  128.     QUnknownInterface** operator &() const { 
  129.     if( iface ) 
  130.         iface->release();
  131.     return (QUnknownInterface**)&iface; 
  132.     }
  133.  
  134.     T** operator &() { 
  135.     if ( iface )
  136.         iface->release();
  137.     return &iface; 
  138.     }
  139.  
  140. private:
  141.     T* iface;
  142. };
  143.  
  144. // {10A1501B-4C5F-4914-95DD-C400486CF900} 
  145. #ifndef IID_QObject
  146. #define IID_QObject QUuid( 0x10a1501b, 0x4c5f, 0x4914, 0x95, 0xdd, 0xc4, 0x00, 0x48, 0x6c, 0xf9, 0x00)
  147. #endif
  148.  
  149. struct Q_EXPORT QObjectInterface
  150. {
  151.     virtual QObject*   qObject() = 0;
  152. };
  153.  
  154. // {5F3968A5-F451-45b1-96FB-061AD98F926E}
  155. #ifndef IID_QComponentInformation
  156. #define IID_QComponentInformation QUuid(0x5f3968a5, 0xf451, 0x45b1, 0x96, 0xfb, 0x6, 0x1a, 0xd9, 0x8f, 0x92, 0x6e)
  157. #endif
  158.  
  159. struct Q_EXPORT QComponentInformationInterface : public QUnknownInterface
  160. {
  161.     virtual QString name() const = 0;
  162.     virtual QString description() const = 0;
  163.     virtual QString author() const = 0;
  164.     virtual QString version() const = 0;
  165. };
  166.  
  167. // {6CAA771B-17BB-4988-9E78-BA5CDDAAC31E}
  168. #ifndef IID_QComponentFactory
  169. #define IID_QComponentFactory QUuid( 0x6caa771b, 0x17bb, 0x4988, 0x9e, 0x78, 0xba, 0x5c, 0xdd, 0xaa, 0xc3, 0x1e)
  170. #endif
  171.  
  172. struct Q_EXPORT QComponentFactoryInterface : public QUnknownInterface
  173. {
  174.     virtual QRESULT createInstance( const QUuid &cid, const QUuid &iid, QUnknownInterface** instance, QUnknownInterface *outer ) = 0;
  175. };
  176.  
  177. // {D16111D4-E1E7-4C47-8599-24483DAE2E07}
  178. #ifndef IID_QLibrary
  179. #define IID_QLibrary QUuid( 0xd16111d4, 0xe1e7, 0x4c47, 0x85, 0x99, 0x24, 0x48, 0x3d, 0xae, 0x2e, 0x07)
  180. #endif
  181.  
  182. struct Q_EXPORT QLibraryInterface : public QUnknownInterface
  183. {
  184.     virtual bool    init() = 0;
  185.     virtual void    cleanup() = 0;
  186.     virtual bool    canUnload() const = 0;
  187. };
  188.  
  189. // {3F8FDC44-3015-4f3e-B6D6-E4AAAABDEAAD}
  190. #ifndef IID_QFeatureList
  191. #define IID_QFeatureList QUuid(0x3f8fdc44, 0x3015, 0x4f3e, 0xb6, 0xd6, 0xe4, 0xaa, 0xaa, 0xbd, 0xea, 0xad)
  192. #endif
  193.  
  194. struct Q_EXPORT QFeatureListInterface : public QUnknownInterface
  195. {
  196.     virtual QStringList    featureList() const = 0;
  197. };
  198.  
  199. // {B5FEB5DE-E0CD-4E37-B0EB-8A812499A0C1}
  200. #ifndef IID_QComponentRegistration
  201. #define IID_QComponentRegistration QUuid( 0xb5feb5de, 0xe0cd, 0x4e37, 0xb0, 0xeb, 0x8a, 0x81, 0x24, 0x99, 0xa0, 0xc1)
  202. #endif
  203.  
  204. struct Q_EXPORT QComponentRegistrationInterface : public QUnknownInterface
  205. {
  206.     virtual bool    registerComponents( const QString &filepath ) const = 0;
  207.     virtual bool    unregisterComponents() const = 0;
  208. };
  209.  
  210.  
  211. #ifndef Q_EXTERN_C
  212. #ifdef __cplusplus
  213. #define Q_EXTERN_C    extern "C"
  214. #else
  215. #define Q_EXTERN_C    extern
  216. #endif
  217. #endif
  218.  
  219. // This macro expands to the default implementation of ucm_instantiate.
  220. #ifndef Q_CREATE_INSTANCE
  221. #    define Q_CREATE_INSTANCE( IMPLEMENTATION )        \
  222.     IMPLEMENTATION *i = new IMPLEMENTATION;        \
  223.     QUnknownInterface* iface = 0;             \
  224.     i->queryInterface( IID_QUnknown, &iface );    \
  225.     return iface;
  226. #endif
  227.  
  228. // internal class that wraps an initialized ulong
  229. struct Q_EXPORT QtULong
  230. {
  231.     QtULong() : ref( 0 ) { }
  232.     operator unsigned long () const { return ref; }
  233.     unsigned long& operator++() { return ++ref; }
  234.     unsigned long operator++( int ) { return ref++; }
  235.     unsigned long& operator--() { return --ref; }
  236.     unsigned long operator--( int ) { return ref--; }
  237.  
  238.     unsigned long ref;
  239. };
  240. // default implementation of ref counting. A variable "ulong ref" has to be a member
  241.  
  242.  
  243. #define Q_REFCOUNT \
  244. private:       \
  245.     QtULong qtrefcount;   \
  246. public:           \
  247.     ulong addRef() {return qtrefcount++;} \
  248.     ulong release() {if(!--qtrefcount){delete this;return 0;}return qtrefcount;}
  249.  
  250. #if defined(QT_THREAD_SUPPORT)
  251. #define QT_THREADED_BUILD 1
  252. #else
  253. #define QT_THREADED_BUILD 0
  254. #endif
  255.  
  256. #if defined(QT_DEBUG)
  257. #define QT_DEBUG_BUILD 1
  258. #else
  259. #define QT_DEBUG_BUILD 0
  260. #endif
  261.  
  262. #ifndef Q_EXPORT_COMPONENT
  263. #    ifdef Q_WS_WIN
  264. #    ifdef Q_CC_BOR
  265. #        define Q_EXPORT_COMPONENT() \
  266.         class QApplication;\
  267.         extern Q_EXPORT QApplication *qApp; \
  268.         extern Q_EXPORT void qt_ucm_initialize( QApplication *theApp ); \
  269.         Q_EXTERN_C __declspec(dllexport) int __stdcall ucm_initialize( QApplication *theApp, bool *mt, bool *debug ) \
  270.         { \
  271.             if ( !qApp && theApp ) \
  272.             qt_ucm_initialize( theApp ); \
  273.             if ( mt ) \
  274.             *mt = QT_THREADED_BUILD; \
  275.             if ( debug ) \
  276.                 *debug = QT_DEBUG_BUILD; \
  277.             return QT_VERSION; \
  278.         } \
  279.         Q_EXTERN_C __declspec(dllexport) QUnknownInterface* __stdcall ucm_instantiate()
  280. #    else
  281. #        define Q_EXPORT_COMPONENT() \
  282.         class QApplication;\
  283.         extern Q_EXPORT QApplication *qApp; \
  284.         extern Q_EXPORT void qt_ucm_initialize( QApplication *theApp ); \
  285.         Q_EXTERN_C __declspec(dllexport) int ucm_initialize( QApplication *theApp, bool *mt, bool *debug ) \
  286.         { \
  287.             if ( !qApp && theApp ) \
  288.             qt_ucm_initialize( theApp ); \
  289.             if ( mt ) \
  290.             *mt = QT_THREADED_BUILD; \
  291.             if ( debug ) \
  292.                 *debug = QT_DEBUG_BUILD; \
  293.             return QT_VERSION; \
  294.         } \
  295.         Q_EXTERN_C __declspec(dllexport) QUnknownInterface* ucm_instantiate()
  296. #    endif
  297. #    else
  298. #    define Q_EXPORT_COMPONENT() \
  299.         class QApplication;\
  300.         extern Q_EXPORT QApplication *qApp; \
  301.         extern Q_EXPORT void qt_ucm_initialize( QApplication *theApp ); \
  302.         Q_EXTERN_C int ucm_initialize( QApplication *theApp, bool *mt, bool *debug ) \
  303.         { \
  304.         if ( !qApp && theApp ) \
  305.             qt_ucm_initialize( theApp ); \
  306.         if ( mt ) \
  307.             *mt = QT_THREADED_BUILD; \
  308.         if ( debug ) \
  309.             *debug = QT_DEBUG_BUILD; \
  310.         return QT_VERSION; \
  311.         } \
  312.         Q_EXTERN_C QUnknownInterface* ucm_instantiate()
  313. #    endif
  314. #    define Q_EXPORT_INTERFACE() Q_EXPORT_COMPONENT()
  315. #endif
  316.  
  317. #endif //QT_NO_COMPONENT
  318.  
  319. #endif //QCOM_H
  320.