Short: C++:ifyning the standard elate .h files Author: Stefan Andersen (elate_cpp@vectrace.com) Uploader: elate_cpp@vectrace.com Type: dev/cpp Version: elate_cpp 0.2 Homepage: www.vectrace.com Distribution: as you like as long as in sourcecode only. About ----- This is a try to c++ify the elate .h files. I uses the Intent 1.1 this means that only the Amiga SDK 1.1 and PartyPack owners can use this. History ------- Well I was starting my new project and wanted to use c++ as a start I decided to make a simple class that wrapped the initialisation in c++ and I did. TODO/Future ----------- Mode of the .h files should be converted. Decide if all the static functions are realy usefull at all? Overview -------- ave ave.hpp Wrapper for the others so they are accesed via ave:: ave::dev dev.hpp All ave_dev_ and handles the application and aveinstance, and opens the toolkit ave::toolkit toolkit.hpp Toolkit opened via your ave::dev object, currently it wrapps Examples --------- Here is why this classes will make your life easier. Here is an example that are based on code from tutorials at http://www.neoapathy.org/tut_index.html (its been intent1.1:ified) Old c way of doing things: ave_dev_t *aveinstance; ave_app_t *appinstance; ave_toolkit_t *tkit; ave_avo_t *window; char *appname="ExampleWindow"; kn_dev_lookup((char *)"/device/ave/", (ELATE_OO_DATA **)(&aveinstance), &appname); if (aveinstance == NULL) { puts("Unable to find device/ave/window"); exit(1); } appinstance = ave_dev_open(aveinstance, (ELATE_OO_DATA *)appname, 0, 0); if (appinstance == NULL) { puts("Unable to open ave"); exit(1); } tkit = ave_dev_opentoolkit(aveinstance,appinstance); if (tkit == NULL) { puts("Unable to open toolkit"); exit(1); } window = (ave_avo_t *) ave_toolkit_createdialog(tkit, "ExampleWindow", 0, WINDOW_SIZE, WINDOW_SIZE, FDI_INNER | FDI_CLOSE | FDI_BORDER | FDI_TITLE | FDI_CONTENT | FDI_DRAG | FDI_CLOSE); if (window==NULL) { puts("Unable to open window"); exit(1); } ave_app_addavo(appinstance,NULL, window, 0); ave_avo_addlink(window,(ave_evt_t *) appinstance, CH_DIALOG_ACTION, EV_QUIT); ave_avo_update(window); do { windowevent = ave_app_getevent(appinstance, (long)-1); if(!windowevent.target) { continue; } ave_evt_event(windowevent.target, windowevent.msg, windowevent.type); ave_dev_freeevent(aveinstance, windowevent.msg); } while (windowevent.type != EV_QUIT); ave_app_closeall(appinstance); ave_dev_closetoolkit(aveinstance, tkit); ave_dev_close(aveinstance, appinstance); The elate_cpp way: #include "inc/ave.hpp" ave::dev my_ave_dev; char *appname="ExampleWindow"; ave_avo_t *window; /* Not c++:ified yet */ ave_event_t windowevent; /* Not c++:ified yet */ if(my_ave_dev.isOK()) my_ave_dev.open("hello"); if(!(my_ave_dev.isOK())) { puts("Unable to create ave device object"); fflush(stdout); exit(1); } my_ave_dev.opentoolkit(); if (my_ave_dev.get_Toolkit() == NULL) { puts("Unable to open toolkit"); exit(1); } window = (ave_avo_t *) my_ave_dev.get_Toolkit()->createdialog(APP, 0, WINDOW_SIZE, WINDOW_SIZE, FDI_INNER | FDI_CLOSE | FDI_BORDER | FDI_TITLE | FDI_CONTENT | FDI_DRAG | FDI_CLOSE); if (window==NULL) { puts("Unable to open window"); exit(1); } ave_app_addavo(my_ave_dev.get_AppInst(),NULL, window, 0); ave_avo_addlink(window,(ave_evt_t *) my_ave_dev.get_AppInst(), CH_DIALOG_ACTION, EV_QUIT); ave_avo_update(window); do { windowevent = ave_app_getevent(my_ave_dev.get_AppInst(), (long)-1); if(!windowevent.target) { continue; } ave_evt_event(windowevent.target, windowevent.msg, windowevent.type); my_ave_dev.freeevent(windowevent.msg); } while (windowevent.type != EV_QUIT); ave_app_closeall(my_ave_dev.get_AppInst()); Well as you can se we dont have to handle the aveinstance,appinstance and toolkit, thay are handled by the ave:dev object all we have to do is to: my_ave_dev.open("hello"); my_ave_dev.opentoolkit(); and then we are ready to go. As you can se of the example there are a lot of stuff in the middle that has not been converted to c++ yet. ave --- File: ave.hpp Description: This class is just a wrapper for the other classes it is used so that the other classes are accesed via ave:: instead of . If this can be solved in a better way let me know. ave::dev -------- File: dev.hpp Description: All ave_dev_ are wrapped att both static methods and as methods using the internal ave-devinstance. This means that the class can be used without creating a object, in a similiur way that the standard .h files is used, se below. But instancing an object ot this class makes it possible to let it handle the ave-instancedevice and application object. And after opening a toolkit it will also manage this for you. Methods: This class has all know function declerade as static this means that if you can use c++ calls for all known none c++ calls prefixing the function ave::dev:: insted of the old c interface ave_dev_ e.g. old c: ave_dev_open(aveinstance, (ELATE_OO_DATA *)appname, 0, 0); new c++: ave::dev::open(aveinstance, (ELATE_OO_DATA *)appname, 0, 0); you can also make an object of the dev class giving it a aveinstance using ave::dev *my_dev=new ave::dev(aveinstance); You can then use the object to access all methods and you don't have to issue the aveinstance pointer all the time, since this is keeped in the class. Extra methods: (exept those defined by elate/ave/dev.h) dev(void) // constructor will use ave_dev_lookup("/device/ave/") to get ave device dev(ave_dev_t *pDevInst_in); // constructor bool isOK(void); // Check status it should be "true" before you start to use the object after creation The set funtion sould probably never have to be used. USE the set functions if you realy are sure of what you do, they may lead to problems void set_DevInst(ave_dev_t *pDevInst_in); // set internal DevInst ave_dev_t *get_DevInst(void); // get internal DevInst void set_AppInst(ave_app_t *pAppInst_in); // set internal AppInst ave_app_t *get_AppInst(void); // get internal AppInst ave_toolkit_t *get_Toolkit(void); // set internal Toolkit void set_Toolkit(ave_toolkit_t tlk); // Get internal Toolkit ave::toolkit ------------ File: toolkit.hpp Description: all ave_toolkit_create() function class are wrapped here. Methods: all ave_toolkit_create() function class are wrapped here. Extra functions: (exept those defined by elate/ave/toolkit.h) ave_toolkit_t *get_Toolkit(void); // Get internal toolkit pointer void set_Toolkit(ave_toolkit_t *tlk); // Set internal toolkit pointer to tlk toolkit(ave_toolkit_t *tlk); // Set internal toolkit pointer to tlk toolkit(ave_dev_t *pDevInst, ave_app_t *pAppInst); // calls ave_dev_opentoolkit(); and sets internal toolkit pointer examples: 1. Setup ave_dev old: kn_dev_lookup((char *)"/device/ave/", (ELATE_OO_DATA **)(&aveinstance), &appname); appinstance = ave_dev_open(aveinstance, (ELATE_OO_DATA *)appname, 0, 0); c++: ave::dev my_dev(appname); //lookup will be made the aveinstance can be retrieved with my_dev.get_DevInst(); and then open or ave::dev my_dev; //lookup will be made the aveinstance can be retrieved with my_dev.get_DevInst(); appinstance = my_dev.open((ELATE_OO_DATA *)appname, 0, 0); or if now objects should be used: kn_dev_lookup((char *)"/device/ave/", (ELATE_OO_DATA **)(&aveinstance), &appname); appinstance = ave::dev::open(aveinstance,(ELATE_OO_DATA *)appname, 0, 0);