xref: /trunk/main/vos/inc/vos/object.hxx (revision d98e0520)
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 #	include <vos/vosdllapi.h>
31 
32 namespace vos
33 {
34 
35 // ***************************************
36 // Object super class
37 
38 struct OClassInfo;
39 struct OCreateParam;
40 
41 /** OObject
42 	common base class for all framework classes. Used for memory-management
43 	and runtime type-info.
44 */
45 class VOS_DLLPUBLIC OObject
46 {
47 public:
48 
49 	///
50 	OObject();
51 
52 	///
53 	OObject(const OCreateParam& rParam);
54 
55 	// Disable the copy constructor and assignment by default so you will get
56 	// compiler errors instead of unexpected behaviour if you pass objects
57 	// by value or assign objects.
58 private:
59 	OObject(const OObject& objectSrc);			// no implementation
60 	void SAL_CALL operator=(const OObject& objectSrc);	// no implementation
61 
62 public:
63 	virtual ~OObject();
64 
65 public:
66 
67 	/** Define private new and delete operator because of compiler bug,
68 		when allocating and deleteing a exported class
69 	*/
70 	void* SAL_CALL operator new(size_t size);
71 	void* SAL_CALL operator new(size_t size, void* p);
72 
73 	void  SAL_CALL operator delete(void* p);
74 
75 // Attributes
76 public:
77 
78 	///
79 	virtual const OClassInfo& SAL_CALL getClassInfo() const;
80 
81 	///
82 	sal_Bool SAL_CALL isKindOf(const OClassInfo& rClass) const;
83 
84 // Implementation
85 public:
86 	static const OClassInfo& SAL_CALL classInfo();
87 
88 public:
89 	static OClassInfo __ClassInfo__;
90 };
91 
92 
93 /**
94 	Basic class information
95 */
96 struct OCreateParam
97 {
98 	sal_uInt32 m_Size;
99 	void*	 m_pParam;
100 
101 	///
OCreateParamvos::OCreateParam102 	OCreateParam(void *pParam)
103 	{
104 		m_Size = sizeof(OCreateParam);
105 		m_pParam = pParam;
106 	}
107 };
108 
109 /**
110 */
111 struct VOS_DLLPUBLIC OClassInfo
112 {
113 	///
114 	const sal_Char  *m_pClassName;
115 	///
116 	sal_Int32			 m_nObjectSize;
117 	/// schema number of the loaded class
118 	sal_uInt32	 m_wSchema;
119 
120 	///
121 	OObject* (SAL_CALL * m_pfnCreateObject)(const OCreateParam&);	// NULL => abstract class
122 
123 	/// linked list of registered classes
124 	const OClassInfo* m_pBaseClass;
125 	/// linked list of registered classes
126 	const OClassInfo* m_pNextClass;
127 
128 	///
129 	OObject* SAL_CALL createObject(const OCreateParam& rParam) const;
130 
131 	///
132 	sal_Bool SAL_CALL isDerivedFrom(const OClassInfo& rBaseClass) const;
133 
134 	///
135 	static const OClassInfo* SAL_CALL getClassInfo(const sal_Char* pClassName);
136 
137 	///
138 	OClassInfo(const sal_Char *pClassName, sal_Int32 ObjectSize,
139 		       const OClassInfo* pBaseClass = NULL, sal_uInt32 Schema = (sal_uInt32)-1,
140 			   OObject* (SAL_CALL * fnCreateObject)(const OCreateParam&) = NULL);
141 };
142 
143 // *****************************************************************
144 // Helper macros for declaring OClassInfo data
145 
146 
147 #define VOS_STRINGIZE(name) #name
148 
149 #define VOS_CLASSNAME(class_name, domain_name) VOS_STRINGIZE(domain_name.class_name)
150 
151 #define VOS_CLASSINFO(class_name) (class_name::classInfo())
152 
153 // generate static object constructor for class registration
154 struct VOS_CLASSINIT
155 { VOS_CLASSINIT(VOS_NAMESPACE(OClassInfo, vos)* pNewClass); };
156 
157 #define VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, constructor) \
158 	VOS_NAMESPACE(OClassInfo, vos) class_name::__ClassInfo__(class_spec, \
159 	    sizeof(class_name), &VOS_CLASSINFO(base_class_name), wSchema, constructor); \
160     const VOS_NAMESPACE(VOS_CLASSINIT, vos) class_name::__ClassInit__(&class_name::__ClassInfo__); \
161     const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL class_name::getClassInfo() const \
162 		{ return (VOS_CLASSINFO(class_name)); } \
163     const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL class_name::classInfo() \
164 		{ return (__ClassInfo__); }
165 
166 #define VOS_DECLARE_CLASSINFO(class_name) \
167 public: \
168 	static const VOS_NAMESPACE(VOS_CLASSINIT, vos) __ClassInit__; \
169     static VOS_NAMESPACE(OClassInfo, vos) __ClassInfo__; \
170 public: \
171 	virtual const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL getClassInfo() const; \
172     static const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL classInfo()
173 
174 #define VOS_IMPLEMENT_CLASSINFO(class_spec, class_name, base_class_name, wSchema) \
175 	VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, NULL)
176 
177 #define VOS_DECLARE_CLASSTYPE(class_name) \
178 	VOS_DECLARE_CLASSINFO(class_name); \
179 public: \
180 	static VOS_NAMESPACE(OObject, vos)* SAL_CALL createObject(const VOS_NAMESPACE(OCreateParam, vos)& rParam);
181 
182 #define VOS_IMPLEMENT_CLASSTYPE(class_spec, class_name, base_class_name, wSchema) \
183 	VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, class_name::createObject) \
184 	VOS_NAMESPACE(OObject, vos)* class_name::createObject(const VOS_NAMESPACE(OCreateParam, vos)& rParam) \
185 		{ return new class_name(rParam); }
186 
187 }
188 
189 #endif // _VOS_OBJECT_HXX_
190 
191