root/branches/Carsten_PtrWork2/Tools/convScript/OperationRegistry.py

Revision 151, 1.6 kB (checked in by cneumann, 2 years ago)

added: script for mechanical code conversions

Line 
1 class OperationRegistry:
2     """ Registry of available operations.
3     """
4    
5     #### member
6     #  regOpMap  -- map opName to opInstance
7     
8     # list of registered operations
9     regOpMap = {};
10      
11     # adds an operation to the system
12     @staticmethod
13     def registerOp(opInstance):
14         #print "OperationRegistry.registerOp(%s)" % opInstance.getName();
15         
16         opName = opInstance.getName();
17         if not OperationRegistry.regOpMap.has_key(opName):
18             OperationRegistry.regOpMap[opName] = opInstance;
19    
20     # removes an operation from the system
21     @staticmethod
22     def unregisterOp(opInstance):
23         #print "OperationRegistry.unregisterOp(%s)" % opInstance.getName();
24         
25         opName = opInstance.getName();
26         if OperationRegistry.regOpMap.has_key(opName):
27             OperationRegistry.regOpMap.pop(opName);
28    
29     # get operation instance with given name
30     @staticmethod
31     def getRegisteredOp(opName):
32         #print "OperationRegistry.getRegisteredOp(%s)" % opName;
33         
34         if OperationRegistry.regOpMap.has_key(opName):
35             return OperationRegistry.regOpMap[opName];
36        
37         return None;
38    
39     # get list of registered operations
40     @staticmethod
41     def getRegisteredOpList():
42         return OperationRegistry.regOpMap.values();
43
44 def registerOperation(opInstance, group = None):
45     """ Helper for operation registration, if group is not None, the operation
46         opInstance is also added to the given group.
47     """
48     OperationRegistry.registerOp(opInstance);
49     if group != None:
50         group.addOp(opInstance.getName());
Note: See TracBrowser for help on using the browser.