summaryrefslogtreecommitdiff
path: root/qpid/cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2013-12-20 02:01:56 +0000
committerAlan Conway <aconway@apache.org>2013-12-20 02:01:56 +0000
commit3d3057235cb58c78aa35c985e7d13bce163a4ae8 (patch)
tree045bdeb144aad4d2b1733b5c8fa8c011d3591910 /qpid/cpp
parent4af75997444193adc0947cb8ec367ce1887ceb2d (diff)
downloadqpid-python-3d3057235cb58c78aa35c985e7d13bce163a4ae8.tar.gz
NO-JIRA: Added ostream operator for qpid::Messaging::Message
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1552476 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
-rw-r--r--qpid/cpp/examples/messaging/drain.cpp13
-rw-r--r--qpid/cpp/examples/messaging/spout.cpp5
-rw-r--r--qpid/cpp/include/qpid/messaging/Message_ostream.h34
-rw-r--r--qpid/cpp/src/CMakeLists.txt1
-rw-r--r--qpid/cpp/src/qpid/messaging/Message_ostream.cpp45
5 files changed, 86 insertions, 12 deletions
diff --git a/qpid/cpp/examples/messaging/drain.cpp b/qpid/cpp/examples/messaging/drain.cpp
index 6ac1d3a236..aa2d7b4964 100644
--- a/qpid/cpp/examples/messaging/drain.cpp
+++ b/qpid/cpp/examples/messaging/drain.cpp
@@ -21,6 +21,7 @@
#include <qpid/messaging/Connection.h>
#include <qpid/messaging/Message.h>
+#include <qpid/messaging/Message_ostream.h>
#include <qpid/messaging/Receiver.h>
#include <qpid/messaging/Session.h>
@@ -92,17 +93,7 @@ int main(int argc, char** argv)
int i = 0;
while (receiver.fetch(message, timeout)) {
- std::cout << "Message(properties=" << message.getProperties();
- if (!message.getSubject().empty()) {
- std::cout << ", subject='" << message.getSubject() << "'";
- }
- std::cout << ", content='";
- if (message.getContentType() == "amqp/map") {
- std::cout << message.getContentObject().asMap();
- } else {
- std::cout << message.getContentObject();
- }
- std::cout << "')" << std::endl;
+ std::cout << message << std::endl;
session.acknowledge();
if (count && (++i == count))
break;
diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp
index d3451c084b..b2fc3aa40b 100644
--- a/qpid/cpp/examples/messaging/spout.cpp
+++ b/qpid/cpp/examples/messaging/spout.cpp
@@ -22,6 +22,7 @@
#include <qpid/messaging/Address.h>
#include <qpid/messaging/Connection.h>
#include <qpid/messaging/Message.h>
+#include <qpid/messaging/Message_ostream.h>
#include <qpid/messaging/Sender.h>
#include <qpid/messaging/Session.h>
#include <qpid/types/Variant.h>
@@ -51,6 +52,7 @@ struct Options : OptionParser
string_vector entries;
std::string content;
std::string connectionOptions;
+ bool print;
Options()
: OptionParser("Usage: spout [OPTIONS] ADDRESS", "Send messages to the specified address"),
@@ -69,6 +71,7 @@ struct Options : OptionParser
add("map,M", entries, "specify entry for map content");
add("content", content, "specify textual content");
add("connection-options", connectionOptions, "connection options string in the form {name1:value1, name2:value2}");
+ add("print", print, "print each message sent");
}
static bool nameval(const std::string& in, std::string& name, std::string& value)
@@ -137,7 +140,6 @@ struct Options : OptionParser
}
};
-
int main(int argc, char** argv)
{
Options options;
@@ -170,6 +172,7 @@ int main(int argc, char** argv)
std::stringstream spoutid;
spoutid << id << ":" << count;
message.getProperties()["spout-id"] = spoutid.str();
+ if (options.print) std::cout << message << std::endl;
sender.send(message);
}
session.sync();
diff --git a/qpid/cpp/include/qpid/messaging/Message_ostream.h b/qpid/cpp/include/qpid/messaging/Message_ostream.h
new file mode 100644
index 0000000000..f5e36bda24
--- /dev/null
+++ b/qpid/cpp/include/qpid/messaging/Message_ostream.h
@@ -0,0 +1,34 @@
+#ifndef QPID_MESSAGING_MESSAGE_OSTREAM_H
+#define QPID_MESSAGING_MESSAGE_OSTREAM_H
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+#include "Message.h"
+#include <iosfwd>
+
+namespace qpid {
+namespace messaging {
+
+QPID_MESSAGING_EXTERN std::ostream& operator<<(std::ostream&, const Message&);
+
+}} // namespace qpid::messaging
+
+#endif /*!QPID_MESSAGING_MESSAGE_OSTREAM_H*/
diff --git a/qpid/cpp/src/CMakeLists.txt b/qpid/cpp/src/CMakeLists.txt
index 9780343ecf..43037ee2bf 100644
--- a/qpid/cpp/src/CMakeLists.txt
+++ b/qpid/cpp/src/CMakeLists.txt
@@ -1064,6 +1064,7 @@ set (qpidmessaging_SOURCES
qpid/messaging/ConnectionOptions.cpp
qpid/messaging/MessageImpl.h
qpid/messaging/MessageImpl.cpp
+ qpid/messaging/Message_ostream.cpp
qpid/messaging/ProtocolRegistry.cpp
qpid/messaging/amqp/EncodedMessage.h
qpid/messaging/amqp/EncodedMessage.cpp
diff --git a/qpid/cpp/src/qpid/messaging/Message_ostream.cpp b/qpid/cpp/src/qpid/messaging/Message_ostream.cpp
new file mode 100644
index 0000000000..6adae12315
--- /dev/null
+++ b/qpid/cpp/src/qpid/messaging/Message_ostream.cpp
@@ -0,0 +1,45 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+#include "qpid/messaging/Message_ostream.h"
+#include <ostream>
+
+namespace qpid {
+namespace messaging {
+
+using namespace std;
+ostream& operator<<(ostream& o, const Message& message) {
+ o << "Message(properties=" << message.getProperties();
+ if (!message.getSubject().empty()) {
+ o << ", subject='" << message.getSubject() << "'";
+ }
+ if (!message.getContentObject().isVoid()) {
+ o << ", content='";
+ if (message.getContentType() == "amqp/map") {
+ o << message.getContentObject().asMap();
+ } else {
+ o << message.getContentObject();
+ }
+ }
+ o << "')";
+ return o;
+}
+
+}} // namespace qpid::messaging