The Mozilla
Organization
Our Mission
Who We Are
Getting Involved
Community
Editorials
What's New
Newsbot
Development
Roadmap
Module Owners
Blue Sky
Projects
Status
Tools
Products
Source Code
Binaries
Documentation
License Terms
Bug Reports
Quality
Search
Feedback


IDL Author's Guide - Rules and Syntax

XPIDL (XP1 Interface Description Language) is based on the OMG IDL specification, which is used to describe CORBA interfaces. XPIDL is neither a strict superset nor a strict subset of OMG IDL, since we introduce some XPCOM-specific syntax but don't support all elements of OMG IDL syntax. This section describes the rules for describing interfaces in XPIDL. To see the C++ code generated for a given sample, click the [C++].

Interfaces
    An interface is declared with the interface keyword, and the simplest possible interface is as follows:
      interface nsIFoo {
      };
      	
    To specify an interface's parent, follow the interface name with a colon and the parent name:
      interface nsIFoo : nsIParent {
      };
      	
    In XPCOM, all interfaces have an associated IID. Use the identifier attribute syntax to specify the uuid attribute:
      [
          uuid(00000000-0000-0000-c000-000000000046)
      ]
      interface nsIFoo : nsIParent {
      };
      	
    If you wish to have a forward declaration for an interface, simply omit the interface definition and all parent and attribute data:
      interface nsIForward;
              
Methods and Attributes
    An interface can have both methods and attributes. Attributes are properties of interface objects, which can be read and optionally set. The following is an interface with one method (no return value, no parameters) named fun and an integer-valued attribute named attr:
      interface nsIFoo {
          attribute long attr;
          void fun();
      };
            
    Methods can have any number of in, out or inout parameters, with a variety of types. The following interface shows parameters of different types and ``in-out-ness''2:
      interface nsIStringStuff {
        void FindStringLength(in string str, out long l);
        void ConcatenateStrings(in string str1, in string str2,
                                out string result);
        void ReplaceChar(inout string str, in char from, in char to,
                         in boolean foldCase);
      };
             
    You can specify a non-void return type for your method, but you should be aware of the code-generation rules. A non-void return type is converted to a trailing out parameter when the C++ is generated :
      interface nsINonVoidReturn {
        string GimmeString(in string str, in long count);
        long GimmeLong(in boolean prime);
      };
              
    Attributes can be made read-only, by prepending the readonly keyword to the definition :
      interface nsIThing {
        readonly attribute string LookButDontTouch;
      };
              

1: ``XP'' stands for ``cross-platform'', of course.
2: I crave a better name for this.

Mike Shaver
Last modified: Tue Feb 16 07:04:13 EST 1999



Copyright © 1998 The Mozilla Organization.