openModeller
Version 1.4.0
|
00001 /* ************************************** 00002 * GARP Modeling Package 00003 * 00004 * ************************************** 00005 * 00006 * Copyright (c), The Center for Research, University of Kansas, 2385 Irving Hill Road, Lawrence, KS 66044-4755, USA. 00007 * Copyright (C), David R.B. Stockwell of Symbiotik Pty. Ltd. 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the license that is distributed with the software. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * license.txt file included with this software for more details. 00016 */ 00017 00018 // EnvCell.cpp: implementation of the EnvCell class. 00019 // 00021 00022 #include "EnvCell.h" 00023 #include "Utilities.h" 00024 00025 #include <stdio.h> 00026 00027 // ============================================================================ 00028 EnvCell::EnvCell() 00029 { 00030 intCount = 0; 00031 values = NULL; 00032 00033 intPos = -1; 00034 x = y = 0.0; 00035 } 00036 00037 // ============================================================================ 00038 EnvCell::EnvCell(int ct, BYTE * val) 00039 { 00040 intCount = ct; 00041 values = val; 00042 00043 intPos = -1; 00044 x = y = 0.0; 00045 } 00046 00047 // ============================================================================ 00048 EnvCell::EnvCell(int ct, BYTE * val, int pos, double px, double py) 00049 { 00050 intCount = ct; 00051 values = val; 00052 00053 intPos = pos; 00054 x = px; 00055 y = py; 00056 } 00057 00058 // ============================================================================ 00059 EnvCell::~EnvCell() 00060 { 00061 } 00062 00063 // ============================================================================ 00064 void EnvCell::setSize(int newSize) 00065 { 00066 intCount = newSize; 00067 } 00068 00069 // ============================================================================ 00070 int EnvCell::size() 00071 { 00072 return intCount; 00073 } 00074 00075 // ============================================================================ 00076 void EnvCell::setValues(BYTE * newValues) 00077 { 00078 values = newValues; 00079 } 00080 00081 // ============================================================================ 00082 BYTE * EnvCell::getValues() 00083 { 00084 return values; 00085 } 00086 00087 // ============================================================================ 00088 bool EnvCell::operator==(EnvCell oCell) 00089 { 00090 int i; 00091 00092 // if the sizes are different than they are not equal 00093 if (intCount != oCell.intCount) 00094 return false; 00095 00096 // check if the values in both cells are identical 00097 i = 0; 00098 while ((values[i] == oCell.values[i]) && (i < intCount)) 00099 i++; 00100 00101 // if (i == intCount) then all values are equal 00102 // otherwise, the values at index [i] are the first difference found 00103 return (i == intCount); 00104 } 00105 00106 // ============================================================================ 00107 bool EnvCell::operator!=(EnvCell oCell) 00108 { 00109 return !(operator==(oCell)); 00110 } 00111 00112 // ============================================================================ 00113 char * EnvCell::toXML() 00114 { 00115 const int iStringSize = 1024; 00116 00117 char * strXML = new char[iStringSize]; 00118 char strAux[256]; 00119 00120 sprintf(strXML, "<EnvCell Pos=\"%d\" X=\"%f\" Y=\"%f\">", intPos, x, y); 00121 00122 for (int i = 0; i < intCount; i++) 00123 { 00124 sprintf(strAux, "%d ", values[i]); 00125 strcat(strXML, strAux); 00126 } 00127 00128 strcat(strXML, "</EnvCell>\n"); 00129 00130 if (strlen(strXML) > static_cast<int> (iStringSize)) 00131 throw GarpException(82, "String size exceeded in EnvCell::toXML()"); 00132 00133 return strXML; 00134 } 00135 00136 // ============================================================================ 00137 // ============================================================================