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

Codechange: convert news C-strings to std::string #9378

Merged
merged 3 commits into from Jul 1, 2021

Conversation

@rubidium42
Copy link
Contributor

@rubidium42 rubidium42 commented Jun 17, 2021

Motivation / Problem

Continue the C-string to std::string conversion.

Description

Change free_data from something that is malloced/freed to something that is allocated with new and delete. Type this so it becomes easier to spot all types of information that get passed into there by finding the appropriate sub classes. In doing so replace strduped strings with strings in an allocated sub class.

Limitations

Practically all this information could be put in sub classes of NewsItem, but that is something that should be done at a later point.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')
src/news_type.h Outdated
@@ -115,6 +115,10 @@ struct NewsTypeData {
NewsDisplay GetDisplay() const;
};

/** Container for any custom data that must be deleted after the news item has reached end-of-life. */
struct NewsAllocatedData {};
Copy link
Member

@LordAro LordAro Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we can force this type to never be used directly? (Which is presumably undesirable?)

Loading

Copy link
Contributor Author

@rubidium42 rubidium42 Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could define all "default" constructors as protected and then you must make a sub class of it. On the other hand, why make a new instance of this when you can pass nullptr as easily?
So I'm not quite sure whether all the guarding against such a thing is worth it. I just added it for a tiny bit more type safety.

Loading

src/news_type.h Outdated Show resolved Hide resolved
Loading
src/news_type.h Show resolved Hide resolved
Loading
@rubidium42 rubidium42 merged commit 9c7a7b5 into OpenTTD:master Jul 1, 2021
15 checks passed
Loading
@rubidium42 rubidium42 deleted the string_news branch Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants