loolwsd/TileCache.cpp | 50 ------------------- loolwsd/TileCache.hpp | 62 +----------------------- loolwsd/TileDesc.hpp | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 109 deletions(-)
New commits: commit b2fa9d6f2ec8c16c52e657841564292f45f90fdb Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sat May 21 09:41:23 2016 -0400 loolwsd: moved TileDesc into own file Change-Id: I54162f7ebaaca51f9c52a30af1e278db212562fa Reviewed-on: https://gerrit.libreoffice.org/25261 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp index 836cb5f..bac923d 100644 --- a/loolwsd/TileCache.cpp +++ b/loolwsd/TileCache.cpp @@ -44,56 +44,6 @@ using Poco::Timestamp; using namespace LOOLProtocol; -std::string TileDesc::serialize(const std::string& prefix) const -{ - std::ostringstream oss; - oss << prefix - << " part=" << _part - << " width=" << _width - << " height=" << _height - << " tileposx=" << _tilePosX - << " tileposy=" << _tilePosY - << " tilewidth=" << _tileWidth - << " tileheight=" << _tileHeight; - if (_id >= 0) - { - oss << " id=" << _id; - } - - return oss.str(); -} - -TileDesc TileDesc::parse(const Poco::StringTokenizer& tokens) -{ - // We don't expect undocument fields and - // assume all values to be int. - std::map<std::string, int> pairs; - - // id is optional. - pairs["id"] = -1; - - for (size_t i = 0; i < tokens.count(); ++i) - { - std::string name; - int value = -1; - if (parseNameIntegerPair(tokens[i], name, value)) - { - pairs[name] = value; - } - } - - return TileDesc(pairs["part"], pairs["width"], pairs["height"], - pairs["tileposx"], pairs["tileposy"], - pairs["tilewidth"], pairs["tileheight"], - pairs["id"]); -} - -TileDesc TileDesc::parse(const std::string& message) -{ - StringTokenizer tokens(message, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); - return parse(tokens); -} - TileCache::TileCache(const std::string& docURL, const Timestamp& modifiedTime, const std::string& cacheDir) : diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp index 617ca67..4f72ef8 100644 --- a/loolwsd/TileCache.hpp +++ b/loolwsd/TileCache.hpp @@ -13,72 +13,16 @@ #include <fstream> #include <memory> #include <mutex> -#include <set> +#include <map> #include <string> -#include <vector> #include <Poco/Timestamp.h> -#include <Poco/StringTokenizer.h> -#include "Exceptions.hpp" - -/** Handles the cache for tiles of one document. -*/ +#include "TileDesc.hpp" class ClientSession; -/// Tile Descriptor -/// Represents a tile's coordinates and dimensions. -class TileDesc -{ -public: - TileDesc(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, int id = -1) : - _part(part), - _width(width), - _height(height), - _tilePosX(tilePosX), - _tilePosY(tilePosY), - _tileWidth(tileWidth), - _tileHeight(tileHeight), - _id(id) - { - if (_part < 0 || - _width <= 0 || - _height <= 0 || - _tilePosX < 0 || - _tilePosY < 0 || - _tileWidth <= 0 || - _tileHeight <= 0) - { - throw BadArgumentException("Invalid tile descriptor."); - } - } - - int getPart() const { return _part; } - int getWidth() const { return _width; } - int getHeight() const { return _height; } - int getTilePosX() const { return _tilePosX; } - int getTilePosY() const { return _tilePosY; } - int getTileWidth() const { return _tileWidth; } - int getTileHeight() const { return _tileHeight; } - - std::string serialize(const std::string& prefix = "") const; - - /// Deserialize a TileDesc from a string format. - static TileDesc parse(const std::string& message); - static TileDesc parse(const Poco::StringTokenizer& tokens); - -private: - int _part; - int _width; - int _height; - int _tilePosX; - int _tilePosY; - int _tileWidth; - int _tileHeight; - int _id; -}; - +/// Handles the caching of tiles of one document. class TileCache { struct TileBeingRendered; diff --git a/loolwsd/TileDesc.hpp b/loolwsd/TileDesc.hpp new file mode 100644 index 0000000..c8ee2d8 --- /dev/null +++ b/loolwsd/TileDesc.hpp @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_TILEDESC_HPP +#define INCLUDED_TILEDESC_HPP + +#include <map> +#include <sstream> +#include <string> + +#include <Poco/StringTokenizer.h> + +#include "Exceptions.hpp" +#include "LOOLProtocol.hpp" + +/// Tile Descriptor +/// Represents a tile's coordinates and dimensions. +class TileDesc +{ +public: + TileDesc(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, int id = -1) : + _part(part), + _width(width), + _height(height), + _tilePosX(tilePosX), + _tilePosY(tilePosY), + _tileWidth(tileWidth), + _tileHeight(tileHeight), + _id(id) + { + if (_part < 0 || + _width <= 0 || + _height <= 0 || + _tilePosX < 0 || + _tilePosY < 0 || + _tileWidth <= 0 || + _tileHeight <= 0) + { + throw BadArgumentException("Invalid tile descriptor."); + } + } + + int getPart() const { return _part; } + int getWidth() const { return _width; } + int getHeight() const { return _height; } + int getTilePosX() const { return _tilePosX; } + int getTilePosY() const { return _tilePosY; } + int getTileWidth() const { return _tileWidth; } + int getTileHeight() const { return _tileHeight; } + + /// Serialize this instance into a string. + /// Optionally prepend a prefix. + std::string serialize(const std::string& prefix = "") const + { + std::ostringstream oss; + oss << prefix + << " part=" << _part + << " width=" << _width + << " height=" << _height + << " tileposx=" << _tilePosX + << " tileposy=" << _tilePosY + << " tilewidth=" << _tileWidth + << " tileheight=" << _tileHeight; + if (_id >= 0) + { + oss << " id=" << _id; + } + + return oss.str(); + } + + /// Deserialize a TileDesc from a tokenized string. + static + TileDesc parse(const Poco::StringTokenizer& tokens) + { + // We don't expect undocument fields and + // assume all values to be int. + std::map<std::string, int> pairs; + + // id is optional. + pairs["id"] = -1; + + for (size_t i = 0; i < tokens.count(); ++i) + { + std::string name; + int value = -1; + if (LOOLProtocol::parseNameIntegerPair(tokens[i], name, value)) + { + pairs[name] = value; + } + } + + return TileDesc(pairs["part"], pairs["width"], pairs["height"], + pairs["tileposx"], pairs["tileposy"], + pairs["tilewidth"], pairs["tileheight"], + pairs["id"]); + } + + /// Deserialize a TileDesc from a string format. + static + TileDesc parse(const std::string& message) + { + Poco::StringTokenizer tokens(message, " ", + Poco::StringTokenizer::TOK_IGNORE_EMPTY | + Poco::StringTokenizer::TOK_TRIM); + return parse(tokens); + } + +private: + int _part; + int _width; + int _height; + int _tilePosX; + int _tilePosY; + int _tileWidth; + int _tileHeight; + int _id; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits