xref: /AOO41X/main/vos/inc/vos/object.hxx (revision 1be3ed10e7d2672e4fa7df184b766627fd8bc1dd)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 #ifndef _VOS_OBJECT_HXX_
26 #define _VOS_OBJECT_HXX_
27 
28 #   include <vos/types.hxx>
29 #   include <vos/macros.hxx>
30 
31 namespace vos
32 {
33 
34 // ***************************************
35 // Object super class
36 
37 struct OClassInfo;
38 struct OCreateParam;
39 
40 /** OObject
41     common base class for all framework classes. Used for memory-management
42     and runtime type-info.
43 */
44 class OObject
45 {
46 public:
47 
48     ///
49     OObject();
50 
51     ///
52     OObject(const OCreateParam& rParam);
53 
54     // Disable the copy constructor and assignment by default so you will get
55     // compiler errors instead of unexpected behaviour if you pass objects
56     // by value or assign objects.
57 private:
58     OObject(const OObject& objectSrc);          // no implementation
59     void SAL_CALL operator=(const OObject& objectSrc);  // no implementation
60 
61 public:
62     virtual ~OObject();
63 
64 public:
65 
66     /** Define private new and delete operator because of compiler bug,
67         when allocating and deleteing a exported class
68     */
69     void* SAL_CALL operator new(size_t size);
70     void* SAL_CALL operator new(size_t size, void* p);
71 
72     void  SAL_CALL operator delete(void* p);
73 
74 // Attributes
75 public:
76 
77     ///
78     virtual const OClassInfo& SAL_CALL getClassInfo() const;
79 
80     ///
81     sal_Bool SAL_CALL isKindOf(const OClassInfo& rClass) const;
82 
83 // Implementation
84 public:
85     static const OClassInfo& SAL_CALL classInfo();
86 
87 public:
88     static OClassInfo __ClassInfo__;
89 };
90 
91 
92 /**
93     Basic class information
94 */
95 struct OCreateParam
96 {
97     sal_uInt32 m_Size;
98     void*    m_pParam;
99 
100     ///
OCreateParamvos::OCreateParam101     OCreateParam(void *pParam)
102     {
103         m_Size = sizeof(OCreateParam);
104         m_pParam = pParam;
105     }
106 };
107 
108 /**
109 */
110 struct OClassInfo
111 {
112     ///
113     const sal_Char  *m_pClassName;
114     ///
115     sal_Int32            m_nObjectSize;
116     /// schema number of the loaded class
117     sal_uInt32   m_wSchema;
118 
119     ///
120     OObject* (SAL_CALL * m_pfnCreateObject)(const OCreateParam&);   // NULL => abstract class
121 
122     /// linked list of registered classes
123     const OClassInfo* m_pBaseClass;
124     /// linked list of registered classes
125     const OClassInfo* m_pNextClass;
126 
127     ///
128     OObject* SAL_CALL createObject(const OCreateParam& rParam) const;
129 
130     ///
131     sal_Bool SAL_CALL isDerivedFrom(const OClassInfo& rBaseClass) const;
132 
133     ///
134     static const OClassInfo* SAL_CALL getClassInfo(const sal_Char* pClassName);
135 
136     ///
137     OClassInfo(const sal_Char *pClassName, sal_Int32 ObjectSize,
138                const OClassInfo* pBaseClass = NULL, sal_uInt32 Schema = (sal_uInt32)-1,
139                OObject* (SAL_CALL * fnCreateObject)(const OCreateParam&) = NULL);
140 };
141 
142 // *****************************************************************
143 // Helper macros for declaring OClassInfo data
144 
145 
146 #define VOS_STRINGIZE(name) #name
147 
148 #define VOS_CLASSNAME(class_name, domain_name) VOS_STRINGIZE(domain_name.class_name)
149 
150 #define VOS_CLASSINFO(class_name) (class_name::classInfo())
151 
152 // generate static object constructor for class registration
153 struct VOS_CLASSINIT
154 { VOS_CLASSINIT(VOS_NAMESPACE(OClassInfo, vos)* pNewClass); };
155 
156 #define VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, constructor) \
157     VOS_NAMESPACE(OClassInfo, vos) class_name::__ClassInfo__(class_spec, \
158         sizeof(class_name), &VOS_CLASSINFO(base_class_name), wSchema, constructor); \
159     const VOS_NAMESPACE(VOS_CLASSINIT, vos) class_name::__ClassInit__(&class_name::__ClassInfo__); \
160     const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL class_name::getClassInfo() const \
161         { return (VOS_CLASSINFO(class_name)); } \
162     const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL class_name::classInfo() \
163         { return (__ClassInfo__); }
164 
165 #define VOS_DECLARE_CLASSINFO(class_name) \
166 public: \
167     static const VOS_NAMESPACE(VOS_CLASSINIT, vos) __ClassInit__; \
168     static VOS_NAMESPACE(OClassInfo, vos) __ClassInfo__; \
169 public: \
170     virtual const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL getClassInfo() const; \
171     static const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL classInfo()
172 
173 #define VOS_IMPLEMENT_CLASSINFO(class_spec, class_name, base_class_name, wSchema) \
174     VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, NULL)
175 
176 #define VOS_DECLARE_CLASSTYPE(class_name) \
177     VOS_DECLARE_CLASSINFO(class_name); \
178 public: \
179     static VOS_NAMESPACE(OObject, vos)* SAL_CALL createObject(const VOS_NAMESPACE(OCreateParam, vos)& rParam);
180 
181 #define VOS_IMPLEMENT_CLASSTYPE(class_spec, class_name, base_class_name, wSchema) \
182     VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, class_name::createObject) \
183     VOS_NAMESPACE(OObject, vos)* class_name::createObject(const VOS_NAMESPACE(OCreateParam, vos)& rParam) \
184         { return new class_name(rParam); }
185 
186 }
187 
188 #endif // _VOS_OBJECT_HXX_
189 
190