ifa.h 729 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef ifa_H_INCLUDED
  2. #define ifa_H_INCLUDED
  3. /** Ifa contains functionality to emulate go language style interfaces in C. */
  4. #define INTERFACE_BODY() \
  5. void * self;
  6. #define INTERFACE(NAME) \
  7. struct name
  8. #define INTERFACE_SELF(IFA) ((IFA)->self)
  9. #define INTERFACE_INIT(IFA, SELF) do { ((IFA)->self) = SELF; } while(0)
  10. typedef struct Ifa_ Ifa;
  11. typedef struct Metab_ Metab;
  12. struct Metab_ {
  13. void * (*free)(void * ptr);
  14. void * (*done)(void * ptr);
  15. };
  16. struct Ifa_ {
  17. void * data;
  18. struct Metab * methods;
  19. };
  20. /** Ref is a reference counted wrapper around arbitrary data pointer, */
  21. struct Ref_ {
  22. struct Inter_ * inter;
  23. int refcount;
  24. };
  25. #endif