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 FTextEncoder.h
19 * @brief This is the header file for the %Encoder class.
21 * This header file contains the declarations of the %Encoder class.
24 #ifndef _FTEXT_ENCODER_H_
25 #define _FTEXT_ENCODER_H_
27 #include <FBaseObject.h>
28 #include <FBaseTypes.h>
29 #include <FBaseBuffer.h>
31 namespace Tizen { namespace Text
35 * @brief This class is an implementation of the character encoder.
39 * The %Encoder class converts blocks of characters to blocks of encoded bytes
40 * through successive calls to the GetBytesN() method. This class maintains the state consistency information between
41 * successive calls to %GetBytesN(), enabling it to encode a character into a sequence of bytes,
42 * such as surrogate pairs, that span adjacent blocks.
44 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/text/converting_text_data_separate_blocks.htm">Converting Text Data in Separate Blocks</a>.
47 class _OSP_EXPORT_ Encoder
48 : public Tizen::Base::Object
52 * This is the destructor for this class. @n
53 * This destructor overrides Tizen::Base::Object::~Object().
57 virtual ~Encoder(void) { };
60 * Gets the total number of bytes that are required to encode a range of characters in the specified Tizen::Base::WcharBuffer instance.
64 * @return An error code
65 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
66 * @param[in] charIndex The index from where encoding begins in the Tizen::Base::WcharBuffer instance
67 * @param[in] charCount The total number of characters to encode
68 * @param[in] flush Set to @c true to allow this instance to flush its state at the end of the conversion, @n
70 * @param[out] byteCount The total number of bytes required to encode the specified range of characters
71 * @exception E_SUCCESS The method is successful.
72 * @exception E_INVALID_ARG A specified input parameter is invalid, or
73 * the specified @c chars is empty.
74 * @exception E_OUT_OF_RANGE The value of an argument is outside the valid range defined by the method, or
75 * the length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
76 * @exception E_UNDERFLOW This operation has caused the memory to underflow, or
77 * the sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
78 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
79 * @see Decoder::GetCharCount()
81 virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars,
82 int charIndex, int charCount, int& byteCount, bool flush = false) const = 0;
85 * Encodes an instance of the specified Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer.
89 * @return A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
90 * else @c null if an exception occurs @n
91 * The buffer limit is the position of the last encoded byte plus one in the buffer and the starting position is zero.
92 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
93 * @param[in] flush Set to @c true to allow this instance to flush its state at the end of the conversion, @n
95 * @exception E_SUCCESS The method is successful.
96 * @exception E_OUT_OF_MEMORY The memory is insufficient.
97 * @exception E_INVALID_ARG A specified input parameter is invalid, or
98 * the specified @c chars is empty.
99 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
100 * @remarks The specific error code can be accessed using the GetLastResult() method.
101 * @see Decoder::GetCharsN()
103 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars, bool flush = false) const = 0;
106 * Encodes an instance of Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer as per the specified range.
110 * @return A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
111 * else @c null if an exception occurs @n
112 * The buffer limit is the position of the last encoded byte in the buffer and the starting position is zero.
113 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
114 * @param[in] charIndex The index from where encoding begins in the Tizen::Base::WcharBuffer instance
115 * @param[in] charCount The total number of characters to encode
116 * @param[in] flush Set to @c true to allow this instance to flush its state at the end of the conversion, @n
118 * @exception E_SUCCESS The method is successful.
119 * @exception E_OUT_OF_MEMORY The memory is insufficient.
120 * @exception E_INVALID_ARG A specified input parameter is invalid, or
121 * the specified @c chars is empty.
122 * @exception E_OUT_OF_RANGE The value of an argument is outside the valid range defined by the method, or
123 * the length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
124 * @exception E_UNDERFLOW This operation has caused the memory to underflow, or
125 * the sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
126 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
127 * @remarks The specific error code can be accessed using the GetLastResult() method.
128 * @remarks The pointer to the Tizen::Base::ByteBuffer instance is not terminated by a @c null character.
129 * @see Decoder::GetCharsN()
131 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount,
132 bool flush = false) const = 0;
136 : _pEncoderImpl(null){};
137 friend class _EncoderImpl;
138 class _EncoderImpl* _pEncoderImpl;
142 * The implementation of this copy constructor is intentionally blank and declared as private to
143 * prohibit copying of objects.
145 Encoder(const Encoder& encoder);
148 * The implementation of this copy assignment operator is intentionally blank and declared as private
149 * to prohibit copying of objects.
151 Encoder& operator =(const Encoder& encoder);
155 #endif //_FTEXT_ENCODER_H_