Code Monkey home page Code Monkey logo

Comments (3)

operamint avatar operamint commented on August 17, 2024 1

Actually, as the attributes are a map with unique keys, the operator[] could work like the std::map operator[], so that it will add a new attribute if it does not exist. Makes it simple to add and update attributes, and to look up attributes that are mandatory. Optional attributes should be accessed with the usual attribute(name) method:

xml_attribute operator[](string_arg name) {
    xml_attribute att = attribute(name);
    return att ? att : append_attribute(name);
}

Example:

node["radius"] = 0.5; // add attribute
node["radius"] = 1.0; // update it.
double r = node["radius"].as_double(); // look up mandatory attribute

from pugixml.

lexxmark avatar lexxmark commented on August 17, 2024 1

This was the 1st thing I've added once cloned the library.

from pugixml.

zeux avatar zeux commented on August 17, 2024

FWIW there's a lot of different opinions on the syntax and semantics of the operators (should [] automatically add an attribute? should it only do it if the attribute is a non-const value?).

A straightforward answer is to only provide read-only operators for attributes, but that just saves a tiny bit of typing over explicit .attribute calls.

Overall it doesn't seem like it's an obviously good idea. It saves typing, which is great, but it introduces additional syntax that duplicates existing one - see #255 for a different take. I'm going to close this since I think it's best that pugixml core interface remains unambiguous and clear.

from pugixml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.