[storage] Factor out 'recognized amount' (bug #123)
[abstract.git] / base / aaFlow.cpp
blob8ae9b05d01f7b2b920d0cfce51c56d1356e01ade
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"
28 /* Project includes */
29 #include <abstract/base/aaIEntity.h>
30 #include <abstract/base/aaIResource.h>
31 #include <abstract/base/aaIFlow.h>
32 #include <abstract/base/aaIHandler.h>
33 #include "aaFlow.h"
35 aaFlow::aaFlow()
36 :mTag((const PRUnichar *) nsnull), mRead(PR_FALSE), mEdited(PR_FALSE),
37 mRate(1.0), mLimit(0.0)
41 aaFlow::~aaFlow()
45 NS_IMPL_ISUPPORTS2(aaFlow,
46 aaIDataNode,
47 aaIFlow)
48 /* aaIDataNode */
49 NS_IMETHODIMP
50 aaFlow::GetId(PRInt64 *aId)
52 NS_ENSURE_ARG_POINTER(aId);
53 *aId = mId;
54 return NS_OK;
56 NS_IMETHODIMP
57 aaFlow::SetId(PRInt64 aId)
59 mId = aId;
60 return NS_OK;
63 NS_IMETHODIMP
64 aaFlow::Accept(aaIHandler* aQuery)
66 NS_ENSURE_ARG_POINTER(aQuery);
67 return aQuery->HandleFlow(this);
70 NS_IMETHODIMP
71 aaFlow::GetEdited(PRBool* aEdited)
73 NS_ENSURE_ARG_POINTER(aEdited);
74 *aEdited = mEdited;
75 return NS_OK;
78 /* aaIFlow */
79 PRInt64
80 aaFlow::PickId()
82 return mId;
85 NS_IMETHODIMP
86 aaFlow::GetTag(nsAString & aTag)
88 aTag.Assign(mTag);
89 mRead = PR_TRUE;
90 return NS_OK;
92 NS_IMETHODIMP
93 aaFlow::SetTag(const nsAString & aTag)
95 if (mTag.Equals(aTag))
96 return NS_OK;
97 if (mRead)
98 mEdited = PR_TRUE;
99 mTag.Assign(aTag);
100 return NS_OK;
103 NS_IMETHODIMP
104 aaFlow::GetEntity(aaIEntity ** aEntity)
106 NS_ENSURE_ARG_POINTER(aEntity);
107 NS_IF_ADDREF(*aEntity = mEntity);
108 mRead = PR_TRUE;
109 return NS_OK;
111 NS_IMETHODIMP
112 aaFlow::SetEntity(aaIEntity * aEntity)
114 if (mEntity == aEntity)
115 return NS_OK;
116 if (mRead)
117 mEdited = PR_TRUE;
118 mEntity = aEntity;
119 return NS_OK;
122 NS_IMETHODIMP
123 aaFlow::GetGiveResource(aaIResource ** aGiveResource)
125 NS_ENSURE_ARG_POINTER(aGiveResource);
126 NS_IF_ADDREF(*aGiveResource = mGiveResource);
127 mRead = PR_TRUE;
128 return NS_OK;
130 NS_IMETHODIMP
131 aaFlow::SetGiveResource(aaIResource * aGiveResource)
133 if (mGiveResource == aGiveResource)
134 return NS_OK;
135 if (mRead)
136 mEdited = PR_TRUE;
137 mGiveResource = aGiveResource;
138 return NS_OK;
141 NS_IMETHODIMP
142 aaFlow::GetTakeResource(aaIResource ** aTakeResource)
144 NS_ENSURE_ARG_POINTER(aTakeResource);
145 NS_IF_ADDREF(*aTakeResource = mTakeResource);
146 mRead = PR_TRUE;
147 return NS_OK;
149 NS_IMETHODIMP
150 aaFlow::SetTakeResource(aaIResource * aTakeResource)
152 if (mTakeResource == aTakeResource)
153 return NS_OK;
154 if (mRead)
155 mEdited = PR_TRUE;
156 mTakeResource = aTakeResource;
157 return NS_OK;
160 NS_IMETHODIMP
161 aaFlow::GetRate(double *aRate)
163 NS_ENSURE_ARG_POINTER(aRate);
164 *aRate = mRate;
165 mRead = PR_TRUE;
166 return NS_OK;
168 NS_IMETHODIMP
169 aaFlow::SetRate(double aRate)
171 if (mRate == aRate)
172 return NS_OK;
173 if (mRead)
174 mEdited = PR_TRUE;
175 mRate = aRate;
176 return NS_OK;
179 NS_IMETHODIMP
180 aaFlow::GetLimit(double *aLimit)
182 NS_ENSURE_ARG_POINTER(aLimit);
183 *aLimit = mLimit;
184 mRead = PR_TRUE;
185 return NS_OK;
187 NS_IMETHODIMP
188 aaFlow::SetLimit(double aLimit)
190 if (mLimit == aLimit)
191 return NS_OK;
192 if (mRead)
193 mEdited = PR_TRUE;
194 mLimit = aLimit;
195 return NS_OK;