Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.78 KB | None | 0 0
  1. // Defines a signature made of an abstracttype
  2. // and a function using this type.
  3. signature Factory {
  4.     alias Type;
  5.     Type create();
  6. }
  7.  
  8. // Extends the Factory signature
  9. signature RoomFactory : Factory {
  10.     void setSize(vec2 size);
  11. }
  12.  
  13. // A Test type, used as Factory.Type
  14. struct Room {
  15.     vec2 size;
  16. }
  17.  
  18. // An aggregate compliant with the extended factory
  19. struct MyRoomFactory {
  20.     alias Type=Room*;
  21.  
  22.     vec2 size_;
  23.     void setSize(vec2 size) { size_ = size; }
  24.     Room* create() { return new Room(size_); }
  25. }
  26.  
  27. void main() {
  28.     MyRoomFactory factory = ...;
  29.     setSize(factory);
  30. }
  31.  
  32. void setSize(IFactory : MyRoomFactory)(scope ref IFactory factory) {
  33.     factory.setSize(...);
  34. }
  35.  
  36. void myFunc(IFactory : Factory)(scope ref IFactory factory) {
  37.     IFactory.Type myRoom = factory.create();
  38.     ...
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement