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

Iterator for Elements #26

Closed
JaimeIvanCervantes opened this issue Sep 6, 2017 · 1 comment
Closed

Iterator for Elements #26

JaimeIvanCervantes opened this issue Sep 6, 2017 · 1 comment

Comments

@JaimeIvanCervantes
Copy link
Contributor

JaimeIvanCervantes commented Sep 6, 2017

Visitors are used to traverse the dom, since derived Element classes are not homogeneous. It would be convenient, however, to have a custom iterator to access all Elements and their members.

It would be great to access the IDs of all the elements with a simple loop, for example, instead of having to create a new Visitor:

for (auto element : dom)
    cout<<element.id<<endl;

This would be helpful to do simple operations like counting the number of elements, or searching for an element with certain ID.

Edit: Looking at the problem, it seems like the Container's children member would have to be moved to Element in order for this to work.

@igagis
Copy link
Member

igagis commented Dec 17, 2020

Looking at the problem, it seems like the Container's children member would have to be moved to Element in order for this to work.

Yes, this is actually a problem. The DOM is supposed to closely represent the xml structure of the SVG document. And far not all SVG's elements can have child elements, i.e. not all of them are containers.

One possible compromise to the problem would be to implement a universal visitor (possible name element_visitor) and include it to the library. This visitor would visit all the elements and call a user supplied handler function to handle each element as simple element. Actually, maybe a special visitor is not needed, as the visitor class provides default_visit() method which can be overridden. I.e. no need to override all the visit() methods, just override one default_visit(element) and then each DOM's element can be visited without casting it to specific element class.

@igagis igagis closed this as completed Dec 28, 2020
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