Codechange: C++-ify the Layouter and related functions

They all now access a std::string_view, instead of a "const char *"
or std::string (in some cases).

Additionally, GetCharAtPosition and friends now return an index
instead of a "const char *", as it makes for a more clear interface.
This commit is contained in:
Patric Stout
2023-05-06 19:53:02 +02:00
committed by Patric Stout
parent 61d1b330d1
commit 60399e17bd
10 changed files with 84 additions and 157 deletions

View File

@@ -124,7 +124,7 @@ public:
* It also accounts for the memory allocations and frees.
*/
class Layouter : public std::vector<std::unique_ptr<const ParagraphLayouter::Line>> {
const char *string; ///< Pointer to the original string.
std::string_view string; ///< Pointer to the original string.
/** Key into the linecache */
struct LineCacheKey {
@@ -168,17 +168,17 @@ private:
typedef std::map<LineCacheKey, LineCacheItem, LineCacheCompare> LineCache;
static LineCache *linecache;
static LineCacheItem &GetCachedParagraphLayout(const char *str, size_t len, const FontState &state);
static LineCacheItem &GetCachedParagraphLayout(std::string_view str, const FontState &state);
typedef SmallMap<TextColour, Font *> FontColourMap;
static FontColourMap fonts[FS_END];
public:
static Font *GetFont(FontSize size, TextColour colour);
Layouter(const char *str, int maxw = INT32_MAX, TextColour colour = TC_FROMSTRING, FontSize fontsize = FS_NORMAL);
Layouter(std::string_view str, int maxw = INT32_MAX, TextColour colour = TC_FROMSTRING, FontSize fontsize = FS_NORMAL);
Dimension GetBounds();
Point GetCharPosition(const char *ch) const;
const char *GetCharAtPosition(int x) const;
Point GetCharPosition(std::string_view::const_iterator ch) const;
ptrdiff_t GetCharAtPosition(int x) const;
static void ResetFontCache(FontSize size);
static void ResetLineCache();