xref: /AOO41X/main/rdbmaker/inc/codemaker/registry.hxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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 #ifndef _CODEMAKER_REGISTRY_HXX_
25 #define _CODEMAKER_REGISTRY_HXX_
26 
27 #include <rtl/alloc.h>
28 #include <osl/interlck.h>
29 #include    <registry/registry.hxx>
30 #include "registry/reader.hxx"
31 #include "registry/version.h"
32 #include    <codemaker/options.hxx>
33 
34 struct TypeReader_Impl
35 {
36     TypeReader_Impl(const sal_uInt8* buffer,
37                     sal_uInt32 bufferLen,
38                     sal_Bool copyData)
39         : m_refCount(0)
40         , m_copyData(copyData)
41         , m_blopSize(bufferLen)
42         , m_pBlop(buffer)
43         {
44             if (copyData)
45             {
46                 m_pBlop = (sal_uInt8*)rtl_allocateMemory(bufferLen);
47                 rtl_copyMemory((void*)m_pBlop, buffer, bufferLen);
48             } else
49             {
50                 m_blopSize = bufferLen;
51                 m_pBlop = buffer;
52             }
53 
54             m_pReader = new typereg::Reader(
55                 m_pBlop, m_blopSize, false, TYPEREG_VERSION_1);
56         }
57 
58     ~TypeReader_Impl()
59         {
60             if (m_copyData && m_pReader)
61             {
62                 delete m_pReader;
63             }
64         }
65 
66     sal_Int32           m_refCount;
67     sal_Bool            m_copyData;
68     sal_Int32           m_blopSize;
69     const sal_uInt8*    m_pBlop;
70     typereg::Reader*    m_pReader;
71 };
72 
73 class TypeReader
74 {
75 /*
76     inline TypeReader(const RegistryTypeReader_Api* pApi,
77                               const sal_uInt8* buffer,
78                               sal_uInt32 bufferLen,
79                               sal_Bool copyData);
80 */
81 public:
82     inline TypeReader()
83         : m_pImpl(NULL)
84     {}
85 
86     inline TypeReader(        const sal_uInt8* buffer,
87                               sal_uInt32 bufferLen,
88                               sal_Bool copyData)
89     {
90         m_pImpl = new TypeReader_Impl(buffer, bufferLen, copyData);
91         acquire();
92     }
93 
94     inline TypeReader(const TypeReader& toCopy)
95         : m_pImpl(toCopy.m_pImpl)
96     {
97         acquire();
98     }
99 
100     inline ~TypeReader()
101     {
102         release();
103     }
104 
105     inline void acquire()
106     {
107         if (m_pImpl)
108             osl_incrementInterlockedCount(&m_pImpl->m_refCount);
109     }
110 
111     inline void release()
112     {
113         if (m_pImpl && 0 == osl_decrementInterlockedCount(&m_pImpl->m_refCount))
114         {
115             delete m_pImpl;
116         }
117     }
118 
119     inline TypeReader& operator = ( const TypeReader& value )
120     {
121         release();
122         m_pImpl = value.m_pImpl;
123         acquire();
124         return *this;
125     }
126 
127     inline sal_Bool         isValid() const
128         {
129             if (m_pImpl)
130                 return m_pImpl->m_pReader->isValid();
131             else
132                 return sal_False;
133         }
134 
135     inline RTTypeClass              getTypeClass() const
136         { return m_pImpl->m_pReader->getTypeClass(); }
137     inline const ::rtl::OString     getTypeName() const
138         { return inGlobalSet( m_pImpl->m_pReader->getTypeName() ); }
139     inline sal_uInt16 getSuperTypeCount() const
140         { return m_pImpl->m_pReader->getSuperTypeCount(); }
141     inline const ::rtl::OString     getSuperTypeName(sal_uInt16 index) const
142         { return inGlobalSet( m_pImpl->m_pReader->getSuperTypeName(index) ); }
143     inline const ::rtl::OString     getDoku() const
144         { return inGlobalSet( m_pImpl->m_pReader->getDocumentation() ); }
145     inline const ::rtl::OString     getFileName() const
146         { return inGlobalSet( m_pImpl->m_pReader->getFileName() ); }
147     inline sal_uInt32               getFieldCount() const
148         { return m_pImpl->m_pReader->getFieldCount(); }
149     inline const ::rtl::OString     getFieldName( sal_uInt16 index ) const
150         { return inGlobalSet( m_pImpl->m_pReader->getFieldName(index) ); }
151     inline const ::rtl::OString     getFieldType( sal_uInt16 index ) const
152         { return inGlobalSet( m_pImpl->m_pReader->getFieldTypeName(index) ); }
153     inline RTFieldAccess            getFieldAccess( sal_uInt16 index ) const
154         { return m_pImpl->m_pReader->getFieldFlags(index); }
155     inline RTConstValue             getFieldConstValue( sal_uInt16 index ) const
156         { return m_pImpl->m_pReader->getFieldValue(index); }
157     inline const ::rtl::OString     getFieldDoku( sal_uInt16 index ) const
158         { return inGlobalSet( m_pImpl->m_pReader->getFieldDocumentation(index) ); }
159     inline const ::rtl::OString     getFieldFileName( sal_uInt16 index ) const
160         { return inGlobalSet( m_pImpl->m_pReader->getFieldFileName(index) ); }
161     inline sal_uInt32               getMethodCount() const
162         { return m_pImpl->m_pReader->getMethodCount(); }
163     inline const ::rtl::OString     getMethodName( sal_uInt16 index ) const
164         { return inGlobalSet( m_pImpl->m_pReader->getMethodName(index) ); }
165     inline sal_uInt32               getMethodParamCount( sal_uInt16 index ) const
166         { return m_pImpl->m_pReader->getMethodParameterCount(index); }
167     inline const ::rtl::OString     getMethodParamType( sal_uInt16 index, sal_uInt16 paramIndex ) const
168         { return inGlobalSet( m_pImpl->m_pReader->getMethodParameterTypeName(index,paramIndex) ); }
169     inline const ::rtl::OString     getMethodParamName( sal_uInt16 index, sal_uInt16 paramIndex ) const
170         { return inGlobalSet( m_pImpl->m_pReader->getMethodParameterName(index,paramIndex) ); }
171     inline RTParamMode              getMethodParamMode( sal_uInt16 index, sal_uInt16 paramIndex ) const
172         { return m_pImpl->m_pReader->getMethodParameterFlags(index,paramIndex); }
173     inline sal_uInt32               getMethodExcCount( sal_uInt16 index ) const
174         { return m_pImpl->m_pReader->getMethodExceptionCount(index); }
175     inline const ::rtl::OString     getMethodExcType( sal_uInt16 index, sal_uInt16 excIndex ) const
176         { return inGlobalSet( m_pImpl->m_pReader->getMethodExceptionTypeName(index,excIndex) ); }
177     inline const ::rtl::OString     getMethodReturnType( sal_uInt16 index ) const
178         { return inGlobalSet( m_pImpl->m_pReader->getMethodReturnTypeName(index) ); }
179     inline RTMethodMode             getMethodMode( sal_uInt16 index ) const
180         { return m_pImpl->m_pReader->getMethodFlags(index); }
181     inline const ::rtl::OString     getMethodDoku( sal_uInt16 index ) const
182         { return inGlobalSet( m_pImpl->m_pReader->getMethodDocumentation(index) ); }
183 
184     inline sal_uInt32               getReferenceCount() const
185         { return m_pImpl->m_pReader->getReferenceCount(); }
186     inline const ::rtl::OString     getReferenceName( sal_uInt16 index ) const
187         { return inGlobalSet( m_pImpl->m_pReader->getReferenceTypeName(index) ); }
188     inline RTReferenceType          getReferenceType( sal_uInt16 index ) const
189         { return m_pImpl->m_pReader->getReferenceSort(index); }
190     inline const ::rtl::OString     getReferenceDoku( sal_uInt16 index ) const
191         { return inGlobalSet( m_pImpl->m_pReader->getReferenceDocumentation(index) ); }
192 
193     inline sal_uInt32 getBlopSize() const
194         { return m_pImpl->m_blopSize; }
195 
196     inline const sal_uInt8* getBlop() const
197         { return m_pImpl->m_pBlop; }
198 
199 private:
200     TypeReader_Impl* m_pImpl;
201 };
202 
203 
204 #endif // _CODEMAKER_REGISTRY_HXX_
205