Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2@file 

3@brief defines custom types 

4""" 

5 

6 

7class long: 

8 

9 """ 

10 Defines the long type as int. 

11 """ 

12 

13 def __init__(self, v): 

14 self._v = int(v) 

15 

16 def __mul__(self, y): 

17 return long(self._v * y._v) 

18 

19 def __add__(self, y): 

20 return long(self._v + y._v) 

21 

22 def __sub__(self, y): 

23 return long(self._v - y._v) 

24 

25 def __div__(self, y): 

26 return long(self._v / y._v) 

27 

28 def __str__(self): 

29 return "%d" % self._v 

30 

31 def __int__(self): 

32 return self._v 

33 

34 def __float__(self): 

35 return float(self._v) 

36 

37 

38class NA: 

39 

40 """ 

41 Defines the missing type. 

42 """ 

43 

44 def __init__(self): 

45 pass 

46 

47 def __mul__(self, y): 

48 return NA() 

49 

50 def __add__(self, y): 

51 return NA() 

52 

53 def __sub__(self, y): 

54 return NA() 

55 

56 def __div__(self, y): 

57 return NA() 

58 

59 

60class EmptyGroup: 

61 

62 """ 

63 defines an empty group 

64 """ 

65 

66 def __init__(self): 

67 pass 

68 

69 

70class NoSortClass: 

71 

72 """ 

73 Container which overloads the sort operator to return 0 all the times. 

74 """ 

75 

76 def __init__(self, value): 

77 """ 

78 any value 

79 """ 

80 self.value = value 

81 

82 def __lt__(self, o): 

83 """ 

84 operator __lt__ 

85 """ 

86 return -1 

87 

88 def __str__(self): 

89 """ 

90 usual 

91 """ 

92 return "NSC:{0}".format(str(self.value)) 

93 

94 

95class GroupByContainer (list): 

96 

97 """ 

98 to differiate between a list and a list introduced by a groupby 

99 """ 

100 pass