892 Commits

Author SHA1 Message Date
JJ Marr
0b46bd3044 Enable performance-no-automatic-move
Variables can be automatically moved when a function returns. However,
declaring a variable as const prevents that move from occuring (as the
move modifies the moved-from variable).
2025-01-25 08:58:45 -05:00
Charles Dang
e8a29976cf Chrono: add helper to get normalized progress over a duration 2025-01-11 15:18:20 -05:00
Charles Dang
b9d67848ae Markup: doc cleanup, take arguments by string_view when possible 2025-01-04 09:31:32 -05:00
gfgtdf
2dcfe2435c deploy use of std::string_view 2024-12-12 03:12:38 +01:00
gfgtdf
e28217b213 Add utils::stod/stoi
There are drop in replacements for std::stod/stoi, the differences are:
- They are locale independent
- The take string_view arguments.
2024-12-12 03:12:29 +01:00
gfgtdf
1bd64bd8aa fix utils::unescape 2024-12-12 03:12:26 +01:00
gfgtdf
5801b5bcdb
use to/from_chars in attribute_value and lexical_cast (#8790)
This makes attribute_value and lexical_cast use the "new" to/from_chars api.

Its main advantages are:
- It's guaranteed to be locale independent, hopefully fixing all cases of #3945 and similar
- It fixes some cases config serialization, in particular the test
```
	cfg["x"] = "9.87654321";
	BOOST_CHECK_EQUAL(cfg["x"], 9.87654321);
```
- Previously the lexical_cast implementation used exception
  handling for invalid formats (catching std::invalid_argument)
  which made noise during debugging (and is also slower if it
  is not optimized out).
- It's faster

So far afaik the only compiler which has a complete and proper to/from_chars implementation is msvc, gccs implementation of from_chars sometimes uses strtod under the hood and clang simply hasn't implemented from_chars for floating point numbers yet at all (actually the upcomig clang 20 will have it). Luckily for us, there is now also boost::charconv that can be used. So this raises to minimum build requirement to have at least one of:

- msvc 2019 update 5
- gcc 11
- clang 14 (i have added a fallback implementation of from_chars for this case, that doesn't support all of its features, and is probably certainly not as fast as the boost version, but supports the features that we use from it)
- boost 1.85
 
Since in particular the gcc implementation isn't that good (at least it on gcc11), boost charconv is the preferred implementation that is used if available.

This also removes a strange overload for
pointers to integers in lexical_cast while changing lexical_cast to use the new api.
2024-12-08 22:28:10 +01:00
Charles Dang
2c216eec72
Refactor utils::format_timespan to use chrono types (#9610)
This also adjusts the periods for years and months. Previously, we were using values of 30 days for a month and 12 months for year. Now, we use the chrono values of a month as 1/12 of a year and a year as 365.2425 days.
2024-11-28 22:07:52 -05:00
Subhraman Sarkar
a50f047c7c add preprocess_string method and use preprocessed loyal trait 2024-11-24 16:51:12 +01:00
Charles Dang
79120f1e31 wesnothd: use std::chrono instead of the C time API 2024-11-20 01:03:42 -05:00
Subhraman Sarkar
e64765da2a markup: doc update, return empty string instead of empty tag pair
Related to #9583.
2024-11-14 22:26:10 +05:30
Subhraman Sarkar
ea6f903c04 markup: don't escape internally and update docs
Internal escaping causing markup failure when tags are nested.
See #9569 and #9572 for example. Functions in markup will no longer
escape their contents, and those should be escaped by caller if needed.
2024-11-14 10:30:36 +05:30
Charles Dang
9a77b72aac Different approach to chrono::duration serialization
Since we're relying on free functions to parse and serialize time_points, it makes more sense to do likewise for durations rather than relying on a config_attribute_value member function. Leaves the assignment support for now.
2024-11-07 11:10:13 -05:00
Charles Dang
6dc65f6483 Campaignd: use chrono::system_clock instead of std::time_t
Includes adjustments to client code to likewise use chrono types. I decided to keep using time_t
(which is just an alias for long_long) for serializing time points. This avoids compatibility issues,
since we keep the same resolution (seconds since Unix epoch), and unless we're going to "properly"
store time points in config, the time_t's unitless value is a good a representation as any.
2024-11-07 11:10:13 -05:00
Charles Dang
dfa4d7dd35 Remove chars_equals_insensitive and chars_less_insensitive
These aren't used anymore as of #9332 (save one place, which has been inlined here), and they're not good to rely on, since they don't handle utf8 properly.
2024-10-25 14:53:17 -04:00
Charles Dang
cb4d8a8dff Deploy utils::erase_if 2024-10-25 04:03:23 -04:00
Charles Dang
491c236113 Config: deploy all_children_view en-mass 2024-10-16 09:36:59 -04:00
Subhraman Sarkar
1ca69e1eca move markup parser to markup.cpp/hpp 2024-10-10 01:31:14 -04:00
Subhraman Sarkar
c2757a1d35 markup refactor: replace hardcoded markup strings
Examples:
formatter() << "<b>" << "Hello" << "</b>" becomes just markup::bold("Hello")
formatter() << font::span_color(color) << text << "</span>" becomes formatter() << markup::span_color(color, text)
also adds markup.cpp/markup.hpp to XCode and CodeBlocks source files and removes text_formatting.cpp/hpp from projectfiles.
2024-10-10 01:31:14 -04:00
Charles Dang
56cc3aee0f
Config: remove implicit conversion to int and bool (#9444)
Resolves #9009, closes #9384. Besides the issues that came from having both int and bool conversions (even with bool marked explicit), it doesn't make sense to use int for all numeric assignments. I didn't test whether it would be an issue in practice, but it seems better to let callers be explicit about what type they want for numeric values than risking overflow or wrapping for very large values.
2024-10-09 01:36:10 -04:00
Wedge009
558650bd14 Typography update for source code (in addition to .cfg data files previously reviewed). 2024-10-06 09:13:10 +11:00
pentarctagon
d4e7f5bc43 remove unsigned_matches_if_present 2024-09-29 23:19:39 -05:00
pentarctagon
d20128530a fix clang warning for signed unsigned comparison 2024-09-27 13:20:08 -05:00
Charles Dang
95c9f0c720
Config: use structured bindings with all_children_range (#9387) 2024-09-27 02:49:57 -04:00
Pentarctagon
bd8322a40b
add code documentation for the tokenizer (#9354)
Also clean up/simplify the code a bit.
2024-09-23 13:29:43 -05:00
Charles Dang
78676a27ad Use structured bindings for config attribute ranges in most places 2024-09-15 00:16:51 -04:00
Subhraman Sarkar
59911072aa support loading gui2 themes from add-ons
Requires a `gui-theme.cfg` file in Add-on root with a `[gui]` tag.
(Add-ons without all buttons in title_screen may get flagged as defunct.)
2024-08-25 01:56:22 -04:00
Charles Dang
8bf49639ea Fix build on VS 17.11 2024-08-15 19:30:23 -04:00
Charles Dang
a4fa20a331 Schema: delete empty dtors in parser and wml_tag 2024-07-30 21:03:43 -04:00
Charles Dang
221b17b9f6 Schema/Tag: clean up constructors, use inline initialization 2024-07-30 21:03:43 -04:00
Celtic Minstrel
7f3378d00c Use boost::optional only on MacOS and remove has_optional_value 2024-07-23 13:49:16 -04:00
Celtic Minstrel
f6ae8ab850 Mass replace all std::optional with utils::optional
Also import bad_optional_access into the utils namespace so we can catch the exception when we need to
2024-07-23 09:29:20 -04:00
Celtic Minstrel
62d9ebecc2 Revert "Used std::optional directly since we support C++17 now"
This reverts commit 4d54b2a7fd75696e9d7f745104f4c2e2ce5d0e6c.
2024-07-23 09:03:13 -04:00
Celtic Minstrel
ac431ca9dd Revert "Remove macOS compat path for std::variant and std::any"
This reverts commit c2decdfb585b9f3551fb4f0eaa41d42c9fe14422.
2024-07-23 08:23:38 -04:00
Charles Dang
e45b46107e
FS: use optional<string> to represent non-existent paths (#9107) 2024-07-18 09:58:55 -04:00
Charles Dang
156630d314 Use std::numeric_limits instead of C macros 2024-07-12 02:49:27 -04:00
Charles Dang
c2decdfb58 Remove macOS compat path for std::variant and std::any 2024-07-08 22:02:32 -04:00
Subhraman Sarkar
078c618f3a reduce hardcoded extensions in cpp files, only instance at filesystem.cpp 2024-07-05 09:05:26 +05:30
shijie.chen
d88ddec6f1
Remove unnecessary header files (#8531)
Co-authored-by: shijie.chen <shijie.chen@goland.cn>
2024-03-12 00:07:48 -04:00
Rafael Fillipe Silva
e24c13a1b7 implement cycle detection for type aliases (links)
Since the detection happens after loading the config tree, it is necessary to expose the links and subtypes of the types alias and composite, respectively.

This implementation builds a graph of all links to detect cycles, ignoring all other types.

To handle links in elements of lists, all subtypes of composite types are visited, keeping the type name of the parent composite type.

Signed-off-by: Rafael Fillipe Silva <rfsc.mori@gmail.com>
2024-02-26 10:12:43 -06:00
Rafael Fillipe Silva
c925737f54 format changes related super mandatory keys validation with clang-format 2024-02-26 10:12:43 -06:00
Rafael Fillipe Silva
c421d7e8be verify if all mandatory keys are specified, including the ones from the super tags
This pattern presents the same infinite loop issue as the find_key and find_tag calls on wml_tag. The solution is the same, to use a helper to keep track of the already seen tags and stop when a cycle is detected.
2024-02-26 10:12:43 -06:00
Rafael Fillipe Silva
4600043492 detect when a super defined in the schema doesn't exist
Note that this is only detected if the tag referencing the missing super is used in a .cfg file. The super element itself doesn't need to be used for the detection to work.

The schema self validator should already catch this, but it deserves a warning of its own as the schema self validator can be disabled.
2024-02-26 10:12:43 -06:00
Rafael Fillipe Silva
1c36153f06 detect schema super cycles while validating a .cfg file
Note that if the .cfg file does not use the tags that causes a cycle, those won't be detected.

This change exposes the super_refs_ so the schema validator does not need to reinvent wml_tag::expand when detecting super cycles.

The super dependency graph is built during the validation of each tag, finishing and reporting cycles at the end of the root tag.
2024-02-26 10:12:43 -06:00
Rafael Fillipe Silva
a3672ba509 add the super's full path to the tag's super_list
This allows for better diagonistic when the specified super doesn't exist and when super cycles are detected.
2024-02-26 10:12:43 -06:00
Rafael Fillipe Silva
c64416bbb6 handle super cycles while searching for a key or for a tag
A super cycle may be found during the validation, leading to an infinite loop. For example, calling find_key on an unknown key defined in the .cfg file may trigger this behavior if a cycle exists.

To handle this, a new version of these functions was introduced, keeping the original in the class' private scope. During the search there is a bookkeeping helper that will cause the routine to return nullptr if the search goes back to the initial tag context.
2024-02-26 10:12:43 -06:00
Rafael Fillipe Silva
f7511ea731 fix wml_tag::iterator CRTP parameter
Forwards the Map type parameter instead of defaulting to `std::map<string, T>`.
2024-02-26 10:12:43 -06:00
Rafael Fillipe Silva
dafb78cdf1 implement super cycle detection for the schema self validator
The super tag dependency forms a directed graph. Boost Graph's depth first search implementation was used with a back edge detector to find the cycles.

This is a preparation for enumerating all keys that a tag can use, including the keys from the super tags. If cycles aren't handled, it is impossible to validate mandatory keys without entering an infinite loop.
2024-02-26 10:12:43 -06:00
pentarctagon
63d14217c9 Revert "Revert IPF string handling optimisations"
This reverts commit e14d7ddee99950f208407ca35434ea7b316f807f.
2024-02-19 21:13:22 -06:00
Steve Cotton
e14d7ddee9 Revert IPF string handling optimisations
When reverting this revert (after 1.18 has branched), the
new .hpp file should be added to XCode and CodeBlocks.

This reverts PR #8396, PR #8407 and the "Small fixup" commit;
they bumped the minimum compiler version from GCC 7 to 8 or 11.

This reverts commit 870eeff8e68de000bbe6608c2b6f982b28a2200f.
This reverts commit 029136b19acf9627170e9ab9383cea48b7d70a81.
This reverts commit d74ff6f31b3668d07236ffaa4059f31c373d4996.
This reverts commit 8a6de95d489b4e96d2c9a368b25a0c20e249cdf6.
This reverts commit d14d233d79957ddfcbe200d21f16ab78915c883b.
This reverts commit 698f5c115c1546e3fcf1c52be90d72a5a841abb6.
2024-02-19 12:25:56 +01:00