2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FBaseBufferBase.h
19 * @brief This is the header file for the %BufferBase class.
21 * This header file contains the declarations of the %BufferBase class.
23 #ifndef _FBASE_BUFFER_BASE_H_
24 #define _FBASE_BUFFER_BASE_H_
26 #include <FBaseObject.h>
27 #include <FBaseTypes.h>
28 #include <FBaseRtMutex.h>
30 namespace Tizen { namespace Base
42 POSITION_TO_ZERO = 0, /**< The position is set to zero */
43 POSITION_TO_MARK = 1, /**< The position is set to the mark */
49 * @brief This class is the abstract base class of all buffer classes.
53 * The %BufferBase class is the abstract base class of all buffer classes.
55 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/buffer.htm">Buffer</a>.
57 * @see Tizen::Base::ByteBuffer
58 * @see Tizen::Base::Buffer< Type >
61 class _OSP_EXPORT_ BufferBase
65 // Forward declaration
71 * This destructor overrides Tizen::Base::Object::~Object().
75 virtual ~BufferBase(void);
78 * Clears the calling %BufferBase object. @n
79 * The buffer's position is set to @c 0, the limit is set to the capacity, and the mark is discarded.
86 * Copies the elements between the current position and the limit (that are also known as the remaining
87 * elements), to the beginning of the calling %BufferBase instance.
91 * @remarks After copying, the position is set to the number of elements copied rather than to @c 0,
92 * so that an invocation of this method can be followed immediately by an invocation
93 * of another relative set method. @n
94 * The limit is set to the capacity, and the mark is discarded.
99 * Flips the calling %BufferBase instance. @n
100 * It sets the limit to the current position
101 * and sets the position to either @c 0 or the mark, depending on the input value.
105 * @param[in] to The value of the buffer position to set @n
106 * The parameter may contain @c POSITION_TO_ZERO or @c POSITION_TO_MARK.
107 * @remarks If @c to is @c POSITION_TO_ZERO (or unspecified), the position is set to @c 0 after setting a limit to
108 * the current position, and the mark is discarded.
109 * Otherwise, if @c to is @c POSITION_TO_MARK, the position is set to the mark and
110 * the mark is not discarded. @n
111 * 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 Either of the following conditions has occurred:
164 * - The current state of the instance prohibits the execution of the specified operation.
165 * - The mark has not been set.
166 * @remarks Invoking this method neither changes nor discards the mark's value.
171 * Rewinds the current instance of %BufferBase. @n
172 * It sets the position to
173 * @c 0, discards the mark, and leaves the limit unchanged.
180 * Shifts the limit of the current instance of %BufferBase. @n
181 * The new limit is the current limit plus the given @c amount.
185 * @return An error code
186 * @param[in] amount The quantity of the shift needed
187 * @exception E_SUCCESS The method is successful.
188 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
189 * - The value of the argument is outside the valid range defined by the method.
190 * - The @c amount is larger than the capacity starting from the current limit.
191 * - The @c amount is smaller than @c 0.
193 * - If the position is larger than the new limit, it is set to the new limit.
194 * - If the mark is defined and is larger than the new limit, it is discarded.
197 result ShiftLimit(int amount);
200 * Gets the capacity of the calling %BufferBase instance.
204 * @return The capacity of the calling %BufferBase instance
206 int GetCapacity(void) const;
210 * Gets the limit of the calling %BufferBase instance.
214 * @return The limit of the calling %BufferBase instance
217 int GetLimit(void) const;
221 * Gets the mark of the calling %BufferBase instance. @n
222 * If the mark has not been set, it returns @c -1.
226 * @return The mark of the calling %BufferBase instance
229 int GetMark(void) const;
233 * Gets the current position of the calling %BufferBase instance.
237 * @return The current position of the calling %BufferBase instance
240 int GetPosition(void) const;
244 * Gets the number of elements between the current position and the limit
245 * of the calling %BufferBase instance.
249 * @return The number of elements between the current position and the limit
250 * @see HasRemaining()
252 int GetRemaining(void) const;
256 * Sets the limit of the calling %BufferBase instance.
260 * @return An error code
261 * @param[in] limit The limit of the calling %BufferBase instance
262 * @exception E_SUCCESS The method is successful.
263 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
264 * - The value of the argument is outside the valid range defined by the method.
265 * - The specified @c limit is larger than the capacity.
266 * - The specified @c limit is less than @c 0.
268 * - If the position is larger than the new limit, it is set to the new limit.
269 * - If the mark is defined and is larger than the new limit, it is discarded.
272 result SetLimit(int limit);
276 * Sets the mark of the current instance of %BufferBase at the current position. @n
277 * If this method is called after the InvalidateMark() method , the mark is set to @c -1.
287 * Sets the position of the calling %BufferBase instance.
291 * @return An error code
292 * @param[in] position The position of the calling %BufferBase instance
293 * @exception E_SUCCESS The method is successful.
294 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
295 * - The value of the argument is outside the valid range defined by the method.
296 * - The specified @c position is larger than the current limit.
297 * - The specified @c position is less than @c 0.
298 * @remarks If the mark is defined and is larger than the new position then it is discarded.
301 result SetPosition(int position);
304 * Returns @c true if there is at least one element between the current position and
305 * the limit of the current %BufferBase instance. Otherwise, it returns @c false.
309 * @return @c true if there is at least one element between the current position and the limit of the current %BufferBase instance, @n
311 * @see GetRemaining()
313 bool HasRemaining(void) const;
316 * Expands the capacity and the limit of the internal buffer with the specified @c newCapacity.
320 * @return An error code
321 * @param[in] newCapacity The new capacity of this instance
322 * @exception E_SUCCESS The method is successful.
323 * @exception E_INVALID_ARG The specified @c newCapacity is less than the current capacity.
324 * @remarks After calling this method, the address of the internal buffer may be either the same or a new location.
326 result ExpandCapacity(int newCapacity);
330 * The object is not fully constructed after this constructor is called. For full construction,
331 * the Construct() method must be called right after calling this constructor.
338 * Initializes this instance of %BufferBase with the specified @c capacity.
342 * @return An error code
343 * @param[in] capacity The number of elements
344 * @exception E_SUCCESS The method is successful.
345 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
346 * The @c capacity is negative.
348 result Construct(int capacity);
351 * Increments the reference count by one.
355 long AddRef(void) const;
359 * Decrements the reference count by one.
363 * @return The reference count after decrement
365 long Release(void) const;
368 * Decreases the reference count. @n
369 * After that, it frees the resource (memory allocation) if the reference count is zero.
373 virtual void Dispose(void);
377 * @brief This class encapsulates the @c byte array used by the buffer classes.
386 // This is the default constructor for this class.
393 // This is the destructor for this class.
397 virtual ~_BufferData(void);
400 // Gets a pointer to the byte array.
403 // @return Pointer to the @c byte array
405 byte* GetArray(void);
409 unsigned long long capacityInByte;
425 * Returns the size of the type of the current %BufferBase instance.
427 * @return The size of the type of the current %BufferBase instance
429 virtual int GetTypeSize(void) const = 0;
432 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
434 BufferBase(const BufferBase& obj);
437 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
439 BufferBase& operator =(const BufferBase& rhs);
441 friend class _BufferBaseImpl;
442 class _BufferBaseImpl* __pBufferBaseImpl;
448 #endif // _FBASE_BUFFER_BASE_H_