| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (C) 2013 Google Inc. All rights reserved. | 2 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 class EventFactoryWriter(name_macros.Writer): | 58 class EventFactoryWriter(name_macros.Writer): |
| 59 defaults = { | 59 defaults = { |
| 60 'interfaceName' : None, | 60 'interfaceName' : None, |
| 61 'conditional' : None, | 61 'conditional' : None, |
| 62 'runtimeConditional': None, | 62 'runtimeConditional': None, |
| 63 } | 63 } |
| 64 default_parameters = { | 64 default_parameters = { |
| 65 'namespace': '', | 65 'namespace': '', |
| 66 } | 66 } |
| 67 | 67 |
| 68 def __init__(self, in_file_path, enabled_conditions): |
| 69 super(EventFactoryWriter, self).__init__(in_file_path, enabled_condition
s) |
| 70 self._outputs[(self.class_name + ".cpp")] = self.generate_implementation |
| 71 |
| 68 def _events(self): | 72 def _events(self): |
| 69 return self.in_file.name_dictionaries | 73 return self.in_file.name_dictionaries |
| 70 | 74 |
| 71 def _factory_implementation(self, event): | 75 def _factory_implementation(self, event): |
| 72 runtime_condition = '' | 76 runtime_condition = '' |
| 73 if event['runtimeConditional']: | 77 if event['runtimeConditional']: |
| 74 runtime_condition = ' && RuntimeEnabledFeatures::' + event['runtimeC
onditional'] + '()' | 78 runtime_condition = ' && RuntimeEnabledFeatures::' + event['runtimeC
onditional'] + '()' |
| 75 name = os.path.basename(event['name']) | 79 name = os.path.basename(event['name']) |
| 76 interface_name = event['interfaceName'] if event['interfaceName'] else n
ame | 80 interface_name = event['interfaceName'] if event['interfaceName'] else n
ame |
| 77 implementation = """ if (type == "%(name)s"%(runtime_condition)s) | 81 implementation = """ if (type == "%(name)s"%(runtime_condition)s) |
| 78 return %(interface_name)s::create();""" % { | 82 return %(interface_name)s::create();""" % { |
| 79 'name': name, | 83 'name': name, |
| 80 'runtime_condition': runtime_condition, | 84 'runtime_condition': runtime_condition, |
| 81 'interface_name': interface_name, | 85 'interface_name': interface_name, |
| 82 } | 86 } |
| 83 return self.wrap_with_condition(implementation, event['conditional']) | 87 return self.wrap_with_condition(implementation, event['conditional']) |
| 84 | 88 |
| 85 def generate_implementation(self): | 89 def generate_implementation(self): |
| 86 return IMPLEMENTATION_TEMPLATE % { | 90 return IMPLEMENTATION_TEMPLATE % { |
| 87 'class_name': self.class_name, | 91 'class_name': self.class_name, |
| 88 'license': license.license_for_generated_cpp(), | 92 'license': license.license_for_generated_cpp(), |
| 89 'factory_implementation': "\n".join(map(self._factory_implementation
, self._events())), | 93 'factory_implementation': "\n".join(map(self._factory_implementation
, self._events())), |
| 90 } | 94 } |
| 91 | 95 |
| 92 | 96 |
| 93 if __name__ == "__main__": | 97 if __name__ == "__main__": |
| 94 name_macros.Maker(EventFactoryWriter).main(sys.argv) | 98 name_macros.Maker(EventFactoryWriter).main(sys.argv) |
| OLD | NEW |