]> git.ipfire.org Git - thirdparty/squid.git/blob - src/wordlist.h
mempools-nozero part 2: wordlist
[thirdparty/squid.git] / src / wordlist.h
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_WORDLIST_H
10 #define SQUID_WORDLIST_H
11
12 #include "globals.h"
13 #include "profiler/Profiler.h"
14 #include "SBufList.h"
15
16 /** A list of C-strings
17 *
18 * \deprecated use SBufList instead
19 */
20 class wordlist
21 {
22 MEMPROXY_CLASS(wordlist);
23 friend void wordlistDestroy(wordlist ** list);
24 friend char *wordlistChopHead(wordlist **);
25
26 public:
27 wordlist() : key(nullptr), next(nullptr) {}
28 // create a new wordlist node, with a copy of k as key
29 explicit wordlist(const char *k) : key(xstrdup(k)), next(nullptr) {}
30
31 wordlist(const wordlist &) = delete;
32 wordlist &operator=(const wordlist &) = delete;
33
34 char *key;
35 wordlist *next;
36
37 private:
38 // use wordlistDestroy instead
39 ~wordlist() = default;
40 };
41
42 class MemBuf;
43
44 /** Add a null-terminated c-string to a wordlist
45 *
46 * \deprecated use SBufList.push_back(SBuf(word)) instead
47 */
48 const char *wordlistAdd(wordlist **, const char *);
49
50 /** Concatenate a wordlist
51 *
52 * \deprecated use SBufListContainerJoin(SBuf()) from SBufAlgos.h instead
53 */
54 void wordlistCat(const wordlist *, MemBuf *);
55
56 /** append a wordlist to another
57 *
58 * \deprecated use SBufList.merge(otherwordlist) instead
59 */
60 void wordlistAddWl(wordlist **, wordlist *);
61
62 /** Concatenate the words in a wordlist
63 *
64 * \deprecated use SBufListContainerJoin(SBuf()) from SBufAlgos.h instead
65 */
66 void wordlistJoin(wordlist **, wordlist **);
67
68 /// destroy a wordlist
69 void wordlistDestroy(wordlist **);
70
71 /** remove the first element in a wordlist, and return its key
72 *
73 * \note the returned key must be freed by the caller using safe_free
74 * \note wl is altered so that it points to the second element
75 * \return nullptr if pointed-to wordlist is nullptr.
76 */
77 char *wordlistChopHead(wordlist **);
78
79 /// convert a wordlist to a SBufList
80 SBufList ToSBufList(wordlist *);
81
82 #endif /* SQUID_WORDLIST_H */
83