Thu, 25 Apr 2013 01:54:25 +0300
Converted combo boxes in add object and new part dialogs to radio buttons. Added a convenience widget which makes it easier for me to add groups of radio buttons. My first widget.. :')
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
1 | /* |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
104 | 3 | * Copyright (C) 2013 Santeri Piippo |
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
4 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
8 | * (at your option) any later version. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
9 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
13 | * GNU General Public License for more details. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
14 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
17 | */ |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
18 | |
135
c243df39913e
Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
19 | #ifndef STR_H |
c243df39913e
Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
20 | #define STR_H |
0 | 21 | |
22 | #include <string.h> | |
23 | #include <stdlib.h> | |
24 | #include <stdarg.h> | |
25 | #include <vector> | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
26 | #include <QString> |
0 | 27 | |
28 | char* vdynformat (const char* csFormat, va_list vArgs, long int lSize); | |
29 | ||
18
a6732098fed8
Convert the static getCoordinateRep to a common ftoa, use this function to get proper coordinate representation when converting objects to LDraw code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
30 | class vertex; |
a6732098fed8
Convert the static getCoordinateRep to a common ftoa, use this function to get proper coordinate representation when converting objects to LDraw code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
31 | |
0 | 32 | // Dynamic string object, allocates memory when needed and |
33 | // features a good bunch of manipulation methods | |
34 | class str { | |
35 | private: | |
36 | // The actual message | |
37 | char* text; | |
38 | ||
39 | // Where will append() place new characters? | |
40 | unsigned short curs; | |
41 | ||
42 | // Allocated length | |
43 | unsigned short alloclen; | |
44 | ||
45 | // Resize the text buffer to len characters | |
46 | void resize (unsigned int len); | |
47 | ||
48 | public: | |
49 | // ====================================================================== | |
50 | str (); | |
51 | str (const char* c); | |
52 | str (char c); | |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
53 | str (QString c); |
0 | 54 | ~str (); |
55 | ||
56 | // ====================================================================== | |
57 | // METHODS | |
58 | ||
59 | // Empty the string | |
60 | void clear (); | |
61 | ||
62 | // Length of the string | |
63 | size_t len () { | |
64 | return strlen (text); | |
65 | } | |
66 | ||
67 | // The char* form of the string | |
68 | char* chars (); | |
69 | ||
70 | // Dumps the character table of the string | |
71 | void dump (); | |
72 | ||
73 | // Appends text to the string | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
74 | void append (const char c); |
0 | 75 | void append (const char* c); |
76 | void append (str c); | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
77 | void append (QString c); |
0 | 78 | |
79 | // Formats text to the string. | |
80 | void format (const char* fmt, ...); | |
81 | str format (...); | |
82 | ||
83 | // Appends formatted text to the string. | |
84 | void appendformat (const char* c, ...); | |
85 | ||
86 | // Returns the first occurrence of c in the string, optionally starting | |
87 | // from a certain position rather than the start. | |
88 | int first (const char* c, unsigned int a = 0); | |
89 | ||
90 | // Returns the last occurrence of c in the string, optionally starting | |
91 | // from a certain position rather than the end. | |
92 | int last (const char* c, int a = -1); | |
93 | ||
94 | // Returns a substring of the string, from a to b. | |
95 | str substr (unsigned int a, unsigned int b); | |
96 | ||
97 | // Replace a substring with another substring. | |
98 | void replace (const char* o, const char* n, unsigned int a = 0); | |
99 | ||
100 | // Removes a given index from the string, optionally more characters than just 1. | |
101 | void remove (unsigned int idx, unsigned int dellen=1); | |
102 | ||
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
103 | // Trims the given amount of characters. If negative, the characters |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
104 | // are removed from the beginning of the string, if positive, from the |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
105 | // end of the string. |
0 | 106 | str trim (int dellen); |
107 | ||
108 | // Inserts a substring into a certain position. | |
109 | void insert (char* c, unsigned int pos); | |
110 | ||
111 | // Reverses the string. | |
112 | str reverse (); | |
113 | ||
114 | // Repeats the string a given amount of times. | |
115 | str repeat (int n); | |
116 | ||
117 | // Is the string a number? | |
118 | bool isnumber (); | |
119 | ||
120 | // Is the string a word, i.e consists only of alphabetic letters? | |
121 | bool isword (); | |
122 | ||
123 | // Convert string to lower case | |
124 | str tolower (); | |
125 | ||
126 | // Convert string to upper case | |
127 | str toupper (); | |
128 | ||
129 | // Compare this string with another | |
130 | int compare (const char* c); | |
131 | int compare (str c); | |
132 | int icompare (str c); | |
133 | int icompare (const char* c); | |
134 | ||
135 | // Counts the amount of substrings in the string | |
136 | unsigned int count (char* s); | |
137 | unsigned int count (char s); | |
138 | ||
139 | // Counts where the given substring is seen for the nth time | |
140 | int instanceof (const char* s, unsigned n); | |
141 | ||
142 | char subscript (uint pos) { | |
143 | return operator[] (pos); | |
144 | } | |
145 | ||
60
961663d05463
Parsing stability, finally figured that dumb crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
146 | std::vector<str> split (str del, bool bNoBlanks = false); |
0 | 147 | |
113
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
148 | str strip (char c); |
bbaa40226ec9
Radial saving and reading from files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
149 | str strip (std::initializer_list<char> unwanted); |
0 | 150 | |
151 | // ====================================================================== | |
152 | // OPERATORS | |
153 | str operator+ (str& c) { | |
154 | append (c); | |
155 | return *this; | |
156 | } | |
157 | ||
158 | str& operator+= (char c) { | |
159 | append (c); | |
160 | return *this; | |
161 | } | |
162 | ||
163 | str& operator+= (const char* c) { | |
164 | append (c); | |
165 | return *this; | |
166 | } | |
167 | ||
168 | str& operator+= (const str c) { | |
169 | append (c); | |
170 | return *this; | |
171 | } | |
172 | ||
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
173 | str& operator+= (const QString c) { |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
174 | append (c); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
175 | return *this; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
176 | } |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
177 | |
18
a6732098fed8
Convert the static getCoordinateRep to a common ftoa, use this function to get proper coordinate representation when converting objects to LDraw code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
178 | str& operator+= (vertex vrt); |
a6732098fed8
Convert the static getCoordinateRep to a common ftoa, use this function to get proper coordinate representation when converting objects to LDraw code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
179 | |
0 | 180 | str operator* (const int repcount) { |
181 | repeat (repcount); | |
182 | return *this; | |
183 | } | |
184 | ||
185 | str& operator*= (const int repcount) { | |
186 | str other = repeat (repcount); | |
187 | clear (); | |
188 | append (other); | |
189 | return *this; | |
190 | } | |
191 | ||
192 | str operator- (const int trimcount) { | |
193 | return trim (trimcount); | |
194 | } | |
195 | ||
196 | str& operator-= (const int trimcount) { | |
197 | str other = trim (trimcount); | |
198 | clear (); | |
199 | append (other); | |
200 | return *this; | |
201 | } | |
202 | ||
203 | std::vector<str> operator/ (str splitstring); | |
204 | std::vector<str> operator/ (char* splitstring); | |
205 | std::vector<str> operator/ (const char* splitstring); | |
206 | ||
207 | int operator% (str splitstring) { | |
208 | return count (splitstring.chars()); | |
209 | } | |
210 | ||
211 | int operator% (char* splitstring) { | |
212 | return count (splitstring); | |
213 | } | |
214 | ||
215 | int operator% (const char* splitstring) { | |
216 | return count (str (splitstring).chars()); | |
217 | } | |
218 | ||
219 | str operator+ () { | |
220 | return toupper (); | |
221 | } | |
222 | ||
223 | str operator- () { | |
224 | return tolower (); | |
225 | } | |
226 | ||
227 | str operator! () { | |
228 | return reverse (); | |
229 | } | |
230 | ||
231 | size_t operator~ () { | |
232 | return len (); | |
233 | } | |
234 | ||
235 | #define DEFINE_OPERATOR_TYPE(OPER, TYPE) \ | |
236 | bool operator OPER (TYPE other) {return compare(other) OPER 0;} | |
237 | #define DEFINE_OPERATOR(OPER) \ | |
238 | DEFINE_OPERATOR_TYPE (OPER, str) \ | |
239 | DEFINE_OPERATOR_TYPE (OPER, char*) \ | |
240 | DEFINE_OPERATOR_TYPE (OPER, const char*) | |
241 | ||
242 | DEFINE_OPERATOR (==) | |
243 | DEFINE_OPERATOR (!=) | |
244 | DEFINE_OPERATOR (>) | |
245 | DEFINE_OPERATOR (<) | |
246 | DEFINE_OPERATOR (>=) | |
247 | DEFINE_OPERATOR (<=) | |
248 | ||
249 | char& operator[] (int pos) { | |
250 | return text[pos]; | |
251 | } | |
252 | ||
253 | operator char* () const { | |
254 | return text; | |
255 | } | |
256 | ||
257 | operator QString () const { | |
258 | return text; | |
259 | } | |
260 | ||
261 | operator int () const { | |
262 | return atoi (text); | |
263 | } | |
264 | ||
265 | operator uint () const { | |
266 | return operator int(); | |
267 | } | |
268 | }; | |
269 | ||
116 | 270 | str format (const char* fmt, ...); |
271 | ||
135
c243df39913e
Cleanup and some restructuring
Santeri Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
272 | #endif // STR_H |