1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2004 Sebastien Granjoux
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Actions data read in .wiz file
24 * It's just a list containing all data
25 *---------------------------------------------------------------------------*/
31 #include <glib/gdir.h>
33 /*---------------------------------------------------------------------------*/
35 #define STRING_CHUNK_SIZE 256
37 /*---------------------------------------------------------------------------*/
39 /* List containing all actions. It includes chunk for strings and actions
40 * object, so memory allocation is handled by the list itself */
45 GStringChunk
* string_pool
;
49 /* Action object, it includes a pointer on its owner to allocate new data */
60 *---------------------------------------------------------------------------*/
63 npw_action_new (NPWActionList
* owner
, NPWActionType type
)
67 g_return_val_if_fail (owner
!= NULL
, NULL
);
69 this = g_chunk_new0(NPWAction
, owner
->data_pool
);
72 owner
->list
= g_list_append (owner
->list
, this);
73 this->node
= g_list_last (owner
->list
);
79 npw_action_free (NPWAction
* this)
81 /* Memory allocated in string pool and project pool is not free */
85 npw_action_get_type (const NPWAction
* this)
91 npw_action_set_command (NPWAction
* this, const gchar
* command
)
93 this->command
= g_string_chunk_insert (this->owner
->string_pool
, command
);
97 npw_action_get_command (const NPWAction
* this)
103 npw_action_set_file (NPWAction
* this, const gchar
* file
)
105 npw_action_set_command (this, file
);
109 npw_action_get_file (const NPWAction
* this)
111 return npw_action_get_command (this);
115 npw_action_next (const NPWAction
* this)
117 GList
* node
= this->node
->next
;
119 return node
== NULL
? NULL
: (NPWAction
*)node
->data
;
123 /* Action list object
124 *---------------------------------------------------------------------------*/
127 npw_action_list_new (void)
131 this = g_new (NPWActionList
, 1);
132 this->string_pool
= g_string_chunk_new (STRING_CHUNK_SIZE
);
133 this->data_pool
= g_mem_chunk_new ("action pool", sizeof (NPWAction
), STRING_CHUNK_SIZE
* sizeof (NPWAction
) / 4, G_ALLOC_ONLY
);
140 npw_action_list_free (NPWActionList
* this)
142 g_return_if_fail (this != NULL
);
144 g_string_chunk_free (this->string_pool
);
145 g_mem_chunk_destroy (this->data_pool
);
146 g_list_free (this->list
);
151 npw_action_list_first (const NPWActionList
* this)
153 GList
* node
= g_list_first (this->list
);
155 return node
== NULL
? NULL
: (NPWAction
*)node
->data
;