From 1084820a8afe2dee17cc0c9e77b690273967289e Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Tue, 27 Oct 2015 16:09:23 +0100 Subject: [PATCH] Inline simple accessor functions --- include/tr/interface/indexable.h | 14 +++++++++-- include/tr/interface/observer.h | 12 +++++++--- include/tr/interface/serializable.h | 32 +++++++++++++++++++++---- include/tr/interface/subject.h | 34 ++++++++++++++++++++++++--- src/i_indexable.c | 13 +---------- src/i_observer.c | 11 +++------ src/i_serializable.c | 36 ++--------------------------- src/i_subject.c | 32 +++---------------------- 8 files changed, 88 insertions(+), 96 deletions(-) diff --git a/include/tr/interface/indexable.h b/include/tr/interface/indexable.h index 1898f51..94480c4 100644 --- a/include/tr/interface/indexable.h +++ b/include/tr/interface/indexable.h @@ -11,7 +11,7 @@ * an instance of class Index / or an class that implements * the index interface. Uuid would then be a candidate for such * a class. - * + * * \todo * Maybe merge hashable and indexable. Thus we might get an * easy way to exchange the hashing mechanism used for my @@ -49,7 +49,17 @@ TR_INTERFACE(TR_Indexable) { fptr_TR_getIndex index; }; -void * TR_getIndex(void *); +/** + * Get it's index from an indexable object. + */ +inline +void * +TR_getIndex(void * indexable) +{ + void * ret; + TR_RETCALL(indexable, TR_Indexable, index, ret); + return ret; +} #endif // __TR_INTERFACE_INDEXABLE_H__ diff --git a/include/tr/interface/observer.h b/include/tr/interface/observer.h index edc576c..8ed70dd 100644 --- a/include/tr/interface/observer.h +++ b/include/tr/interface/observer.h @@ -37,10 +37,16 @@ TR_INTERFACE(TR_Observer) { }; /** - * This will be called on each registered observer if the subject - * needs to notify them. + * The implementation of update will be called by a + * subject whenever it ments to inform the observer about + * something */ -void TR_observerUpdate(void *, void *); +inline +void +TR_observerUpdate(void * observer, void * subject) +{ + TR_CALL(observer, TR_Observer, update, subject); +} #endif // __TR_INTERFACE_OBSERVER_H__ diff --git a/include/tr/interface/serializable.h b/include/tr/interface/serializable.h index d1b2743..2ada4ac 100644 --- a/include/tr/interface/serializable.h +++ b/include/tr/interface/serializable.h @@ -30,20 +30,42 @@ #include "tr/interface.h" -//typedef size_t (* fptr_serializeSize)(void *); typedef void (* fptr_serialize)(void *, unsigned char **, size_t *); typedef void (* fptr_unserialize)(void *, const unsigned char *, size_t); TR_INTERFACE(TR_Serializable) { TR_IFID; -// fptr_serializeSize serializeSize; fptr_serialize serialize; fptr_unserialize unserialize; }; -//size_t TR_serializeSize(void *); -void TR_serialize(void *, unsigned char **, size_t *); -void TR_unserialize(void *, const unsigned char *, size_t); +/** + * Serialize the given instance to a byte array + */ +inline +void +TR_serialize( + void * serializable, + unsigned char ** serialized, + size_t * nserialized) +{ + TR_CALL(serializable, TR_Serializable, serialize, serialized, + nserialized); +} + +/** + * Unerialize the given instance to a byte array + */ +inline +void +TR_unserialize( + void * serializable, + const unsigned char * serialized, + size_t nserialized) +{ + TR_CALL(serializable, TR_Serializable, unserialize, serialized, + nserialized); +} #endif // __TR_SERIALIZABLE_H__ diff --git a/include/tr/interface/subject.h b/include/tr/interface/subject.h index 30a69d5..e0a33c9 100644 --- a/include/tr/interface/subject.h +++ b/include/tr/interface/subject.h @@ -37,9 +37,37 @@ TR_INTERFACE(TR_Subject) { fptr_subjectNotify notify; }; -void TR_subjectAttach(void *, void *); -void TR_subjectDetach(void *, void *); -void TR_subjectNotify(void *); +/** + * Attach an observer to a subject. After a successfull + * call to this the subject will inform the observer about events. + */ +inline +void +TR_subjectAttach(void * subject, void * observer) +{ + TR_CALL(subject, TR_Subject, attach, observer); +} + +/** + * Detach an Observer from a Subject. After this no events + * will be propagated from the subject to the observer anymore. + */ +inline +void +TR_subjectDetach(void * subject, void * observer) +{ + TR_CALL(subject, TR_Subject, detach, observer); +} + +/** + * Trigger the a notification of all attached observers. + */ +inline +void +TR_subjectNotify(void * subject) +{ + TR_CALL(subject, TR_Subject, notify); +} #endif // __SUBJECT_H__ diff --git a/src/i_indexable.c b/src/i_indexable.c index f7dd313..00ba499 100644 --- a/src/i_indexable.c +++ b/src/i_indexable.c @@ -29,17 +29,6 @@ */ TR_CREATE_INTERFACE(TR_Indexable, 1); -/** - * Get it's index from an indexable object. - */ -void * -TR_getIndex(void * indexable) -{ - void * ret; - - TR_RETCALL(indexable, TR_Indexable, index, ret); - - return ret; -} +extern inline void * TR_getIndex(void *); // vim: set ts=4 sw=4: diff --git a/src/i_observer.c b/src/i_observer.c index 9da1c0f..09743ee 100644 --- a/src/i_observer.c +++ b/src/i_observer.c @@ -29,14 +29,9 @@ TR_CREATE_INTERFACE(TR_Observer, 1); /** - * The implementation of update will be called by a - * subject whenever it ments to inform the observer about - * something + * This will be called on each registered observer if the subject + * needs to notify them. */ -void -TR_observerUpdate(void * observer, void * subject) -{ - TR_CALL(observer, TR_Observer, update, subject); -} +extern inline void TR_observerUpdate(void *, void *); // vim: set ts=4 sw=4: diff --git a/src/i_serializable.c b/src/i_serializable.c index 3d097ce..780cd86 100644 --- a/src/i_serializable.c +++ b/src/i_serializable.c @@ -28,39 +28,7 @@ */ TR_CREATE_INTERFACE(TR_Serializable, 2); - -/** - * Serialize the given instance to a byte array - */ -void -TR_serialize( - void * serializable, - unsigned char ** serialized, - size_t * nserialized) -{ - TR_CALL( - serializable, - TR_Serializable, - serialize, - serialized, - nserialized); -} - -/** - * Unerialize the given instance to a byte array - */ -void -TR_unserialize( - void * serializable, - const unsigned char * serialized, - size_t nserialized) -{ - TR_CALL( - serializable, - TR_Serializable, - unserialize, - serialized, - nserialized); -} +extern inline void TR_serialize(void *, unsigned char **, size_t *); +extern inline void TR_unserialize(void *, const unsigned char *, size_t); // vim: set ts=4 sw=4: diff --git a/src/i_subject.c b/src/i_subject.c index 73a830a..9ac12a4 100644 --- a/src/i_subject.c +++ b/src/i_subject.c @@ -28,34 +28,8 @@ */ TR_CREATE_INTERFACE(TR_Subject, 3); - -/** - * Attach an observer to a subject. After a successfull - * call to this the subject will inform the observer about events. - */ -void -TR_subjectAttach(void * subject, void * observer) -{ - TR_CALL(subject, TR_Subject, attach, observer); -} - -/** - * Detach an Observer from a Subject. After this no events - * will be propagated from the subject to the observer anymore. - */ -void -TR_subjectDetach(void * subject, void * observer) -{ - TR_CALL(subject, TR_Subject, detach, observer); -} - -/** - * Trigger the a notification of all attached observers. - */ -void -TR_subjectNotify(void * subject) -{ - TR_CALL(subject, TR_Subject, notify); -} +extern inline void TR_subjectAttach(void *, void *); +extern inline void TR_subjectDetach(void *, void *); +extern inline void TR_subjectNotify(void *); // vim: set ts=4 sw=4: