home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / boopsi / dragclass / classer / 2.tplt next >
Text File  |  1977-12-31  |  21KB  |  877 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. // $VER: Class.C.tplt 1.10 (18-06-94) (c) by Bernd "0" Noll
  4. //
  5. //  A skeleton to build easy and fast prototypes of small
  6. //  BOOPSI-Klassen for test purposes.
  7. //
  8. // History:
  9. //  11.05.94 1.7
  10. //  23.05.94 1.8  added OM_*MEMBER
  11. //  29-05-94 1.9  OBJ_??IT <-> OM_NEW/DISPOSE
  12. //  18-06-94 1.10 added TRACKING
  13. //
  14. // Anmerkung:
  15. //  Die folgende Auflistung erhebt weder Anspruch auf Vollstaendigkeit
  16. //  noch auf Richtigkeit! Die vordefinierten Bezeichner sind noch nicht
  17. //  vollstaendig durchdacht, daher kann ich nur eine vorlaeufige Liste
  18. //  angeben, die (leider) nicht mit jeder Aenderung des Templates
  19. //  aktualisiert wurde ...
  20. //
  21. // es ist eine reihe von Begriffen vordefiniert:
  22. //  SUPER   - gibt die aktuellen parameter an die Superclass weiter
  23. //  inst    - ist ein Zeiger auf die aktuelle Instanzenstruktur
  24. //  o        - ist das aktuelle Objekt
  25. //  cl        - ist die Klasse
  26. //  msg     - ist die aktuelle Nachricht
  27. //  val     - bei ISUN ti_Data des aktuellen attrs; bei G destination
  28. // beim testen:
  29. //  my_win  - Window
  30. //  $(CLASS)_class - Class
  31. //  my_gad  - 1.Object
  32. //  im        - IntuiMessage
  33. //  done    - !running
  34. //
  35. ////////////////////////////////////////////////////////////
  36. //
  37. //  Use the following line to rearrange the "#line"
  38. //  directives found in this file, if You made any
  39. //  change (the commands are XDME-syntax; if You might
  40. //  use another editor (...) these commands are likely
  41. //  to not work with it, else just call "col 3 eval $restofline"):
  42. //
  43. // ping 1 first find (#line) unfail (100 (next down getlineno xx up wright while ca del writevar xx)) pong 1
  44. //
  45. ////////////////////////////////////////////////////////////
  46. #line 47 "Class.C.tplt"
  47.  
  48.  
  49. // needed for testing ...
  50. #include <stdlib.h>
  51. #include <stdio.h>
  52.  
  53. /* STANDARD INCLUDES */
  54. #include <exec/types.h>
  55. #include <exec/ports.h>
  56. #include <exec/libraries.h>
  57. #include <exec/execbase.h>
  58. #include <intuition/intuitionbase.h>
  59. #include <intuition/cghooks.h>
  60. #include <intuition/classusr.h>
  61. #include <intuition/classes.h>
  62. #include <intuition/intuitionbase.h>
  63. //#include "classnames.h"
  64.  
  65. #if $(HAS_TRACKING)
  66. #include <support/AUTO.h>
  67. #define DisposeObject(o)  DoMethod(o, OM_DISPOSE);
  68. #define RemoveObject(o)   DoMethod(o, OM_REMOVE);
  69. #define AppendObject(o,l) DoMethod(o, OM_ADDTAIL, l);
  70. #endif
  71.  
  72.  
  73. /* INCLUDES */
  74. $(INCLUDES)
  75. #line 76 "Class.C.tplt"
  76.  
  77.  
  78. /* LIBRARY PROTOS */
  79. #ifndef   CLIB_EXEC_PROTOS_H
  80. #include <clib/exec_protos.h>
  81. #endif
  82. #ifndef   CLIB_INTUITION_PROTOS_H
  83. #include <clib/intuition_protos.h>
  84. #endif
  85. #ifndef   CLIB_UTILITY_PROTOS_H
  86. #include <clib/utility_protos.h>
  87. #endif
  88. #ifndef   CLIB_ALIB_PROTOS_H
  89. #include <clib/alib_protos.h>
  90. #endif
  91. $(LIB_PROTOS)
  92. #line 93 "Class.C.tplt"
  93.  
  94.  
  95. /* PRIVATE INCLUDES */
  96. $(PRIVATE_INCLUDES)
  97. #line 98 "Class.C.tplt"
  98.  
  99. #ifndef SIGBREAKF_CTRL_C
  100. #define SIGBREAKF_CTRL_C   (1<<12)
  101. #endif
  102.  
  103.  
  104. /* LIBRARY BASE DECLARATIONS */
  105. extern struct IntuitionBase *IntuitionBase;
  106. extern struct SysBase        *SysBase;
  107. $(LIB_EXTERNS)
  108. #line 109 "Class.C.tplt"
  109.  
  110. /* LIBRARY PRAGMAS */
  111. #ifdef PRAGMAS
  112. #include <pragmas/exec_pragmas.h>
  113. #include <pragmas/intuition_pragmas.h>
  114. #include <pragmas/alib_pragmas.h>
  115. $(LIB_PRAGMAS)
  116. #line 117 "Class.C.tplt"
  117. #endif
  118.  
  119.  
  120. #ifdef    _DCC
  121. #define  PRE_A4 __geta4
  122. #define POST_A4
  123. #define __A0(x) __A0 x
  124. #define __A1(x) __A1 x
  125. #define __A2(x) __A2 x
  126. #endif
  127. #ifdef __SASC
  128. #define  PRE_A4 __saveds __asm
  129. #define POST_A4
  130. #define __A0(x) register __a0 x
  131. #define __A1(x) register __a1 x
  132. #define __A2(x) register __a2 x
  133. #endif
  134. #ifdef __GNUC__
  135. #error "Dieses Modul ist im Augenblick nicht mit GCC kompilierbar"
  136. #define  PRE_A4
  137. #define POST_A4
  138. #define __A0 register x asm("a0")
  139. #define __A1 register x asm("a1")
  140. #define __A2 register x asm("a2")
  141. #endif
  142. #ifndef PRE_A4
  143. #error "Unknown Compiler!"
  144. #endif
  145.  
  146.  
  147. #define SUPER  DoSuperMethodA(cl, o, (Msg)msg)
  148. #define GADOB  ((struct Gadget *)o)
  149. #define OB     o
  150. #define INST   inst
  151. #define _CLASS $(CLASS)
  152.  
  153. // Es waere wuenschenswert, diese Dummies
  154. // veraendern zu koennen ... nur wie ????
  155. #define DUMMY_A ($(FIRST_ATTR_NUM))
  156. #define DUMMY_M ($(FIRST_METH_NUM))
  157.  
  158. ////////////////////////////////////////////////////
  159. //
  160. //  Defines, Attributes, Methods and Messages;
  161. //  these Information should be put into an extern
  162. //  Heraderfile for bigger projects
  163. //
  164. ////////////////////////////////////////////////////
  165.  
  166. /* DEFINES */
  167. $(DEFINES)
  168. #line 169 "Class.C.tplt"
  169.  
  170. /* ATTRIBUTES */
  171. $(ATTRIBUTES)
  172. #line 173 "Class.C.tplt"
  173.  
  174. /* METHODS */
  175. $(METHODS)
  176. #line 177 "Class.C.tplt"
  177.  
  178. /* MESSAGES */
  179. $(MESSAGES)
  180. #line 181 "Class.C.tplt"
  181.  
  182. /* STRUCTURES */
  183. $(STRUCTURES)
  184. #line 185 "Class.C.tplt"
  185.  
  186. ////////////////////////////////////////////////////
  187. //
  188. //  Following Struct defines the internal Data
  189. //  of each instance
  190. //
  191. //  Anm. these Information is normally privat and
  192. //     thus should not be put into a headerfile
  193. //
  194. ////////////////////////////////////////////////////
  195.  
  196. /* PRIVATE DEFINES */
  197. $(PRIVATE_DEFINES)
  198. #line 199 "Class.C.tplt"
  199.  
  200. #ifdef MYDEBUG
  201. #include <debug.h>
  202. #else
  203. #define DQ(x)
  204. #define D(x)
  205. #define DD(x)
  206. #endif
  207.  
  208.  
  209. /* CONTENTS */
  210. struct $(CLASS) {
  211. $(CONTENTS)
  212. #line 213 "Class.C.tplt"
  213. #if $(HAS_TRACKING)
  214.     struct Object *__Self;
  215. #endif
  216. }; /* $(CLASS) */
  217.  
  218. /* SUPPORT */
  219. $(SUPPORT)
  220. #line 221 "Class.C.tplt"
  221.  
  222. ////////////////////////////////////////////////////
  223. //
  224. //  Following is the Class-dispatcher
  225. //  and its sub functions
  226. //
  227. ////////////////////////////////////////////////////
  228. //
  229. //  RootClass-Support:
  230. //
  231. //  Es sind bereits Gerueste definiert fuer die
  232. //  Methoden OM_DISPOSE, OM_NEW, OM_SET, OM_GET
  233. //  OM_NOTIFY, OM_UPDATE, und OM_*MEBER die verwendet
  234. //  werden, sobald ein Attribut mit dem Vermerk
  235. //  I,S,G,N,U verwendet wird, oder den Schluesselworten
  236. //  OM_NEW/OM_DISPOSE C-source folgt, oder das
  237. //  Schluesselwort LIST auftaucht.
  238. //
  239. //  Anm.: Von der Verwendung der U/N-Attribute
  240. //      sollten abgesehen werden, es handelt sich
  241. //      zur Zeit bei ihren Implementationen um
  242. //      blosse Kopien der OM_SET-Implementation
  243. //
  244. //  Jede Methode kann jedoch redefiniert werden;
  245. //  dabei ist dann aber zu beachten, dass die
  246. //  Automatische Einfuegung von OM_NEW/EXIT
  247. //  und ISGNU-Attributen verloren geht.
  248. //  Um sicherzugehen, dass kein vordefiniertes
  249. //  Geruest verwendet wird empfiehlt es sich
  250. //  #define NO_PREDEFINED_OM_*
  251. //  in die SUPPORT-sektion aufzunehmen.
  252. //
  253. ////////////////////////////////////////////////////
  254.  
  255.  
  256.  
  257. #if ($(HAS_OM_DISPOSE) || $(HAS_TRACKING) || ($(HAS_LIST) && !defined(NO_PREDEFINED_OM_MEMBER))) && !defined(NO_PREDEFINED_OM_DISPOSE)
  258. static ULONG method_OM_DISPOSE (Class *cl, Object *o, Msg *msg, struct $(CLASS) *inst) {
  259.  
  260. $(OM_DISPOSE)
  261. #line 262 "Class.C.tplt"
  262.  
  263. #if $(HAS_LIST) && !defined(NO_PREDEFINED_OM_MEMBER)
  264.     {
  265.     Object *member;
  266.     APTR    state;
  267.  
  268.     state = (struct MinList *)(&inst->$(LIST))->mlh_Head;
  269.     while (NULL != (member = NextObject(&state))) {
  270.         DoMethod   (member, OM_REMOVE);
  271.         DoMethodA  (member, msg);
  272.     } /* while */
  273.     }
  274. #endif
  275.  
  276. #if $(HAS_TRACKING)
  277.     Remove (&INST->$(TRACKING));
  278. #endif
  279.  
  280.     return (ULONG)SUPER;
  281. } /* method_OM_DISPOSE */
  282. #endif
  283.  
  284. #if ($(HAS_OM_NEW) || $(HAS_ATTRIBUTES_I) || $(HAS_TRACKING) || ($(HAS_LIST) && !defined(NO_PREDEFINED_OM_MEMBER))) && !defined(NO_PREDEFINED_OM_NEW)
  285. #define BEGIN_ATTRIBUTE(id) case id: {
  286. #define END_ATTRIBUTE        } break;
  287.  
  288. static ULONG method_OM_NEW (Class *cl, Object *o, struct opSet *msg, struct $(CLASS) *inst) {
  289.     // APTR trueclass = o;
  290.     struct TagItem *tstate, *ti;
  291.  
  292.     if (o = (Object *)SUPER) {
  293.     inst = INST_DATA(cl, o);
  294.     // setmem (inst, sizeof (struct $(CLASS)), 0);
  295.  
  296. $(OM_NEW)
  297. #line 298 "Class.C.tplt"
  298.  
  299. #if $(HAS_LIST) && !defined(NO_PREDEFINED_OM_MEMBER)
  300.     NewList ((struct List *)inst->$(LIST));
  301. #endif
  302. #if $(HAS_TRACKING)
  303.     AddHead (&__ObjectsList, &INST->$(TRACKING));
  304.     INST->__Self = o;
  305. #endif
  306.  
  307. #if $(HAS_ATTRIBUTES_I)
  308.     ti     = msg->ops_AttrList;
  309.     tstate = ti;
  310.     while (ti = NextTagItem(&tstate)) {
  311.         ULONG tg  = ti->ti_Tag;
  312.         ULONG val = ti->ti_Data;
  313.         switch (tg) {
  314. $(ATTRIBUTES_I)
  315. #line 316 "Class.C.tplt"
  316.         } /* switch */
  317.     } /* while */
  318. #endif
  319.     } /* if */
  320.     return (ULONG)o;
  321. } /* method_OM_NEW */
  322.  
  323. #undef    BEGIN_ATTRIBUTE
  324. #undef    END_ATTRIBUTE
  325. #endif
  326.  
  327. #if ($(HAS_OM_SET) || $(HAS_ATTRIBUTES_S)) && !defined(NO_PREDEFINED_OM_SET)
  328. #define BEGIN_ATTRIBUTE(id) case id: {
  329. #define END_ATTRIBUTE        } break;
  330.  
  331. static ULONG method_OM_SET (Class *cl, Object *o, struct opSet *msg, struct $(CLASS) *inst) {
  332.     struct TagItem *tstate, *ti;
  333.     ULONG retval;
  334.  
  335. $(OM_SET)
  336. #line 337 "Class.C.tplt"
  337.  
  338.     retval = SUPER;
  339. #if $(HAS_ATTRIBUTES_S)
  340.     ti       = msg->ops_AttrList;
  341.     tstate = ti;
  342.     while (ti = NextTagItem(&tstate)) {
  343.     ULONG tg  = ti->ti_Tag;
  344.     ULONG val = ti->ti_Data;
  345.     switch (tg) {
  346. $(ATTRIBUTES_S)
  347. #line 348 "Class.C.tplt"
  348.     } /* switch */
  349.     } /* while */
  350. #endif
  351.     return retval;
  352. } /* method_OM_SET */
  353.  
  354. #undef    BEGIN_ATTRIBUTE
  355. #undef    END_ATTRIBUTE
  356. #endif
  357.  
  358. #if $(HAS_ATTRIBUTES_G) && !defined(NO_PREDEFINED_OM_GET)
  359. #define BEGIN_ATTRIBUTE(id) case id: {
  360. #define END_ATTRIBUTE        } return TRUE;
  361. #define val *(msg->opg_Storage)
  362.  
  363. static ULONG method_OM_GET (Class *cl, Object *o, struct opGet *msg, struct $(CLASS) *inst) {
  364.     int tg;
  365.  
  366. $(OM_GET)
  367. #line 368 "Class.C.tplt"
  368.  
  369. #if $(HAS_ATTRIBUTES_G)
  370.     switch (tg = msg->opg_AttrID) {
  371. $(ATTRIBUTES_G)
  372. #line 373 "Class.C.tplt"
  373.     default: return SUPER;
  374.     } /* switch */
  375. #endif
  376.     return TRUE;
  377. } /* method_OM_GET */
  378.  
  379. #undef    val
  380. #undef    BEGIN_ATTRIBUTE
  381. #undef    END_ATTRIBUTE
  382. #endif
  383.  
  384. #if $(HAS_ATTRIBUTES_N) && !defined(NO_PREDEFINED_OM_NOTIFY)
  385. #define BEGIN_ATTRIBUTE(id) case id: {
  386. #define END_ATTRIBUTE        } break;
  387.  
  388. static ULONG method_OM_NOTIFY (Class *cl, Object *o, struct opSet *msg, struct $(CLASS) *inst) {
  389.     struct TagItem *tstate, *ti;
  390.  
  391. $(OM_NOTIFY)
  392. #line 393 "Class.C.tplt"
  393.  
  394.     SUPER;
  395.  
  396. #if $(HAS_ATTRIBUTES_N)
  397.     ti       = msg->ops_AttrList;
  398.     tstate = ti;
  399.     while (ti = NextTagItem(&tstate)) {
  400.     ULONG tg  = ti->ti_Tag;
  401.     ULONG val = ti->ti_Data;
  402.     switch (tg) {
  403. $(ATTRIBUTES_N)
  404. #line 405 "Class.C.tplt"
  405.     } /* switch */
  406.     } /* while */
  407. #endif
  408.     return TRUE;
  409. } /* method_OM_NOTIFY */
  410.  
  411. #undef    BEGIN_ATTRIBUTE
  412. #undef    END_ATTRIBUTE
  413. #endif
  414.  
  415. #if $(HAS_ATTRIBUTES_U) && !defined(NO_PREDEFINED_OM_UPDATE)
  416. #define BEGIN_ATTRIBUTE(id) case id: {
  417. #define END_ATTRIBUTE        } break;
  418.  
  419. static ULONG method_OM_UPDATE (Class *cl, Object *o, struct opSet *msg, struct $(CLASS) *inst) {
  420.     struct TagItem *tstate, *ti;
  421.  
  422. $(OM_UPDATE)
  423. #line 424 "Class.C.tplt"
  424.  
  425.     SUPER;
  426. #if $(HAS_ATTRIBUTES_U)
  427.     ti       = msg->ops_AttrList;
  428.     tstate = ti;
  429.     while (ti = NextTagItem(&tstate)) {
  430.     ULONG tg  = ti->ti_Tag;
  431.     ULONG val = ti->ti_Data;
  432.     switch (tg) {
  433. $(ATTRIBUTES_U)
  434. #line 435 "Class.C.tplt"
  435.     } /* switch */
  436.     } /* while */
  437. #endif
  438.     return TRUE;
  439. } /* method_OM_UPDATE */
  440.  
  441. #undef    BEGIN_ATTRIBUTE
  442. #undef    END_ATTRIBUTE
  443. #endif
  444.  
  445.  
  446. #if $(HAS_LIST) && !defined(NO_PREDEFINED_OM_MEMBER)
  447. static ULONG method_OM_ADDMEMBER (Class *cl, Object *o, struct opMember *msg, struct $(CLASS) *inst) {
  448.  
  449. $(OM_ADDMEMBER)
  450. #line 451 "Class.C.tplt"
  451.  
  452.     DoMethod (o, OM_ADDTAIL, &inst->$(LIST));
  453.     // ---- Was but must not be:
  454.     // AddTail ((struct List *)&inst->$(LIST), (struct Node *)(o-1));
  455.     return TRUE;
  456. } /* method_OM_ADDMEMBER */
  457.  
  458. static ULONG method_OM_REMMEMBER (Class *cl, Object *o, struct opMember *msg, struct $(CLASS) *inst) {
  459.  
  460. $(OM_REMMEMBER)
  461. #line 462 "Class.C.tplt"
  462.  
  463.     DoMethod (o, OM_REMOVE);
  464.     // ---- Was but must not be:
  465.     // Remove ((struct Node *)(o-1));
  466.     return TRUE;
  467. } /* method_OM_REMMEMBER */
  468. #endif
  469.  
  470.  
  471.  
  472. ////////////////////////////////////////////////////
  473. //
  474. //  Following are newly defined Methods
  475. //
  476. ////////////////////////////////////////////////////
  477.  
  478. /* METHOD IMPLEMENTATIONS */
  479. $(IMP_METHODS)
  480. #line 481 "Class.C.tplt"
  481.  
  482.  
  483. ////////////////////////////////////////////////////
  484. //
  485. //  the dispatcher itself ...
  486. //  again we have RootClass-Support
  487. //
  488. ////////////////////////////////////////////////////
  489.  
  490.  
  491. PRE_A4 ULONG $(CLASS)_dispatch( __A0( Class *cl ), __A2( Object *o ), __A1( Msg msg )) {
  492.     ULONG       retval = 0;
  493.     struct $(CLASS) *inst   = NULL;
  494.  
  495.     POST_A4
  496.  
  497.     if (msg->MethodID != OM_NEW)
  498.     inst = INST_DATA(cl, o);
  499.  
  500.  
  501.     switch (msg->MethodID) {
  502. #if ($(HAS_OM_DISPOSE) || $(HAS_TRACKING) || ($(HAS_LIST) && !defined(NO_PREDEFINED_OM_MEMBER))) && !defined(NO_PREDEFINED_OM_DISPOSE)
  503.     case OM_DISPOSE:
  504.             DQ(bug("$(CLASS):OM_DISPOSE\n"));
  505.             retval = method_OM_DISPOSE(cl, o, (Msg)msg, inst);
  506.             break;
  507. #endif
  508. #if ($(HAS_ATTRIBUTES_I) || $(HAS_OM_NEW) || $(HAS_TRACKING) || ($(HAS_LIST) && !defined(NO_PREDEFINED_OM_MEMBER))) && !defined(NO_PREDEFINED_OM_NEW)
  509.     case OM_NEW:
  510.             DQ(bug("$(CLASS):OM_NEW\n"));
  511.             retval = method_OM_NEW    (cl, o, (struct opSet*)msg, inst);
  512.             break;
  513. #endif
  514. #if $(HAS_ATTRIBUTES_S) && !defined(NO_PREDEFINED_OM_SET)
  515.     case OM_SET:
  516.             DQ(bug("$(CLASS):OM_SET\n"));
  517.             retval = method_OM_SET    (cl, o, (struct opSet*)msg, inst);
  518.             break;
  519. #endif
  520. #if $(HAS_ATTRIBUTES_G) && !defined(NO_PREDEFINED_OM_GET)
  521.     case OM_GET:
  522.             DQ(bug("$(CLASS):OM_GET\n"));
  523.             retval = method_OM_GET    (cl, o, (struct opGet*)msg, inst);
  524.             break;
  525. #endif
  526. #if $(HAS_ATTRIBUTES_N) && !defined(NO_PREDEFINED_OM_NOTIFY)
  527.     case OM_NOTIFY:
  528.             DQ(bug("$(CLASS):OM_NOTIFY\n"));
  529.             retval = method_OM_NOTIFY (cl, o, (struct opSet*)msg, inst);
  530.             break;
  531. #endif
  532. #if $(HAS_ATTRIBUTES_U) && !defined(NO_PREDEFINED_OM_UPDATE)
  533.     case OM_UPDATE:
  534.             DQ(bug("$(CLASS):OM_UPDATE\n"));
  535.             retval = method_OM_UPDATE (cl, o, (struct opSet*)msg, inst);
  536.             break;
  537. #endif
  538. #if $(HAS_LIST) && !defined(NO_PREDEFINED_OM_MEMBER)
  539.     case OM_ADDMEMBER:
  540.             DQ(bug("$(CLASS):OM_ADDMEMBER\n"));
  541.             retval = method_OM_ADDMEMBER (cl, o, (struct opMember*)msg, inst);
  542.             break;
  543.     case OM_REMMEMBER:
  544.             DQ(bug("$(CLASS):OM_REMMEMBER\n"));
  545.             retval = method_OM_REMMEMBER (cl, o, (struct opMember*)msg, inst);
  546.             break;
  547. #endif
  548. //  case M_: return method_ (cl, o, ( ... )msg, inst);
  549. /* METHOD CALLS */
  550. $(CALL_METHODS)
  551. #line 552 "Class.C.tplt"
  552.  
  553.     default:
  554. DQ(bug("$(CLASS):SUPERMETHOD\n"));
  555.     retval = DoSuperMethodA(cl, o, msg);
  556.     } /* switch */
  557. DQ(bug("-> $%08lx\n", retval));
  558.     return retval;
  559. } /* $(CLASS)_dispatch */
  560.  
  561.  
  562.  
  563.  
  564. ////////////////////////////////////////////////////
  565. //
  566. //  Following are functions for creation and
  567. //  deletion of the class itself
  568. //
  569. ////////////////////////////////////////////////////
  570.  
  571.  
  572. #if $(HAS_TRACKING)
  573.     static struct List __ObjectsList;
  574.     static Class      *__Class = NULL;
  575. #endif
  576.  
  577. BOOL $(CLASS)_exit(Class *cl) {
  578.     APTR USERDATA;
  579.     if (!cl)
  580.     return FALSE;
  581.     USERDATA = (APTR)cl->cl_UserData;
  582.     if (FreeClass(cl)) {
  583. $(CLASS_EXIT)
  584. #line 585 "Class.C.tplt"
  585. #if $(HAS_TRACKING)
  586.     __Class = NULL;
  587.     NewList(&__ObjectsList);
  588. #endif
  589.     return TRUE;
  590.     } /* if */
  591.     return FALSE;
  592. } /* $(CLASS)_exit */
  593.  
  594.  
  595. Class *$(CLASS)_init(void) {
  596.     Class *cl        = NULL;
  597.     APTR   USERDATA = NULL;
  598.  
  599.     if (cl = MakeClass(NULL, $(SUPERCLASS), sizeof (struct $(CLASS)), 0)) {
  600.     cl->cl_Dispatcher.h_Entry    = $(CLASS)_dispatch;
  601.     cl->cl_Dispatcher.h_SubEntry = NULL;
  602. $(CLASS_INIT)
  603. #line 604 "Class.C.tplt"
  604.     if (USERDATA) cl->cl_UserData = (ULONG)USERDATA;
  605.     } /* if */
  606. #if $(HAS_TRACKING)
  607.     __Class = cl;
  608. #endif
  609.     return cl;
  610. } /* $(CLASS)_init */
  611.  
  612.  
  613.  
  614. ////////////////////////////////////////////////////
  615. //
  616. //  For developement purposes it might be necessary
  617. //  to make sure all members of a class are really
  618. //  freed
  619. //
  620. ////////////////////////////////////////////////////
  621.  
  622. #if $(HAS_TRACKING)
  623. MK_AUTOINIT(__$(CLASS)_Exit) {
  624.     if (__Class) {
  625.     long  counter = 0;
  626.     ULONG offset  = offsetof(struct $(CLASS), __Self) - offsetof(struct $(CLASS), $(TRACKING));
  627.     struct Node *ptr;
  628.     while ((ptr = __ObjectsList.lh_Head) && (ptr->ln_Succ)) {
  629.         Object *o;
  630.         o = *(APTR*)((ULONG)ptr + offset);
  631.         DisposeObject(o);
  632.         ++ i;
  633.     } /* while */
  634.     DQ(bug("%ld Elements freed after end of Program!\n", counter));
  635.     } /* if */
  636. } /* __$(CLASS)_Exit */
  637. #endif
  638.  
  639.  
  640.  
  641. ////////////////////////////////////////////////////
  642. //
  643. //  The rest of the file contains functions for
  644. //  testing the above defined BOOPSI class
  645. //  the needed libraries (as long as they are noted
  646. //  in the class file) are opened, the class is
  647. //  initialized, and a Window is opened;
  648. //  after thst we call a simple IDCMP-handler
  649. //
  650. ////////////////////////////////////////////////////
  651.  
  652. #ifdef TEST
  653.  
  654.  
  655. /* LIBRARY BASES */
  656. // struct SysBase    *SysBase        = NULL;
  657. struct Library         *UtilityBase   = NULL;
  658. struct IntuitionBase *IntuitionBase = NULL;
  659. $(LIB_BASES)
  660. #line 661 "Class.C.tplt"
  661.  
  662.        BOOL          done        = FALSE;
  663. struct IntuiMessage  *im        = NULL;
  664.        Class         *$(CLASS)_class= NULL;
  665. struct Window         *my_win        = NULL;
  666.        Object         *my_gad        = NULL;
  667.  
  668. /* TEST OBJECTS */
  669. $(TEST_OBJECTS)
  670. #line 671 "Class.C.tplt"
  671.  
  672. /* TEST SUPPORT */
  673. $(TEST_SUPPORT)
  674. #line 675 "Class.C.tplt"
  675.  
  676. //******************************
  677. //
  678. //  Main-loop
  679. //
  680. //    simple IDCMP handler
  681. //
  682. //    shold be the last call
  683. //    in main() since it can
  684. //    left only w/ "exit"
  685. //    (X11-like)
  686. //
  687. //*****************************/
  688.  
  689. void main_loop (void) {
  690.  
  691.     while (done == FALSE) {
  692.     if (Wait((1 << my_win->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
  693.         exit(1);
  694.  
  695.     while (im = (struct IntuiMessage *)GetMsg((struct MsgPort *)my_win->UserPort)) {
  696.         switch (im->Class) {
  697.         case IDCMP_CLOSEWINDOW:
  698.         done = TRUE;
  699.         break;
  700. $(TEST_HANDLER)
  701. #line 702 "Class.C.tplt"
  702.         } /* switch */
  703.         ReplyMsg((struct Message *)im);
  704.     } /* while */
  705.     } /* while */
  706.  
  707.     exit (0);
  708. } /* main_loop */
  709.  
  710.  
  711. //******************************
  712. //
  713. //  GUI_init/exit
  714. //
  715. //    to be called at pgmstart
  716. //    open window and create
  717. //    instance
  718. //
  719. //*****************************/
  720.  
  721. void gui_exits (void) {
  722.     struct Message *msg;
  723.  
  724. DQ(bug("$(CLASS):gui_exits\n"));
  725.     while (msg = GetMsg(my_win->UserPort))
  726.     ReplyMsg(msg);
  727.  
  728.     if (my_win)
  729.     CloseWindow(my_win);
  730.     my_win = NULL;
  731.  
  732. $(TEST_EXITS)
  733. #line 734 "Class.C.tplt"
  734.  
  735. } /* gui_exits */
  736.  
  737. int gui_inits (void) {
  738.     atexit (gui_exits);
  739.  
  740. DQ(bug("$(CLASS):gui_inits\n"));
  741.     if (NULL == (my_win = OpenWindowTags( NULL, WA_CloseGadget, TRUE,
  742.                         WA_DragBar,    TRUE,
  743.                         WA_DepthGadget, TRUE,
  744.                         WA_Activate,    TRUE,
  745.                         WA_IDCMP,    IDCMP_CLOSEWINDOW,
  746. //                        WA_Top,     100,
  747. //                        WA_Left,    100,
  748. //                        WA_Width,    400,
  749. //                        WA_Height,    200,
  750. $(TEST_WINDOW)
  751. #line 752 "Class.C.tplt"
  752.     TAG_DONE))) {
  753.     printf ("WINDOW_init failure\n");
  754.     return 21;
  755.     } /* if */
  756.  
  757.     if (NULL == (APTR)((
  758. $(TEST_INITS)
  759. #line 760 "Class.C.tplt"
  760.     TAG_DONE))) {
  761.     printf ("OBJECT_init failure\n");
  762.     return 22;
  763.     } /* if */
  764.  
  765.     AddGList (my_win, (struct Gadget *)my_gad, ~0, -1, NULL);
  766.     RefreshGadgets((struct Gadget *)my_gad, my_win, NULL);
  767.     return 0;
  768. } /* gui_inits */
  769.  
  770.  
  771. //******************************
  772. //
  773. //  CLASS_init/exit
  774. //
  775. //    to be called at pgmstart
  776. //    initializes CLASS
  777. //
  778. //******************************
  779.  
  780. void class_exits (void) {
  781. DQ(bug("$(CLASS):class_exits\n"));
  782.     if ($(CLASS)_class)
  783.     $(CLASS)_exit($(CLASS)_class);
  784.     $(CLASS)_class = NULL;
  785. } /* class_exits */
  786.  
  787. int class_inits (void) {
  788.     atexit(class_exits);
  789.  
  790. DQ(bug("$(CLASS):class_init\n"));
  791.     if (NULL == ($(CLASS)_class = $(CLASS)_init())) {
  792.     printf ("CLASS_init failure\n");
  793.     return 11;
  794.     } /* if */
  795.  
  796.     return 0;
  797. } /* class_inits */
  798.  
  799.  
  800. //******************************
  801. //
  802. //  SYS_init/exit
  803. //
  804. //    init the needed
  805. //    runtime libraries
  806. //
  807. //******************************
  808.  
  809. void sys_exits (void) {
  810.  
  811. DQ(bug("$(CLASS):sys_exits\n"));
  812.     if (IntuitionBase) {
  813.     CloseLibrary((struct Library *)IntuitionBase);
  814.     IntuitionBase = NULL;
  815.     } /* if */
  816.  
  817.     if (UtilityBase) {
  818.     CloseLibrary(UtilityBase);
  819.     UtilityBase = NULL;
  820.     } /* if */
  821.  
  822. $(LIB_EXITS)
  823. #line 824 "Class.C.tplt"
  824.  
  825. } /* sys_exits */
  826.  
  827. int sys_inits (void) {
  828.     atexit(sys_exits);
  829.  
  830. DQ(bug("$(CLASS):sys_inits\n"));
  831.     SysBase = *((struct SysBase **)4l);
  832.  
  833.     if (NULL == (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37L))) {
  834.     return 2;
  835.     } /* if */
  836.  
  837.     if (NULL == (UtilityBase = OpenLibrary("utility.library",37L))) {
  838.     return 1;
  839.     } /* if */
  840.  
  841. $(LIB_INITS)
  842. #line 843 "Class.C.tplt"
  843.  
  844.     return 0;
  845. } /* sys_inits */
  846.  
  847.  
  848. //******************************
  849. //
  850. //  MAIN
  851. //    simple classtester
  852. //
  853. //******************************
  854.  
  855. int main (int ac, char ** av) {
  856.     if (sys_inits() != 0) {
  857.     return 20;
  858.     } /* if */
  859.  
  860.     if (class_inits() != 0) {
  861.     return 10;
  862.     } /* if */
  863.  
  864.     if (gui_inits() != 0) {
  865.     return 10;
  866.     } /* if */
  867.     main_loop();
  868.     return 0;
  869. } /* main */
  870.  
  871. #endif /* TEST */
  872.  
  873. ////////////////////////////////////////////////////////////
  874. //
  875. ////////////////////////////////////////////////////////////
  876.  
  877.