summaryrefslogtreecommitdiff
path: root/Tools/bgen/bgen/bgenStringBuffer.py
blob: 39c8cf9d0cdc1e005df092c7b7426bc993e2fa26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Buffers used to hold null-terminated strings."""


from bgenBuffer import FixedOutputBufferType
from bgenStackBuffer import StackOutputBufferType
from bgenHeapBuffer import HeapOutputBufferType


class StringBufferMixIn:

    """Mix-in class to create various string buffer types.

    Strings are character arrays terminated by a null byte.
    (For input, this is also covered by stringptr.)
    For output, there are again three variants:
    - Fixed: size is a constant given in the documentation; or
    - Stack: size is passed to the C function but we decide on a size at
      code generation time so we can still allocate on the heap); or
    - Heap: size is passed to the C function and we let the Python caller
      pass a size.
    (Note that this doesn't cover output parameters in which a string
    pointer is returned.  These are actually easier (no allocation) but far
    less common.  I'll write the classes when there is demand.)
    """
    
    def declareSize(self, name):
        pass
    
    def getargsFormat(self):
        return "s"
    
    def getargsArgs(self, name):
        return "&%s__in__" % name

    def mkvalueFormat(self):
        return "s"

    def mkvalueArgs(self, name):
        return "%s__out__" % name


class FixedOutputStringType(StringBufferMixIn, FixedOutputBufferType):

    """Null-terminated output string -- passed without size.

    Instantiate with buffer size as parameter.
    """


class StackOutputStringType(StringBufferMixIn, StackOutputBufferType):

    """Null-terminated output string -- passed as (buffer, size).

    Instantiate with buffer size as parameter.
    """


class HeapOutputStringType(StringBufferMixIn, HeapOutputBufferType):

    """Null-terminated output string -- passed as (buffer, size).

    Instantiate without parameters.
    Call from Python with buffer size.
    """