1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
4 * Copyright (C) 2008 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
25 #include "nsStringAPI.h"
28 /* Project includes */
29 #include "nsStringUtils.h"
31 #include "aaStorageUtils.h"
32 #include "aaSqlFilter.h"
34 aaSqlFilter::aaSqlFilter()
39 aaSqlFilter::~aaSqlFilter()
43 NS_IMPL_ISUPPORTS2(aaSqlFilter
,
44 nsIInterfaceRequestor
,
46 /* nsIInterfaceRequestor */
48 aaSqlFilter::GetInterface(const nsIID
& uuid
, void * *result
)
50 NS_ENSURE_ARG_POINTER(result
);
53 for (i
= 0; i
< mElements
.Count(); i
++) {
54 mElements
[i
]->QueryInterface(uuid
, &tmp
);
61 return NS_NOINTERFACE
;
66 aaSqlFilter::SetInterface(const nsIID
& uuid
, nsISupports
*aInstance
)
68 NS_ENSURE_ARG_POINTER(aInstance
);
71 for (i
= 0; i
< mElements
.Count(); i
++) {
72 mElements
[i
]->QueryInterface(uuid
, &tmp
);
74 mElements
.ReplaceObjectAt(aInstance
, i
);
78 mElements
.AppendObject(aInstance
);
84 aaSqlFilter::Clear(void)
92 aaSqlFilter::AddParam(const nsACString
& name
, nsISupports
* aParamInst
)
94 NS_ENSURE_ARG_POINTER(aParamInst
);
95 NS_ENSURE_TRUE(name
.Length() > 0, NS_ERROR_INVALID_ARG
);
96 if (mParams
.Put(name
, aParamInst
)) {
99 return NS_ERROR_FAILURE
;
103 aaSqlFilter::GetParam(const nsACString
& name
, nsISupports
** _retval
)
105 NS_ENSURE_ARG_POINTER(_retval
);
106 NS_ENSURE_TRUE(name
.Length() > 0, NS_ERROR_INVALID_ARG
);
107 if (mParams
.Get(name
, _retval
)) {
110 return NS_ERROR_FAILURE
;
113 PLDHashOperator
HashTableEnumerator(const nsACString
& name
, nsCOMPtr
<nsISupports
>& ptr
, void* userArg
)
115 aaIParamObserver
* pObserver
= static_cast<aaIParamObserver
*>(userArg
);
116 if (NS_SUCCEEDED(pObserver
->Param(name
, ptr
.get()))) {
117 return PL_DHASH_STOP
;
119 return PL_DHASH_NEXT
;//PLDHashOperator::PL_DHASH_NEXT;
123 aaSqlFilter::Enumerate(aaIParamObserver
* pObserver
)
125 NS_ENSURE_ARG_POINTER(pObserver
);
126 if (mParams
.Enumerate(&HashTableEnumerator
, static_cast<void*>(pObserver
)) > 0) {
129 return NS_ERROR_FAILURE
;