void RemoteObjectGenerator::structStart(const Poco::CppParser::Struct* pStruct, const CodeGenerator::Properties& properties)
{
	AbstractGenerator::structStart(pStruct, properties);
	_codeInjectors.clear();
	// add constructor/destructor
	Poco::CppParser::Function* pConstr = new Poco::CppParser::Function(_pStruct->name(), _pStruct);
	//const Identifiable::ObjectId& oid
	Poco::CppParser::Parameter* pParam1 = new Poco::CppParser::Parameter("const Poco::RemotingNG::Identifiable::ObjectId& oid", pConstr);
	Poco::CppParser::Parameter* pParam2 = new Poco::CppParser::Parameter("Poco::SharedPtr<" + pStruct->fullName() + "> pServiceObject", pConstr);
	pConstr->addParameter(pParam1);
	pConstr->addParameter(pParam2);

	pConstr->addDocumentation(	" Creates a " + _pStruct->name() + ".");

	Poco::CppParser::Function* pDestr = new Poco::CppParser::Function(std::string("virtual ~")+_pStruct->name(), _pStruct);
	pDestr->addDocumentation(	" Destroys the " + _pStruct->name() + ".");

	Poco::CppParser::TypeDef* pTypeDef = new Poco::CppParser::TypeDef("typedef Poco::AutoPtr<" + generateClassName(pStruct) + "> Ptr", _pStruct);
	poco_check_ptr (pTypeDef); // just avoid unused variable warning

	// adds the member var
	_cppGen.addIncludeFile("Poco/SharedPtr.h");
	_cppGen.addIncludeFile("Poco/RemotingNG/RemoteObject.h");
	_cppGen.addIncludeFile("Poco/RemotingNG/Identifiable.h");
	Poco::CppParser::Variable* pVar = new Poco::CppParser::Variable("Poco::SharedPtr<" + pStruct->fullName() + "> _pServiceObject", _pStruct);
	pVar->setAccess(Poco::CppParser::Symbol::ACC_PRIVATE);
	// add a method virtual const Poco::RemotingNG::Identifiable::TypeId& remoting__typeId() const
	Poco::CppParser::Function* pTypeId = new Poco::CppParser::Function("virtual const Poco::RemotingNG::Identifiable::TypeId& remoting__typeId", _pStruct);
	pTypeId->makeConst();
	pTypeId->makeInline();

	if (GenUtility::hasEvents(pStruct))
	{
		Poco::CppParser::Function* pEvents = new Poco::CppParser::Function("virtual std::string remoting__enableEvents", _pStruct);
		Poco::CppParser::Parameter* pParam = new Poco::CppParser::Parameter("Poco::RemotingNG::Listener::Ptr pListener", 0);
		pEvents->addParameter(pParam);
		pParam = new Poco::CppParser::Parameter("bool enable = true", 0);
		pEvents->addParameter(pParam);

		Poco::CppParser::Function* pHasEvents = new Poco::CppParser::Function("virtual bool remoting__hasEvents", _pStruct);
		pHasEvents->makeConst();

		Poco::CppParser::Function* pRemoteEvents = new Poco::CppParser::Function("virtual void remoting__enableRemoteEvents", _pStruct);
		pParam = new Poco::CppParser::Parameter("const std::string& protocol", 0);
		pRemoteEvents->addParameter(pParam);

		std::string inc = Utility::createInclude(_pStruct, _cppGen.usePocoIncludeStyle());
		Poco::replaceInPlace(inc, "RemoteObject", "EventDispatcher");
		_cppGen.addSrcIncludeFile(inc);
	}

	handleParentFunctions(_pStructIn);
	checkForEventMembers(pStruct);
}
Poco::CppParser::Function* XSDGenerator::createGetFct(const Poco::CppParser::Parameter* pParam, Poco::CppParser::Struct* pStruct)
{
	std::string methodName("get");
	methodName.append(pParam->name());
	methodName[3] = (char)std::toupper(methodName[3]);

	// we return either by value or by const &
	std::string decl(createParameterTypeDecl(pParam->declType()));
	decl.append(" ");
	decl.append(methodName);
	Poco::CppParser::Function* pFct = new Poco::CppParser::Function(decl, pStruct);
	pFct->makeConst();
	pFct->makeInline();

	return pFct;
}
void XSDGenerator::deepCopyMembers(const Poco::CppParser::Struct* pIn, Poco::CppParser::Struct* pOut)
{
	// deep copy all variables and functions, exluding constructor/destructor
	Poco::CppParser::Struct::BaseIterator itB = pIn->baseBegin();
	Poco::CppParser::Struct::BaseIterator itBEnd = pIn->baseEnd();
	for (; itB!= itBEnd; ++itB)
	{
		if (itB->pClass)
			deepCopyMembers(itB->pClass, pOut);
	}
	// handle members
	Poco::CppParser::NameSpace::SymbolTable members;
	pIn->variables(members);
	Poco::CppParser::NameSpace::SymbolTable::const_iterator it = members.begin();
	Poco::CppParser::NameSpace::SymbolTable::const_iterator itEnd = members.end();
	for (; it != itEnd; ++it)
	{
		Poco::CppParser::Variable* pVar = static_cast<Poco::CppParser::Variable*>(it->second);
		Poco::CppParser::Variable* pCpyVar = new Poco::CppParser::Variable(pVar->declaration(), pOut);
		pCpyVar->setAccess(pVar->getAccess());
		pCpyVar->setAttributes(pVar->getAttributes());
	}
	// handle methods
	members.clear();
	Poco::CppParser::Struct::Functions fcts;
	pIn->methods(Poco::CppParser::Symbol::ACC_PUBLIC, fcts);
	Poco::CppParser::Struct::Functions::const_iterator itt = fcts.begin();
	Poco::CppParser::Struct::Functions::const_iterator ittEnd = fcts.end();
	for (; itt != ittEnd; ++itt)
	{
		Poco::CppParser::Function* pFct = static_cast<Poco::CppParser::Function*>(*itt);
		if (!pFct->isConstructor() && ! pFct->isDestructor())
		{
			Poco::CppParser::Function* pCpyFct = new Poco::CppParser::Function(pFct->declaration(), pOut);
			pCpyFct->setAccess (pFct->getAccess());
			addDocumentation(pFct, pCpyFct);
			pCpyFct->setAttributes(pFct->getAttributes());
			if (pFct->isConst())
				pCpyFct->makeConst();

			Poco::CppParser::Function::Iterator itF = pFct->begin();
			Poco::CppParser::Function::Iterator itFEnd = pFct->end();

			for (; itF != itFEnd; ++itF)
			{
				std::string decl = Poco::CodeGeneration::Utility::resolveParamDecl(pIn, *itF);
				if ((*itF)->hasDefaultValue())
				{
					decl.append(" = ");
					decl.append(Poco::CodeGeneration::Utility::resolveType(_pStructIn, (*itF)->declType()));
					decl.append("(");
					decl.append((*itF)->defaultValue());
					decl.append(")");
				}
				
				Poco::CppParser::Parameter* pParam = new Poco::CppParser::Parameter(decl, pCpyFct);
				
				pCpyFct->addParameter(pParam);
			}
		}
			
	}
}