storage/src/mozStorageResultSet.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/storage/src/mozStorageResultSet.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "mozStorageRow.h"
    1.11 +#include "mozStorageResultSet.h"
    1.12 +
    1.13 +namespace mozilla {
    1.14 +namespace storage {
    1.15 +
    1.16 +////////////////////////////////////////////////////////////////////////////////
    1.17 +//// ResultSet
    1.18 +
    1.19 +ResultSet::ResultSet()
    1.20 +: mCurrentIndex(0)
    1.21 +{
    1.22 +}
    1.23 +
    1.24 +ResultSet::~ResultSet()
    1.25 +{
    1.26 +  mData.Clear();
    1.27 +}
    1.28 +
    1.29 +nsresult
    1.30 +ResultSet::add(mozIStorageRow *aRow)
    1.31 +{
    1.32 +  return mData.AppendObject(aRow) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
    1.33 +}
    1.34 +
    1.35 +/**
    1.36 + * Note:  This object is only ever accessed on one thread at a time.  It it not
    1.37 + *        threadsafe, but it does need threadsafe AddRef and Release.
    1.38 + */
    1.39 +NS_IMPL_ISUPPORTS(
    1.40 +  ResultSet,
    1.41 +  mozIStorageResultSet
    1.42 +)
    1.43 +
    1.44 +////////////////////////////////////////////////////////////////////////////////
    1.45 +//// mozIStorageResultSet
    1.46 +
    1.47 +NS_IMETHODIMP
    1.48 +ResultSet::GetNextRow(mozIStorageRow **_row)
    1.49 +{
    1.50 +  NS_ENSURE_ARG_POINTER(_row);
    1.51 +
    1.52 +  if (mCurrentIndex >= mData.Count()) {
    1.53 +    // Just return null here
    1.54 +    return NS_OK;
    1.55 +  }
    1.56 +
    1.57 +  NS_ADDREF(*_row = mData.ObjectAt(mCurrentIndex++));
    1.58 +  return NS_OK;
    1.59 +}
    1.60 +
    1.61 +} // namespace storage
    1.62 +} // namespace mozilla

mercurial