MessageHeader.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/MessageHeader.h"
00020 
00021 namespace variant_topic_tools {
00022 
00023 /*****************************************************************************/
00024 /* Constructors and Destructor                                               */
00025 /*****************************************************************************/
00026 
00027 MessageHeader::MessageHeader() :
00028   fields(new Fields()) {
00029 }
00030 
00031 MessageHeader::MessageHeader(const FieldsPtr& fields) :
00032   fields(fields) {
00033 }
00034 
00035 MessageHeader::MessageHeader(const MessageHeader& src) :
00036   fields(src.fields) {
00037 }
00038 
00039 MessageHeader::~MessageHeader() {
00040 }
00041 
00042 /*****************************************************************************/
00043 /* Accessors                                                                 */
00044 /*****************************************************************************/
00045 
00046 void MessageHeader::setField(const std::string& name, const std::string&
00047     value) {
00048   (*fields)[name] = value;
00049 }
00050 
00051 const std::string& MessageHeader::getField(const std::string& name) const {
00052   Fields::const_iterator it = fields->find(name);
00053     
00054   if (it == fields->end()) {
00055     static std::string value = std::string();
00056     return value;
00057   }
00058   else
00059     return it->second;
00060 }
00061 
00062 void MessageHeader::setPublisher(const std::string& publisher) {
00063   (*fields)["callerid"] = publisher;
00064 }
00065 
00066 const std::string& MessageHeader::getPublisher() const {
00067   return getField("callerid");
00068 }
00069 
00070 void MessageHeader::setTopic(const std::string& topic) {
00071   (*fields)["topic"] = topic;
00072 }
00073 
00074 const std::string& MessageHeader::getTopic() const {
00075   return getField("topic");
00076 }
00077 
00078 void MessageHeader::setLatched(bool latched) {
00079   (*fields)["latching"] = latched ? "1" : "0";
00080 }
00081 
00082 bool MessageHeader::isLatched() const {
00083   return (getField("latching") == "1");
00084 }
00085 
00086 bool MessageHeader::hasField(const std::string& name) const {
00087   return (fields->find(name) != fields->end());
00088 }
00089 
00090 /*****************************************************************************/
00091 /* Operators                                                                 */
00092 /*****************************************************************************/
00093 
00094 std::string& MessageHeader::operator[](const std::string& name) {
00095   return (*fields)[name];
00096 }
00097 
00098 const std::string& MessageHeader::operator[](const std::string& name) const {
00099   return getField(name);
00100 }
00101 
00102 }


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