qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject svn commit: r587480 - in /incubator/qpid/trunk/qpid/cpp/src: qpid/broker/QueuePolicy.cpp qpid/framing/FieldTable.cpp qpid/framing/FieldTable.h qpid/framing/FieldValue.h tests/FieldValue.cpp tests/Makefile.am
Date Tue, 23 Oct 2007 12:41:17 GMT
Author: astitcher
Date: Tue Oct 23 05:41:16 2007
New Revision: 587480

URL: http://svn.apache.org/viewvc?rev=587480&view=rev
Log:
More tidying up of field table API

Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/QueuePolicy.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h
    incubator/qpid/trunk/qpid/cpp/src/tests/FieldValue.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/QueuePolicy.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/QueuePolicy.cpp?rev=587480&r1=587479&r2=587480&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/QueuePolicy.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/QueuePolicy.cpp Tue Oct 23 05:41:16 2007
@@ -19,6 +19,7 @@
  *
  */
 #include "QueuePolicy.h"
+#include "qpid/framing/FieldValue.h"
 
 using namespace qpid::broker;
 using namespace qpid::framing;
@@ -60,7 +61,7 @@
     //      restricts the values that can be set on the queue policy.
     try {
         return settings.getInt(key); 
-    } catch (FieldNotFoundException& ignore) {
+    } catch (FieldValueException& ignore) {
         return defaultValue;
     }
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp?rev=587480&r1=587479&r2=587480&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp Tue Oct 23 05:41:16 2007
@@ -104,9 +104,9 @@
     return value->get<T>();
 }
 
-//std::string FieldTable::getString(const std::string& name) const {
-//    return getValue<std::string>(name);
-//}
+std::string FieldTable::getString(const std::string& name) const {
+    return getValue<std::string>(get(name));
+}
 
 int FieldTable::getInt(const std::string& name) const {
     return getValue<int>(get(name));

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.h?rev=587480&r1=587479&r2=587480&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.h Tue Oct 23 05:41:16 2007
@@ -64,7 +64,7 @@
     void setTable(const std::string& name, const FieldTable& value);
     //void setDecimal(string& name, xxx& value);
 
-//    std::string getString(const std::string& name) const;
+    std::string getString(const std::string& name) const;
     int getInt(const std::string& name) const;
 //    uint64_t getTimestamp(const std::string& name) const;
 //    void getTable(const std::string& name, FieldTable& value) const;
@@ -86,9 +86,9 @@
     friend std::ostream& operator<<(std::ostream& out, const FieldTable&
body);
 };
 
-class FieldNotFoundException{};
-class UnknownFieldName : public FieldNotFoundException{};
-class IncorrectFieldType : public FieldNotFoundException{};
+//class FieldNotFoundException{};
+//class UnknownFieldName : public FieldNotFoundException{};
+//class IncorrectFieldType : public FieldNotFoundException{};
 }
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h?rev=587480&r1=587479&r2=587480&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h Tue Oct 23 05:41:16 2007
@@ -21,6 +21,7 @@
  *
  */
 
+#include "qpid/Exception.h"
 #include "Buffer.h"
 #include "amqp_types.h"
 
@@ -34,6 +35,22 @@
 namespace framing {
 
 /**
+ * Exception that is base exception for all field table errors 
+ * 
+ * \ingroup clientapi
+ */
+class FieldValueException : public qpid::Exception {};
+
+/**
+ * Exception thrown when we can't perform requested conversion
+ * 
+ * \ingroup clientapi
+ */
+struct InvalidConversionException : public FieldValueException {
+    InvalidConversionException() {}
+};
+
+/**
  * Value that can appear in an AMQP field table
  *
  * \ingroup clientapi
@@ -51,10 +68,10 @@
         virtual void decode(Buffer& buffer) = 0;
         virtual bool operator==(const Data&) const = 0;
 
-        virtual bool convertsToInt() const { assert(0!=0); return false; }
+        virtual bool convertsToInt() const { return false; }
         virtual bool convertsToString() const { return false; }
-        virtual int64_t getInt() const { assert(0!=0); return 0;}
-        virtual std::string getString() const { assert(0!=0); return ""; }
+        virtual int64_t getInt() const { throw InvalidConversionException();}
+        virtual std::string getString() const { throw InvalidConversionException(); }
 
         virtual void print(std::ostream& out) const = 0;
     };
@@ -70,7 +87,7 @@
     void print(std::ostream& out) const { out << "(0x" << std::hex <<
int(typeOctet) << ")"; data->print(out); }
     
     template <typename T> bool convertsTo() const { return false; }
-    template <typename T> T get() const;
+    template <typename T> T get() const { throw InvalidConversionException(); }
 
   protected:
     FieldValue(uint8_t t, Data* d): typeOctet(t), data(d) {}
@@ -172,6 +189,10 @@
         if (rhs == 0) return false;
         else return octets==rhs->octets; 
     }
+    
+    bool convertsToString() const { return true; }
+    std::string getString() const { return std::string(octets.begin(), octets.end()); }
+
     void print(std::ostream& o) const { o << "V" << lenwidth << ":"
<< octets.size() << ":"; };
 };
 

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/FieldValue.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/FieldValue.cpp?rev=587480&r1=587479&r2=587480&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/FieldValue.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/FieldValue.cpp Tue Oct 23 05:41:16 2007
@@ -35,7 +35,12 @@
     BOOST_CHECK(StringValue("abc") == s);
     BOOST_CHECK(StringValue("foo") != s);
     BOOST_CHECK(s != i);
+    BOOST_CHECK(s.convertsTo<std::string>() == true);
+    BOOST_CHECK(s.convertsTo<int>() == false);
+    BOOST_CHECK(s.get<std::string>() == "abc");
+    BOOST_CHECK_THROW(s.get<int>(), InvalidConversionException);
 //    BOOST_CHECK(s != ft);
+
 }
 
 BOOST_AUTO_TEST_CASE(testIntegerValueEquals)
@@ -43,6 +48,10 @@
     BOOST_CHECK(IntegerValue(42) == i);
     BOOST_CHECK(IntegerValue(5) != i);
     BOOST_CHECK(i != s);
+    BOOST_CHECK(i.convertsTo<std::string>() == false);
+    BOOST_CHECK(i.convertsTo<int>() == true);
+    BOOST_CHECK_THROW(i.get<std::string>(), InvalidConversionException);
+    BOOST_CHECK(i.get<int>() == 42);
 //    BOOST_CHECK(i != ft);
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am?rev=587480&r1=587479&r2=587480&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am Tue Oct 23 05:41:16 2007
@@ -113,7 +113,7 @@
   ClientSessionTest
 
 #client_unit_tests =	\
-  ClientChannelTest     
+#  ClientChannelTest     
 
 framing_unit_tests =	\
   FramingTest		\
@@ -139,8 +139,7 @@
   topic_publisher	
 #  echo_service
 
-#check_PROGRAMS += $(testprogs) interop_runner
-check_PROGRAMS += $(testprogs)
+check_PROGRAMS += $(testprogs) interop_runner
 
 TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir) $(srcdir)/run_test
 
@@ -201,14 +200,14 @@
 CLEANFILES+=valgrind.out *.log *.vglog .valgrindrc .valgrind.supp dummy_test $(unit_wrappers)
 MAINTAINERCLEANFILES=gen.mk
 
-#interop_runner_SOURCES = 	\
-#  interop_runner.cpp	 	\
-#  SimpleTestCaseBase.cpp	\
-#  BasicP2PTest.cpp		\
-#  BasicPubSubTest.cpp		\
-#  SimpleTestCaseBase.h		\
-#  BasicP2PTest.h		\
-#  BasicPubSubTest.h		\
-#  TestCase.h			\
-#  TestOptions.h
-#interop_runner_LDADD = $(lib_client) $(lib_common) $(extra_libs)
+interop_runner_SOURCES = 	\
+  interop_runner.cpp	 	\
+  SimpleTestCaseBase.cpp	\
+  BasicP2PTest.cpp		\
+  BasicPubSubTest.cpp		\
+  SimpleTestCaseBase.h		\
+  BasicP2PTest.h		\
+  BasicPubSubTest.h		\
+  TestCase.h			\
+  TestOptions.h
+interop_runner_LDADD = $(lib_client) $(lib_common) $(extra_libs)



Mime
View raw message