-
Notifications
You must be signed in to change notification settings - Fork 32
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
feat: add method to add child/children elements to objects #115
feat: add method to add child/children elements to objects #115
Conversation
- also adds a corresponding method to get some information about them The function is added to `BaseWithoutId` and so should be inherited by everything. The `add` method: - gets the list of the members defined by generateDS for each each class - checks the type of the object being added to the types of the members to find the right member to add to. If a member with the type cannot be found, an Exception is raised. - if a member is found, it can either be a child member (can only have one value) or a children member (can have multiple values in a list). - For child members a check is made to see if a value is already set. If not, the value is set to the given object. - For children members, a check is made to see if the object has already been added. If not, the object is added. - If either test fails, an Exception is raised (since one does not need to re-add objects to update their value) - A `force` option allows overwriting and readdition, but is set to `False` by default. So, example usage would be of this type: ``` cell = neuroml.Cell(id="acell") biprop = neuroml.BiophysicalProperties(id="biprop") cell.add(biprop) # success cell.add(biprop) # will throw an Exception unless `force=True` cell.add("a string") # will throw an Exception since no member has a type "str" ``` Note: we have a few ComponentTypes which don't inherit from anywhere, and we need to check if these are correctly defined in the XSD file (Location is an example).
5dcea7a
to
6ab810c
Compare
This will be useful for testing purposes.
- get_member_info - add
Note: we could probably use a better name than "get_info |
So users can primarily just use `add()`.
tweaked the function names to:
if |
Attempting to readd an object is harmless, so make this a warning. Also fixes the comparison to not use `is` because it doesn't only compare the reference, it also compares the value.
We want a copy of the object to add other inherited member_data_types_ to. If we use `=`, we get a reference to `self.member_data_types_` object and end up modifying it, which we do not want to do. Not only does that change the nml.py representation, it also means that all the "expanded" lists of `member_data_types_` is held in memory for every neuroml object which greatly increases the memory foot print of models. So, calculate the complete list of member_data_types_ when required and then forget about it, which will allow memory to be garbage collected and freed up.
Opening this against the existing generateds PR since it'll cause conflicts otherwise. (#110)
TODO: