MessageHeader.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2014 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
20 
21 namespace variant_topic_tools {
22 
23 /*****************************************************************************/
24 /* Constructors and Destructor */
25 /*****************************************************************************/
26 
28  fields(new Fields()) {
29 }
30 
32  fields(fields) {
33 }
34 
36  fields(src.fields) {
37 }
38 
40 }
41 
42 /*****************************************************************************/
43 /* Accessors */
44 /*****************************************************************************/
45 
46 void MessageHeader::setField(const std::string& name, const std::string&
47  value) {
48  (*fields)[name] = value;
49 }
50 
51 const std::string& MessageHeader::getField(const std::string& name) const {
52  Fields::const_iterator it = fields->find(name);
53 
54  if (it == fields->end()) {
55  static std::string value = std::string();
56  return value;
57  }
58  else
59  return it->second;
60 }
61 
62 void MessageHeader::setPublisher(const std::string& publisher) {
63  (*fields)["callerid"] = publisher;
64 }
65 
66 const std::string& MessageHeader::getPublisher() const {
67  return getField("callerid");
68 }
69 
70 void MessageHeader::setTopic(const std::string& topic) {
71  (*fields)["topic"] = topic;
72 }
73 
74 const std::string& MessageHeader::getTopic() const {
75  return getField("topic");
76 }
77 
78 void MessageHeader::setLatched(bool latched) {
79  (*fields)["latching"] = latched ? "1" : "0";
80 }
81 
83  return (getField("latching") == "1");
84 }
85 
86 bool MessageHeader::hasField(const std::string& name) const {
87  return (fields->find(name) != fields->end());
88 }
89 
90 /*****************************************************************************/
91 /* Operators */
92 /*****************************************************************************/
93 
94 std::string& MessageHeader::operator[](const std::string& name) {
95  return (*fields)[name];
96 }
97 
98 const std::string& MessageHeader::operator[](const std::string& name) const {
99  return getField(name);
100 }
101 
102 }
std::map< std::string, std::string > Fields
Definition of the fields type.
bool isLatched() const
True, if the message publication is latched.
Header file providing the MessageHeader class interface.
variant_topic_tools::Publisher publisher
Definition: publish.cpp:25
const std::string & getPublisher() const
Retrieve the name of the publishing node.
const std::string & getField(const std::string &name) const
Retrieve a field of the message header.
void setTopic(const std::string &topic)
Set the message publishing topic.
void setPublisher(const std::string &publisher)
Set the name of the publishing node.
void setField(const std::string &name, const std::string &value)
Set a field of the message header.
std::string & operator[](const std::string &name)
Operator for retrieving a field of the message header (non-const version)
void setLatched(bool latched)
Set to true to indicate that the message publication is latched.
const std::string & getTopic() const
Retrieve the message publishing topic.
bool hasField(const std::string &name) const
True, if the message header contains a field with the specified name.
Variant message header.
Definition: MessageHeader.h:33
FieldsPtr fields
The fields of the message header.
MessageHeader()
Default constructor.


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:49