void EntityInput::print(std::ostream& os) const { os << "EntityInput(" << "Services="; for( Services::const_iterator itr = fServices.begin(); itr != fServices.end(); ++itr ) { os << "[addresses="; ServiceAddresses addresses = itr->first; for( ServiceAddresses::const_iterator addrItr = addresses.begin(); addrItr != addresses.end(); ++addrItr ) { os << *addrItr << ","; } os << "id=" << itr->second << "]"; } os << ")"; }
void EntityInput::loadServices( EntityInput& input, string result ) { // TODO: LK: why is the service assignment so complicated? Why is it not only Address=Name? stringstream sstr(result); string setting; while( sstr >> setting ) { int pos = setting.find('='); if( pos <= 0 ) { // erase a possible service when no '=' is used ServiceAddress addr = boost::lexical_cast<ServiceAddress>(setting); #ifdef DEBUG Logger::debug3() << "EntityInput: erasing service " << addr << std::endl; #endif for( Services::iterator itr = input.fServices.begin(); itr != input.fServices.end(); ++itr ) { bool hasAddr = false; for( ServiceAddresses::iterator addrItr = itr->first.begin(); addrItr != itr->first.end(); ++addrItr ) { if(*addrItr == addr) { #ifdef DEBUG Logger::debug3() << "EntityInput: erasing ServiceAddress" << std::endl; #endif hasAddr = true; itr->first.erase(addrItr); break; } } if(hasAddr) { if(itr->first.size() == 0) { // erase the whole thing #ifdef DEBUG Logger::debug3() << "EntityInput: erasing ServiceAssignment" << std::endl; #endif input.fServices.erase(itr); } break; } } } else { #ifdef DEBUG Logger::debug3() << "EntityInput: adding service" << std::endl; #endif // add serviceaddr-servicename setting string addressStr = setting.substr(0,pos); ServiceName id = boost::lexical_cast<ServiceName>( setting.substr(pos+1,setting.size()) ); #ifdef DEBUG Logger::debug3() << "EntityInput: id: " << id << std::endl; #endif ServiceAddresses addresses; pos = addressStr.find(','); while(pos > 0) { ServiceAddress address = boost::lexical_cast<ServiceAddress>( addressStr.substr(0, pos)); addresses.push_back(address); addressStr = addressStr.substr(pos+1, addressStr.size()); pos = addressStr.find(','); } // add last address ServiceAddress address = boost::lexical_cast<ServiceAddress>( addressStr); addresses.push_back(address); #ifdef DEBUG Logger::debug3() << "EntityInput: addresses: " << std::endl; #endif for( ServiceAddresses::const_iterator itr = addresses.begin(); itr != addresses.end(); ++itr ) { #ifdef DEBUG Logger::debug3() << " " << *itr << std::endl; #endif } input.fServices.push_back(ServiceAssignment(addresses, id)); } } }