![]() |
IDL Author's Guide - Rules and Syntax .
Interfaces
:
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
:
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;
};
C++ get and set methods for attributes are automatically declared for attributes in the interface. An attribute name foo generates accessor methods GetFoo and SetFoo. Notice that the first letter of the attribute is changed to uppercase for the accessor method.
XPIDL provides several built-in types. The use of native types is also possible, though this may limit scriptability.
It is possible to use native types in XPIDL by declaring then using the native declaration syntax which works similar to a typedef in C++.
A native type can be given a name using the following syntax:
It is also possible to define reference and pointer types by combining [ref] or [ptr] with native:
Using native types in your code can be a good way to migrate existing interfaces. However, using native types in a method may mean that method is not scriptable.
C-style enumerations are not supported, since the size of enums can be compiler-specific. Instead XPIDL supports defining constants that appear in the C++ and JavaScript mappings. Constants must be of type short or long, and must appear inside an interface declaration. Other types are not supported for constants since they do not map into all languages or have memory management issues. To define a "constant" that is not a short or long, write a method that returns the value, or put the value into an attribute.
[Rules and Syntax] [Best Practices] [Keywords] 1: ``XP'' stands for ``cross-platform'', of course. 2: I crave a better name for this. Mike Shaver and Mike Ang Last modified: Fri Aug 27 19:26:12 PDT 1999 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Copyright © 1998-1999 The Mozilla Organization. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||