Merge lp:~thomas-voss/compiz-core/CompizOptionRework into lp:compiz-core/0.9.5

Proposed by Thomas Voß
Status: Rejected
Rejected by: Sam Spilsbury
Proposed branch: lp:~thomas-voss/compiz-core/CompizOptionRework
Merge into: lp:compiz-core/0.9.5
Diff against target: 2697 lines (+848/-1202)
4 files modified
include/core/action.h (+126/-116)
include/core/option.h (+300/-193)
src/action.cpp (+160/-200)
src/option.cpp (+262/-693)
To merge this branch: bzr merge lp:~thomas-voss/compiz-core/CompizOptionRework
Reviewer Review Type Date Requested Status
Daniel van Vugt Needs Fixing
Sam Spilsbury Needs Resubmitting
Review via email: mp+87714@code.launchpad.net

Description of the change

Switched CompOption to boost::variant

To post a comment you must log in.
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

14 +// #include <core/option.h>

Remove

164 + BindingTypeNone = 0, BindingTypeKey = 1 << 0, BindingTypeButton = 1
165 + << 1, BindingTypeEdgeButton = 1 << 2

Please put that on separate lines. Can you fix your IDE so that it doesn't autoformat existing code?

review: Needs Resubmitting
Revision history for this message
Thomas Voß (thomas-voss) wrote :

Done.

2899. By Thomas Voß

Removed commented out include and adjusted code formatting.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Most of the diff is still reformatting changes that we don't want. Please fix and resubmit again.

review: Needs Fixing

Unmerged revisions

2899. By Thomas Voß

Removed commented out include and adjusted code formatting.

2898. By Thomas Voß

Switched CompOption to boost::variant.

2897. By Sam Spilsbury

Merge lp:~compiz-team/compiz-core/GoogleTest

2896. By Sam Spilsbury

Merged lp:~smspillaz/compiz-core/compiz-core.fix_890947

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-09 16:07:25 +0000
4@@ -30,9 +30,13 @@
5
6 #include <boost/function.hpp>
7
8+#include <vector>
9+
10 #include <X11/Xlib-xcb.h>
11
12-#include <core/option.h>
13+#include <core/string.h>
14+
15+class CompOption;
16
17 class PrivateAction;
18
19@@ -58,121 +62,127 @@
20 /**
21 * Context of an event occuring.
22 */
23-class CompAction {
24- public:
25- typedef enum {
26- StateInitKey = 1 << 0,
27- StateTermKey = 1 << 1,
28- StateInitButton = 1 << 2,
29- StateTermButton = 1 << 3,
30- StateInitBell = 1 << 4,
31- StateInitEdge = 1 << 5,
32- StateTermEdge = 1 << 6,
33- StateInitEdgeDnd = 1 << 7,
34- StateTermEdgeDnd = 1 << 8,
35- StateCommit = 1 << 9,
36- StateCancel = 1 << 10,
37- StateAutoGrab = 1 << 11,
38- StateNoEdgeDelay = 1 << 12
39- } StateEnum;
40-
41- /**
42- * Type of event a CompAction is bound to.
43- */
44- typedef enum {
45- BindingTypeNone = 0,
46- BindingTypeKey = 1 << 0,
47- BindingTypeButton = 1 << 1,
48- BindingTypeEdgeButton = 1 << 2
49- } BindingTypeEnum;
50-
51- class KeyBinding {
52- public:
53- KeyBinding ();
54- KeyBinding (const KeyBinding&);
55- KeyBinding (int keycode, unsigned int modifiers = 0);
56-
57- unsigned int modifiers () const;
58- int keycode () const;
59-
60- bool fromString (const CompString &str);
61- CompString toString () const;
62-
63- private:
64- unsigned int mModifiers;
65- int mKeycode;
66- };
67-
68- class ButtonBinding {
69- public:
70- ButtonBinding ();
71- ButtonBinding (const ButtonBinding&);
72- ButtonBinding (int button, unsigned int modifiers = 0);
73-
74- unsigned int modifiers () const;
75- int button () const;
76-
77- bool fromString (const CompString &str);
78- CompString toString () const;
79-
80- private:
81- unsigned int mModifiers;
82- int mButton;
83- };
84-
85- typedef unsigned int State;
86- typedef unsigned int BindingType;
87- typedef boost::function <bool (CompAction *, State, CompOption::Vector &)> CallBack;
88-
89- public:
90- CompAction ();
91- CompAction (const CompAction &);
92- ~CompAction ();
93-
94- CallBack initiate ();
95- CallBack terminate ();
96-
97- void setInitiate (const CallBack &initiate);
98- void setTerminate (const CallBack &terminate);
99-
100- State state ();
101- BindingType type ();
102-
103- KeyBinding & key ();
104- void setKey (const KeyBinding &key);
105-
106- ButtonBinding & button ();
107- void setButton (const ButtonBinding &button);
108-
109- unsigned int edgeMask ();
110- void setEdgeMask (unsigned int edge);
111-
112- bool bell ();
113- void setBell (bool bell);
114-
115- void setState (State state);
116-
117- void copyState (const CompAction &action);
118-
119- bool operator== (const CompAction& val);
120- CompAction & operator= (const CompAction &action);
121-
122- bool keyFromString (const CompString &str);
123- bool buttonFromString (const CompString &str);
124- bool edgeMaskFromString (const CompString &str);
125-
126- CompString keyToString ();
127- CompString buttonToString ();
128- CompString edgeMaskToString ();
129-
130- static CompString edgeToString (unsigned int edge);
131-
132- bool active ();
133-
134- friend class CompScreen;
135-
136- private:
137- PrivateAction *priv;
138+class CompAction
139+{
140+public:
141+ enum StateEnum
142+ {
143+ StateInitKey = 1 << 0,
144+ StateTermKey = 1 << 1,
145+ StateInitButton = 1 << 2,
146+ StateTermButton = 1 << 3,
147+ StateInitBell = 1 << 4,
148+ StateInitEdge = 1 << 5,
149+ StateTermEdge = 1 << 6,
150+ StateInitEdgeDnd = 1 << 7,
151+ StateTermEdgeDnd = 1 << 8,
152+ StateCommit = 1 << 9,
153+ StateCancel = 1 << 10,
154+ StateAutoGrab = 1 << 11,
155+ StateNoEdgeDelay = 1 << 12
156+ };
157+
158+ /**
159+ * Type of event a CompAction is bound to.
160+ */
161+ enum BindingTypeEnum
162+ {
163+ BindingTypeNone = 0,
164+ BindingTypeKey = 1 << 0,
165+ BindingTypeButton = 1 << 1,
166+ BindingTypeEdgeButton = 1 << 2
167+ };
168+
169+ class KeyBinding
170+ {
171+ public:
172+ KeyBinding ();
173+ KeyBinding (const KeyBinding&);
174+ KeyBinding (int keycode, unsigned int modifiers = 0);
175+
176+ unsigned int modifiers () const;
177+ int keycode () const;
178+
179+ bool fromString (const CompString &str);
180+ CompString toString () const;
181+
182+ private:
183+ unsigned int mModifiers;
184+ int mKeycode;
185+ };
186+
187+ class ButtonBinding
188+ {
189+ public:
190+ ButtonBinding ();
191+ ButtonBinding (const ButtonBinding&);
192+ ButtonBinding (int button, unsigned int modifiers = 0);
193+
194+ unsigned int modifiers () const;
195+ int button () const;
196+
197+ bool fromString (const CompString &str);
198+ CompString toString () const;
199+
200+ private:
201+ unsigned int mModifiers;
202+ int mButton;
203+ };
204+
205+ typedef unsigned int State;
206+ typedef unsigned int BindingType;
207+ typedef boost::function<
208+ bool (CompAction *, State, std::vector<CompOption> &)> CallBack;
209+
210+public:
211+ CompAction ();
212+ CompAction (const CompAction &);
213+ ~CompAction ();
214+
215+ CallBack initiate ();
216+ CallBack terminate ();
217+
218+ void setInitiate (const CallBack &initiate);
219+ void setTerminate (const CallBack &terminate);
220+
221+ State state ();
222+ BindingType type ();
223+
224+ KeyBinding & key ();
225+ void setKey (const KeyBinding &key);
226+
227+ ButtonBinding & button ();
228+ void setButton (const ButtonBinding &button);
229+
230+ unsigned int edgeMask ();
231+ void setEdgeMask (unsigned int edge);
232+
233+ bool bell ();
234+ void setBell (bool bell);
235+
236+ void setState (State state);
237+
238+ void copyState (const CompAction &action);
239+
240+ bool operator== (const CompAction& val) const;
241+ CompAction & operator= (const CompAction &action);
242+
243+ bool keyFromString (const CompString &str);
244+ bool buttonFromString (const CompString &str);
245+ bool edgeMaskFromString (const CompString &str);
246+
247+ CompString keyToString ();
248+ CompString buttonToString ();
249+ CompString edgeMaskToString ();
250+
251+ static CompString edgeToString (unsigned int edge);
252+
253+ bool active ();
254+
255+ friend class CompScreen;
256+
257+private:
258+ PrivateAction *priv;
259 };
260
261 #endif
262
263=== modified file 'include/core/option.h'
264--- include/core/option.h 2011-10-31 13:51:00 +0000
265+++ include/core/option.h 2012-01-09 16:07:25 +0000
266@@ -29,11 +29,15 @@
267 #define _COMPOPTION_H
268
269 #include <core/string.h>
270+
271+#include <boost/variant.hpp>
272+
273 #include <vector>
274
275 class PrivateOption;
276 class PrivateValue;
277 class PrivateRestriction;
278+
279 class CompAction;
280 class CompMatch;
281 class CompScreen;
282@@ -42,199 +46,302 @@
283 * A configuration option with boolean, int, float, String, Color, Key, Button,
284 * Edge, Bell, or List.
285 */
286-class CompOption {
287- /**
288- * Option data types
289- */
290- public:
291- typedef enum {
292- TypeBool,
293- TypeInt,
294- TypeFloat,
295- TypeString,
296- TypeColor,
297- TypeAction,
298- TypeKey,
299- TypeButton,
300- TypeEdge,
301- TypeBell,
302- TypeMatch,
303- TypeList,
304- /* internal use only */
305- TypeUnset
306- } Type;
307-
308- /**
309- * A value of an Option
310- */
311- class Value {
312- public:
313- typedef std::vector<Value> Vector;
314-
315- public:
316- Value ();
317- Value (const Value &);
318- Value (const bool b);
319- Value (const int i);
320- Value (const float f);
321- Value (const unsigned short *color);
322- Value (const CompString& s);
323- Value (const char *s);
324- Value (const CompMatch& m);
325- Value (const CompAction& a);
326- Value (Type type, const Vector& l);
327- ~Value ();
328-
329- Type type () const;
330-
331- void set (const bool b);
332- void set (const int i);
333- void set (const float f);
334- void set (const unsigned short *color);
335- void set (const CompString& s);
336- void set (const char *s);
337- void set (const CompMatch& m);
338- void set (const CompAction& a);
339- void set (Type type, const Vector& l);
340-
341- bool b ();
342- int i ();
343- float f ();
344- unsigned short* c ();
345- CompString s ();
346- CompMatch & match ();
347- CompAction & action ();
348- Type listType ();
349- Vector & list ();
350-
351- bool operator== (const Value& val);
352- bool operator!= (const Value& val);
353- Value & operator= (const Value &val);
354-
355- operator bool ();
356- operator int ();
357- operator float ();
358- operator unsigned short * ();
359- operator CompString ();
360- operator CompMatch & ();
361- operator CompAction & ();
362- operator CompAction * ();
363- operator Type ();
364- operator Vector & ();
365-
366- private:
367- PrivateValue *priv;
368- };
369-
370- /**
371- * TODO
372- */
373- class Restriction {
374- public:
375- Restriction ();
376- Restriction (const Restriction &);
377- ~Restriction ();
378-
379- int iMin ();
380- int iMax ();
381- float fMin ();
382- float fMax ();
383- float fPrecision ();
384-
385- void set (int, int);
386- void set (float, float, float);
387-
388- bool inRange (int);
389- bool inRange (float);
390-
391- Restriction & operator= (const Restriction &rest);
392- private:
393- PrivateRestriction *priv;
394- };
395-
396- typedef std::vector<CompOption> Vector;
397-
398- /**
399- * TODO
400- */
401- class Class {
402- public:
403- virtual ~Class() {};
404- virtual Vector & getOptions () = 0;
405-
406- virtual CompOption * getOption (const CompString &name);
407-
408- virtual bool setOption (const CompString &name,
409- Value &value) = 0;
410- };
411-
412- public:
413- CompOption ();
414- CompOption (const CompOption &);
415- CompOption (CompString name, Type type);
416- ~CompOption ();
417-
418- void setName (CompString name, Type type);
419-
420- void reset ();
421-
422- CompString name ();
423-
424- Type type ();
425- Value & value ();
426- Restriction & rest ();
427-
428- bool set (Value &val);
429- bool isAction ();
430-
431- CompOption & operator= (const CompOption &option);
432-
433- public:
434- static CompOption * findOption (Vector &options, CompString name,
435- unsigned int *index = NULL);
436-
437- static bool
438- getBoolOptionNamed (const Vector& options,
439- const CompString& name,
440- bool defaultValue = false);
441-
442- static int
443- getIntOptionNamed (const Vector& options,
444- const CompString& name,
445- int defaultValue = 0);
446-
447- static float
448- getFloatOptionNamed (const Vector& options,
449- const CompString& name,
450- const float& defaultValue = 0.0);
451-
452- static CompString
453- getStringOptionNamed (const Vector& options,
454- const CompString& name,
455- const CompString& defaultValue = "");
456-
457- static unsigned short *
458- getColorOptionNamed (const Vector& options,
459- const CompString& name,
460- unsigned short *defaultValue);
461-
462- static CompMatch
463- getMatchOptionNamed (const Vector& options,
464- const CompString& name,
465- const CompMatch& defaultValue);
466-
467- static CompString typeToString (Type type);
468-
469- static bool stringToColor (CompString color,
470- unsigned short *rgba);
471-
472- static CompString colorToString (unsigned short *rgba);
473-
474-
475- static bool setOption (CompOption &o, Value &value);
476-
477- private:
478- PrivateOption *priv;
479+class CompOption
480+{
481+ /**
482+ * Option data types
483+ */
484+public:
485+ typedef enum
486+ {
487+ TypeBool = 0,
488+ TypeInt = 1,
489+ TypeFloat = 2,
490+ TypeString = 3,
491+ TypeColor = 4,
492+ TypeAction = 5,
493+ TypeKey = 6,
494+ TypeButton = 7,
495+ TypeEdge = 8,
496+ TypeBell = 9,
497+ TypeMatch = 10,
498+ TypeList = 11,
499+ /* internal use only */
500+ TypeUnset
501+ } Type;
502+
503+ /**
504+ * A value of an Option
505+ */
506+ class Value
507+ {
508+ public:
509+
510+ typedef boost::variant<bool, int, float, unsigned short*, CompString,
511+ char*, boost::recursive_wrapper<CompMatch>,
512+ boost::recursive_wrapper<CompAction>,
513+ boost::recursive_wrapper<Value>,
514+ boost::recursive_wrapper<std::vector<Value> > > variant_type;
515+
516+ typedef std::vector<Value> Vector;
517+
518+ Value ()
519+ {
520+ }
521+
522+ template<typename T>
523+ Value (const T & t) :
524+ value(t)
525+ {
526+ }
527+
528+ Type type () const
529+ {
530+ return static_cast<Type>(value.which());
531+ }
532+
533+ template<typename T>
534+ void set (const T & t)
535+ {
536+ value = t;
537+ }
538+
539+ void set (Type type, const Vector & v)
540+ {
541+ value = v;
542+ }
543+
544+ bool
545+ b ();
546+
547+ int
548+ i ();
549+
550+ float
551+ f ();
552+
553+ unsigned short*
554+ c ();
555+
556+ CompString&
557+ s ();
558+
559+ CompMatch&
560+ match ();
561+
562+ CompAction&
563+ action ();
564+
565+ Type
566+ listType ();
567+
568+ Vector&
569+ list ();
570+
571+ bool
572+ operator== (const Value & rhs) const;
573+
574+ bool operator!= (const Value & rhs) const
575+ {
576+ return (!(*this == rhs));
577+ }
578+
579+ private:
580+ variant_type value;
581+ };
582+
583+ /**
584+ * @brief Models an interval of valid values for numeric types.
585+ */
586+ class Restriction
587+ {
588+ public:
589+ /**
590+ * @brief Default c'tor.
591+ */
592+ Restriction ();
593+
594+ /**
595+ * @brief Copy c'tor.
596+ *
597+ * Replace compiler-generated copy c'tor due to pimpl
598+ * and missing copy-on-write functionality.
599+ */
600+ Restriction (const Restriction &);
601+
602+ /**
603+ * @brief Default d'tor.
604+ *
605+ * Replace compiler-generated d'tor due to pimpl.
606+ */
607+ ~Restriction ();
608+
609+ /**
610+ * @brief Accesses the minimum valid integer value.
611+ */
612+ int
613+ iMin ();
614+
615+ /**
616+ * @brief Accesses the maximum valid integer value.
617+ */
618+ int
619+ iMax ();
620+
621+ /**
622+ * @brief Accesses the minimum valid fp value.
623+ */
624+ float
625+ fMin ();
626+
627+ /**
628+ * @brief Accesses the maximum valid fp value.
629+ */
630+ float
631+ fMax ();
632+
633+ /**
634+ * @brief Accesses the fp precision.
635+ */
636+ float
637+ fPrecision ();
638+
639+ /**
640+ * @brief Adjusts the integer bounds.
641+ */
642+ void
643+ set (int, int);
644+
645+ /**
646+ * @brief Adjusts the fp bounds and fp precision.
647+ */
648+ void
649+ set (float, float, float);
650+
651+ /**
652+ * @brief Checks the provided value if its valid w.r.t. the restriction object.
653+ * @returns true if iMin <= value <= iMax.
654+ */
655+ bool
656+ inRange (int);
657+
658+ /**
659+ * @brief Checks the provided value if its valid w.r.t. the restriction object.
660+ * @returns true if fMin <= value <= fMax.
661+ */
662+ bool
663+ inRange (float);
664+
665+ /**
666+ * @brief Assignment operator overriden due to pimpl.
667+ */
668+ Restriction&
669+ operator= (const Restriction &rest);
670+ private:
671+ PrivateRestriction *priv;
672+ };
673+public:
674+ typedef std::vector<CompOption> Vector;
675+
676+ /**
677+ * @brief Models a type that provides options.
678+ */
679+ class Class
680+ {
681+ public:
682+ virtual ~Class ()
683+ {
684+ }
685+ ;
686+
687+ virtual Vector &
688+ getOptions () = 0;
689+
690+ virtual CompOption *
691+ getOption (const CompString &name);
692+
693+ virtual bool
694+ setOption (const CompString &name, Value &value) = 0;
695+ };
696+
697+public:
698+ CompOption ();
699+ CompOption (const CompOption &);
700+ CompOption (CompString name, Type type);
701+ ~CompOption ();
702+
703+ void
704+ setName (CompString name, Type type);
705+
706+ void
707+ reset ();
708+
709+ CompString
710+ name ();
711+
712+ Type
713+ type ();
714+
715+ Value &
716+ value ();
717+
718+ Restriction &
719+ rest ();
720+
721+ bool
722+ set (Value &val);
723+
724+ bool
725+ isAction ();
726+
727+ CompOption &
728+ operator= (const CompOption &option);
729+
730+public:
731+ static CompOption * findOption (Vector &options,
732+ CompString name,
733+ unsigned int *index = NULL);
734+
735+ static bool
736+ getBoolOptionNamed (const Vector& options,
737+ const CompString& name,
738+ bool defaultValue = false);
739+
740+ static int
741+ getIntOptionNamed (const Vector& options,
742+ const CompString& name,
743+ int defaultValue = 0);
744+
745+ static float
746+ getFloatOptionNamed (const Vector& options,
747+ const CompString& name,
748+ const float& defaultValue = 0.0);
749+
750+ static CompString
751+ getStringOptionNamed (const Vector& options,
752+ const CompString& name,
753+ const CompString& defaultValue = "");
754+
755+ static unsigned short *
756+ getColorOptionNamed (const Vector& options,
757+ const CompString& name,
758+ unsigned short *defaultValue);
759+
760+ static CompMatch
761+ getMatchOptionNamed (const Vector& options,
762+ const CompString& name,
763+ const CompMatch& defaultValue);
764+
765+ static CompString typeToString (Type type);
766+
767+ static bool stringToColor (CompString color, unsigned short *rgba);
768+
769+ static CompString colorToString (unsigned short *rgba);
770+
771+ static bool setOption (CompOption &o, Value &value);
772+
773+private:
774+ PrivateOption *priv;
775 };
776
777 extern CompOption::Vector noOptions;
778
779=== modified file 'src/action.cpp'
780--- src/action.cpp 2011-10-31 13:51:00 +0000
781+++ src/action.cpp 2012-01-09 16:07:25 +0000
782@@ -33,42 +33,43 @@
783 #include "privateaction.h"
784 #include "privatescreen.h"
785
786-struct _Modifier {
787+struct _Modifier
788+{
789 const char *name;
790- int modifier;
791-} modifiers[] = {
792- { "<Shift>", ShiftMask },
793- { "<Control>", ControlMask },
794- { "<Mod1>", Mod1Mask },
795- { "<Mod2>", Mod2Mask },
796- { "<Mod3>", Mod3Mask },
797- { "<Mod4>", Mod4Mask },
798- { "<Mod5>", Mod5Mask },
799- { "<Alt>", CompAltMask },
800- { "<Meta>", CompMetaMask },
801- { "<Super>", CompSuperMask },
802- { "<Hyper>", CompHyperMask },
803- { "<ModeSwitch>", CompModeSwitchMask }
804-};
805+ int modifier;
806+} modifiers[] =
807+{
808+{ "<Shift>", ShiftMask },
809+{ "<Control>", ControlMask },
810+{ "<Mod1>", Mod1Mask },
811+{ "<Mod2>", Mod2Mask },
812+{ "<Mod3>", Mod3Mask },
813+{ "<Mod4>", Mod4Mask },
814+{ "<Mod5>", Mod5Mask },
815+{ "<Alt>", CompAltMask },
816+{ "<Meta>", CompMetaMask },
817+{ "<Super>", CompSuperMask },
818+{ "<Hyper>", CompHyperMask },
819+{ "<ModeSwitch>", CompModeSwitchMask } };
820
821 #define N_MODIFIERS (sizeof (modifiers) / sizeof (struct _Modifier))
822
823-struct _Edge {
824+struct _Edge
825+{
826 const char *name;
827 const char *modifierName;
828-} edges[] = {
829- { "Left", "<LeftEdge>" },
830- { "Right", "<RightEdge>" },
831- { "Top", "<TopEdge>" },
832- { "Bottom", "<BottomEdge>" },
833- { "TopLeft", "<TopLeftEdge>" },
834- { "TopRight", "<TopRightEdge>" },
835- { "BottomLeft", "<BottomLeftEdge>" },
836- { "BottomRight", "<BottomRightEdge>" }
837-};
838+} edges[] =
839+{
840+{ "Left", "<LeftEdge>" },
841+{ "Right", "<RightEdge>" },
842+{ "Top", "<TopEdge>" },
843+{ "Bottom", "<BottomEdge>" },
844+{ "TopLeft", "<TopLeftEdge>" },
845+{ "TopRight", "<TopRightEdge>" },
846+{ "BottomLeft", "<BottomLeftEdge>" },
847+{ "BottomRight", "<BottomRightEdge>" } };
848
849-static CompString
850-modifiersToString (unsigned int modMask)
851+static CompString modifiersToString (unsigned int modMask)
852 {
853 CompString binding;
854
855@@ -81,37 +82,34 @@
856 return binding;
857 }
858
859-static unsigned int
860-stringToModifiers (CompString str)
861+static unsigned int stringToModifiers (CompString str)
862 {
863 unsigned int mods = 0;
864
865 for (unsigned int i = 0; i < N_MODIFIERS; i++)
866 {
867- if (str.find (modifiers[i].name) != std::string::npos)
868+ if (str.find(modifiers[i].name) != std::string::npos)
869 mods |= modifiers[i].modifier;
870 }
871
872 return mods;
873 }
874
875-static unsigned int
876-bindingStringToEdgeMask (CompString str)
877+static unsigned int bindingStringToEdgeMask (CompString str)
878 {
879 unsigned int edgeMask = 0;
880
881 for (int i = 0; i < SCREEN_EDGE_NUM; i++)
882- if (str.find (edges[i].modifierName) != std::string::npos)
883+ if (str.find(edges[i].modifierName) != std::string::npos)
884 edgeMask |= 1 << i;
885
886 return edgeMask;
887 }
888
889-static CompString
890-edgeMaskToBindingString (unsigned int edgeMask)
891+static CompString edgeMaskToBindingString (unsigned int edgeMask)
892 {
893 CompString binding;
894- int i;
895+ int i;
896
897 for (i = 0; i < SCREEN_EDGE_NUM; i++)
898 if (edgeMask & (1 << i))
899@@ -121,60 +119,54 @@
900 }
901
902 CompAction::KeyBinding::KeyBinding () :
903- mModifiers (0),
904- mKeycode (0)
905+ mModifiers(0), mKeycode(0)
906 {
907 }
908
909 CompAction::KeyBinding::KeyBinding (const KeyBinding& k) :
910- mModifiers (k.mModifiers),
911- mKeycode (k.mKeycode)
912+ mModifiers(k.mModifiers), mKeycode(k.mKeycode)
913 {
914 }
915
916 CompAction::KeyBinding::KeyBinding (int keycode, unsigned int modifiers) :
917- mModifiers (modifiers),
918- mKeycode (keycode)
919+ mModifiers(modifiers), mKeycode(keycode)
920 {
921 }
922
923-unsigned int
924-CompAction::KeyBinding::modifiers () const
925+unsigned int CompAction::KeyBinding::modifiers () const
926 {
927 return mModifiers;
928 }
929
930-int
931-CompAction::KeyBinding::keycode () const
932+int CompAction::KeyBinding::keycode () const
933 {
934 return mKeycode;
935 }
936
937-bool
938-CompAction::KeyBinding::fromString (const CompString &str)
939+bool CompAction::KeyBinding::fromString (const CompString &str)
940 {
941- CompString sStr;
942+ CompString sStr;
943 unsigned int mods;
944- size_t pos, start = 0;
945- KeySym keysym;
946+ size_t pos, start = 0;
947+ KeySym keysym;
948
949 if (!screen)
950 return false;
951
952- mods = stringToModifiers (str);
953+ mods = stringToModifiers(str);
954
955- pos = str.rfind ('>');
956+ pos = str.rfind('>');
957 if (pos != std::string::npos)
958 start = pos + 1;
959
960- while (start < str.size () && !isalnum (str[start]))
961+ while (start < str.size() && !isalnum(str[start]))
962 start++;
963
964- if (start == str.size ())
965+ if (start == str.size())
966 {
967 if (mods)
968 {
969- mKeycode = 0;
970+ mKeycode = 0;
971 mModifiers = mods;
972
973 return true;
974@@ -183,26 +175,26 @@
975 return false;
976 }
977
978- sStr = str.substr (start);
979- keysym = XStringToKeysym (sStr.c_str ());
980+ sStr = str.substr(start);
981+ keysym = XStringToKeysym(sStr.c_str());
982
983 if (keysym != NoSymbol)
984 {
985 KeyCode keycode;
986
987- keycode = XKeysymToKeycode (screen->dpy (), keysym);
988+ keycode = XKeysymToKeycode(screen->dpy(), keysym);
989 if (keycode)
990 {
991- mKeycode = keycode;
992+ mKeycode = keycode;
993 mModifiers = mods;
994
995 return true;
996 }
997 }
998
999- if (sStr.compare (0, 2, "0x") == 0)
1000+ if (sStr.compare(0, 2, "0x") == 0)
1001 {
1002- mKeycode = strtol (sStr.c_str (), NULL, 0);
1003+ mKeycode = strtol(sStr.c_str(), NULL, 0);
1004 mModifiers = mods;
1005
1006 return true;
1007@@ -211,85 +203,78 @@
1008 return false;
1009 }
1010
1011-CompString
1012-CompAction::KeyBinding::toString () const
1013+CompString CompAction::KeyBinding::toString () const
1014 {
1015 CompString binding;
1016
1017 if (!screen)
1018 return "";
1019
1020- binding = modifiersToString (mModifiers);
1021+ binding = modifiersToString(mModifiers);
1022
1023 if (mKeycode != 0)
1024 {
1025 KeySym keysym;
1026- char *keyname;
1027+ char *keyname;
1028
1029- keysym = XKeycodeToKeysym (screen->dpy (), mKeycode, 0);
1030- keyname = XKeysymToString (keysym);
1031+ keysym = XKeycodeToKeysym(screen->dpy(), mKeycode, 0);
1032+ keyname = XKeysymToString(keysym);
1033
1034 if (keyname)
1035 binding += keyname;
1036 else
1037- binding += compPrintf ("0x%x", mKeycode);
1038+ binding += compPrintf("0x%x", mKeycode);
1039 }
1040
1041 return binding;
1042 }
1043
1044 CompAction::ButtonBinding::ButtonBinding () :
1045- mModifiers (0),
1046- mButton (0)
1047+ mModifiers(0), mButton(0)
1048 {
1049 }
1050
1051 CompAction::ButtonBinding::ButtonBinding (const ButtonBinding& b) :
1052- mModifiers (b.mModifiers),
1053- mButton (b.mButton)
1054+ mModifiers(b.mModifiers), mButton(b.mButton)
1055 {
1056 }
1057
1058 CompAction::ButtonBinding::ButtonBinding (int button, unsigned int modifiers) :
1059- mModifiers (modifiers),
1060- mButton (button)
1061+ mModifiers(modifiers), mButton(button)
1062 {
1063 }
1064
1065-unsigned int
1066-CompAction::ButtonBinding::modifiers () const
1067+unsigned int CompAction::ButtonBinding::modifiers () const
1068 {
1069 return mModifiers;
1070 }
1071
1072-int
1073-CompAction::ButtonBinding::button () const
1074+int CompAction::ButtonBinding::button () const
1075 {
1076 return mButton;
1077 }
1078
1079-bool
1080-CompAction::ButtonBinding::fromString (const CompString &str)
1081+bool CompAction::ButtonBinding::fromString (const CompString &str)
1082 {
1083 unsigned int mods;
1084- size_t pos, start = 0;
1085-
1086- mods = stringToModifiers (str);
1087-
1088- pos = str.rfind ('>');
1089+ size_t pos, start = 0;
1090+
1091+ mods = stringToModifiers(str);
1092+
1093+ pos = str.rfind('>');
1094 if (pos != std::string::npos)
1095 start = pos + 1;
1096
1097- while (start < str.size () && !isalnum (str[start]))
1098+ while (start < str.size() && !isalnum(str[start]))
1099 start++;
1100
1101- if (start != str.size () && str.compare (start, 6, "Button") == 0)
1102+ if (start != str.size() && str.compare(start, 6, "Button") == 0)
1103 {
1104 int buttonNum;
1105
1106- if (sscanf (str.substr (start + 6).c_str (), "%d", &buttonNum) == 1)
1107+ if (sscanf(str.substr(start + 6).c_str(), "%d", &buttonNum) == 1)
1108 {
1109- mButton = buttonNum;
1110+ mButton = buttonNum;
1111 mModifiers = mods;
1112
1113 return true;
1114@@ -299,27 +284,26 @@
1115 return false;
1116 }
1117
1118-CompString
1119-CompAction::ButtonBinding::toString () const
1120+CompString CompAction::ButtonBinding::toString () const
1121 {
1122 CompString binding;
1123
1124 if (!mModifiers && !mButton)
1125 return "";
1126
1127- binding = modifiersToString (mModifiers);
1128- binding += compPrintf ("Button%d", mButton);
1129+ binding = modifiersToString(mModifiers);
1130+ binding += compPrintf("Button%d", mButton);
1131
1132 return binding;
1133 }
1134
1135 CompAction::CompAction () :
1136- priv (new PrivateAction ())
1137+ priv(new PrivateAction())
1138 {
1139 }
1140
1141 CompAction::CompAction (const CompAction & a) :
1142- priv (new PrivateAction (*a.priv))
1143+ priv(new PrivateAction(*a.priv))
1144 {
1145 }
1146
1147@@ -328,38 +312,32 @@
1148 delete priv;
1149 }
1150
1151-CompAction::CallBack
1152-CompAction::initiate ()
1153+CompAction::CallBack CompAction::initiate ()
1154 {
1155 return priv->initiate;
1156 }
1157
1158-CompAction::CallBack
1159-CompAction::terminate ()
1160+CompAction::CallBack CompAction::terminate ()
1161 {
1162 return priv->terminate;
1163 }
1164
1165-void
1166-CompAction::setInitiate (const CompAction::CallBack &initiate)
1167+void CompAction::setInitiate (const CompAction::CallBack &initiate)
1168 {
1169 priv->initiate = initiate;
1170 }
1171
1172-void
1173-CompAction::setTerminate (const CompAction::CallBack &terminate)
1174+void CompAction::setTerminate (const CompAction::CallBack &terminate)
1175 {
1176 priv->terminate = terminate;
1177 }
1178
1179-CompAction::State
1180-CompAction::state ()
1181+CompAction::State CompAction::state ()
1182 {
1183 return priv->state;
1184 }
1185
1186-CompAction::BindingType
1187-CompAction::type ()
1188+CompAction::BindingType CompAction::type ()
1189 {
1190 return priv->type;
1191 }
1192@@ -370,12 +348,11 @@
1193 return priv->key;
1194 }
1195
1196-void
1197-CompAction::setKey (const CompAction::KeyBinding &key)
1198+void CompAction::setKey (const CompAction::KeyBinding &key)
1199 {
1200 priv->key = key;
1201
1202- if (key.modifiers () || key.keycode ())
1203+ if (key.modifiers() || key.keycode())
1204 priv->type = CompAction::BindingTypeKey;
1205 else
1206 priv->type = CompAction::BindingTypeNone;
1207@@ -387,12 +364,11 @@
1208 return priv->button;
1209 }
1210
1211-void
1212-CompAction::setButton (const CompAction::ButtonBinding &button)
1213+void CompAction::setButton (const CompAction::ButtonBinding &button)
1214 {
1215 priv->button = button;
1216
1217- if (button.modifiers () || button.button ())
1218+ if (button.modifiers() || button.button())
1219 {
1220 if (priv->edgeMask)
1221 priv->type = CompAction::BindingTypeEdgeButton;
1222@@ -405,19 +381,17 @@
1223 }
1224 }
1225
1226-unsigned int
1227-CompAction::edgeMask ()
1228+unsigned int CompAction::edgeMask ()
1229 {
1230 return priv->edgeMask;
1231 }
1232
1233-void
1234-CompAction::setEdgeMask (unsigned int edge)
1235+void CompAction::setEdgeMask (unsigned int edge)
1236 {
1237 priv->edgeMask = edge;
1238
1239- if (priv->type == CompAction::BindingTypeEdgeButton ||
1240- priv->type == CompAction::BindingTypeButton)
1241+ if (priv->type == CompAction::BindingTypeEdgeButton
1242+ || priv->type == CompAction::BindingTypeButton)
1243 {
1244 if (priv->edgeMask)
1245 priv->type = CompAction::BindingTypeEdgeButton;
1246@@ -426,54 +400,49 @@
1247 }
1248 }
1249
1250-bool
1251-CompAction::bell ()
1252+bool CompAction::bell ()
1253 {
1254 return priv->bell;
1255 }
1256
1257-void
1258-CompAction::setBell (bool bell)
1259+void CompAction::setBell (bool bell)
1260 {
1261 priv->bell = bell;
1262 }
1263
1264-void
1265-CompAction::setState (CompAction::State state)
1266+void CompAction::setState (CompAction::State state)
1267 {
1268 priv->state = state;
1269 }
1270
1271-void
1272-CompAction::copyState (const CompAction &action)
1273+void CompAction::copyState (const CompAction &action)
1274 {
1275- priv->initiate = action.priv->initiate;
1276+ priv->initiate = action.priv->initiate;
1277 priv->terminate = action.priv->terminate;
1278- priv->state = action.priv->state;
1279+ priv->state = action.priv->state;
1280
1281- memcpy (&priv->priv, &action.priv->priv, sizeof (CompPrivate));
1282+ memcpy(&priv->priv, &action.priv->priv, sizeof(CompPrivate));
1283 }
1284
1285-bool
1286-CompAction::operator== (const CompAction& val)
1287+bool CompAction::operator== (const CompAction& val) const
1288 {
1289 if (priv->state != val.priv->state)
1290 return false;
1291 if (priv->type != val.priv->type)
1292 return false;
1293- if (priv->key.modifiers () != val.priv->key.modifiers ())
1294- return false;
1295- if (priv->key.keycode () != val.priv->key.keycode ())
1296- return false;
1297- if (priv->button.modifiers () != val.priv->button.modifiers ())
1298- return false;
1299- if (priv->button.button () != val.priv->button.button ())
1300+ if (priv->key.modifiers() != val.priv->key.modifiers())
1301+ return false;
1302+ if (priv->key.keycode() != val.priv->key.keycode())
1303+ return false;
1304+ if (priv->button.modifiers() != val.priv->button.modifiers())
1305+ return false;
1306+ if (priv->button.button() != val.priv->button.button())
1307 return false;
1308 if (priv->bell != val.priv->bell)
1309 return false;
1310 if (priv->edgeMask != val.priv->edgeMask)
1311 return false;
1312- if (memcmp (&priv->priv, &val.priv->priv, sizeof (CompPrivate)) != 0)
1313+ if (memcmp(&priv->priv, &val.priv->priv, sizeof(CompPrivate)) != 0)
1314 return false;
1315
1316 return true;
1317@@ -486,15 +455,14 @@
1318 return *this;
1319
1320 delete priv;
1321- priv = new PrivateAction (*action.priv);
1322+ priv = new PrivateAction(*action.priv);
1323
1324 return *this;
1325 }
1326
1327-bool
1328-CompAction::keyFromString (const CompString &str)
1329+bool CompAction::keyFromString (const CompString &str)
1330 {
1331- bool retval = priv->key.fromString (str);
1332+ bool retval = priv->key.fromString(str);
1333
1334 if (retval)
1335 {
1336@@ -510,14 +478,13 @@
1337 return retval;
1338 }
1339
1340-bool
1341-CompAction::buttonFromString (const CompString &str)
1342+bool CompAction::buttonFromString (const CompString &str)
1343 {
1344- bool retval = priv->button.fromString (str);
1345+ bool retval = priv->button.fromString(str);
1346
1347 if (retval)
1348 {
1349- priv->edgeMask = bindingStringToEdgeMask (str);
1350+ priv->edgeMask = bindingStringToEdgeMask(str);
1351 if (priv->edgeMask)
1352 priv->type = CompAction::BindingTypeEdgeButton;
1353 else
1354@@ -533,26 +500,25 @@
1355 return retval;
1356 }
1357
1358-bool
1359-CompAction::edgeMaskFromString (const CompString &str)
1360+bool CompAction::edgeMaskFromString (const CompString &str)
1361 {
1362 unsigned int edgeMask = 0;
1363- size_t pos;
1364+ size_t pos;
1365
1366 for (int i = 0; i < SCREEN_EDGE_NUM; i++)
1367 {
1368 pos = 0;
1369- while ((pos = str.find (edgeToString (i), pos)) != std::string::npos)
1370+ while ((pos = str.find(edgeToString(i), pos)) != std::string::npos)
1371 {
1372- if (pos > 0 && isalnum (str[pos - 1]))
1373+ if (pos > 0 && isalnum(str[pos - 1]))
1374 {
1375 pos++;
1376 continue;
1377 }
1378
1379- pos += edgeToString (i).size ();
1380+ pos += edgeToString(i).size();
1381
1382- if (pos < str.size () && isalnum (str[pos]))
1383+ if (pos < str.size() && isalnum(str[pos]))
1384 continue;
1385
1386 edgeMask |= 1 << i;
1387@@ -561,39 +527,36 @@
1388
1389 priv->edgeMask = edgeMask;
1390
1391- return (edgeMask != 0 || str.empty ());
1392+ return (edgeMask != 0 || str.empty());
1393 }
1394
1395-CompString
1396-CompAction::keyToString ()
1397+CompString CompAction::keyToString ()
1398 {
1399 CompString binding;
1400
1401- binding = priv->key.toString ();
1402- if (!binding.size ())
1403+ binding = priv->key.toString();
1404+ if (!binding.size())
1405 return "Disabled";
1406
1407 return binding;
1408 }
1409
1410-CompString
1411-CompAction::buttonToString ()
1412+CompString CompAction::buttonToString ()
1413 {
1414 CompString binding, edge;
1415
1416- binding = modifiersToString (priv->button.modifiers ());
1417- binding += edgeMaskToBindingString (priv->edgeMask);
1418-
1419- binding += compPrintf ("Button%d", priv->button.button ());
1420-
1421- if (!priv->button.button ())
1422+ binding = modifiersToString(priv->button.modifiers());
1423+ binding += edgeMaskToBindingString(priv->edgeMask);
1424+
1425+ binding += compPrintf("Button%d", priv->button.button());
1426+
1427+ if (!priv->button.button())
1428 return "Disabled";
1429
1430 return binding;
1431 }
1432
1433-CompString
1434-CompAction::edgeMaskToString ()
1435+CompString CompAction::edgeMaskToString ()
1436 {
1437 CompString edge;
1438
1439@@ -601,53 +564,50 @@
1440 {
1441 if (priv->edgeMask & (1 << i))
1442 {
1443- if (!edge.empty ())
1444+ if (!edge.empty())
1445 edge += " | ";
1446
1447- edge += edgeToString (i);
1448+ edge += edgeToString(i);
1449 }
1450 }
1451
1452 return edge;
1453 }
1454
1455-
1456-CompString
1457-CompAction::edgeToString (unsigned int edge)
1458+CompString CompAction::edgeToString (unsigned int edge)
1459 {
1460 return edges[edge].name;
1461 }
1462
1463-bool
1464-CompAction::active ()
1465+bool CompAction::active ()
1466 {
1467 return priv->active;
1468 }
1469
1470 PrivateAction::PrivateAction () :
1471- initiate (),
1472- terminate (),
1473- state (0),
1474- type (0),
1475- key (),
1476- button (),
1477- bell (false),
1478- edgeMask (0),
1479- active (false)
1480+ initiate(),
1481+ terminate(),
1482+ state(0),
1483+ type(0),
1484+ key(),
1485+ button(),
1486+ bell(false),
1487+ edgeMask(0),
1488+ active(false)
1489 {
1490- memset (&priv, 0, sizeof (CompPrivate));
1491+ memset(&priv, 0, sizeof(CompPrivate));
1492 }
1493
1494 PrivateAction::PrivateAction (const PrivateAction& a) :
1495- initiate (a.initiate),
1496- terminate (a.terminate),
1497- state (a.state),
1498- type (a.type),
1499- key (a.key),
1500- button (a.button),
1501- bell (a.bell),
1502- edgeMask (a.edgeMask),
1503- active (a.active)
1504+ initiate(a.initiate),
1505+ terminate(a.terminate),
1506+ state(a.state),
1507+ type(a.type),
1508+ key(a.key),
1509+ button(a.button),
1510+ bell(a.bell),
1511+ edgeMask(a.edgeMask),
1512+ active(a.active)
1513 {
1514- memcpy (&priv, &a.priv, sizeof (CompPrivate));
1515+ memcpy(&priv, &a.priv, sizeof(CompPrivate));
1516 }
1517
1518=== modified file 'src/option.cpp'
1519--- src/option.cpp 2010-11-11 03:14:20 +0000
1520+++ src/option.cpp 2012-01-09 16:07:25 +0000
1521@@ -32,491 +32,89 @@
1522 #include <boost/foreach.hpp>
1523 #define foreach BOOST_FOREACH
1524
1525+#include <core/action.h>
1526 #include <core/core.h>
1527 #include <core/option.h>
1528 #include "privateoption.h"
1529
1530-CompOption::Vector noOptions (0);
1531-
1532-CompOption::Value::Value () :
1533- priv (new PrivateValue ())
1534-{
1535-}
1536-
1537-CompOption::Value::Value (const Value &v) :
1538- priv (new PrivateValue (*v.priv))
1539-{
1540-}
1541-
1542-CompOption::Value::~Value ()
1543-{
1544- delete priv;
1545-}
1546-
1547-CompOption::Value::Value (const bool b) :
1548- priv (new PrivateValue ())
1549-{
1550- set (b);
1551-}
1552-
1553-CompOption::Value::Value (const int i) :
1554- priv (new PrivateValue ())
1555-{
1556- set (i);
1557-}
1558-
1559-CompOption::Value::Value (const float f) :
1560- priv (new PrivateValue ())
1561-{
1562- set (f);
1563-}
1564-
1565-CompOption::Value::Value (const unsigned short *color) :
1566- priv (new PrivateValue ())
1567-{
1568- set (color);
1569-}
1570-
1571-CompOption::Value::Value (const CompString& s) :
1572- priv (new PrivateValue ())
1573-{
1574- set (s);
1575-}
1576-
1577-CompOption::Value::Value (const char *s) :
1578- priv (new PrivateValue ())
1579-{
1580- set (s);
1581-}
1582-
1583-
1584-CompOption::Value::Value (const CompMatch& m) :
1585- priv (new PrivateValue ())
1586-{
1587- set (m);
1588-}
1589-
1590-CompOption::Value::Value (const CompAction& a) :
1591- priv (new PrivateValue ())
1592-{
1593- set (a);
1594-}
1595-
1596-CompOption::Value::Value (CompOption::Type type, const Vector& l) :
1597- priv (new PrivateValue ())
1598-{
1599- set (type, l);
1600-}
1601-
1602-CompOption::Type
1603-CompOption::Value::type () const
1604-{
1605- return priv->type;
1606-}
1607-
1608-void
1609-CompOption::Value::set (const bool b)
1610-{
1611- priv->reset ();
1612- priv->type = CompOption::TypeBool;
1613- priv->value.b = b;
1614-}
1615-
1616-void
1617-CompOption::Value::set (const int i)
1618-{
1619- priv->reset ();
1620- priv->type = CompOption::TypeInt;
1621- priv->value.i = i;
1622-}
1623-
1624-void
1625-CompOption::Value::set (const float f)
1626-{
1627- priv->reset ();
1628- priv->type = CompOption::TypeFloat;
1629- priv->value.f = f;
1630-}
1631-
1632-void
1633-CompOption::Value::set (const unsigned short *color)
1634-{
1635- priv->reset ();
1636- priv->type = CompOption::TypeColor;
1637- priv->value.c[0] = color[0];
1638- priv->value.c[1] = color[1];
1639- priv->value.c[2] = color[2];
1640- priv->value.c[3] = color[3];
1641-}
1642-
1643-void
1644-CompOption::Value::set (const CompString& s)
1645-{
1646- priv->reset ();
1647- priv->type = CompOption::TypeString;
1648- priv->string = s;
1649-}
1650-
1651-void
1652-CompOption::Value::set (const char *s)
1653-{
1654- priv->reset ();
1655- priv->type = CompOption::TypeString;
1656- priv->string = CompString (s);
1657-}
1658-
1659-void
1660-CompOption::Value::set (const CompMatch& m)
1661-{
1662- priv->reset ();
1663- priv->type = CompOption::TypeMatch;
1664- priv->match = m;
1665-}
1666-
1667-void
1668-CompOption::Value::set (const CompAction& a)
1669-{
1670- priv->reset ();
1671- priv->type = CompOption::TypeAction;
1672- priv->action = a;
1673-}
1674-
1675-void
1676-CompOption::Value::set (CompOption::Type type, const Vector& l)
1677-{
1678- priv->reset ();
1679- priv->type = CompOption::TypeList;
1680- priv->list = l;
1681- priv->listType = type;
1682-}
1683-
1684-static bool
1685-checkIsAction (CompOption::Type type)
1686-{
1687- switch (type) {
1688- case CompOption::TypeAction:
1689- case CompOption::TypeKey:
1690- case CompOption::TypeButton:
1691- case CompOption::TypeEdge:
1692- case CompOption::TypeBell:
1693- return true;
1694- default:
1695- break;
1696+CompOption::Vector noOptions(0);
1697+
1698+static bool checkIsAction (CompOption::Type type)
1699+{
1700+ switch (type)
1701+ {
1702+ case CompOption::TypeAction:
1703+ case CompOption::TypeKey:
1704+ case CompOption::TypeButton:
1705+ case CompOption::TypeEdge:
1706+ case CompOption::TypeBell:
1707+ return true;
1708+ default:
1709+ break;
1710 }
1711
1712 return false;
1713 }
1714
1715-bool
1716-CompOption::Value::b ()
1717-{
1718- if (!priv->checkType (CompOption::TypeBool))
1719- return false;
1720-
1721- return priv->value.b;
1722-}
1723-
1724-int
1725-CompOption::Value::i ()
1726-{
1727- if (!priv->checkType (CompOption::TypeInt))
1728- return 0;
1729-
1730- return priv->value.i;
1731-}
1732-
1733-float
1734-CompOption::Value::f ()
1735-{
1736- if (!priv->checkType (CompOption::TypeFloat))
1737- return 0.0;
1738-
1739- return priv->value.f;
1740-}
1741-
1742-static unsigned short defaultColor[4] = { 0x0, 0x0, 0x0, 0xffff};
1743-
1744-unsigned short *
1745+bool CompOption::Value::b ()
1746+{
1747+ return boost::get<bool>(value);
1748+}
1749+int CompOption::Value::i ()
1750+{
1751+ return boost::get<int>(value);
1752+}
1753+float CompOption::Value::f ()
1754+{
1755+ return boost::get<float>(value);
1756+}
1757+unsigned short*
1758 CompOption::Value::c ()
1759 {
1760- if (!priv->checkType (CompOption::TypeColor))
1761- return reinterpret_cast<unsigned short *> (defaultColor);
1762-
1763- return priv->value.c;
1764+ return boost::get<unsigned short*>(value);
1765 }
1766
1767-CompString
1768+CompString&
1769 CompOption::Value::s ()
1770 {
1771- if (!priv->checkType (CompOption::TypeString))
1772- return "";
1773-
1774- return priv->string;
1775+ return boost::get<CompString>(value);
1776 }
1777
1778-CompMatch &
1779+CompMatch&
1780 CompOption::Value::match ()
1781 {
1782- priv->checkType (CompOption::TypeMatch);
1783-
1784- return priv->match;
1785+ return boost::get<CompMatch>(value);
1786 }
1787
1788-CompAction &
1789+CompAction&
1790 CompOption::Value::action ()
1791 {
1792- priv->checkType (priv->type);
1793-
1794- if (!checkIsAction (priv->type))
1795- compLogMessage ("core", CompLogLevelWarn,
1796- "CompOption::Value not an action");
1797-
1798- return priv->action;
1799+ return boost::get<CompAction>(value);
1800 }
1801
1802-CompOption::Type
1803-CompOption::Value::listType ()
1804+CompOption::Type CompOption::Value::listType ()
1805 {
1806- priv->checkType (CompOption::TypeList);
1807-
1808- return priv->listType;
1809+ return type();
1810 }
1811
1812-CompOption::Value::Vector &
1813+CompOption::Value::Vector&
1814 CompOption::Value::list ()
1815 {
1816- priv->checkType (CompOption::TypeList);
1817-
1818- return priv->list;
1819-}
1820-
1821-CompOption::Value::operator bool ()
1822-{
1823- return b ();
1824-}
1825-
1826-CompOption::Value::operator int ()
1827-{
1828- return i ();
1829-}
1830-
1831-CompOption::Value::operator float ()
1832-{
1833- return f ();
1834-}
1835-
1836-CompOption::Value::operator unsigned short * ()
1837-{
1838- return c ();
1839-}
1840-
1841-CompOption::Value::operator CompString ()
1842-{
1843- return s ();
1844-}
1845-
1846-CompOption::Value::operator CompMatch & ()
1847-{
1848- return match ();
1849-}
1850-
1851-CompOption::Value::operator CompAction & ()
1852-{
1853- return action ();
1854-}
1855-
1856-CompOption::Value::operator CompAction * ()
1857-{
1858- return &action ();
1859-}
1860-
1861-CompOption::Value::operator Type ()
1862-{
1863- return listType ();
1864-}
1865-
1866-CompOption::Value::operator Vector & ()
1867-{
1868- return list ();
1869-}
1870-
1871-bool
1872-CompOption::Value::operator== (const CompOption::Value &val)
1873-{
1874- if (priv->type != val.priv->type)
1875- return false;
1876-
1877- switch (priv->type)
1878- {
1879- case CompOption::TypeBool:
1880- return priv->value.b == val.priv->value.b;
1881- break;
1882-
1883- case CompOption::TypeInt:
1884- return priv->value.i == val.priv->value.i;
1885- break;
1886-
1887- case CompOption::TypeFloat:
1888- return priv->value.f == val.priv->value.f;
1889- break;
1890-
1891- case CompOption::TypeColor:
1892- return (priv->value.c[0] == val.priv->value.c[0]) &&
1893- (priv->value.c[1] == val.priv->value.c[1]) &&
1894- (priv->value.c[2] == val.priv->value.c[2]) &&
1895- (priv->value.c[3] == val.priv->value.c[3]);
1896- break;
1897-
1898- case CompOption::TypeString:
1899- return priv->string.compare (val.priv->string) == 0;
1900- break;
1901-
1902- case CompOption::TypeMatch:
1903- return priv->match == val.priv->match;
1904- break;
1905-
1906- case CompOption::TypeAction:
1907- return priv->action == val.priv->action;
1908- break;
1909-
1910- case CompOption::TypeList:
1911- if (priv->listType != val.priv->listType)
1912- return false;
1913-
1914- if (priv->list.size () != val.priv->list.size ())
1915- return false;
1916-
1917- for (unsigned int i = 0; i < priv->list.size (); i++)
1918- if (priv->list[i] != val.priv->list[i])
1919- return false;
1920-
1921- return true;
1922- break;
1923-
1924- default:
1925- break;
1926- }
1927-
1928- return true;
1929-}
1930-
1931-bool
1932-CompOption::Value::operator!= (const CompOption::Value &val)
1933-{
1934- return !(*this == val);
1935-}
1936-
1937-static void
1938-finiOptionValue (CompOption::Value &v,
1939- CompOption::Type type)
1940-{
1941- switch (type) {
1942- case CompOption::TypeAction:
1943- case CompOption::TypeKey:
1944- case CompOption::TypeButton:
1945- case CompOption::TypeEdge:
1946- case CompOption::TypeBell:
1947- if (v.action ().state () & CompAction::StateAutoGrab && screen)
1948- screen->removeAction (&v.action ());
1949- break;
1950-
1951- case CompOption::TypeList:
1952- foreach (CompOption::Value &val, v.list ())
1953- finiOptionValue (val, v.listType ());
1954- break;
1955-
1956- default:
1957- break;
1958- }
1959-}
1960-
1961-CompOption::Value &
1962-CompOption::Value::operator= (const CompOption::Value &val)
1963-{
1964- if (this == &val)
1965- return *this;
1966-
1967- finiOptionValue (*this, priv->type);
1968-
1969- delete priv;
1970- priv = new PrivateValue (*val.priv);
1971-
1972- return *this;
1973-}
1974-
1975-PrivateValue::PrivateValue () :
1976- type (CompOption::TypeUnset),
1977- string (""),
1978- action (),
1979- match (),
1980- listType (CompOption::TypeUnset),
1981- list ()
1982-{
1983- memset (&value, 0, sizeof (ValueUnion));
1984-}
1985-
1986-PrivateValue::PrivateValue (const PrivateValue& p) :
1987- type (p.type),
1988- string (p.string),
1989- action (p.action),
1990- match (p.match),
1991- listType (p.listType),
1992- list (p.list)
1993-{
1994- memcpy (&value, &p.value, sizeof (ValueUnion));
1995-}
1996-
1997-bool
1998-PrivateValue::checkType (CompOption::Type refType)
1999-{
2000- if (type == CompOption::TypeUnset)
2001- {
2002- compLogMessage ("core", CompLogLevelWarn,
2003- "Value type is not yet set");
2004- return false;
2005- }
2006-
2007- if (type != refType)
2008- {
2009- compLogMessage ("core", CompLogLevelWarn,
2010- "Value type does not match (is %d, expected %d)",
2011- type, refType);
2012- return false;
2013- }
2014-
2015- return true;
2016-}
2017-
2018-void
2019-PrivateValue::reset ()
2020-{
2021- switch (type) {
2022- case CompOption::TypeString:
2023- string = "";
2024- break;
2025- case CompOption::TypeMatch:
2026- match = CompMatch ();
2027- break;
2028- case CompOption::TypeAction:
2029- action = CompAction ();
2030- break;
2031- case CompOption::TypeList:
2032- list.clear ();
2033- listType = CompOption::TypeBool;
2034- break;
2035- default:
2036- break;
2037- }
2038- type = CompOption::TypeBool;
2039+ return boost::get<CompOption::Value::Vector>(value);
2040+}
2041+
2042+bool CompOption::Value::operator== (const Value & rhs) const
2043+{
2044+ return value == rhs.value;
2045 }
2046
2047 CompOption::Restriction::Restriction () :
2048- priv (new PrivateRestriction ())
2049+ priv(new PrivateRestriction())
2050 {
2051 }
2052
2053 CompOption::Restriction::Restriction (const CompOption::Restriction &r) :
2054- priv (new PrivateRestriction (*r.priv))
2055+ priv(new PrivateRestriction(*r.priv))
2056 {
2057 }
2058
2059@@ -525,66 +123,57 @@
2060 delete priv;
2061 }
2062
2063-int
2064-CompOption::Restriction::iMin ()
2065+int CompOption::Restriction::iMin ()
2066 {
2067 if (priv->type == CompOption::TypeInt)
2068 return priv->rest.i.min;
2069 return MINSHORT;
2070 }
2071
2072-int
2073-CompOption::Restriction::iMax ()
2074+int CompOption::Restriction::iMax ()
2075 {
2076 if (priv->type == CompOption::TypeInt)
2077 return priv->rest.i.max;
2078 return MAXSHORT;
2079 }
2080
2081-float
2082-CompOption::Restriction::fMin ()
2083-{
2084- if (priv->type == CompOption::TypeFloat)
2085- return priv->rest.f.min;
2086- return MINSHORT;
2087-}
2088-
2089-float
2090-CompOption::Restriction::fMax ()
2091-{
2092- if (priv->type == CompOption::TypeFloat)
2093- return priv->rest.f.min;
2094- return MINSHORT;
2095-}
2096-
2097-float
2098-CompOption::Restriction::fPrecision ()
2099+float CompOption::Restriction::fMin ()
2100+{
2101+ if (priv->type == CompOption::TypeFloat)
2102+ return priv->rest.f.min;
2103+ return MINSHORT;
2104+}
2105+
2106+float CompOption::Restriction::fMax ()
2107+{
2108+ if (priv->type == CompOption::TypeFloat)
2109+ return priv->rest.f.min;
2110+ return MINSHORT;
2111+}
2112+
2113+float CompOption::Restriction::fPrecision ()
2114 {
2115 if (priv->type == CompOption::TypeFloat)
2116 return priv->rest.f.precision;
2117 return 0.1f;
2118 }
2119
2120-
2121-void
2122-CompOption::Restriction::set (int min, int max)
2123+void CompOption::Restriction::set (int min, int max)
2124 {
2125 priv->type = CompOption::TypeInt;
2126 priv->rest.i.min = min;
2127 priv->rest.i.max = max;
2128 }
2129
2130-void
2131-CompOption::Restriction::set (float min, float max, float precision)
2132+void CompOption::Restriction::set (float min, float max, float precision)
2133 {
2134 priv->type = CompOption::TypeFloat;
2135- priv->rest.f.min = min;
2136- priv->rest.f.max = max;
2137+ priv->rest.f.min = min;
2138+ priv->rest.f.max = max;
2139 priv->rest.f.precision = precision;
2140 }
2141
2142-bool
2143-CompOption::Restriction::inRange (int i)
2144+bool CompOption::Restriction::inRange (int i)
2145 {
2146 if (priv->type != CompOption::TypeInt)
2147 return true;
2148@@ -595,8 +184,7 @@
2149 return true;
2150 }
2151
2152-bool
2153-CompOption::Restriction::inRange (float f)
2154+bool CompOption::Restriction::inRange (float f)
2155 {
2156 if (priv->type != CompOption::TypeFloat)
2157 return true;
2158@@ -613,26 +201,25 @@
2159 if (this == &rest)
2160 return *this;
2161
2162- delete priv;
2163- priv = new PrivateRestriction (*rest.priv);
2164+ *priv = *rest.priv;
2165 return *this;
2166 }
2167
2168 CompOption *
2169 CompOption::Class::getOption (const CompString &name)
2170 {
2171- CompOption *o = CompOption::findOption (getOptions (), name);
2172+ CompOption *o = CompOption::findOption(getOptions(), name);
2173 return o;
2174 }
2175
2176 CompOption *
2177 CompOption::findOption (CompOption::Vector &options,
2178- CompString name,
2179- unsigned int *index)
2180+ CompString name,
2181+ unsigned int *index)
2182 {
2183 unsigned int i;
2184
2185- for (i = 0; i < options.size (); i++)
2186+ for (i = 0; i < options.size(); i++)
2187 {
2188 if (options[i].priv->name == name)
2189 {
2190@@ -647,74 +234,70 @@
2191 }
2192
2193 CompOption::CompOption () :
2194- priv (new PrivateOption ())
2195+ priv(new PrivateOption())
2196 {
2197 }
2198
2199 CompOption::CompOption (const CompOption &o) :
2200- priv (new PrivateOption (*o.priv))
2201+ priv(new PrivateOption(*o.priv))
2202 {
2203 }
2204
2205 CompOption::CompOption (CompString name, CompOption::Type type) :
2206- priv (new PrivateOption ())
2207+ priv(new PrivateOption())
2208 {
2209- setName (name, type);
2210+ setName(name, type);
2211 }
2212
2213-static void
2214-finiScreenOptionValue (CompScreen *s,
2215- CompOption::Value &v,
2216- CompOption::Type type)
2217+static void finiScreenOptionValue (CompScreen *s,
2218+ CompOption::Value &v,
2219+ CompOption::Type type)
2220 {
2221- switch (type) {
2222- case CompOption::TypeAction:
2223- case CompOption::TypeKey:
2224- case CompOption::TypeButton:
2225- case CompOption::TypeEdge:
2226- case CompOption::TypeBell:
2227- if (v.action ().state () & CompAction::StateAutoGrab)
2228- s->removeAction (&v.action ());
2229- break;
2230-
2231- case CompOption::TypeList:
2232- foreach (CompOption::Value &val, v.list ())
2233- finiScreenOptionValue (s, val, v.listType ());
2234- break;
2235-
2236- default:
2237- break;
2238+ switch (type)
2239+ {
2240+ case CompOption::TypeAction:
2241+ case CompOption::TypeKey:
2242+ case CompOption::TypeButton:
2243+ case CompOption::TypeEdge:
2244+ case CompOption::TypeBell:
2245+ if (v.action().state() & CompAction::StateAutoGrab)
2246+ s->removeAction(&v.action());
2247+ break;
2248+
2249+ case CompOption::TypeList:
2250+ foreach (CompOption::Value &val, v.list ())
2251+ finiScreenOptionValue(s, val, v.listType());
2252+ break;
2253+
2254+ default:
2255+ break;
2256 }
2257 }
2258
2259 CompOption::~CompOption ()
2260 {
2261- finiOptionValue (priv->value, priv->type);
2262+ // finiOptionValue (priv->value, priv->type);
2263 delete priv;
2264 }
2265
2266-void
2267-CompOption::reset ()
2268+void CompOption::reset ()
2269 {
2270 priv->name = "";
2271 priv->type = TypeUnset;
2272 }
2273
2274-void
2275-CompOption::setName (CompString name, CompOption::Type type)
2276+void CompOption::setName (CompString name, CompOption::Type type)
2277 {
2278 priv->name = name;
2279 priv->type = type;
2280 }
2281
2282-CompString
2283-CompOption::name ()
2284+CompString CompOption::name ()
2285 {
2286 return priv->name;
2287 }
2288
2289-CompOption::Type
2290-CompOption::type ()
2291+CompOption::Type CompOption::type ()
2292 {
2293 return priv->type;
2294 }
2295@@ -731,74 +314,73 @@
2296 return priv->rest;
2297 }
2298
2299-bool
2300-CompOption::set (CompOption::Value &val)
2301+bool CompOption::set (CompOption::Value &val)
2302 {
2303- if (isAction () && priv->type != CompOption::TypeAction)
2304- val.action ().copyState (priv->value.action ());
2305+ if (isAction() && priv->type != CompOption::TypeAction)
2306+ val.action().copyState(priv->value.action());
2307
2308- if (priv->type != val.type () &&
2309- (!isAction () || !checkIsAction (val.type ())))
2310+ if (priv->type != val.type() && (!isAction() || !checkIsAction(val.type())))
2311 {
2312- compLogMessage ("core", CompLogLevelWarn,
2313- "Can't set Value with type %d to "
2314- "option \"%s\" with type %d",
2315- val.type (), priv->name.c_str (), priv->type);
2316+ compLogMessage("core", CompLogLevelWarn,
2317+ "Can't set Value with type %d to "
2318+ "option \"%s\" with type %d", val.type(),
2319+ priv->name.c_str(), priv->type);
2320 return false;
2321 }
2322
2323 if (priv->value == val)
2324 return false;
2325
2326- if (isAction () &&
2327- priv->value.action ().state () & CompAction::StateAutoGrab && screen)
2328+ if (isAction() && priv->value.action().state() & CompAction::StateAutoGrab
2329+ && screen)
2330 {
2331- if (!screen->addAction (&val.action ()))
2332+ if (!screen->addAction(&val.action()))
2333 return false;
2334 else
2335- screen->removeAction (&priv->value.action ());
2336+ screen->removeAction(&priv->value.action());
2337 }
2338
2339 switch (priv->type)
2340 {
2341- case CompOption::TypeInt:
2342- if (!priv->rest.inRange (val.i ()))
2343- return false;
2344- break;
2345-
2346- case CompOption::TypeFloat:
2347- {
2348- float v, p;
2349- int sign = (val.f () < 0 ? -1 : 1);
2350-
2351- if (!priv->rest.inRange (val.f ()))
2352- return false;
2353-
2354- p = 1.0f / priv->rest.fPrecision ();
2355- v = ((int) (val.f () * p + sign * 0.5f)) / p;
2356-
2357- priv->value.set (v);
2358- return true;
2359- }
2360-
2361- case CompOption::TypeAction:
2362- return false;
2363-
2364- case CompOption::TypeKey:
2365- if (val.action ().type () == value().action ().type () &&
2366- !(val.action ().type () & CompAction::BindingTypeKey))
2367- return false;
2368- break;
2369-
2370- case CompOption::TypeButton:
2371- if (val.action ().type () == value().action ().type () &&
2372- !(val.action ().type () & (CompAction::BindingTypeButton |
2373- CompAction::BindingTypeEdgeButton)))
2374- return false;
2375- break;
2376-
2377- default:
2378- break;
2379+ case CompOption::TypeInt:
2380+ if (!priv->rest.inRange(val.i()))
2381+ return false;
2382+ break;
2383+
2384+ case CompOption::TypeFloat:
2385+ {
2386+ float v, p;
2387+ int sign = (val.f() < 0 ? -1 : 1);
2388+
2389+ if (!priv->rest.inRange(val.f()))
2390+ return false;
2391+
2392+ p = 1.0f / priv->rest.fPrecision();
2393+ v = ((int) (val.f() * p + sign * 0.5f)) / p;
2394+
2395+ priv->value.set(v);
2396+ return true;
2397+ }
2398+
2399+ case CompOption::TypeAction:
2400+ return false;
2401+
2402+ case CompOption::TypeKey:
2403+ if (val.action().type() == value().action().type()
2404+ && !(val.action().type() & CompAction::BindingTypeKey))
2405+ return false;
2406+ break;
2407+
2408+ case CompOption::TypeButton:
2409+ if (val.action().type() == value().action().type()
2410+ && !(val.action().type()
2411+ & (CompAction::BindingTypeButton
2412+ | CompAction::BindingTypeEdgeButton)))
2413+ return false;
2414+ break;
2415+
2416+ default:
2417+ break;
2418 }
2419
2420 priv->value = val;
2421@@ -806,10 +388,9 @@
2422 return true;
2423 }
2424
2425-bool
2426-CompOption::isAction ()
2427+bool CompOption::isAction ()
2428 {
2429- return checkIsAction (priv->type);
2430+ return checkIsAction(priv->type);
2431 }
2432
2433 CompOption &
2434@@ -819,90 +400,87 @@
2435 return *this;
2436
2437 delete priv;
2438- priv = new PrivateOption (*option.priv);
2439+ priv = new PrivateOption(*option.priv);
2440 return *this;
2441 }
2442
2443-bool
2444-CompOption::getBoolOptionNamed (const Vector& options,
2445- const CompString& name,
2446- bool defaultValue)
2447-{
2448- foreach (const CompOption &o, options)
2449- if (o.priv->type == CompOption::TypeBool && o.priv->name == name)
2450- return o.priv->value.b ();
2451-
2452- return defaultValue;
2453-}
2454-
2455-int
2456-CompOption::getIntOptionNamed (const Vector& options,
2457- const CompString& name,
2458- int defaultValue)
2459-{
2460- foreach (const CompOption &o, options)
2461- if (o.priv->type == CompOption::TypeInt && o.priv->name == name)
2462- return o.priv->value.i ();
2463-
2464- return defaultValue;
2465-}
2466-
2467-float
2468-CompOption::getFloatOptionNamed (const Vector& options,
2469- const CompString& name,
2470- const float& defaultValue)
2471-{
2472- foreach (const CompOption &o, options)
2473- if (o.priv->type == CompOption::TypeFloat && o.priv->name == name)
2474- return o.priv->value.f ();
2475-
2476- return defaultValue;
2477-}
2478-
2479-CompString
2480-CompOption::getStringOptionNamed (const Vector& options,
2481- const CompString& name,
2482- const CompString& defaultValue)
2483-{
2484- foreach (const CompOption &o, options)
2485- if (o.priv->type == CompOption::TypeString && o.priv->name == name)
2486- return o.priv->value.s ();
2487+bool CompOption::getBoolOptionNamed (const Vector& options,
2488+ const CompString& name,
2489+ bool defaultValue)
2490+{
2491+ foreach (const CompOption &o, options)
2492+ if (o.priv->type == CompOption::TypeBool
2493+ && o.priv->name == name)
2494+ return o.priv->value.b();
2495+
2496+ return defaultValue;
2497+}
2498+
2499+int CompOption::getIntOptionNamed (const Vector& options,
2500+ const CompString& name,
2501+ int defaultValue)
2502+{
2503+ foreach (const CompOption &o, options)
2504+ if (o.priv->type == CompOption::TypeInt && o.priv->name == name)
2505+ return o.priv->value.i();
2506+
2507+ return defaultValue;
2508+}
2509+
2510+float CompOption::getFloatOptionNamed (const Vector& options,
2511+ const CompString& name,
2512+ const float& defaultValue)
2513+{
2514+ foreach (const CompOption &o, options)
2515+ if (o.priv->type == CompOption::TypeFloat
2516+ && o.priv->name == name)
2517+ return o.priv->value.f();
2518+
2519+ return defaultValue;
2520+}
2521+
2522+CompString CompOption::getStringOptionNamed (const Vector& options,
2523+ const CompString& name,
2524+ const CompString& defaultValue)
2525+{
2526+ foreach (const CompOption &o, options)
2527+ if (o.priv->type == CompOption::TypeString
2528+ && o.priv->name == name)
2529+ return o.priv->value.s();
2530
2531 return defaultValue;
2532 }
2533
2534 unsigned short *
2535-CompOption::getColorOptionNamed (const Vector& options,
2536- const CompString& name,
2537- unsigned short *defaultValue)
2538-{
2539- foreach (const CompOption &o, options)
2540- if (o.priv->type == CompOption::TypeColor && o.priv->name == name)
2541- return o.priv->value.c ();
2542-
2543- return defaultValue;
2544-}
2545-
2546-CompMatch
2547-CompOption::getMatchOptionNamed (const Vector& options,
2548+CompOption::getColorOptionNamed (const Vector& options,
2549 const CompString& name,
2550- const CompMatch& defaultValue)
2551-{
2552- foreach (const CompOption &o, options)
2553- if (o.priv->type == CompOption::TypeMatch && o.priv->name == name)
2554- return o.priv->value.match ();
2555-
2556- return defaultValue;
2557-}
2558-
2559-bool
2560-CompOption::stringToColor (CompString color,
2561- unsigned short *rgba)
2562+ unsigned short *defaultValue)
2563+{
2564+ foreach (const CompOption &o, options)
2565+ if (o.priv->type == CompOption::TypeColor
2566+ && o.priv->name == name)
2567+ return o.priv->value.c();
2568+
2569+ return defaultValue;
2570+}
2571+
2572+CompMatch CompOption::getMatchOptionNamed (const Vector& options,
2573+ const CompString& name,
2574+ const CompMatch& defaultValue)
2575+{
2576+ foreach (const CompOption &o, options)
2577+ if (o.priv->type == CompOption::TypeMatch
2578+ && o.priv->name == name)
2579+ return o.priv->value.match();
2580+
2581+ return defaultValue;
2582+}
2583+
2584+bool CompOption::stringToColor (CompString color, unsigned short *rgba)
2585 {
2586 int c[4];
2587
2588- if (sscanf (color.c_str (), "#%2x%2x%2x%2x",
2589- &c[0], &c[1], &c[2], &c[3]) == 4)
2590+ if (sscanf(color.c_str(), "#%2x%2x%2x%2x", &c[0], &c[1], &c[2], &c[3]) == 4)
2591 {
2592 rgba[0] = c[0] << 8 | c[0];
2593 rgba[1] = c[1] << 8 | c[1];
2594@@ -915,68 +493,59 @@
2595 return false;
2596 }
2597
2598-CompString
2599-CompOption::colorToString (unsigned short *rgba)
2600+CompString CompOption::colorToString (unsigned short *rgba)
2601 {
2602- return compPrintf ("#%.2x%.2x%.2x%.2x", rgba[0] / 256, rgba[1] / 256,
2603- rgba[2] / 256, rgba[3] / 256);
2604+ return compPrintf("#%.2x%.2x%.2x%.2x", rgba[0] / 256, rgba[1] / 256,
2605+ rgba[2] / 256, rgba[3] / 256);
2606 }
2607
2608-CompString
2609-CompOption::typeToString (CompOption::Type type)
2610+CompString CompOption::typeToString (CompOption::Type type)
2611 {
2612- switch (type) {
2613- case CompOption::TypeBool:
2614- return "bool";
2615- case CompOption::TypeInt:
2616- return "int";
2617- case CompOption::TypeFloat:
2618- return "float";
2619- case CompOption::TypeString:
2620- return "string";
2621- case CompOption::TypeColor:
2622- return "color";
2623- case CompOption::TypeAction:
2624- return "action";
2625- case CompOption::TypeKey:
2626- return "key";
2627- case CompOption::TypeButton:
2628- return "button";
2629- case CompOption::TypeEdge:
2630- return "edge";
2631- case CompOption::TypeBell:
2632- return "bell";
2633- case CompOption::TypeMatch:
2634- return "match";
2635- case CompOption::TypeList:
2636- return "list";
2637- default:
2638- break;
2639+ switch (type)
2640+ {
2641+ case CompOption::TypeBool:
2642+ return "bool";
2643+ case CompOption::TypeInt:
2644+ return "int";
2645+ case CompOption::TypeFloat:
2646+ return "float";
2647+ case CompOption::TypeString:
2648+ return "string";
2649+ case CompOption::TypeColor:
2650+ return "color";
2651+ case CompOption::TypeAction:
2652+ return "action";
2653+ case CompOption::TypeKey:
2654+ return "key";
2655+ case CompOption::TypeButton:
2656+ return "button";
2657+ case CompOption::TypeEdge:
2658+ return "edge";
2659+ case CompOption::TypeBell:
2660+ return "bell";
2661+ case CompOption::TypeMatch:
2662+ return "match";
2663+ case CompOption::TypeList:
2664+ return "list";
2665+ default:
2666+ break;
2667 }
2668
2669 return "unknown";
2670 }
2671
2672-bool
2673-CompOption::setOption (CompOption &o,
2674- CompOption::Value &value)
2675+bool CompOption::setOption (CompOption &o, CompOption::Value &value)
2676 {
2677- return o.set (value);
2678+ return o.set(value);
2679 }
2680
2681 PrivateOption::PrivateOption () :
2682- name (""),
2683- type (CompOption::TypeUnset),
2684- value (),
2685- rest ()
2686+ name(""), type(CompOption::TypeUnset), value(), rest()
2687 {
2688 }
2689
2690 PrivateOption::PrivateOption (const PrivateOption &p) :
2691- name (p.name),
2692- type (p.type),
2693- value (p.value),
2694- rest (p.rest)
2695+ name(p.name), type(p.type), value(p.value), rest(p.rest)
2696 {
2697 }
2698

Subscribers

People subscribed via source and target branches