Main Page | Class List | File List | Class Members | Related Pages

townarray.cpp

00001 /***************************************************************************
00002                            townarray.cpp
00003                            -------------------
00004     begin                : 2005-01-16
00005     copyright            : (C) 2005 by Dominik Haumann
00006     email                : dhaumann@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  This program is free software; you can redistribute it and/or
00011  modify it under the terms of the GNU General Public License
00012  as published by the Free Software Foundation; either version 2
00013  of the License, or (at your option) any later version.
00014 
00015  This program is distributed in the hope that it will be useful,
00016  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  GNU General Public License for more details.
00019 
00020  You should have received a copy of the GNU General Public License
00021  along with this program; if not, write to the Free Software
00022  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023  ***************************************************************************/
00024 
00025 #include "townarray.h"
00026 
00027 namespace WDS
00028 {
00029 
00030 CTownArray::CTownArray()
00031 {
00032 }
00033 
00034 CTownArray::~CTownArray()
00035 {
00036     clear();
00037 }
00038 
00039 CTown* CTownArray::get(int x, int y)
00040 {
00041     TownArray::iterator it1 =  m_towns.find(x);
00042 
00043     if ( it1 != m_towns.end() ) {
00044         map <int, CTown*>::iterator it2 = it1->second.find(y);
00045 
00046         if ( it2 != it1->second.end() ) {
00047             return it2->second;
00048         }
00049     }
00050 
00051     return 0L;
00052 }
00053 
00054 void CTownArray::set(int x, int y, CTown town)
00055 {
00056     CTown* entry = m_towns[x][y];
00057 
00058     if ( entry == 0L )
00059         m_towns[x][y] = new CTown(town);
00060     else *m_towns[x][y] = town;
00061 }
00062 
00063 void CTownArray::erase(int x, int y)
00064 {
00065     TownArray::iterator it1 = m_towns.find(x);
00066 
00067     if ( it1 != m_towns.end() ) {
00068         map <int, CTown*>::iterator it2 = it1->second.find(y);
00069 
00070         if ( it2 != it1->second.end() ) {
00071             delete it2->second;
00072 
00073             it1->second.erase(it2);
00074 
00075             if ( it1->second.size() == 0 ) {
00076                 m_towns.erase(it1);
00077             }
00078         }
00079     }
00080 }
00081 
00082 void CTownArray::clear()
00083 {
00084     TownArray::iterator it1 = m_towns.begin();
00085 
00086     while ( it1 != m_towns.end() ) {
00087         map <int, CTown*>::iterator it2 = it1->second.begin();
00088 
00089         while ( it2 != it1->second.end() ) {
00090             delete it2->second;
00091 
00092             it2++;
00093         }
00094 
00095         it1++;
00096     }
00097     m_towns.clear();
00098 }
00099 
00100 unsigned int CTownArray::size()
00101 {
00102     int s = 0;
00103 
00104     TownArray::iterator it1 = m_towns.begin();
00105 
00106     while ( it1 != m_towns.end() ) {
00107         s += it1->second.size();
00108 
00109         it1++;
00110     }
00111 
00112     return s;
00113 }
00114 
00115 CTown* CTownArray::firstSibling()
00116 {
00117     m_first = m_towns.begin();
00118     while ( m_first != m_towns.end() ) {
00119         m_second = m_first->second.begin();
00120 
00121         if ( m_second != m_first->second.end() ) {
00122             return m_second->second;
00123         }
00124 
00125         m_first++;
00126     }
00127 
00128     return 0L;
00129 }
00130 
00131 CTown* CTownArray::nextSibling()
00132 {
00133     if ( m_first == m_towns.end() ) {
00134         return 0L;
00135     } else {
00136         if ( m_second != m_first->second.end() ) {
00137             m_second++;
00138             if ( m_second != m_first->second.end() ) {
00139                 return m_second->second;
00140             } else {
00141                 return nextSibling();
00142             }
00143         } else {
00144             m_first++;
00145             if ( m_first != m_towns.end() ) {
00146                 m_second = m_first->second.begin();
00147                 if ( m_second != m_first->second.end() ) {
00148                     return m_second->second;
00149                 } else {
00150                     return nextSibling();
00151                 }
00152             } else {
00153                 return 0L;
00154             }
00155         }
00156     }
00157 
00158     return 0L;
00159 }
00160 
00161 }
00162 
00163 // kate: space-indent off; tab-width 4; replace-tabs off;

Generated on Sun Jan 16 18:20:26 2005 for WDSMap by  doxygen 1.3.9.1