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);
|
return ArrayFieldProxy(this, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a const field
|
* Get a const field
|
||||||
* @param index field index
|
* @param index field index
|
||||||
|
|
@ -168,6 +168,16 @@ public:
|
||||||
return 'A';
|
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
|
* Output the object to a stream
|
||||||
* @param std::ostream
|
* @param std::ostream
|
||||||
|
|
@ -176,27 +186,27 @@ public:
|
||||||
{
|
{
|
||||||
// prefix
|
// prefix
|
||||||
stream << "array(";
|
stream << "array(";
|
||||||
|
|
||||||
// is this the first iteration
|
// is this the first iteration
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
||||||
// loop through all members
|
// loop through all members
|
||||||
for (auto &iter : _fields)
|
for (auto &iter : _fields)
|
||||||
{
|
{
|
||||||
// split with comma
|
// split with comma
|
||||||
if (!first) stream << ",";
|
if (!first) stream << ",";
|
||||||
|
|
||||||
// show output
|
// show output
|
||||||
stream << *iter;
|
stream << *iter;
|
||||||
|
|
||||||
// no longer first iter
|
// no longer first iter
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// postfix
|
// postfix
|
||||||
stream << ")";
|
stream << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cast to array
|
* Cast to array
|
||||||
* @return Array
|
* @return Array
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,16 @@ public:
|
||||||
return 't';
|
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
|
* Get the size this field will take when
|
||||||
* encoded in the AMQP wire-frame format
|
* encoded in the AMQP wire-frame format
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,16 @@ public:
|
||||||
return *this;
|
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
|
* Get the type ID that is used to identify this type of
|
||||||
* field in a field table
|
* field in a field table
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ public:
|
||||||
* @param envelope the envelope to move
|
* @param envelope the envelope to move
|
||||||
*/
|
*/
|
||||||
Envelope(Envelope &&envelope) :
|
Envelope(Envelope &&envelope) :
|
||||||
|
MetaData(std::move(envelope)),
|
||||||
_str(std::move(envelope._str)),
|
_str(std::move(envelope._str)),
|
||||||
_body(_str.data()),
|
_body(_str.data()),
|
||||||
_bodySize(_str.size())
|
_bodySize(_str.size())
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
/**
|
/**
|
||||||
* Available field types for AMQP
|
* Available field types for AMQP
|
||||||
*
|
*
|
||||||
* @copyright 2014 Copernica BV
|
* @copyright 2014 Copernica BV
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ protected:
|
||||||
* @return Field*
|
* @return Field*
|
||||||
*/
|
*/
|
||||||
static Field *decode(ReceivedFrame &frame);
|
static Field *decode(ReceivedFrame &frame);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
|
|
@ -58,13 +58,13 @@ public:
|
||||||
* @return char
|
* @return char
|
||||||
*/
|
*/
|
||||||
virtual char typeID() const = 0;
|
virtual char typeID() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output the object to a stream
|
* Output the object to a stream
|
||||||
* @param std::ostream
|
* @param std::ostream
|
||||||
*/
|
*/
|
||||||
virtual void output(std::ostream &stream) const = 0;
|
virtual void output(std::ostream &stream) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Casting operators
|
* Casting operators
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|
@ -83,6 +83,18 @@ public:
|
||||||
virtual operator double () const { return 0; }
|
virtual operator double () const { return 0; }
|
||||||
virtual operator const Array& () const;
|
virtual operator const Array& () const;
|
||||||
virtual operator const Table& () 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
|
* Get the value
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
virtual operator T () const override
|
operator uint8_t () const override { return _value; }
|
||||||
{
|
operator uint16_t() const override { return _value; }
|
||||||
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
|
* Get the value
|
||||||
|
|
@ -117,6 +121,16 @@ public:
|
||||||
return _value;
|
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
|
* Get the size this field will take when
|
||||||
* encoded in the AMQP wire-frame format
|
* encoded in the AMQP wire-frame format
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,16 @@ public:
|
||||||
return F;
|
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
|
* Output the object to a stream
|
||||||
* @param std::ostream
|
* @param std::ostream
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,13 @@ public:
|
||||||
*/
|
*/
|
||||||
Table &operator=(Table &&table);
|
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
|
* Create a new instance on the heap of this object, identical to the object passed
|
||||||
* @return Field*
|
* @return Field*
|
||||||
|
|
@ -167,6 +174,16 @@ public:
|
||||||
return 'F';
|
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
|
* Output the object to a stream
|
||||||
* @param std::ostream
|
* @param std::ostream
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
// we live in the copernica namespace
|
// we live in the copernica namespace
|
||||||
namespace AMQP {
|
namespace AMQP {
|
||||||
|
|
@ -91,6 +92,24 @@ Table &Table::operator=(Table &&table)
|
||||||
return *this;
|
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
|
* Get a field
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue