Merge "Update deprecated libprivilege-control API functions." into tizen
[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() and enables 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 the 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           Either of the following conditions has occurred:
73          *                                                                              - A specified input parameter is invalid.
74          *                                                                              - The specified @c chars is empty.
75          * @exception   E_OUT_OF_RANGE                  Either of the following conditions has occurred:
76          *                                                                              - A specified input parameter is outside the valid range defined by the method.
77          *                                                                              - The length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
78          * @exception   E_UNDERFLOW             Either of the following conditions has occurred:
79          *                                                                              - This operation has caused the memory to underflow.
80          *                                                                              - The sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
81          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
82          * @see                         Decoder::GetCharCount()
83          */
84         virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars,
85                 int charIndex, int charCount, int& byteCount, bool flush = false) const = 0;
86
87         /**
88          * Encodes an instance of the specified Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer.
89          *
90          * @since                       2.0
91          *
92          * @return              A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
93          *                              else @c null if an exception occurs @n
94          *                              The buffer limit is the position of the last encoded byte plus one in the buffer and the starting position is zero.
95          * @param[in]   chars                                   An instance of Tizen::Base::WcharBuffer to encode
96          * @param[in]   flush                                   Set to @c true to allow this instance to flush its state at the end of the conversion, @n
97          *                                                                              else @c false
98          * @exception   E_SUCCESS               The method is successful.
99          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
100          * @exception   E_INVALID_ARG           Either of the following conditions has occurred:
101          *                                                                              - A specified input parameter is invalid.
102          *                                                                              - The specified @c chars is empty.
103          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
104          * @remarks             The specific error code can be accessed using the GetLastResult() method.
105          * @see       Decoder::GetCharsN()
106          */
107         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars, bool flush = false) const = 0;
108
109         /**
110          * Encodes an instance of Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer as per the specified range.
111          *
112          * @since                       2.0
113          *
114          * @return              A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
115          *                              else @c null if an exception occurs @n
116          *                              The buffer limit is the position of the last encoded byte in the buffer and the starting position is zero.
117          * @param[in]   chars                                   An instance of Tizen::Base::WcharBuffer to encode
118          * @param[in]   charIndex                               The index from where the encoding begins in the Tizen::Base::WcharBuffer instance
119          * @param[in]   charCount                               The total number of characters to encode
120          * @param[in]   flush                                   Set to @c true to allow this instance to flush its state at the end of the conversion, @n
121          *                                                                              else @c false
122          * @exception   E_SUCCESS               The method is successful.
123          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
124          * @exception   E_INVALID_ARG           Either of the following conditions has occurred:
125          *                                                                              - A specified input parameter is invalid.
126          *                                                                              - The specified @c chars is empty.
127          * @exception   E_OUT_OF_RANGE          Either of the following conditions has occurred:
128          *                                                                              - A specified input parameter is outside the valid range defined by the method.
129          *                                                                              - The length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
130          * @exception   E_UNDERFLOW                 Either of the following conditions has occurred:
131          *                                                                              - This operation has caused the memory to underflow.
132          *                                                                              - The sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
133          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
134          * @remarks             
135          *                              - The specific error code can be accessed using the GetLastResult() method.
136          *                              - The pointer to the Tizen::Base::ByteBuffer instance is not terminated by a @c null character.
137          * @see         Decoder::GetCharsN()
138          */
139         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount,
140                 bool flush = false) const = 0;
141
142 protected:
143         Encoder(void)
144                 : _pEncoderImpl(null){};
145         friend class _EncoderImpl;
146         class _EncoderImpl* _pEncoderImpl;
147
148 private:
149         /**
150          * The implementation of this copy constructor is intentionally blank and declared as private to
151          * prohibit copying of objects.
152          */
153         Encoder(const Encoder& encoder);
154
155         /**
156          * The implementation of this copy assignment operator is intentionally blank and declared as private
157          * to prohibit copying of objects.
158          */
159         Encoder& operator =(const Encoder& encoder);
160 };
161
162 } } // Tizen::Text
163 #endif //_FTEXT_ENCODER_H_