-
Notifications
You must be signed in to change notification settings - Fork 44
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
Raii #14
base: master
Are you sure you want to change the base?
Raii #14
Conversation
valgrind shows memory as still reachable
in this test value is expected to be false, but should this return true?
now manual resource management anymore
this helped me figuring out that Catch itself includes <memory> and the tests compiled without including memory in CmdParser.hpp to compile this, type make sample now cmdparser.hpp is the first include in tests
In general looks good to me. Regarding the question: The problem here is / was to stop the program execution if the "help option" was detected. Now this changed to be implemented via a custom exception. No matter if we return true or false, the execution will continue. We could also exit here, but potentially this is also not an ideal solution (was always a kind of workaround; obviously it is not good / easy to test, and not as flexible as potentially desired). If the Long story short: I think neither |
how about returning an enum class like
The names are a quick shot, but you get the idea. |
Yes, I was thinking the same, but the question is - how does it play with a method like |
In my opinion, it is not the responsibility of the parser to exit the program. My suggestion would be, to remove |
Of course, you are right that this is not the main responsibility. However, for convenience this method was introduced and is used quite often as far as I can see. Regarding the enum - on second thought we have actually flags. We have
The happy path is either success with continue or failure with exit, however, we can also have success with exit or failure with continue (the latter could be that some parsing condition fails, but since the argument is optional this could be ignored; currently not implemented but it is a possibility). |
Today I read about signal handling. What if the system is supposed to not reboot for months/years? I really have mixed feelings about this exit() stuff. Initially I wanted to use your parser for my csv2xls. With kind regards |
All OSs free the resources allocated from an application when it exits. Otherwise, we would be doomed. And I think you misunderstood - its an opt-in and the parser does not exit for you if you do not wish to do that. It's a convenience method that can be used. But feel free to use something more appropriate for your workflow! Thanks for contributing 👍 ! |
Feel free to merge the PR anyway or at least cherrypick 42320bf please. |
Hi @ferkulat and @FlorianRappl
Instead of exception, why not simply add a destroy() private method called by 1/ the class destructor and 2/ explicitly in before the exit(). As second alternative (but I do not like) you can use a "Proxy" class referring to class to be destroyed and before exit() you call delete on the Proxy. To heavy here !
The idea would be not storing pointers in vector but directly the class, implement the movable constructor, and let the explicit move() operator. After all your project in >= C++11
Seems ok to me but with adding () to delte ? |
Hello @Lecrapouille ,
Raw pointers are not bad by default. |
Hello @Lecrapouille,
Since runtime polymorphism is used in this project, you will have to stick with pointers. |
With this you don't have to manage heap memory manually anymore and its exception save.
Could you please have a look at 33fffb6