Serializer.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2014 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include "variant_topic_tools/DataType.h"
00020 #include "variant_topic_tools/Exceptions.h"
00021 #include "variant_topic_tools/Serializer.h"
00022 
00023 namespace variant_topic_tools {
00024 
00025 /*****************************************************************************/
00026 /* Constructors and Destructor                                               */
00027 /*****************************************************************************/
00028 
00029 Serializer::Serializer() {
00030 }
00031 
00032 Serializer::Serializer(const DataType& dataType) {
00033   if (dataType.isValid())
00034     impl = dataType.createSerializer().impl;
00035 }
00036 
00037 Serializer::Serializer(const Serializer& src) :
00038   impl(src.impl) {
00039 }
00040 
00041 Serializer::~Serializer() {
00042 }
00043 
00044 Serializer::Impl::Impl() {
00045 }
00046 
00047 Serializer::Impl::~Impl() {
00048 }
00049 
00050 /*****************************************************************************/
00051 /* Accessors                                                                 */
00052 /*****************************************************************************/
00053 
00054 size_t Serializer::getSerializedLength(const Variant& value) const {
00055   if (impl)
00056     return impl->getSerializedLength(value);
00057   else
00058     return 0;
00059 }
00060 
00061 bool Serializer::isValid() const {
00062   return impl;
00063 }
00064 
00065 /*****************************************************************************/
00066 /* Methods                                                                   */
00067 /*****************************************************************************/
00068 
00069 void Serializer::clear() {
00070   impl.reset();
00071 }
00072 
00073 void Serializer::serialize(ros::serialization::OStream& stream, const Variant&
00074     value) {
00075   if (impl)
00076     impl->serialize(stream, value);
00077   else
00078     throw InvalidSerializerException();
00079 }
00080 
00081 void Serializer::deserialize(ros::serialization::IStream& stream, Variant&
00082     value) {
00083   if (impl)
00084     impl->deserialize(stream, value);
00085   else
00086     throw InvalidSerializerException();
00087 }
00088 
00089 void Serializer::advance(ros::serialization::Stream& stream, const Variant&
00090     value) {
00091   if (impl)
00092     return impl->advance(stream, value);
00093   else
00094     throw InvalidSerializerException();
00095 }
00096 
00097 void Serializer::Impl::advance(ros::serialization::Stream& stream, const
00098     Variant& value) {
00099   stream.advance(getSerializedLength(value));
00100 }
00101 
00102 /*****************************************************************************/
00103 /* Operators                                                                 */
00104 /*****************************************************************************/
00105 
00106 std::ostream& operator<<(std::ostream& stream, const Serializer& serializer) {
00107   return stream;
00108 }
00109 
00110 }


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Fri Aug 5 2016 06:06:27