-
Notifications
You must be signed in to change notification settings - Fork 5
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
XML Ranges #333
Comments
What's the advantage of this over using a function that calls a callback inside a for loop?
It seems to me you would end up writing way more code than if you just extract out the boilerplate repeated code into a simple function. |
Well, the main advantage is that you can use range-for loops. There's also an efficiency gain over using runtime callback, particularly You can improve the efficiency of the callback approach by using a template method with a function parameter. Having the called method known at compile time means the compiler can inline the called method. Passing a lambda to the method should then compile to about the same efficiency as the range-for loop. That imposes lambda syntax on the caller though. So yeah, the code to support range-for syntax is a little larger, though efficiency is quite good, and the syntax benefits are nice. Either way though, the support code is packaged away in a library, so users don't need to worry about it. Oh, and C++20 is getting some major additions in terms of Range support. Having these classes would allow us to make use of those additions for more complicated algorithms, such as filtering and transforming ranges. |
Reference: C++20 Ranges library. |
Some more good references: TinyXML Documentation: One thing to watch out for is I noticed a few TinyXML functions come in I've noticed at least 3 sets of objects that might be iterated over:
We could support both forward iterators and reverse iterators. For reverse iteration we would use:
There does not appear to be reverse iteration support for |
Can easily be added. I added UInt64 support and it was approved and merged into the library. |
Exactly what I was thinking. Submit some changes upstream for And yeah, I noticed you made that change to TinyXML. |
Thinking further about this, the Dictionary class may be a good way to decouple NAS2D entirely from XML -- ultimately I'd like to deprecate and remove the exposed XML library functions and remove it from NAS2D ultimately requiring the end user to decide what storage format they want to use. |
I was looking into how to reduce coupling between the
Configuration
andSprite
classes with the TinyXML library. As part of that, I was looking at simplifying the loop code by using range-based for loops. It can be done with a bit of support code. I believe it might look something like this (compiles, but untested):Usage would then look like:
The two iterator cases I think we need to support are for child nodes, and for attributes.
I haven't yet given much thought to
const
iterators with the above.Reference: How to make my custom type to work with “range-based for loops”?
Summary:
Iterator type, with support for:
operator*
,operator++
,operator!=
Range type, with support for:
begin()
,end()
(can be member methods, or free-standing with parameter)As we likely want to support two types of iteration (children and attributes) using the same base node, we likely want custom range types for each case, with member
begin()
andend()
on the range types.The text was updated successfully, but these errors were encountered: