From Apache OpenOffice Wiki
Jump to: navigation, search

A struct type defines several elements in a record. The elements of a struct are UNO types with a unique name within the struct. Structs have the disadvantage not to encapsulate data, but the absence of get() and set() methods can help to avoid the overhead of method calls over a UNO bridge. UNO supports single inheritance for struct types. A derived struct recursively inherits all elements of the parent and its parents.

  /** specifies the base for all event objects and identifies the
          source of the event.
  struct EventObject
          /** refers to the object that fired the event.
          com::sun::star::uno::XInterface Source; 
  struct PropertyChangeEvent : com::sun::star::lang::EventObject {
      string PropertyName;
      boolean Further;
      long PropertyHandle;
      any OldValue;
      any NewValue;

A new feature of Apache OpenOffice is the polymorphic struct type. A polymorphic struct type template is similar to a plain struct type, but it has one or more type parameters, and its members can have these parameters as types. A polymorphic struct type template is not itself a UNO type - it has to be instantiated with actual type arguments to be used as a type.

  // A polymorphic struct type template with two type parameters:
  struct Poly<T,U> {
      T member1;
      T member2;
      U member3;
      long member4;
  // Using an instantiation of Poly as a UNO type:
  interface XIfc { Poly<boolean, any> fn(); };

In the example, Poly<boolean, any> will be an instantiated polymorphic struct type with the same form as the plain struct type

  struct PolyBooleanAny { 
      boolean member1;
      boolean member2;
      any member3;
      long member4;

Polymorphic struct types were added primarily to support rich interface type attributes that are as expressive as maybeambiguous, maybedefault, or maybevoid properties (see,,, but they are probably useful in other contexts, too.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages