File: group__m17nObject.html

package info (click to toggle)
m17n-docs 1.2.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 14,708 kB
  • ctags: 1,682
  • sloc: sh: 4,456; makefile: 294
file content (222 lines) | stat: -rw-r--r-- 11,229 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
Copyright (C) 2001 Information-technology Promotion Agency (IPA)
Copyright (C) 2001-2004
  National Institute of Advanced Industrial Science and Technology (AIST)
This file is part of the m17n library documentation.
See the end for copying conditions.
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset="UTF-8">
<title>The m17n Library</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head>

<body bgcolor="#ffffff">

<a name="top-of-page"></a>

<hr><center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; 
<a class="qindex" href="modules.html">Modules</a> &nbsp; 
<!-- <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; -->
<a class="qindex" href="annotated.html">Data Structures</a> &nbsp; 
<!-- <a class="qindex" href="files.html">File List</a> &nbsp;  -->
<!-- <a class="qindex" href="functions.html">Data Fields</a> &nbsp; -->
<a class="qindex" href="globals.html">Globals</a> &nbsp; 
<a class="qindex" href="pages.html">Appendix</a> &nbsp; 
</center>

<hr>
<!-- Generated by Doxygen 1.3.9.1 -->
<h1>Managed Object<br>
<small>
[<a class="el" href="group__m17nCore.html">CORE API</a>]</small>
</h1>Managed objects are objects managed by the reference count.  
<a href="#_details">More...</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Data Structures</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">struct &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="structM17NObjectHead.html">M17NObjectHead</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The first member of a managed object.  <a href="structM17NObjectHead.html#_details">More...</a><br></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__m17nObject.html#ga0">m17n_object</a> (int size, void(*freer)(void *))</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Allocate a managed object.  <a href="#ga0"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__m17nObject.html#ga1">m17n_object_ref</a> (void *object)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Increment the reference count of a managed object.  <a href="#ga1"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__m17nObject.html#ga2">m17n_object_unref</a> (void *object)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Decrement the reference count of a managed object.  <a href="#ga2"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
There are some types of m17n objects that are managed by their reference count. Those objects are called <em>managed</em> <em>objects</em>. When created, the reference count of a managed object is initialized to one. The <a class="el" href="group__m17nObject.html#ga1">m17n_object_ref()</a> function increments the reference count of a managed object by one, and the <a class="el" href="group__m17nObject.html#ga2">m17n_object_unref()</a> function decrements by one. A managed object is automatically freed when its reference count becomes zero.<p>
A property whose key is a managing key can have only a managed object as its value. Such functions as <a class="el" href="group__m17nSymbol.html#ga9">msymbol_put()</a> and <a class="el" href="group__m17nPlist.html#ga7">mplist_put()</a> pay special attention to such a property.<p>
In addition to the predefined managed object types, users can define their own managed object types. See the documentation of the <a class="el" href="group__m17nObject.html#ga0">m17n_object()</a> for more details. <hr><h2>Function Documentation</h2>
<a class="anchor" name="ga0" doxytag="m17n-core.c::m17n_object"></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top">void* m17n_object           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">int&nbsp;</td>
          <td class="mdname" nowrap> <em>size</em>, </td>
        </tr>
        <tr>
          <td class="md" nowrap align="right"></td>
          <td class="md"></td>
          <td class="md" nowrap>void(*)(void *)&nbsp;</td>
          <td class="mdname" nowrap> <em>freer</em></td>
        </tr>
        <tr>
          <td class="md"></td>
          <td class="md">)&nbsp;</td>
          <td class="md" colspan="2"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
The <a class="el" href="group__m17nObject.html#ga0">m17n_object()</a> function allocates a new managed object of <b>size</b> bytes and sets its reference count to 1. <b>freer</b> is the function that is used to free the object when the reference count becomes 0. If <b>freer</b> is NULL, the object is freed by the free() function.<p>
The heading bytes of the allocated object is occupied by <a class="el" href="structM17NObjectHead.html">M17NObjectHead</a>. That area is reserved for the m17n library and application programs should never touch it.<p>
<dl compact><dt><b>Return value:</b></dt><dd>This function returns a newly allocated object.</dd></dl>
<dl compact><dt><b>Errors:</b></dt><dd>This function never fails.</dd></dl>
<dl compact><dt><b>Example:</b></dt><dd><div class="fragment"><pre class="fragment"><span class="keyword">typedef</span> <span class="keyword">struct</span>
<span class="keyword"></span>{
  <a class="code" href="structM17NObjectHead.html">M17NObjectHead</a> head;
  <span class="keywordtype">int</span> mem1;
  <span class="keywordtype">char</span> *mem2;
} MYStruct;

<span class="keywordtype">void</span>
my_freer (<span class="keywordtype">void</span> *obj)
{
  free (((MYStruct *) obj)-&gt;mem2);
  free (obj);
}

<span class="keywordtype">void</span>
my_func (MText *mt, MSymbol key, <span class="keywordtype">int</span> num, <span class="keywordtype">char</span> *str)
{
  MYStruct *st = <a class="code" href="group__m17nObject.html#ga0">m17n_object</a> (<span class="keyword">sizeof</span> (MYStruct), my_freer);

  st-&gt;mem1 = num;
  st-&gt;mem2 = strdup (str);
  <span class="comment">// KEY must be a managing key.    </span>
  <a class="code" href="group__m17nTextProperty.html#ga8">mtext_put_prop</a> (mt, 0, mtext_len (mt), key, st);
  <span class="comment">// This sets the reference count of ST back to 1.   </span>
  <a class="code" href="group__m17nObject.html#ga2">m17n_object_unref</a> (st);
}
</pre></div></dd></dl>
    </td>
  </tr>
</table>
<a class="anchor" name="ga1" doxytag="m17n-core.c::m17n_object_ref"></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top">int m17n_object_ref           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">void *&nbsp;</td>
          <td class="mdname1" valign="top" nowrap> <em>object</em>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
The <a class="el" href="group__m17nObject.html#ga1">m17n_object_ref()</a> function increments the reference count of the managed object pointed to by <b>object</b>.<p>
<dl compact><dt><b>Return value:</b></dt><dd>This function returns the resulting reference count if it fits in a 16-bit unsigned integer (i.e. less than 0x10000). Otherwise, it return -1.</dd></dl>
<dl compact><dt><b>Errors:</b></dt><dd>This function never fails. </dd></dl>
    </td>
  </tr>
</table>
<a class="anchor" name="ga2" doxytag="m17n-core.c::m17n_object_unref"></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top">int m17n_object_unref           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">void *&nbsp;</td>
          <td class="mdname1" valign="top" nowrap> <em>object</em>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
The <a class="el" href="group__m17nObject.html#ga2">m17n_object_unref()</a> function decrements the reference count of the managed object pointed to by <b>object</b>. When the reference count becomes zero, the object is freed by its freer function.<p>
<dl compact><dt><b>Return value:</b></dt><dd>This function returns the resulting reference count if it fits in a 16-bit unsigned integer (i.e. less than 0x10000). Otherwise, it returns -1. Thus, the return value zero means that <b>object</b> is freed.</dd></dl>
<dl compact><dt><b>Errors:</b></dt><dd>This function never fails. </dd></dl>
    </td>
  </tr>
</table>
<hr>
<center>
<a href="#top-of-page">Top of this page</a><br><br>

<a class="qindex" href="index.html">Main Page</a> &nbsp; 
<a class="qindex" href="modules.html">Modules</a> &nbsp; 
<!-- <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; -->
<a class="qindex" href="annotated.html">Data Structures</a> &nbsp; 
<!-- <a class="qindex" href="files.html">File List</a> &nbsp;  -->
<!-- <a class="qindex" href="functions.html">Data Fields</a> &nbsp; -->
<a class="qindex" href="globals.html">Globals</a> &nbsp; 
<a class="qindex" href="pages.html">Appendix</a> &nbsp; 
</center>
<hr>
<ADDRESS>
<a href="http://www.m17n.org/m17n-lib/index.html" target="mulewindow"><img src="parrot.png" align=bottom alt="mulemark" border=0></a>
<A HREF="mailto:mule-aist@m17n.org">mule-aist@m17n.org</a>

</ADDRESS>
</body>
</HTML>

<!-- Copyright information

Copyright (C) 2001 Information-technology Promotion Agency (IPA)
Copyright (C) 2001-2004
  National Institute of Advanced Industrial Science and Technology (AIST)

This file is part of the m17n library documentation.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with no
Invariant Section, Front-Cover Texts "The m17n library documentation",
and no Back-Cover Texts.  A copy of the license is included in the
appendix entitled "GNU Free Documentation License".
-->