Advertisement
Advertisement
| 02.28.2008 at 05:54AM PST, ID: 23200197 |
|
[x]
Attachment Details
|
||
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: |
#include <map>
#include <string>
#include <fstream>
#include <limits>
#define WithOutArg Shape* (* )(std::ifstream&)
#define WithArg(a) Shape* (*a)(std::ifstream&)
class Shape {
public:
static void AddSerializableType(const std::string&, WithArg(a));
protected:
Shape(std::ifstream&);
private:
static std::map<std::string, WithOutArg> map;
};
std::map<std::string, WithOutArg> Shape::map;
void Shape::AddSerializableType(const std::string& name, WithArg(constructor)) {
map.insert(make_pair(name,constructor));
}
class Circle : public Shape {
public:
Circle(std::ifstream& str) : Shape(str) {
str.width(std::numeric_limits<double>::digits10);
str >> m_radius;
}
private:
double m_radius;
};
int main() {
Shape::AddSerializableType("Circle",Circle(std::ifstream&));
}
|