text: //--------------------------------------------------------------------------
  // Code generated by the SmartSoft MDSD Toolchain
  // The SmartSoft Toolchain has been developed by:
  //  
  // Service Robotics Research Center
  // University of Applied Sciences Ulm
  // Prittwitzstr. 10
  // 89075 Ulm (Germany)
  //
  // Information about the SmartSoft MDSD Toolchain is available at:
  // www.servicerobotik-ulm.de
  //
  // Please do not modify this file. It will be re-generated
  // running the code generator.
  //--------------------------------------------------------------------------
  #include "CommBasicObjects/CommDataFilesCore.hh"
  
  // serialization/deserialization operators
  //#include "CommBasicObjects/CommDataFilesACE.hh"
  
  // include the hash.idl containing the hash constant
  #include "hash.hh"
  #include <assert.h>
  #include <cstring>
  #include <iostream>
  
  // SmartUtils used in from_xml method
  #include "smartKnuthMorrisPratt.hh"
  
  #ifdef ENABLE_HASH
  	#include <boost/functional/hash.hpp>
  #endif
  
  namespace CommBasicObjects 
  {
  	const char* CommDataFilesCore::getCompiledHash()
  	{
  		return CommBasicObjectsIDL::REPO_HASH;
  	}
  	
  	void CommDataFilesCore::getAllHashValues(std::list<std::string> &hashes)
  	{
  		// get own hash value
  		hashes.push_back(getCompiledHash());
  		// get hash value(s) for CommBasicObjects::CommFileMetaData(idl_CommDataFiles.fileMetaData)
  		CommBasicObjects::CommFileMetaData::getAllHashValues(hashes);
  		// get hash value(s) for CommBasicObjects::CommTimeStamp(idl_CommDataFiles.timestamp)
  		CommBasicObjects::CommTimeStamp::getAllHashValues(hashes);
  	}
  	
  	void CommDataFilesCore::checkAllHashValues(std::list<std::string> &hashes)
  	{
  		// check own hash value
  		if (strcmp(getCompiledHash(), hashes.front().c_str()) != 0)
  		{
  			std::cerr << "###################################################" << std::endl;
  			std::cerr << "WARNING: HASHES OF COMMUNICATION OBJECTS MISSMATCH!" << std::endl;
  			std::cerr << "CommDataFilesCore hash" << std::endl;
  			std::cerr << "Expected: " << getCompiledHash() << std::endl;
  			std::cerr << "Received: " << hashes.front() << std::endl;
  			std::cerr << "###################################################" << std::endl;
  		}
  		assert(strcmp(getCompiledHash(), hashes.front().c_str()) == 0);
  		hashes.pop_front();
  		
  		// check hash value(s) for CommBasicObjects::CommFileMetaData(idl_CommDataFiles.fileMetaData)
  		CommBasicObjects::CommFileMetaData::checkAllHashValues(hashes);
  		// check hash value(s) for CommBasicObjects::CommTimeStamp(idl_CommDataFiles.timestamp)
  		CommBasicObjects::CommTimeStamp::checkAllHashValues(hashes);
  	}
  	
  	#ifdef ENABLE_HASH
  	size_t CommDataFilesCore::generateDataHash(const DATATYPE &data)
  	{
  		size_t seed = 0;
  		
  		std::vector<CommBasicObjectsIDL::CommFileMetaData>::const_iterator data_fileMetaDataIt;
  		for(data_fileMetaDataIt=data.fileMetaData.begin(); data_fileMetaDataIt!=data.fileMetaData.end(); data_fileMetaDataIt++) {
  			seed += CommBasicObjects::CommFileMetaData::generateDataHash(*data_fileMetaDataIt);
  		}
  		seed += CommBasicObjects::CommTimeStamp::generateDataHash(data.timestamp);
  		std::vector<ACE_CDR::Char>::const_iterator data_datastreamIt;
  		for(data_datastreamIt=data.datastream.begin(); data_datastreamIt!=data.datastream.end(); data_datastreamIt++) {
  			boost::hash_combine(seed, *data_datastreamIt);
  		}
  		boost::hash_combine(seed, data.commpression);
  		boost::hash_combine(seed, std::string(data.baseFileName.c_str()));
  		boost::hash_combine(seed, data.isSingleFile);
  		boost::hash_combine(seed, data.valid);
  		
  		return seed;
  	}
  	#endif
  	
  	// default constructor
  	CommDataFilesCore::CommDataFilesCore()
  	:	idl_CommDataFiles()
  	{  
  		setFileMetaData(std::vector<CommBasicObjects::CommFileMetaData>());
  		setTimestamp(CommBasicObjects::CommTimeStamp());
  		setDatastream(std::vector<char>());
  		setCommpression(false);
  		setBaseFileName("");
  		setIsSingleFile(false);
  		setValid(false);
  	}
  	
  	CommDataFilesCore::CommDataFilesCore(const DATATYPE &data)
  	:	idl_CommDataFiles(data)
  	{  }
  
  	CommDataFilesCore::~CommDataFilesCore()
  	{  }
  	
  	void CommDataFilesCore::to_ostream(std::ostream &os) const
  	{
  	  os << "CommDataFiles(";
  	  std::vector<CommBasicObjects::CommFileMetaData>::const_iterator fileMetaDataIt;
  	  std::vector<CommBasicObjects::CommFileMetaData> fileMetaDataList = getFileMetaDataCopy();
  	  for(fileMetaDataIt=fileMetaDataList.begin(); fileMetaDataIt!=fileMetaDataList.end(); fileMetaDataIt++) {
  	  	fileMetaDataIt->to_ostream(os);
  	  }
  	  getTimestamp().to_ostream(os);
  	  std::vector<char>::const_iterator datastreamIt;
  	  std::vector<char> datastreamList = getDatastreamCopy();
  	  for(datastreamIt=datastreamList.begin(); datastreamIt!=datastreamList.end(); datastreamIt++) {
  	  	os << *datastreamIt << " ";
  	  }
  	  os << getCommpression() << " ";
  	  os << getBaseFileName() << " ";
  	  os << getIsSingleFile() << " ";
  	  os << getValid() << " ";
  	  os << ") ";
  	}
  	
  	// convert to xml stream
  	void CommDataFilesCore::to_xml(std::ostream &os, const std::string &indent) const {
  		size_t counter = 0;
  		
  		std::vector<CommBasicObjects::CommFileMetaData>::const_iterator fileMetaDataIt;
  		std::vector<CommBasicObjects::CommFileMetaData> fileMetaDataList = getFileMetaDataCopy();
  		counter = 0;
  		os << indent << "<fileMetaDataList n=\"" << fileMetaDataList.size() << "\">";
  		for(fileMetaDataIt=fileMetaDataList.begin(); fileMetaDataIt!=fileMetaDataList.end(); fileMetaDataIt++) {
  			os << indent << "<fileMetaData i=\"" << counter++ << "\">";
  			fileMetaDataIt->to_xml(os, indent);
  			os << indent << "</fileMetaData>";
  		}
  		os << indent << "</fileMetaDataList>";
  		os << indent << "<timestamp>";
  		getTimestamp().to_xml(os, indent);
  		os << indent << "</timestamp>";
  		std::vector<char>::const_iterator datastreamIt;
  		std::vector<char> datastreamList = getDatastreamCopy();
  		counter = 0;
  		os << indent << "<datastreamList n=\"" << datastreamList.size() << "\">";
  		for(datastreamIt=datastreamList.begin(); datastreamIt!=datastreamList.end(); datastreamIt++) {
  			os << indent << "<datastream i=\"" << counter++ << "\">" << *datastreamIt << "</datastream>";
  		}
  		os << indent << "</datastreamList>";
  		os << indent << "<commpression>" << getCommpression() << "</commpression>";
  		os << indent << "<baseFileName>" << getBaseFileName() << "</baseFileName>";
  		os << indent << "<isSingleFile>" << getIsSingleFile() << "</isSingleFile>";
  		os << indent << "<valid>" << getValid() << "</valid>";
  	}
  	
  	// restore from xml stream
  	void CommDataFilesCore::from_xml(std::istream &is) {
  		size_t counter = 0;
  		
  		static const Smart::KnuthMorrisPratt kmp_fileMetaDataList("<fileMetaDataList n=\"");
  		static const Smart::KnuthMorrisPratt kmp_fileMetaData("\">");
  		static const Smart::KnuthMorrisPratt kmp_timestamp("<timestamp>");
  		static const Smart::KnuthMorrisPratt kmp_datastreamList("<datastreamList n=\"");
  		static const Smart::KnuthMorrisPratt kmp_datastream("\">");
  		static const Smart::KnuthMorrisPratt kmp_commpression("<commpression>");
  		static const Smart::KnuthMorrisPratt kmp_baseFileName("<baseFileName>");
  		static const Smart::KnuthMorrisPratt kmp_isSingleFile("<isSingleFile>");
  		static const Smart::KnuthMorrisPratt kmp_valid("<valid>");
  		
  		if(kmp_fileMetaDataList.search(is)) {
  			size_t numberElements;
  			is >> numberElements;
  			CommBasicObjects::CommFileMetaData fileMetaDataItem;
  			std::vector<CommBasicObjects::CommFileMetaData> fileMetaDataList;
  			kmp_fileMetaData.search(is);
  			for(counter=0; counter<numberElements; counter++) {
  				if(kmp_fileMetaData.search(is)) {
  					fileMetaDataItem.from_xml(is);
  					fileMetaDataList.push_back(fileMetaDataItem);
  				}
  			}
  			setFileMetaData(fileMetaDataList);
  		}
  		if(kmp_timestamp.search(is)) {
  			CommBasicObjects::CommTimeStamp timestampItem;
  			timestampItem.from_xml(is);
  			setTimestamp(timestampItem);
  		}
  		if(kmp_datastreamList.search(is)) {
  			size_t numberElements;
  			is >> numberElements;
  			char datastreamItem;
  			std::vector<char> datastreamList;
  			kmp_datastream.search(is);
  			for(counter=0; counter<numberElements; counter++) {
  				if(kmp_datastream.search(is)) {
  					is >> datastreamItem;
  					datastreamList.push_back(datastreamItem);
  				}
  			}
  			setDatastream(datastreamList);
  		}
  		if(kmp_commpression.search(is)) {
  			bool commpressionItem;
  			is >> commpressionItem;
  			setCommpression(commpressionItem);
  		}
  		if(kmp_baseFileName.search(is)) {
  			std::string baseFileNameItem;
  			is >> baseFileNameItem;
  			setBaseFileName(baseFileNameItem);
  		}
  		if(kmp_isSingleFile.search(is)) {
  			bool isSingleFileItem;
  			is >> isSingleFileItem;
  			setIsSingleFile(isSingleFileItem);
  		}
  		if(kmp_valid.search(is)) {
  			bool validItem;
  			is >> validItem;
  			setValid(validItem);
  		}
  	}
  	
  	/*
  	void CommDataFilesCore::get(ACE_Message_Block *&msg) const
  	{
  		// start with a default internal buffer size(will automatically grow if needed)
  		ACE_OutputCDR cdr(ACE_DEFAULT_CDR_BUFSIZE);
  		
  		CommBasicObjectsIDL::HashList hashes;
  		getAllHashValues(hashes);
  		cdr << static_cast<ACE_CDR::Long>(hashes.size());
  		for(CommBasicObjectsIDL::HashList::const_iterator it=hashes.begin(); it!=hashes.end(); it++)
  		{
  			cdr << ACE_CString(it->c_str());
  		}
  		
  		// Here the actual serialization takes place using the OutputCDR serialization operator<<
  		// (see CommDataFilesACE.hh)
  		cdr << idl_CommDataFiles;
  		
  	#ifdef ENABLE_HASH
  		ACE_CDR::ULong data_hash = generateDataHash(idl_CommDataFiles);
  		cdr << data_hash;
  		// std::cout << "CommDataFilesCore: current data hash: " << data_hash << std::endl;
  	#endif
  		
  		// return a shallow copy of the serialized message 
  		// (no data is actually copied, only the internal reference counter is incremented)
  		// in order to prevent memory leaks the caller of this get(msg) method must
  		// manually free the memory by calling the release() method of the message block msg
  		msg = cdr.begin()->duplicate();
  	}
  	
  	void CommDataFilesCore::set(const ACE_Message_Block *msg)
  	{
  		ACE_InputCDR cdr(msg);
  	
  		CommBasicObjectsIDL::HashList hashes;
  		ACE_CDR::Long hashes_size;
  		cdr >> hashes_size;
  		for(int i=0; i<hashes_size; ++i) 
  		{
  			ACE_CString hash;
  			cdr >> hash;
  			hashes.push_back(hash.c_str());
  		}
  		checkAllHashValues(hashes);
  		
  		// Here the actual de-serialization takes place using the InputCDR serialization operator>>
  		// (see CommDataFilesACE.hh)
  		cdr >> idl_CommDataFiles;
  		
  	#ifdef ENABLE_HASH
  		ACE_CDR::Long data_hash;
  		cdr >> data_hash;
  		ACE_CDR::Long own_hash = generateDataHash(idl_CommDataFiles);
  		assert(data_hash == own_hash);
  		// std::cout << "CommDataFilesCore: own data hash: " << own_hash << "; received data hash: " << data_hash << std::endl;
  	#endif
  	}
  	*/
  } /* namespace CommBasicObjects */
  