Introducing the Mutator class

This commit is contained in:
Pierre Pronchery 2014-05-07 02:42:21 +02:00
parent 8ef9a253c0
commit 300e598151
8 changed files with 133 additions and 4 deletions

View File

@ -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 \

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2008-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2008-2014 Pierre Pronchery <khorben@defora.org> */
/* 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"

View File

@ -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

44
include/System/mutator.h Normal file
View File

@ -0,0 +1,44 @@
/* $Id$ */
/* Copyright (c) 2014 Pierre Pronchery <khorben@defora.org> */
/* 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 <http://www.gnu.org/licenses/>. */
#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 */

View File

@ -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

View File

@ -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

73
src/mutator.c Normal file
View File

@ -0,0 +1,73 @@
/* $Id$ */
/* Copyright (c) 2014 Pierre Pronchery <khorben@defora.org> */
/* 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 <http://www.gnu.org/licenses/>. */
#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);
}

View File

@ -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)