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