Difference between revisions of "Documentation/DevGuide/ProUNO/Structs"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Documentation/Developers Guide/Professional UNO)
m (FINAL VERSION FOR L10N)
(One intermediate revision by one other user not shown)
Line 6: Line 6:
 
|NextPage=Documentation/DevGuide/ProUNO/Predefined Values
 
|NextPage=Documentation/DevGuide/ProUNO/Predefined Values
 
}}
 
}}
 +
{{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:Structs}}
 
{{DISPLAYTITLE:Structs}}
 
A <code>struct</code> 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 <code>get()</code> and <code>set()</code> methods can help to avoid the overhead of method calls over a UNO bridge. UNO supports single inheritance for struct types. A derived <code>struct</code> recursively inherits all elements of the parent and its parents.
 
A <code>struct</code> 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 <code>get()</code> and <code>set()</code> methods can help to avoid the overhead of method calls over a UNO bridge. UNO supports single inheritance for struct types. A derived <code>struct</code> recursively inherits all elements of the parent and its parents.

Revision as of 07:55, 13 May 2009



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.

  // com.sun.star.lang.EventObject
  /** 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; 
 
  }; 
 
  // com.sun.star.beans.PropertyChangeEvent
  struct PropertyChangeEvent : com::sun::star::lang::EventObject {
      string PropertyName;
      boolean Further;
      long PropertyHandle;
      any OldValue;
      any NewValue;
  };

A new feature of OpenOffice.org2.0 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 com.sun.star.beans.Ambiguous, com.sun.star.beans.Defaulted, com.sun.star.beans.Optional), 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