1 #ifndef __DALI_INTERNAL_MESSAGE_BUFFER_H__
2 #define __DALI_INTERNAL_MESSAGE_BUFFER_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
30 * Utility class to reserve a buffer for storing messages.
37 * Create a new MessageBuffer
38 * @param[in] The smallest capacity which the buffer will allocate, with respect to the size of type "char".
39 * @note The buffer will not allocate memory until the first call to ReserveMessageSlot().
41 MessageBuffer( std::size_t initialCapacity );
44 * Non-virtual destructor; not suitable as a base class
49 * Reserve space for another message in the buffer.
50 * @pre size is greater than zero.
51 * @param[in] The message size with respect to the size of type "char".
52 * @return A pointer to the address allocated for the message.
54 unsigned int* ReserveMessageSlot( std::size_t size );
57 * Query the capacity of the message buffer.
58 * @return The capacity with respect to the size of type "char".
60 std::size_t GetCapacity() const;
63 * Used to iterate though the messages in the buffer.
70 Iterator(unsigned int* current);
72 // Inlined for performance
75 // Valid until end marker has been found
76 return 0 != mMessageSize;
79 // Inlined for performance
82 return ( 0 != mMessageSize ) ? mCurrent : NULL;
85 // Inlined for performance
88 // Jump to next object and read size
89 mCurrent += mMessageSize;
90 mMessageSize = *mCurrent++;
94 Iterator(const Iterator& copy);
99 Iterator& operator=(const Iterator& rhs);
103 unsigned int* mCurrent;
104 unsigned int mMessageSize;
108 * Returns an iterator to the first message in the buffer.
109 * There is no past-the-end iterator; use Iterator::IsValid() to determine when the has been reached.
110 * @note Adding more messages with ReserveMessageSlot() may corrupt this iterator.
111 * @return The iterator.
113 Iterator Begin() const;
116 * Sets the size of the buffer to zero (does not deallocate memory)
123 MessageBuffer(const MessageBuffer&);
126 MessageBuffer& operator=(const MessageBuffer& rhs);
129 * Helper to increase the capacity of the buffer.
130 * @pre The newCapacity is greater than mCapacity.
131 * @param[in] The newCapacity
133 void IncreaseCapacity( std::size_t newCapacity );
137 std::size_t mInitialCapacity; ///< The capacity to allocate during first call to ReserveMessageSlot
139 unsigned int* mData; ///< The data allocated for the message buffer
140 unsigned int* mNextSlot; ///< The next free location in the buffer
142 std::size_t mCapacity; ///< The memory allocated with respect to sizeof(unsigned int)
143 std::size_t mSize; ///< The memory reserved for messages with respect to sizeof(unsigned int)
146 } // namespace Internal
150 #endif // __DALI_INTERNAL_MESSAGE_BUFFER_H__