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

Implement Tuple Name Differences in XML/JSON #143

Closed
wants to merge 3 commits into from
Closed

Implement Tuple Name Differences in XML/JSON #143

wants to merge 3 commits into from

Conversation

erichkeane
Copy link
Contributor

User rggjan requested that tuples provide a different name for each
element in this issue: #140.

This fix modifies tuple.hpp to generate tuple names in the order which
they are are placed in the tuple. Note that this will appear to be a
countdown (tuple_element2, tuple_element1, tuple_element0) since tuples
are generated in reverse order.

Signed-off-by: Erich Keane erich.keane@verizon.net

User rggjan requested that tuples provide a different name for each
element in this issue: #140.

This fix modifies tuple.hpp to generate tuple names in the order which
they are are placed in the tuple.  Note that this will appear to be a
countdown (tuple_element2, tuple_element1, tuple_element0) since tuples
are generated in reverse order.

Signed-off-by: Erich Keane <erich.keane@verizon.net>
User rggjan requested that tuples provide a different name for each
element in this issue: #140.

This fix modifies tuple.hpp to generate tuple names in the order which
they are are placed in the tuple.  Note that this will appear to be a
countdown (tuple_element2, tuple_element1, tuple_element0) since tuples
are generated in reverse order.

Signed-off-by: Erich Keane <erich.keane@verizon.net>
@AzothAmmo
Copy link
Contributor

I don't like allocating that string just to get the NVP name. I think we can stringify the number using templates at compile time. It'd be easier/cleaner with constexpr, but we unfortunately don't get to use that (thanks MSVC!).

@AzothAmmo
Copy link
Contributor

Templates: transforming run time solutions into compile time solutions through the magic of many lines of code: https://gist.github.com/AzothAmmo/4e9d145e5cce0a174b36

tuple names are now generated at compile time.  Additionally,
a breaking-change of re-ordering tuples to be from first-last
rather than last-first has been included.
@erichkeane
Copy link
Contributor Author

58d1675 now uses Azoth's example to generate compile-time names. Additionally, he mentioned wanting tuples to reverse their order in another comment, so I implemented that as well.

@erichkeane
Copy link
Contributor Author

Any comments or anything on this one? Should i remove the ordering change?

@AzothAmmo
Copy link
Contributor

Does this actually change the ordering? It looks like it is still counting down instead of counting up. Other than that it looks good - I do want to change the order to be in the natural tuple order (0, 1, 2, ...)

@erichkeane
Copy link
Contributor Author

It DOES reverse it. Note how I've reversed the call to apply and the ar( call.

This is my test snippet:

std::tuple<int, int, int, int> tup(1,2,3,4);
ostringstream os;
{
    cereal::JSONOutputArchive ar(os);
    ar(tup);
}
std::cout<< os.str()<<std::endl;

With apply happening second, this is the output:

{
    "value0": {
        "tuple_element3": 4,
        "tuple_element2": 3,
        "tuple_element1": 2,
        "tuple_element0": 1
    }
}

However, with the apply second (like in 58d1675) this is my output:

{
    "value0": {
        "tuple_element0": 1,
        "tuple_element1": 2,
        "tuple_element2": 3,
        "tuple_element3": 4
    }
}

@AzothAmmo
Copy link
Contributor

Right you are. My eyes glossed over the unchanged line in the diff. Will fully test and merge this into 1.1.

@AzothAmmo AzothAmmo added this to the v1.1.0 milestone Jan 9, 2015
AzothAmmo added a commit that referenced this pull request Jan 9, 2015
@AzothAmmo
Copy link
Contributor

Everything seems fine on Linux, I don't expect any problems on Windows. Will compile with MSVC later anyway, but closing now.

@AzothAmmo AzothAmmo closed this Jan 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants