54{
55 FakeOne *person1, *person2, *person3;
57
58
59
60 person1 =
new FakeOne(
"Jack Tripper", 654);
61 person2 =
new FakeOne(
"Richard Kanningam", 456);
62 person3 =
new FakeOne(
"Dana Scully", 231);
63
64 location1 =
new FakeTwo(
"531 Stanford Avenue", 2);
65 location2 =
new FakeTwo(
"520 Cowper Street", 3);
66
67
68
74
75
76
77
78
79
80
83
84
85 std::vector< Relation<FakeOne, FakeTwo>* > empty = tab.
getRelByFirst(person1);
86 std::cout << "Querying and empty table the size of the returned vector is "
87 << empty.size() << std::endl;
88
89
95
96
97
98
99
101
102
103
104 std::vector< Relation<FakeOne, FakeTwo>* >::iterator i;
105
106
107 std::vector< Relation<FakeOne, FakeTwo>* > locs = tab.
getRelByFirst(person1);
108
109 std::cout << std::endl << person1->
name << std::endl;
110 for (i = locs.begin(); i != locs.end(); i++)
111 {
112 std::cout << "Address: " << (*i)->getSecond()->address
113 << " Floor: " << (*i)->getSecond()->floor
114 << " Date : " << (*i)->getInfos()[0] << std::endl;
115 }
116
117
118 std::vector< Relation<FakeOne, FakeTwo>* > pers = tab.
getRelBySecond(location2);
119
120 std::cout << std::endl << location2->
address << std::endl;
121 for (i = pers.begin(); i != pers.end(); i++)
122 {
123 std::cout << "Name: " << (*i)->getFirst()->name
124 << " ssn: " << (*i)->getFirst()->ssn << std::endl;
125 }
126
127
128
129
130
132 for (i = locs.begin(); i != locs.end(); i++)
133 {
135 }
136
137 std::cout << std::endl << "persion3 location changed" << std::endl;
138 std::cout << std::endl << location2->
address << std::endl;
139
141 for (i = pers.begin(); i != pers.end(); i++)
142 {
143 std::cout << "Name: " << (*i)->getFirst()->name
144 << " ssn: " << (*i)->getFirst()->ssn << std::endl;
145 }
146
147
148
150
151 for (i = locs.begin(); i != locs.end(); i++)
152 {
154 }
155
156 std::cout << std::endl << "Jack Tripper set to null" << std::endl;
157
158
159
160
162
163 std::cout << "Number of relations with location2 = " << pers.size() << std::endl;
164
165 std::cout << std::endl << location2->
address << std::endl;
166 for (i = pers.begin(); i != pers.end(); i++)
167 {
168 if ((*i)->getFirst())
169 std::cout << "Name: " << (*i)->getFirst()->name
170 << " ssn: " << (*i)->getFirst()->ssn << std::endl;
171 }
172
173
174
175
177 for (i = pers.begin(); i != pers.end(); i++)
178 {
180 }
181
182 std::cout << std::endl << "Removed relations with null pointer" << std::endl;
183 std::cout <<
"Number of relations = " << tab.
size() << std::endl;
184 std::cout << std::endl << location2->
address << std::endl;
185
187 for (i = pers.begin(); i != pers.end(); i++)
188 {
189 std::cout << "Name: " << (*i)->getFirst()->name
190 << " ssn: " << (*i)->getFirst()->ssn << std::endl;
191 }
192
193
194
195 std::cout << std::endl << person2->
name << std::endl;
196
197
198 unsigned int index;
199
201 for (i = locs.begin(); i != locs.end(); i++)
202 {
203 std::cout << "Address: " << (*i)->getSecond()->address << std::endl;
204 std::cout << "Floor: " << (*i)->getSecond()->floor << std::endl;
205 std::cout << "Dates : " << std::endl;
206 for ( index = 0; index < (*i)->getInfos().size(); index++)
207 {
208 std::cout << (*i)->getInfos()[index] << std::endl;
209 }
210 }
211
212
213
214
215
216
217 return 0;
218}
void changeSecond(Relation< T1, T2 > *rel, T2 *pobj)
std::vector< Relation< T1, T2 > * > getRelBySecond(const T2 *pobj) const
void init()
Initialize the internal pointer to an ObjectList of relations.
unsigned long size() const
This method returns the number of relations in the table.
void erase(Relation< T1, T2 > *rel)
bool addRelation(Relation< T1, T2 > *rel)
std::vector< Relation< T1, T2 > * > getRelByFirst(const T1 *pobj) const
void changeFirst(Relation< T1, T2 > *rel, T1 *pobj)
std::ostream & fillStream(std::ostream &s) const
Fill the ASCII output stream.