home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / NeoIntroTCL3.0 folder / TCL / NeoBench / Source / CNeoBenchApp.cp < prev    next >
Encoding:
Text File  |  1994-09-04  |  5.0 KB  |  223 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * CNeoBenchApp.c
  3.  *
  4.  *    Application methods for a typical application.
  5.  *
  6.  *  Copyright © 1992-1993 NeoLogic Systems.  All rights reserved.
  7.  *
  8.  *****/
  9.  
  10. #include "NeoTypes.h"
  11. #include <CDesktop.h>
  12. #include <CList.h>
  13. #include "CNeoBenchApp.h"
  14. #include "CNeoBenchDoc.h"
  15. #include "CFiller.h"
  16. #include CNeoMetaClassH
  17. #ifdef qNeoThreads
  18. #include CNeoThreadNativeH
  19. #endif
  20.  
  21. extern    OSType    gSignature;
  22.  
  23. int main(void)
  24. {
  25.     CNeoBenchApp *    app;
  26.  
  27.     app = new CNeoBenchApp();
  28.     app->Run();
  29.     app->Exit();
  30.  
  31.     return 0;
  32. }
  33.  
  34. /***
  35.  * CNeoBenchApp
  36.  *
  37.  *    Initialize the application. Your initialization method should
  38.  *    at least call the inherited method. If your application class
  39.  *    defines its own instance variables or global variables, this
  40.  *    is a good place to initialize them.
  41.  *
  42.  ***/
  43. CNeoBenchApp::CNeoBenchApp(void)
  44.     : CNeoAppTCL()
  45. {
  46.     long        index;
  47.     long        delay    = 0;
  48.     TMTask        timer;
  49.  
  50. #if defined(qNeoDebug) && !defined(__MWERKS__)
  51.     gBreakFailure = TRUE;
  52. #endif
  53.  
  54.     IApplication(kNeoExtraMasters, kNeoRainyDayFund, kNeoCriticalBalance, kNeoToolboxBalance);
  55.  
  56.     (void)new CNeoMetaClass(kFillerID, kNeoPersistID, "\pCFiller", CFiller::New);
  57.  
  58.     // measure Time Manager overhead
  59.     timer.tmAddr        = NULL;
  60.     timer.tmCount        = 0;
  61.     timer.tmWakeUp        = 0;
  62.     timer.tmReserved    = 0;
  63.     
  64.     for (index = 0; index < 100; index++) {
  65.         InsTime((QElemPtr)&timer);
  66.         PrimeTime((QElemPtr)&timer, k30MicroMinutes);
  67.         RmvTime((QElemPtr)&timer);
  68.         
  69.         if (timer.tmCount > 0)
  70.             // milliseconds
  71.             delay += -(k30MicroMinutes + timer.tmCount * 1000);
  72.         else
  73.             // negated microseconds
  74.             delay += -(k30MicroMinutes - timer.tmCount);
  75.     }
  76.     
  77.     // compute average overhead
  78.     gLoopOverhead = delay / 100;
  79. }
  80.  
  81. /***
  82.  * SetUpFileParameters
  83.  *
  84.  *    In this routine, you specify the kinds of files your
  85.  *    application opens.
  86.  *
  87.  *
  88.  ***/
  89.  
  90. void CNeoBenchApp::SetUpFileParameters(void)
  91.  
  92. {
  93.     inherited::SetUpFileParameters();    /* Be sure to call the default method */
  94.  
  95.         /**
  96.          **    sfNumTypes is the number of file types
  97.          **    your application knows about.
  98.          **    sfFileTypes[] is an array of file types.
  99.          **    You can define up to 4 file types in
  100.          **    sfFileTypes[].
  101.          **
  102.          **/
  103.     sfNumTypes = 1;
  104.     sfFileTypes[0] = kNeoBenchFileType;
  105.  
  106.         /**
  107.          **    Although it's not an instance variable,
  108.          **    this method is a good place to set the
  109.          **    gSignature global variable. Set this global
  110.          **    to your application's signature. You'll use it
  111.          **    to create a file (see CFile::CreateNew()).
  112.          **
  113.          **/
  114.     gSignature = kNeoBenchSig;
  115. }
  116.  
  117. /***
  118.  * createDocument
  119.  *
  120.  *    The user chose New from the File menu.
  121.  *    In this method, you need to create a document and send it
  122.  *    a NewFile() message.
  123.  *
  124.  ***/
  125. CNeoDoc    *CNeoBenchApp::createDocument(void)
  126. {
  127.     CNeoBenchDoc *    document = nil;
  128.  
  129.     NEOTRY {
  130.         /*
  131.          * Create your document.
  132.          *
  133.          * The arguments indicate whether the document is...
  134.          *    printable (FALSE),
  135.          *    a new file (TRUE),
  136.          *    remote (FALSE).
  137.          */
  138.         document = new CNeoBenchDoc(kNotPrintable, TRUE, FALSE);
  139.  
  140.         /*
  141.          * Send the document a NewFile() message.
  142.          * The document will open a window, and
  143.          * set up the heart of the application.
  144.          */
  145.         document->NewFile();
  146.     }
  147.     NEOCATCH {
  148.         /*
  149.          * This exception handler gets executed if a failure occurred
  150.          * anywhere within the scope of the TRY block above. Since
  151.          * this indicates that a new doc could not be created, we
  152.          * check if an object had been allocated and if it has, send
  153.          * it a unrefer message. The exception will propagate up to
  154.          * CSwitchboard's exception handler, which handles displaying
  155.          * an error alert.
  156.          */
  157.         if (document) {
  158.             delete document;
  159.             document = nil;
  160.         }
  161.     }
  162.     NEOENDTRY;
  163.  
  164.     return document;
  165. }
  166.  
  167. /***
  168.  * OpenDocument
  169.  *
  170.  *    The user chose Open… from the File menu.
  171.  *    In this method you need to create a document
  172.  *    and send it an OpenFile() message.
  173.  *
  174.  *    The macSFReply is a good SFReply record that contains
  175.  *    the name and vRefNum of the file the user chose to
  176.  *    open.
  177.  *
  178.  ***/
  179.  
  180. void CNeoBenchApp::OpenDocument(SFReply *macSFReply)
  181. {
  182.     Boolean            remote        = FALSE;
  183.     long            procID;
  184.     FSSpec            fsSpec;
  185.     CNeoBenchDoc *    document    = nil;
  186.  
  187.     NEOTRY
  188.     {
  189.         // Our parent will check to see if this is a document we have already opened.
  190.         // If we find the file already open by the app, then fDocument will refer to it.
  191.         // If the file is opened but not by this app, then the parent will signal a failure.
  192.         inherited::OpenDocument(macSFReply);
  193.         if (fDocument)
  194.             return;
  195.  
  196.         document = new CNeoBenchDoc(TRUE, FALSE, remote);
  197.  
  198.         /**
  199.          **    Send the document an OpenFile() message.
  200.          **    The document will open a window, open
  201.          **    the file specified in the macSFReply record,
  202.          **    and display it in its window.
  203.          **
  204.          **/
  205.         document->OpenFile(macSFReply);
  206.     }
  207.     NEOCATCH
  208.     {
  209.         /*
  210.          * This exception handler gets executed if a failure occurred
  211.          * anywhere within the scope of the TRY block above. Since
  212.          * this indicates that the document could not be opened, we
  213.          * send it a unrefer message. The exception will propagate up to
  214.          * CSwitchboard's exception handler, which handles displaying
  215.          * an error alert.
  216.          */
  217.  
  218.         if (document)
  219.             delete document;
  220.     }
  221.     NEOENDTRY;
  222. }
  223.