Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有没有打算支持继承类的智能指针呢? #237

Open
RavielXing opened this issue Jan 12, 2024 · 2 comments
Open

有没有打算支持继承类的智能指针呢? #237

RavielXing opened this issue Jan 12, 2024 · 2 comments

Comments

@RavielXing
Copy link

实例代码大概是这样:

class TestXmlBase
{
public:
    int id;
    std::string name;
};
class TestXmlDerived:public TestXmlBase
{
public:
    int version;
    std::string tag;
};
REFLECTION(TestXmlBase, id, name);
REFLECTION(TestXmlDerived, id, name, version, tag);

class TestXmlClassContainer
{
public:
    std::vector<std::shared_ptr<TestXmlBase>> content;
};
REFLECTION(TestXmlClassContainer, content);

void TestDerived()
{
    TestXmlClassContainer c;
    auto d = std::make_shared<TestXmlDerived>();
    auto b = std::make_shared<TestXmlBase>();
    c.content.push_back(b);
    c.content.push_back(d);
    std::string ss;
    iguana::to_xml<true>(c, ss);
}

实际输出目前是这样:

<TestXmlClassContainer>
    <content>
        <id>0</id>
        <name></name>
    </content>
    <content>
        <id>0</id>
        <name></name>
    </content>
</TestXmlClassContainer>

希望能输出这样:

<TestXmlClassContainer>
    <content>
        <TestXmlBase>
            <id>0</id>
            <name></name>
        </TestXmlBase>
    <TestXmlDerived>
        <TestXmlBase>
            <id>0</id>
            <name></name>
        </TestXmlBase>
        <version>0</version>
        <tag></tag>
    <TestXmlDerived>
    </content>
</TestXmlClassContainer>
@bbbgan
Copy link
Collaborator

bbbgan commented Jan 21, 2024

用智能指针的时候,如果是反射的类型把类型名字也当成一个tag?是可以做到的,有趣但不知道是否具有应用场景呢。

@RavielXing
Copy link
Author

用智能指针的时候,如果是反射的类型把类型名字也当成一个tag?是可以做到的,有趣但不知道是否具有应用场景呢。

主要还是使用容器时需要,这种情况下没有办法处理子类部分。

171930433 pushed a commit to 171930433/iguana that referenced this issue Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants