You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2009/10/02 15:01:52 UTC
svn commit: r821000 - in /qpid/trunk/qpid/cpp: examples/messaging/
include/qpid/messaging/ src/ src/qpid/client/amqp0_10/ src/qpid/messaging/
src/tests/
Author: gsim
Date: Fri Oct 2 13:01:51 2009
New Revision: 821000
URL: http://svn.apache.org/viewvc?rev=821000&view=rev
Log:
define content- and view- classes separately from message class
Added:
qpid/trunk/qpid/cpp/include/qpid/messaging/ListContent.h
qpid/trunk/qpid/cpp/include/qpid/messaging/ListView.h
qpid/trunk/qpid/cpp/include/qpid/messaging/MapContent.h
qpid/trunk/qpid/cpp/include/qpid/messaging/MapView.h
qpid/trunk/qpid/cpp/src/qpid/messaging/ListContent.cpp
qpid/trunk/qpid/cpp/src/qpid/messaging/ListView.cpp
qpid/trunk/qpid/cpp/src/qpid/messaging/MapContent.cpp
qpid/trunk/qpid/cpp/src/qpid/messaging/MapView.cpp
Removed:
qpid/trunk/qpid/cpp/include/qpid/messaging/MessageContent.h
Modified:
qpid/trunk/qpid/cpp/examples/messaging/client.cpp
qpid/trunk/qpid/cpp/examples/messaging/map_receiver.cpp
qpid/trunk/qpid/cpp/examples/messaging/map_sender.cpp
qpid/trunk/qpid/cpp/examples/messaging/queue_listener.cpp
qpid/trunk/qpid/cpp/examples/messaging/queue_receiver.cpp
qpid/trunk/qpid/cpp/examples/messaging/queue_sender.cpp
qpid/trunk/qpid/cpp/examples/messaging/server.cpp
qpid/trunk/qpid/cpp/examples/messaging/topic_listener.cpp
qpid/trunk/qpid/cpp/examples/messaging/topic_receiver.cpp
qpid/trunk/qpid/cpp/include/qpid/messaging/Message.h
qpid/trunk/qpid/cpp/src/Makefile.am
qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/AddressResolution.cpp
qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/IncomingMessages.cpp
qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/OutgoingMessage.cpp
qpid/trunk/qpid/cpp/src/qpid/messaging/Message.cpp
qpid/trunk/qpid/cpp/src/qpid/messaging/MessageImpl.cpp
qpid/trunk/qpid/cpp/src/qpid/messaging/MessageImpl.h
qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp
Modified: qpid/trunk/qpid/cpp/examples/messaging/client.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/client.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/client.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/client.cpp Fri Oct 2 13:01:51 2009
@@ -63,7 +63,7 @@
request.setContent(s[i]);
sender.send(request);
Message response = receiver.fetch();
- std::cout << request.getContent().asString() << " -> " << response.getContent().asString() << std::endl;
+ std::cout << request.getContent() << " -> " << response.getContent() << std::endl;
}
connection.close();
return 0;
Modified: qpid/trunk/qpid/cpp/examples/messaging/map_receiver.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/map_receiver.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/map_receiver.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/map_receiver.cpp Fri Oct 2 13:01:51 2009
@@ -20,6 +20,7 @@
*/
#include <qpid/messaging/Connection.h>
+#include <qpid/messaging/MapView.h>
#include <qpid/messaging/Message.h>
#include <qpid/messaging/Receiver.h>
#include <qpid/messaging/Session.h>
@@ -42,7 +43,8 @@
Session session = connection.newSession();
Receiver receiver = session.createReceiver("message_queue");
Message message = receiver.fetch();
- std::cout << message.getContent().asMap() << std::endl;
+ MapView content(message);
+ std::cout << content << std::endl;
session.acknowledge();
receiver.cancel();
connection.close();
Modified: qpid/trunk/qpid/cpp/examples/messaging/map_sender.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/map_sender.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/map_sender.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/map_sender.cpp Fri Oct 2 13:01:51 2009
@@ -20,6 +20,7 @@
*/
#include <qpid/messaging/Connection.h>
+#include <qpid/messaging/MapContent.h>
#include <qpid/messaging/Message.h>
#include <qpid/messaging/Sender.h>
#include <qpid/messaging/Session.h>
@@ -43,14 +44,16 @@
Sender sender = session.createSender("message_queue");
Message message;
- message.getContent()["id"] = 987654321;
- message.getContent()["name"] = "Widget";
- message.getContent()["price"] = 0.99;//bad use of floating point number, just an example!
+ MapContent content(message);
+ content["id"] = 987654321;
+ content["name"] = "Widget";
+ content["price"] = 0.99;//bad use of floating point number, just an example!
Variant::List colours;
colours.push_back(Variant("red"));
colours.push_back(Variant("green"));
colours.push_back(Variant("white"));
- message.getContent()["colours"] = colours;
+ content["colours"] = colours;
+ content.encode();
sender.send(message);
session.sync();
Modified: qpid/trunk/qpid/cpp/examples/messaging/queue_listener.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/queue_listener.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/queue_listener.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/queue_listener.cpp Fri Oct 2 13:01:51 2009
@@ -47,8 +47,8 @@
void Listener::received(Message& message)
{
- std::cout << "Message: " << message.getContent().asString() << std::endl;
- if (message.getContent().asString() == "That's all, folks!") {
+ std::cout << "Message: " << message.getContent() << std::endl;
+ if (message.getContent() == "That's all, folks!") {
std::cout << "Shutting down listener" << std::endl;
receiver.cancel();
finished = true;
Modified: qpid/trunk/qpid/cpp/examples/messaging/queue_receiver.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/queue_receiver.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/queue_receiver.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/queue_receiver.cpp Fri Oct 2 13:01:51 2009
@@ -24,16 +24,10 @@
#include <qpid/messaging/Receiver.h>
#include <qpid/messaging/Session.h>
-#include <cstdlib>
#include <iostream>
-#include <sstream>
-
using namespace qpid::messaging;
-using std::stringstream;
-using std::string;
-
int main(int argc, char** argv) {
const char* url = argc>1 ? argv[1] : "amqp:tcp:127.0.0.1:5672";
@@ -47,7 +41,7 @@
Message message = receiver.fetch();
std::cout << "Message: " << message.getContent() << std::endl;
session.acknowledge();
- if (message.getContent().asString() == "That's all, folks!") {
+ if (message.getContent() == "That's all, folks!") {
std::cout << "Cancelling receiver" << std::endl;
receiver.cancel();
break;
Modified: qpid/trunk/qpid/cpp/examples/messaging/queue_sender.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/queue_sender.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/queue_sender.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/queue_sender.cpp Fri Oct 2 13:01:51 2009
@@ -26,14 +26,10 @@
#include <cstdlib>
#include <iostream>
-
#include <sstream>
using namespace qpid::messaging;
-using std::stringstream;
-using std::string;
-
int main(int argc, char** argv) {
const char* url = argc>1 ? argv[1] : "amqp:tcp:127.0.0.1:5672";
int count = argc>2 ? atoi(argv[2]) : 10;
@@ -45,14 +41,13 @@
// Now send some messages ...
for (int i=0; i<count; i++) {
- Message message;
- message.getContent() << "Message " << i;
- sender.send(message);
+ std::stringstream content;
+ content << "Message " << i;
+ sender.send(Message(content.str()));
}
- // And send a final message to indicate termination.
- Message message("That's all, folks!");
- sender.send(message);
+ // And send a final message to indicate termination.
+ sender.send(Message("That's all, folks!"));
session.sync();
connection.close();
return 0;
Modified: qpid/trunk/qpid/cpp/examples/messaging/server.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/server.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/server.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/server.cpp Fri Oct 2 13:01:51 2009
@@ -51,17 +51,17 @@
const Address& address = request.getReplyTo();
if (address) {
Sender sender = session.createSender(address);
- std::string s = request.getContent().asString();
+ std::string s = request.getContent();
std::transform(s.begin(), s.end(), s.begin(), toupper);
Message response(s);
sender.send(response);
std::cout << "Processed request: "
- << request.getContent().asString()
+ << request.getContent()
<< " -> "
- << response.getContent().asString() << std::endl;
+ << response.getContent() << std::endl;
session.acknowledge();
} else {
- std::cerr << "Error: no reply address specified for request: " << request.getContent().asString() << std::endl;
+ std::cerr << "Error: no reply address specified for request: " << request.getContent() << std::endl;
session.reject(request);
}
}
Modified: qpid/trunk/qpid/cpp/examples/messaging/topic_listener.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/topic_listener.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/topic_listener.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/topic_listener.cpp Fri Oct 2 13:01:51 2009
@@ -48,8 +48,8 @@
void Listener::received(Message& message)
{
- std::cout << "Message: " << message.getContent().asString() << std::endl;
- if (message.getContent().asString() == "That's all, folks!") {
+ std::cout << "Message: " << message.getContent() << std::endl;
+ if (message.getContent() == "That's all, folks!") {
std::cout << "Shutting down listener" << std::endl;
receiver.cancel();
finished = true;
Modified: qpid/trunk/qpid/cpp/examples/messaging/topic_receiver.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/topic_receiver.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/topic_receiver.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/topic_receiver.cpp Fri Oct 2 13:01:51 2009
@@ -47,8 +47,8 @@
Receiver receiver = session.createReceiver(Address("news_service", "topic"), filter);
while (true) {
Message message = receiver.fetch();
- std::cout << "Message: " << message.getContent().asString() << std::endl;
- if (message.getContent().asString() == "That's all, folks!") {
+ std::cout << "Message: " << message.getContent() << std::endl;
+ if (message.getContent() == "That's all, folks!") {
std::cout << "Cancelling receiver" << std::endl;
receiver.cancel();
break;
Added: qpid/trunk/qpid/cpp/include/qpid/messaging/ListContent.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/messaging/ListContent.h?rev=821000&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/messaging/ListContent.h (added)
+++ qpid/trunk/qpid/cpp/include/qpid/messaging/ListContent.h Fri Oct 2 13:01:51 2009
@@ -0,0 +1,90 @@
+#ifndef QPID_MESSAGING_LISTCONTENT_H
+#define QPID_MESSAGING_LISTCONTENT_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 "qpid/client/ClientImportExport.h"
+#include "Variant.h"
+
+namespace qpid {
+namespace messaging {
+
+class ListContentImpl;
+class Message;
+
+/**
+ * Allows message content to be manipulated as a list.
+ */
+class ListContent
+{
+ public:
+ typedef Variant::List::iterator iterator;
+ typedef Variant::List::reverse_iterator reverse_iterator;
+ typedef Variant::List::const_iterator const_iterator;
+ typedef Variant::List::const_reverse_iterator const_reverse_iterator;
+
+ QPID_CLIENT_EXTERN ListContent(Message&);
+ QPID_CLIENT_EXTERN ~ListContent();
+
+ QPID_CLIENT_EXTERN const_iterator begin() const;
+ QPID_CLIENT_EXTERN iterator begin();
+ QPID_CLIENT_EXTERN const_iterator end() const;
+ QPID_CLIENT_EXTERN iterator end();
+ QPID_CLIENT_EXTERN const_reverse_iterator rbegin() const;
+ QPID_CLIENT_EXTERN reverse_iterator rbegin();
+ QPID_CLIENT_EXTERN const_reverse_iterator rend() const;
+ QPID_CLIENT_EXTERN reverse_iterator rend();
+
+ QPID_CLIENT_EXTERN bool empty() const;
+ QPID_CLIENT_EXTERN size_t size() const;
+
+ QPID_CLIENT_EXTERN const Variant& front() const;
+ QPID_CLIENT_EXTERN Variant& front();
+ QPID_CLIENT_EXTERN const Variant& back() const;
+ QPID_CLIENT_EXTERN Variant& back();
+
+ QPID_CLIENT_EXTERN void push_front(const Variant&);
+ QPID_CLIENT_EXTERN void push_back(const Variant&);
+
+ QPID_CLIENT_EXTERN void pop_front();
+ QPID_CLIENT_EXTERN void pop_back();
+
+ QPID_CLIENT_EXTERN iterator insert(iterator position, const Variant&);
+ QPID_CLIENT_EXTERN void insert(iterator position, size_t n, const Variant&);
+ QPID_CLIENT_EXTERN iterator erase(iterator position);
+ QPID_CLIENT_EXTERN iterator erase(iterator first, iterator last);
+ QPID_CLIENT_EXTERN void clear();
+
+ QPID_CLIENT_EXTERN void encode();
+
+ QPID_CLIENT_EXTERN const Variant::List& asList() const;
+ QPID_CLIENT_EXTERN Variant::List& asList();
+ private:
+ ListContentImpl* impl;
+
+ QPID_CLIENT_EXTERN ListContent& operator=(const ListContent&);
+};
+
+QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const ListContent& m);
+
+}} // namespace qpid::messaging
+
+#endif /*!QPID_MESSAGING_LISTCONTENT_H*/
Added: qpid/trunk/qpid/cpp/include/qpid/messaging/ListView.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/messaging/ListView.h?rev=821000&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/messaging/ListView.h (added)
+++ qpid/trunk/qpid/cpp/include/qpid/messaging/ListView.h Fri Oct 2 13:01:51 2009
@@ -0,0 +1,67 @@
+#ifndef QPID_MESSAGING_LISTVIEW_H
+#define QPID_MESSAGING_LISTVIEW_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 "qpid/client/ClientImportExport.h"
+#include "Variant.h"
+
+namespace qpid {
+namespace messaging {
+
+class ListViewImpl;
+class Message;
+
+/**
+ * Provides a view of message content as a list
+ */
+class ListView
+{
+ public:
+ typedef Variant::List::const_iterator const_iterator;
+ typedef Variant::List::const_reverse_iterator const_reverse_iterator;
+
+ QPID_CLIENT_EXTERN ListView(const Message&);
+ QPID_CLIENT_EXTERN ~ListView();
+ QPID_CLIENT_EXTERN ListView& operator=(const ListView&);
+
+ QPID_CLIENT_EXTERN const_iterator begin() const;
+ QPID_CLIENT_EXTERN const_iterator end() const;
+ QPID_CLIENT_EXTERN const_reverse_iterator rbegin() const;
+ QPID_CLIENT_EXTERN const_reverse_iterator rend() const;
+
+ QPID_CLIENT_EXTERN bool empty() const;
+ QPID_CLIENT_EXTERN size_t size() const;
+
+ QPID_CLIENT_EXTERN const Variant& front() const;
+ QPID_CLIENT_EXTERN const Variant& back() const;
+
+ QPID_CLIENT_EXTERN const Variant::List& asList() const;
+ private:
+ ListViewImpl* impl;
+};
+
+QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const ListView& m);
+
+}} // namespace qpid::messaging
+
+#endif /*!QPID_MESSAGING_LISTVIEW_H*/
Added: qpid/trunk/qpid/cpp/include/qpid/messaging/MapContent.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/messaging/MapContent.h?rev=821000&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/messaging/MapContent.h (added)
+++ qpid/trunk/qpid/cpp/include/qpid/messaging/MapContent.h Fri Oct 2 13:01:51 2009
@@ -0,0 +1,90 @@
+#ifndef QPID_MESSAGING_MAPCONTENT_H
+#define QPID_MESSAGING_MAPCONTENT_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 "qpid/client/ClientImportExport.h"
+#include "Variant.h"
+#include <map>
+#include <string>
+
+namespace qpid {
+namespace messaging {
+
+class MapContentImpl;
+class Message;
+
+/**
+ * Allows message content to be manipulated as a map
+ */
+class MapContent
+{
+ public:
+ typedef std::string key_type;
+ typedef std::pair<std::string, Variant> value_type;
+ typedef std::map<key_type, Variant>::const_iterator const_iterator;
+ typedef std::map<key_type, Variant>::iterator iterator;
+ typedef std::map<key_type, Variant>::const_reverse_iterator const_reverse_iterator;
+ typedef std::map<key_type, Variant>::reverse_iterator reverse_iterator;
+
+ QPID_CLIENT_EXTERN MapContent(Message&);
+ QPID_CLIENT_EXTERN ~MapContent();
+
+ QPID_CLIENT_EXTERN const_iterator begin() const;
+ QPID_CLIENT_EXTERN const_iterator end() const;
+ QPID_CLIENT_EXTERN const_reverse_iterator rbegin() const;
+ QPID_CLIENT_EXTERN const_reverse_iterator rend() const;
+ QPID_CLIENT_EXTERN iterator begin();
+ QPID_CLIENT_EXTERN iterator end();
+ QPID_CLIENT_EXTERN reverse_iterator rbegin();
+ QPID_CLIENT_EXTERN reverse_iterator rend();
+
+ QPID_CLIENT_EXTERN bool empty() const;
+ QPID_CLIENT_EXTERN size_t size() const;
+
+ QPID_CLIENT_EXTERN const_iterator find(const key_type&) const;
+ QPID_CLIENT_EXTERN iterator find(const key_type&);
+ QPID_CLIENT_EXTERN const Variant& operator[](const key_type&) const;
+ QPID_CLIENT_EXTERN Variant& operator[](const key_type&);
+
+ QPID_CLIENT_EXTERN std::pair<iterator,bool> insert(const value_type&);
+ QPID_CLIENT_EXTERN iterator insert(iterator position, const value_type&);
+ QPID_CLIENT_EXTERN void erase(iterator position);
+ QPID_CLIENT_EXTERN void erase(iterator first, iterator last);
+ QPID_CLIENT_EXTERN size_t erase(const key_type&);
+ QPID_CLIENT_EXTERN void clear();
+
+ QPID_CLIENT_EXTERN void encode();
+
+ QPID_CLIENT_EXTERN const std::map<key_type, Variant>& asMap() const;
+ QPID_CLIENT_EXTERN std::map<key_type, Variant>& asMap();
+ private:
+ MapContentImpl* impl;
+
+ QPID_CLIENT_EXTERN MapContent& operator=(const MapContent&);
+};
+
+QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const MapContent& m);
+
+}} // namespace qpid::messaging
+
+#endif /*!QPID_MESSAGING_MAPCONTENT_H*/
Added: qpid/trunk/qpid/cpp/include/qpid/messaging/MapView.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/messaging/MapView.h?rev=821000&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/messaging/MapView.h (added)
+++ qpid/trunk/qpid/cpp/include/qpid/messaging/MapView.h Fri Oct 2 13:01:51 2009
@@ -0,0 +1,70 @@
+#ifndef QPID_MESSAGING_MAPVIEW_H
+#define QPID_MESSAGING_MAPVIEW_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 "qpid/client/ClientImportExport.h"
+#include "Variant.h"
+#include <map>
+#include <string>
+
+namespace qpid {
+namespace messaging {
+
+class MapViewImpl;
+class Message;
+
+/**
+ * Provides a view of message content as a list
+ */
+class MapView
+{
+ public:
+ typedef std::string key_type;
+ typedef std::pair<key_type, Variant> value_type;
+ typedef std::map<key_type, Variant>::const_iterator const_iterator;
+ typedef std::map<key_type, Variant>::const_reverse_iterator const_reverse_iterator;
+
+ QPID_CLIENT_EXTERN MapView(const Message&);
+ QPID_CLIENT_EXTERN ~MapView();
+ QPID_CLIENT_EXTERN MapView& operator=(const MapView&);
+
+ QPID_CLIENT_EXTERN const_iterator begin() const;
+ QPID_CLIENT_EXTERN const_iterator end() const;
+ QPID_CLIENT_EXTERN const_reverse_iterator rbegin() const;
+ QPID_CLIENT_EXTERN const_reverse_iterator rend() const;
+
+ QPID_CLIENT_EXTERN bool empty() const;
+ QPID_CLIENT_EXTERN size_t size() const;
+
+ QPID_CLIENT_EXTERN const_iterator find(const key_type&) const;
+ QPID_CLIENT_EXTERN const Variant& operator[](const key_type&) const;
+
+ QPID_CLIENT_EXTERN const std::map<key_type, Variant>& asMap() const;
+ private:
+ MapViewImpl* impl;
+};
+
+QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const MapView& m);
+
+}} // namespace qpid::messaging
+
+#endif /*!QPID_MESSAGING_MAPVIEW_H*/
Modified: qpid/trunk/qpid/cpp/include/qpid/messaging/Message.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/messaging/Message.h?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/messaging/Message.h (original)
+++ qpid/trunk/qpid/cpp/include/qpid/messaging/Message.h Fri Oct 2 13:01:51 2009
@@ -24,7 +24,6 @@
#include <string>
#include "qpid/messaging/Variant.h"
-#include "qpid/messaging/MessageContent.h"
#include "qpid/client/ClientImportExport.h"
namespace qpid {
@@ -62,22 +61,11 @@
QPID_CLIENT_EXTERN const VariantMap& getHeaders() const;
QPID_CLIENT_EXTERN VariantMap& getHeaders();
- QPID_CLIENT_EXTERN const std::string& getBytes() const;
- QPID_CLIENT_EXTERN std::string& getBytes();
- QPID_CLIENT_EXTERN void setBytes(const std::string&);
- QPID_CLIENT_EXTERN void setBytes(const char* chars, size_t count);
- QPID_CLIENT_EXTERN const char* getRawContent() const;
- QPID_CLIENT_EXTERN size_t getContentSize() const;
-
-
- QPID_CLIENT_EXTERN MessageContent& getContent();
- QPID_CLIENT_EXTERN const MessageContent& getContent() const;
- QPID_CLIENT_EXTERN void setContent(const std::string& s);
- QPID_CLIENT_EXTERN void setContent(const Variant::Map&);
- QPID_CLIENT_EXTERN void setContent(const Variant::List&);
-
- QPID_CLIENT_EXTERN void encode(Codec&);
- QPID_CLIENT_EXTERN void decode(Codec&);
+ QPID_CLIENT_EXTERN const std::string& getContent() const;
+ QPID_CLIENT_EXTERN std::string& getContent();
+ QPID_CLIENT_EXTERN void setContent(const std::string&);
+ QPID_CLIENT_EXTERN void setContent(const char* chars, size_t count);
+ QPID_CLIENT_EXTERN void getContent(std::pair<const char*, size_t>& content) const;
private:
MessageImpl* impl;
Modified: qpid/trunk/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/Makefile.am?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ qpid/trunk/qpid/cpp/src/Makefile.am Fri Oct 2 13:01:51 2009
@@ -686,6 +686,10 @@
qpid/messaging/Address.cpp \
qpid/messaging/Connection.cpp \
qpid/messaging/Filter.cpp \
+ qpid/messaging/ListContent.cpp \
+ qpid/messaging/ListView.cpp \
+ qpid/messaging/MapContent.cpp \
+ qpid/messaging/MapView.cpp \
qpid/messaging/Message.cpp \
qpid/messaging/MessageImpl.h \
qpid/messaging/MessageImpl.cpp \
@@ -790,8 +794,11 @@
../include/qpid/messaging/Connection.h \
../include/qpid/messaging/Codec.h \
../include/qpid/messaging/Filter.h \
+ ../include/qpid/messaging/ListContent.h \
+ ../include/qpid/messaging/ListView.h \
+ ../include/qpid/messaging/MapContent.h \
+ ../include/qpid/messaging/MapView.h \
../include/qpid/messaging/Message.h \
- ../include/qpid/messaging/MessageContent.h \
../include/qpid/messaging/MessageListener.h \
../include/qpid/messaging/Sender.h \
../include/qpid/messaging/Receiver.h \
Modified: qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/AddressResolution.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/AddressResolution.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/AddressResolution.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/AddressResolution.cpp Fri Oct 2 13:01:51 2009
@@ -362,21 +362,12 @@
void QueueSink::cancel(qpid::client::AsyncSession&, const std::string&) {}
-template <class T> void encode(qpid::messaging::Message& from)
-{
- T codec;
- from.encode(codec);
- from.setContentType(T::contentType);
-}
-
void translate(const Variant::Map& from, FieldTable& to);//implementation in Codecs.cpp
void convert(qpid::messaging::Message& from, qpid::client::Message& to)
{
//TODO: need to avoid copying as much as possible
- if (from.getContent().isList()) encode<ListCodec>(from);
- if (from.getContent().isMap()) encode<MapCodec>(from);
- to.setData(from.getBytes());
+ to.setData(from.getContent());
to.getDeliveryProperties().setRoutingKey(from.getSubject());
//TODO: set other delivery properties
to.getMessageProperties().setContentType(from.getContentType());
Modified: qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/IncomingMessages.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/IncomingMessages.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/IncomingMessages.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/IncomingMessages.cpp Fri Oct 2 13:01:51 2009
@@ -269,18 +269,9 @@
//e.g. for rejecting.
MessageImplAccess::get(message).setInternalId(command.getId());
- command.getContent(message.getBytes());
+ command.getContent(message.getContent());
populateHeaders(message, command.getHeaders());
-
- //decode content if necessary
- if (message.getContentType() == ListCodec::contentType) {
- ListCodec codec;
- message.decode(codec);
- } else if (message.getContentType() == MapCodec::contentType) {
- MapCodec codec;
- message.decode(codec);
- }
}
Modified: qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/OutgoingMessage.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/OutgoingMessage.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/OutgoingMessage.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/OutgoingMessage.cpp Fri Oct 2 13:01:51 2009
@@ -33,24 +33,11 @@
using qpid::messaging::Address;
using qpid::messaging::MessageImplAccess;
-template <class T> void encode(const qpid::messaging::Message& from, qpid::client::Message& to)
-{
- T codec;
- MessageImplAccess::get(from).getEncodedContent(codec, to.getData());
- to.getMessageProperties().setContentType(T::contentType);
-}
-
void OutgoingMessage::convert(const qpid::messaging::Message& from)
{
//TODO: need to avoid copying as much as possible
- if (from.getContent().isList()) {
- encode<ListCodec>(from, message);
- } else if (from.getContent().isMap()) {
- encode<MapCodec>(from, message);
- } else {
- message.setData(from.getBytes());
- message.getMessageProperties().setContentType(from.getContentType());
- }
+ message.setData(from.getContent());
+ message.getMessageProperties().setContentType(from.getContentType());
const Address& address = from.getReplyTo();
if (!address.value.empty()) {
message.getMessageProperties().setReplyTo(AddressResolution::convert(address));
Added: qpid/trunk/qpid/cpp/src/qpid/messaging/ListContent.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/ListContent.cpp?rev=821000&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/ListContent.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/ListContent.cpp Fri Oct 2 13:01:51 2009
@@ -0,0 +1,98 @@
+/*
+ *
+ * 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/ListContent.h"
+#include "qpid/messaging/Message.h"
+#include "qpid/client/amqp0_10/Codecs.h"
+
+namespace qpid {
+namespace messaging {
+
+class ListContentImpl : public Variant
+{
+ Message* msg;
+ public:
+ ListContentImpl(Message& m) : Variant(Variant::List()), msg(&m)
+ {
+ if (msg->getContent().size()) {
+ qpid::client::amqp0_10::ListCodec codec;
+ codec.decode(msg->getContent(), *this);
+ }
+ }
+
+ void encode()
+ {
+ qpid::client::amqp0_10::ListCodec codec;
+ codec.encode(*this, msg->getContent());
+ }
+};
+
+ListContent::ListContent(Message& m) : impl(new ListContentImpl(m)) {}
+ListContent::~ListContent() { delete impl; }
+ListContent& ListContent::operator=(const ListContent& l) { *impl = *l.impl; return *this; }
+
+ListContent::const_iterator ListContent::begin() const { return impl->asList().begin(); }
+ListContent::const_iterator ListContent::end() const { return impl->asList().end(); }
+ListContent::const_reverse_iterator ListContent::rbegin() const { return impl->asList().rbegin(); }
+ListContent::const_reverse_iterator ListContent::rend() const { return impl->asList().rend(); }
+
+ListContent::iterator ListContent::begin() { return impl->asList().begin(); }
+ListContent::iterator ListContent::end() { return impl->asList().end(); }
+ListContent::reverse_iterator ListContent::rbegin() { return impl->asList().rbegin(); }
+ListContent::reverse_iterator ListContent::rend() { return impl->asList().rend(); }
+
+bool ListContent::empty() const { return impl->asList().empty(); }
+size_t ListContent::size() const { return impl->asList().size(); }
+
+const Variant& ListContent::front() const { return impl->asList().front(); }
+Variant& ListContent::front() { return impl->asList().front(); }
+const Variant& ListContent::back() const { return impl->asList().back(); }
+Variant& ListContent::back() { return impl->asList().back(); }
+
+void ListContent::push_front(const Variant& v) { impl->asList().push_front(v); }
+void ListContent::push_back(const Variant& v) { impl->asList().push_back(v); }
+
+void ListContent::pop_front() { impl->asList().pop_front(); }
+void ListContent::pop_back() { impl->asList().pop_back(); }
+
+ListContent::iterator ListContent::insert(iterator position, const Variant& v)
+{
+ return impl->asList().insert(position, v);
+}
+void ListContent::insert(iterator position, size_t n, const Variant& v)
+{
+ impl->asList().insert(position, n, v);
+}
+ListContent::iterator ListContent::erase(iterator position) { return impl->asList().erase(position); }
+ListContent::iterator ListContent::erase(iterator first, iterator last) { return impl->asList().erase(first, last); }
+void ListContent::clear() { impl->asList().clear(); }
+
+void ListContent::encode() { impl->encode(); }
+
+const Variant::List& ListContent::asList() const { return impl->asList(); }
+Variant::List& ListContent::asList() { return impl->asList(); }
+
+std::ostream& operator<<(std::ostream& out, const ListContent& m)
+{
+ out << m.asList();
+ return out;
+}
+
+}} // namespace qpid::messaging
Added: qpid/trunk/qpid/cpp/src/qpid/messaging/ListView.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/ListView.cpp?rev=821000&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/ListView.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/ListView.cpp Fri Oct 2 13:01:51 2009
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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/ListView.h"
+#include "qpid/messaging/Message.h"
+#include "qpid/client/amqp0_10/Codecs.h"
+
+namespace qpid {
+namespace messaging {
+
+class ListViewImpl : public Variant
+{
+ public:
+ ListViewImpl(const Message& msg) : Variant(Variant::List())
+ {
+ if (msg.getContent().size()) {
+ qpid::client::amqp0_10::ListCodec codec;
+ codec.decode(msg.getContent(), *this);
+ }
+ }
+};
+
+ListView::ListView(const Message& m) :impl(new ListViewImpl(m)) {}
+ListView::~ListView() { delete impl; }
+ListView& ListView::operator=(const ListView& l) { *impl = *l.impl; return *this; }
+
+ListView::const_iterator ListView::begin() const { return impl->asList().begin(); }
+ListView::const_iterator ListView::end() const { return impl->asList().end(); }
+ListView::const_reverse_iterator ListView::rbegin() const { return impl->asList().rbegin(); }
+ListView::const_reverse_iterator ListView::rend() const { return impl->asList().rend(); }
+
+bool ListView::empty() const { return impl->asList().empty(); }
+size_t ListView::size() const { return impl->asList().size(); }
+
+const Variant& ListView::front() const { return impl->asList().front(); }
+const Variant& ListView::back() const { return impl->asList().back(); }
+
+const Variant::List& ListView::asList() const { return impl->asList(); }
+
+std::ostream& operator<<(std::ostream& out, const ListView& m)
+{
+ out << m.asList();
+ return out;
+}
+
+}} // namespace qpid::messaging
Added: qpid/trunk/qpid/cpp/src/qpid/messaging/MapContent.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/MapContent.cpp?rev=821000&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/MapContent.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/MapContent.cpp Fri Oct 2 13:01:51 2009
@@ -0,0 +1,87 @@
+/*
+ *
+ * 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/MapContent.h"
+#include "qpid/messaging/Message.h"
+#include "qpid/client/amqp0_10/Codecs.h"
+
+namespace qpid {
+namespace messaging {
+
+class MapContentImpl : public Variant
+{
+ Message* msg;
+ public:
+ MapContentImpl(Message& m) : Variant(Variant::Map()), msg(&m)
+ {
+ if (msg->getContent().size()) {
+ qpid::client::amqp0_10::MapCodec codec;
+ codec.decode(msg->getContent(), *this);
+ }
+ }
+
+ void encode()
+ {
+ qpid::client::amqp0_10::MapCodec codec;
+ codec.encode(*this, msg->getContent());
+ }
+};
+
+MapContent::MapContent(Message& m) : impl(new MapContentImpl(m)) {}
+MapContent::~MapContent() { delete impl; }
+MapContent& MapContent::operator=(const MapContent& m) { *impl = *m.impl; return *this; }
+
+MapContent::const_iterator MapContent::begin() const { return impl->asMap().begin(); }
+MapContent::const_iterator MapContent::end() const { return impl->asMap().end(); }
+MapContent::const_reverse_iterator MapContent::rbegin() const { return impl->asMap().rbegin(); }
+MapContent::const_reverse_iterator MapContent::rend() const { return impl->asMap().rend(); }
+MapContent::iterator MapContent::begin() { return impl->asMap().begin(); }
+MapContent::iterator MapContent::end() { return impl->asMap().end(); }
+MapContent::reverse_iterator MapContent::rbegin() { return impl->asMap().rbegin(); }
+MapContent::reverse_iterator MapContent::rend() { return impl->asMap().rend(); }
+
+bool MapContent::empty() const { return impl->asMap().empty(); }
+size_t MapContent::size() const { return impl->asMap().size(); }
+
+MapContent::const_iterator MapContent::find(const key_type& key) const { return impl->asMap().find(key); }
+MapContent::iterator MapContent::find(const key_type& key) { return impl->asMap().find(key); }
+const Variant& MapContent::operator[](const key_type& key) const { return impl->asMap()[key]; }
+Variant& MapContent::operator[](const key_type& key) { return impl->asMap()[key]; }
+
+std::pair<MapContent::iterator,bool> MapContent::insert(const value_type& item) { return impl->asMap().insert(item); }
+MapContent::iterator MapContent::insert(iterator position, const value_type& item) { return impl->asMap().insert(position, item); }
+void MapContent::erase(iterator position) { impl->asMap().erase(position); }
+void MapContent::erase(iterator first, iterator last) { impl->asMap().erase(first, last); }
+size_t MapContent::erase(const key_type& key) { return impl->asMap().erase(key); }
+void MapContent::clear() { impl->asMap().clear(); }
+
+void MapContent::encode() { impl->encode(); }
+
+const std::map<MapContent::key_type, Variant>& MapContent::asMap() const { return impl->asMap(); }
+std::map<MapContent::key_type, Variant>& MapContent::asMap() { return impl->asMap(); }
+
+
+std::ostream& operator<<(std::ostream& out, const MapContent& m)
+{
+ out << m.asMap();
+ return out;
+}
+
+}} // namespace qpid::messaging
Added: qpid/trunk/qpid/cpp/src/qpid/messaging/MapView.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/MapView.cpp?rev=821000&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/MapView.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/MapView.cpp Fri Oct 2 13:01:51 2009
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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/MapView.h"
+#include "qpid/messaging/Message.h"
+#include "qpid/client/amqp0_10/Codecs.h"
+
+namespace qpid {
+namespace messaging {
+
+class MapViewImpl : public Variant
+{
+ public:
+ MapViewImpl(const Message& msg) : Variant(Variant::Map())
+ {
+ if (msg.getContent().size()) {
+ qpid::client::amqp0_10::MapCodec codec;
+ codec.decode(msg.getContent(), *this);
+ }
+ }
+};
+
+MapView::MapView(const Message& m) : impl(new MapViewImpl(m)) {}
+MapView::~MapView() { delete impl; }
+MapView& MapView::operator=(const MapView& m) { *impl = *m.impl; return *this; }
+
+MapView::const_iterator MapView::begin() const { return impl->asMap().begin(); }
+MapView::const_iterator MapView::end() const { return impl->asMap().end(); }
+MapView::const_reverse_iterator MapView::rbegin() const { return impl->asMap().rbegin(); }
+MapView::const_reverse_iterator MapView::rend() const { return impl->asMap().rend(); }
+
+bool MapView::empty() const { return impl->asMap().empty(); }
+size_t MapView::size() const { return impl->asMap().size(); }
+
+MapView::const_iterator MapView::find(const key_type& key) const { return impl->asMap().find(key); }
+const Variant& MapView::operator[](const key_type& key) const { return impl->asMap()[key]; }
+
+const std::map<MapView::key_type, Variant>& MapView::asMap() const { return impl->asMap(); }
+
+std::ostream& operator<<(std::ostream& out, const MapView& m)
+{
+ out << m.asMap();
+ return out;
+}
+
+}} // namespace qpid::messaging
Modified: qpid/trunk/qpid/cpp/src/qpid/messaging/Message.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/Message.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/Message.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/Message.cpp Fri Oct 2 13:01:51 2009
@@ -27,7 +27,7 @@
Message::Message(const std::string& bytes) : impl(new MessageImpl(bytes)) {}
Message::Message(const char* bytes, size_t count) : impl(new MessageImpl(bytes, count)) {}
-Message::Message(const Message& m) : impl(new MessageImpl(m.getBytes())) {}
+Message::Message(const Message& m) : impl(new MessageImpl(m.getContent())) {}
Message::~Message() { delete impl; }
Message& Message::operator=(const Message& m) { *impl = *m.impl; return *this; }
@@ -44,27 +44,15 @@
const VariantMap& Message::getHeaders() const { return impl->getHeaders(); }
VariantMap& Message::getHeaders() { return impl->getHeaders(); }
-void Message::setBytes(const std::string& c) { impl->setBytes(c); }
-void Message::setBytes(const char* chars, size_t count) { impl->setBytes(chars, count); }
-const std::string& Message::getBytes() const { return impl->getBytes(); }
-std::string& Message::getBytes() { return impl->getBytes(); }
+void Message::setContent(const std::string& c) { impl->setBytes(c); }
+void Message::setContent(const char* chars, size_t count) { impl->setBytes(chars, count); }
+const std::string& Message::getContent() const { return impl->getBytes(); }
+std::string& Message::getContent() { return impl->getBytes(); }
-const char* Message::getRawContent() const { return impl->getBytes().data(); }
-size_t Message::getContentSize() const { return impl->getBytes().size(); }
-
-MessageContent& Message::getContent() { return *impl; }
-const MessageContent& Message::getContent() const { return *impl; }
-void Message::setContent(const std::string& s) { *impl = s; }
-void Message::setContent(const Variant::Map& m) { *impl = m; }
-void Message::setContent(const Variant::List& l) { *impl = l; }
-
-void Message::encode(Codec& codec) { impl->encode(codec); }
-
-void Message::decode(Codec& codec) { impl->decode(codec); }
-
-std::ostream& operator<<(std::ostream& out, const MessageContent& content)
+void Message::getContent(std::pair<const char*, size_t>& content) const
{
- return content.print(out);
+ content.first = impl->getBytes().data();
+ content.second = impl->getBytes().size();
}
}} // namespace qpid::messaging
Modified: qpid/trunk/qpid/cpp/src/qpid/messaging/MessageImpl.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/MessageImpl.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/MessageImpl.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/MessageImpl.cpp Fri Oct 2 13:01:51 2009
@@ -28,8 +28,8 @@
const std::string EMPTY_STRING = "";
}
-MessageImpl::MessageImpl(const std::string& c) : bytes(c), type(VAR_VOID), internalId(0) {}
-MessageImpl::MessageImpl(const char* chars, size_t count) : bytes(chars, count), type(VAR_VOID), internalId(0) {}
+MessageImpl::MessageImpl(const std::string& c) : bytes(c), internalId(0) {}
+MessageImpl::MessageImpl(const char* chars, size_t count) : bytes(chars, count), internalId(0) {}
void MessageImpl::setReplyTo(const Address& d) { replyTo = d; }
const Address& MessageImpl::getReplyTo() const { return replyTo; }
@@ -44,155 +44,14 @@
VariantMap& MessageImpl::getHeaders() { return headers; }
//should these methods be on MessageContent?
-void MessageImpl::setBytes(const std::string& c) { clear(); bytes = c; }
-void MessageImpl::setBytes(const char* chars, size_t count) { clear(); bytes.assign(chars, count); }
+void MessageImpl::setBytes(const std::string& c) { bytes = c; }
+void MessageImpl::setBytes(const char* chars, size_t count) { bytes.assign(chars, count); }
const std::string& MessageImpl::getBytes() const { return bytes; }
std::string& MessageImpl::getBytes() { return bytes; }
-
-Variant& MessageImpl::operator[](const std::string& key) { return asMap()[key]; }
-
-std::ostream& MessageImpl::print(std::ostream& out) const
-{
- if (type == VAR_MAP) {
- return out << content.asMap();
- } else if (type == VAR_LIST) {
- return out << content.asList();
- } else {
- return out << bytes;
- }
-}
-
-template <class T> MessageContent& MessageImpl::append(T& t)
-{
- if (type == VAR_VOID) {
- //TODO: this is inefficient, probably want to hold on to the stream object
- std::stringstream s;
- s << bytes;
- s << t;
- bytes = s.str();
- } else if (type == VAR_LIST) {
- content.asList().push_back(Variant(t));
- } else {
- throw InvalidConversion("<< operator only valid on strings and lists");
- }
- return *this;
-}
-
-MessageContent& MessageImpl::operator<<(const std::string& v) { return append(v); }
-MessageContent& MessageImpl::operator<<(const char* v) { return append(v); }
-MessageContent& MessageImpl::operator<<(bool v) { return append(v); }
-MessageContent& MessageImpl::operator<<(int8_t v) { return append(v); }
-MessageContent& MessageImpl::operator<<(int16_t v) { return append(v); }
-MessageContent& MessageImpl::operator<<(int32_t v) { return append(v); }
-MessageContent& MessageImpl::operator<<(int64_t v) { return append(v); }
-MessageContent& MessageImpl::operator<<(uint8_t v) { return append(v); }
-MessageContent& MessageImpl::operator<<(uint16_t v) { return append(v); }
-MessageContent& MessageImpl::operator<<(uint32_t v) { return append(v); }
-MessageContent& MessageImpl::operator<<(uint64_t v) { return append(v); }
-MessageContent& MessageImpl::operator<<(double v) { return append(v); }
-MessageContent& MessageImpl::operator<<(float v) { return append(v); }
-MessageContent& MessageImpl::operator=(const std::string& s)
-{
- type = VAR_VOID;
- bytes = s;
- return *this;
-}
-MessageContent& MessageImpl::operator=(const char* c)
-{
- type = VAR_VOID;
- bytes = c;
- return *this;
-}
-MessageContent& MessageImpl::operator=(const Variant::Map& m)
-{
- type = VAR_MAP;
- content = m;
- return *this;
-}
-
-MessageContent& MessageImpl::operator=(const Variant::List& l)
-{
- type = VAR_LIST;
- content = l;
- return *this;
-}
-
-void MessageImpl::encode(Codec& codec)
-{
- if (content.getType() != VAR_VOID) {
- bytes = EMPTY_STRING;
- codec.encode(content, bytes);
- }
-}
-
-void MessageImpl::getEncodedContent(Codec& codec, std::string& out) const
-{
- if (content.getType() != VAR_VOID) {
- codec.encode(content, out);
- } else {
- out = bytes;
- }
-}
-
-void MessageImpl::decode(Codec& codec)
-{
- codec.decode(bytes, content);
- if (content.getType() == VAR_MAP) type = VAR_MAP;
- else if (content.getType() == VAR_LIST) type = VAR_LIST;
- else type = VAR_VOID;//TODO: what if codec set some type other than map or list??
-}
-
void MessageImpl::setInternalId(qpid::framing::SequenceNumber i) { internalId = i; }
qpid::framing::SequenceNumber MessageImpl::getInternalId() { return internalId; }
-bool MessageImpl::isVoid() const { return type == VAR_VOID; }
-
-const std::string& MessageImpl::asString() const
-{
- if (isVoid()) return getBytes();
- else return content.getString();//will throw an error
-}
-std::string& MessageImpl::asString()
-{
- if (isVoid()) return getBytes();
- else return content.getString();//will throw an error
-}
-
-const char* MessageImpl::asChars() const
-{
- if (!isVoid()) throw InvalidConversion("Content is of structured type.");
- return bytes.data();
-}
-size_t MessageImpl::size() const
-{
- return bytes.size();
-}
-
-const Variant::Map& MessageImpl::asMap() const { return content.asMap(); }
-Variant::Map& MessageImpl::asMap()
-{
- if (isVoid()) {
- content = Variant::Map();
- type = VAR_MAP;
- }
- return content.asMap();
-}
-bool MessageImpl::isMap() const { return type == VAR_MAP; }
-
-const Variant::List& MessageImpl::asList() const { return content.asList(); }
-Variant::List& MessageImpl::asList()
-{
- if (isVoid()) {
- content = Variant::List();
- type = VAR_LIST;
- }
- return content.asList();
-}
-bool MessageImpl::isList() const { return type == VAR_LIST; }
-
-void MessageImpl::clear() { bytes = EMPTY_STRING; content.reset(); type = VAR_VOID; }
-
MessageImpl& MessageImplAccess::get(Message& msg)
{
return *msg.impl;
Modified: qpid/trunk/qpid/cpp/src/qpid/messaging/MessageImpl.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/MessageImpl.h?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/MessageImpl.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/MessageImpl.h Fri Oct 2 13:01:51 2009
@@ -22,15 +22,13 @@
*
*/
#include "qpid/messaging/Address.h"
-#include "qpid/messaging/Codec.h"
-#include "qpid/messaging/MessageContent.h"
#include "qpid/messaging/Variant.h"
#include "qpid/framing/SequenceNumber.h"
namespace qpid {
namespace messaging {
-struct MessageImpl : MessageContent
+struct MessageImpl
{
Address replyTo;
std::string subject;
@@ -38,8 +36,6 @@
Variant::Map headers;
std::string bytes;
- Variant content;//used only for LIST and MAP
- VariantType type;//if LIST, MAP content holds the value; if VOID bytes holds the value
qpid::framing::SequenceNumber internalId;
@@ -66,54 +62,6 @@
void setInternalId(qpid::framing::SequenceNumber id);
qpid::framing::SequenceNumber getInternalId();
- bool isVoid() const;
-
- const std::string& asString() const;
- std::string& asString();
-
- const char* asChars() const;
- size_t size() const;
-
- const Variant::Map& asMap() const;
- Variant::Map& asMap();
- bool isMap() const;
-
- const Variant::List& asList() const;
- Variant::List& asList();
- bool isList() const;
-
- void clear();
-
- void getEncodedContent(Codec& codec, std::string&) const;
- void encode(Codec& codec);
- void decode(Codec& codec);
-
- Variant& operator[](const std::string&);
-
- std::ostream& print(std::ostream& out) const;
-
- //operator<< for variety of types...
- MessageContent& operator<<(const std::string&);
- MessageContent& operator<<(const char*);
- MessageContent& operator<<(bool);
- MessageContent& operator<<(int8_t);
- MessageContent& operator<<(int16_t);
- MessageContent& operator<<(int32_t);
- MessageContent& operator<<(int64_t);
- MessageContent& operator<<(uint8_t);
- MessageContent& operator<<(uint16_t);
- MessageContent& operator<<(uint32_t);
- MessageContent& operator<<(uint64_t);
- MessageContent& operator<<(double);
- MessageContent& operator<<(float);
-
- //assignment from string, map and list
- MessageContent& operator=(const std::string&);
- MessageContent& operator=(const char*);
- MessageContent& operator=(const Variant::Map&);
- MessageContent& operator=(const Variant::List&);
-
- template <class T> MessageContent& append(T& t);
};
class Message;
Modified: qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp?rev=821000&r1=820999&r2=821000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp Fri Oct 2 13:01:51 2009
@@ -22,6 +22,10 @@
#include "test_tools.h"
#include "BrokerFixture.h"
#include "qpid/messaging/Connection.h"
+#include "qpid/messaging/ListContent.h"
+#include "qpid/messaging/ListView.h"
+#include "qpid/messaging/MapContent.h"
+#include "qpid/messaging/MapView.h"
#include "qpid/messaging/Message.h"
#include "qpid/messaging/MessageListener.h"
#include "qpid/messaging/Receiver.h"
@@ -160,7 +164,7 @@
std::vector<std::string> messageData;
void received(Message& message) {
- messageData.push_back(message.getBytes());
+ messageData.push_back(message.getContent());
}
};
@@ -169,7 +173,7 @@
std::vector<std::string> data;
Message message;
for (int i = 0; i < count && receiver.fetch(message, timeout); i++) {
- data.push_back(message.getBytes());
+ data.push_back(message.getContent());
}
return data;
}
@@ -183,7 +187,7 @@
Receiver receiver = fix.session.createReceiver(fix.queue);
Message in = receiver.fetch(5 * qpid::sys::TIME_SEC);
fix.session.acknowledge();
- BOOST_CHECK_EQUAL(in.getBytes(), out.getBytes());
+ BOOST_CHECK_EQUAL(in.getContent(), out.getContent());
}
QPID_AUTO_TEST_CASE(testSendReceiveHeaders)
@@ -199,7 +203,7 @@
Message in;
for (uint i = 0; i < 10; ++i) {
BOOST_CHECK(receiver.fetch(in, 5 * qpid::sys::TIME_SEC));
- BOOST_CHECK_EQUAL(in.getBytes(), out.getBytes());
+ BOOST_CHECK_EQUAL(in.getContent(), out.getContent());
BOOST_CHECK_EQUAL(in.getHeaders()["a"].asUint32(), i);
fix.session.acknowledge();
}
@@ -229,22 +233,22 @@
Receiver sub1 = fix.session.createReceiver(fix.topic);
sub1.setCapacity(10u);
sub1.start();
- msg.setBytes("two");
+ msg.setContent("two");
sender.send(msg);
Receiver sub2 = fix.session.createReceiver(fix.topic);
sub2.setCapacity(10u);
sub2.start();
- msg.setBytes("three");
+ msg.setContent("three");
sender.send(msg);
Receiver sub3 = fix.session.createReceiver(fix.topic);
sub3.setCapacity(10u);
sub3.start();
- msg.setBytes("four");
+ msg.setContent("four");
sender.send(msg);
BOOST_CHECK_EQUAL(fetch(sub2, 2), boost::assign::list_of<std::string>("three")("four"));
sub2.cancel();
- msg.setBytes("five");
+ msg.setContent("five");
sender.send(msg);
BOOST_CHECK_EQUAL(fetch(sub1, 4), boost::assign::list_of<std::string>("two")("three")("four")("five"));
BOOST_CHECK_EQUAL(fetch(sub3, 2), boost::assign::list_of<std::string>("four")("five"));
@@ -274,7 +278,7 @@
for (uint i = 0; i < fix.queues.size(); i++) {
Message msg;
BOOST_CHECK(fix.session.fetch(msg, qpid::sys::TIME_SEC));
- BOOST_CHECK_EQUAL(msg.getBytes(), (boost::format("Message_%1%") % (i+1)).str());
+ BOOST_CHECK_EQUAL(msg.getContent(), (boost::format("Message_%1%") % (i+1)).str());
}
}
@@ -307,13 +311,16 @@
QueueFixture fix;
Sender sender = fix.session.createSender(fix.queue);
Message out;
- out.getContent().asMap()["abc"] = "def";
- out.getContent().asMap()["pi"] = 3.14f;
+ MapContent content(out);
+ content["abc"] = "def";
+ content["pi"] = 3.14f;
+ content.encode();
sender.send(out);
Receiver receiver = fix.session.createReceiver(fix.queue);
Message in = receiver.fetch(5 * qpid::sys::TIME_SEC);
- BOOST_CHECK_EQUAL(in.getContent().asMap()["abc"].asString(), "def");
- BOOST_CHECK_EQUAL(in.getContent().asMap()["pi"].asFloat(), 3.14f);
+ MapView view(in);
+ BOOST_CHECK_EQUAL(view["abc"].asString(), "def");
+ BOOST_CHECK_EQUAL(view["pi"].asFloat(), 3.14f);
fix.session.acknowledge();
}
@@ -322,23 +329,31 @@
QueueFixture fix;
Sender sender = fix.session.createSender(fix.queue);
Message out;
- out.getContent() = Variant::List();
- out.getContent() << "abc";
- out.getContent() << 1234;
- out.getContent() << "def";
- out.getContent() << 56.789;
+ ListContent content(out);
+ content.push_back(Variant("abc"));
+ content.push_back(Variant(1234));
+ content.push_back(Variant("def"));
+ content.push_back(Variant(56.789));
+ content.encode();
sender.send(out);
Receiver receiver = fix.session.createReceiver(fix.queue);
Message in = receiver.fetch(5 * qpid::sys::TIME_SEC);
- Variant::List& list = in.getContent().asList();
- BOOST_CHECK_EQUAL(list.size(), out.getContent().asList().size());
- BOOST_CHECK_EQUAL(list.front().asString(), "abc");
- list.pop_front();
- BOOST_CHECK_EQUAL(list.front().asInt64(), 1234);
- list.pop_front();
- BOOST_CHECK_EQUAL(list.front().asString(), "def");
- list.pop_front();
- BOOST_CHECK_EQUAL(list.front().asDouble(), 56.789);
+ ListView view(in);
+ BOOST_CHECK_EQUAL(view.size(), content.size());
+ BOOST_CHECK_EQUAL(view.front().asString(), "abc");
+ BOOST_CHECK_EQUAL(view.back().asDouble(), 56.789);
+
+ ListView::const_iterator i = view.begin();
+ BOOST_CHECK(i != view.end());
+ BOOST_CHECK_EQUAL(i->asString(), "abc");
+ BOOST_CHECK(++i != view.end());
+ BOOST_CHECK_EQUAL(i->asInt64(), 1234);
+ BOOST_CHECK(++i != view.end());
+ BOOST_CHECK_EQUAL(i->asString(), "def");
+ BOOST_CHECK(++i != view.end());
+ BOOST_CHECK_EQUAL(i->asDouble(), 56.789);
+ BOOST_CHECK(++i == view.end());
+
fix.session.acknowledge();
}
@@ -352,10 +367,10 @@
sender.send(m2);
Receiver receiver = fix.session.createReceiver(fix.queue);
Message in = receiver.fetch(5 * qpid::sys::TIME_SEC);
- BOOST_CHECK_EQUAL(in.getBytes(), m1.getBytes());
+ BOOST_CHECK_EQUAL(in.getContent(), m1.getContent());
fix.session.reject(in);
in = receiver.fetch(5 * qpid::sys::TIME_SEC);
- BOOST_CHECK_EQUAL(in.getBytes(), m2.getBytes());
+ BOOST_CHECK_EQUAL(in.getContent(), m2.getContent());
fix.session.acknowledge();
}
@@ -384,15 +399,15 @@
for (uint i = 0; i < 5; ++i) {
BOOST_CHECK_EQUAL(fix.session.available(), 15u - 2*i);
BOOST_CHECK_EQUAL(r1.available(), 10u - i);
- BOOST_CHECK_EQUAL(r1.fetch().getBytes(), (boost::format("A_%1%") % (i+1)).str());
+ BOOST_CHECK_EQUAL(r1.fetch().getContent(), (boost::format("A_%1%") % (i+1)).str());
BOOST_CHECK_EQUAL(r2.available(), 5u - i);
- BOOST_CHECK_EQUAL(r2.fetch().getBytes(), (boost::format("B_%1%") % (i+1)).str());
+ BOOST_CHECK_EQUAL(r2.fetch().getContent(), (boost::format("B_%1%") % (i+1)).str());
fix.session.acknowledge();
}
for (uint i = 5; i < 10; ++i) {
BOOST_CHECK_EQUAL(fix.session.available(), 10u - i);
BOOST_CHECK_EQUAL(r1.available(), 10u - i);
- BOOST_CHECK_EQUAL(r1.fetch().getBytes(), (boost::format("A_%1%") % (i+1)).str());
+ BOOST_CHECK_EQUAL(r1.fetch().getContent(), (boost::format("A_%1%") % (i+1)).str());
}
}
@@ -405,7 +420,7 @@
}
Receiver receiver = fix.session.createReceiver(fix.queue);
for (uint i = 0; i < 10; ++i) {
- BOOST_CHECK_EQUAL(receiver.fetch().getBytes(), (boost::format("Message_%1%") % (i+1)).str());
+ BOOST_CHECK_EQUAL(receiver.fetch().getContent(), (boost::format("Message_%1%") % (i+1)).str());
}
BOOST_CHECK_EQUAL(fix.session.pendingAck(), 0u);
fix.session.acknowledge();
@@ -431,7 +446,7 @@
Receiver receiver = fix.session.createReceiver(fix.queue);
for (uint i = 0; i < 10; ++i) {
- BOOST_CHECK_EQUAL(receiver.fetch().getBytes(), (boost::format("Message_%1%") % (i+1)).str());
+ BOOST_CHECK_EQUAL(receiver.fetch().getContent(), (boost::format("Message_%1%") % (i+1)).str());
}
fix.session.acknowledge();
}
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org