diff options
Diffstat (limited to 'Swiften/Entity')
-rw-r--r-- | Swiften/Entity/Entity.cpp | 23 | ||||
-rw-r--r-- | Swiften/Entity/Entity.h | 58 | ||||
-rw-r--r-- | Swiften/Entity/GenericPayloadPersister.h | 40 | ||||
-rw-r--r-- | Swiften/Entity/PayloadPersister.cpp | 62 | ||||
-rw-r--r-- | Swiften/Entity/PayloadPersister.h | 31 | ||||
-rw-r--r-- | Swiften/Entity/SConscript | 4 |
6 files changed, 109 insertions, 109 deletions
diff --git a/Swiften/Entity/Entity.cpp b/Swiften/Entity/Entity.cpp index 77d0cc6..0875fb1 100644 --- a/Swiften/Entity/Entity.cpp +++ b/Swiften/Entity/Entity.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -9,42 +9,41 @@ #include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> #include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> - namespace Swift { Entity::Entity() { - payloadParserFactories = new FullPayloadParserFactoryCollection(); - payloadSerializers = new FullPayloadSerializerCollection(); + payloadParserFactories = new FullPayloadParserFactoryCollection(); + payloadSerializers = new FullPayloadSerializerCollection(); } Entity::~Entity() { - delete payloadSerializers; - delete payloadParserFactories; + delete payloadSerializers; + delete payloadParserFactories; } void Entity::addPayloadParserFactory(PayloadParserFactory* payloadParserFactory) { - payloadParserFactories->addFactory(payloadParserFactory); + payloadParserFactories->addFactory(payloadParserFactory); } void Entity::removePayloadParserFactory(PayloadParserFactory* payloadParserFactory) { - payloadParserFactories->removeFactory(payloadParserFactory); + payloadParserFactories->removeFactory(payloadParserFactory); } void Entity::addPayloadSerializer(PayloadSerializer* payloadSerializer) { - payloadSerializers->addSerializer(payloadSerializer); + payloadSerializers->addSerializer(payloadSerializer); } void Entity::removePayloadSerializer(PayloadSerializer* payloadSerializer) { - payloadSerializers->removeSerializer(payloadSerializer); + payloadSerializers->removeSerializer(payloadSerializer); } PayloadParserFactoryCollection* Entity::getPayloadParserFactories() { - return payloadParserFactories; + return payloadParserFactories; } PayloadSerializerCollection* Entity::getPayloadSerializers() { - return payloadSerializers; + return payloadSerializers; } } diff --git a/Swiften/Entity/Entity.h b/Swiften/Entity/Entity.h index d563c5e..a44c145 100644 --- a/Swiften/Entity/Entity.h +++ b/Swiften/Entity/Entity.h @@ -9,33 +9,33 @@ #include <Swiften/Base/API.h> namespace Swift { - class PayloadParserFactory; - class PayloadSerializer; - class FullPayloadParserFactoryCollection; - class FullPayloadSerializerCollection; - class PayloadParserFactoryCollection; - class PayloadSerializerCollection; - - /** - * The base class for XMPP entities (Clients, Components). - */ - class SWIFTEN_API Entity { - public: - Entity(); - virtual ~Entity(); - - void addPayloadParserFactory(PayloadParserFactory* payloadParserFactory); - void removePayloadParserFactory(PayloadParserFactory* payloadParserFactory); - - void addPayloadSerializer(PayloadSerializer* payloadSerializer); - void removePayloadSerializer(PayloadSerializer* payloadSerializer); - - protected: - PayloadParserFactoryCollection* getPayloadParserFactories(); - PayloadSerializerCollection* getPayloadSerializers(); - - private: - FullPayloadParserFactoryCollection* payloadParserFactories; - FullPayloadSerializerCollection* payloadSerializers; - }; + class PayloadParserFactory; + class PayloadSerializer; + class FullPayloadParserFactoryCollection; + class FullPayloadSerializerCollection; + class PayloadParserFactoryCollection; + class PayloadSerializerCollection; + + /** + * The base class for XMPP entities (Clients, Components). + */ + class SWIFTEN_API Entity { + public: + Entity(); + virtual ~Entity(); + + void addPayloadParserFactory(PayloadParserFactory* payloadParserFactory); + void removePayloadParserFactory(PayloadParserFactory* payloadParserFactory); + + void addPayloadSerializer(PayloadSerializer* payloadSerializer); + void removePayloadSerializer(PayloadSerializer* payloadSerializer); + + protected: + PayloadParserFactoryCollection* getPayloadParserFactories(); + PayloadSerializerCollection* getPayloadSerializers(); + + private: + FullPayloadParserFactoryCollection* payloadParserFactories; + FullPayloadSerializerCollection* payloadSerializers; + }; } diff --git a/Swiften/Entity/GenericPayloadPersister.h b/Swiften/Entity/GenericPayloadPersister.h index 6f07c3b..7cef857 100644 --- a/Swiften/Entity/GenericPayloadPersister.h +++ b/Swiften/Entity/GenericPayloadPersister.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,27 +11,27 @@ #include <Swiften/Parser/GenericPayloadParserFactory.h> namespace Swift { - template<typename PAYLOAD, typename PARSER, typename SERIALIZER> - class SWIFTEN_API GenericPayloadPersister : public PayloadPersister { - public: - GenericPayloadPersister() { - } + template<typename PAYLOAD, typename PARSER, typename SERIALIZER> + class SWIFTEN_API GenericPayloadPersister : public PayloadPersister { + public: + GenericPayloadPersister() { + } - public: - boost::shared_ptr<PAYLOAD> loadPayloadGeneric(const boost::filesystem::path& path) { - return boost::dynamic_pointer_cast<PAYLOAD>(loadPayload(path)); - } + public: + std::shared_ptr<PAYLOAD> loadPayloadGeneric(const boost::filesystem::path& path) { + return std::dynamic_pointer_cast<PAYLOAD>(loadPayload(path)); + } - protected: - virtual const PayloadSerializer* getSerializer() const { - return &serializer; - } + protected: + virtual const PayloadSerializer* getSerializer() const { + return &serializer; + } - virtual PayloadParser* createParser() const { - return new PARSER(); - } + virtual PayloadParser* createParser() const { + return new PARSER(); + } - private: - SERIALIZER serializer; - }; + private: + SERIALIZER serializer; + }; } diff --git a/Swiften/Entity/PayloadPersister.cpp b/Swiften/Entity/PayloadPersister.cpp index b92102e..3fd246c 100644 --- a/Swiften/Entity/PayloadPersister.cpp +++ b/Swiften/Entity/PayloadPersister.cpp @@ -1,19 +1,19 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Entity/PayloadPersister.h> -#include <boost/filesystem/fstream.hpp> #include <boost/filesystem.hpp> -#include <iostream> +#include <boost/filesystem/fstream.hpp> -#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h> #include <Swiften/Base/ByteArray.h> +#include <Swiften/Base/Log.h> #include <Swiften/Parser/PayloadParser.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h> #include <Swiften/Serializer/PayloadSerializer.h> using namespace Swift; @@ -24,33 +24,33 @@ PayloadPersister::PayloadPersister() { PayloadPersister::~PayloadPersister() { } -void PayloadPersister::savePayload(boost::shared_ptr<Payload> payload, const boost::filesystem::path& path) { - try { - if (!boost::filesystem::exists(path.parent_path())) { - boost::filesystem::create_directories(path.parent_path()); - } - boost::filesystem::ofstream file(path); - file << getSerializer()->serialize(payload); - file.close(); - } - catch (const boost::filesystem::filesystem_error& e) { - std::cerr << "ERROR: " << e.what() << std::endl; - } +void PayloadPersister::savePayload(std::shared_ptr<Payload> payload, const boost::filesystem::path& path) { + try { + if (!boost::filesystem::exists(path.parent_path())) { + boost::filesystem::create_directories(path.parent_path()); + } + boost::filesystem::ofstream file(path); + file << getSerializer()->serialize(payload); + file.close(); + } + catch (const boost::filesystem::filesystem_error& e) { + SWIFT_LOG(error) << e.what() << std::endl; + } } -boost::shared_ptr<Payload> PayloadPersister::loadPayload(const boost::filesystem::path& path) { - try { - if (boost::filesystem::exists(path)) { - ByteArray data; - readByteArrayFromFile(data, path); - boost::shared_ptr<PayloadParser> parser(createParser()); - PayloadParserTester tester(parser.get()); - tester.parse(byteArrayToString(data)); - return parser->getPayload(); - } - } - catch (const boost::filesystem::filesystem_error& e) { - std::cerr << "ERROR: " << e.what() << std::endl; - } - return boost::shared_ptr<Payload>(); +std::shared_ptr<Payload> PayloadPersister::loadPayload(const boost::filesystem::path& path) { + try { + if (boost::filesystem::exists(path)) { + ByteArray data; + readByteArrayFromFile(data, path); + std::shared_ptr<PayloadParser> parser(createParser()); + PayloadParserTester tester(parser.get()); + tester.parse(byteArrayToString(data)); + return parser->getPayload(); + } + } + catch (const boost::filesystem::filesystem_error& e) { + SWIFT_LOG(error) << e.what() << std::endl; + } + return std::shared_ptr<Payload>(); } diff --git a/Swiften/Entity/PayloadPersister.h b/Swiften/Entity/PayloadPersister.h index 5907c69..c747a41 100644 --- a/Swiften/Entity/PayloadPersister.h +++ b/Swiften/Entity/PayloadPersister.h @@ -1,32 +1,33 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> + #include <boost/filesystem/path.hpp> #include <Swiften/Base/API.h> namespace Swift { - class Payload; - class PayloadSerializer; - class PayloadParser; + class Payload; + class PayloadSerializer; + class PayloadParser; - class SWIFTEN_API PayloadPersister { - public: - PayloadPersister(); - virtual ~PayloadPersister(); + class SWIFTEN_API PayloadPersister { + public: + PayloadPersister(); + virtual ~PayloadPersister(); - void savePayload(boost::shared_ptr<Payload>, const boost::filesystem::path&); - boost::shared_ptr<Payload> loadPayload(const boost::filesystem::path&); + void savePayload(std::shared_ptr<Payload>, const boost::filesystem::path&); + std::shared_ptr<Payload> loadPayload(const boost::filesystem::path&); - protected: + protected: - virtual const PayloadSerializer* getSerializer() const = 0; - virtual PayloadParser* createParser() const = 0; - }; + virtual const PayloadSerializer* getSerializer() const = 0; + virtual PayloadParser* createParser() const = 0; + }; } diff --git a/Swiften/Entity/SConscript b/Swiften/Entity/SConscript index 1342ec1..284e0c0 100644 --- a/Swiften/Entity/SConscript +++ b/Swiften/Entity/SConscript @@ -1,6 +1,6 @@ Import("swiften_env") objects = swiften_env.SwiftenObject([ - "Entity.cpp", - ]) + "Entity.cpp", + ]) swiften_env.Append(SWIFTEN_OBJECTS = [objects]) |