Back to index

lightning-sunbird  0.9+nobinonly
nsUCConstructors.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 
00039 
00040 #include "nsUCSupport.h"
00041 #include "nsUCConstructors.h"
00042 
00043 template<class T>
00044 inline NS_METHOD StabilizedQueryInterface(T* aNewObject,
00045                                          REFNSIID aIID,
00046                                          void **aResult)
00047 {
00048     NS_ADDREF(aNewObject);
00049     nsresult rv = aNewObject->QueryInterface(aIID, aResult);
00050     NS_RELEASE(aNewObject);
00051     return rv;
00052 }
00053 
00054 NS_METHOD
00055 CreateMultiTableDecoder(PRInt32 aTableCount, const uRange * aRangeArray, 
00056                         uShiftTable ** aShiftTable,
00057                         uMappingTable ** aMappingTable,
00058                         PRUint32 aMaxLengthFactor,
00059                         nsISupports* aOuter,
00060                         REFNSIID aIID,
00061                         void** aResult)
00062 {
00063 
00064   if (aOuter)
00065     return NS_ERROR_NO_AGGREGATION;
00066   
00067   nsMultiTableDecoderSupport* decoder =
00068     new nsMultiTableDecoderSupport(aTableCount, aRangeArray,
00069                                    aShiftTable, aMappingTable,
00070                                    aMaxLengthFactor);
00071   if (!decoder)
00072     return NS_ERROR_OUT_OF_MEMORY;
00073 
00074   return StabilizedQueryInterface(decoder, aIID, aResult);
00075 }
00076 
00077 NS_METHOD
00078 CreateMultiTableEncoder(PRInt32 aTableCount,
00079                         uShiftTable ** aShiftTable,
00080                         uMappingTable ** aMappingTable,
00081                         PRUint32 aMaxLengthFactor,
00082                         nsISupports* aOuter,
00083                         REFNSIID aIID,
00084                         void** aResult)
00085 {
00086 
00087   if (aOuter)
00088     return NS_ERROR_NO_AGGREGATION;
00089   
00090   nsMultiTableEncoderSupport* encoder =
00091     new nsMultiTableEncoderSupport(aTableCount,
00092                                    aShiftTable, aMappingTable,
00093                                    aMaxLengthFactor);
00094   if (!encoder)
00095     return NS_ERROR_OUT_OF_MEMORY;
00096 
00097   return StabilizedQueryInterface(encoder, aIID, aResult);
00098 }
00099 
00100 NS_METHOD
00101 CreateTableEncoder(uShiftTable * aShiftTable, 
00102                    uMappingTable  * aMappingTable,
00103                    PRUint32 aMaxLengthFactor,
00104                    nsISupports* aOuter,
00105                    REFNSIID aIID,
00106                    void** aResult)
00107 {
00108   if (aOuter)
00109     return NS_ERROR_NO_AGGREGATION;
00110   
00111   nsTableEncoderSupport* encoder =
00112       new nsTableEncoderSupport(aShiftTable, aMappingTable,
00113                                 aMaxLengthFactor);
00114   if (!encoder)
00115     return NS_ERROR_OUT_OF_MEMORY;
00116 
00117   return StabilizedQueryInterface(encoder, aIID, aResult);
00118 }
00119 
00120 NS_METHOD
00121 CreateTableDecoder(uShiftTable * aShiftTable, 
00122                    uMappingTable  * aMappingTable,
00123                    PRUint32 aMaxLengthFactor,
00124                    nsISupports* aOuter,
00125                    REFNSIID aIID,
00126                    void** aResult)
00127 {
00128   if (aOuter)
00129     return NS_ERROR_NO_AGGREGATION;
00130   
00131   nsTableDecoderSupport* decoder =
00132       new nsTableDecoderSupport(aShiftTable, aMappingTable,
00133                                 aMaxLengthFactor);
00134   if (!decoder)
00135     return NS_ERROR_OUT_OF_MEMORY;
00136 
00137   return StabilizedQueryInterface(decoder, aIID, aResult);
00138 }
00139 
00140 NS_METHOD
00141 CreateOneByteDecoder(uShiftTable * aShiftTable, 
00142                      uMappingTable * aMappingTable,
00143                      
00144                      nsISupports* aOuter,
00145                      REFNSIID aIID,
00146                      void** aResult)
00147 {
00148     if (aOuter) return NS_ERROR_NO_AGGREGATION;
00149     
00150     nsOneByteDecoderSupport* decoder =
00151         new nsOneByteDecoderSupport(aShiftTable, aMappingTable);
00152 
00153     if (!decoder)
00154         return NS_ERROR_OUT_OF_MEMORY;
00155     
00156     return StabilizedQueryInterface(decoder, aIID, aResult);
00157 }