44 {
45 FakeOne *person1, *person2, *person3;
47
48
49 person1 =
new FakeOne(
"Jack Tripper", 654 );
50 person2 =
new FakeOne(
"Richard Kanningam", 456 );
51 person3 =
new FakeOne(
"Dana Scully", 231 );
52
53 location1 =
new FakeTwo(
"531 Stanford Avenue", 2 );
54 location2 =
new FakeTwo(
"520 Cowper Street", 3 );
55
56
67
68
69
70
71
72
75
76
77 std::vector<Relation<FakeOne, FakeTwo>*> empty = tab.
getRelByFirst( person1 );
78 std::cout << "Querying and empty table the size of the returned vector is " << empty.size()
79 << std::endl;
80
86
87
88
89
90
92
93
94
95 std::vector<Relation<FakeOne, FakeTwo>*>::iterator i;
96
97
98 std::vector<Relation<FakeOne, FakeTwo>*> locs = tab.
getRelByFirst( person1 );
99
100 std::cout << std::endl << person1->
name << std::endl;
101 for ( i = locs.begin(); i != locs.end(); i++ )
102 {
103 std::cout << "Address: " << ( *i )->getSecond()->address
104 << " Floor: " << ( *i )->getSecond()->floor
105 << " Date : " << ( *i )->getInfos()[0] << std::endl;
106 }
107
108
109 std::vector<Relation<FakeOne, FakeTwo>*> pers = tab.
getRelBySecond( location2 );
110
111 std::cout << std::endl << location2->
address << std::endl;
112 for ( i = pers.begin(); i != pers.end(); i++ )
113 {
114 std::cout << "Name: " << ( *i )->getFirst()->name
115 << " ssn: " << ( *i )->getFirst()->ssn << std::endl;
116 }
117
118
119
121 for ( i = locs.begin(); i != locs.end(); i++ ) { tab.
changeSecond( *i, location1 ); }
122
123 std::cout << std::endl << "persion3 location changed" << std::endl;
124 std::cout << std::endl << location2->
address << std::endl;
125
127 for ( i = pers.begin(); i != pers.end(); i++ )
128 {
129 std::cout << "Name: " << ( *i )->getFirst()->name
130 << " ssn: " << ( *i )->getFirst()->ssn << std::endl;
131 }
132
134
135 for ( i = locs.begin(); i != locs.end(); i++ ) { tab.
changeFirst( *i, 0 ); }
136
137 std::cout << std::endl << "Jack Tripper set to null" << std::endl;
138
139
140
141
143
144 std::cout << "Number of relations with location2 = " << pers.size() << std::endl;
145
146 std::cout << std::endl << location2->
address << std::endl;
147 for ( i = pers.begin(); i != pers.end(); i++ )
148 {
149 if ( ( *i )->getFirst() )
150 std::cout << "Name: " << ( *i )->getFirst()->name
151 << " ssn: " << ( *i )->getFirst()->ssn << std::endl;
152 }
153
154
155
157 for ( i = pers.begin(); i != pers.end(); i++ ) { tab.
erase( *i ); }
158
159 std::cout << std::endl << "Removed relations with null pointer" << std::endl;
160 std::cout <<
"Number of relations = " << tab.
size() << std::endl;
161 std::cout << std::endl << location2->
address << std::endl;
162
164 for ( i = pers.begin(); i != pers.end(); i++ )
165 {
166 std::cout << "Name: " << ( *i )->getFirst()->name
167 << " ssn: " << ( *i )->getFirst()->ssn << std::endl;
168 }
169
170 std::cout << std::endl << person2->
name << std::endl;
171
172 unsigned int index;
173
175 for ( i = locs.begin(); i != locs.end(); i++ )
176 {
177 std::cout << "Address: " << ( *i )->getSecond()->address << std::endl;
178 std::cout << "Floor: " << ( *i )->getSecond()->floor << std::endl;
179 std::cout << "Dates : " << std::endl;
180 for ( index = 0; index < ( *i )->getInfos().size(); index++ )
181 { std::cout << ( *i )->getInfos()[index] << std::endl; }
182 }
183
184
185
186
187
188 return 0;
189}
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.