1/* This may look like C code, but it is really -*- C++ -*- */
2
3/* Keyword list.
4
5   Copyright (C) 2002 Free Software Foundation, Inc.
6   Written by Bruno Haible <bruno@clisp.org>.
7
8   This file is part of GNU GPERF.
9
10   This program is free software: you can redistribute it and/or modify
11   it under the terms of the GNU General Public License as published by
12   the Free Software Foundation; either version 3 of the License, or
13   (at your option) any later version.
14
15   This program is distributed in the hope that it will be useful,
16   but WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   GNU General Public License for more details.
19
20   You should have received a copy of the GNU General Public License
21   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
23#ifndef keyword_list_h
24#define keyword_list_h 1
25
26#include "keyword.h"
27
28/* List node of a linear list of Keyword.  */
29class Keyword_List
30{
31public:
32  /* Constructor.  */
33                        Keyword_List (Keyword *car);
34
35  /* Access to first element of list.  */
36  Keyword *             first () const;
37  /* Access to next element of list.  */
38  Keyword_List *&       rest ();
39
40protected:
41  Keyword_List *        _cdr;
42  Keyword * const       _car;
43};
44
45/* List node of a linear list of KeywordExt.  */
46class KeywordExt_List : public Keyword_List
47{
48public:
49  /* Constructor.  */
50                        KeywordExt_List (KeywordExt *car);
51
52  /* Access to first element of list.  */
53  KeywordExt *          first () const;
54  /* Access to next element of list.  */
55  KeywordExt_List *&    rest ();
56};
57
58/* Copies a linear list, sharing the list elements.  */
59extern Keyword_List * copy_list (Keyword_List *list);
60extern KeywordExt_List * copy_list (KeywordExt_List *list);
61
62/* Deletes a linear list, keeping the list elements in memory.  */
63extern void delete_list (Keyword_List *list);
64
65/* Sorts a linear list, given a comparison function.
66   Note: This uses a variant of mergesort that is *not* a stable sorting
67   algorithm.  */
68extern Keyword_List * mergesort_list (Keyword_List *list,
69                                      bool (*less) (Keyword *keyword1,
70                                                    Keyword *keyword2));
71extern KeywordExt_List * mergesort_list (KeywordExt_List *list,
72                                         bool (*less) (KeywordExt *keyword1,
73                                                       KeywordExt *keyword2));
74
75#ifdef __OPTIMIZE__
76
77#define INLINE inline
78#include "keyword-list.icc"
79#undef INLINE
80
81#endif
82
83#endif
84