Commit 1084820a8afe2dee17cc0c9e77b690273967289e

Authored by Georg Hopp
1 parent d8c92a6c

Inline simple accessor functions

@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 * an instance of class Index / or an class that implements 11 * an instance of class Index / or an class that implements
12 * the index interface. Uuid would then be a candidate for such 12 * the index interface. Uuid would then be a candidate for such
13 * a class. 13 * a class.
14 - * 14 + *
15 * \todo 15 * \todo
16 * Maybe merge hashable and indexable. Thus we might get an 16 * Maybe merge hashable and indexable. Thus we might get an
17 * easy way to exchange the hashing mechanism used for my 17 * easy way to exchange the hashing mechanism used for my
@@ -49,7 +49,17 @@ TR_INTERFACE(TR_Indexable) { @@ -49,7 +49,17 @@ TR_INTERFACE(TR_Indexable) {
49 fptr_TR_getIndex index; 49 fptr_TR_getIndex index;
50 }; 50 };
51 51
52 -void * TR_getIndex(void *); 52 +/**
  53 + * Get it's index from an indexable object.
  54 + */
  55 +inline
  56 +void *
  57 +TR_getIndex(void * indexable)
  58 +{
  59 + void * ret;
  60 + TR_RETCALL(indexable, TR_Indexable, index, ret);
  61 + return ret;
  62 +}
53 63
54 #endif // __TR_INTERFACE_INDEXABLE_H__ 64 #endif // __TR_INTERFACE_INDEXABLE_H__
55 65
@@ -37,10 +37,16 @@ TR_INTERFACE(TR_Observer) { @@ -37,10 +37,16 @@ TR_INTERFACE(TR_Observer) {
37 }; 37 };
38 38
39 /** 39 /**
40 - * This will be called on each registered observer if the subject  
41 - * needs to notify them. 40 + * The implementation of update will be called by a
  41 + * subject whenever it ments to inform the observer about
  42 + * something
42 */ 43 */
43 -void TR_observerUpdate(void *, void *); 44 +inline
  45 +void
  46 +TR_observerUpdate(void * observer, void * subject)
  47 +{
  48 + TR_CALL(observer, TR_Observer, update, subject);
  49 +}
44 50
45 #endif // __TR_INTERFACE_OBSERVER_H__ 51 #endif // __TR_INTERFACE_OBSERVER_H__
46 52
@@ -30,20 +30,42 @@ @@ -30,20 +30,42 @@
30 #include "tr/interface.h" 30 #include "tr/interface.h"
31 31
32 32
33 -//typedef size_t (* fptr_serializeSize)(void *);  
34 typedef void (* fptr_serialize)(void *, unsigned char **, size_t *); 33 typedef void (* fptr_serialize)(void *, unsigned char **, size_t *);
35 typedef void (* fptr_unserialize)(void *, const unsigned char *, size_t); 34 typedef void (* fptr_unserialize)(void *, const unsigned char *, size_t);
36 35
37 TR_INTERFACE(TR_Serializable) { 36 TR_INTERFACE(TR_Serializable) {
38 TR_IFID; 37 TR_IFID;
39 -// fptr_serializeSize serializeSize;  
40 fptr_serialize serialize; 38 fptr_serialize serialize;
41 fptr_unserialize unserialize; 39 fptr_unserialize unserialize;
42 }; 40 };
43 41
44 -//size_t TR_serializeSize(void *);  
45 -void TR_serialize(void *, unsigned char **, size_t *);  
46 -void TR_unserialize(void *, const unsigned char *, size_t); 42 +/**
  43 + * Serialize the given instance to a byte array
  44 + */
  45 +inline
  46 +void
  47 +TR_serialize(
  48 + void * serializable,
  49 + unsigned char ** serialized,
  50 + size_t * nserialized)
  51 +{
  52 + TR_CALL(serializable, TR_Serializable, serialize, serialized,
  53 + nserialized);
  54 +}
  55 +
  56 +/**
  57 + * Unerialize the given instance to a byte array
  58 + */
  59 +inline
  60 +void
  61 +TR_unserialize(
  62 + void * serializable,
  63 + const unsigned char * serialized,
  64 + size_t nserialized)
  65 +{
  66 + TR_CALL(serializable, TR_Serializable, unserialize, serialized,
  67 + nserialized);
  68 +}
47 69
48 #endif // __TR_SERIALIZABLE_H__ 70 #endif // __TR_SERIALIZABLE_H__
49 71
@@ -37,9 +37,37 @@ TR_INTERFACE(TR_Subject) { @@ -37,9 +37,37 @@ TR_INTERFACE(TR_Subject) {
37 fptr_subjectNotify notify; 37 fptr_subjectNotify notify;
38 }; 38 };
39 39
40 -void TR_subjectAttach(void *, void *);  
41 -void TR_subjectDetach(void *, void *);  
42 -void TR_subjectNotify(void *); 40 +/**
  41 + * Attach an observer to a subject. After a successfull
  42 + * call to this the subject will inform the observer about events.
  43 + */
  44 +inline
  45 +void
  46 +TR_subjectAttach(void * subject, void * observer)
  47 +{
  48 + TR_CALL(subject, TR_Subject, attach, observer);
  49 +}
  50 +
  51 +/**
  52 + * Detach an Observer from a Subject. After this no events
  53 + * will be propagated from the subject to the observer anymore.
  54 + */
  55 +inline
  56 +void
  57 +TR_subjectDetach(void * subject, void * observer)
  58 +{
  59 + TR_CALL(subject, TR_Subject, detach, observer);
  60 +}
  61 +
  62 +/**
  63 + * Trigger the a notification of all attached observers.
  64 + */
  65 +inline
  66 +void
  67 +TR_subjectNotify(void * subject)
  68 +{
  69 + TR_CALL(subject, TR_Subject, notify);
  70 +}
43 71
44 #endif // __SUBJECT_H__ 72 #endif // __SUBJECT_H__
45 73
@@ -29,17 +29,6 @@ @@ -29,17 +29,6 @@
29 */ 29 */
30 TR_CREATE_INTERFACE(TR_Indexable, 1); 30 TR_CREATE_INTERFACE(TR_Indexable, 1);
31 31
32 -/**  
33 - * Get it's index from an indexable object.  
34 - */  
35 -void *  
36 -TR_getIndex(void * indexable)  
37 -{  
38 - void * ret;  
39 -  
40 - TR_RETCALL(indexable, TR_Indexable, index, ret);  
41 -  
42 - return ret;  
43 -} 32 +extern inline void * TR_getIndex(void *);
44 33
45 // vim: set ts=4 sw=4: 34 // vim: set ts=4 sw=4:
@@ -29,14 +29,9 @@ @@ -29,14 +29,9 @@
29 TR_CREATE_INTERFACE(TR_Observer, 1); 29 TR_CREATE_INTERFACE(TR_Observer, 1);
30 30
31 /** 31 /**
32 - * The implementation of update will be called by a  
33 - * subject whenever it ments to inform the observer about  
34 - * something 32 + * This will be called on each registered observer if the subject
  33 + * needs to notify them.
35 */ 34 */
36 -void  
37 -TR_observerUpdate(void * observer, void * subject)  
38 -{  
39 - TR_CALL(observer, TR_Observer, update, subject);  
40 -} 35 +extern inline void TR_observerUpdate(void *, void *);
41 36
42 // vim: set ts=4 sw=4: 37 // vim: set ts=4 sw=4:
@@ -28,39 +28,7 @@ @@ -28,39 +28,7 @@
28 */ 28 */
29 TR_CREATE_INTERFACE(TR_Serializable, 2); 29 TR_CREATE_INTERFACE(TR_Serializable, 2);
30 30
31 -  
32 -/**  
33 - * Serialize the given instance to a byte array  
34 - */  
35 -void  
36 -TR_serialize(  
37 - void * serializable,  
38 - unsigned char ** serialized,  
39 - size_t * nserialized)  
40 -{  
41 - TR_CALL(  
42 - serializable,  
43 - TR_Serializable,  
44 - serialize,  
45 - serialized,  
46 - nserialized);  
47 -}  
48 -  
49 -/**  
50 - * Unerialize the given instance to a byte array  
51 - */  
52 -void  
53 -TR_unserialize(  
54 - void * serializable,  
55 - const unsigned char * serialized,  
56 - size_t nserialized)  
57 -{  
58 - TR_CALL(  
59 - serializable,  
60 - TR_Serializable,  
61 - unserialize,  
62 - serialized,  
63 - nserialized);  
64 -} 31 +extern inline void TR_serialize(void *, unsigned char **, size_t *);
  32 +extern inline void TR_unserialize(void *, const unsigned char *, size_t);
65 33
66 // vim: set ts=4 sw=4: 34 // vim: set ts=4 sw=4:
@@ -28,34 +28,8 @@ @@ -28,34 +28,8 @@
28 */ 28 */
29 TR_CREATE_INTERFACE(TR_Subject, 3); 29 TR_CREATE_INTERFACE(TR_Subject, 3);
30 30
31 -  
32 -/**  
33 - * Attach an observer to a subject. After a successfull  
34 - * call to this the subject will inform the observer about events.  
35 - */  
36 -void  
37 -TR_subjectAttach(void * subject, void * observer)  
38 -{  
39 - TR_CALL(subject, TR_Subject, attach, observer);  
40 -}  
41 -  
42 -/**  
43 - * Detach an Observer from a Subject. After this no events  
44 - * will be propagated from the subject to the observer anymore.  
45 - */  
46 -void  
47 -TR_subjectDetach(void * subject, void * observer)  
48 -{  
49 - TR_CALL(subject, TR_Subject, detach, observer);  
50 -}  
51 -  
52 -/**  
53 - * Trigger the a notification of all attached observers.  
54 - */  
55 -void  
56 -TR_subjectNotify(void * subject)  
57 -{  
58 - TR_CALL(subject, TR_Subject, notify);  
59 -} 31 +extern inline void TR_subjectAttach(void *, void *);
  32 +extern inline void TR_subjectDetach(void *, void *);
  33 +extern inline void TR_subjectNotify(void *);
60 34
61 // vim: set ts=4 sw=4: 35 // vim: set ts=4 sw=4:
Please register or login to post a comment