26e4d0cd0c884c0abf7d495993473aed7420f256
[platform/framework/native/appfw.git] / inc / FTextEncoder.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FTextEncoder.h
19  * @brief               This is the header file for the %Encoder class.
20  *
21  * This header file contains the declarations of the %Encoder class.
22  *
23  */
24 #ifndef _FTEXT_ENCODER_H_
25 #define _FTEXT_ENCODER_H_
26
27 #include <FBaseObject.h>
28 #include <FBaseTypes.h>
29 #include <FBaseBuffer.h>
30
31 namespace Tizen { namespace Text
32 {
33 /**
34  * @class       Encoder
35  * @brief       This class is an implementation of the character encoder.
36  *
37  * @since       2.0
38  *
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.
43  *
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>.
45  */
46
47 class _OSP_EXPORT_ Encoder
48         : public Tizen::Base::Object
49 {
50 public:
51         /**
52          * This is the destructor for this class. @n
53          * This destructor overrides Tizen::Base::Object::~Object().
54          *
55          * @since       2.0
56          */
57         virtual ~Encoder(void) { };
58
59         /**
60          * Gets the total number of bytes that are required to encode a range of characters in the specified Tizen::Base::WcharBuffer instance.
61          *
62          * @since                       2.0
63          *
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
69          *                                              else @c false
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()
80          */
81         virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars,
82                 int charIndex, int charCount, int& byteCount, bool flush = false) const = 0;
83
84         /**
85          * Encodes an instance of the specified Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer.
86          *
87          * @since                       2.0
88          *
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
94          *                              else @c false
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()
102          */
103         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars, bool flush = false) const = 0;
104
105         /**
106          * Encodes an instance of Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer as per the specified range.
107          *
108          * @since                       2.0
109          *
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
117          *                                              else @c false
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()
130          */
131         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount,
132                 bool flush = false) const = 0;
133
134 protected:
135         Encoder(void)
136                 : _pEncoderImpl(null){};
137         friend class _EncoderImpl;
138         class _EncoderImpl* _pEncoderImpl;
139
140 private:
141         /**
142          * The implementation of this copy constructor is intentionally blank and declared as private to
143          * prohibit copying of objects.
144          */
145         Encoder(const Encoder& encoder);
146
147         /**
148          * The implementation of this copy assignment operator is intentionally blank and declared as private
149          * to prohibit copying of objects.
150          */
151         Encoder& operator =(const Encoder& encoder);
152 };
153
154 } } // Tizen::Text
155 #endif //_FTEXT_ENCODER_H_