1 |
/*************************************************************************** |
2 |
* Copyright (C) 2005 by Torben Nielsen * |
3 |
* torben@t-hoerup.dk * |
4 |
* * |
5 |
* This program is free software; you can redistribute it and/or modify * |
6 |
* it under the terms of the GNU General Public License as published by * |
7 |
* the Free Software Foundation; either version 2 of the License, or * |
8 |
* (at your option) any later version. * |
9 |
* * |
10 |
* This program is distributed in the hope that it will be useful, * |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 |
* GNU General Public License for more details. * |
14 |
* * |
15 |
* You should have received a copy of the GNU General Public License * |
16 |
* along with this program; if not, write to the * |
17 |
* Free Software Foundation, Inc., * |
18 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 |
***************************************************************************/ |
20 |
#include "containerlist.h" |
21 |
|
22 |
ContainerList::ContainerList(GUIUpdate* update) |
23 |
: SolutionContainer(update) |
24 |
{ |
25 |
total = 0; |
26 |
} |
27 |
|
28 |
|
29 |
ContainerList::~ContainerList() |
30 |
{ |
31 |
} |
32 |
|
33 |
|
34 |
int ContainerList::numSolutions() |
35 |
{ |
36 |
return solutions.size(); |
37 |
} |
38 |
|
39 |
int ContainerList::totalSolutions() |
40 |
{ |
41 |
return total; |
42 |
} |
43 |
|
44 |
|
45 |
void ContainerList::uniqueSolutions() |
46 |
{ |
47 |
for (int i=1;i<=4;i++) { |
48 |
if (m_halt) |
49 |
return; |
50 |
uniqueSolutionsWorker(i,false); |
51 |
uniqueSolutionsWorker(i,true); |
52 |
} |
53 |
} |
54 |
|
55 |
|
56 |
void ContainerList::uniqueSolutionsWorker(int rot,bool mirror) |
57 |
{ |
58 |
int match_count; |
59 |
|
60 |
if (total == -1) |
61 |
total = solutions.size(); |
62 |
|
63 |
for (ListIt i=solutions.begin(); i != solutions.end(); i++) { |
64 |
if (m_halt) |
65 |
return; |
66 |
match_count = 0; |
67 |
|
68 |
std::auto_ptr<Solution> tmp ( (*i)->copy() ); |
69 |
if (mirror) |
70 |
tmp->mirror(); |
71 |
for (int k=0;k<rot;k++) |
72 |
tmp->rotate90(); |
73 |
|
74 |
//unders�g kun resten af m�ngden, start ved i+1 |
75 |
ListIt j =i; |
76 |
j++; |
77 |
for ( ; j!=solutions.end();j++) |
78 |
{ |
79 |
if ( *tmp == *(*j) ) |
80 |
{ |
81 |
solutions.erase(j); |
82 |
m_uniqueRemoved++; |
83 |
m_update->duplicateRemoved(); |
84 |
break; |
85 |
} |
86 |
} |
87 |
} |
88 |
} |
89 |
|
90 |
|
91 |
void ContainerList::addSolution(Solution* sol) |
92 |
{ |
93 |
solutions.push_back(boost::shared_ptr<Solution>(sol)); |
94 |
total++; |
95 |
} |
96 |
|
97 |
Solution* ContainerList::solution(int index) |
98 |
{ |
99 |
int count=0; |
100 |
ListIt it; |
101 |
|
102 |
for (it = solutions.begin(); it != solutions.end(); it++, count++) { |
103 |
if (count == index) { |
104 |
break; |
105 |
} |
106 |
} |
107 |
return (*it).get(); |
108 |
} |