Skip to content

Is it possible to load an object that has an rfl::Ref that is referenced multiple times? #426

@Lazrius

Description

@Lazrius

Good evening.

I was wondering if it is possible to use rfl::Ref to reference different parts of the same document with the same 'instance'? To better explain my meaning, here is some sample code:

{
    "items": [
        {
            "name": "Special Item",
            "count": 5
        },
        {
            "name": "Mundane Item",
            "count": 10
        },
        {
            "name": "Boring Item",
            "count": 5
        }
    ],
    "itemGroups": [
        {
            "name": "Every day items",
            "items": [
                "Mundane Item", "Boring Item"
            ]
        }
    ]
}
struct Item
{
    std::string name;
    int count;
}

struct ItemGroup
{
    std::string name;
    std::vector<rfl::Ref<Item> items; // <--- Contents: 3 items
}

struct Config
{
    std::vector<rfl::Ref<Item> items; // <--- The SAME 3 items, i.e. update one, update both
    std::vector<rfl::Ref<ItemGroup> groups; // <-- 1 Group ptr that contains the aforementioned 3 existing items.
    // In total the Item constructor would have been called 3 times, the ItemGroup constructor, once
}

In this example, I'd like to use the string name as an id to map them together. I'd want to use something like rfl::json::read and the result being a shared pointer between the two object types. I've read the documentation a fair bit and I've not determined if this isn't possible or if I have just missed something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions