Share Mind

Love Reading | Film | Climbing | Snooker

关于

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*
This is a simple C++ program about me
*/

#include "stdafx.h"
#include <algorithm>
#incluce <string>
#include <iostream>
#include <list>

// set and get attrib macro
#define GET_ATTRIBUTE(attrname) get##_##attrname
#define SET_ATTRIBUTE(attrname) set##_##attrname

#define SET_ATTRIBUTE_INVOKE(attrname, value) SET_ATTRIBUTE(attrname)(value)
#define GET_ATTRIBUTE_INVOKE(attrname) GET_ATTRIBUTE(attrname)()

#define GET_ATTRIBUTE_DECL(attrtype, attrname) attrtype & GET_ATTRIBUTE(attrname)()
#define SET_ATTRIBUTE_DECL(attrtype, attrname) void SET_ATTRIBUTE(attrname)(attrtype attrname)

#define GET_ATTRIBUTE_IMPL(attrtype, attrname) GET_ATTRIBUTE_DECL(attrtype, attrname) \
{\
return _##attrname;\
}
#define SET_ATTRIBUTE_IMPL(attrtype, attrname) SET_ATTRIBUTE_DECL(attrtype, attrname) \
{\
_##attrname = attrname;\
}

// A function for deleting an object. Handy for being used as a functor.
template <typename T>
void Delete(T* x)
{
delete x;
}

// Applies a function/functor to each element in the container.
template <class Container, typename Functor>
void ForEach(const Container& c, Functor functor)
{
for_each(c.begin(), c.end(), functor);
}

//Base Person Info
class BasicPersonalInfo
{
public:
BasicPersonalInfo() {};
BasicPersonalInfo(string name, int age, string sex) : _name(name), _age(age), _sex(sex) {};
public:
SET_ATTRIBUTE_IMPL(string, name);
SET_ATTRIBUTE_IMPL(int, age);
SET_ATTRIBUTE_IMPL(string, sex);

GET_ATTRIBUTE_IMPL(string, name);
GET_ATTRIBUTE_IMPL(int, age);
GET_ATTRIBUTE_IMPL(string, sex);
private:
string _name;
int _age;
string _sex;
};

//Address Info
class AddressInfo
{
public:
AddressInfo() {};
AddressInfo(string bornCity, string workCity) : _bornCity(bornCity), _workCity(workCity) {};
public:
SET_ATTRIBUTE_IMPL(string, bornCity);
SET_ATTRIBUTE_IMPL(string, workCity);
SET_ATTRIBUTE_IMPL(string, postCode);

GET_ATTRIBUTE_IMPL(string, bornCity);
GET_ATTRIBUTE_IMPL(string, workCity);
GET_ATTRIBUTE_IMPL(string, postCode);
private:
string _bornCity;
string _workCity;
string _postCode;
};

// Contact Info
class ContactInfo
{
public:
ContactInfo() {};
ContactInfo(string qq, string email, string phoneNumber) : _qq(qq), _email(email), _phoneNumber(phoneNumber) {};
public:
SET_ATTRIBUTE_IMPL(string, qq);
SET_ATTRIBUTE_IMPL(string, email);
SET_ATTRIBUTE_IMPL(string, phoneNumber);

GET_ATTRIBUTE_IMPL(string, qq);
GET_ATTRIBUTE_IMPL(string, email);
GET_ATTRIBUTE_IMPL(string, phoneNumber);
private:
string _qq;
string _email;
string _phoneNumber;
};

// Enducation Exprience Record
class EnducationExprience
{
public:
EnducationExprience(string school, string period, string major, string enducationBackground):_school(school), \
_period(period),_major(major), _enducationBackground(enducationBackground) {};
public:
SET_ATTRIBUTE_IMPL(string, school);
SET_ATTRIBUTE_IMPL(string, period);
SET_ATTRIBUTE_IMPL(string, major);
SET_ATTRIBUTE_IMPL(string, enducationBackground);

GET_ATTRIBUTE_IMPL(string, school);
GET_ATTRIBUTE_IMPL(string, period);
GET_ATTRIBUTE_IMPL(string, major);
GET_ATTRIBUTE_IMPL(string, enducationBackground);

private:
string _school;
string _period;
string _major;
string _enducationBackground;
};

// Enducation Info
class EnducationInfo
{
public:
EnducationInfo() {};
public:
virtual ~EnducationInfo()
{
ForEach(_listEnducationExprience, Delete<EnducationExprience>);
}
public:
void addEnducationExperience(EnducationExprience *ee)
{
_listEnducationExprience.push_back(ee);
}
void delEnducationExperience(EnducationExprience *ee)
{
_listEnducationExprience.remove(ee);
}
void diplayEnducationInfo(void)
{
for (list<EnducationExprience*>::iterator it = _listEnducationExprience.begin();
it != _listEnducationExprience.end(); ++it)
{
cout << (*it)->GET_ATTRIBUTE_INVOKE(school) << " ";
cout << (*it)->GET_ATTRIBUTE_INVOKE(period) << " ";
cout << (*it)->GET_ATTRIBUTE_INVOKE(major) << " ";
cout << (*it)->GET_ATTRIBUTE_INVOKE(enducationBackground) << endl;
}
}
private:
list<EnducationExprience*> _listEnducationExprience;
};

//Hobby
class Hobby
{
public:
Hobby() {};
virtual ~Hobby()
{
ForEach(_listHobby, Delete<string>);
}
public:
void addHobby(string *hobby)
{
_listHobby.push_back(hobby);
}
void delHobby(string *hobby)
{
_listHobby.remove(hobby);
}
void diplayHobby(void)
{
for (list<string*>::iterator it = _listHobby.begin();
it != _listHobby.end(); ++it)
{
cout << *(*it) << endl;
}
}
private:
list<string*> _listHobby;
};

// About Impl
class AboutImpl
{
public:
AboutImpl()
{
initAllPersonalInfo();
}
public:
void disPlayAllInfo(void)
{
cout << " ***************** About Me Beign ***************** "<< endl;
displayBasicPersonalInfo();
displayAddressInfo();
displayContactInfo();
displayEnducationInfo();
displayHobby();
displayLovedWords();
cout << " ***************** About Me end ***************** " << endl;
}
private:
void initBasicPersonalInfo(void)
{
_basicInfo.SET_ATTRIBUTE_INVOKE(name, "tao ling yang");
_basicInfo.SET_ATTRIBUTE_INVOKE(age, 27);
_basicInfo.SET_ATTRIBUTE_INVOKE(sex, "boy");
}
void displayBasicPersonalInfo(void)
{
cout << "----------------------------" << endl;
cout << "Basic Personal Information: " << endl;
cout << "Name: " << _basicInfo.GET_ATTRIBUTE_INVOKE(name) << endl;
cout << "Age: " << _basicInfo.GET_ATTRIBUTE_INVOKE(age) << endl;
cout << "Sex: " << _basicInfo.GET_ATTRIBUTE_INVOKE(sex) << endl;
cout << endl;
}
void initAddressInfo(void)
{
_addressInfo.SET_ATTRIBUTE_INVOKE(bornCity, "Wuxue, Hubei");
_addressInfo.SET_ATTRIBUTE_INVOKE(workCity, "Shenzhen, Guangdong");
_addressInfo.SET_ATTRIBUTE_INVOKE(postCode, "518055");
}
void displayAddressInfo(void)
{
cout << "----------------------------" << endl;
cout << "Address Information: " << endl;
cout << "Born City: " << _addressInfo.GET_ATTRIBUTE_INVOKE(bornCity) << endl;
cout << "Work City: " << _addressInfo.GET_ATTRIBUTE_INVOKE(workCity) << endl;
cout << "Post Code: " << _addressInfo.GET_ATTRIBUTE_INVOKE(postCode) << endl;
cout << endl;
}
void initContactInfo(void)
{
_contactInfo.SET_ATTRIBUTE_INVOKE(qq, "475168208");
_contactInfo.SET_ATTRIBUTE_INVOKE(email, "franktly@163.com");
_contactInfo.SET_ATTRIBUTE_INVOKE(phoneNumber, "18565****87");
}
void displayContactInfo(void)
{
cout << "----------------------------" << endl;
cout << "Contact Information: " << endl;
cout << "QQ: " << _contactInfo.GET_ATTRIBUTE_INVOKE(qq) << endl;
cout << "Email: " << _contactInfo.GET_ATTRIBUTE_INVOKE(email) << endl;
cout << "PhoneNumber: " << _contactInfo.GET_ATTRIBUTE_INVOKE(phoneNumber) << endl;
cout << endl;
}
void initEnducationInfo(void)
{
EnducationExprience *ee1 = new EnducationExprience("HUST", "2011.09 --> 2014.3", "Mechatronics Enggineering", "Master Engineering(ME)");
_enducationInfo.addEnducationExperience(ee1);
EnducationExprience *ee2 = new EnducationExprience("HUST", "2007.09 --> 2011.6", "Mechine design manufacture and automation", "Bachelor Engineering(BE)");
_enducationInfo.addEnducationExperience(ee2);
}
void displayEnducationInfo(void)
{
cout << "----------------------------" << endl;
cout << "Enducation Information: " << endl;
_enducationInfo.diplayEnducationInfo();
cout << endl;
}
void initHobby(void)
{
string *hb1 = new string("New Technology");
_hobbyInfo.addHobby(hb1);
string *hb2 = new string("Music");
_hobbyInfo.addHobby(hb2);
string *hb3 = new string("Badminton");
_hobbyInfo.addHobby(hb3);
string *hb4 = new string("Snooker");
_hobbyInfo.addHobby(hb4);
string *hb5 = new string("Film");
_hobbyInfo.addHobby(hb5);
string *hb6 = new string("Climbing");
_hobbyInfo.addHobby(hb6);
}
void displayHobby(void)
{
cout << "----------------------------" << endl;
cout << "Hobby Information: " << endl;
_hobbyInfo.diplayHobby();
cout << endl;
}
void initLovedWords(void)
{
_lovedWords.append("Work to work steadfastly, play will play happily\n");
}
void displayLovedWords(void)
{
cout << "----------------------------" << endl;
cout << "Love Words: " << endl;
cout << _lovedWords << endl;
cout << endl;
}

void initAllPersonalInfo(void)
{
initBasicPersonalInfo();
initAddressInfo();
initContactInfo();
initEnducationInfo();
initHobby();
initLovedWords();
}
private:
BasicPersonalInfo _basicInfo;
AddressInfo _addressInfo;
ContactInfo _contactInfo;
EnducationInfo _enducationInfo;
Hobby _hobbyInfo;
string _lovedWords;
};

// About
class About
{
public:
~About()
{
delete _impl;
}
static About* getInstance(void)
{
static About about;
return &about;
}
void displayMe(void)
{
_impl->disPlayAllInfo();
}
private:
AboutImpl *_impl;
private:
About()
{
_impl = new AboutImpl;
};
About(const About &about) {};
About& operator==(const About &about) {};
};

int _tmain(int argc, _TCHAR* argv[])
{
About::getInstance()->displayMe();
}