1
<refentry id="libxfce4util-Xfce-Generics">
3
<refentrytitle role="top_of_page" id="libxfce4util-Xfce-Generics.top_of_page">Xfce Generics</refentrytitle>
4
<manvolnum>3</manvolnum>
5
<refmiscinfo>LIBXFCE4UTIL Library</refmiscinfo>
9
<refname>Xfce Generics</refname>
10
<refpurpose>Generic data types and related functions.</refpurpose>
11
<!--[<xref linkend="desc" endterm="desc.title"/>]-->
14
<refsynopsisdiv id="libxfce4util-Xfce-Generics.synopsis" role="synopsis">
15
<title role="synopsis.title">Synopsis</title>
19
#include <libxfce4util/libxfce4util.h>
21
#define <link linkend="XFCE-GENERIC-STACK:CAPS">XFCE_GENERIC_STACK</link> (Type)
22
#define <link linkend="xfce-stack-new">xfce_stack_new</link> (StackType)
23
#define <link linkend="xfce-stack-free">xfce_stack_free</link> (stack)
24
#define <link linkend="xfce-stack-top">xfce_stack_top</link> (stack)
25
#define <link linkend="xfce-stack-pop">xfce_stack_pop</link> (stack)
26
#define <link linkend="xfce-stack-push">xfce_stack_push</link> (stack, value)
38
<refsect1 id="libxfce4util-Xfce-Generics.description" role="desc">
39
<title role="desc.title">Description</title>
41
This module provides generic data types - as known from the C++ standard
42
template library - for the brave C programmer. Since C does not provide
43
any template mechanism, these generics are completely based on C preprocessor
44
macros and the functions offer no type safety at all (though some common
45
mistakes will surely be caught by the C compiler).
50
<title>Using a generic stack</title>
52
typedef XFCE_GENERIC_STACK(int) IntStack;
54
IntStack *stack = xfce_stack_new (IntStack);
56
xfce_stack_push (stack, 0);
57
xfce_stack_push (stack, 1);
59
printf ("Top is %d\n", xfce_stack_top (stack));
61
xfce_stack_pop (stack);
63
printf ("Top is %d\n", xfce_stack_top (stack));
65
xfce_stack_free (stack);
71
<refsect1 id="libxfce4util-Xfce-Generics.details" role="details">
72
<title role="details.title">Details</title>
73
<refsect2 id="XFCE-GENERIC-STACK:CAPS" role="macro">
74
<title>XFCE_GENERIC_STACK()</title>
75
<indexterm zone="XFCE-GENERIC-STACK:CAPS"><primary>XFCE_GENERIC_STACK</primary></indexterm><programlisting>#define XFCE_GENERIC_STACK(Type)</programlisting>
77
This macro is used to create a new stack data type which elements are of
78
<parameter>Type</parameter>. For example, to create a stack type that handles elements of type
79
<link linkend="double"><literal>double</literal></link>, you'd write the following
81
typedef XFCE_GENERIC_STACK(double) MyDoubleStack;
83
and furtheron refer to your stack type as <link linkend="MyDoubleStack"><literal>MyDoubleStack</literal></link>.
84
</para><variablelist role="params">
85
<varlistentry><term><parameter>Type</parameter> :</term>
86
<listitem><simpara>Data type of the elements that should be handled by the stack. Can
87
be any valid data type from simple int's to complex structures.
90
</simpara></listitem></varlistentry>
91
</variablelist></refsect2>
92
<refsect2 id="xfce-stack-new" role="macro">
93
<title>xfce_stack_new()</title>
94
<indexterm zone="xfce-stack-new"><primary>xfce_stack_new</primary></indexterm><programlisting>#define xfce_stack_new(StackType)</programlisting>
96
Creates a new instance of <parameter>StackType</parameter> and returns a pointer to the newly
97
created instance. For example, imagine you declared a type <link linkend="MyDoubleStack"><literal>MyDoubleStack</literal></link>
98
as shown above, you can instantiate this type with
100
MyDoubleStack *my_stack = xfce_stack_new (MyDoubleStack);
102
</para><variablelist role="params">
103
<varlistentry><term><parameter>StackType</parameter> :</term>
104
<listitem><simpara>Type of stack declared with <link linkend="XFCE-GENERIC-STACK:CAPS"><type>XFCE_GENERIC_STACK</type></link>.
107
</simpara></listitem></varlistentry>
108
</variablelist></refsect2>
109
<refsect2 id="xfce-stack-free" role="macro">
110
<title>xfce_stack_free()</title>
111
<indexterm zone="xfce-stack-free"><primary>xfce_stack_free</primary></indexterm><programlisting>#define xfce_stack_free(stack)</programlisting>
113
Frees a stack, that was allocated using <link linkend="xfce-stack-new"><type>xfce_stack_new</type></link>.
114
</para><variablelist role="params">
115
<varlistentry><term><parameter>stack</parameter> :</term>
116
<listitem><simpara>A stack object.
119
</simpara></listitem></varlistentry>
120
</variablelist></refsect2>
121
<refsect2 id="xfce-stack-top" role="macro">
122
<title>xfce_stack_top()</title>
123
<indexterm zone="xfce-stack-top"><primary>xfce_stack_top</primary></indexterm><programlisting>#define xfce_stack_top(stack)</programlisting>
125
Returns the top element from <parameter>stack</parameter>. Note that this function does not
126
pop the top element, it just returns it.
127
</para><variablelist role="params">
128
<varlistentry><term><parameter>stack</parameter> :</term>
132
</simpara></listitem></varlistentry>
133
</variablelist></refsect2>
134
<refsect2 id="xfce-stack-pop" role="macro">
135
<title>xfce_stack_pop()</title>
136
<indexterm zone="xfce-stack-pop"><primary>xfce_stack_pop</primary></indexterm><programlisting>#define xfce_stack_pop(stack)</programlisting>
138
Removes the top element from <parameter>stack</parameter>.
139
</para><variablelist role="params">
140
<varlistentry><term><parameter>stack</parameter> :</term>
144
</simpara></listitem></varlistentry>
145
</variablelist></refsect2>
146
<refsect2 id="xfce-stack-push" role="macro">
147
<title>xfce_stack_push()</title>
148
<indexterm zone="xfce-stack-push"><primary>xfce_stack_push</primary></indexterm><programlisting>#define xfce_stack_push(stack, value)</programlisting>
150
Pushes a new <parameter>value</parameter> on top of <parameter>stack</parameter>.
151
</para><variablelist role="params">
152
<varlistentry><term><parameter>stack</parameter> :</term>
154
</simpara></listitem></varlistentry>
155
<varlistentry><term><parameter>value</parameter> :</term>
159
</simpara></listitem></varlistentry>
160
</variablelist></refsect2>