add the 2.1-bootstrap dir to MONO_PATH when running smcs
[moon.git] / src / value.h.in
blob340e29e70d43a99a133c725ff931a587ec2d20f9
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);
111 void Set (double value);
113 bool operator!= (const Value &v) const;
114 bool operator== (const Value &v) const;
116 Value& operator= (const Value& other);
118 bool Is (Type::Kind type) { return Type::IsSubclassOf (k, type); }
120 bool AsBool () { checked_get_exact (Type::BOOL, false, (bool)u.i32); }
121 gunichar AsChar () { checked_get_exact (Type::CHAR, 0, u.c); }
122 double AsDouble () { checked_get_exact (Type::DOUBLE, 0.0, u.d); }
123 float AsFloat () { checked_get_exact (Type::FLOAT, 0.0, u.f); }
124 guint64 AsUInt64 () { checked_get_exact (Type::UINT64, 0, u.ui64); }
125 gint64 AsInt64 () { checked_get_exact (Type::INT64, 0, u.i64); }
126 TimeSpan AsTimeSpan () { checked_get_exact (Type::TIMESPAN, 0, (TimeSpan)u.i64); }
127 guint32 AsUInt32 () { checked_get_exact (Type::UINT32, 0, u.ui32); }
128 gint32 AsInt32 () { checked_get_exact (Type::INT32, 0, u.i32); }
129 Color* AsColor () { checked_get_exact (Type::COLOR, NULL, u.color); }
130 Point* AsPoint () { checked_get_exact (Type::POINT, NULL, u.point); }
131 Uri* AsUri () { checked_get_exact (Type::URI, NULL, u.uri); }
132 Rect* AsRect () { checked_get_exact (Type::RECT, NULL, u.rect); }
133 Size* AsSize () { checked_get_exact (Type::SIZE, NULL, u.size); }
134 FontFamily* AsFontFamily () { checked_get_exact (Type::FONTFAMILY, NULL, u.fontfamily); }
135 FontWeight* AsFontWeight () { checked_get_exact (Type::FONTWEIGHT, NULL, u.fontweight); }
136 FontStyle* AsFontStyle () { checked_get_exact (Type::FONTSTYLE, NULL, u.fontstyle); }
137 FontStretch* AsFontStretch() { checked_get_exact (Type::FONTSTRETCH, NULL, u.fontstretch); }
138 FontSource* AsFontSource () { checked_get_exact (Type::FONTSOURCE, NULL, u.fontsource); }
139 PropertyPath* AsPropertyPath () { checked_get_exact (Type::PROPERTYPATH, NULL, u.propertypath); }
140 char* AsString () { checked_get_exact (Type::STRING, NULL, u.s); }
141 DependencyProperty* AsDependencyProperty () { checked_get_exact (Type::DEPENDENCYPROPERTY, NULL, u.dp); }
143 void * AsManagedObject () { checked_get_exact (Type::MANAGED, NULL, u.managed_object); }
144 void * AsNPObj () { checked_get_exact (Type::NPOBJ, NULL, u.npobj); }
146 RepeatBehavior* AsRepeatBehavior () { checked_get_exact (Type::REPEATBEHAVIOR, NULL, u.repeat); }
147 Duration* AsDuration () { checked_get_exact (Type::DURATION, NULL, u.duration); }
148 KeyTime* AsKeyTime () { checked_get_exact (Type::KEYTIME, NULL, u.keytime); }
149 GridLength* AsGridLength () { checked_get_exact (Type::GRIDLENGTH, NULL, u.grid_length); }
150 Thickness* AsThickness () { checked_get_exact (Type::THICKNESS, NULL, u.thickness); }
151 CornerRadius* AsCornerRadius () { checked_get_exact (Type::CORNERRADIUS, NULL, u.corner); }
152 ManagedTypeInfo* AsManagedTypeInfo () { checked_get_exact (Type::MANAGEDTYPEINFO, NULL, u.type_info); }
153 /* nullable primitives (all but bool) */
154 double* AsNullableDouble () { checked_get_exact (Type::DOUBLE, NULL, &u.d); }
155 guint64* AsNullableUint64 () { checked_get_exact (Type::UINT64, NULL, &u.ui64); }
156 gint64* AsNullableInt64 () { checked_get_exact (Type::INT64, NULL, &u.i64); }
157 gint32* AsNullableInt32 () { checked_get_exact (Type::INT32, NULL, &u.i32); }
159 /*DO_AS*/
161 char *ToString ();
163 Type::Kind GetKind ();
165 void FreeValue ();
167 private:
168 Type::Kind k;
170 gint32 padding;
172 union {
173 double d;
174 float f;
175 guint64 ui64;
176 gint64 i64;
177 guint32 ui32;
178 gint32 i32;
179 gunichar c;
180 char *s;
181 EventObject *dependency_object;
182 Color *color;
183 DependencyProperty *dp;
184 Point *point;
185 Uri *uri;
186 Rect *rect;
187 Size *size;
188 FontFamily *fontfamily;
189 FontSource *fontsource;
190 FontWeight *fontweight;
191 FontStretch *fontstretch;
192 FontStyle *fontstyle;
193 PropertyPath *propertypath;
194 RepeatBehavior *repeat;
195 Duration *duration;
196 KeyTime *keytime;
197 GridLength *grid_length;
198 Thickness *thickness;
199 CornerRadius *corner;
200 ManagedTypeInfo *type_info;
201 void *managed_object;
202 void *npobj;
203 } u;
205 // You don't want to be using this ctor. it's here to help
206 // c++ recognize bad unspecified pointer args to Value ctors
207 // (it normally converts them to bool, which we handle, so you
208 // never see the error of your ways). So do the world a
209 // favor, and don't expose this ctor. :)
210 Value (void *v) { }
211 // You don't want to be using this ctor either.
212 // Use the Value (gint64, Type::Kind) ctor
213 // (Both for TimeSpan and int64_t)
214 // This one is bad because it get used by either int64_t
215 // and TimeSpan, and the constructor doesn't know which
216 // of the two types it is.
217 explicit Value (gint64 i) {};
219 void Copy (const Value& other);
220 char *GetName ();
223 G_BEGIN_DECLS
224 /* @GeneratePInvoke */
225 void value_free_value (Value *value);
226 /* @GeneratePInvoke */
227 void value_free_value2 (/* @MarshalAs=IntPtr */ Value *value);
228 G_END_DECLS
231 #endif /* MOON_VALUE_H */