Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. // AppDelegate.h/cpp - Generated by Cocoa app wizard
  2.  
  3. //
  4. // AppDelegate.h
  5. // helper
  6. //
  7. // Created by Hariharan Mahadevan on 2019/9/25.
  8. // Copyright © 2019 smallpearl. All rights reserved.
  9. //
  10. // Important:
  11. // By default XCode wizard generates AppDelegate.h as 'Objective-C Header'.
  12. // This has to be changed to 'Objective-C++ Header' in the File Inspector.
  13.  
  14. #include <string>
  15. #include <memory>
  16.  
  17. #import <Cocoa/Cocoa.h>
  18.  
  19. // A dummy C++ objects to illustrate their creation/destruction from
  20. // Objective-C code.
  21. struct DummyObject {
  22. char buf[1000];
  23. };
  24.  
  25. struct HelperApp {
  26. std::string _name; // should also involve memory alloc/dealloc
  27. // Use unique_ptr to test memory alloc/dealloc
  28. std::unique_ptr<DummyObject> _dummy;
  29.  
  30. HelperApp();
  31. virtual ~HelperApp();
  32. };
  33.  
  34. @interface AppDelegate : NSObject <NSApplicationDelegate>
  35. {
  36. HelperApp* _helperApp;
  37. }
  38. @end
  39.  
  40. // AppDelegate.cpp
  41.  
  42. //
  43. // AppDelegate.cpp
  44. // helper
  45. //
  46. // Created by Hariharan Mahadevan on 2019/9/25.
  47. // Copyright © 2019 smallpearl. All rights reserved.
  48. //
  49. // Important:
  50. // By default XCode wizard generates AppDelegate.m. This file has to be renamed to
  51. // AppDelegate.cpp and the file type has to be changed from 'Objective-C Source'
  52. // to 'Objective-C++ Source' in the File Inspector.
  53.  
  54. #import "AppDelegate.h"
  55.  
  56. HelperApp::HelperApp()
  57. : _name("HelperApp"), _dummy(new DummyObject)
  58. {
  59. NSLog(@"Helper::Helper");
  60. }
  61.  
  62. HelperApp::~HelperApp()
  63. {
  64. NSLog(@"Helper::~Helper");
  65. }
  66.  
  67. @interface AppDelegate ()
  68.  
  69. @property (weak) IBOutlet NSWindow *window;
  70. @end
  71.  
  72. @implementation AppDelegate
  73.  
  74. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  75. // Insert code here to initialize your application
  76. _helperApp = new HelperApp();
  77. }
  78.  
  79.  
  80. - (void)applicationWillTerminate:(NSNotification *)aNotification {
  81. // Insert code here to tear down your application
  82. delete _helperApp;
  83. }
  84. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement