File: base_spec.py

package info (click to toggle)
python-scipy 0.18.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 75,464 kB
  • ctags: 79,406
  • sloc: python: 143,495; cpp: 89,357; fortran: 81,650; ansic: 79,778; makefile: 364; sh: 265
file content (120 lines) | stat: -rw-r--r-- 3,516 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from __future__ import absolute_import, print_function


class base_converter(object):
    """
        Properties:
        headers --  list of strings that name the header files needed by this
                    object.
        include_dirs -- list of directories where the header files can be found.
        libraries   -- list of libraries needed to link to when compiling
                       extension.
        library_dirs -- list of directories to search for libraries.

        support_code -- list of strings.  Each string is a subroutine needed
                        by the type.  Functions that are used in the conversion
                        between Python and C++ files are examples of these.

        Methods:

        type_match(value) returns 1 if this class is used to represent type
                          specification for value.
        type_spec(name, value)  returns a new object (of this class) that is
                                used to produce C++ code for value.
        declaration_code()    returns C++ code fragment for type declaration and
                              conversion of python object to C++ object.
        cleanup_code()    returns C++ code fragment for cleaning up after the
                          variable after main C++ code fragment has executed.

    """
    _build_information = []
    compiler = ''

    def set_compiler(self,compiler):
        self.compiler = compiler

    def type_match(self,value):
        raise NotImplementedError("You must override method in derived class")

    def build_information(self):
        return self._build_information

    def type_spec(self,name,value):
        pass

    def declaration_code(self,templatize=0):
        return ""

    def local_dict_code(self):
        return ""

    def cleanup_code(self):
        return ""

    def retrieve_py_variable(self,inline=0):
        # this needs a little coordination in name choices with the
        # ext_inline_function class.
        if inline:
            vn = 'get_variable("%s",raw_locals,raw_globals)' % self.name
        else:
            vn = 'py_' + self.name
        return vn

    def py_reference(self):
        return "&py_" + self.name

    def py_pointer(self):
        return "*py_" + self.name

    def py_variable(self):
        return "py_" + self.name

    def reference(self):
        return "&" + self.name

    def pointer(self):
        return "*" + self.name

    def init_flag(self):
        return self.name + "_used"

    def variable(self):
        return self.name

    def variable_as_string(self):
        return '"' + self.name + '"'

import UserList
from . import base_info


class arg_spec_list(UserList.UserList):
    def build_information(self):
        all_info = base_info.info_list()
        for i in self:
            all_info.extend(i.build_information())
        return all_info

    def py_references(self):
        return map(lambda x: x.py_reference(),self)

    def py_pointers(self):
        return map(lambda x: x.py_pointer(),self)

    def py_variables(self):
        return map(lambda x: x.py_variable(),self)

    def references(self):
        return map(lambda x: x.py_reference(),self)

    def pointers(self):
        return map(lambda x: x.pointer(),self)

    def variables(self):
        return map(lambda x: x.variable(),self)

    def init_flags(self):
        return map(lambda x: x.init_flag(),self)

    def variable_as_strings(self):
        return map(lambda x: x.variable_as_string(),self)