IT翻訳 Nobuyuki の仕事部屋

ボランティアでソフトウエアーローカライズのために翻訳をしている。

Mozilla DOM Hacking Guide: Introduction to XPCOM10

2006-01-19 23:18:31 | InDraft
人気のない仕事部屋。ウウーツ、寒い。パソコンのドライブのパネルが冷たいよ。”冬将軍、やはりあなたは強かった!”(・_・、

----------------------------------------

原文:  青色表示
訳文:  黒色表示
注記/訂正: 赤色表示

At the beginning of this section, I talked about a second solution to get a pointer to an interface. This should be used in the case a getter function is not available. As you probably know, the "this" member of an object is a pointer to that object. You can thus simply cast "this" statically to the desired interface. You should however be absolutely sure of what you are doing before coding such a cast. It can lead to troubles with refcounting.

この節の始めに、インターフェイスへのポインタを取得する 2 つ目の方法について話しました。これは、getter 関数が有効でない場合に使われるはずです。おそらくご存知でしょうが、オブジェクトの”this”メンバはそのオブジェクトへのポインタです。そこで必要なインターフェイスへ static に”this”を単にキャストできます。しかしキャストする前にご自分の処理が絶対間違いようにしてください。間違いがあれば参照カウントで問題が発生します。

Here is a simple problem I encountered recently: In a member function of the nsHTMLAnchorElement class, I had to get a pointer to the nsIContent interface implemented by the nsHTMLAnchorElement object. However there is no such getter. I had to use the second solution:

nsCOMPtr content = getter_AddRefs(NS_STATIC_CAST(nsIContent*, this));
// Or, if you want to do the refcounting yourself,
nsIContent *content = NS_STATIC_CAST(nsIContent*, this);


最近遭遇した問題の例を紹介します: nsHTMLAnchorElement クラスのメンバ関数で、nsHTMLAnchorElement オブジェクトによって実装された nsIContent インターフェイスへのポインタを取得する必要がありました。しかし、getter 関数がなかったので 2 つ目の方法を使わなければなりませんでした:

nsCOMPtr content = getter_AddRefs(NS_STATIC_CAST(nsIContent*, this));
// または自分自身をカウントしたいならば、
nsIContent *content = NS_STATIC_CAST(nsIContent*, this);


The second form should be used with care, and is recommended only for advanced XPCOM'ers.

この 2 つめの構文は注意して扱われる必要があり、XPCOM プログラマーの上級者だけに推奨されます。


The use of XPCOM and nsCOMPtr's described until now covers about 80% of what you need to know to read the code, and even write some. I could go on about do_GetService, explain the implementation of QueryInterface, etc, but I feel this is not worth the trouble. For the more advanced topics of XPCOM, please see the XPCOM project page.

ここまでに解説しました XPCOM と nsCOMPtr の使用方法はコードを読んだり少しでも書くのに必要な知識の 80% をカバーしています。引き続き do_GetService へ進んで、QueryInterface などの実装を説明できますが、そこまでする必要があると思いません。そこで XPCOM のさらに詳しい内容については XPCOM プロジェクト頁を参照してください。


The next section is a tutorial on how to add a new interface to the Mozilla DOM, with build instructions et al, and the last section is a discussion of the more advanced topics of object-oriented C++, interface inheritance, and other fun stuff.

次の節は Mozilla DOM へ新しいインターフェイスを追加する方法に関するチュートリアルであり、ビルドの解説やその他を含みます。最後の節はオブジェクト指向の C++ 、インターフェイスの継承、その他面白いトピックに関する詳細の内容についての議論になっています。

これでとてもとても長かった QueryInterface() の節を終わります。
See you at the next section.(^Q^)/"