diff --git a/Makefile b/Makefile index 7da8c49..fbdc87f 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,7 @@ dist: $(PACKAGE)-$(VERSION)/include/System/event.h \ $(PACKAGE)-$(VERSION)/include/System/file.h \ $(PACKAGE)-$(VERSION)/include/System/hash.h \ + $(PACKAGE)-$(VERSION)/include/System/mutator.h \ $(PACKAGE)-$(VERSION)/include/System/object.h \ $(PACKAGE)-$(VERSION)/include/System/parser.h \ $(PACKAGE)-$(VERSION)/include/System/plugin.h \ @@ -71,6 +72,7 @@ dist: $(PACKAGE)-$(VERSION)/src/error.c \ $(PACKAGE)-$(VERSION)/src/event.c \ $(PACKAGE)-$(VERSION)/src/hash.c \ + $(PACKAGE)-$(VERSION)/src/mutator.c \ $(PACKAGE)-$(VERSION)/src/object.c \ $(PACKAGE)-$(VERSION)/src/parser.c \ $(PACKAGE)-$(VERSION)/src/plugin.c \ diff --git a/include/System.h b/include/System.h index 7777870..9a5307c 100644 --- a/include/System.h +++ b/include/System.h @@ -1,5 +1,5 @@ /* $Id$ */ -/* Copyright (c) 2008-2012 Pierre Pronchery */ +/* Copyright (c) 2008-2014 Pierre Pronchery */ /* This file is part of DeforaOS System libSystem */ /* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -24,6 +24,7 @@ # include "System/error.h" # include "System/event.h" # include "System/file.h" +# include "System/mutator.h" # include "System/object.h" # include "System/parser.h" # include "System/plugin.h" diff --git a/include/System/Makefile b/include/System/Makefile index d4c4cd3..4930749 100644 --- a/include/System/Makefile +++ b/include/System/Makefile @@ -29,6 +29,8 @@ install: $(MKDIR) $(DESTDIR)$(INCLUDEDIR)/System $(INSTALL) -m 0644 hash.h $(DESTDIR)$(INCLUDEDIR)/System/hash.h $(MKDIR) $(DESTDIR)$(INCLUDEDIR)/System + $(INSTALL) -m 0644 mutator.h $(DESTDIR)$(INCLUDEDIR)/System/mutator.h + $(MKDIR) $(DESTDIR)$(INCLUDEDIR)/System $(INSTALL) -m 0644 object.h $(DESTDIR)$(INCLUDEDIR)/System/object.h $(MKDIR) $(DESTDIR)$(INCLUDEDIR)/System $(INSTALL) -m 0644 parser.h $(DESTDIR)$(INCLUDEDIR)/System/parser.h @@ -49,6 +51,7 @@ uninstall: $(RM) -- $(DESTDIR)$(INCLUDEDIR)/System/event.h $(RM) -- $(DESTDIR)$(INCLUDEDIR)/System/file.h $(RM) -- $(DESTDIR)$(INCLUDEDIR)/System/hash.h + $(RM) -- $(DESTDIR)$(INCLUDEDIR)/System/mutator.h $(RM) -- $(DESTDIR)$(INCLUDEDIR)/System/object.h $(RM) -- $(DESTDIR)$(INCLUDEDIR)/System/parser.h $(RM) -- $(DESTDIR)$(INCLUDEDIR)/System/plugin.h diff --git a/include/System/mutator.h b/include/System/mutator.h new file mode 100644 index 0000000..b5817ab --- /dev/null +++ b/include/System/mutator.h @@ -0,0 +1,44 @@ +/* $Id$ */ +/* Copyright (c) 2014 Pierre Pronchery */ +/* This file is part of DeforaOS System libSystem */ +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ + + + +#ifndef LIBSYSTEM_MUTATOR_H +# define LIBSYSTEM_MUTATOR_H + +# include "string.h" + + +/* Mutator */ +/* types */ +typedef struct _Hash Mutator; + +typedef void (*MutatorForeach)(void const * key, void * value, void * data); + + +/* functions */ +Mutator * mutator_new(void); +void mutator_delete(Mutator * mutator); + +/* accessors */ +void * mutator_get(Mutator * mutator, String const * key); +int mutator_set(Mutator * mutator, String const * key, void * value); +size_t mutator_count(Mutator * mutator); + +/* useful */ +void mutator_foreach(Mutator * mutator, MutatorForeach func, void * data); +int mutator_reset(Mutator * mutator); + +#endif /* !LIBSYSTEM_MUTATOR_H */ diff --git a/include/System/project.conf b/include/System/project.conf index 9005855..4f217f2 100644 --- a/include/System/project.conf +++ b/include/System/project.conf @@ -1,4 +1,4 @@ -includes=array.h,buffer.h,config.h,error.h,event.h,file.h,hash.h,object.h,parser.h,plugin.h,string.h,token.h,variable.h +includes=array.h,buffer.h,config.h,error.h,event.h,file.h,hash.h,mutator.h,object.h,parser.h,plugin.h,string.h,token.h,variable.h dist=Makefile [array.h] @@ -22,6 +22,9 @@ install=$(INCLUDEDIR)/System [hash.h] install=$(INCLUDEDIR)/System +[mutator.h] +install=$(INCLUDEDIR)/System + [object.h] install=$(INCLUDEDIR)/System diff --git a/src/Makefile b/src/Makefile index 0b282df..513d206 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,7 +19,7 @@ INSTALL = install all: $(TARGETS) -libSystem_OBJS = array.o buffer.o config.o error.o event.o hash.o object.o parser.o plugin.o string.o token.o variable.o +libSystem_OBJS = array.o buffer.o config.o error.o event.o hash.o mutator.o object.o parser.o plugin.o string.o token.o variable.o libSystem_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) libSystem_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) @@ -50,6 +50,9 @@ event.o: event.c hash.o: hash.c $(CC) $(libSystem_CFLAGS) -c hash.c +mutator.o: mutator.c + $(CC) $(libSystem_CFLAGS) -c mutator.c + object.o: object.c $(CC) $(libSystem_CFLAGS) -c object.c diff --git a/src/mutator.c b/src/mutator.c new file mode 100644 index 0000000..a647f66 --- /dev/null +++ b/src/mutator.c @@ -0,0 +1,73 @@ +/* $Id$ */ +/* Copyright (c) 2014 Pierre Pronchery */ +/* This file is part of DeforaOS System libSystem */ +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ + + + +#include "System/hash.h" +#include "System/mutator.h" +#include "System/object.h" + + +/* Mutator */ +/* public */ +/* functions */ +/* mutator_new */ +Mutator * mutator_new(void) +{ + return hash_new(hash_func_string, hash_compare_string); +} + + +/* mutator_delete */ +void mutator_delete(Mutator * mutator) +{ + hash_delete(mutator); +} + + +/* accessors */ +/* mutator_count */ +size_t mutator_count(Mutator * mutator) +{ + return hash_count(mutator); +} + + +/* mutator_get */ +void * mutator_get(Mutator * mutator, String const * key) +{ + return hash_get(mutator, key); +} + + +/* mutator_set */ +int mutator_set(Mutator * mutator, String const * key, void * value) +{ + return hash_set(mutator, key, value); +} + + +/* useful */ +void mutator_foreach(Mutator * mutator, MutatorForeach func, void * data) +{ + hash_foreach(mutator, func, data); +} + + +/* mutator_reset */ +int mutator_reset(Mutator * mutator) +{ + return hash_reset(mutator); +} diff --git a/src/project.conf b/src/project.conf index f375a02..5d59c97 100644 --- a/src/project.conf +++ b/src/project.conf @@ -9,7 +9,7 @@ dist=Makefile,token.h,python/project.conf,python/Makefile,python/libSystem.c,pyt [libSystem] type=library -sources=array.c,buffer.c,config.c,error.c,event.c,hash.c,object.c,parser.c,plugin.c,string.c,token.c,variable.c +sources=array.c,buffer.c,config.c,error.c,event.c,hash.c,mutator.c,object.c,parser.c,plugin.c,string.c,token.c,variable.c ldflags=-ldl -lsocket -lws2_32 install=$(LIBDIR)