cross.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (C) 2005 Eliot
00003  * Authors: Olivier Teuliere  <ipkiss@via.ecp.fr>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  *****************************************************************************/
00019 
00020 #include "cross.h"
00021 
00022 
00023 Cross::Cross()
00024 {
00025     // the default behaviour is to match everything
00026     m_any = true;
00027 }
00028 
00029 
00030 void Cross::clear()
00031 {
00032     m_tilesSet.clear();
00033     m_any = false;
00034 }
00035 
00036 
00037 bool Cross::check(const Tile& iTile) const
00038 {
00039     if (m_any || (iTile.isJoker() && !m_tilesSet.empty()))
00040         return true;
00041     set<Tile>::const_iterator it = m_tilesSet.find(iTile);
00042     return it != m_tilesSet.end();
00043 }
00044 
00045 
00046 bool Cross::operator==(const Cross &iOther) const
00047 {
00048     if (isAny() && iOther.isAny())
00049         return true;
00050     // Two sets are equal if they have the same size and one of them contains
00051     // the other one
00052     if (m_tilesSet.size() == iOther.m_tilesSet.size())
00053     {
00054         set<Tile>::const_iterator it;
00055         for (it = m_tilesSet.begin(); it != m_tilesSet.end(); it++)
00056         {
00057             if (!iOther.check(*it))
00058                 return false;
00059         }
00060         return true;
00061     }
00062     else
00063         return false;
00064 }
00065 
00066 /// Local Variables:
00067 /// mode: c++
00068 /// mode: hs-minor
00069 /// c-basic-offset: 4
00070 /// indent-tabs-mode: nil
00071 /// End:

Generated on Thu Dec 29 02:01:14 2005 for Eliot by  doxygen 1.4.5