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

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //                                              SAMPLE CODE
  3. //
  4. // FileName: ACDFMdl2.cpp
  5. //
  6. // ClassName: ACompDocFwkModel
  7. //
  8. // Description: Compound Document Framework (SimpleServer) Model
  9. //              This sample is to illustrates the use of notification in the
  10. //              server application.When the model data is changed, a notification
  11. //              event will be sent to the view object, in this example the notification ID
  12. //              is "Data String Changed".
  13. //              There are 'get' and 'set' methods for all of the model data. 
  14. //              When the model data is streamed out the pointer to 'MyObject'
  15. //              is 'flatten'ed, and when the streamed in the pointer is 'resurrect'ed
  16. ///////////////////////////////////////////////////////////////////////////////
  17.  
  18. #include "ACDFMdl2.hpp"
  19. #include "ACDFVw2.hpp"
  20. #include "ACDFMy2.hpp"
  21. #include "ACDFSt2.hpp"
  22. #include "ACDFRes2.h"
  23.  
  24. #include <fstream.h>
  25. #include <ibasstrm.hpp>
  26. #include <ireslib.hpp>
  27. #include <iexcept.hpp>
  28. #include <icconst.h>
  29. #include <assert.h>
  30. #include <iframe.hpp>
  31.  
  32. TypeExtensionMacro(ACompDocFwkModel)
  33.  
  34. const INotificationId ACompDocFwkModel::kDataPointerChange = "Pointer Changed ";
  35. const INotificationId ACompDocFwkModel::kDataStringChange1 = "String Changed 1";
  36. const INotificationId ACompDocFwkModel::kDataStringChange2 = "String Changed 2";
  37.  
  38. ACompDocFwkModel::ACompDocFwkModel() 
  39. // Default Constructor
  40. {       IFUNCTRACE_DEVELOP();
  41.     fDataString1 = IApplication::current().userResourceLibrary().loadString(STR_HELLO_1);
  42.     fDataString2 = IApplication::current().userResourceLibrary().loadString(STR_HELLO_2);
  43.     fPointerMyString = new ACompDocFwkMyObject;
  44.     fPointerMyString->setMyString(fDataString1);
  45.  }
  46.  
  47. ACompDocFwkModel::~ACompDocFwkModel()
  48. // Default Destructor
  49. {       IFUNCTRACE_DEVELOP();
  50.     delete fPointerMyString;
  51. }
  52.  
  53. ACompDocFwkModel::ACompDocFwkModel( const ACompDocFwkModel& other ) :
  54.             IModel( other ) // force assert
  55. // Copy Constructor
  56. {       IFUNCTRACE_DEVELOP();}
  57.  
  58. IString ACompDocFwkModel::getString1() const
  59. // Implement method for reading member data
  60.  
  61. {       IFUNCTRACE_DEVELOP();
  62.     return fDataString1;
  63. }
  64.  
  65. Boolean ACompDocFwkModel::setString1( const IString& str )
  66. // Implement method for setting member data
  67. {       IFUNCTRACE_DEVELOP();
  68.     fDataString1 = str;
  69.     notifyOfChange(INotificationEvent(kDataStringChange1, notifier()));
  70.     return true;
  71. }
  72. IString ACompDocFwkModel::getString2() const
  73. // Implement method for reading member data
  74.  
  75. {       IFUNCTRACE_DEVELOP();
  76.     return fDataString2;
  77. }
  78.  
  79. Boolean ACompDocFwkModel::setString2( const IString& str )
  80. // Implement method for setting member data
  81. {       IFUNCTRACE_DEVELOP();
  82.     fDataString2 = str;
  83.     notifyOfChange(INotificationEvent(kDataStringChange2, notifier()));
  84.     return true;
  85. }
  86.  
  87. IString ACompDocFwkModel::getPointerMyString() const
  88. // Implement method for reading member data
  89.  
  90. {       IFUNCTRACE_DEVELOP();
  91.     return fPointerMyString->getMyString();
  92. }
  93.  
  94. Boolean ACompDocFwkModel::setPointerMyString( const IString& str )
  95. // Implement method for setting member data
  96. {       IFUNCTRACE_DEVELOP();
  97.  
  98.     fPointerMyString->setMyString(str);
  99.     notifyOfChange(INotificationEvent(kDataPointerChange, notifier()));
  100.     return true;
  101.  
  102. IBaseStream& ACompDocFwkModel::operator>>=(IBaseStream& toWhere) const
  103. // Stream member data out
  104. {       IFUNCTRACE_DEVELOP();
  105.     writeVersion(toWhere, kOriginalVersion);
  106.     IModel::operator>>=( toWhere );
  107.     fDataString1 >>= toWhere;
  108.     fDataString2 >>= toWhere;
  109.     ::flatten (fPointerMyString, toWhere);
  110.     return toWhere;
  111. }
  112.  
  113.  
  114. IBaseStream& ACompDocFwkModel::operator<<=(IBaseStream& fromWhere)
  115. // Stream member data in
  116. {       IFUNCTRACE_DEVELOP();
  117.     switch (readVersion(fromWhere))
  118.     {
  119.         case kOriginalVersion:
  120.             IModel::operator<<=( fromWhere );
  121.             fDataString1 <<= fromWhere;
  122.             fDataString2 <<= fromWhere;
  123.             ::resurrect(fPointerMyString, fromWhere);
  124.             break;
  125.         default:
  126.             ITHROWLIBRARYERROR(IC_STREAM_VERSION_UNSUPPORTED, 
  127.                                IBaseErrorInfo::invalidRequest,
  128.                                IException::recoverable);
  129.     }
  130.     return fromWhere;
  131. }
  132. // IComponent Stationery class is created using the model, view
  133.  
  134. ACompDocFwkMyStationery CompDocFwkStationery;
  135.  
  136. int main( int argc, char* argv[] )
  137. {
  138.     int ireturn;
  139.     try
  140.     {
  141.         // Stationery run will eventually call the IApplication::current().run()
  142.         ireturn =  CompDocFwkStationery.run( argc, argv );
  143.     }
  144.  
  145.     catch (IException& exc)
  146.     {
  147.         ofstream  errorFile("errormsg.log",ios::app);
  148.         const IExceptionLocation *excLocate = exc.locationAtIndex(0);
  149.  
  150.         errorFile << "Exception on exit " << exc.text() << endl;
  151.         errorFile << "File : " << excLocate->fileName() << endl;
  152.         errorFile << "Function : " << excLocate->functionName() << endl;
  153.         errorFile << "Line : " << excLocate->lineNumber() << endl;
  154.  
  155.         cout << "Exception on exit " << exc.text() << endl;
  156.         cout << "File : " << excLocate->fileName() << endl;
  157.         cout << "Function : " << excLocate->functionName() << endl;
  158.         cout << "Line : " << excLocate->lineNumber() << endl;
  159.     }
  160.     return ireturn;
  161. }
  162.     
  163.