2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FBaseBufferBase.h
20 * @brief This is the header file for the %BufferBase class.
22 * This header file contains the declarations of the %BufferBase class.
25 #ifndef _FBASE_BUFFER_BASE_H_
26 #define _FBASE_BUFFER_BASE_H_
28 #include <FBaseObject.h>
29 #include <FBaseTypes.h>
30 #include <FBaseRtMutex.h>
32 namespace Tizen { namespace Base
44 POSITION_TO_ZERO = 0, /**< The position is set to zero */
45 POSITION_TO_MARK = 1, /**< The position is set to the mark */
51 * @brief This class is the abstract base class of all buffer classes.
55 * The %BufferBase class is the abstract base class of all buffer classes.
57 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/buffer.htm">Buffer</a>.
59 * @see Tizen::Base::ByteBuffer
60 * @see Tizen::Base::Buffer< Type >
63 class _OSP_EXPORT_ BufferBase
67 // Forward declaration
73 * This destructor overrides Tizen::Base::Object::~Object().
77 virtual ~BufferBase(void);
80 * Clears the calling %BufferBase object. @n
81 * The buffer's position is set to @c 0, the limit is set to the capacity, and the mark is discarded.
88 * Copies the elements between the current position and limit (that are also known as remaining
89 * elements), to the beginning of the calling %BufferBase instance.
93 * @remarks After copying, the position is set to the number of elements copied rather than to @c 0,
94 * so that an invocation of this method can be followed immediately by an invocation
95 * of another relative set method. The limit is set to the capacity, and the mark is discarded.
100 * Flips the calling %BufferBase instance. @n
101 * It sets the limit to the current position
102 * and sets the position to either @c 0 or the mark, depending on the input value.
106 * @param[in] to The value to set the buffer position @n
107 * The parameter may contain @c POSITION_TO_ZERO or @c POSITION_TO_MARK.
108 * @remarks If @c to is POSITION_TO_ZERO (or unspecified), the position is set to @c 0 after setting a limit to
109 * the current position, and the mark is discarded.
110 * Otherwise, if @c to is POSITION_TO_MARK, the position is set to the mark and
111 * the mark is not discarded. If the mark is undefined, the position is set to @c 0.
113 * The following example demonstrates how to use the %Flip() method.
118 * buf.Construct(10); // buf's position is zero, limit is 10, and mark is undefined.
120 * buf.SetPosition(7); // Now, buf's position is 7 (limit and mark is unchanged).
122 * buf.Flip(); // equal to "buf.Flip(POSITION_TO_ZERO)"
123 * // buf's position : 0, limit : 7, mark is still undefined.
125 * buf.SetPosition(3);
126 * buf.SetMark(); // Both buf's position and mark are 3.
128 * buf.SetPosition(5); // buf's position is 5, limit is 7, and mark is 3.
130 * buf.Flip(POSITION_TO_MARK); // Now, buf's position is 3, and limit and mark are unchanged.
134 void Flip(PositionTo to = POSITION_TO_ZERO);
137 * Gets the hash value of the calling object.
141 * @return The hash value of the calling object
142 * @remarks The hash code of a buffer depends only upon its remaining elements.
143 * @see Tizen::Base::Object::Equals()
145 virtual int GetHashCode(void) const;
148 * Invalidates the mark of the calling instance of %BufferBase (set to @c -1).
154 void InvalidateMark(void);
157 * Resets the position of the calling %BufferBase object to the previously marked position.
161 * @return An error code
162 * @exception E_SUCCESS The method is successful.
163 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation. @n
164 * The mark has not been set.
165 * @remarks Invoking this method neither changes nor discards the mark's value.
170 * Rewinds the current instance of %BufferBase. @n
171 * It sets the position to
172 * @c 0, discards the mark, and leaves the limit unchanged.
179 * Shifts the limit of the current instance of %BufferBase. @n
180 * The new limit is the current limit plus the given amount.
184 * @return An error code
185 * @param[in] amount The quantity of shift needed
186 * @exception E_SUCCESS The method is successful.
187 * @exception E_OUT_OF_RANGE The value of an argument is outside the valid range defined by the method. @n
188 * The @c amount is larger than the capacity or smaller than @c 0 starting from the current limit.
189 * @remarks If the position is larger than the new limit, it is set to the new limit.
190 * If the mark is defined and larger than the new limit, it is discarded.
193 result ShiftLimit(int amount);
196 * Gets the capacity of the calling %BufferBase instance.
200 * @return The capacity of the calling object
202 int GetCapacity(void) const;
206 * Gets the limit of the calling %BufferBase instance.
210 * @return The limit of the calling object
213 int GetLimit(void) const;
217 * Gets the mark of the calling %BufferBase instance. @n
218 * If the mark has not been set, it returns @c -1.
222 * @return The mark of the calling %BufferBase instance
225 int GetMark(void) const;
229 * Gets the current position of the calling %BufferBase instance.
233 * @return The current position of the calling %BufferBase instance
236 int GetPosition(void) const;
240 * Gets the number of elements between the current position and the limit
241 * of the calling %BufferBase instance.
245 * @return The number of elements between the current position and the limit
246 * @see HasRemaining()
248 int GetRemaining(void) const;
252 * Sets the limit of the calling %BufferBase instance.
256 * @return An error code
257 * @param[in] limit The new limit
258 * @exception E_SUCCESS The method is successful.
259 * @exception E_OUT_OF_RANGE The value of an argument is outside the valid range defined by the method. @n
260 * The @c limit is larger than the capacity or less than @c 0.
261 * @remarks If the position is larger than the new limit, it is set to the new limit.
262 * If the mark is defined and larger than the new limit, it is discarded.
265 result SetLimit(int limit);
269 * Sets the mark of the current instance of %BufferBase at the current position. @n
270 * If this method is called after InvalidateMark(), the mark is set to @c -1.
280 * Sets the position of the calling %BufferBase instance.
284 * @return An error code
285 * @param[in] position The new position
286 * @exception E_SUCCESS The method is successful.
287 * @exception E_OUT_OF_RANGE The value of an argument is outside the valid range defined by the method. @n
288 * The @c position is larger than the current limit or less than @c 0.
289 * @remarks If the mark is defined and larger than the new position then it is discarded.
292 result SetPosition(int position);
295 * Returns @c true if there is at least one element between the current position and
296 * the limit of the current instance of %BufferBase. Otherwise, it returns @c false.
300 * @return @c true if there is at least one element between the current position and the limit of the current instance of %BufferBase, @n
302 * @see GetRemaining()
304 bool HasRemaining(void) const;
307 * Expands the capacity and the limit of the internal buffer with the specified capacity.
311 * @return An error code
312 * @param[in] newCapacity The new capacity of this instance
313 * @exception E_SUCCESS The method is successful.
314 * @exception E_INVALID_ARG The specified @c capacity is less than the current capacity.
315 * @remarks After calling this method, the address of the internal buffer may be either the same or a new location.
317 result ExpandCapacity(int newCapacity);
321 * The object is not fully constructed after this constructor is called. For full construction,
322 * the Construct() method must be called right after calling this constructor.
329 * Initializes this instance of %BufferBase with the specified @c capacity.
333 * @return An error code
334 * @param[in] capacity The number of elements
335 * @exception E_SUCCESS The method is successful.
336 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
337 * The @c capacity is negative.
339 result Construct(int capacity);
342 * Increments the reference count by one.
346 long AddRef(void) const;
350 * Decrements the reference count by one.
354 * @return The reference count after decrement
356 long Release(void) const;
359 * Decreases the reference count. @n
360 * After that, it frees the resource (memory allocation) if the reference count is zero.
364 virtual void Dispose(void);
368 * @brief This class encapsulates the @c byte array used by the buffer classes.
377 // This is the default constructor for this class.
384 // This is the destructor for this class.
388 virtual ~_BufferData(void);
391 // Gets the pointer to the byte array.
394 // @return Pointer to the @c byte array
396 byte* GetArray(void);
400 unsigned long long capacityInByte;
416 * Returns the size of the type of the current %BufferBase instance.
418 * @return The size of the type of the current %BufferBase instance
420 virtual int GetTypeSize(void) const = 0;
423 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
425 BufferBase(const BufferBase& obj);
428 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
430 BufferBase& operator =(const BufferBase& rhs);
432 friend class _BufferBaseImpl;
433 class _BufferBaseImpl * __pBufferBaseImpl;
439 #endif // _FBASE_BUFFER_BASE_H_