Fixed a bug in the envelope, easy retrieval of field type and improved casting operators for numeric fields
This commit is contained in:
parent
fcc9522e16
commit
7ae4f9c5ff
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<std::string> 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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "includes.h"
|
||||
#include <algorithm>
|
||||
|
||||
// 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<std::string> Table::keys() const
|
||||
{
|
||||
// the result vector
|
||||
std::vector<std::string> 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
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue