1b2859abeSMarcus Overhagen/*
2b2859abeSMarcus Overhagen * Copyright (c) 2004-2007 Marcus Overhagen <marcus@overhagen.de>
3b2859abeSMarcus Overhagen *
4b2859abeSMarcus Overhagen * Permission is hereby granted, free of charge, to any person
5b2859abeSMarcus Overhagen * obtaining a copy of this software and associated documentation
6b2859abeSMarcus Overhagen * files (the "Software"), to deal in the Software without restriction,
7b2859abeSMarcus Overhagen * including without limitation the rights to use, copy, modify,
8b2859abeSMarcus Overhagen * merge, publish, distribute, sublicense, and/or sell copies of
9b2859abeSMarcus Overhagen * the Software, and to permit persons to whom the Software is
10b2859abeSMarcus Overhagen * furnished to do so, subject to the following conditions:
11b2859abeSMarcus Overhagen *
12b2859abeSMarcus Overhagen * The above copyright notice and this permission notice shall be
13b2859abeSMarcus Overhagen * included in all copies or substantial portions of the Software.
14b2859abeSMarcus Overhagen *
15b2859abeSMarcus Overhagen * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16b2859abeSMarcus Overhagen * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17b2859abeSMarcus Overhagen * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18b2859abeSMarcus Overhagen * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19b2859abeSMarcus Overhagen * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20b2859abeSMarcus Overhagen * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21b2859abeSMarcus Overhagen * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22b2859abeSMarcus Overhagen * OTHER DEALINGS IN THE SOFTWARE.
23b2859abeSMarcus Overhagen */
24b2859abeSMarcus Overhagen
25b2859abeSMarcus Overhagen#ifndef __STRING_LIST_H
26b2859abeSMarcus Overhagen#define __STRING_LIST_H
27b2859abeSMarcus Overhagen
28b2859abeSMarcus Overhagen#include <List.h>
29b2859abeSMarcus Overhagen#include <stdio.h>
30b2859abeSMarcus Overhagen#include <stdlib.h>
31b2859abeSMarcus Overhagen#include <string.h>
32b2859abeSMarcus Overhagen
33b2859abeSMarcus Overhagenclass StringList
34b2859abeSMarcus Overhagen{
35b2859abeSMarcus Overhagenpublic:
36b2859abeSMarcus Overhagen			StringList();
37b2859abeSMarcus Overhagen			~StringList();
38b2859abeSMarcus Overhagen
39b2859abeSMarcus Overhagen			// AddItem makes a copy of the data
40b2859abeSMarcus Overhagen			void AddItem(const char *string);
41b2859abeSMarcus Overhagen
42b2859abeSMarcus Overhagen			// either the String or NULL
43b2859abeSMarcus Overhagen			const char *ItemAt(int index) const;
44b2859abeSMarcus Overhagen
45b2859abeSMarcus Overhagen			void MakeEmpty();
46b2859abeSMarcus Overhagen
47b2859abeSMarcus Overhagenprivate:
48b2859abeSMarcus Overhagen	BList	list;
49b2859abeSMarcus Overhagen};
50b2859abeSMarcus Overhagen
51b2859abeSMarcus Overhagen
52b2859abeSMarcus Overhageninline
53b2859abeSMarcus OverhagenStringList::StringList()
54b2859abeSMarcus Overhagen :	list()
55b2859abeSMarcus Overhagen{
56b2859abeSMarcus Overhagen}
57b2859abeSMarcus Overhagen
58b2859abeSMarcus Overhagen
59b2859abeSMarcus Overhageninline
60b2859abeSMarcus OverhagenStringList::~StringList()
61b2859abeSMarcus Overhagen{
62b2859abeSMarcus Overhagen	MakeEmpty();
63b2859abeSMarcus Overhagen}
64b2859abeSMarcus Overhagen
65b2859abeSMarcus Overhagen
66b2859abeSMarcus Overhageninline void
67b2859abeSMarcus OverhagenStringList::AddItem(const char *string)
68b2859abeSMarcus Overhagen{
69b2859abeSMarcus Overhagen	list.AddItem(strdup(string));
70b2859abeSMarcus Overhagen}
71b2859abeSMarcus Overhagen
72b2859abeSMarcus Overhagen
73b2859abeSMarcus Overhageninline const char *
74b2859abeSMarcus OverhagenStringList::ItemAt(int index) const
75b2859abeSMarcus Overhagen{
76b2859abeSMarcus Overhagen	return (const char *)list.ItemAt(index);
77b2859abeSMarcus Overhagen}
78b2859abeSMarcus Overhagen
79b2859abeSMarcus Overhagen
80b2859abeSMarcus Overhageninline void
81b2859abeSMarcus OverhagenStringList::MakeEmpty()
82b2859abeSMarcus Overhagen{
83b2859abeSMarcus Overhagen	int i = list.CountItems();
84b2859abeSMarcus Overhagen	while (--i > -1)
85b2859abeSMarcus Overhagen		free(list.RemoveItem(i));
86b2859abeSMarcus Overhagen}
87b2859abeSMarcus Overhagen
88b2859abeSMarcus Overhagen
89b2859abeSMarcus Overhagen#endif
90