Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_REGISTRY_WRITER_HXX
21 : #define INCLUDED_REGISTRY_WRITER_HXX
22 :
23 : #include <registry/writer.h>
24 : #include <registry/refltype.hxx>
25 : #include <registry/types.h>
26 : #include <registry/version.h>
27 :
28 : #include <rtl/ustring.hxx>
29 : #include <sal/types.h>
30 :
31 : #include <new>
32 :
33 : namespace typereg {
34 :
35 : /**
36 : A type writer working on a binary blob that represents a UNOIDL type.
37 :
38 : <p>Instances of this class are not multi-thread–safe.</p>
39 :
40 : @since UDK 3.2.0
41 : */
42 : class Writer {
43 : public:
44 : /**
45 : Creates a type writer.
46 :
47 : @param version the version of the created type writer; must not be
48 : negative
49 :
50 : @param documentation the documentation
51 :
52 : @param fileName the file name (deprecated, use an empty string)
53 :
54 : @param typeClass the type class of the created type writer
55 :
56 : @param published whether the created type writer is published; for a type
57 : class that cannot be published, this should be false
58 :
59 : @param typeName the type name of the created type writer
60 :
61 : @param superTypeCount the number of super types of the created type
62 : writer
63 :
64 : @param fieldCount the number of fields of the created type writer
65 :
66 : @param methodCount the number of methods of the created type writer
67 :
68 : @param referenceCount the number of references of the created type writer
69 :
70 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
71 : */
72 1074 : Writer(
73 : typereg_Version version, rtl::OUString const & documentation,
74 : rtl::OUString const & fileName, RTTypeClass typeClass, bool published,
75 : rtl::OUString const & typeName, sal_uInt16 superTypeCount,
76 : sal_uInt16 fieldCount, sal_uInt16 methodCount,
77 : sal_uInt16 referenceCount):
78 : m_handle(
79 : typereg_writer_create(
80 : version, documentation.pData, fileName.pData, typeClass,
81 : published, typeName.pData, superTypeCount, fieldCount,
82 1074 : methodCount, referenceCount))
83 : {
84 1074 : if (m_handle == 0) {
85 0 : throw std::bad_alloc();
86 : }
87 1074 : }
88 :
89 : /**
90 : Destroys this <code>Writer</code> instance.
91 : */
92 1074 : ~Writer() {
93 1074 : typereg_writer_destroy(m_handle);
94 1074 : }
95 :
96 : /**
97 : Sets the type name of a super type of this type writer.
98 :
99 : @param index a valid index into the range of super types of this type
100 : writer
101 :
102 : @param typeName the super type name
103 :
104 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
105 : */
106 360 : void setSuperTypeName(sal_uInt16 index, rtl::OUString const & typeName) {
107 360 : if (!typereg_writer_setSuperTypeName(m_handle, index, typeName.pData)) {
108 0 : throw std::bad_alloc();
109 : }
110 360 : }
111 :
112 : /**
113 : Sets the data of a field of this type writer.
114 :
115 : @param index a valid index into the range of fields of this type writer
116 :
117 : @param documentation the documentation of the field
118 :
119 : @param fileName the file name of the field (deprecated, use an empty string)
120 :
121 : @param flags the flags of the field
122 :
123 : @param name the name of the field
124 :
125 : @param typeName the type name of the field
126 :
127 : @param value the value of the field
128 :
129 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
130 : */
131 346 : void setFieldData(
132 : sal_uInt16 index, rtl::OUString const & documentation,
133 : rtl::OUString const & fileName, RTFieldAccess flags, rtl::OUString const & name,
134 : rtl::OUString const & typeName, RTConstValue const & value)
135 : {
136 346 : if (!typereg_writer_setFieldData(
137 : m_handle, index, documentation.pData, fileName.pData, flags,
138 346 : name.pData, typeName.pData, value.m_type, value.m_value))
139 : {
140 0 : throw std::bad_alloc();
141 : }
142 346 : }
143 :
144 : /**
145 : Sets the data of a method of this type writer.
146 :
147 : @param index a valid index into the range of methods of this type writer
148 :
149 : @param documentation the documentation of the method
150 :
151 : @param flags the flags of the method
152 :
153 : @param name the name of the method
154 :
155 : @param returnTypeName the return type name of the method
156 :
157 : @param parameterCount the number of parameters of the method
158 :
159 : @param exceptionCount the number of exceptions of the method
160 :
161 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
162 : */
163 108 : void setMethodData(
164 : sal_uInt16 index, rtl::OUString const & documentation,
165 : RTMethodMode flags, rtl::OUString const & name,
166 : rtl::OUString const & returnTypeName, sal_uInt16 parameterCount,
167 : sal_uInt16 exceptionCount)
168 : {
169 108 : if (!typereg_writer_setMethodData(
170 : m_handle, index, documentation.pData, flags, name.pData,
171 108 : returnTypeName.pData, parameterCount, exceptionCount))
172 : {
173 0 : throw std::bad_alloc();
174 : }
175 108 : }
176 :
177 : /**
178 : Sets the data of a parameter of a method of this type writer.
179 :
180 : @param methodIndex a valid index into the range of methods of this type
181 : writer
182 :
183 : @param parameterIndex a valid index into the range of parameters of the
184 : given method
185 :
186 : @param flags the flags of the parameter
187 :
188 : @param name the name of the parameter
189 :
190 : @param typeName the type name of the parameter
191 :
192 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
193 : */
194 42 : void setMethodParameterData(
195 : sal_uInt16 methodIndex, sal_uInt16 parameterIndex,
196 : RTParamMode flags, rtl::OUString const & name,
197 : rtl::OUString const & typeName)
198 : {
199 42 : if (!typereg_writer_setMethodParameterData(
200 : m_handle, methodIndex, parameterIndex, flags, name.pData,
201 42 : typeName.pData))
202 : {
203 0 : throw std::bad_alloc();
204 : }
205 42 : }
206 :
207 : /**
208 : Sets an exception type name of a method of this type writer.
209 :
210 : @param methodIndex a valid index into the range of methods of this type
211 : writer
212 :
213 : @param exceptionIndex a valid index into the range of exceptions of the
214 : given method
215 :
216 : @param typeName the exception type name
217 :
218 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
219 : */
220 40 : void setMethodExceptionTypeName(
221 : sal_uInt16 methodIndex, sal_uInt16 exceptionIndex,
222 : rtl::OUString const & typeName)
223 : {
224 40 : if (!typereg_writer_setMethodExceptionTypeName(
225 40 : m_handle, methodIndex, exceptionIndex, typeName.pData))
226 : {
227 0 : throw std::bad_alloc();
228 : }
229 40 : }
230 :
231 : /**
232 : Sets the data of a reference of this type writer.
233 :
234 : @param index a valid index into the range of references of this type
235 : writer
236 :
237 : @param documentation the documentation of the reference
238 :
239 : @param sort the sort of the reference
240 :
241 : @param flags the flags of the reference
242 :
243 : @param typeName the type name of the reference
244 :
245 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
246 : */
247 118 : void setReferenceData(
248 : sal_uInt16 index, rtl::OUString const & documentation,
249 : RTReferenceType sort, RTFieldAccess flags,
250 : rtl::OUString const & typeName)
251 : {
252 118 : if (!typereg_writer_setReferenceData(
253 : m_handle, index, documentation.pData, sort, flags,
254 118 : typeName.pData))
255 : {
256 0 : throw std::bad_alloc();
257 : }
258 118 : }
259 :
260 : /**
261 : Returns the blob of this type writer.
262 :
263 : @param size an out-parameter obtaining the size of the blob
264 :
265 : @return a (byte-aligned) pointer to the blob; the returned pointer and
266 : the returned <code>size</code> remain valid until the next function is
267 : called on this type writer
268 :
269 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
270 : (in which case <code>siez</code> is not modified
271 : */
272 1074 : void const * getBlob(sal_uInt32 * size) {
273 1074 : void const * p = typereg_writer_getBlob(m_handle, size);
274 1074 : if (p == 0) {
275 0 : throw std::bad_alloc();
276 : }
277 1074 : return p;
278 : }
279 :
280 : private:
281 : Writer(Writer &); // not implemented
282 : void operator =(Writer); // not implemented
283 :
284 : void * m_handle;
285 : };
286 :
287 : }
288 :
289 : #endif
290 :
291 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|