summaryrefslogtreecommitdiff
path: root/vos/inc/vos/object.hxx
blob: 0f302084ab4216af97359690fd1d0ee71580809c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: object.hxx,v $
 * $Revision: 1.6 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/


#ifndef _VOS_OBJECT_HXX_
#define _VOS_OBJECT_HXX_

#   include <vos/types.hxx>
#   include <vos/macros.hxx>

namespace vos
{

// ***************************************
// Object super class

struct OClassInfo;
struct OCreateParam;

/** OObject
    common base class for all framework classes. Used for memory-management
    and runtime type-info.
*/
class OObject
{
public:

    ///
    OObject();

    ///
    OObject(const OCreateParam& rParam);

    // Disable the copy constructor and assignment by default so you will get
    // compiler errors instead of unexpected behaviour if you pass objects
    // by value or assign objects.
private:
    OObject(const OObject& objectSrc);          // no implementation
    void SAL_CALL operator=(const OObject& objectSrc);  // no implementation

public:
    virtual ~OObject();

public:

    /** Define private new and delete operator because of compiler bug,
        when allocating and deleteing a exported class
    */
    void* SAL_CALL operator new(size_t size);
    void* SAL_CALL operator new(size_t size, void* p);

    void  SAL_CALL operator delete(void* p);

// Attributes
public:

    ///
    virtual const OClassInfo& SAL_CALL getClassInfo() const;

    ///
    sal_Bool SAL_CALL isKindOf(const OClassInfo& rClass) const;

// Implementation
public:
    static const OClassInfo& SAL_CALL classInfo();

public:
    static OClassInfo __ClassInfo__;
};


/**
    Basic class information
*/
struct OCreateParam
{
    sal_uInt32 m_Size;
    void*    m_pParam;

    ///
    OCreateParam(void *pParam)
    {
        m_Size = sizeof(OCreateParam);
        m_pParam = pParam;
    }
};

/**
*/
struct OClassInfo
{
    ///
    const sal_Char  *m_pClassName;
    ///
    sal_Int32            m_nObjectSize;
    /// schema number of the loaded class
    sal_uInt32   m_wSchema;

    ///
    OObject* (SAL_CALL * m_pfnCreateObject)(const OCreateParam&);   // NULL => abstract class

    /// linked list of registered classes
    const OClassInfo* m_pBaseClass;
    /// linked list of registered classes
    const OClassInfo* m_pNextClass;

    ///
    OObject* SAL_CALL createObject(const OCreateParam& rParam) const;

    ///
    sal_Bool SAL_CALL isDerivedFrom(const OClassInfo& rBaseClass) const;

    ///
    static const OClassInfo* SAL_CALL getClassInfo(const sal_Char* pClassName);

    ///
    OClassInfo(const sal_Char *pClassName, sal_Int32 ObjectSize,
               const OClassInfo* pBaseClass = NULL, sal_uInt32 Schema = (sal_uInt32)-1,
               OObject* (SAL_CALL * fnCreateObject)(const OCreateParam&) = NULL);
};

// *****************************************************************
// Helper macros for declaring OClassInfo data


#define VOS_STRINGIZE(name) #name

#define VOS_CLASSNAME(class_name, domain_name) VOS_STRINGIZE(domain_name.class_name)

#define VOS_CLASSINFO(class_name) (class_name::classInfo())

// generate static object constructor for class registration
struct VOS_CLASSINIT
{ VOS_CLASSINIT(VOS_NAMESPACE(OClassInfo, vos)* pNewClass); };

#define VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, constructor) \
    VOS_NAMESPACE(OClassInfo, vos) class_name::__ClassInfo__(class_spec, \
        sizeof(class_name), &VOS_CLASSINFO(base_class_name), wSchema, constructor); \
    const VOS_NAMESPACE(VOS_CLASSINIT, vos) class_name::__ClassInit__(&class_name::__ClassInfo__); \
    const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL class_name::getClassInfo() const \
        { return (VOS_CLASSINFO(class_name)); } \
    const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL class_name::classInfo() \
        { return (__ClassInfo__); }

#define VOS_DECLARE_CLASSINFO(class_name) \
public: \
    static const VOS_NAMESPACE(VOS_CLASSINIT, vos) __ClassInit__; \
    static VOS_NAMESPACE(OClassInfo, vos) __ClassInfo__; \
public: \
    virtual const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL getClassInfo() const; \
    static const VOS_NAMESPACE(OClassInfo, vos)& SAL_CALL classInfo()

#define VOS_IMPLEMENT_CLASSINFO(class_spec, class_name, base_class_name, wSchema) \
    VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, NULL)

#define VOS_DECLARE_CLASSTYPE(class_name) \
    VOS_DECLARE_CLASSINFO(class_name); \
public: \
    static VOS_NAMESPACE(OObject, vos)* SAL_CALL createObject(const VOS_NAMESPACE(OCreateParam, vos)& rParam);

#define VOS_IMPLEMENT_CLASSTYPE(class_spec, class_name, base_class_name, wSchema) \
    VOS_CLASSDATA(class_spec, class_name, base_class_name, wSchema, class_name::createObject) \
    VOS_NAMESPACE(OObject, vos)* class_name::createObject(const VOS_NAMESPACE(OCreateParam, vos)& rParam) \
        { return new class_name(rParam); }

}

#endif // _VOS_OBJECT_HXX_