File indexing completed on 2024-05-19 04:38:47

0001 {% load kdev_filters %}
0002 {% include "license_header_cpp.txt" %}
0003 
0004 
0005 #include "{{ output_file_header }}"
0006 
0007 
0008 {% with namespaces|join:"_"|default:"___"|add:"_"|cut:"____"|upper as uc_prefix %}
0009 {% with namespaces|join:"_"|default:"___"|add:"_"|cut:"____"|lower as lc_prefix %}
0010 {% with namespaces|join:"" as prefix %}
0011 {% with prefix|add:name as full_name %}
0012 
0013 
0014 #define {{ uc_prefix }}{{ name|upper }}_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), {{ uc_prefix }}TYPE_{{ name|upper }}, {{ full_name }}Private))
0015 
0016 
0017 struct _{{ full_name }}Private
0018 {
0019     /* private members */
0020 };
0021 
0022 
0023 
0024 
0025 /* 
0026  * forward definitions
0027  */
0028 G_DEFINE_TYPE ({{ full_name }}, {{ lc_prefix }}{{ name|lower }}, G_TYPE_OBJECT);
0029 
0030 
0031 /*
0032 /* forward declarations of default virtual methods 
0033  */
0034 {% for f in functions %}
0035 {% if f.isVirtual %}
0036 {% with f.arguments as arguments %}
0037 {{ f.returnType|default:"void" }} {{ lc_prefix }}{{ name|lower }}_real_{{ f.name }}({{ full_name }}* self{% if arguments %}, {% include "arguments_types_names.txt" %}{% endif %});
0038 {% endwith %}
0039 {% endif %}
0040 {% endfor %}
0041 
0042 
0043 enum {
0044     PROP_0,
0045     {% for m in members %}
0046     PROP_{{ m.name|upper }},
0047     {% endfor %}
0048     N_PROPERTIES
0049 };
0050 
0051 
0052 static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
0053 
0054 static void
0055 {{ lc_prefix }}{{ name|lower }}_set_property (GObject      *object,
0056                         guint         property_id,
0057                         const GValue *value,
0058                         GParamSpec   *pspec)
0059 {
0060     {{ full_name }} *self = {{ uc_prefix}}{{ name|upper }} (object);
0061     
0062     switch (property_id)
0063     {
0064         {% for m in members %}
0065         
0066         case PROP_{{ m.name|upper }}:
0067             /* WARNING: Strings and custom types require special handling here */
0068             self->priv->{{ m.name }} = g_value_get_{{ m.type }} (value);
0069             break;
0070             
0071             {% endfor %}
0072             
0073         default:
0074             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
0075             break;
0076     }
0077 }
0078 
0079 
0080 static void
0081 {{ lc_prefix }}{{ name|lower }}_get_property (GObject      *object,
0082                         guint         property_id,
0083                         GValue       *value,
0084                         GParamSpec   *pspec)
0085 {
0086     {{ full_name }} *self = {{ uc_prefix}}{{ name|upper }} (object);
0087 
0088     switch (property_id)
0089     {
0090         {% for m in members %}
0091 
0092         case PROP_{{ m.name|upper }}:
0093             /* WARNING: Strings and custom types require special handling here */
0094             g_value_set_{{ m.type }} (value, self->priv->{{ m.name }});
0095             break;
0096 
0097         {% endfor %}
0098 
0099         default:
0100             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
0101             break;
0102     }
0103 }
0104 
0105 
0106 static void
0107 {{ lc_prefix }}{{ name|lower }}_class_init ({{ full_name }}Class *klass)
0108 {
0109   g_type_class_add_private (klass, sizeof ({{ full_name }}Private));
0110 
0111 
0112   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
0113   gobject_class->set_property = {{ lc_prefix }}{{ name|lower}}_set_property;
0114   gobject_class->get_property = {{ lc_prefix }}{{ name|lower}}_get_property;
0115 
0116 
0117   {% for m in members %}
0118   /* WARNING: Most property types require special handling here, check before compiling */
0119   obj_properties[PROP_{{ m.name|upper }}] =
0120   g_param_spec_{{ m.type }} ("{{ m.name }}",
0121                        "{{ m.name|capfirst }} property",
0122                        "Set/Get {{ m.name }}",
0123                        {{ m.value|default:0 }} /* default value */,
0124                        G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
0125   {% endfor %}
0126 
0127 
0128   g_object_class_install_properties (gobject_class,
0129                                      N_PROPERTIES,
0130                                      obj_properties);
0131 }
0132 
0133 
0134 static void
0135 {{ lc_prefix }}{{ name|lower }}_dispose (GObject *gobject)
0136 {
0137   {{ full_name }} *self = {{ uc_prefix }}{{ name|upper }} (gobject);
0138 
0139 
0140   /* 
0141    * In dispose, you are supposed to free all types referenced from this
0142    * object which might themselves hold a reference to self. Generally,
0143    * the most simple solution is to unref all members on which you own a 
0144    * reference.
0145    */
0146 
0147 
0148   /* Chain up to the parent class */
0149   G_OBJECT_CLASS ({{ lc_prefix }}{{ name|lower }}_parent_class)->dispose (gobject);
0150 }
0151 
0152 
0153 static void
0154 {{ lc_prefix }}{{ name|lower }}_finalize (GObject *gobject)
0155 {
0156   {{ full_name }} *self = {{ uc_prefix }}{{ name|upper }} (gobject);
0157 
0158 
0159   /* Chain up to the parent class */
0160   G_OBJECT_CLASS ({{ lc_prefix }}{{ name|lower }}_parent_class)->finalize (gobject);
0161 }
0162 
0163 
0164 static void
0165 {{ lc_prefix }}{{ name|lower }}_init ({{ full_name }} *self)
0166 {
0167   self->priv = {{ uc_prefix }}{{ name|upper }}_GET_PRIVATE (self);
0168 
0169 
0170   /* initialize all public and private members to reasonable default values. */
0171 
0172 
0173   /*
0174    * Default implementations for virtual methods 
0175    * For pure-virtual functions, set these to NULL
0176    */
0177   {% for f in functions %}
0178   {% if f.isVirtual %}
0179     klass->{{ f.name }} = {{ lc_prefix }}{{ name|lower }}_real_{{ f.name }};
0180   {% endif %}
0181   {% endfor %}
0182 }
0183 
0184 {% for f in functions %}
0185 {% with f.arguments as arguments %}
0186 {{ f.returnType|default:"void" }} {{ lc_prefix }}{{ name|lower }}_{{ f.name }}({{ full_name }}* self{% if arguments %}, {% include "arguments_types_names.txt" %}{% endif %})
0187 {
0188     g_return_if_fail ({{ uc_prefix }}IS_{{ name|upper }} (self));
0189 
0190     {% if f.isVirtual %}
0191 
0192     {{ uc_prefix }}{{ name|upper }}_GET_CLASS (self)->{{ f.name }} (self{% if arguments %}, {% include "arguments_names.txt" %}{% endif %});
0193     {% endif %}
0194 }
0195 
0196 {% if f.isVirtual %}
0197 {{ f.returnType|default:"void" }} {{ lc_prefix }}{{ name|lower }}_real_{{ f.name }}({{ full_name }}* self{% if arguments %}, {% include "arguments_types_names.txt" %}{% endif %})
0198 {
0199     /* Default implementation for the virtual method {{ f.name }} */
0200 }
0201 {% endif %}
0202 {% endwith %}
0203 {% endfor %}
0204 
0205 {% endwith %}
0206 {% endwith %}
0207 {% endwith %}
0208 {% endwith %}