Browse Source

Inline simple accessor functions

1.0.2
Georg Hopp 10 years ago
parent
commit
1084820a8a
  1. 12
      include/tr/interface/indexable.h
  2. 12
      include/tr/interface/observer.h
  3. 32
      include/tr/interface/serializable.h
  4. 34
      include/tr/interface/subject.h
  5. 13
      src/i_indexable.c
  6. 11
      src/i_observer.c
  7. 36
      src/i_serializable.c
  8. 32
      src/i_subject.c

12
include/tr/interface/indexable.h

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

12
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__

32
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__

34
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__

13
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:

11
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:

36
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:

32
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:
Loading…
Cancel
Save