-
Notifications
You must be signed in to change notification settings - Fork 30
Various fixes #6
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
base: master
Are you sure you want to change the base?
Conversation
This library will be used in the next commit, but since it needs wizard97/Embedded_RingBuf_CPP#6 applied, the sources are added integrally for now. Once that PR is merged, we can link to the normal version again.
|
Everything looks good, thanks for the merge, a few questions though.
|
Instead of duplicating the implementation for a pointer and reference argument, this lets the reference version call the pointer version.
This adds a prepend method to add elements at the start, a pop function to remove elements from the end.
append can be more appealing when combined with prepend, push can look better in combination with pop.
This removes the element, without saving it to anywhere. Additionally, this is made the default value for the argument, so you can call pull and pop without arguments to get this behaviour.
This file was copy-pasted from the C version, including the github url to that version. This fixes the url and adds a small note to the summary to distinguish both libraries. This fixes wizard97#5.
This makes it easier to trace the origin of code if files are copied elsewhere, and makes it more explicit what license applies.
1131633 to
26c78f0
Compare
When the buffer allows modifying either end,
I hadn't seen the dev branch until after I created this PR, but I've now rebased it on top of |
I understand now what your intensions are, my only concern is now just looking at all the methods, the API is kinda confusing. I think the README needs to be revised to make it clear which methods are relevant for FIFO (queue) usage and which are relevant for LIFO (stack) usage. Then all the more complicated methods can go under an advanced section ( I'm almost tempted at this point to make two new classes that inherit from some RingBuf base class: A FIFO class and a LIFO class. The FIFO class will have the queue related aliases and the LIFO class will have the stack related aliases. Let me know what you are thinking, as this is the direction I'm thinking is best right now. |
Right. For the aliases, you could probably solve this using an anonymous union (to have multiple names for the same pointer), but you'd still have 4 methods of which you'll likely not using all. However, looking at the C implementation, why are you using function pointers for a vtable anyway? It looks like these pointers are always pointing to the same methods anyway?
If you only add the methods relevant to either FIFO or LIFO (so only one addition and one removal method), then you lose flexibility for a mixed usecase (which is why I started writing this in the first place, since I was using a LIFO buffer, but sometimes needed FIFO behaviour). I would think that splitting into two classes would be more confusing than having a few extra methods (even with the duplicate names). A bit of documentation explaining what the idea is would also help, I think. I'm not really attached to the aliases, though, so if you think it is better to just keep one method per operation, that's also fine by me. That would give |
I have actually never heard of anonymous unions until now, I'm much more inclined now to have aliases since it possible to remove the overhead of them.
Initially part of the intention of this library was to show how you can apply OOP principles using only C. At this point there is no reason for having these virtual methods, and they still exist solely for ease in programming and backwards compatibility.
I understand you loose flexibility by not incorporating all these methods, but personally I have not convinced myself of a use case where you would need to have access to LIFO and FIFO methods on the same buffer. It seems to me you are either using a Queue (FIFO) or a Stack (LIFO). Can you give me an example of your use case that shows why it is critical to have access to both of these sets of methods at once? Part of design goal of this library is to make it as simple to use as possible, and methods that will only be used in 1% of use cases at the expense of complexity are not worth IMHO.
I actually completely agree with you on this one.
The idea would be you would have some base RingBuf class which implements all the basic prepend(), append(), pull(), etc... Then you have a Queue class that inherits and implements add() and remove() methods. And a Stack class that inherits for the base class and implements push() and pop(). At this point the question is should people have access to both stack and queue methods simultaneously. I personally think they should be separated, but if you can convince me of use cases when you need both then we can do that. Once this is figured out I will go ahead and merge the changes and draft a new release. |
The usecase I had was the following. I was building a list of measurements, to be sent using a radio protocol. For redundancy, I would periodically add one measurement to the list ( Note that by now, I've redesigned the operation of my sketch, so I'm not currently using this anymore. If the above example does not convince you, feel free to adopt the split-class approach (but I probably won't have time to implement that). |
|
Ok, I think you convinced me enough. I have just been thinking about the cleanest solution that gives you these advanced features without making the common case too complex. I'm not a huge fan of the derived split class approach either... I think what I'm going to do is as follows: This way, if you need the advanced features you can use a raw RingBuf class, otherwise (and in most cases) you use the correct |
|
One alternative springs to mind: Make |
|
Or, perhaps privately inherit from them and use the C++11 I'm not sure if any of these are better per se, it's just some options that came to mind. |
|
Actually I think exactly what we are looking for is private C++ inheritance. The I will get this merged in when I get a chance! |
Heres a few improvements to the code that I needed, as well as a fix to the library.properties file. I didn't bump the version number, I'll let that up to you.