Evita  0.16
evAddress.h
Go to the documentation of this file.
1 /*
2  *
3  * EVITA: Efficient Visualization of Terascale Datasets
4  * Copyright (C) 2000-2016 Team Evita
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library 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  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
19  * MA 02139, USA.
20  *
21  */
22 
23 
24 #ifndef __evAddress_h
25 #define __evAddress_h
26 
27 
28 #include "evDataObject.h"
29 
30 #include <vector>
31 #include <iostream>
32 #include <iterator>
33 #include <numeric>
34 #include <cstdlib>
35 #include <cmath>
36 
37 class evAddress : public evDataObject
38 {
39  public:
40  evAddress(void);
41  evAddress(const unsigned int num_dimensions);
42  evAddress(const evAddress &address);
43  virtual ~evAddress(void)
44  { }
45 
46  virtual const evString GetClassName(void) const
47  {
48  return(evString("evAddress"));
49  }
50 
51  void Set(const int value,
52  const unsigned int dimension);
53 
54  int *Get(void);
55  int Get(const unsigned int dimension) const;
56  int &operator [] (const unsigned int index);
57  const int &operator [] (const unsigned int index) const;
58 
59  unsigned int GetNumDimensions(void) const;
60 
61  evAddress operator = (const evAddress &address);
62  evAddress operator = (const int value);
63  bool operator == (const evAddress &address) const;
64  bool operator != (const evAddress &address) const;
65  bool operator < (const evAddress &address) const;
66 
67  evAddress operator + (const evAddress &address) const;
68  evAddress operator + (const int value) const;
69  evAddress operator - (const evAddress &address) const;
70  evAddress operator - (const int value) const;
71  evAddress &operator += (const evAddress &address);
72  evAddress &operator -= (const evAddress &address);
73 
74  evAddress operator % (const int value) const;
75 
76  void SetIncrementStep(const int increment_step);
77  int GetIncrementStep(void) const;
78 
79  void Increment(const unsigned int dimension);
80  int Increment(const evAddress &max_address);
81  int Increment(const evAddress &max_address,
82  const unsigned int fixed_dimension);
83 
84  int Sum(void) const;
85  int Product(void) const;
86 
87  void Clip(const evAddress *lower_bound,
88  const evAddress *upper_bound);
89 
90  virtual void PrintSelf(const int tabbing) const;
91 
92  protected:
93 
94  private:
95  std::vector<int> Address;
97 };
98 
99 
100 inline evAddress::evAddress(void) :
101  IncrementStep(1)
102 { }
103 
104 
105 inline evAddress::evAddress(const unsigned int num_dimensions) :
106  Address(num_dimensions, 0),
107  IncrementStep(1)
108 { }
109 
110 
111 inline evAddress::evAddress(const evAddress &address) :
112  Address(address.Address),
113  IncrementStep(1)
114 { }
115 
116 
117 inline void evAddress::Set(const int value,
118  const unsigned int dimension)
119 {
120  this->Address[dimension] = value;
121 }
122 
123 
124 inline int *evAddress::Get(void)
125 {
126  return(&(this->Address.front()));
127 }
128 
129 
130 inline int evAddress::Get(const unsigned int dimension) const
131 {
132  return(this->Address[dimension]);
133 }
134 
135 
136 inline int &evAddress::operator [] (const unsigned int index)
137 {
138  return(this->Address[index]);
139 }
140 
141 
142 inline const int &evAddress::operator [] (const unsigned int index) const
143 {
144  return(this->Address[index]);
145 }
146 
147 
148 inline unsigned int evAddress::GetNumDimensions(void) const
149 {
150  return(this->Address.size());
151 }
152 
153 
155 {
156  this->Address = address.Address;
157  return(*this);
158 }
159 
160 
161 inline evAddress evAddress::operator = (const int value)
162 {
163  std::fill(this->Address.begin(),
164  this->Address.end(),
165  value);
166 
167  return(*this);
168 }
169 
170 
171 inline bool evAddress::operator == (const evAddress &address) const
172 {
173  return(this->Address == address.Address);
174 }
175 
176 
177 inline bool evAddress::operator != (const evAddress &address) const
178 {
179  return(!((*this) == address));
180 }
181 
182 
183 inline bool evAddress::operator < (const evAddress &address) const
184 {
185  unsigned int dimension;
186 
187  for (dimension = 0; dimension < this->GetNumDimensions(); dimension++)
188  if (this->Get(dimension) > address.Get(dimension))
189  return(0);
190  else
191  if (this->Get(dimension) < address.Get(dimension))
192  return(1);
193 
194  return(0);
195 }
196 
197 
198 inline void evAddress::SetIncrementStep(const int increment_step)
199 {
200  this->IncrementStep = increment_step;
201 }
202 
203 
204 inline int evAddress::GetIncrementStep(void) const
205 {
206  return(this->IncrementStep);
207 }
208 
209 
210 inline void evAddress::Increment(const unsigned int dimension)
211 {
212  this->Address[dimension] += this->IncrementStep;
213 }
214 
215 
216 inline int evAddress::Increment(const evAddress &max_address)
217 {
218  unsigned int dimension;
219 
220  for (dimension = 0; dimension < this->Address.size(); dimension++)
221  {
222  this->Address[dimension] += this->IncrementStep;
223  if (this->Address[dimension] < max_address.Get(dimension))
224  return(0);
225  this->Address[dimension] = 0;
226  }
227 
228  return(1);
229 }
230 
231 
232 inline int evAddress::Increment(const evAddress &max_address,
233  const unsigned int fixed_dimension)
234 {
235  unsigned int dimension;
236 
237  for (dimension = 0; dimension < this->Address.size(); dimension++)
238  if (dimension != fixed_dimension)
239  {
240  this->Address[dimension] += this->IncrementStep;
241  if (this->Address[dimension] < max_address.Get(dimension))
242  return(0);
243  this->Address[dimension] = 0;
244  }
245 
246  return(1);
247 }
248 
249 
250 inline int evAddress::Sum(void) const
251 {
252  return(std::accumulate(this->Address.begin(), this->Address.end(), 0));
253 }
254 
255 
256 inline int evAddress::Product(void) const
257 {
258  return(std::accumulate(this->Address.begin(), this->Address.end(), 1,
259  std::multiplies<int>()));
260 }
261 
262 
263 inline void evAddress::Clip(const evAddress *lower_bound,
264  const evAddress *upper_bound)
265 {
266  for (unsigned int dimension = 0;
267  dimension < this->Address.size(); dimension++)
268  {
269  int value = this->Get(dimension);
270  if (lower_bound)
271  value = QccMathMax(value,
272  lower_bound->Get(dimension));
273 
274  if (upper_bound)
275  value = QccMathMin(value,
276  upper_bound->Get(dimension));
277 
278  this->Set(value, dimension);
279  }
280 }
281 
282 
283 inline evAddress evAddress::operator + (const evAddress &address) const
284 {
285  unsigned int dimension;
286 
287  if (this->Address.size() != address.Address.size())
288  {
289  evAddress result;
290  return(result);
291  }
292 
293  evAddress result = *this;
294 
295  for (dimension = 0; dimension < this->Address.size(); dimension++)
296  result.Address[dimension] += address.Address[dimension];
297 
298  return(result);
299 }
300 
301 
302 inline evAddress evAddress::operator + (const int value) const
303 {
304  unsigned int dimension;
305 
306  evAddress result = *this;
307 
308  for (dimension = 0; dimension < this->Address.size(); dimension++)
309  result.Address[dimension] += value;
310 
311  return(result);
312 }
313 
314 
315 inline evAddress evAddress::operator - (const evAddress &address) const
316 {
317  unsigned int dimension;
318 
319  if (this->Address.size() != address.Address.size())
320  {
321  evAddress result;
322  return(result);
323  }
324 
325  evAddress result = *this;
326 
327  for (dimension = 0; dimension < this->Address.size(); dimension++)
328  result.Address[dimension] -= address.Address[dimension];
329 
330  return(result);
331 }
332 
333 
334 inline evAddress evAddress::operator - (const int value) const
335 {
336  unsigned int dimension;
337 
338  evAddress result = *this;
339 
340  for (dimension = 0; dimension < this->Address.size(); dimension++)
341  result.Address[dimension] -= value;
342 
343  return(result);
344 }
345 
346 
348 {
349  unsigned int dimension;
350 
351  if (this->Address.size() != address.Address.size())
352  this->Address = std::vector<int>();
353  else
354  for (dimension = 0; dimension < this->Address.size(); dimension++)
355  this->Address[dimension] += address.Address[dimension];
356 
357  return(*this);
358 }
359 
360 
362 {
363  unsigned int dimension;
364 
365 
366  if (this->Address.size() != address.Address.size())
367  this->Address = std::vector<int>();
368  else
369  for (dimension = 0; dimension < this->Address.size(); dimension++)
370  this->Address[dimension] -= address.Address[dimension];
371 
372  return(*this);
373 }
374 
375 
376 inline evAddress evAddress::operator % (const int value) const
377 {
378  evAddress result(this->Address.size());
379 
380  for (unsigned int dimension = 0;
381  dimension < this->Address.size(); dimension++)
382  result.Address[dimension] = this->Address[dimension] % value;
383 
384  return(result);
385 }
386 
387 
388 #endif
void Increment(const unsigned int dimension)
Definition: evAddress.h:210
evAddress operator=(const evAddress &address)
Definition: evAddress.h:154
evAddress operator%(const int value) const
Definition: evAddress.h:376
bool operator!=(const evAddress &address) const
Definition: evAddress.h:177
int GetIncrementStep(void) const
Definition: evAddress.h:204
void Set(const int value, const unsigned int dimension)
Definition: evAddress.h:117
Definition: evAddress.h:37
evAddress(void)
Definition: evAddress.h:100
void SetIncrementStep(const int increment_step)
Definition: evAddress.h:198
bool operator<(const evAddress &address) const
Definition: evAddress.h:183
Definition: evDataObject.h:31
int * Get(void)
Definition: evAddress.h:124
bool operator==(const evAddress &address) const
Definition: evAddress.h:171
virtual void PrintSelf(const int tabbing) const
evAddress & operator-=(const evAddress &address)
Definition: evAddress.h:361
virtual ~evAddress(void)
Definition: evAddress.h:43
evAddress operator+(const evAddress &address) const
Definition: evAddress.h:283
evAddress operator-(const evAddress &address) const
Definition: evAddress.h:315
virtual const evString GetClassName(void) const
Definition: evAddress.h:46
void Clip(const evAddress *lower_bound, const evAddress *upper_bound)
Definition: evAddress.h:263
unsigned int GetNumDimensions(void) const
Definition: evAddress.h:148
std::vector< int > Address
Definition: evAddress.h:95
int IncrementStep
Definition: evAddress.h:96
int Sum(void) const
Definition: evAddress.h:250
int & operator[](const unsigned int index)
Definition: evAddress.h:136
int Product(void) const
Definition: evAddress.h:256
evAddress & operator+=(const evAddress &address)
Definition: evAddress.h:347
Definition: evString.h:30