Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00023
00024 #include <icl_core/Convert.h>
00025
00026 #include <iostream>
00027
00028 struct Foo
00029 {
00030 Foo() : foo(42) { }
00031 int foo;
00032 };
00033
00034 struct Bar
00035 {
00036 Bar() : bar(23) { }
00037 int bar;
00038 };
00039
00040 std::ostream& operator << (std::ostream& os, const Foo& foo)
00041 {
00042 return os << "Foo:" << foo.foo;
00043 }
00044
00045 std::ostream& operator << (std::ostream& os, const Bar& bar)
00046 {
00047 return os << "Bar:" << bar.bar;
00048 }
00049
00050 namespace icl_core {
00051
00052 template <>
00053 void convert<>(const Foo& from, Bar& to)
00054 {
00055 to.bar = from.foo;
00056 }
00057
00058 template <>
00059 void convert<>(const Bar& from, Foo& to)
00060 {
00061 to.foo = from.bar;
00062 }
00063
00064 }
00065
00066 int main()
00067 {
00068 Foo foo;
00069 Bar bar;
00070
00071 Bar bar2 = icl_core::convert<Bar>(foo);
00072 Foo foo2 = icl_core::convert<Foo>(bar);
00073
00074 std::cout << "Original objects: " << foo << " " << bar << "\n"
00075 << "Converted objects: " << foo2 << " " << bar2 << std::endl;
00076 return 0;
00077 }