
// Auto-generated file -- do not edit

#include "Box.h"

#include <sstream>

#include "autogen_TestProtocolClient.h"
#include "IOStream.h"

#include "MemLeakFindOn.h"
TestProtocolClientError::TestProtocolClientError()
	: mType(0),
	  mSubType(0)
{
}
TestProtocolClientError::TestProtocolClientError(const TestProtocolClientError &rToCopy)
	: mType(rToCopy.mType),
	  mSubType(rToCopy.mSubType)
{
}
TestProtocolClientError::~TestProtocolClientError()
{
}
int TestProtocolClientError::GetType() const
{
	return 0;
}
void TestProtocolClientError::SetPropertiesFromStreamData(Protocol &rProtocol)
{
	rProtocol.Read(mType);
	rProtocol.Read(mSubType);
}
bool TestProtocolClientError::IsError(int &rTypeOut, int &rSubTypeOut) const
{
	rTypeOut = mType;
	rSubTypeOut = mSubType;
	return true;
}
std::string TestProtocolClientError::GetMessage() const
{
	switch(mSubType)
	{
		default:
			std::ostringstream out;
			out << "Unknown subtype " << mSubType;
			return out.str();
	}
}
TestProtocolClientHello::TestProtocolClientHello()
	: mNumber32(0),
	  mNumber16(0),
	  mNumber8(0)
{
}
TestProtocolClientHello::TestProtocolClientHello(const TestProtocolClientHello &rToCopy)
	: mNumber32(rToCopy.mNumber32),
	  mNumber16(rToCopy.mNumber16),
	  mNumber8(rToCopy.mNumber8),
	  mText(rToCopy.mText)
{
}
TestProtocolClientHello::~TestProtocolClientHello()
{
}
int TestProtocolClientHello::GetType() const
{
	return 1;
}
void TestProtocolClientHello::SetPropertiesFromStreamData(Protocol &rProtocol)
{
	rProtocol.Read(mNumber32);
	rProtocol.Read(mNumber16);
	rProtocol.Read(mNumber8);
	rProtocol.Read(mText);
}
TestProtocolClientHello::TestProtocolClientHello(int32_t Number32, int16_t Number16, int8_t Number8, const std::string& Text)
	: mNumber32(Number32),
	  mNumber16(Number16),
	  mNumber8(Number8),
	  mText(Text)
{
}
void TestProtocolClientHello::WritePropertiesToStreamData(Protocol &rProtocol) const
{
	rProtocol.Write(mNumber32);
	rProtocol.Write(mNumber16);
	rProtocol.Write(mNumber8);
	rProtocol.Write(mText);
}
TestProtocolClientLists::TestProtocolClientLists()
{
}
TestProtocolClientLists::TestProtocolClientLists(const TestProtocolClientLists &rToCopy)
	: mLotsOfText(rToCopy.mLotsOfText)
{
}
TestProtocolClientLists::~TestProtocolClientLists()
{
}
int TestProtocolClientLists::GetType() const
{
	return 2;
}
TestProtocolClientLists::TestProtocolClientLists(const std::vector<std::string>& LotsOfText)
	: mLotsOfText(LotsOfText)
{
}
void TestProtocolClientLists::WritePropertiesToStreamData(Protocol &rProtocol) const
{
	rProtocol.WriteVector(mLotsOfText);
}
TestProtocolClientListsReply::TestProtocolClientListsReply()
	: mNumberOfStrings(0)
{
}
TestProtocolClientListsReply::TestProtocolClientListsReply(const TestProtocolClientListsReply &rToCopy)
	: mNumberOfStrings(rToCopy.mNumberOfStrings)
{
}
TestProtocolClientListsReply::~TestProtocolClientListsReply()
{
}
int TestProtocolClientListsReply::GetType() const
{
	return 3;
}
void TestProtocolClientListsReply::SetPropertiesFromStreamData(Protocol &rProtocol)
{
	rProtocol.Read(mNumberOfStrings);
}
TestProtocolClientQuit::TestProtocolClientQuit()
{
}
TestProtocolClientQuit::TestProtocolClientQuit(const TestProtocolClientQuit &rToCopy)
{
}
TestProtocolClientQuit::~TestProtocolClientQuit()
{
}
int TestProtocolClientQuit::GetType() const
{
	return 4;
}
void TestProtocolClientQuit::SetPropertiesFromStreamData(Protocol &rProtocol)
{
}
void TestProtocolClientQuit::WritePropertiesToStreamData(Protocol &rProtocol) const
{
}
bool TestProtocolClientQuit::IsConversationEnd() const
{
	return true;
}
TestProtocolClientSimple::TestProtocolClientSimple()
	: mValue(0)
{
}
TestProtocolClientSimple::TestProtocolClientSimple(const TestProtocolClientSimple &rToCopy)
	: mValue(rToCopy.mValue)
{
}
TestProtocolClientSimple::~TestProtocolClientSimple()
{
}
int TestProtocolClientSimple::GetType() const
{
	return 5;
}
TestProtocolClientSimple::TestProtocolClientSimple(int32_t Value)
	: mValue(Value)
{
}
void TestProtocolClientSimple::WritePropertiesToStreamData(Protocol &rProtocol) const
{
	rProtocol.Write(mValue);
}
TestProtocolClientSimpleReply::TestProtocolClientSimpleReply()
	: mValuePlusOne(0)
{
}
TestProtocolClientSimpleReply::TestProtocolClientSimpleReply(const TestProtocolClientSimpleReply &rToCopy)
	: mValuePlusOne(rToCopy.mValuePlusOne)
{
}
TestProtocolClientSimpleReply::~TestProtocolClientSimpleReply()
{
}
int TestProtocolClientSimpleReply::GetType() const
{
	return 6;
}
void TestProtocolClientSimpleReply::SetPropertiesFromStreamData(Protocol &rProtocol)
{
	rProtocol.Read(mValuePlusOne);
}
TestProtocolClientGetStream::TestProtocolClientGetStream()
	: mStartingValue(0),
	  mUncertainSize(0)
{
}
TestProtocolClientGetStream::TestProtocolClientGetStream(const TestProtocolClientGetStream &rToCopy)
	: mStartingValue(rToCopy.mStartingValue),
	  mUncertainSize(rToCopy.mUncertainSize)
{
}
TestProtocolClientGetStream::~TestProtocolClientGetStream()
{
}
int TestProtocolClientGetStream::GetType() const
{
	return 7;
}
void TestProtocolClientGetStream::SetPropertiesFromStreamData(Protocol &rProtocol)
{
	rProtocol.Read(mStartingValue);
	rProtocol.Read(mUncertainSize);
}
TestProtocolClientGetStream::TestProtocolClientGetStream(int32_t StartingValue, bool UncertainSize)
	: mStartingValue(StartingValue),
	  mUncertainSize(UncertainSize)
{
}
void TestProtocolClientGetStream::WritePropertiesToStreamData(Protocol &rProtocol) const
{
	rProtocol.Write(mStartingValue);
	rProtocol.Write(mUncertainSize);
}
TestProtocolClientSendStream::TestProtocolClientSendStream()
	: mValue(0)
{
}
TestProtocolClientSendStream::TestProtocolClientSendStream(const TestProtocolClientSendStream &rToCopy)
	: mValue(rToCopy.mValue)
{
}
TestProtocolClientSendStream::~TestProtocolClientSendStream()
{
}
int TestProtocolClientSendStream::GetType() const
{
	return 8;
}
TestProtocolClientSendStream::TestProtocolClientSendStream(int64_t Value)
	: mValue(Value)
{
}
void TestProtocolClientSendStream::WritePropertiesToStreamData(Protocol &rProtocol) const
{
	rProtocol.Write(mValue);
}
TestProtocolClientString::TestProtocolClientString()
{
}
TestProtocolClientString::TestProtocolClientString(const TestProtocolClientString &rToCopy)
	: mTest(rToCopy.mTest)
{
}
TestProtocolClientString::~TestProtocolClientString()
{
}
int TestProtocolClientString::GetType() const
{
	return 9;
}
void TestProtocolClientString::SetPropertiesFromStreamData(Protocol &rProtocol)
{
	rProtocol.Read(mTest);
}
TestProtocolClientString::TestProtocolClientString(const std::string& Test)
	: mTest(Test)
{
}
void TestProtocolClientString::WritePropertiesToStreamData(Protocol &rProtocol) const
{
	rProtocol.Write(mTest);
}
TestProtocolClient::TestProtocolClient(IOStream &rStream)
	: Protocol(rStream)
{
}
TestProtocolClient::~TestProtocolClient()
{
}
const char *TestProtocolClient::GetIdentString()
{
	return "Test-0.00";
}
std::auto_ptr<ProtocolObject> TestProtocolClient::MakeProtocolObject(int ObjType)
{
	switch(ObjType)
	{
	case 0:
		return std::auto_ptr<ProtocolObject>(new TestProtocolClientError);
		break;
	case 1:
		return std::auto_ptr<ProtocolObject>(new TestProtocolClientHello);
		break;
	case 2:
		return std::auto_ptr<ProtocolObject>(new TestProtocolClientLists);
		break;
	case 3:
		return std::auto_ptr<ProtocolObject>(new TestProtocolClientListsReply);
		break;
	case 4:
		return std::auto_ptr<ProtocolObject>(new TestProtocolClientQuit);
		break;
	case 5:
		return std::auto_ptr<ProtocolObject>(new TestProtocolClientSimple);
		break;
	case 6:
		return std::auto_ptr<ProtocolObject>(new TestProtocolClientSimpleReply);
		break;
	case 7:
		return std::auto_ptr<ProtocolObject>(new TestProtocolClientGetStream);
		break;
	case 8:
		return std::auto_ptr<ProtocolObject>(new TestProtocolClientSendStream);
		break;
	case 9:
		return std::auto_ptr<ProtocolObject>(new TestProtocolClientString);
		break;
	default:
		THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnknownCommandRecieved)
	}
}
std::auto_ptr<ProtocolObject> TestProtocolClient::Receive()
{
	std::auto_ptr<ProtocolObject> preply((ProtocolObject*)(Protocol::Receive().release()));


	return preply;
}

void TestProtocolClient::Send(const ProtocolObject &rObject)
{
	Protocol::Send(rObject);
}

std::auto_ptr<TestProtocolClientHello> TestProtocolClient::Query(const TestProtocolClientHello &rQuery)
{
	// Send query
	Send(rQuery);
	
	// Wait for the reply
	std::auto_ptr<ProtocolObject> preply(Receive().release());

	if(preply->GetType() == 1)
	{
		// Correct response
		return std::auto_ptr<TestProtocolClientHello>((TestProtocolClientHello*)preply.release());
	}
	else
	{
		// Set protocol error
		int type, subType;
		if(preply->IsError(type, subType))
		{
			SetError(type, subType);
			BOX_WARNING("Hello command failed: received error " <<
				((TestProtocolClientError&)*preply).GetMessage());
		}
		else
		{
			SetError(Protocol::UnknownError, Protocol::UnknownError);
			BOX_WARNING("Hello command failed: received "
				"unexpected response type " <<
				preply->GetType());
		}
		
		// Throw an exception
		THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply)
	}
}
std::auto_ptr<TestProtocolClientListsReply> TestProtocolClient::Query(const TestProtocolClientLists &rQuery)
{
	// Send query
	Send(rQuery);
	
	// Wait for the reply
	std::auto_ptr<ProtocolObject> preply(Receive().release());

	if(preply->GetType() == 3)
	{
		// Correct response
		return std::auto_ptr<TestProtocolClientListsReply>((TestProtocolClientListsReply*)preply.release());
	}
	else
	{
		// Set protocol error
		int type, subType;
		if(preply->IsError(type, subType))
		{
			SetError(type, subType);
			BOX_WARNING("Lists command failed: received error " <<
				((TestProtocolClientError&)*preply).GetMessage());
		}
		else
		{
			SetError(Protocol::UnknownError, Protocol::UnknownError);
			BOX_WARNING("Lists command failed: received "
				"unexpected response type " <<
				preply->GetType());
		}
		
		// Throw an exception
		THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply)
	}
}
std::auto_ptr<TestProtocolClientQuit> TestProtocolClient::Query(const TestProtocolClientQuit &rQuery)
{
	// Send query
	Send(rQuery);
	
	// Wait for the reply
	std::auto_ptr<ProtocolObject> preply(Receive().release());

	if(preply->GetType() == 4)
	{
		// Correct response
		return std::auto_ptr<TestProtocolClientQuit>((TestProtocolClientQuit*)preply.release());
	}
	else
	{
		// Set protocol error
		int type, subType;
		if(preply->IsError(type, subType))
		{
			SetError(type, subType);
			BOX_WARNING("Quit command failed: received error " <<
				((TestProtocolClientError&)*preply).GetMessage());
		}
		else
		{
			SetError(Protocol::UnknownError, Protocol::UnknownError);
			BOX_WARNING("Quit command failed: received "
				"unexpected response type " <<
				preply->GetType());
		}
		
		// Throw an exception
		THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply)
	}
}
std::auto_ptr<TestProtocolClientSimpleReply> TestProtocolClient::Query(const TestProtocolClientSimple &rQuery)
{
	// Send query
	Send(rQuery);
	
	// Wait for the reply
	std::auto_ptr<ProtocolObject> preply(Receive().release());

	if(preply->GetType() == 6)
	{
		// Correct response
		return std::auto_ptr<TestProtocolClientSimpleReply>((TestProtocolClientSimpleReply*)preply.release());
	}
	else
	{
		// Set protocol error
		int type, subType;
		if(preply->IsError(type, subType))
		{
			SetError(type, subType);
			BOX_WARNING("Simple command failed: received error " <<
				((TestProtocolClientError&)*preply).GetMessage());
		}
		else
		{
			SetError(Protocol::UnknownError, Protocol::UnknownError);
			BOX_WARNING("Simple command failed: received "
				"unexpected response type " <<
				preply->GetType());
		}
		
		// Throw an exception
		THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply)
	}
}
std::auto_ptr<TestProtocolClientGetStream> TestProtocolClient::Query(const TestProtocolClientGetStream &rQuery)
{
	// Send query
	Send(rQuery);
	
	// Wait for the reply
	std::auto_ptr<ProtocolObject> preply(Receive().release());

	if(preply->GetType() == 7)
	{
		// Correct response
		return std::auto_ptr<TestProtocolClientGetStream>((TestProtocolClientGetStream*)preply.release());
	}
	else
	{
		// Set protocol error
		int type, subType;
		if(preply->IsError(type, subType))
		{
			SetError(type, subType);
			BOX_WARNING("GetStream command failed: received error " <<
				((TestProtocolClientError&)*preply).GetMessage());
		}
		else
		{
			SetError(Protocol::UnknownError, Protocol::UnknownError);
			BOX_WARNING("GetStream command failed: received "
				"unexpected response type " <<
				preply->GetType());
		}
		
		// Throw an exception
		THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply)
	}
}
std::auto_ptr<TestProtocolClientGetStream> TestProtocolClient::Query(const TestProtocolClientSendStream &rQuery, IOStream &rStream)
{
	// Send query
	Send(rQuery);
		
	// Send stream after the command
	SendStream(rStream);

	// Wait for the reply
	std::auto_ptr<ProtocolObject> preply(Receive().release());

	if(preply->GetType() == 7)
	{
		// Correct response
		return std::auto_ptr<TestProtocolClientGetStream>((TestProtocolClientGetStream*)preply.release());
	}
	else
	{
		// Set protocol error
		int type, subType;
		if(preply->IsError(type, subType))
		{
			SetError(type, subType);
			BOX_WARNING("SendStream command failed: received error " <<
				((TestProtocolClientError&)*preply).GetMessage());
		}
		else
		{
			SetError(Protocol::UnknownError, Protocol::UnknownError);
			BOX_WARNING("SendStream command failed: received "
				"unexpected response type " <<
				preply->GetType());
		}
		
		// Throw an exception
		THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply)
	}
}
std::auto_ptr<TestProtocolClientString> TestProtocolClient::Query(const TestProtocolClientString &rQuery)
{
	// Send query
	Send(rQuery);
	
	// Wait for the reply
	std::auto_ptr<ProtocolObject> preply(Receive().release());

	if(preply->GetType() == 9)
	{
		// Correct response
		return std::auto_ptr<TestProtocolClientString>((TestProtocolClientString*)preply.release());
	}
	else
	{
		// Set protocol error
		int type, subType;
		if(preply->IsError(type, subType))
		{
			SetError(type, subType);
			BOX_WARNING("String command failed: received error " <<
				((TestProtocolClientError&)*preply).GetMessage());
		}
		else
		{
			SetError(Protocol::UnknownError, Protocol::UnknownError);
			BOX_WARNING("String command failed: received "
				"unexpected response type " <<
				preply->GetType());
		}
		
		// Throw an exception
		THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply)
	}
}
