Commit 5a917171 authored by Kenton Varda's avatar Kenton Varda

Allow implicit conversion from Orphan<T> to…

Allow implicit conversion from Orphan<T> to Orphan<DynamicStruct/DynamicList/DynamicCapability> where applicable.
parent e71deb9c
...@@ -561,6 +561,10 @@ TEST(Capability, ObjectsAndOrphans) { ...@@ -561,6 +561,10 @@ TEST(Capability, ObjectsAndOrphans) {
EXPECT_TRUE(orphan == nullptr); EXPECT_TRUE(orphan == nullptr);
verifyClient(request.getCap(), loop, callCount2); verifyClient(request.getCap(), loop, callCount2);
Orphan<DynamicCapability> dynamicOrphan2 = request.disownCap();
verifyClient(dynamicOrphan2.get(), loop, callCount2);
verifyClient(dynamicOrphan2.getReader(), loop, callCount2);
} }
TEST(Capability, Lists) { TEST(Capability, Lists) {
......
...@@ -784,6 +784,9 @@ public: ...@@ -784,6 +784,9 @@ public:
Orphan(Orphan&&) = default; Orphan(Orphan&&) = default;
Orphan& operator=(Orphan&&) = default; Orphan& operator=(Orphan&&) = default;
template <typename T, typename = kj::EnableIf<kind<T>() == Kind::STRUCT>>
inline Orphan(Orphan<T>&& other): schema(Schema::from<T>()), builder(kj::mv(other.builder)) {}
DynamicStruct::Builder get(); DynamicStruct::Builder get();
DynamicStruct::Reader getReader() const; DynamicStruct::Reader getReader() const;
...@@ -820,6 +823,9 @@ public: ...@@ -820,6 +823,9 @@ public:
Orphan(Orphan&&) = default; Orphan(Orphan&&) = default;
Orphan& operator=(Orphan&&) = default; Orphan& operator=(Orphan&&) = default;
template <typename T, typename = kj::EnableIf<kind<T>() == Kind::LIST>>
inline Orphan(Orphan<T>&& other): schema(Schema::from<T>()), builder(kj::mv(other.builder)) {}
DynamicList::Builder get(); DynamicList::Builder get();
DynamicList::Reader getReader() const; DynamicList::Reader getReader() const;
...@@ -855,6 +861,9 @@ public: ...@@ -855,6 +861,9 @@ public:
Orphan(Orphan&&) = default; Orphan(Orphan&&) = default;
Orphan& operator=(Orphan&&) = default; Orphan& operator=(Orphan&&) = default;
template <typename T, typename = kj::EnableIf<kind<T>() == Kind::INTERFACE>>
inline Orphan(Orphan<T>&& other): schema(Schema::from<T>()), builder(kj::mv(other.builder)) {}
DynamicCapability::Client get(); DynamicCapability::Client get();
DynamicCapability::Client getReader() const; DynamicCapability::Client getReader() const;
......
...@@ -332,6 +332,11 @@ TEST(Orphans, DynamicStruct) { ...@@ -332,6 +332,11 @@ TEST(Orphans, DynamicStruct) {
EXPECT_TRUE(orphan == nullptr); EXPECT_TRUE(orphan == nullptr);
EXPECT_TRUE(root.hasObjectField()); EXPECT_TRUE(root.hasObjectField());
checkTestMessage(root.asReader().getObjectField().getAs<TestAllTypes>()); checkTestMessage(root.asReader().getObjectField().getAs<TestAllTypes>());
Orphan<DynamicStruct> orphan2 = root.getObjectField().disownAs<TestAllTypes>();
EXPECT_FALSE(orphan2 == nullptr);
EXPECT_TRUE(orphan2.get().getSchema() == Schema::from<TestAllTypes>());
checkDynamicTestMessage(orphan2.getReader());
} }
TEST(Orphans, DynamicList) { TEST(Orphans, DynamicList) {
...@@ -352,6 +357,10 @@ TEST(Orphans, DynamicList) { ...@@ -352,6 +357,10 @@ TEST(Orphans, DynamicList) {
EXPECT_TRUE(orphan == nullptr); EXPECT_TRUE(orphan == nullptr);
EXPECT_TRUE(root.hasObjectField()); EXPECT_TRUE(root.hasObjectField());
checkList(root.asReader().getObjectField().getAs<List<uint32_t>>(), {12u, 34u, 56u}); checkList(root.asReader().getObjectField().getAs<List<uint32_t>>(), {12u, 34u, 56u});
Orphan<DynamicList> orphan2 = root.getObjectField().disownAs<List<uint32_t>>();
EXPECT_FALSE(orphan2 == nullptr);
checkList<uint32_t>(orphan2.getReader(), {12, 34, 56});
} }
TEST(Orphans, DynamicStructList) { TEST(Orphans, DynamicStructList) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment