2009-11-13 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / value.h.in
blob0eae5c296d87c6766a1a39153acb5e760021325b
1 /*
2 * value.h: Generated code for the type system.
4 * Contact:
5 * Moonlight List (moonlight-list@lists.ximian.com)
7 * Copyright 2007 Novell, Inc. (http://www.novell.com)
9 * See the LICENSE file included with the distribution for details.
13 #ifndef MOON_VALUE_H
14 #define MOON_VALUE_H
16 #include <glib.h>
18 #include "type.h"
20 /*
21 * ugly file containing the catchall value type we use.
24 struct FontFamily;
25 struct FontSource;
26 struct FontWeight;
27 struct FontStyle;
28 struct FontStretch;
29 struct PropertyPath;
30 struct Color;
31 struct Duration;
32 struct KeyTime;
33 struct Point;
34 struct Rect;
35 struct Size;
36 struct Uri;
37 struct RepeatBehavior;
38 struct GridLength;
39 struct Thickness;
40 struct CornerRadius;
41 struct ManagedTypeInfo;
43 struct Value;
45 class Type;
46 class DependencyProperty;
47 class Surface;
48 class AnimationStorage;
50 /*DO_FWD_DECLS*/
52 #if SANITY || DEBUG
53 #define checked_get_exact(kind, errval, mem) g_return_val_if_fail (k == (kind), errval); return mem;
54 #define checked_get_subclass(kind, castas) \
55 if (u.dependency_object == NULL || k == (kind)) \
56 return (castas*)u.dependency_object; \
57 g_return_val_if_fail (Types::IsSubclassOrSuperclassOf (types, k, kind), NULL); \
58 return (castas*)u.dependency_object;
59 #else
60 #define checked_get_exact(kind, errval, mem) return mem;
61 #define checked_get_subclass(kind, castas) return (castas*)u.dependency_object;
62 #endif
64 struct Value {
65 public:
66 void Init ();
68 Value ();
69 Value (const Value& v);
70 explicit Value (Type::Kind k);
71 explicit Value (bool z);
72 explicit Value (double d);
73 explicit Value (gint32 i);
74 explicit Value (guint32 i);
75 Value (gunichar c, Type::Kind as); // for use with char values.
76 Value (gint64 i, Type::Kind as); // Use for TimeSpan and int64 values.
77 Value (Color c);
78 Value (EventObject *obj);
79 Value (FontFamily family);
80 Value (FontSource source);
81 Value (FontWeight weight);
82 Value (FontStyle style);
83 Value (FontStretch stretch);
84 Value (PropertyPath propertypath);
85 Value (Point pt);
86 Value (Rect rect);
87 Value (Size size);
88 Value (Uri uri);
89 Value (RepeatBehavior repeat);
90 Value (Duration duration);
91 Value (KeyTime keytime);
92 Value (GridLength grid_length);
93 Value (Thickness thickness);
94 Value (CornerRadius radius);
95 Value (ManagedTypeInfo type_info);
96 Value (const char *s, bool take = false);
97 Value (Point *points, int count);
98 Value (double *values, int count);
99 Value (Type::Kind, void *npobj);
101 ~Value ();
103 // Use these to create Values with dependency objects with
104 // a reference count of 1 (giving the ownership of the object
105 // to Value).
106 // Useful in cases like this:
107 // SetValue (SomeProperty, new DependencyObject ())
108 // in which case we have to unref the newly created object.
109 static Value* CreateUnrefPtr (EventObject* dob);
110 static Value CreateUnref (EventObject* dob);
112 // essentially the same as the copy constructor, except it
113 // does a deep copy of DependencyObjects.
114 static Value* Clone (Value *v, Types *types = NULL);
116 bool GetIsNull ();
117 void SetIsNull (bool isNull);
119 bool operator!= (const Value &v) const;
120 bool operator== (const Value &v) const;
122 Value& operator= (const Value& other);
124 bool Is (Deployment *deployment, Type::Kind type) { return Type::IsSubclassOf (deployment, k, type); }
126 bool AsBool () { checked_get_exact (Type::BOOL, false, (bool)u.i32); }
127 gunichar AsChar () { checked_get_exact (Type::CHAR, 0, u.c); }
128 double AsDouble () { checked_get_exact (Type::DOUBLE, 0.0, u.d); }
129 float AsFloat () { checked_get_exact (Type::FLOAT, 0.0, u.f); }
130 guint64 AsUInt64 () { checked_get_exact (Type::UINT64, 0, u.ui64); }
131 gint64 AsInt64 () { checked_get_exact (Type::INT64, 0, u.i64); }
132 TimeSpan AsTimeSpan () { checked_get_exact (Type::TIMESPAN, 0, (TimeSpan)u.i64); }
133 guint32 AsUInt32 () { checked_get_exact (Type::UINT32, 0, u.ui32); }
134 gint32 AsInt32 () { checked_get_exact (Type::INT32, 0, u.i32); }
135 Color* AsColor () { checked_get_exact (Type::COLOR, NULL, u.color); }
136 Point* AsPoint () { checked_get_exact (Type::POINT, NULL, u.point); }
137 Uri* AsUri () { checked_get_exact (Type::URI, NULL, u.uri); }
138 Rect* AsRect () { checked_get_exact (Type::RECT, NULL, u.rect); }
139 Size* AsSize () { checked_get_exact (Type::SIZE, NULL, u.size); }
140 FontFamily* AsFontFamily () { checked_get_exact (Type::FONTFAMILY, NULL, u.fontfamily); }
141 FontWeight* AsFontWeight () { checked_get_exact (Type::FONTWEIGHT, NULL, u.fontweight); }
142 FontStyle* AsFontStyle () { checked_get_exact (Type::FONTSTYLE, NULL, u.fontstyle); }
143 FontStretch* AsFontStretch() { checked_get_exact (Type::FONTSTRETCH, NULL, u.fontstretch); }
144 FontSource* AsFontSource () { checked_get_exact (Type::FONTSOURCE, NULL, u.fontsource); }
145 PropertyPath* AsPropertyPath () { checked_get_exact (Type::PROPERTYPATH, NULL, u.propertypath); }
146 char* AsString () { checked_get_exact (Type::STRING, NULL, u.s); }
147 DependencyProperty* AsDependencyProperty () { checked_get_exact (Type::DEPENDENCYPROPERTY, NULL, u.dp); }
149 void * AsManagedObject () { checked_get_exact (Type::MANAGED, NULL, u.managed_object); }
150 void * AsNPObj () { checked_get_exact (Type::NPOBJ, NULL, u.npobj); }
152 RepeatBehavior* AsRepeatBehavior () { checked_get_exact (Type::REPEATBEHAVIOR, NULL, u.repeat); }
153 Duration* AsDuration () { checked_get_exact (Type::DURATION, NULL, u.duration); }
154 KeyTime* AsKeyTime () { checked_get_exact (Type::KEYTIME, NULL, u.keytime); }
155 GridLength* AsGridLength () { checked_get_exact (Type::GRIDLENGTH, NULL, u.grid_length); }
156 Thickness* AsThickness () { checked_get_exact (Type::THICKNESS, NULL, u.thickness); }
157 CornerRadius* AsCornerRadius () { checked_get_exact (Type::CORNERRADIUS, NULL, u.corner); }
158 ManagedTypeInfo* AsManagedTypeInfo () { checked_get_exact (Type::MANAGEDTYPEINFO, NULL, u.type_info); }
159 /* nullable primitives (all but bool) */
160 double* AsNullableDouble () { checked_get_exact (Type::DOUBLE, NULL, &u.d); }
161 guint64* AsNullableUint64 () { checked_get_exact (Type::UINT64, NULL, &u.ui64); }
162 gint64* AsNullableInt64 () { checked_get_exact (Type::INT64, NULL, &u.i64); }
163 gint32* AsNullableInt32 () { checked_get_exact (Type::INT32, NULL, &u.i32); }
165 /*DO_AS*/
167 char *ToString ();
169 Type::Kind GetKind ();
171 void FreeValue ();
173 private:
174 Type::Kind k;
176 gint32 padding;
178 union {
179 double d;
180 float f;
181 guint64 ui64;
182 gint64 i64;
183 guint32 ui32;
184 gint32 i32;
185 gunichar c;
186 char *s;
187 EventObject *dependency_object;
188 Color *color;
189 DependencyProperty *dp;
190 Point *point;
191 Uri *uri;
192 Rect *rect;
193 Size *size;
194 FontFamily *fontfamily;
195 FontSource *fontsource;
196 FontWeight *fontweight;
197 FontStretch *fontstretch;
198 FontStyle *fontstyle;
199 PropertyPath *propertypath;
200 RepeatBehavior *repeat;
201 Duration *duration;
202 KeyTime *keytime;
203 GridLength *grid_length;
204 Thickness *thickness;
205 CornerRadius *corner;
206 ManagedTypeInfo *type_info;
207 void *managed_object;
208 void *npobj;
209 } u;
211 // You don't want to be using this ctor. it's here to help
212 // c++ recognize bad unspecified pointer args to Value ctors
213 // (it normally converts them to bool, which we handle, so you
214 // never see the error of your ways). So do the world a
215 // favor, and don't expose this ctor. :)
216 Value (void *v) { }
217 // You don't want to be using this ctor either.
218 // Use the Value (gint64, Type::Kind) ctor
219 // (Both for TimeSpan and int64_t)
220 // This one is bad because it get used by either int64_t
221 // and TimeSpan, and the constructor doesn't know which
222 // of the two types it is.
223 explicit Value (gint64 i) {};
225 void Copy (const Value& other);
226 char *GetName ();
229 G_BEGIN_DECLS
230 /* @GeneratePInvoke */
231 void value_free_value (Value *value);
232 /* @GeneratePInvoke */
233 void value_free_value2 (/* @MarshalAs=IntPtr */ Value *value);
234 G_END_DECLS
237 #endif /* MOON_VALUE_H */