00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _COMPOPTION_H
00029 #define _COMPOPTION_H
00030
00031 #include <compiz.h>
00032
00033 #include <vector>
00034
00035 class PrivateOption;
00036 class PrivateValue;
00037 class PrivateRestriction;
00038 class CompAction;
00039 class CompMatch;
00040 class CompScreen;
00041
00046 class CompOption {
00050 public:
00051 typedef enum {
00052 TypeBool,
00053 TypeInt,
00054 TypeFloat,
00055 TypeString,
00056 TypeColor,
00057 TypeAction,
00058 TypeKey,
00059 TypeButton,
00060 TypeEdge,
00061 TypeBell,
00062 TypeMatch,
00063 TypeList,
00064
00065 TypeUnset
00066 } Type;
00067
00071 class Value {
00072 public:
00073 typedef std::vector<Value> Vector;
00074
00075 public:
00076 Value ();
00077 Value (const Value &);
00078 Value (const bool b);
00079 Value (const int i);
00080 Value (const float f);
00081 Value (const unsigned short *color);
00082 Value (const CompString& s);
00083 Value (const char *s);
00084 Value (const CompMatch& m);
00085 Value (const CompAction& a);
00086 Value (Type type, const Vector& l);
00087 ~Value ();
00088
00089 Type type () const;
00090
00091 void set (const bool b);
00092 void set (const int i);
00093 void set (const float f);
00094 void set (const unsigned short *color);
00095 void set (const CompString& s);
00096 void set (const char *s);
00097 void set (const CompMatch& m);
00098 void set (const CompAction& a);
00099 void set (Type type, const Vector& l);
00100
00101 bool b ();
00102 int i ();
00103 float f ();
00104 unsigned short* c ();
00105 CompString s ();
00106 CompMatch & match ();
00107 CompAction & action ();
00108 Type listType ();
00109 Vector & list ();
00110
00111 bool operator== (const Value& val);
00112 bool operator!= (const Value& val);
00113 Value & operator= (const Value &val);
00114
00115 operator bool ();
00116 operator int ();
00117 operator float ();
00118 operator unsigned short * ();
00119 operator CompString ();
00120 operator CompMatch & ();
00121 operator CompAction & ();
00122 operator CompAction * ();
00123 operator Type ();
00124 operator Vector & ();
00125
00126 private:
00127 PrivateValue *priv;
00128 };
00129
00133 class Restriction {
00134 public:
00135 Restriction ();
00136 Restriction (const Restriction &);
00137 ~Restriction ();
00138
00139 int iMin ();
00140 int iMax ();
00141 float fMin ();
00142 float fMax ();
00143 float fPrecision ();
00144
00145 void set (int, int);
00146 void set (float, float, float);
00147
00148 bool inRange (int);
00149 bool inRange (float);
00150
00151 Restriction & operator= (const Restriction &rest);
00152 private:
00153 PrivateRestriction *priv;
00154 };
00155
00156 typedef std::vector<CompOption> Vector;
00157
00161 class Class {
00162 public:
00163 virtual Vector & getOptions () = 0;
00164
00165 virtual CompOption * getOption (const CompString &name);
00166
00167 virtual bool setOption (const CompString &name,
00168 Value &value) = 0;
00169 };
00170
00171 public:
00172 CompOption ();
00173 CompOption (const CompOption &);
00174 CompOption (CompString name, Type type);
00175 ~CompOption ();
00176
00177 void setName (CompString name, Type type);
00178
00179 CompString name ();
00180
00181 Type type ();
00182 Value & value ();
00183 Restriction & rest ();
00184
00185 bool set (Value &val);
00186 bool isAction ();
00187
00188 CompOption & operator= (const CompOption &option);
00189
00190 public:
00191 static CompOption * findOption (Vector &options, CompString name,
00192 unsigned int *index = NULL);
00193
00194 static bool
00195 getBoolOptionNamed (const Vector& options,
00196 const CompString& name,
00197 bool defaultValue = false);
00198
00199 static int
00200 getIntOptionNamed (const Vector& options,
00201 const CompString& name,
00202 int defaultValue = 0);
00203
00204 static float
00205 getFloatOptionNamed (const Vector& options,
00206 const CompString& name,
00207 const float& defaultValue = 0.0);
00208
00209 static CompString
00210 getStringOptionNamed (const Vector& options,
00211 const CompString& name,
00212 const CompString& defaultValue = "");
00213
00214 static unsigned short *
00215 getColorOptionNamed (const Vector& options,
00216 const CompString& name,
00217 unsigned short *defaultValue);
00218
00219 static CompMatch
00220 getMatchOptionNamed (const Vector& options,
00221 const CompString& name,
00222 const CompMatch& defaultValue);
00223
00224 static CompString typeToString (Type type);
00225
00226 static bool stringToColor (CompString color,
00227 unsigned short *rgba);
00228
00229 static CompString colorToString (unsigned short *rgba);
00230
00231
00232 static bool setOption (CompOption &o, Value &value);
00233
00234 private:
00235 PrivateOption *priv;
00236 };
00237
00238 extern CompOption::Vector noOptions;
00239
00240 #endif