///////////////////////////////////////////////////////////////////// // component.cpp - implements announce protocol in two derived // // ver 1.0 classes with slightly different behavior // // // // Language: Visual C++, version 6.0, sp5 // // Platform: Dell Dimension 8100, Windows 2000 sp2 // // Application: CSE791 - Distributed Objects // // Demonstration of Programming to Interface // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////// #define IN_DLL #pragma warning(disable : 4786) #include #include #include "componentv1.h" //----< constructor >------------------------------------------ announce1::announce1() { setString("new announce1 object"); } //----< destructor >------------------------------------------- announce1::~announce1() { delete str; } //----< save string for use by announcer() >------------------- DLL_DECL void announce1::setString(const char *s) { str = new char[strlen(s)+1]; strcpy(str,s); str[strlen(s)] = '\0'; } //----< display class identity >------------------------------- DLL_DECL void announce1::announcer() { std::cout << "\n object of class " << id(); std::cout << ", version number = 1.0"; std::cout << "\n my string is: \"" << str << "\""; } //----< constructor >------------------------------------------ announce2::announce2() { setString("new announce2 object"); } //----< destructor >------------------------------------------- announce2::~announce2() { delete str; } //----< save string for use by announcer() >------------------- DLL_DECL void announce2::setString(const char *s) { str = new char[strlen(s)+1]; strcpy(str,s); str[strlen(s)] = '\0'; } //----< display class identity >------------------------------- DLL_DECL void announce2::announcer() { std::cout << "\n object of class " << id(); std::cout << ", version number = 1.0"; std::cout << "\n my string is: \"" << str << "\""; } // //----< register objects of this module for client >----------- DLL_DECL void announce::registerObjects() { objFactory::reg(announce1::id(),announce1::create); objFactory::reg(announce2::id(),announce2::create); } //----< let client identify the object needed >---------------- DLL_DECL std::string announce::type(int n) { switch(n) { case 1 : return announce1::id(); case 2 : return announce2::id(); default : throw "unknown class in announce::ids()"; } return "unknown"; }