00001 /* 00002 * * 00003 * This program is free software; you can redistribute it and/or modify * 00004 * it under the terms of the GNU General Public License as published by * 00005 * the Free Software Foundation; either version 2 of the License, or * 00006 * (at your option) any later version. * 00007 * * 00008 * This program is distributed in the hope that it will be useful, * 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00011 * GNU General Public License for more details. * 00012 * * 00013 * You should have received a copy of the GNU General Public License * 00014 * along with this program; if not, write to the * 00015 * Free Software Foundation, Inc., * 00016 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00017 */ 00018 00019 // $Revision: 1.17 $ 00020 00021 #include "grid.hpp" 00022 #include <iostream> 00023 00024 using namespace std; 00025 00026 00028 00031 Grid::Grid() 00032 { 00033 width = 0; 00034 height = 0; 00035 } 00036 00037 00039 00043 Grid::Grid(int w, int h) 00044 { 00045 width = w; 00046 height = h; 00047 //Main vector 00048 cells.resize(w); 00049 //Vector's vector resizes 00050 for (int i = 0; i < w; i++) 00051 { 00052 cells[i].resize(h); 00053 } 00054 } 00055 00056 00058 00061 Grid::Grid(matrix newList) 00062 { 00063 width = newList.size(); 00064 height = newList[0].size(); 00065 cells = newList; 00066 } 00067 00068 00070 Grid::~Grid() 00071 { 00072 } 00073 00074 00075 //Grid class 00077 00080 void Grid::init(const Grid& grid) 00081 { 00082 width = grid.getWidth(); 00083 height = grid.getHeight(); 00084 cells = grid.getCells(); 00085 } 00086 00087 00089 00092 int Grid::getHeight() const 00093 { 00094 return height; 00095 } 00096 00097 00099 00102 int Grid::getWidth() const 00103 { 00104 return width; 00105 } 00106 00107 00109 00115 bool Grid::isEnabled(int x, int y) 00116 { 00117 return cells[x][y] == nENABLED; 00118 } 00119 00120 00122 00128 bool Grid::isDisabled(int x, int y) 00129 { 00130 return cells[x][y] == nDISABLED; 00131 } 00132 00133 00135 00141 bool Grid::isInput(int x, int y) 00142 { 00143 return cells[x][y] == nINPUT; 00144 } 00145 00146 00148 00154 bool Grid::isOutput(int x, int y) 00155 { 00156 return cells[x][y] == nOUTPUT; 00157 } 00158 00159 00161 00167 bool Grid::isSpace(int x, int y) 00168 { 00169 return cells[x][y] != nNOSPACE; 00170 } 00171 00172 00174 00177 matrix Grid::getCells() const 00178 { 00179 return cells; 00180 } 00181 00182 00184 00192 int& Grid::operator()(int x, int y) 00193 { 00194 return cells[x][y]; 00195 } 00196 00197 00199 00205 bool Grid::operator ==(Grid grid) 00206 { 00207 if (grid.getWidth() != getWidth()) 00208 { 00209 return false; 00210 } 00211 else if (grid.getHeight() != getHeight()) 00212 { 00213 return false; 00214 } 00215 else 00216 { 00217 for (int i = 0; i < getWidth(); i++) 00218 { 00219 for (int j = 0; j < getHeight(); j++) 00220 { 00221 if (cells[i][j] != grid(i, j)) 00222 { 00223 return false; 00224 } 00225 } 00226 } 00227 } 00228 return true; 00229 }