Merge lp:~thomas-voss/compiz-core/fix-globals-simplified into lp:compiz-core/0.9.5
- fix-globals-simplified
- Merge into 0.9.5
Proposed by
Sam Spilsbury
Status: | Superseded |
---|---|
Proposed branch: | lp:~thomas-voss/compiz-core/fix-globals-simplified |
Merge into: | lp:compiz-core/0.9.5 |
Diff against target: |
1126 lines (+358/-554) 10 files modified
include/core/action.h (+1/-1) include/core/option.h (+100/-52) src/CMakeLists.txt (+36/-14) src/action.cpp (+1/-1) src/global.cpp (+52/-0) src/main.cpp (+0/-27) src/option.cpp (+105/-433) src/privateoption.h (+0/-26) src/tests/CMakeLists.txt (+20/-0) src/tests/option.cpp (+43/-0) |
To merge this branch: | bzr merge lp:~thomas-voss/compiz-core/fix-globals-simplified |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel van Vugt | Needs Fixing | ||
Review via email: mp+89052@code.launchpad.net |
This proposal has been superseded by a proposal from 2012-01-19.
Commit message
Description of the change
Move the globals definitions into a separate file
To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote : | # |
Revision history for this message
Daniel van Vugt (vanvugt) wrote : | # |
Please remove all the changes unrelated to the globals clean-up in question.
It looks like lots of them crept in from:
https:/
review:
Needs Fixing
- 2922. By Thomas Voß
-
Re-enabled command-line flag --use-root-window and defined the variable in main.cpp.
Unmerged revisions
- 2913. By Daniel van Vugt
-
Fixes focus being on the wrong window after viewport changes (LP: #896762)
Merged from lp:~smspillaz/compiz-core/fix_896762
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'include/core/action.h' |
2 | --- include/core/action.h 2010-11-09 14:13:19 +0000 |
3 | +++ include/core/action.h 2012-01-18 14:51:30 +0000 |
4 | @@ -154,7 +154,7 @@ |
5 | |
6 | void copyState (const CompAction &action); |
7 | |
8 | - bool operator== (const CompAction& val); |
9 | + bool operator== (const CompAction& val) const; |
10 | CompAction & operator= (const CompAction &action); |
11 | |
12 | bool keyFromString (const CompString &str); |
13 | |
14 | === modified file 'include/core/option.h' |
15 | --- include/core/option.h 2011-10-31 13:51:00 +0000 |
16 | +++ include/core/option.h 2012-01-18 14:51:30 +0000 |
17 | @@ -29,11 +29,15 @@ |
18 | #define _COMPOPTION_H |
19 | |
20 | #include <core/string.h> |
21 | + |
22 | +#include <boost/variant.hpp> |
23 | + |
24 | #include <vector> |
25 | |
26 | class PrivateOption; |
27 | class PrivateValue; |
28 | class PrivateRestriction; |
29 | + |
30 | class CompAction; |
31 | class CompMatch; |
32 | class CompScreen; |
33 | @@ -54,12 +58,12 @@ |
34 | TypeString, |
35 | TypeColor, |
36 | TypeAction, |
37 | + TypeMatch, |
38 | + TypeList, |
39 | TypeKey, |
40 | TypeButton, |
41 | TypeEdge, |
42 | TypeBell, |
43 | - TypeMatch, |
44 | - TypeList, |
45 | /* internal use only */ |
46 | TypeUnset |
47 | } Type; |
48 | @@ -69,61 +73,105 @@ |
49 | */ |
50 | class Value { |
51 | public: |
52 | + |
53 | + typedef boost::variant< |
54 | + bool, |
55 | + int, |
56 | + float, |
57 | + CompString, |
58 | + unsigned short*, |
59 | + boost::recursive_wrapper<CompAction>, |
60 | + boost::recursive_wrapper<CompMatch>, |
61 | + boost::recursive_wrapper<std::vector<Value> > |
62 | + > variant_type; |
63 | + |
64 | typedef std::vector<Value> Vector; |
65 | |
66 | public: |
67 | - Value (); |
68 | - Value (const Value &); |
69 | - Value (const bool b); |
70 | - Value (const int i); |
71 | - Value (const float f); |
72 | - Value (const unsigned short *color); |
73 | - Value (const CompString& s); |
74 | - Value (const char *s); |
75 | - Value (const CompMatch& m); |
76 | - Value (const CompAction& a); |
77 | - Value (Type type, const Vector& l); |
78 | - ~Value (); |
79 | - |
80 | - Type type () const; |
81 | - |
82 | - void set (const bool b); |
83 | - void set (const int i); |
84 | - void set (const float f); |
85 | - void set (const unsigned short *color); |
86 | - void set (const CompString& s); |
87 | - void set (const char *s); |
88 | - void set (const CompMatch& m); |
89 | - void set (const CompAction& a); |
90 | - void set (Type type, const Vector& l); |
91 | - |
92 | - bool b (); |
93 | - int i (); |
94 | - float f (); |
95 | - unsigned short* c (); |
96 | - CompString s (); |
97 | - CompMatch & match (); |
98 | - CompAction & action (); |
99 | - Type listType (); |
100 | - Vector & list (); |
101 | - |
102 | - bool operator== (const Value& val); |
103 | - bool operator!= (const Value& val); |
104 | - Value & operator= (const Value &val); |
105 | - |
106 | - operator bool (); |
107 | - operator int (); |
108 | - operator float (); |
109 | - operator unsigned short * (); |
110 | - operator CompString (); |
111 | - operator CompMatch & (); |
112 | - operator CompAction & (); |
113 | - operator CompAction * (); |
114 | - operator Type (); |
115 | - operator Vector & (); |
116 | + Value () : mListType(TypeUnset) |
117 | + { |
118 | + } |
119 | + |
120 | + template<typename T> |
121 | + Value( const T & t ) : mListType(TypeUnset), |
122 | + mValue(t) |
123 | + { |
124 | + } |
125 | + |
126 | + ~Value(); |
127 | + |
128 | + Type |
129 | + type () const |
130 | + { |
131 | + return static_cast<Type>(mValue.which()); |
132 | + } |
133 | + |
134 | + Type |
135 | + listType () const |
136 | + { |
137 | + return mListType; |
138 | + } |
139 | + |
140 | + template<typename T> |
141 | + void set (const T & t) |
142 | + { |
143 | + mValue = t; |
144 | + } |
145 | + |
146 | + template<typename T> |
147 | + const T & get () const |
148 | + { |
149 | + return boost::get<T> (mValue); |
150 | + } |
151 | + |
152 | + void |
153 | + set (Type t, const Vector & v); |
154 | + |
155 | + bool |
156 | + b () const; |
157 | + |
158 | + int |
159 | + i () const; |
160 | + |
161 | + float |
162 | + f () const; |
163 | + |
164 | + unsigned short* |
165 | + c () const; |
166 | + |
167 | + const CompString & |
168 | + s () const; |
169 | + |
170 | + CompString & |
171 | + s (); |
172 | + |
173 | + const CompMatch & |
174 | + match () const; |
175 | + |
176 | + CompMatch & |
177 | + match (); |
178 | + |
179 | + const CompAction & |
180 | + action () const; |
181 | + |
182 | + CompAction & |
183 | + action (); |
184 | + |
185 | + const Vector & |
186 | + list () const; |
187 | + |
188 | + Vector & |
189 | + list (); |
190 | + |
191 | + bool |
192 | + operator== (const Value & rhs) const; |
193 | + |
194 | + bool |
195 | + operator!= (const Value & rhs) const; |
196 | |
197 | private: |
198 | - PrivateValue *priv; |
199 | + Type mListType; |
200 | + variant_type mValue; |
201 | }; |
202 | |
203 | /** |
204 | |
205 | === modified file 'src/CMakeLists.txt' |
206 | --- src/CMakeLists.txt 2012-01-12 13:44:07 +0000 |
207 | +++ src/CMakeLists.txt 2012-01-18 14:51:30 +0000 |
208 | @@ -59,10 +59,10 @@ |
209 | ${CORE_MOD_LIBRARY_DIRS} |
210 | ) |
211 | |
212 | -add_executable (compiz |
213 | - ${CMAKE_CURRENT_SOURCE_DIR}/region.cpp |
214 | +add_library (compiz_core |
215 | + ${CMAKE_CURRENT_SOURCE_DIR}/global.cpp |
216 | + ${CMAKE_CURRENT_SOURCE_DIR}/region.cpp |
217 | ${CMAKE_CURRENT_SOURCE_DIR}/atoms.cpp |
218 | - ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp |
219 | ${CMAKE_CURRENT_SOURCE_DIR}/actions.cpp |
220 | ${CMAKE_CURRENT_SOURCE_DIR}/screen.cpp |
221 | ${CMAKE_CURRENT_SOURCE_DIR}/window.cpp |
222 | @@ -86,6 +86,10 @@ |
223 | ${_bcop_sources} |
224 | ) |
225 | |
226 | +add_executable (compiz |
227 | + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp |
228 | +) |
229 | + |
230 | # workaround for build race |
231 | add_dependencies (compiz core-xml-file) |
232 | |
233 | @@ -94,17 +98,33 @@ |
234 | PROPERTY CORE_MOD_LIBRARIES) |
235 | |
236 | target_link_libraries ( |
237 | - compiz ${COMPIZ_LIBRARIES} |
238 | - |
239 | - m |
240 | - pthread |
241 | - dl |
242 | - |
243 | - compiz_string |
244 | - compiz_timer |
245 | - compiz_logmessage |
246 | - compiz_pluginclasshandler |
247 | -# ${CORE_MOD_LIBRARIES} |
248 | + compiz_core |
249 | + |
250 | + ${COMPIZ_LIBRARIES} |
251 | + |
252 | + m |
253 | + pthread |
254 | + dl |
255 | + |
256 | + compiz_string |
257 | + compiz_timer |
258 | + compiz_logmessage |
259 | + compiz_pluginclasshandler |
260 | +) |
261 | + |
262 | +target_link_libraries ( |
263 | + compiz |
264 | + compiz_core |
265 | + ${COMPIZ_LIBRARIES} |
266 | + |
267 | + m |
268 | + pthread |
269 | + dl |
270 | + |
271 | + compiz_string |
272 | + compiz_timer |
273 | + compiz_logmessage |
274 | + compiz_pluginclasshandler |
275 | ) |
276 | |
277 | install ( |
278 | @@ -112,4 +132,6 @@ |
279 | DESTINATION ${COMPIZ_DESTDIR}${exec_prefix} |
280 | ) |
281 | |
282 | +add_subdirectory(tests) |
283 | + |
284 | enable_coverage_report( TARGETS compiz ) |
285 | |
286 | === modified file 'src/action.cpp' |
287 | --- src/action.cpp 2011-10-31 13:51:00 +0000 |
288 | +++ src/action.cpp 2012-01-18 14:51:30 +0000 |
289 | @@ -455,7 +455,7 @@ |
290 | } |
291 | |
292 | bool |
293 | -CompAction::operator== (const CompAction& val) |
294 | +CompAction::operator== (const CompAction& val) const |
295 | { |
296 | if (priv->state != val.priv->state) |
297 | return false; |
298 | |
299 | === added file 'src/global.cpp' |
300 | --- src/global.cpp 1970-01-01 00:00:00 +0000 |
301 | +++ src/global.cpp 2012-01-18 14:51:30 +0000 |
302 | @@ -0,0 +1,52 @@ |
303 | +/* |
304 | + * Copyright © 2012 Canonical Ltd. |
305 | + * |
306 | + * Permission to use, copy, modify, distribute, and sell this software |
307 | + * and its documentation for any purpose is hereby granted without |
308 | + * fee, provided that the above copyright notice appear in all copies |
309 | + * and that both that copyright notice and this permission notice |
310 | + * appear in supporting documentation, and that the name of |
311 | + * Novell, Inc. not be used in advertising or publicity pertaining to |
312 | + * distribution of the software without specific, written prior permission. |
313 | + * Novell, Inc. makes no representations about the suitability of this |
314 | + * software for any purpose. It is provided "as is" without express or |
315 | + * implied warranty. |
316 | + * |
317 | + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
318 | + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN |
319 | + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
320 | + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
321 | + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
322 | + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
323 | + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
324 | + * |
325 | + * Author: Thomas Voss <thomas.voss@canonical.com> |
326 | + */ |
327 | + |
328 | +#include <list> |
329 | + |
330 | +#include "core/string.h" |
331 | + |
332 | +class CompWindow; |
333 | + |
334 | +char *programName; |
335 | +char **programArgv; |
336 | +int programArgc; |
337 | + |
338 | +char *backgroundImage = NULL; |
339 | + |
340 | +bool shutDown = false; |
341 | +bool restartSignal = false; |
342 | + |
343 | +CompWindow *lastFoundWindow = 0; |
344 | + |
345 | +bool replaceCurrentWm = false; |
346 | +bool indirectRendering = false; |
347 | +bool noDetection = false; |
348 | +bool useDesktopHints = false; |
349 | +bool debugOutput = false; |
350 | +bool useCow = true; |
351 | + |
352 | +std::list <CompString> initialPlugins; |
353 | + |
354 | +unsigned int pluginClassHandlerIndex = 0; |
355 | |
356 | === modified file 'src/main.cpp' |
357 | --- src/main.cpp 2011-10-31 13:51:00 +0000 |
358 | +++ src/main.cpp 2012-01-18 14:51:30 +0000 |
359 | @@ -38,28 +38,6 @@ |
360 | #include "privatescreen.h" |
361 | #include "privatestackdebugger.h" |
362 | |
363 | -char *programName; |
364 | -char **programArgv; |
365 | -int programArgc; |
366 | - |
367 | -char *backgroundImage = NULL; |
368 | - |
369 | -bool shutDown = false; |
370 | -bool restartSignal = false; |
371 | - |
372 | -CompWindow *lastFoundWindow = 0; |
373 | - |
374 | -bool replaceCurrentWm = false; |
375 | -bool indirectRendering = false; |
376 | -bool noDetection = false; |
377 | -bool useDesktopHints = false; |
378 | -bool debugOutput = false; |
379 | -bool useCow = true; |
380 | - |
381 | -std::list <CompString> initialPlugins; |
382 | - |
383 | -unsigned int pluginClassHandlerIndex = 0; |
384 | - |
385 | void |
386 | CompManager::usage () |
387 | { |
388 | @@ -72,7 +50,6 @@ |
389 | "[--bg-image PNG] " |
390 | "[--no-detection] " |
391 | "[--keep-desktop-hints]\n " |
392 | - "[--use-root-window] " |
393 | "[--debug] " |
394 | "[--version] " |
395 | "[--help] " |
396 | @@ -132,10 +109,6 @@ |
397 | { |
398 | useDesktopHints = true; |
399 | } |
400 | - else if (!strcmp (argv[i], "--use-root-window")) |
401 | - { |
402 | - useCow = false; |
403 | - } |
404 | else if (!strcmp (argv[i], "--replace")) |
405 | { |
406 | replaceCurrentWm = true; |
407 | |
408 | === modified file 'src/option.cpp' |
409 | --- src/option.cpp 2010-11-11 03:14:20 +0000 |
410 | +++ src/option.cpp 2012-01-18 14:51:30 +0000 |
411 | @@ -32,164 +32,14 @@ |
412 | #include <boost/foreach.hpp> |
413 | #define foreach BOOST_FOREACH |
414 | |
415 | +#include <core/action.h> |
416 | #include <core/core.h> |
417 | +#include <core/match.h> |
418 | #include <core/option.h> |
419 | #include "privateoption.h" |
420 | |
421 | CompOption::Vector noOptions (0); |
422 | |
423 | -CompOption::Value::Value () : |
424 | - priv (new PrivateValue ()) |
425 | -{ |
426 | -} |
427 | - |
428 | -CompOption::Value::Value (const Value &v) : |
429 | - priv (new PrivateValue (*v.priv)) |
430 | -{ |
431 | -} |
432 | - |
433 | -CompOption::Value::~Value () |
434 | -{ |
435 | - delete priv; |
436 | -} |
437 | - |
438 | -CompOption::Value::Value (const bool b) : |
439 | - priv (new PrivateValue ()) |
440 | -{ |
441 | - set (b); |
442 | -} |
443 | - |
444 | -CompOption::Value::Value (const int i) : |
445 | - priv (new PrivateValue ()) |
446 | -{ |
447 | - set (i); |
448 | -} |
449 | - |
450 | -CompOption::Value::Value (const float f) : |
451 | - priv (new PrivateValue ()) |
452 | -{ |
453 | - set (f); |
454 | -} |
455 | - |
456 | -CompOption::Value::Value (const unsigned short *color) : |
457 | - priv (new PrivateValue ()) |
458 | -{ |
459 | - set (color); |
460 | -} |
461 | - |
462 | -CompOption::Value::Value (const CompString& s) : |
463 | - priv (new PrivateValue ()) |
464 | -{ |
465 | - set (s); |
466 | -} |
467 | - |
468 | -CompOption::Value::Value (const char *s) : |
469 | - priv (new PrivateValue ()) |
470 | -{ |
471 | - set (s); |
472 | -} |
473 | - |
474 | - |
475 | -CompOption::Value::Value (const CompMatch& m) : |
476 | - priv (new PrivateValue ()) |
477 | -{ |
478 | - set (m); |
479 | -} |
480 | - |
481 | -CompOption::Value::Value (const CompAction& a) : |
482 | - priv (new PrivateValue ()) |
483 | -{ |
484 | - set (a); |
485 | -} |
486 | - |
487 | -CompOption::Value::Value (CompOption::Type type, const Vector& l) : |
488 | - priv (new PrivateValue ()) |
489 | -{ |
490 | - set (type, l); |
491 | -} |
492 | - |
493 | -CompOption::Type |
494 | -CompOption::Value::type () const |
495 | -{ |
496 | - return priv->type; |
497 | -} |
498 | - |
499 | -void |
500 | -CompOption::Value::set (const bool b) |
501 | -{ |
502 | - priv->reset (); |
503 | - priv->type = CompOption::TypeBool; |
504 | - priv->value.b = b; |
505 | -} |
506 | - |
507 | -void |
508 | -CompOption::Value::set (const int i) |
509 | -{ |
510 | - priv->reset (); |
511 | - priv->type = CompOption::TypeInt; |
512 | - priv->value.i = i; |
513 | -} |
514 | - |
515 | -void |
516 | -CompOption::Value::set (const float f) |
517 | -{ |
518 | - priv->reset (); |
519 | - priv->type = CompOption::TypeFloat; |
520 | - priv->value.f = f; |
521 | -} |
522 | - |
523 | -void |
524 | -CompOption::Value::set (const unsigned short *color) |
525 | -{ |
526 | - priv->reset (); |
527 | - priv->type = CompOption::TypeColor; |
528 | - priv->value.c[0] = color[0]; |
529 | - priv->value.c[1] = color[1]; |
530 | - priv->value.c[2] = color[2]; |
531 | - priv->value.c[3] = color[3]; |
532 | -} |
533 | - |
534 | -void |
535 | -CompOption::Value::set (const CompString& s) |
536 | -{ |
537 | - priv->reset (); |
538 | - priv->type = CompOption::TypeString; |
539 | - priv->string = s; |
540 | -} |
541 | - |
542 | -void |
543 | -CompOption::Value::set (const char *s) |
544 | -{ |
545 | - priv->reset (); |
546 | - priv->type = CompOption::TypeString; |
547 | - priv->string = CompString (s); |
548 | -} |
549 | - |
550 | -void |
551 | -CompOption::Value::set (const CompMatch& m) |
552 | -{ |
553 | - priv->reset (); |
554 | - priv->type = CompOption::TypeMatch; |
555 | - priv->match = m; |
556 | -} |
557 | - |
558 | -void |
559 | -CompOption::Value::set (const CompAction& a) |
560 | -{ |
561 | - priv->reset (); |
562 | - priv->type = CompOption::TypeAction; |
563 | - priv->action = a; |
564 | -} |
565 | - |
566 | -void |
567 | -CompOption::Value::set (CompOption::Type type, const Vector& l) |
568 | -{ |
569 | - priv->reset (); |
570 | - priv->type = CompOption::TypeList; |
571 | - priv->list = l; |
572 | - priv->listType = type; |
573 | -} |
574 | - |
575 | static bool |
576 | checkIsAction (CompOption::Type type) |
577 | { |
578 | @@ -207,307 +57,130 @@ |
579 | return false; |
580 | } |
581 | |
582 | -bool |
583 | -CompOption::Value::b () |
584 | -{ |
585 | - if (!priv->checkType (CompOption::TypeBool)) |
586 | - return false; |
587 | - |
588 | - return priv->value.b; |
589 | -} |
590 | - |
591 | -int |
592 | -CompOption::Value::i () |
593 | -{ |
594 | - if (!priv->checkType (CompOption::TypeInt)) |
595 | - return 0; |
596 | - |
597 | - return priv->value.i; |
598 | -} |
599 | - |
600 | -float |
601 | -CompOption::Value::f () |
602 | -{ |
603 | - if (!priv->checkType (CompOption::TypeFloat)) |
604 | - return 0.0; |
605 | - |
606 | - return priv->value.f; |
607 | -} |
608 | + |
609 | |
610 | static unsigned short defaultColor[4] = { 0x0, 0x0, 0x0, 0xffff}; |
611 | |
612 | -unsigned short * |
613 | -CompOption::Value::c () |
614 | -{ |
615 | - if (!priv->checkType (CompOption::TypeColor)) |
616 | - return reinterpret_cast<unsigned short *> (defaultColor); |
617 | - |
618 | - return priv->value.c; |
619 | -} |
620 | - |
621 | -CompString |
622 | + |
623 | +static void |
624 | +finiOptionValue (CompOption::Value &v) |
625 | +{ |
626 | + switch (v.type()) { |
627 | + case CompOption::TypeAction: |
628 | + case CompOption::TypeKey: |
629 | + case CompOption::TypeButton: |
630 | + case CompOption::TypeEdge: |
631 | + case CompOption::TypeBell: |
632 | + if (v.action ().state () & CompAction::StateAutoGrab && screen) |
633 | + screen->removeAction (&v.action ()); |
634 | + break; |
635 | + |
636 | + case CompOption::TypeList: |
637 | + foreach (CompOption::Value &val, v.list ()) |
638 | + finiOptionValue (val); |
639 | + break; |
640 | + |
641 | + default: |
642 | + break; |
643 | + } |
644 | +} |
645 | + |
646 | +CompOption::Value::~Value() |
647 | +{ |
648 | + finiOptionValue(*this); |
649 | +} |
650 | + |
651 | +void |
652 | +CompOption::Value::set (Type t, const CompOption::Value::Vector & v) |
653 | +{ |
654 | + mListType = t; |
655 | + mValue = v; |
656 | +} |
657 | + |
658 | +bool |
659 | +CompOption::Value::b () const |
660 | +{ |
661 | + return boost::get<bool>(mValue); |
662 | +} |
663 | + |
664 | +int |
665 | +CompOption::Value::i () const |
666 | +{ |
667 | + return boost::get<int>(mValue); |
668 | +} |
669 | + |
670 | +float |
671 | +CompOption::Value::f () const |
672 | +{ |
673 | + return boost::get<float>(mValue); |
674 | +} |
675 | + |
676 | +unsigned short* |
677 | +CompOption::Value::c () const |
678 | +{ |
679 | + return boost::get<unsigned short*>(mValue); |
680 | +} |
681 | + |
682 | +const CompString & |
683 | +CompOption::Value::s () const |
684 | +{ |
685 | + return boost::get<CompString>(mValue); |
686 | +} |
687 | + |
688 | +CompString & |
689 | CompOption::Value::s () |
690 | { |
691 | - if (!priv->checkType (CompOption::TypeString)) |
692 | - return ""; |
693 | + return boost::get < CompString > (mValue); |
694 | +} |
695 | |
696 | - return priv->string; |
697 | +const CompMatch & |
698 | +CompOption::Value::match () const |
699 | +{ |
700 | + return boost::get<CompMatch>(mValue); |
701 | } |
702 | |
703 | CompMatch & |
704 | CompOption::Value::match () |
705 | { |
706 | - priv->checkType (CompOption::TypeMatch); |
707 | + return boost::get<CompMatch>(mValue); |
708 | +} |
709 | |
710 | - return priv->match; |
711 | +const CompAction & |
712 | +CompOption::Value::action () const |
713 | +{ |
714 | + return boost::get<CompAction>(mValue); |
715 | } |
716 | |
717 | CompAction & |
718 | CompOption::Value::action () |
719 | { |
720 | - priv->checkType (priv->type); |
721 | - |
722 | - if (!checkIsAction (priv->type)) |
723 | - compLogMessage ("core", CompLogLevelWarn, |
724 | - "CompOption::Value not an action"); |
725 | - |
726 | - return priv->action; |
727 | + return boost::get<CompAction>(mValue); |
728 | } |
729 | |
730 | -CompOption::Type |
731 | -CompOption::Value::listType () |
732 | +// Type listType () const; |
733 | + |
734 | +const CompOption::Value::Vector & |
735 | +CompOption::Value::list () const |
736 | { |
737 | - priv->checkType (CompOption::TypeList); |
738 | - |
739 | - return priv->listType; |
740 | + return boost::get< std::vector<Value> >(mValue); |
741 | } |
742 | |
743 | CompOption::Value::Vector & |
744 | CompOption::Value::list () |
745 | { |
746 | - priv->checkType (CompOption::TypeList); |
747 | - |
748 | - return priv->list; |
749 | -} |
750 | - |
751 | -CompOption::Value::operator bool () |
752 | -{ |
753 | - return b (); |
754 | -} |
755 | - |
756 | -CompOption::Value::operator int () |
757 | -{ |
758 | - return i (); |
759 | -} |
760 | - |
761 | -CompOption::Value::operator float () |
762 | -{ |
763 | - return f (); |
764 | -} |
765 | - |
766 | -CompOption::Value::operator unsigned short * () |
767 | -{ |
768 | - return c (); |
769 | -} |
770 | - |
771 | -CompOption::Value::operator CompString () |
772 | -{ |
773 | - return s (); |
774 | -} |
775 | - |
776 | -CompOption::Value::operator CompMatch & () |
777 | -{ |
778 | - return match (); |
779 | -} |
780 | - |
781 | -CompOption::Value::operator CompAction & () |
782 | -{ |
783 | - return action (); |
784 | -} |
785 | - |
786 | -CompOption::Value::operator CompAction * () |
787 | -{ |
788 | - return &action (); |
789 | -} |
790 | - |
791 | -CompOption::Value::operator Type () |
792 | -{ |
793 | - return listType (); |
794 | -} |
795 | - |
796 | -CompOption::Value::operator Vector & () |
797 | -{ |
798 | - return list (); |
799 | -} |
800 | - |
801 | -bool |
802 | -CompOption::Value::operator== (const CompOption::Value &val) |
803 | -{ |
804 | - if (priv->type != val.priv->type) |
805 | - return false; |
806 | - |
807 | - switch (priv->type) |
808 | - { |
809 | - case CompOption::TypeBool: |
810 | - return priv->value.b == val.priv->value.b; |
811 | - break; |
812 | - |
813 | - case CompOption::TypeInt: |
814 | - return priv->value.i == val.priv->value.i; |
815 | - break; |
816 | - |
817 | - case CompOption::TypeFloat: |
818 | - return priv->value.f == val.priv->value.f; |
819 | - break; |
820 | - |
821 | - case CompOption::TypeColor: |
822 | - return (priv->value.c[0] == val.priv->value.c[0]) && |
823 | - (priv->value.c[1] == val.priv->value.c[1]) && |
824 | - (priv->value.c[2] == val.priv->value.c[2]) && |
825 | - (priv->value.c[3] == val.priv->value.c[3]); |
826 | - break; |
827 | - |
828 | - case CompOption::TypeString: |
829 | - return priv->string.compare (val.priv->string) == 0; |
830 | - break; |
831 | - |
832 | - case CompOption::TypeMatch: |
833 | - return priv->match == val.priv->match; |
834 | - break; |
835 | - |
836 | - case CompOption::TypeAction: |
837 | - return priv->action == val.priv->action; |
838 | - break; |
839 | - |
840 | - case CompOption::TypeList: |
841 | - if (priv->listType != val.priv->listType) |
842 | - return false; |
843 | - |
844 | - if (priv->list.size () != val.priv->list.size ()) |
845 | - return false; |
846 | - |
847 | - for (unsigned int i = 0; i < priv->list.size (); i++) |
848 | - if (priv->list[i] != val.priv->list[i]) |
849 | - return false; |
850 | - |
851 | - return true; |
852 | - break; |
853 | - |
854 | - default: |
855 | - break; |
856 | - } |
857 | - |
858 | - return true; |
859 | -} |
860 | - |
861 | -bool |
862 | -CompOption::Value::operator!= (const CompOption::Value &val) |
863 | -{ |
864 | - return !(*this == val); |
865 | -} |
866 | - |
867 | -static void |
868 | -finiOptionValue (CompOption::Value &v, |
869 | - CompOption::Type type) |
870 | -{ |
871 | - switch (type) { |
872 | - case CompOption::TypeAction: |
873 | - case CompOption::TypeKey: |
874 | - case CompOption::TypeButton: |
875 | - case CompOption::TypeEdge: |
876 | - case CompOption::TypeBell: |
877 | - if (v.action ().state () & CompAction::StateAutoGrab && screen) |
878 | - screen->removeAction (&v.action ()); |
879 | - break; |
880 | - |
881 | - case CompOption::TypeList: |
882 | - foreach (CompOption::Value &val, v.list ()) |
883 | - finiOptionValue (val, v.listType ()); |
884 | - break; |
885 | - |
886 | - default: |
887 | - break; |
888 | - } |
889 | -} |
890 | - |
891 | -CompOption::Value & |
892 | -CompOption::Value::operator= (const CompOption::Value &val) |
893 | -{ |
894 | - if (this == &val) |
895 | - return *this; |
896 | - |
897 | - finiOptionValue (*this, priv->type); |
898 | - |
899 | - delete priv; |
900 | - priv = new PrivateValue (*val.priv); |
901 | - |
902 | - return *this; |
903 | -} |
904 | - |
905 | -PrivateValue::PrivateValue () : |
906 | - type (CompOption::TypeUnset), |
907 | - string (""), |
908 | - action (), |
909 | - match (), |
910 | - listType (CompOption::TypeUnset), |
911 | - list () |
912 | -{ |
913 | - memset (&value, 0, sizeof (ValueUnion)); |
914 | -} |
915 | - |
916 | -PrivateValue::PrivateValue (const PrivateValue& p) : |
917 | - type (p.type), |
918 | - string (p.string), |
919 | - action (p.action), |
920 | - match (p.match), |
921 | - listType (p.listType), |
922 | - list (p.list) |
923 | -{ |
924 | - memcpy (&value, &p.value, sizeof (ValueUnion)); |
925 | -} |
926 | - |
927 | -bool |
928 | -PrivateValue::checkType (CompOption::Type refType) |
929 | -{ |
930 | - if (type == CompOption::TypeUnset) |
931 | - { |
932 | - compLogMessage ("core", CompLogLevelWarn, |
933 | - "Value type is not yet set"); |
934 | - return false; |
935 | - } |
936 | - |
937 | - if (type != refType) |
938 | - { |
939 | - compLogMessage ("core", CompLogLevelWarn, |
940 | - "Value type does not match (is %d, expected %d)", |
941 | - type, refType); |
942 | - return false; |
943 | - } |
944 | - |
945 | - return true; |
946 | -} |
947 | - |
948 | -void |
949 | -PrivateValue::reset () |
950 | -{ |
951 | - switch (type) { |
952 | - case CompOption::TypeString: |
953 | - string = ""; |
954 | - break; |
955 | - case CompOption::TypeMatch: |
956 | - match = CompMatch (); |
957 | - break; |
958 | - case CompOption::TypeAction: |
959 | - action = CompAction (); |
960 | - break; |
961 | - case CompOption::TypeList: |
962 | - list.clear (); |
963 | - listType = CompOption::TypeBool; |
964 | - break; |
965 | - default: |
966 | - break; |
967 | - } |
968 | - type = CompOption::TypeBool; |
969 | + return boost::get< std::vector<Value> >(mValue); |
970 | +} |
971 | + |
972 | +bool |
973 | +CompOption::Value::operator== (const Value & rhs) const |
974 | +{ |
975 | + return mValue == rhs.mValue; |
976 | +} |
977 | + |
978 | +bool |
979 | +CompOption::Value::operator!= (const Value & rhs) const |
980 | +{ |
981 | + return !(mValue == rhs.mValue); |
982 | } |
983 | |
984 | CompOption::Restriction::Restriction () : |
985 | @@ -664,10 +337,9 @@ |
986 | |
987 | static void |
988 | finiScreenOptionValue (CompScreen *s, |
989 | - CompOption::Value &v, |
990 | - CompOption::Type type) |
991 | + CompOption::Value &v) |
992 | { |
993 | - switch (type) { |
994 | + switch (v.type()) { |
995 | case CompOption::TypeAction: |
996 | case CompOption::TypeKey: |
997 | case CompOption::TypeButton: |
998 | @@ -679,7 +351,7 @@ |
999 | |
1000 | case CompOption::TypeList: |
1001 | foreach (CompOption::Value &val, v.list ()) |
1002 | - finiScreenOptionValue (s, val, v.listType ()); |
1003 | + finiScreenOptionValue (s, val); |
1004 | break; |
1005 | |
1006 | default: |
1007 | @@ -689,7 +361,7 @@ |
1008 | |
1009 | CompOption::~CompOption () |
1010 | { |
1011 | - finiOptionValue (priv->value, priv->type); |
1012 | + finiOptionValue (priv->value); |
1013 | delete priv; |
1014 | } |
1015 | |
1016 | |
1017 | === modified file 'src/privateoption.h' |
1018 | --- src/privateoption.h 2010-11-09 14:13:19 +0000 |
1019 | +++ src/privateoption.h 2012-01-18 14:51:30 +0000 |
1020 | @@ -56,32 +56,6 @@ |
1021 | RestrictionUnion rest; |
1022 | }; |
1023 | |
1024 | -typedef union { |
1025 | - bool b; |
1026 | - int i; |
1027 | - float f; |
1028 | - unsigned short c[4]; |
1029 | -} ValueUnion; |
1030 | - |
1031 | -class PrivateValue { |
1032 | - public: |
1033 | - PrivateValue (); |
1034 | - PrivateValue (const PrivateValue&); |
1035 | - |
1036 | - void reset (); |
1037 | - bool checkType (CompOption::Type refType); |
1038 | - |
1039 | - CompOption::Type type; |
1040 | - ValueUnion value; |
1041 | - CompString string; |
1042 | - CompAction action; |
1043 | - CompMatch match; |
1044 | - CompOption::Type listType; |
1045 | - CompOption::Value::Vector list; |
1046 | - |
1047 | - bool active; |
1048 | -}; |
1049 | - |
1050 | class PrivateOption |
1051 | { |
1052 | public: |
1053 | |
1054 | === added directory 'src/tests' |
1055 | === added file 'src/tests/CMakeLists.txt' |
1056 | --- src/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
1057 | +++ src/tests/CMakeLists.txt 2012-01-18 14:51:30 +0000 |
1058 | @@ -0,0 +1,20 @@ |
1059 | +include_directories( |
1060 | + ${CMAKE_CURRENT_SOURCE_DIR} |
1061 | +) |
1062 | + |
1063 | +add_executable( |
1064 | + compiz_option_test |
1065 | + |
1066 | + ${CMAKE_CURRENT_SOURCE_DIR}/option.cpp |
1067 | +) |
1068 | + |
1069 | +target_link_libraries( |
1070 | + compiz_option_test |
1071 | + |
1072 | + compiz_core |
1073 | + |
1074 | + ${GTEST_BOTH_LIBRARIES} |
1075 | + ${CMAKE_THREAD_LIBS_INIT} # Link in pthread. |
1076 | +) |
1077 | + |
1078 | +add_test( compiz_option_test compiz_option_test ) |
1079 | |
1080 | === added file 'src/tests/option.cpp' |
1081 | --- src/tests/option.cpp 1970-01-01 00:00:00 +0000 |
1082 | +++ src/tests/option.cpp 2012-01-18 14:51:30 +0000 |
1083 | @@ -0,0 +1,43 @@ |
1084 | +#include <gtest/gtest.h> |
1085 | + |
1086 | +#include "core/core.h" |
1087 | +#include "core/action.h" |
1088 | +#include "core/match.h" |
1089 | +#include "core/option.h" |
1090 | + |
1091 | +namespace { |
1092 | + template<typename T> |
1093 | + void |
1094 | + check_type_value(CompOption::Type type, const T & value) |
1095 | + { |
1096 | + CompOption::Value v; |
1097 | + v.set(value); |
1098 | + ASSERT_EQ(v.type(),type); |
1099 | + ASSERT_EQ (v.get<T>(),value); |
1100 | + } |
1101 | +} |
1102 | + |
1103 | + |
1104 | + |
1105 | +static unsigned short defaultColor[4] = { 0x0, 0x0, 0x0, 0xffff}; |
1106 | + |
1107 | +TEST(CompOption,Value) |
1108 | +{ |
1109 | + |
1110 | + check_type_value<bool> (CompOption::TypeBool, true); |
1111 | + check_type_value<bool> (CompOption::TypeBool, false); |
1112 | + |
1113 | + check_type_value<int> (CompOption::TypeInt, 1); |
1114 | + check_type_value<float> (CompOption::TypeFloat, 1.f); |
1115 | + check_type_value<CompString> (CompOption::TypeString, CompString("Check")); |
1116 | + |
1117 | + check_type_value<CompAction> (CompOption::TypeAction, CompAction()); |
1118 | + check_type_value<CompMatch> (CompOption::TypeMatch, CompMatch()); |
1119 | + |
1120 | + check_type_value<CompOption::Value::Vector> (CompOption::TypeList, CompOption::Value::Vector(5)); |
1121 | + |
1122 | + CompOption::Value v1, v2; |
1123 | + ASSERT_EQ (v1,v2); |
1124 | + v1.set (CompString("SomeString")); |
1125 | + ASSERT_TRUE(v1 != v2); |
1126 | +} |
There seems to be a lot shown in the diff that isn't about moving global variables. (That bit seems fine.)