mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-10-17 21:08:14 +00:00
[common] converted stringlist to a generic objectlist
This commit is contained in:
33
common/include/common/objectlist.h
Normal file
33
common/include/common/objectlist.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
KVMGFX Client - A KVM Client for VGA Passthrough
|
||||
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
|
||||
https://looking-glass.hostfission.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct ObjectList * ObjectList;
|
||||
|
||||
typedef void (*ObjectFreeFn)(void * object);
|
||||
|
||||
ObjectList objectlist_new (ObjectFreeFn free_fn);
|
||||
void objectlist_free (ObjectList * sl);
|
||||
int objectlist_push (ObjectList sl, char * str);
|
||||
unsigned int objectlist_count(ObjectList sl);
|
||||
char * objectlist_at (ObjectList sl, unsigned int index);
|
||||
|
||||
// generic free method
|
||||
void objectlist_free_item(void *object);
|
@@ -17,12 +17,31 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "objectlist.h"
|
||||
|
||||
typedef struct StringList * StringList;
|
||||
typedef ObjectList StringList;
|
||||
|
||||
StringList stringlist_new (bool owns_strings);
|
||||
void stringlist_free (StringList * sl);
|
||||
int stringlist_push (StringList sl, char * str);
|
||||
unsigned int stringlist_count(StringList sl);
|
||||
char * stringlist_at (StringList sl, unsigned int index);
|
||||
inline static StringList stringlist_new(bool owns_strings)
|
||||
{
|
||||
return objectlist_new(owns_strings ? objectlist_free_item : 0);
|
||||
}
|
||||
|
||||
inline static void stringlist_free(StringList * sl)
|
||||
{
|
||||
return objectlist_free(sl);
|
||||
}
|
||||
|
||||
inline static int stringlist_push (StringList sl, char * str)
|
||||
{
|
||||
return objectlist_push(sl, str);
|
||||
}
|
||||
|
||||
inline static unsigned int stringlist_count(StringList sl)
|
||||
{
|
||||
return objectlist_count(sl);
|
||||
}
|
||||
|
||||
inline static char * stringlist_at(StringList sl, unsigned int index)
|
||||
{
|
||||
return objectlist_at(sl, index);
|
||||
}
|
Reference in New Issue
Block a user