home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / acdf1 / acdfmdl1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  3.6 KB  |  117 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //                                              SAMPLE CODE
  3. //
  4. // FileName: ACDFMdl1.cpp
  5. //
  6. // ClassName: ACompDocFwkModel
  7. //
  8. // Description: Compound Document Framework (SimpleServer) Model
  9. //              This is a simple sample to demonstrate how to create a basic
  10. //              server application. The model class inherits from the IModel
  11. //              class.
  12. //              The server has a data string as its model data. This data
  13. //              is set to "Hello World" when the model is constructed.
  14. //              
  15. ///////////////////////////////////////////////////////////////////////////////
  16. #include <ireslib.hpp>
  17. #include "acdfres1.h"
  18. #include "ACDFMdl1.hpp"
  19. #include "ACDFVw1.hpp"
  20.  
  21. #include <ibasstrm.hpp>
  22. #include <fstream.h>
  23. #include <istatnry.hpp>
  24. #include <iexcept.hpp>
  25. #include <icconst.h>
  26. #include <iframe.hpp>
  27.  
  28. TypeExtensionMacro(ACompDocFwkModel) // Type extention for streaming
  29.  
  30. ACompDocFwkModel::ACompDocFwkModel() 
  31. // Default Constructor
  32. {       IFUNCTRACE_DEVELOP();
  33.  
  34.      setString(IApplication::current().userResourceLibrary().loadString(STR_HELLO));
  35. }
  36.  
  37. ACompDocFwkModel::~ACompDocFwkModel()
  38. // Default Destructor
  39. {       IFUNCTRACE_DEVELOP(); }
  40.  
  41. ACompDocFwkModel::ACompDocFwkModel( const ACompDocFwkModel& other ) :
  42.             IModel( other ) // force assert
  43. // Copy Constructor
  44. {       IFUNCTRACE_DEVELOP(); }
  45.  
  46. IString ACompDocFwkModel::getString() const
  47. // Implement method for reading member data
  48. {       IFUNCTRACE_DEVELOP();
  49.     return fDataString;
  50. }
  51.  
  52. Boolean ACompDocFwkModel::setString( const IString& str )
  53. // Implement method for setting member data
  54. {       IFUNCTRACE_DEVELOP();
  55.     fDataString = str;
  56.     return true;
  57. }
  58.  
  59. IBaseStream& ACompDocFwkModel::operator>>=(IBaseStream& toWhere) const
  60. // Stream member data out
  61. {       IFUNCTRACE_DEVELOP();
  62.     writeVersion(toWhere, kOriginalVersion);
  63.     IModel::operator>>=( toWhere );
  64.     fDataString >>= toWhere;
  65.     return toWhere;
  66. }
  67.  
  68.  
  69. IBaseStream& ACompDocFwkModel::operator<<=(IBaseStream& fromWhere)
  70. // Stream member data in
  71. {       IFUNCTRACE_DEVELOP();
  72.     switch (readVersion(fromWhere))
  73.     {
  74.         case kOriginalVersion:
  75.             IModel::operator<<=( fromWhere );
  76.             fDataString <<= fromWhere;
  77.             break;
  78.         default:
  79.             ITHROWLIBRARYERROR(IC_STREAM_VERSION_UNSUPPORTED, 
  80.                               IBaseErrorInfo::invalidRequest,
  81.                               IException::recoverable);
  82.     }
  83.     return fromWhere;
  84. }
  85.  
  86. // IComponent Stationery class is created using the model, view
  87.  
  88. IComponentStationeryFor<ACompDocFwkModel,ACompDocFwkView> CompDocFwkStationery;
  89.  
  90. int main( int argc, char* argv[] )
  91. {
  92.     int ireturn;
  93.     try
  94.     {
  95.         // Stationery run will eventually call the IApplication::current().run()
  96.         ireturn =  CompDocFwkStationery.run( argc, argv );
  97.     }
  98.  
  99.     catch (IException& exc)
  100.     {
  101.         ofstream  errorFile("errormsg.log",ios::app);
  102.         const IExceptionLocation *excLocate = exc.locationAtIndex(0);
  103.  
  104.         errorFile << "Exception on exit " << exc.text() << endl;
  105.         errorFile << "File : " << excLocate->fileName() << endl;
  106.         errorFile << "Function : " << excLocate->functionName() << endl;
  107.         errorFile << "Line : " << excLocate->lineNumber() << endl;
  108.  
  109.         cout << "Exception on exit " << exc.text() << endl;
  110.         cout << "File : " << excLocate->fileName() << endl;
  111.         cout << "Function : " << excLocate->functionName() << endl;
  112.         cout << "Line : " << excLocate->lineNumber() << endl;
  113.     }
  114.     return ireturn;
  115. }
  116.     
  117.