Back to index

lightning-sunbird  0.9+nobinonly
nsMetricsEventItem.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* vim:set ts=2 sw=2 sts=2 et cindent: */
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is the Metrics extension.
00017  *
00018  * The Initial Developer of the Original Code is Google Inc.
00019  * Portions created by the Initial Developer are Copyright (C) 2006
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Brian Ryner <bryner@brianryner.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * 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 
00039 #include "nsMetricsEventItem.h"
00040 #include "nsIPropertyBag.h"
00041 
00042 nsMetricsEventItem::nsMetricsEventItem(const nsAString &itemNamespace,
00043                                        const nsAString &itemName)
00044     : mNamespace(itemNamespace), mName(itemName)
00045 {
00046 }
00047 
00048 nsMetricsEventItem::~nsMetricsEventItem()
00049 {
00050 }
00051 
00052 NS_IMPL_ISUPPORTS1(nsMetricsEventItem, nsIMetricsEventItem)
00053 
00054 NS_IMETHODIMP
00055 nsMetricsEventItem::GetItemNamespace(nsAString &result)
00056 {
00057   result = mNamespace;
00058   return NS_OK;
00059 }
00060 
00061 NS_IMETHODIMP
00062 nsMetricsEventItem::GetItemName(nsAString &result)
00063 {
00064   result = mName;
00065   return NS_OK;
00066 }
00067 
00068 NS_IMETHODIMP
00069 nsMetricsEventItem::GetProperties(nsIPropertyBag **aProperties)
00070 {
00071   NS_IF_ADDREF(*aProperties = mProperties);
00072   return NS_OK;
00073 }
00074 
00075 NS_IMETHODIMP
00076 nsMetricsEventItem::SetProperties(nsIPropertyBag *aProperties)
00077 {
00078   // This do_QueryInterface() shouldn't be necessary, but is needed to avoid
00079   // assertions from nsCOMPtr when an nsIWritablePropertyBag2 is passed in.
00080   mProperties = do_QueryInterface(aProperties);
00081   return NS_OK;
00082 }
00083 
00084 NS_IMETHODIMP
00085 nsMetricsEventItem::ChildAt(PRInt32 index, nsIMetricsEventItem **result)
00086 {
00087   NS_ENSURE_ARG_RANGE(index, 0, PRInt32(mChildren.Length()) - 1);
00088 
00089   NS_ADDREF(*result = mChildren[index]);
00090   return NS_OK;
00091 }
00092 
00093 NS_IMETHODIMP
00094 nsMetricsEventItem::IndexOf(nsIMetricsEventItem *item, PRInt32 *result)
00095 {
00096   *result = PRInt32(mChildren.IndexOf(item));  // NoIndex mapped to -1
00097   return NS_OK;
00098 }
00099 
00100 NS_IMETHODIMP
00101 nsMetricsEventItem::AppendChild(nsIMetricsEventItem *item)
00102 {
00103   NS_ENSURE_ARG_POINTER(item);
00104 
00105   NS_ENSURE_TRUE(mChildren.AppendElement(item), NS_ERROR_OUT_OF_MEMORY);
00106   return NS_OK;
00107 }
00108 
00109 NS_IMETHODIMP
00110 nsMetricsEventItem::InsertChildAt(nsIMetricsEventItem *item, PRInt32 index)
00111 {
00112   NS_ENSURE_ARG_POINTER(item);
00113 
00114   // allow appending
00115   NS_ENSURE_ARG_RANGE(index, 0, PRInt32(mChildren.Length()));
00116 
00117   NS_ENSURE_TRUE(mChildren.InsertElementAt(index, item),
00118                  NS_ERROR_OUT_OF_MEMORY);
00119   return NS_OK;
00120 }
00121 
00122 NS_IMETHODIMP
00123 nsMetricsEventItem::RemoveChildAt(PRInt32 index)
00124 {
00125   NS_ENSURE_ARG_RANGE(index, 0, PRInt32(mChildren.Length()) - 1);
00126 
00127   mChildren.RemoveElementAt(index);
00128   return NS_OK;
00129 }
00130 
00131 NS_IMETHODIMP
00132 nsMetricsEventItem::ReplaceChildAt(nsIMetricsEventItem *newItem, PRInt32 index)
00133 {
00134   NS_ENSURE_ARG_POINTER(newItem);
00135   NS_ENSURE_ARG_RANGE(index, 0, PRInt32(mChildren.Length()) - 1);
00136 
00137   mChildren.ReplaceElementsAt(index, 1, newItem);
00138   return NS_OK;
00139 }
00140 
00141 NS_IMETHODIMP
00142 nsMetricsEventItem::ClearChildren()
00143 {
00144   mChildren.Clear();
00145   return NS_OK;
00146 }
00147 
00148 NS_IMETHODIMP
00149 nsMetricsEventItem::GetChildCount(PRInt32 *childCount)
00150 {
00151   *childCount = PRInt32(mChildren.Length());
00152   return NS_OK;
00153 }