///////////////////////////////////////////////////////////////// // Sender.cpp - defines class to wrap function pointers // // Exam3:Q4 // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 05 // ///////////////////////////////////////////////////////////////// #include #include #include /////////////////////////////////////////////////////////// // ipc mechanism, a simulated socket class SimulatedSocket { public: SimulatedSocket() {} void send(const char *buffer, int len) { std::string temp(&buffer[0],&buffer[len]); std::cout << "\n " << temp.c_str(); } }; typedef struct { std::string ip; int port; } EndPoint; /////////////////////////////////////////////////////////// // required answer class sender : public std::ostringstream { public: sender() {} bool connect(const EndPoint& ep); template sender& operator<<(const T t); void close(); private: SimulatedSocket sock; }; // end required answer - need comment below also /////////////////////////////////////////////////////////// // bool sender::connect(const EndPoint& ep) { // does socket stuff to connect return true; } //----< insertion operator >------------------------------- // // This function is needed to extract the input from // the base stream and forward to the ipc mechanism, // e.g., the socket template sender& sender::operator<<(const T t) { this->clear(); std::ostringstream* pBase = this; *pBase << t; int len = strlen(pBase->str().c_str()); sock.send(pBase->str().c_str(),len); return *this; } void main() { sender sndr; sndr << "Hello World"; std::cout << "\n\n"; }