diff --git a/include/array.h b/include/array.h index befd1d6..7e59406 100644 --- a/include/array.h +++ b/include/array.h @@ -1,6 +1,7 @@ +#pragma once /** * AMQP field array - * + * * @copyright 2014 Copernica BV */ @@ -20,7 +21,7 @@ private: * @typedef */ typedef std::vector> FieldArray; - + /** * The actual fields * @var FieldArray @@ -30,7 +31,7 @@ private: public: /** * Constructor to construct an array from a received frame - * + * * @param frame received frame */ Array(ReceivedFrame &frame); @@ -99,6 +100,25 @@ public: */ const Field &get(uint8_t index); + /** + * Get number of elements on this array + * + * @return array size + */ + uint32_t count() const; + + /** + * Remove last element from array + */ + void pop_back(); + + /** + * Add field to end of array + * + * @param value + */ + void push_back(const Field &value); + /** * Get a field * @@ -111,7 +131,7 @@ public: } /** - * Write encoded payload to the given buffer. + * Write encoded payload to the given buffer. * @param buffer */ virtual void fill(OutBuffer& buffer) const override; diff --git a/include/booleanset.h b/include/booleanset.h index 6383ab2..577fe47 100644 --- a/include/booleanset.h +++ b/include/booleanset.h @@ -1,3 +1,4 @@ +#pragma once /** * BooleanSet.h * diff --git a/include/channel.h b/include/channel.h index 0b36dba..d9dae3e 100644 --- a/include/channel.h +++ b/include/channel.h @@ -1,3 +1,4 @@ +#pragma once /** * Class describing a (mid-level) AMQP channel implementation * diff --git a/include/channelhandler.h b/include/channelhandler.h index ad0c001..c0d3438 100644 --- a/include/channelhandler.h +++ b/include/channelhandler.h @@ -1,3 +1,4 @@ +#pragma once /** * ChannelHandler.h * diff --git a/include/channelimpl.h b/include/channelimpl.h index ad02d27..77e4f16 100644 --- a/include/channelimpl.h +++ b/include/channelimpl.h @@ -1,3 +1,4 @@ +#pragma once /** * ChannelImpl.h * diff --git a/include/classes.h b/include/classes.h index af49200..b4a5500 100644 --- a/include/classes.h +++ b/include/classes.h @@ -1,3 +1,4 @@ +#pragma once /** * Classes.h * diff --git a/include/connection.h b/include/connection.h index 64e0ea1..a67e6ad 100644 --- a/include/connection.h +++ b/include/connection.h @@ -1,3 +1,4 @@ +#pragma once /** * Class describing a mid-level Amqp connection * diff --git a/include/connectionhandler.h b/include/connectionhandler.h index 5233948..7a90b50 100644 --- a/include/connectionhandler.h +++ b/include/connectionhandler.h @@ -1,3 +1,4 @@ +#pragma once /** * ConnectionHandler.h * diff --git a/include/connectionimpl.h b/include/connectionimpl.h index 780c0ff..77adada 100644 --- a/include/connectionimpl.h +++ b/include/connectionimpl.h @@ -1,3 +1,4 @@ +#pragma once /** * Connection implementation * diff --git a/include/decimalfield.h b/include/decimalfield.h index 5df085b..c9d3cfc 100644 --- a/include/decimalfield.h +++ b/include/decimalfield.h @@ -1,3 +1,4 @@ +#pragma once /** * Decimal field type for AMQP * diff --git a/include/entityimpl.h b/include/entityimpl.h index 51ac4ac..be5207d 100644 --- a/include/entityimpl.h +++ b/include/entityimpl.h @@ -1,3 +1,4 @@ +#pragma once /** * EntityImpl.h * diff --git a/include/envelope.h b/include/envelope.h index f66331f..fbe646e 100644 --- a/include/envelope.h +++ b/include/envelope.h @@ -1,3 +1,4 @@ +#pragma once /** * Envelope.h * diff --git a/include/exchangetype.h b/include/exchangetype.h index a5e7929..ea6ade8 100644 --- a/include/exchangetype.h +++ b/include/exchangetype.h @@ -1,3 +1,4 @@ +#pragma once /** * ExchangeType.h * diff --git a/include/field.h b/include/field.h index 41fbdca..079c741 100644 --- a/include/field.h +++ b/include/field.h @@ -1,3 +1,4 @@ +#pragma once /** * Available field types for AMQP * diff --git a/include/fieldproxy.h b/include/fieldproxy.h index 947d6cc..ad8c445 100644 --- a/include/fieldproxy.h +++ b/include/fieldproxy.h @@ -1,3 +1,4 @@ +#pragma once /** * Field proxy. Returned by the table. Can be casted to the * relevant native type (std::string or numeric) diff --git a/include/flags.h b/include/flags.h index 0a9c2ee..5f46b52 100644 --- a/include/flags.h +++ b/include/flags.h @@ -1,3 +1,4 @@ +#pragma once /** * AmqpFlags.h * diff --git a/include/login.h b/include/login.h index 7605696..51f79de 100644 --- a/include/login.h +++ b/include/login.h @@ -1,3 +1,4 @@ +#pragma once /** * The login information to access a server * diff --git a/include/message.h b/include/message.h index a036420..c92cc5e 100644 --- a/include/message.h +++ b/include/message.h @@ -1,3 +1,4 @@ +#pragma once /** * Message.h * diff --git a/include/metadata.h b/include/metadata.h index 7c1714a..42bf051 100644 --- a/include/metadata.h +++ b/include/metadata.h @@ -1,3 +1,4 @@ +#pragma once /** * MetaData.h * diff --git a/include/numericfield.h b/include/numericfield.h index bcddf58..82edf99 100644 --- a/include/numericfield.h +++ b/include/numericfield.h @@ -1,3 +1,4 @@ +#pragma once /** * Numeric field types for AMQP * diff --git a/include/outbuffer.h b/include/outbuffer.h index 70d4b56..24833fa 100644 --- a/include/outbuffer.h +++ b/include/outbuffer.h @@ -1,3 +1,4 @@ +#pragma once /** * OutBuffer.h * diff --git a/include/receivedframe.h b/include/receivedframe.h index 0f9a0e4..03bd0ae 100644 --- a/include/receivedframe.h +++ b/include/receivedframe.h @@ -1,3 +1,4 @@ +#pragma once /** * ReceivedFrame.h * diff --git a/include/stringfield.h b/include/stringfield.h index 1a2ffd3..724b495 100644 --- a/include/stringfield.h +++ b/include/stringfield.h @@ -1,3 +1,4 @@ +#pragma once /** * String field types for amqp * diff --git a/include/table.h b/include/table.h index c26fb6d..3435f13 100644 --- a/include/table.h +++ b/include/table.h @@ -1,3 +1,4 @@ +#pragma once /** * AMQP field table * @@ -109,7 +110,7 @@ public: * @param name field name * @return the field value */ - const Field &get(const std::string &name); + const Field &get(const std::string &name) const; /** * Get a field diff --git a/include/watchable.h b/include/watchable.h index dab54aa..a81e71d 100644 --- a/include/watchable.h +++ b/include/watchable.h @@ -1,3 +1,4 @@ +#pragma once /** * Watchable.h * diff --git a/src/array.cpp b/src/array.cpp index 3b5831b..706572d 100644 --- a/src/array.cpp +++ b/src/array.cpp @@ -1,8 +1,8 @@ /** * Array.cpp - * + * * Implementation of an array - * + * */ #include "includes.h" @@ -23,7 +23,7 @@ Array::Array(ReceivedFrame &frame) { // one byte less for the field type charsToRead -= 1; - + // read the field type and construct the field Field *field = Field::decode(frame); if (!field) continue; @@ -62,7 +62,7 @@ const Field &Array::get(uint8_t index) { // used if index does not exist static ShortString empty; - + // check whether we have that many elements if (index >= _fields.size()) return empty; @@ -70,6 +70,21 @@ const Field &Array::get(uint8_t index) return *_fields[index]; } +uint32_t Array::count() const +{ + return _fields.size(); +} + +void Array::pop_back() +{ + _fields.pop_back(); +} + +void Array::push_back(const Field& value) +{ + _fields.push_back(std::shared_ptr(value.clone())); +} + /** * Get the size this field will take when * encoded in the AMQP wire-frame format @@ -92,7 +107,7 @@ size_t Array::size() const } /** - * Write encoded payload to the given buffer. + * Write encoded payload to the given buffer. */ void Array::fill(OutBuffer& buffer) const { diff --git a/src/table.cpp b/src/table.cpp index ba41983..4be9b11 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -97,7 +97,7 @@ Table &Table::operator=(Table &&table) * @param name field name * @return the field value */ -const Field &Table::get(const std::string &name) +const Field &Table::get(const std::string &name) const { // we need an empty string static ShortString empty;