/* * Copyright (c) 2012 Mateusz Piękos * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #include namespace Swift { void WhiteboardServer::handleLocalOperationReceived(WhiteboardOperation::ref operation) { operations_.push_back(operation); } WhiteboardOperation::ref WhiteboardServer::handleClientOperationReceived(WhiteboardInsertOperation::ref newOperation) { std::list::reverse_iterator it; if (operations_.size() == 0 || newOperation->getParentID() == operations_.back()->getID()) { operations_.push_back(newOperation); return newOperation; } for (it = operations_.rbegin(); it != operations_.rend(); ++it) { WhiteboardOperation::ref operation = *it; while (newOperation->getParentID() == operation->getParentID()) { WhiteboardInsertOperation::ref insertOperation = boost::dynamic_pointer_cast(operation); if (insertOperation) { std::pair tResult = WhiteboardTransformer::transform(newOperation, insertOperation); if (it == operations_.rbegin()) { operations_.push_back(tResult.second); return tResult.second; } else { newOperation = tResult.second; --it; operation = *it; } } else { operations_.push_back(operation); return *it; } } } return WhiteboardOperation::ref(); } }