ManaPlus
Public Member Functions | Data Fields
TextChunkList Class Reference

#include <textchunklist.h>

Public Member Functions

 TextChunkList ()
 
void insertFirst (TextChunk *const item)
 
void moveToFirst (TextChunk *const item)
 
void remove (const TextChunk *const item)
 
void removeBack ()
 
void removeBack (int n)
 
void clear ()
 

Data Fields

TextChunkstart
 
TextChunkend
 
uint32_t size
 
std::map< TextChunkSmall, TextChunk * > search
 
std::map< std::string, TextChunk * > searchWidth
 

Detailed Description

Definition at line 33 of file textchunklist.h.

Constructor & Destructor Documentation

◆ TextChunkList()

TextChunkList::TextChunkList ( )

Definition at line 28 of file textchunklist.cpp.

28  :
29  start(nullptr),
30  end(nullptr),
31  size(0),
32  search(),
33  searchWidth()
34 {
35 }
uint32_t size
Definition: textchunklist.h:56
TextChunk * start
Definition: textchunklist.h:54
TextChunk * end
Definition: textchunklist.h:55
std::map< TextChunkSmall, TextChunk * > search
Definition: textchunklist.h:57
std::map< std::string, TextChunk * > searchWidth
Definition: textchunklist.h:58

Member Function Documentation

◆ clear()

void TextChunkList::clear ( )

Definition at line 140 of file textchunklist.cpp.

141 {
142  search.clear();
143  searchWidth.clear();
144  TextChunk *restrict item = start;
145  while (item != nullptr)
146  {
147  TextChunk *restrict const item2 = item->next;
148  delete item;
149  item = item2;
150  }
151  start = nullptr;
152  end = nullptr;
153  size = 0;
154 }
#define restrict
Definition: localconsts.h:165

References end, restrict, search, searchWidth, size, and start.

◆ insertFirst()

void TextChunkList::insertFirst ( TextChunk *const  item)

Definition at line 37 of file textchunklist.cpp.

38 {
39  TextChunk *restrict const oldFirst = start;
40  if (start != nullptr)
41  start->prev = item;
42  item->prev = nullptr;
43  if (oldFirst != nullptr)
44  item->next = oldFirst;
45  else
46  end = item;
47  start = item;
48  size ++;
49  search[TextChunkSmall(item->text, item->color, item->color2)] = item;
50  searchWidth[item->text] = item;
51 }
TextChunk * next
Definition: textchunk.h:69
Color color
Definition: textchunk.h:66
Color color2
Definition: textchunk.h:67
TextChunk * prev
Definition: textchunk.h:68
std::string text
Definition: textchunk.h:65

References end, TextChunk::next, TextChunk::prev, restrict, search, searchWidth, size, and start.

Referenced by Font::drawString(), and Font::insertChunk().

◆ moveToFirst()

void TextChunkList::moveToFirst ( TextChunk *const  item)

Definition at line 53 of file textchunklist.cpp.

54 {
55  if (item == start)
56  return;
57 
58  TextChunk *restrict const oldPrev = item->prev;
59  if (oldPrev != nullptr)
60  oldPrev->next = item->next;
61  TextChunk *restrict const oldNext = item->next;
62  if (oldNext != nullptr)
63  oldNext->prev = item->prev;
64  else
65  end = oldPrev;
66  TextChunk *restrict const oldFirst = start;
67  if (start != nullptr)
68  start->prev = item;
69  item->prev = nullptr;
70  item->next = oldFirst;
71  start = item;
72 }

References end, TextChunk::next, TextChunk::prev, restrict, and start.

Referenced by Font::drawString(), Font::generate(), and Font::getWidth().

◆ remove()

void TextChunkList::remove ( const TextChunk *const  item)

Definition at line 74 of file textchunklist.cpp.

75 {
76  if (item == nullptr)
77  return;
78 
79  TextChunk *restrict const oldPrev = item->prev;
80  TextChunk *restrict const oldNext = item->next;
81  if (oldPrev != nullptr)
82  oldPrev->next = item->next;
83  else
84  start = oldNext;
85  if (oldNext != nullptr)
86  oldNext->prev = item->prev;
87  else
88  end = oldPrev;
89 
90  search.erase(TextChunkSmall(item->text,
91  item->color, item->color2));
92  searchWidth.erase(item->text);
93  size --;
94 }

References end, TextChunk::prev, restrict, search, searchWidth, size, and start.

Referenced by Font::generate().

◆ removeBack() [1/2]

void TextChunkList::removeBack ( )

Definition at line 96 of file textchunklist.cpp.

97 {
98  TextChunk *restrict oldEnd = end;
99  if (oldEnd != nullptr)
100  {
101  end = oldEnd->prev;
102  if (end != nullptr)
103  end->next = nullptr;
104  else
105  start = nullptr;
106  search.erase(TextChunkSmall(oldEnd->text,
107  oldEnd->color, oldEnd->color2));
108  searchWidth.erase(oldEnd->text);
109  delete oldEnd;
110  size --;
111  }
112 }

References end, TextChunk::next, TextChunk::prev, restrict, search, searchWidth, size, and start.

Referenced by Font::doClean(), Font::drawString(), and Font::generate().

◆ removeBack() [2/2]

void TextChunkList::removeBack ( int  n)

Definition at line 114 of file textchunklist.cpp.

115 {
116  TextChunk *restrict item = end;
117  while ((n != 0) && (item != nullptr))
118  {
119  n --;
120  TextChunk *oldEnd = item;
121  item = item->prev;
122  search.erase(TextChunkSmall(oldEnd->text,
123  oldEnd->color, oldEnd->color2));
124  searchWidth.erase(oldEnd->text);
125  delete oldEnd;
126  size --;
127  }
128  if (item != nullptr)
129  {
130  item->next = nullptr;
131  end = item;
132  }
133  else
134  {
135  start = nullptr;
136  end = nullptr;
137  }
138 }

References TextChunk::color, TextChunk::color2, end, TextChunk::prev, restrict, search, searchWidth, size, start, and TextChunk::text.

Field Documentation

◆ end

TextChunk* TextChunkList::end

Definition at line 55 of file textchunklist.h.

Referenced by clear(), insertFirst(), moveToFirst(), remove(), and removeBack().

◆ search

std::map<TextChunkSmall, TextChunk*> TextChunkList::search

◆ searchWidth

std::map<std::string, TextChunk*> TextChunkList::searchWidth

Definition at line 58 of file textchunklist.h.

Referenced by clear(), Font::getWidth(), insertFirst(), remove(), and removeBack().

◆ size

uint32_t TextChunkList::size

◆ start

TextChunk* TextChunkList::start

Definition at line 54 of file textchunklist.h.

Referenced by clear(), insertFirst(), moveToFirst(), remove(), and removeBack().


The documentation for this class was generated from the following files: