#include #include #include #include #include #include "test_utils.hh" #include "ProxyPack.hh" using namespace gs; using namespace std; int main(int argc, char const* argv[]) { typedef CPP11_shared_ptr Dptr; typedef CPP11_shared_ptr Iptr; auto tuple1 = std::tuple(); cout << "Tuple class id is " << ClassId::makeId().id() << endl; std::ostringstream os1; std::get<0>(tuple1) = 2; std::get<1>(tuple1) = 3.f; std::get<2>(tuple1) = 4.0; std::get<3>(tuple1) = 5; write_item(os1, tuple1); auto tuplecopy(tuple1); std::get<0>(tuple1) = 6; std::get<1>(tuple1) = 7.f; std::get<2>(tuple1) = 8.0; std::get<3>(tuple1) = 9; write_item(os1, tuple1, false); std::istringstream is1(os1.str()); auto tuple2 = std::tuple(); restore_item(is1, &tuple2); assert(tuplecopy == tuple2); assert(tuple1 != tuple2); restore_item(is1, &tuple2, false); assert(tuple1 == tuple2); int i1 = 15; IOProxy ib(i1, "i1"); std::ostringstream os; i1 = 10; ib.write(os); i1 = 15; ib.write(os); i1 = 20; ib.write(os); Dptr dp(new double()); IOProxy bd(dp, "dp"); *dp = 1.0; assert(bd.write(os)); *dp = 3.0; assert(bd.write(os)); *dp = 123.0; assert(bd.write(os)); auto agw = make_proxy_pack( pack_member(i1), pack_member(dp) ); i1 = 30; *dp = 345.0; assert(agw.write(os)); std::istringstream is(os.str()); int ival; IOProxy ivb(ival, "ival"); ClassId dummy(ClassId::invalidId()); IOProxy::restore(dummy, is, &ivb); assert(ivb.name() == "i1"); assert(ival == 10); IOProxy::restore(dummy, is, &ivb); assert(ival == 15); IOProxy::restore(dummy, is, &ivb); assert(ival == 20); Dptr rbd; IOProxy br(rbd, "name should not matter here"); IOProxy::restore(dummy, is, &br); assert(br.name() == "dp"); assert(*rbd == 1.0); IOProxy::restore(dummy, is, &br); assert(*rbd == 3.0); IOProxy::restore(dummy, is, &br); assert(*rbd == 123.0); auto rag = make_proxy_pack( pack_member(ival), pack_member(rbd) ); cout << "ProxyPack class name is " << rag.classId().name() << endl; assert(rag.restore(agw.classId(), is, &rag)); cout << "Var 0 enabled: " << std::get<0>(rag).isEnabled() << endl; cout << "Var 1 enabled: " << std::get<1>(rag).isEnabled() << endl; assert(ival == 30); assert(*rbd == 345.0); // Tuple-related ops // // tuple_cat -- concatenate two tuples // tie // swap // tuple_size::value // tuple_element::type // getx // make_tuple return 0; }