diff --git a/include/array.h b/include/array.h index 054fac6..e6b351a 100644 --- a/include/array.h +++ b/include/array.h @@ -141,7 +141,7 @@ public: { return ArrayFieldProxy(this, index); } - + /** * Get a const field * @param index field index @@ -168,6 +168,16 @@ public: return 'A'; } + /** + * We are an array field + * + * @return true, because we are an array + */ + bool isArray() const override + { + return true; + } + /** * Output the object to a stream * @param std::ostream @@ -176,27 +186,27 @@ public: { // prefix stream << "array("; - + // is this the first iteration bool first = true; - + // loop through all members - for (auto &iter : _fields) + for (auto &iter : _fields) { // split with comma if (!first) stream << ","; - + // show output stream << *iter; - + // no longer first iter first = false; } - + // postfix stream << ")"; } - + /** * Cast to array * @return Array diff --git a/include/booleanset.h b/include/booleanset.h index 9c4dabb..eac186b 100644 --- a/include/booleanset.h +++ b/include/booleanset.h @@ -163,6 +163,16 @@ public: return 't'; } + /** + * We are a boolean field + * + * @return true, because we are a boolean + */ + bool isBoolean() const override + { + return true; + } + /** * Get the size this field will take when * encoded in the AMQP wire-frame format diff --git a/include/decimalfield.h b/include/decimalfield.h index 67ac372..f0171b8 100644 --- a/include/decimalfield.h +++ b/include/decimalfield.h @@ -202,6 +202,16 @@ public: return *this; } + /** + * We are a decimal field + * + * @return true, because we are a decimal field + */ + bool isDecimal() const override + { + return true; + } + /** * Get the type ID that is used to identify this type of * field in a field table diff --git a/include/envelope.h b/include/envelope.h index ae9780f..6b80d39 100644 --- a/include/envelope.h +++ b/include/envelope.h @@ -79,6 +79,7 @@ public: * @param envelope the envelope to move */ Envelope(Envelope &&envelope) : + MetaData(std::move(envelope)), _str(std::move(envelope._str)), _body(_str.data()), _bodySize(_str.size()) diff --git a/include/field.h b/include/field.h index d6a7a88..a7a24ae 100644 --- a/include/field.h +++ b/include/field.h @@ -1,7 +1,7 @@ #pragma once /** * Available field types for AMQP - * + * * @copyright 2014 Copernica BV */ @@ -26,7 +26,7 @@ protected: * @return Field* */ static Field *decode(ReceivedFrame &frame); - + public: /** * Destructor @@ -58,13 +58,13 @@ public: * @return char */ virtual char typeID() const = 0; - + /** * Output the object to a stream * @param std::ostream */ virtual void output(std::ostream &stream) const = 0; - + /** * Casting operators * @return mixed @@ -83,6 +83,18 @@ public: virtual operator double () const { return 0; } virtual operator const Array& () const; virtual operator const Table& () const; + + /** + * Check the field type + * + * @return Is the field a specific type? + */ + virtual bool isInteger() const { return false; } + virtual bool isDecimal() const { return false; } + virtual bool isArray() const { return false; } + virtual bool isTable() const { return false; } + virtual bool isBoolean() const { return false; } + virtual bool isString() const { return false; } }; /** diff --git a/include/numericfield.h b/include/numericfield.h index 04518b9..85f268b 100644 --- a/include/numericfield.h +++ b/include/numericfield.h @@ -102,10 +102,14 @@ public: * Get the value * @return mixed */ - virtual operator T () const override - { - return _value; - } + operator uint8_t () const override { return _value; } + operator uint16_t() const override { return _value; } + operator uint32_t() const override { return _value; } + operator uint64_t() const override { return _value; } + operator int8_t () const override { return _value; } + operator int16_t () const override { return _value; } + operator int32_t () const override { return _value; } + operator int64_t () const override { return _value; } /** * Get the value @@ -117,6 +121,16 @@ public: return _value; } + /** + * We are an integer field + * + * @return true, because we are an integer + */ + bool isInteger() const override + { + return true; + } + /** * Get the size this field will take when * encoded in the AMQP wire-frame format diff --git a/include/stringfield.h b/include/stringfield.h index fe8a437..879d597 100644 --- a/include/stringfield.h +++ b/include/stringfield.h @@ -167,6 +167,16 @@ public: return F; } + /** + * We are a string + * + * @return true, because we are a string + */ + bool isString() const override + { + return true; + } + /** * Output the object to a stream * @param std::ostream diff --git a/include/table.h b/include/table.h index 4fc5c01..b33f260 100644 --- a/include/table.h +++ b/include/table.h @@ -72,6 +72,13 @@ public: */ Table &operator=(Table &&table); + /** + * Retrieve all keys in the table + * + * @return Vector with all keys in the table + */ + std::vector keys() const; + /** * Create a new instance on the heap of this object, identical to the object passed * @return Field* @@ -167,6 +174,16 @@ public: return 'F'; } + /** + * We are a table + * + * @return true, because we are a table + */ + bool isTable() const override + { + return true; + } + /** * Output the object to a stream * @param std::ostream diff --git a/src/table.cpp b/src/table.cpp index 5022bfe..494de94 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -1,4 +1,5 @@ #include "includes.h" +#include // we live in the copernica namespace namespace AMQP { @@ -91,6 +92,24 @@ Table &Table::operator=(Table &&table) return *this; } +/** + * Retrieve all keys in the table + * + * @return Vector with all keys in the table + */ +std::vector Table::keys() const +{ + // the result vector + std::vector result; + result.reserve(_fields.size()); + + // insert all keys into the result vector + for (auto &iter : _fields) result.push_back(iter.first); + + // now return the result + return result; +} + /** * Get a field *