1#==========================================================================
2#
3#   Copyright Insight Software Consortium
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#          http://www.apache.org/licenses/LICENSE-2.0.txt
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16#
17#==========================================================================*/
18
19
20class itkCType:
21    __cTypes__ = {}
22
23    def __init__(self, name, shortName):
24        self.name = name
25        self.short_name = shortName
26
27        itkCType.__cTypes__[self.name] = self
28
29    def __del__(self):
30        try:
31            del itkCType.__cTypes__[self.name]
32        except:
33            pass
34
35    def __repr__(self):
36        return "<itkCType %s>" % self.name
37
38    def GetCType(name):
39        aliases = {'short': 'signed short',
40            'int': 'signed int',
41            'long': 'signed long',
42            'long long': 'signed long long'}
43        if name in aliases:
44            name = aliases[name]
45        try:
46            return(itkCType.__cTypes__[name])
47        except KeyError:
48            return(None)
49    GetCType = staticmethod(GetCType)
50
51
52F = itkCType("float", "F")
53D = itkCType("double", "D")
54LD = itkCType("long double", "LD")
55UC = itkCType("unsigned char", "UC")
56US = itkCType("unsigned short", "US")
57UI = itkCType("unsigned int", "UI")
58UL = itkCType("unsigned long", "UL")
59ULL = itkCType("unsigned long long", "ULL")
60SC = itkCType("signed char", "SC")
61SS = itkCType("signed short", "SS")
62SI = itkCType("signed int", "SI")
63SL = itkCType("signed long", "SL")
64SLL = itkCType("signed long long", "SLL")
65B = itkCType("bool", "B")
66