// ABCMagazine.cpp: implementation of the ABCMagazine class. // ////////////////////////////////////////////////////////////////////// #include "ABCCommon.h" #include "ABCMagazine.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// ABCMagazine::ABCMagazine() { m_szExpirationDate[0] = '\0'; } ABCMagazine::~ABCMagazine() { } bool ABCMagazine::AddOrder( unsigned int uiPrice, const char *pszName, const char *pszAuthor, const char *pszExpirationDate ) { /* Copy the magazine order into our magazine object */ m_uiPrice = uiPrice; strcpy(&m_szTitle[0],pszName); strcpy(&m_szAuthor[0],pszAuthor); strcpy(&m_szExpirationDate[0],pszExpirationDate); WriteObject(); return true; } void ABCMagazine::WriteObject() { /* Save the type of object we are. This will be used by the class factory on the server side to determine which type of class to allocate. */ *this << ABC_MAGAZINE; *this << m_uiPrice << m_szTitle << m_szAuthor << m_szExpirationDate; /* The 1 line call above is equivalent to the 4 lines below. We can use the << and >> operators because we know that the data which we store is not > the current RTR maximum = 65535 byes. WriteToStream(m_uiPrice); WriteToStream(m_szTitle); WriteToStream(m_szAuthor); WriteToStream(m_szExpirationDate) */ } void ABCMagazine::ReadObject() { /* The first data is the type of class we should be. Validate that everything is fine. */ unsigned int uiClassType; *this >> uiClassType; assert(uiClassType == ABC_MAGAZINE); /* Populate this object with the data */ *this >> m_uiPrice >> m_szTitle >> m_szAuthor >> m_szExpirationDate; /* The 1 line call above is equivalent to the 4 lines below. ReadFromStream(m_uiPrice); ReadFromStream(m_szTitle); ReadFromStream(m_szAuthor); */ } abc_status ABCMagazine::ProcessOrder() { // It is here that we would process the request for this Magazine. // For this sample simply print out the Magazine order. cout << "ABCMagazine::ProcessOrder()" << endl; cout << " " << "ExpirationData = " << m_szExpirationDate << endl; cout << " " << "Price = " << m_uiPrice << endl; cout << " " << "Title = " << m_szTitle << endl; cout << " " << "Author = " << m_szAuthor << endl; return ABCOrderSucceeded; }