Commit 95c0d00944f64ab78e767f08cd1c0cc2c56b1e92
1 parent
6591c0a6
get rid of some function calls when selection interfaces
Showing
5 changed files
with
13 additions
and
67 deletions
| ... | ... | @@ -6,7 +6,7 @@ AC_INIT([cclass], [0.0.1], [Georg Hopp <georg@steffers.org>]) |
| 6 | 6 | AM_INIT_AUTOMAKE |
| 7 | 7 | AC_COPYRIGHT([Copyright (C) 2012 Georg Hopp]) |
| 8 | 8 | AC_REVISION([$Revision: 0.01 $]) |
| 9 | -AC_CONFIG_SRCDIR([src/class.c]) | |
| 9 | +AC_CONFIG_SRCDIR([src/testserver.c]) | |
| 10 | 10 | AC_CONFIG_HEADERS([config.h]) |
| 11 | 11 | AC_CONFIG_MACRO_DIR([m4]) |
| 12 | 12 | ... | ... |
| ... | ... | @@ -64,19 +64,23 @@ |
| 64 | 64 | INIT_IMPL(__VA_ARGS__) \ |
| 65 | 65 | }; struct class * const _##name = &c_##name |
| 66 | 66 | |
| 67 | +#define GET_CLASS(object) (*(class_ptr *)((object) - sizeof(void*))) | |
| 68 | +#define IFACE_GET(class,iface) (interfaceGet(&((class)->impl),(iface))) | |
| 69 | +#define IFACE_EXISTS(class,iface) (NULL != IFACE_GET((class),(iface))) | |
| 70 | + | |
| 67 | 71 | /** |
| 68 | 72 | * \todo actually i use gcc feature ## for variadoc... think about |
| 69 | 73 | * a way to make this standard. |
| 70 | 74 | */ |
| 71 | 75 | #define _CALL(object,_iface,method,...) \ |
| 72 | 76 | do { \ |
| 73 | - class_ptr class = class_getClass((object)); \ | |
| 77 | + class_ptr class = GET_CLASS((object)); \ | |
| 74 | 78 | if (class->init) class->init(); \ |
| 75 | - iface = (struct i_##_iface *)class_getInterface(&class, &i_##_iface); \ | |
| 79 | + iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ | |
| 76 | 80 | while ((NULL == iface || NULL == iface->method) && HAS_PARENT(class)) { \ |
| 77 | 81 | class = class->parent; \ |
| 78 | 82 | if (class->init) class->init(); \ |
| 79 | - iface = (struct i_##_iface *)class_getInterface(&class, &i_##_iface); \ | |
| 83 | + iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ | |
| 80 | 84 | }; \ |
| 81 | 85 | assert(NULL != iface->method); \ |
| 82 | 86 | } while(0) |
| ... | ... | @@ -98,20 +102,17 @@ |
| 98 | 102 | #define PARENTCALL(object,_iface,method,...) \ |
| 99 | 103 | do { \ |
| 100 | 104 | struct i_##_iface * iface; \ |
| 101 | - class_ptr class = class_getClass((object)); \ | |
| 105 | + class_ptr class = GET_CLASS((object)); \ | |
| 102 | 106 | if (class->init) class->init(); \ |
| 103 | 107 | assert(HAS_PARENT(class)); \ |
| 104 | 108 | class = class->parent; \ |
| 105 | 109 | if (class->init) class->init(); \ |
| 106 | - iface = (struct i_##_iface *)class_getInterface(&class, &i_##_iface); \ | |
| 110 | + iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ | |
| 107 | 111 | assert(NULL != iface->method); \ |
| 108 | 112 | iface->method(object, ##__VA_ARGS__); \ |
| 109 | 113 | } while(0) |
| 110 | 114 | |
| 111 | 115 | |
| 112 | -#define IFACE_GET(class,iface) (interfaceGet(&((class)->impl),(iface))) | |
| 113 | -#define IFACE_EXISTS(class,iface) (NULL != IFACE_GET((class),(iface))) | |
| 114 | - | |
| 115 | 116 | #define HAS_PARENT(class) (NULL != ((class)->parent)) |
| 116 | 117 | |
| 117 | 118 | typedef void (* fptr_classInit)(void); |
| ... | ... | @@ -126,9 +127,6 @@ struct class { |
| 126 | 127 | struct iface_impl impl; |
| 127 | 128 | }; |
| 128 | 129 | |
| 129 | -extern void * class_getInterface(class_ptr *, iface_ptr); | |
| 130 | -extern class_ptr class_getClass(void *); | |
| 131 | - | |
| 132 | 130 | #endif // __CLASS_H__ |
| 133 | 131 | |
| 134 | 132 | // vim: set ts=4 sw=4: | ... | ... |
| ... | ... | @@ -3,9 +3,7 @@ AUTOMAKE_OPTIONS = subdir-objects |
| 3 | 3 | |
| 4 | 4 | IFACE = interface/class.c interface/stream_reader.c interface/logger.c \ |
| 5 | 5 | interface/stream_writer.c interface/http_intro.c \ |
| 6 | - interface/subject.c interface/observer.c | |
| 7 | -CLASS = class.c interface.c | |
| 8 | -RB = ringbuffer.c ringbuffer/rb_read.c | |
| 6 | + interface/subject.c interface/observer.c interface.c | |
| 9 | 7 | SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c |
| 10 | 8 | SERVER = server.c server/run.c server/close_conn.c server/poll.c \ |
| 11 | 9 | server/handle_accept.c server/read.c |
| ... | ... | @@ -41,7 +39,7 @@ AM_CFLAGS = -Wall -I ../include/ |
| 41 | 39 | bin_PROGRAMS = testserver |
| 42 | 40 | |
| 43 | 41 | testserver_SOURCES = testserver.c \ |
| 44 | - $(IFACE) $(CLASS) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \ | |
| 42 | + $(IFACE) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \ | |
| 45 | 43 | $(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \ |
| 46 | 44 | $(UTILS) |
| 47 | 45 | testserver_CFLAGS = -Wall -I ../include/ | ... | ... |
src/class.c
deleted
100644 → 0
| 1 | -/** | |
| 2 | - * \file | |
| 3 | - * Helper functions for class. | |
| 4 | - * | |
| 5 | - * \todo rename function to fit in the otherwise used scheme. | |
| 6 | - * \author Georg Hopp | |
| 7 | - * | |
| 8 | - * \copyright | |
| 9 | - * Copyright (C) 2012 Georg Hopp | |
| 10 | - * | |
| 11 | - * This program is free software: you can redistribute it and/or modify | |
| 12 | - * it under the terms of the GNU General Public License as published by | |
| 13 | - * the Free Software Foundation, either version 3 of the License, or | |
| 14 | - * (at your option) any later version. | |
| 15 | - * | |
| 16 | - * This program is distributed in the hope that it will be useful, | |
| 17 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | - * GNU General Public License for more details. | |
| 20 | - * | |
| 21 | - * You should have received a copy of the GNU General Public License | |
| 22 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 23 | - */ | |
| 24 | - | |
| 25 | -#include <stdarg.h> | |
| 26 | -#include <stdlib.h> | |
| 27 | - | |
| 28 | -#include "class.h" | |
| 29 | -#include "interface.h" | |
| 30 | - | |
| 31 | -void * | |
| 32 | -class_getInterface(class_ptr * class, iface_ptr _iface) | |
| 33 | -{ | |
| 34 | - void * iface = (void *)IFACE_GET(*class, _iface); | |
| 35 | - | |
| 36 | - while(NULL == iface && HAS_PARENT(*class)) { | |
| 37 | - *class = (*class)->parent; | |
| 38 | - iface = (void *)IFACE_GET(*class, _iface); | |
| 39 | - } | |
| 40 | - | |
| 41 | - return iface; | |
| 42 | -} | |
| 43 | - | |
| 44 | -class_ptr | |
| 45 | -class_getClass(void * object) | |
| 46 | -{ | |
| 47 | - return *(class_ptr *)(object - sizeof(void*)); | |
| 48 | -} | |
| 49 | - | |
| 50 | -// vim: set ts=4 sw=4: |
| ... | ... | @@ -70,7 +70,7 @@ classDelete(void ** object) |
| 70 | 70 | void * |
| 71 | 71 | classClone(void * _object) |
| 72 | 72 | { |
| 73 | - class_ptr class = class_getClass(_object); | |
| 73 | + class_ptr class = GET_CLASS(_object); | |
| 74 | 74 | void * object = calloc(1, class->object_size + sizeof(void*)); |
| 75 | 75 | |
| 76 | 76 | * (class_ptr *)object = class; | ... | ... |
Please
register
or
login
to post a comment