/Tools/bgen/bgen/bgenStringBuffer.py

http://unladen-swallow.googlecode.com/ · Python · 67 lines · 51 code · 5 blank · 11 comment · 0 complexity · 9b39154130428381c912f69a5b7c80d3 MD5 · raw file

  1. """Buffers used to hold null-terminated strings."""
  2. from bgenBuffer import FixedOutputBufferType
  3. from bgenStackBuffer import StackOutputBufferType
  4. from bgenHeapBuffer import HeapOutputBufferType
  5. class StringBufferMixIn:
  6. """Mix-in class to create various string buffer types.
  7. Strings are character arrays terminated by a null byte.
  8. (For input, this is also covered by stringptr.)
  9. For output, there are again three variants:
  10. - Fixed: size is a constant given in the documentation; or
  11. - Stack: size is passed to the C function but we decide on a size at
  12. code generation time so we can still allocate on the heap); or
  13. - Heap: size is passed to the C function and we let the Python caller
  14. pass a size.
  15. (Note that this doesn't cover output parameters in which a string
  16. pointer is returned. These are actually easier (no allocation) but far
  17. less common. I'll write the classes when there is demand.)
  18. """
  19. def getSizeDeclarations(self, name):
  20. return []
  21. def getAuxDeclarations(self, name):
  22. return []
  23. def getargsFormat(self):
  24. return "s"
  25. def getargsArgs(self, name):
  26. return "&%s__in__" % name
  27. def mkvalueFormat(self):
  28. return "s"
  29. def mkvalueArgs(self, name):
  30. return "%s__out__" % name
  31. class FixedOutputStringType(StringBufferMixIn, FixedOutputBufferType):
  32. """Null-terminated output string -- passed without size.
  33. Instantiate with buffer size as parameter.
  34. """
  35. class StackOutputStringType(StringBufferMixIn, StackOutputBufferType):
  36. """Null-terminated output string -- passed as (buffer, size).
  37. Instantiate with buffer size as parameter.
  38. """
  39. class HeapOutputStringType(StringBufferMixIn, HeapOutputBufferType):
  40. """Null-terminated output string -- passed as (buffer, size).
  41. Instantiate without parameters.
  42. Call from Python with buffer size.
  43. """