[base] Implement 'fact.appendElement' and 'fact.queryElementAt'
[abstract.git] / base / aaFact.cpp
blobcd45b4e12fa116233d2d397f5344e2cc35b04f76
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: */
3 /*
4 * Copyright (C) 2007 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 <abstract/aacore.h>
24 #include "nsCOMPtr.h"
25 #include "nsStringAPI.h"
26 #include "nsEmbedString.h"
27 #include "nsIMutableArray.h"
28 #include "nsCOMArray.h"
30 /* Project includes */
31 #include <abstract/base/aaIAction.h>
32 #include <abstract/base/aaIFact.h>
33 #include <abstract/storage/aaIQuery.h>
34 #include "aaFact.h"
36 aaFact::aaFact()
37 :mTag((const PRUnichar *) nsnull), mRead(PR_FALSE), mEdited(PR_FALSE)
41 aaFact::~aaFact()
45 NS_IMPL_ISUPPORTS4(aaFact,
46 aaIDataNode,
47 aaIFact,
48 nsIArray,
49 nsIMutableArray)
50 /* aaIDataNode */
51 NS_IMETHODIMP
52 aaFact::GetId(PRInt64 *aId)
54 NS_ENSURE_ARG_POINTER(aId);
55 *aId = mId;
56 return NS_OK;
58 NS_IMETHODIMP
59 aaFact::SetId(PRInt64 aId)
61 mId = aId;
62 return NS_OK;
65 NS_IMETHODIMP
66 aaFact::Accept(aaIQuery* aQuery)
68 NS_ENSURE_ARG_POINTER(aQuery);
69 //return aQuery->QueryFact(this);
70 return NS_ERROR_NOT_IMPLEMENTED;
73 NS_IMETHODIMP
74 aaFact::GetEdited(PRBool* aEdited)
76 NS_ENSURE_ARG_POINTER(aEdited);
77 *aEdited = mEdited;
78 return NS_OK;
81 /* aaIFact */
82 NS_IMETHODIMP
83 aaFact::GetTag(nsAString & aTag)
85 aTag.Assign(mTag);
86 mRead = PR_TRUE;
87 return NS_OK;
89 NS_IMETHODIMP
90 aaFact::SetTag(const nsAString & aTag)
92 if (mTag.Equals(aTag))
93 return NS_OK;
94 if (mRead)
95 mEdited = PR_TRUE;
96 mTag.Assign(aTag);
97 return NS_OK;
100 /* nsIArray */
101 NS_IMETHODIMP
102 aaFact::GetLength(PRUint32 *aLength)
104 return NS_ERROR_NOT_IMPLEMENTED;
107 NS_IMETHODIMP
108 aaFact::QueryElementAt(PRUint32 index, const nsIID & uuid, void * *result)
110 NS_ENSURE_TRUE( index < (PRUint32) mActions.Count(), NS_ERROR_INVALID_ARG);
111 NS_ENSURE_ARG_POINTER( result );
112 return mActions[index]->QueryInterface(uuid, result);
115 NS_IMETHODIMP
116 aaFact::IndexOf(PRUint32 startIndex, nsISupports *element, PRUint32 *_retval)
118 return NS_ERROR_NOT_IMPLEMENTED;
121 NS_IMETHODIMP
122 aaFact::Enumerate(nsISimpleEnumerator **_retval)
124 return NS_ERROR_NOT_IMPLEMENTED;
127 /* nsIMutableArray */
128 NS_IMETHODIMP
129 aaFact::AppendElement(nsISupports *element, PRBool weak)
131 NS_ENSURE_TRUE(! weak, NS_ERROR_NOT_IMPLEMENTED);
132 nsCOMPtr<aaIAction> action(do_QueryInterface( element ));
133 NS_ENSURE_TRUE(action, NS_ERROR_INVALID_ARG);
134 if (mActions.AppendObject(action))
135 return NS_OK;
136 else
137 return NS_ERROR_FAILURE;
140 NS_IMETHODIMP
141 aaFact::RemoveElementAt(PRUint32 index)
143 return NS_ERROR_NOT_IMPLEMENTED;
146 NS_IMETHODIMP
147 aaFact::InsertElementAt(nsISupports *element, PRUint32 index, PRBool weak)
149 return NS_ERROR_NOT_IMPLEMENTED;
152 NS_IMETHODIMP
153 aaFact::ReplaceElementAt(nsISupports *element, PRUint32 index, PRBool weak)
155 return NS_ERROR_NOT_IMPLEMENTED;
158 NS_IMETHODIMP
159 aaFact::Clear()
161 return NS_ERROR_NOT_IMPLEMENTED;