Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. from mako.template import Template
  2.  
  3. TEMPLATE_H = """
  4. % for binding in bindings:
  5.  
  6. class ${binding.name}_Wrapper
  7. {
  8. private:
  9. ${binding.type} val;
  10.  
  11. public:
  12. ${binding.name}() {}
  13.  
  14. % for prop in binding.getters:
  15. float Get${prop.capitalize()}();
  16. % endfor
  17. };
  18.  
  19. % endfor
  20.  
  21. """
  22.  
  23. TEMPLATE_CPP = """
  24. % for binding in bindings:
  25.  
  26. % for prop in binding.getters:
  27. float ${binding.name}_Wrapper::Get${prop.capitalize()}()
  28. {
  29. return val.${prop.capitalize()};
  30. }
  31.  
  32. % endfor
  33.  
  34. % endfor
  35.  
  36. """
  37.  
  38. class Binding:
  39. def __init__(self, name, type, getters):
  40. self.name = name
  41. self.type = type
  42. self.getters = getters
  43.  
  44.  
  45. if __name__ == '__main__':
  46. bindings = [
  47. Binding("Vector", "FVector", ["x", "y", "z"]),
  48. Binding("Vector2D", "FVector2D", ["x", "y"]),
  49. ]
  50.  
  51. header = Template(TEMPLATE_H).render(bindings=bindings)
  52. cpp = Template(TEMPLATE_CPP).render(bindings=bindings)
  53.  
  54. print("=== Wrapper.h ===")
  55. print(header)
  56.  
  57. print("=== Wrapper.cpp ===")
  58. print(cpp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement