added const access for operator[] (issue #7)

This commit is contained in:
Emiel Bruijntjes 2014-04-14 16:04:49 +02:00
parent 83621790f4
commit bcc6eaff82
3 changed files with 22 additions and 2 deletions

View File

@ -110,7 +110,7 @@ public:
* @param index field index * @param index field index
* @return Field * @return Field
*/ */
const Field &get(uint8_t index); const Field &get(uint8_t index) const;
/** /**
* Get number of elements on this array * Get number of elements on this array
@ -141,6 +141,16 @@ public:
{ {
return ArrayFieldProxy(this, index); return ArrayFieldProxy(this, index);
} }
/**
* Get a const field
* @param index field index
* @return Field
*/
const Field &operator[](uint8_t index) const
{
return get(index);
}
/** /**
* Write encoded payload to the given buffer. * Write encoded payload to the given buffer.

View File

@ -122,6 +122,16 @@ public:
return AssociativeFieldProxy(this, name); return AssociativeFieldProxy(this, name);
} }
/**
* Get a const field
*
* @param name field name
*/
const Field &operator[](const std::string& name) const
{
return get(name);
}
/** /**
* Write encoded payload to the given buffer. * Write encoded payload to the given buffer.
* @param buffer * @param buffer

View File

@ -58,7 +58,7 @@ Array::Array(const Array &array)
* @param index field index * @param index field index
* @return Field * @return Field
*/ */
const Field &Array::get(uint8_t index) const Field &Array::get(uint8_t index) const
{ {
// used if index does not exist // used if index does not exist
static ShortString empty; static ShortString empty;