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

C++ YList: there is no function to remove elements from the list #811

Closed
vhuertas opened this issue Jul 18, 2018 · 5 comments
Closed

C++ YList: there is no function to remove elements from the list #811

vhuertas opened this issue Jul 18, 2018 · 5 comments

Comments

@vhuertas
Copy link

Hi,

I am writing a C++ program with the ydk in C++ and I have seen that for ydk::YList there is the "append" function but not "remove". Is there some workaround in order to remove elements from the list?

Thanks for your attention!

Regards,

@ygorelik
Copy link
Collaborator

The remove/delete function was not included to the ydk::YList class intentionally, because the operation will break order of entities in the list. Originally the feature was designed just to get key access to the YList data obtained from device. This implies that delete operation is irrelevant. Apparently you have another use case, which currently is not covered by YDK.
As a workaround I would suggest to build new YList and include to it all the elements that you need.

@vhuertas
Copy link
Author

Thanks for your answer,

Indeed, I am using YDK as a quick way to have a C++ class implementation of yang models (in this particular the ietf-interfaces although it will be extended with other modules).

I tried two workarounds and I would like to know your opinion on them:

Workaround 1:

If I want to remove a member of the list:

  1. I store a backup of all the elements of the Ylist
  2. I execute the destructor of the YList (hoping that all the maps and vectors are removed and freed.
  3. I try to create a new YList and associate it to the "parent" Entity
  4. I append all the backup elements except the one I want to remove.

In this workaround the step 3 didn't worked. I have tried to create a new YList like this (example done with Ylist 'address' in ipv4 node in the interface-state from ietf-interfaces module):

ietf-interfaces->interfaces-state->interface[ifname].ipv4.address ({"ip"});

but the C++ compiler complains telling that there is no contructor instance for this. Then I tried this (including the Entity pointer as the first parameter):

ietf-interfaces->interfaces-state->interface[ifname].ipv4.address (ietf-interfaces->interfaces-state->interface[ifname].ipv4, {"ip"});

But the result is the same...

Workaround 2:

  1. I create a new shared_ptr of the parent node holding the same content except for the YList (which would be constructed without errors), which would be filled with the backup elements except for the one I want to remove.

  2. I perform a "swap" of shared_ptrs (the new created node and the one in the original class structure).

This last workaround is not as "elegant" as the first one but it is the only way I have found to do it. The only thing that worries me is how to release memory occupied by the object of the old shared_ptr. So it could avoid a memory leak problem every time I want to perform a "remove" operation.

How do you see them?

Regards,

@ygorelik
Copy link
Collaborator

We have decided to add this functionality to the YList class. We will update you when it is ready for download.

ygorelik pushed a commit to ygorelik/ydk-gen that referenced this issue Jul 20, 2018
@vhuertas
Copy link
Author

Thanks a lot!
Kind regards,

@vhuertas
Copy link
Author

Just one further question,

Having a look at the CiscoDevNet/ydk-gen git repository I didn't see such update of the code for YList. Instead They have been added to the fork from ygorelik. When the issues are published here, are some of them solved in the in ygorelik fork and some in the CiscoDevNet? Or will they be applied to both repositories? is the #811 issue only solved in one of the two repos? It's a bit confusing...

I am using the ydk-cpp directly as the ietf bundle is the one I am interested in. But will this code update be integrated in ydk-ccp as well?

If I have to git clone the ygorelik repository I will but I just want to have a clear picture about both ygorelink and CiscoDevNet branches (and its differences) and if all will be merged someday,

Thanks in advance,

ygorelik pushed a commit to ygorelik/ydk-gen that referenced this issue Jul 23, 2018
ygorelik pushed a commit to ygorelik/ydk-gen that referenced this issue Jul 23, 2018
ghost pushed a commit that referenced this issue Jul 25, 2018
@ghost ghost closed this as completed Jul 25, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants