[storage] Store 'fact.amount' once in 'act' table
[abstract.git] / base / aaEvent.cpp
blobf0d024ffc7848ecf8d3fd90c5c2a373a8e141070
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/aaIFact.h>
32 #include <abstract/base/aaIEvent.h>
33 #include <abstract/base/aaIQuery.h>
34 #include "aaEvent.h"
36 aaEvent::aaEvent()
37 :mTag((const PRUnichar *) nsnull), mHasTime(PR_FALSE), mRead(PR_FALSE),
38 mEdited(PR_FALSE)
43 aaEvent::~aaEvent()
47 NS_IMPL_ISUPPORTS4(aaEvent,
48 aaIDataNode,
49 aaIEvent,
50 nsIArray,
51 nsIMutableArray)
52 /* aaIDataNode */
53 NS_IMETHODIMP
54 aaEvent::GetId(PRInt64 *aId)
56 NS_ENSURE_ARG_POINTER(aId);
57 *aId = mId;
58 return NS_OK;
60 NS_IMETHODIMP
61 aaEvent::SetId(PRInt64 aId)
63 mId = aId;
64 return NS_OK;
67 NS_IMETHODIMP
68 aaEvent::Accept(aaIQuery* aQuery)
70 NS_ENSURE_ARG_POINTER(aQuery);
71 return aQuery->QueryEvent(this);
74 NS_IMETHODIMP
75 aaEvent::GetEdited(PRBool* aEdited)
77 NS_ENSURE_ARG_POINTER(aEdited);
78 *aEdited = mEdited;
79 return NS_OK;
82 /* aaIEvent */
83 NS_IMETHODIMP
84 aaEvent::GetTag(nsAString & aTag)
86 aTag.Assign(mTag);
87 mRead = PR_TRUE;
88 return NS_OK;
90 NS_IMETHODIMP
91 aaEvent::SetTag(const nsAString & aTag)
93 if (mTag.Equals(aTag))
94 return NS_OK;
95 if (mRead)
96 mEdited = PR_TRUE;
97 mTag.Assign(aTag);
98 return NS_OK;
101 NS_IMETHODIMP
102 aaEvent::GetTime(PRTime *aTime)
104 NS_ENSURE_TRUE( mHasTime, NS_ERROR_NOT_INITIALIZED);
105 NS_ENSURE_ARG_POINTER( aTime );
106 *aTime = mTime;
107 return NS_OK;
109 NS_IMETHODIMP
110 aaEvent::SetTime(PRTime aTime)
112 mTime = aTime;
113 mHasTime = PR_TRUE;
114 return NS_OK;
117 /* nsIArray */
118 NS_IMETHODIMP
119 aaEvent::GetLength(PRUint32 *aLength)
121 NS_ENSURE_ARG_POINTER( aLength );
122 *aLength = mFacts.Count();
123 return NS_OK;
126 NS_IMETHODIMP
127 aaEvent::QueryElementAt(PRUint32 index, const nsIID & uuid, void * *result)
129 NS_ENSURE_TRUE( index < (PRUint32) mFacts.Count(), NS_ERROR_INVALID_ARG);
130 NS_ENSURE_ARG_POINTER( result );
131 return mFacts[index]->QueryInterface(uuid, result);
134 NS_IMETHODIMP
135 aaEvent::IndexOf(PRUint32 startIndex, nsISupports *element, PRUint32 *_retval)
137 return NS_ERROR_NOT_IMPLEMENTED;
140 NS_IMETHODIMP
141 aaEvent::Enumerate(nsISimpleEnumerator **_retval)
143 return NS_ERROR_NOT_IMPLEMENTED;
146 /* nsIMutableArray */
147 NS_IMETHODIMP
148 aaEvent::AppendElement(nsISupports *element, PRBool weak)
150 NS_ENSURE_TRUE(! weak, NS_ERROR_NOT_IMPLEMENTED);
151 nsCOMPtr<aaIFact> fact(do_QueryInterface( element ));
152 NS_ENSURE_TRUE(fact, NS_ERROR_INVALID_ARG);
153 if (mFacts.AppendObject(fact))
154 return NS_OK;
155 else
156 return NS_ERROR_FAILURE;
159 NS_IMETHODIMP
160 aaEvent::RemoveElementAt(PRUint32 index)
162 return NS_ERROR_NOT_IMPLEMENTED;
165 NS_IMETHODIMP
166 aaEvent::InsertElementAt(nsISupports *element, PRUint32 index, PRBool weak)
168 return NS_ERROR_NOT_IMPLEMENTED;
171 NS_IMETHODIMP
172 aaEvent::ReplaceElementAt(nsISupports *element, PRUint32 index, PRBool weak)
174 return NS_ERROR_NOT_IMPLEMENTED;
177 NS_IMETHODIMP
178 aaEvent::Clear()
180 return NS_ERROR_NOT_IMPLEMENTED;