Initial packaging for Tizen
[profile/ivi/gobject-introspection.git] / girepository / gipropertyinfo.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2  * GObject introspection: Property implementation
3  *
4  * Copyright (C) 2005 Matthias Clasen
5  * Copyright (C) 2008,2009 Red Hat, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <glib.h>
24
25 #include <girepository.h>
26 #include "girepository-private.h"
27 #include "gitypelib-internal.h"
28
29 /**
30  * SECTION:gipropertyinfo
31  * @Short_description: Struct representing a property
32  * @Title: GIPropertyInfo
33  *
34  * GIPropertyInfo represents a property. A property belongs to
35  * either a #GIObjectInfo or a #GIInterfaceInfo.
36  *
37  * <refsect1 id="gi-gipropertyinfo.struct-hierarchy" role="struct_hierarchy">
38  * <title role="struct_hierarchy.title">Struct hierarchy</title>
39  * <synopsis>
40  *   <link linkend="gi-GIBaseInfo">GIBaseInfo</link>
41  *    +----GIPropertyInfo
42  * </synopsis>
43  * </refsect1>
44  */
45
46 /**
47  * g_property_info_get_flags:
48  * @info: a #GIPropertyInfo
49  *
50  * Obtain the flags for this property info. See #GParamFags for
51  * more information about possible flag values.
52  *
53  * Returns: the flags
54  */
55 GParamFlags
56 g_property_info_get_flags (GIPropertyInfo *info)
57 {
58   GParamFlags flags;
59   GIRealInfo *rinfo = (GIRealInfo *)info;
60   PropertyBlob *blob;
61
62   g_return_val_if_fail (info != NULL, 0);
63   g_return_val_if_fail (GI_IS_PROPERTY_INFO (info), 0);
64
65   blob = (PropertyBlob *)&rinfo->typelib->data[rinfo->offset];
66
67   flags = 0;
68
69   if (blob->readable)
70     flags = flags | G_PARAM_READABLE;
71
72   if (blob->writable)
73     flags = flags | G_PARAM_WRITABLE;
74
75   if (blob->construct)
76     flags = flags | G_PARAM_CONSTRUCT;
77
78   if (blob->construct_only)
79     flags = flags | G_PARAM_CONSTRUCT_ONLY;
80
81   return flags;
82 }
83
84 /**
85  * g_property_info_get_type:
86  * @info: a #GIPropertyInfo
87  *
88  * Obtain the type information for the property @info.
89  *
90  * Returns: (transfer full): the #GITypeInfo, free it with
91  * g_base_info_unref() when done.
92  */
93 GITypeInfo *
94 g_property_info_get_type (GIPropertyInfo *info)
95 {
96   GIRealInfo *rinfo = (GIRealInfo *)info;
97
98   g_return_val_if_fail (info != NULL, NULL);
99   g_return_val_if_fail (GI_IS_PROPERTY_INFO (info), NULL);
100
101   return _g_type_info_new ((GIBaseInfo*)info,
102                            rinfo->typelib,
103                            rinfo->offset + G_STRUCT_OFFSET (PropertyBlob, type));
104 }
105
106 /**
107  * g_property_info_get_ownership_transfer:
108  * @info: a #GIPropertyInfo
109  *
110  * Obtain the ownership transfer for this property. See #GITransfer for more
111  * information about transfer values.
112  *
113  * Returns: the transfer
114  */
115 GITransfer
116 g_property_info_get_ownership_transfer (GIPropertyInfo *info)
117 {
118   GIRealInfo *rinfo = (GIRealInfo *)info;
119   PropertyBlob *blob;
120
121   g_return_val_if_fail (info != NULL, -1);
122   g_return_val_if_fail (GI_IS_PROPERTY_INFO (info), -1);
123
124   blob = (PropertyBlob *)&rinfo->typelib->data[rinfo->offset];
125
126   if (blob->transfer_ownership)
127     return GI_TRANSFER_EVERYTHING;
128   else if (blob->transfer_container_ownership)
129     return GI_TRANSFER_CONTAINER;
130   else
131     return GI_TRANSFER_NOTHING;
132 }