|
|
IntroductionThis document describes the C++ representation of UNO IDL types as generated by the
A inline Calling this function you can obtain the meta type of a type, i.e. a value describing
the type. Using this type (reference) you can get comprehensive description of the type
using the C++ runtime ( The // global lnamespace implied const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const Type * ); The UNO IDL character // global namespace implied // header com/sun/star/uno/Type.hxx const ::com::sun::star::uno::Type & SAL_CALL getCppuCharType(); const ::com::sun::star::uno::Type & SAL_CALL getCppuVoidType(); // header com/sun/star/uno/Sequence.hxx const ::com::sun::star::uno::Type & SAL_CALL getCharSequenceCppuType(); The following sections define all types and UNO IDL constructs, which includes the binary memory layout, too. Modules, ConstantsAn IDL module definition is mapped to a C++ namespace with the same name. All IDL type definition within the module are mapped to their corresponding C++ type declarations within the generated namespace. IDL declarations which are not enclosed in any modules are mapped into the C++ global scope. IDL constant groups are mapped to a C++ namespaces with the same name as the constant group. All defined constants in this constant group are mapped to static const variables with type, name and value of the IDL equivalent. Example:
module foo
{
constants group
{
const long BAR = 0xdb0;
};
};
is generated to
file foo/bar.hdl:
namespace foo
{
namespace group
{
static const sal_Int32 BAR = (sal_Int32)0xdb0;
}
}
basic TypesThe binary representation of UNO types is machine (e.g. big-/little-endian), language and operating system dependent. Alignment of data structures complicates even more, and is also processor and bus dependent. The alignment used for C++ UNO types is defined by the following algorithm: Structure members are stored sequentially by the order they are declared. Every data object has an alignment-requirement. For structures, the requirement is the largest size of its members. Every object then has an allocated offset so that offset % alignment-requirement == 0 If it is possible that the maximum alignment-requirement := min( 8, sizeof( type ) ). struct-alignment-requirement := min( 8, sizeof( largest-member-type ) ). The size of the struct is ceiled up to the largest integral member type. In general, if the maximal alignment-requirement := min( max-alignment, sizeof( type ) ). struct-alignment-requirement := min( max-alignment, sizeof( largest-member-type ) ). The size of the struct is ceiled up to the largest integral member type. The following table shows the IDL type, size and layout of the basic C++ UNO specification.
Only 32-Bit C++ UNO is specified and tested for now.
Basic type definitions like
EnumAn IDL enumeration is mapped to a C++ enumeration type ( Example:
module foo
{
enum Bar
{
JOHN, DOE
};
};
is generated to
file foo/Bar.hdl:
namespace foo
{
enum Bar
{
Bar_John = 0,
Bar_DOE = 1,
Bar_MAKE_FIXED_SIZE = SAL_MAX_ENUM
};
}
SequenceC++ UNO sequences are reference counted. The value type of a sequence is handled by
template class
typedef struct _sal_Sequence
{
sal_Int32 nRefCount;
sal_Int32 nElements;
char elements[1];
} sal_Sequence;
typedef sal_Sequence uno_Sequence;
Elements of the sequence follow up directly to the elements array.
API functions to cope with sequences are in header
Sequences are used generically in UNO, i.e. nothing has to be generated for a specific
sequence (e.g. used in an interface method declaration) by the
Header ArrayXXX TODO: The array has yet to be specified, but is in work. Ask Juergen Schmidt for current status. Thus the array specification is not fixed, to give an outlook: It will follow C array specification and generated to a C array of given element type. Arrays will allow multiple dimensions. In contrast to sequences C arrays are not reference counted, thus copying big arrays may be time consuming. Interface
Interfaces are generated to C++ classes having pure virtual member functions
(, e.g.
inline const ::com::sun::star::uno::Type& SAL_CALL getCppuType(
const ::com::sun::star::uno::Reference< generated_C++_class >* )
throw();
Return values are passed as C++ return values, the three different types of parameters are generated as follows:
If the UNO IDL interface declares an attribute, the corresponding C++ class gets a
Any interface method can declare exceptions
that may be thrown upon invocation of it.
Implicitly any method may throw The latter said is valid except for Interface inheritance is similarly adopted to C++ class inheritance.
All interfaces inherit from UNO IDL interface
Example:
module com { module sun { module star { module lang {
interface XMultiServiceFactory: com::sun::star::uno::XInterface
{
com::sun::star::uno::XInterface createInstance(
[in] string aServiceSpecifier )
raises( com::sun::star::uno::Exception );
com::sun::star::uno::XInterface createInstanceWithArguments(
[in] string ServiceSpecifier,
[in] sequence
will be generated to (
namespace com
{
namespace sun
{
namespace star
{
namespace lang
{
class XMultiServiceFactory : public ::com::sun::star::uno::XInterface
{
public:
virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
createInstance( const ::rtl::OUString& aServiceSpecifier )
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) = 0;
virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
createInstanceWithArguments(
const ::rtl::OUString& ServiceSpecifier,
const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Arguments )
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) = 0;
virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
getAvailableServiceNames( )
throw(::com::sun::star::uno::RuntimeException) = 0;
};
} // lang
} // star
} // sun
} // com
Oneway declarations are ignored for C++ bridges, they only affect inter-process bridges.
The macro StructUNO IDL Structs are generated to C++ structs declaring the C++ UNO types and members in the same order. The member names are identical. A default constructor initializing all members to their default values is generated, too. Struct inheritance is adopted to C++ inheritance. Note that the maximal alignment-requirement for structures for the OS/2 and Microsoft Visual C++ compiler is 8.
Example:
module com { module sun { module star { module lang {
struct Locale
{
string Language;
string Country;
string Variant;
};
}; }; }; };
will be generated to (
namespace com
{
namespace sun
{
namespace star
{
namespace lang
{
#ifdef SAL_W32
# pragma pack(push, 8)
#elif defined(SAL_OS2)
# pragma pack(8)
#endif
struct Locale
{
inline Locale();
// inline ctor definition in hpp file
inline Locale(
const ::rtl::OUString& __Language,
const ::rtl::OUString& __Country,
const ::rtl::OUString& __Variant );
::rtl::OUString Language;
::rtl::OUString Country;
::rtl::OUString Variant;
};
#ifdef SAL_W32
# pragma pack(pop)
#elif defined(SAL_OS2)
# pragma pack()
#endif
} // lang
} // star
} // sun
} // com
ExceptionExceptions are generated similarly to structs, meaning
they have identical
binary layout. There is only one minor difference in generation, i.e. exceptions are declared as
C++ classes not as structs. Exception members appear in the
Exceptions need not inherit from any base exception, though UNO API conventions
want any exception ([in-]directly) inherit from
Example:
module com { module sun { module star { module lang {
exception IllegalArgumentException: com::sun::star::uno::Exception
{
short ArgumentPosition;
};
}; }; }; };
will be generated to (
namespace com
{
namespace sun
{
namespace star
{
namespace lang
{
class IllegalArgumentException : public ::com::sun::star::uno::Exception
{
public:
// inline ctor definition in hpp file
inline IllegalArgumentException();
// inline ctor definition in hpp file
inline IllegalArgumentException(
const ::rtl::OUString& __Message,
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& __Context,
const sal_Int16& __ArgumentPosition );
sal_Int16 ArgumentPosition;
};
} // lang
} // star
} // sun
} // com
Union
XXX TODO:
Currently, unions are not supported by the
|


