Back to index

lightning-sunbird  0.9+nobinonly
nsIAtom.idl
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998-1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #include "nsISupports.idl"
00039 
00040 %{C++
00041 #include "nsAString.h"
00042 #include "nsCOMPtr.h"
00043 %}
00044 
00045 /*
00046  * Should this really be scriptable?  Using atoms from script or proxies
00047  * could be dangerous since double-wrapping could lead to loss of
00048  * pointer identity.
00049  */
00050  
00051 [scriptable, uuid(3d1b15b0-93b4-11d1-895b-006008911b81)]
00052 interface nsIAtom : nsISupports
00053 {
00057   AString toString(); 
00058   AUTF8String toUTF8String();
00059   
00063   [noscript] void getUTF8String([shared, retval] out string aResult);
00064 
00069   boolean equals(in AString aString);
00070   
00071   boolean equalsUTF8(in AUTF8String aString);
00072 
00073 %{C++
00074   // note this is NOT virtual so this won't muck with the vtable!
00075   inline PRBool Equals(const nsAString& s) {
00076     PRBool result;
00077     Equals(s, &result);
00078     return result;
00079   }
00080 
00081   inline PRBool EqualsUTF8(const nsACString& s) {
00082     PRBool result;
00083     EqualsUTF8(s, &result);
00084     return result;
00085   }
00086 %}
00087   
00088 };
00089 
00090 
00091 %{C++
00092 /*
00093  * The three forms of NS_NewAtom and do_GetAtom (for use with
00094  * |nsCOMPtr<nsIAtom>|) return the atom for the string given.  At any
00095  * given time there will always be one atom representing a given string.
00096  * Atoms are intended to make string comparison cheaper by simplifying
00097  * it to pointer equality.  A pointer to the atom that does not own a
00098  * reference is not guaranteed to be valid.
00099  *
00100  * The three forms of NS_NewPermanentAtom and do_GetPermanentAtom return
00101  * the atom for the given string and ensure that the atom is permanent.
00102  * An atom that is permanent will exist (occupy space at a specific
00103  * location in memory) until XPCOM is shut down.  The advantage of
00104  * permanent atoms is that they do not need to maintain a reference
00105  * count, which requires locking and hurts performance.
00106  */
00107 
00108 
00113 extern NS_COM nsIAtom* NS_NewAtom(const char* aUTF8String);
00114 extern NS_COM nsIAtom* NS_NewPermanentAtom(const char* aUTF8String);
00115 
00116 inline already_AddRefed<nsIAtom> do_GetAtom(const char* aUTF8String)
00117     { return NS_NewAtom(aUTF8String); }
00118 inline already_AddRefed<nsIAtom> do_GetPermanentAtom(const char* aUTF8String)
00119     { return NS_NewPermanentAtom(aUTF8String); }
00120  
00124 extern NS_COM nsIAtom* NS_NewAtom(const nsACString& aUTF8String);
00125 extern NS_COM nsIAtom* NS_NewPermanentAtom(const nsACString& aUTF8String);
00126 
00127 inline already_AddRefed<nsIAtom> do_GetAtom(const nsACString& aUTF8String)
00128     { return NS_NewAtom(aUTF8String); }
00129 inline already_AddRefed<nsIAtom> do_GetPermanentAtom(const nsACString& aUTF8String)
00130     { return NS_NewPermanentAtom(aUTF8String); }
00131 
00136 extern NS_COM nsIAtom* NS_NewAtom(const PRUnichar* aUTF16String);
00137 extern NS_COM nsIAtom* NS_NewPermanentAtom(const PRUnichar* aUTF16String);
00138 
00139 inline already_AddRefed<nsIAtom> do_GetAtom(const PRUnichar* aUTF16String)
00140     { return NS_NewAtom(aUTF16String); }
00141 inline already_AddRefed<nsIAtom> do_GetPermanentAtom(const PRUnichar* aUTF16String)
00142     { return NS_NewPermanentAtom(aUTF16String); }
00143 
00147 extern NS_COM nsIAtom* NS_NewAtom(const nsAString& aUTF16String);
00148 extern NS_COM nsIAtom* NS_NewPermanentAtom(const nsAString& aUTF16String);
00149 
00150 inline already_AddRefed<nsIAtom> do_GetAtom(const nsAString& aUTF16String)
00151     { return NS_NewAtom(aUTF16String); }
00152 inline already_AddRefed<nsIAtom> do_GetPermanentAtom(const nsAString& aUTF16String)
00153     { return NS_NewPermanentAtom(aUTF16String); }
00154 
00159 extern NS_COM nsrefcnt NS_GetNumberOfAtoms(void);
00160 
00161 %}