Extended demo program.
This commit is contained in:
@@ -2,19 +2,46 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
enum Value {
|
||||
One = 1,
|
||||
Two,
|
||||
Three
|
||||
};
|
||||
|
||||
namespace string2type {
|
||||
|
||||
template <>
|
||||
Value convert<Value>(const std::string &value) {
|
||||
std::cout << "special convert function... " << std::endl;
|
||||
|
||||
if (value == "One") {
|
||||
return One;
|
||||
} else if (value == "Two") {
|
||||
return Two;
|
||||
} else if (value == "Three") {
|
||||
return Three;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct foo : attributes {
|
||||
foo() {
|
||||
REGISTER_ATTRIBUTE(int, x);
|
||||
REGISTER_ATTRIBUTE(Value, y);
|
||||
}
|
||||
|
||||
int x;
|
||||
Value y;
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char *argv) {
|
||||
foo f;
|
||||
f.set_attribute("x", "42");
|
||||
f.set_attribute("y", "One");
|
||||
|
||||
std::cout << f.x << std::endl;
|
||||
std::cout << f.y << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user