Main Page
Namespaces
Classes
Files
File List
File Members
src
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
19
#include "
variant_topic_tools/MessageHeader.h
"
20
21
namespace
variant_topic_tools
{
22
23
/*****************************************************************************/
24
/* Constructors and Destructor */
25
/*****************************************************************************/
26
27
MessageHeader::MessageHeader
() :
28
fields(new
Fields
()) {
29
}
30
31
MessageHeader::MessageHeader
(
const
FieldsPtr
&
fields
) :
32
fields(fields) {
33
}
34
35
MessageHeader::MessageHeader
(
const
MessageHeader
& src) :
36
fields
(src.
fields
) {
37
}
38
39
MessageHeader::~MessageHeader
() {
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
82
bool
MessageHeader::isLatched
()
const
{
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
}
variant_topic_tools
Definition:
ArrayDataType.h:29
variant_topic_tools::MessageHeader::Fields
std::map< std::string, std::string > Fields
Definition of the fields type.
Definition:
MessageHeader.h:100
variant_topic_tools::MessageHeader::~MessageHeader
~MessageHeader()
Destructor.
Definition:
MessageHeader.cpp:39
variant_topic_tools::MessageHeader::isLatched
bool isLatched() const
True, if the message publication is latched.
Definition:
MessageHeader.cpp:82
boost::shared_ptr< std::map< std::string, std::string > >
MessageHeader.h
Header file providing the MessageHeader class interface.
publisher
variant_topic_tools::Publisher publisher
Definition:
publish.cpp:25
variant_topic_tools::MessageHeader::getPublisher
const std::string & getPublisher() const
Retrieve the name of the publishing node.
Definition:
MessageHeader.cpp:66
variant_topic_tools::MessageHeader::getField
const std::string & getField(const std::string &name) const
Retrieve a field of the message header.
Definition:
MessageHeader.cpp:51
variant_topic_tools::MessageHeader::setTopic
void setTopic(const std::string &topic)
Set the message publishing topic.
Definition:
MessageHeader.cpp:70
variant_topic_tools::MessageHeader::setPublisher
void setPublisher(const std::string &publisher)
Set the name of the publishing node.
Definition:
MessageHeader.cpp:62
variant_topic_tools::MessageHeader::setField
void setField(const std::string &name, const std::string &value)
Set a field of the message header.
Definition:
MessageHeader.cpp:46
variant_topic_tools::MessageHeader::operator[]
std::string & operator[](const std::string &name)
Operator for retrieving a field of the message header (non-const version)
Definition:
MessageHeader.cpp:94
variant_topic_tools::MessageHeader::setLatched
void setLatched(bool latched)
Set to true to indicate that the message publication is latched.
Definition:
MessageHeader.cpp:78
variant_topic_tools::MessageHeader::getTopic
const std::string & getTopic() const
Retrieve the message publishing topic.
Definition:
MessageHeader.cpp:74
variant_topic_tools::MessageHeader::hasField
bool hasField(const std::string &name) const
True, if the message header contains a field with the specified name.
Definition:
MessageHeader.cpp:86
variant_topic_tools::MessageHeader
Variant message header.
Definition:
MessageHeader.h:33
variant_topic_tools::MessageHeader::fields
FieldsPtr fields
The fields of the message header.
Definition:
MessageHeader.h:108
variant_topic_tools::MessageHeader::MessageHeader
MessageHeader()
Default constructor.
Definition:
MessageHeader.cpp:27
variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:49