00001 // 00002 // Copyright (c) 2003 00003 // Paul Hamilton; pHamtec P/L 00004 // 00005 // Permission to use, copy, modify, distribute and sell this software 00006 // and its documentation for any purpose is hereby granted without fee, 00007 // provided that the above copyright notice appears in all copies and 00008 // that both the copyright notice and this permission notice appear in 00009 // supporting documentation. No representations are made about the 00010 // suitability of this software for any purpose. It is provided "as is" 00011 // without express or implied warranty. 00012 // 00013 // foo.cpp 00014 // 00015 // 4-Jul-2003 phamilton Created 00016 // 00017 00018 #include "foo.hpp" 00019 #include <boost/test/test_tools.hpp> 00020 #include "../member.hpp" 00021 #include "../member_visitor.hpp" 00022 #include "../object_visitor.hpp" 00023 #include "bar.hpp" 00024 00025 using namespace ph::reflect; 00026 using namespace reflect_test; 00027 00028 bool foo::accept(ph::common::member_visitor *v) 00029 { 00030 if (!base::accept(v)) 00031 return false; 00032 pod_member<int> _x(&x); 00033 if (!v->visit(this, "x", &_x)) 00034 return false; 00035 pod_member<double> _y(&y); 00036 if (!v->visit(this, "y", &_y)) 00037 return false; 00038 pod_member<bool> _z(&z); 00039 if (!v->visit(this, "z", &_z)) 00040 return false; 00041 return true; 00042 } 00043 00044 bool foo::accept(ph::common::const_member_visitor *v) const 00045 { 00046 if (!base::accept(v)) 00047 return false; 00048 const_pod_member<int> _x(&x); 00049 if (!v->visit(this, "x", &_x)) 00050 return false; 00051 const_pod_member<double> _y(&y); 00052 if (!v->visit(this, "y", &_y)) 00053 return false; 00054 const_pod_member<bool> _z(&z); 00055 if (!v->visit(this, "z", &_z)) 00056 return false; 00057 return true; 00058 } 00059 00060 bool foo::accept(ph::common::object_visitor *v) 00061 { 00062 if (!base::accept(v)) 00063 return false; 00064 if (!v->visit(this)) 00065 return false; 00066 if (!bars.accept(v)) 00067 return false; 00068 return true; 00069 } 00070 00071 bool foo::accept(ph::common::const_object_visitor *v) const 00072 { 00073 if (!base::accept(v)) 00074 return false; 00075 if (!v->visit(this)) 00076 return false; 00077 if (!bars.accept(v)) 00078 return false; 00079 return true; 00080 } 00081 00082 static void set(base *obj, const std::string &name, const std::string &val) 00083 { 00084 set_member_visitor v(name, val); 00085 obj->accept(&v); 00086 } 00087 00088 void foo::addbars() 00089 { 00090 bar *o = new bar("bar", "bar_3"); 00091 BOOST_REQUIRE_MESSAGE(o, "could not create bar object."); 00092 set(o, "x", "10"); 00093 set(o, "y", "10.5"); 00094 set(o, "z", "22"); 00095 BOOST_REQUIRE(bars.add(o, true)); 00096 }