PageRenderTime 35ms CodeModel.GetById 31ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Tools/bgen/bgen/bgenStringBuffer.py

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