|
Packit |
8f70b4 |
/*
|
|
Packit |
8f70b4 |
* lftp - file transfer program
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* Copyright (c) 1996-2016 by Alexander V. Lukyanov (lav@yars.free.net)
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
8f70b4 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
8f70b4 |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit |
8f70b4 |
* (at your option) any later version.
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
8f70b4 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8f70b4 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
8f70b4 |
* GNU General Public License for more details.
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
8f70b4 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
8f70b4 |
*/
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
#ifndef STRINGSET_H
|
|
Packit |
8f70b4 |
#define STRINGSET_H
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
#include "xarray.h"
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class StringSet
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
xarray_m<char> set;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
const StringSet &operator=(const StringSet &); // disable assignment
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
public:
|
|
Packit |
8f70b4 |
StringSet();
|
|
Packit |
8f70b4 |
StringSet(const char *const *s,int n);
|
|
Packit |
8f70b4 |
StringSet(const StringSet &o);
|
|
Packit |
8f70b4 |
StringSet(const char *s);
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void Empty() { set.truncate(); }
|
|
Packit |
8f70b4 |
void Assign(const char *const *s,int n);
|
|
Packit |
8f70b4 |
void Assign(const char *s) { Assign(&s,1); }
|
|
Packit |
8f70b4 |
bool IsEqual(const char *const *s,int n) const;
|
|
Packit |
8f70b4 |
bool IsEqual(const StringSet &o) const { return IsEqual(o.Set(),o.Count()); }
|
|
Packit |
8f70b4 |
void Append(const char *);
|
|
Packit |
8f70b4 |
void AppendFormat(const char *,...) PRINTF_LIKE(2,3);
|
|
Packit |
8f70b4 |
void InsertBefore(int,const char *);
|
|
Packit |
8f70b4 |
void Replace(int,const char *);
|
|
Packit |
8f70b4 |
char *Pop(int i=0);
|
|
Packit |
8f70b4 |
void Remove(int i) { xfree(Pop(i)); }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
const char *const *Set() const { return set.get(); }
|
|
Packit |
8f70b4 |
char **SetNonConst() { return set.get_non_const(); }
|
|
Packit |
8f70b4 |
int Count() const { return set.count(); }
|
|
Packit |
8f70b4 |
const char *String(int i) const { return i>=0 && i
|
|
Packit |
8f70b4 |
const char *LastString() const { return String(Count()-1); }
|
|
Packit |
8f70b4 |
const char *operator[](int i) const { return String(i); }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void MoveHere(StringSet &o);
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
char **borrow() { return set.borrow(); }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void qsort(xarray_m<char>::cmp_t cmp) { set.qsort(cmp); }
|
|
Packit |
8f70b4 |
static int default_cmp(const char **a,const char **b) { return strcmp(*a,*b); }
|
|
Packit |
8f70b4 |
void qsort() { qsort(default_cmp); }
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
#endif // STRINGSET_H
|