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