00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import string
00018 import OpenRTM
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 class NumberingPolicy:
00038 """
00039 """
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 class ObjectNotFound:
00050 pass
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 def onCreate(self, obj):
00070 pass
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 def onDelete(self, obj):
00088 pass
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 class DefaultNumberingPolicy(NumberingPolicy):
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 def __init__(self):
00125 self._num = 0
00126 self._objects = []
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 def onCreate(self, obj):
00146 self._num += 1
00147
00148 pos = 0
00149 try:
00150 pos = self.find(None)
00151 self._objects[pos] = obj
00152 return OpenRTM.otos(pos)
00153 except NumberingPolicy.ObjectNotFound:
00154 self._objects.append(obj)
00155 return OpenRTM.otos(int(len(self._objects) - 1))
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 def onDelete(self, obj):
00173 pos = 0
00174 pos = self.find(obj)
00175 if (pos < len(self._objects)):
00176 self._objects[pos] = None
00177 self._num -= 1
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 def find(self, obj):
00197 i = 0
00198 for obj_ in self._objects:
00199 if obj_ == obj:
00200 return i
00201 i += 1
00202 raise NumberingPolicy.ObjectNotFound()
00203
00204