openModeller  Version 1.5.0
EnvCell.cpp
Go to the documentation of this file.
1 /* **************************************
2  * GARP Modeling Package
3  *
4  * **************************************
5  *
6  * Copyright (c), The Center for Research, University of Kansas, 2385 Irving Hill Road, Lawrence, KS 66044-4755, USA.
7  * Copyright (C), David R.B. Stockwell of Symbiotik Pty. Ltd.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the license that is distributed with the software.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * license.txt file included with this software for more details.
16  */
17 
18 // EnvCell.cpp: implementation of the EnvCell class.
19 //
21 
22 #include "EnvCell.h"
23 #include "Utilities.h"
24 
25 #include <stdio.h>
26 
27 // ============================================================================
29 {
30  intCount = 0;
31  values = NULL;
32 
33  intPos = -1;
34  x = y = 0.0;
35 }
36 
37 // ============================================================================
38 EnvCell::EnvCell(int ct, BYTE * val)
39 {
40  intCount = ct;
41  values = val;
42 
43  intPos = -1;
44  x = y = 0.0;
45 }
46 
47 // ============================================================================
48 EnvCell::EnvCell(int ct, BYTE * val, int pos, double px, double py)
49 {
50  intCount = ct;
51  values = val;
52 
53  intPos = pos;
54  x = px;
55  y = py;
56 }
57 
58 // ============================================================================
60 {
61 }
62 
63 // ============================================================================
64 void EnvCell::setSize(int newSize)
65 {
66  intCount = newSize;
67 }
68 
69 // ============================================================================
71 {
72  return intCount;
73 }
74 
75 // ============================================================================
76 void EnvCell::setValues(BYTE * newValues)
77 {
78  values = newValues;
79 }
80 
81 // ============================================================================
83 {
84  return values;
85 }
86 
87 // ============================================================================
89 {
90  int i;
91 
92  // if the sizes are different than they are not equal
93  if (intCount != oCell.intCount)
94  return false;
95 
96  // check if the values in both cells are identical
97  i = 0;
98  while ((values[i] == oCell.values[i]) && (i < intCount))
99  i++;
100 
101  // if (i == intCount) then all values are equal
102  // otherwise, the values at index [i] are the first difference found
103  return (i == intCount);
104 }
105 
106 // ============================================================================
108 {
109  return !(operator==(oCell));
110 }
111 
112 // ============================================================================
114 {
115  const int iStringSize = 1024;
116 
117  char * strXML = new char[iStringSize];
118  char strAux[256];
119 
120  sprintf(strXML, "<EnvCell Pos=\"%d\" X=\"%f\" Y=\"%f\">", intPos, x, y);
121 
122  for (int i = 0; i < intCount; i++)
123  {
124  sprintf(strAux, "%d ", values[i]);
125  strcat(strXML, strAux);
126  }
127 
128  strcat(strXML, "</EnvCell>\n");
129 
130  if (strlen(strXML) > static_cast<int> (iStringSize))
131  throw GarpException(82, "String size exceeded in EnvCell::toXML()");
132 
133  return strXML;
134 }
135 
136 // ============================================================================
137 // ============================================================================
EnvCell()
Definition: EnvCell.cpp:28
char * toXML()
Definition: EnvCell.cpp:113
BYTE * values
Definition: EnvCell.h:32
void setSize(int newSize)
Definition: EnvCell.cpp:64
bool operator!=(EnvCell oCell)
Definition: EnvCell.cpp:107
unsigned char BYTE
Definition: Utilities.h:36
int intCount
Definition: EnvCell.h:31
int intPos
Definition: EnvCell.h:35
BYTE * getValues()
Definition: EnvCell.cpp:82
virtual ~EnvCell()
Definition: EnvCell.cpp:59
double x
Definition: EnvCell.h:36
double y
Definition: EnvCell.h:36
bool operator==(EnvCell oCell)
Definition: EnvCell.cpp:88
void setValues(BYTE *newValues)
Definition: EnvCell.cpp:76
int size()
Definition: EnvCell.cpp:70