Fix the boiler plate codes
[platform/framework/native/appfw.git] / src / text / FText_EncoderImpl.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                FText_EncoderImpl.h
19  * @brief               This is the header file for the _EncoderImpl class.
20  */
21
22 #ifndef _FTEXT_INTERNAL_ENCODER_IMPL_H_
23 #define _FTEXT_INTERNAL_ENCODER_IMPL_H_
24
25 // Include
26 #include <unique_ptr.h>
27 #include <FTextEncoder.h>
28 #include <FBase.h>
29
30
31 namespace Tizen { namespace Text
32 {
33
34 class _EncodingCore;
35
36 class _EncoderImpl
37         : public Encoder
38 {
39 // Lifecycle
40 public:
41         /**
42          * This is the destructor for this class.
43          *
44          * @since       1.0
45          */
46         virtual ~_EncoderImpl(void);
47
48         static _EncoderImpl* GetEncoderN(const Tizen::Base::String& encodingType);
49 // Operations
50 // Operations
51 public:
52         /**
53          * Calculates the number of bytes required to encode a range of characters in the specified WcharBuffer.
54          *
55          * @since               1.0
56          * @return              An error code
57          * @param[in]   chars                       The buffer containing the character array to encode
58          * @param[in]   charIndex                   The starting index of the WcharBuffer to encode
59          * @param[in]   charCount                   The number of characters to encode
60          * @param[in]   flush                       Set to @c true, to allow this instance to flush its state at the end of the conversion @n
61          *                                          @c false, otherwise
62          * @param[out]  byteCount                   The number of bytes required to encode the specified range of characters
63          * @exception   E_SUCCESS                   The method was successful.
64          * @exception   E_INVALID_ARG               A specified input parameter is invalid. @n
65          *                                          The specified @c chars is empty.
66          * @exception   E_OUT_OF_RANGE              The value of the argument is outside the valid range defined by the method. @n
67          *                                          The length of the specified @c charIndex or @c charCount is greater than the @n
68          *                                          length of the specified @c chars.
69          * @exception   E_UNDERFLOW                 This operation caused an underflow. @n
70          *                                          The sum of the length of the specified @c charIndex and @c charCount is greater
71          *                                          than the length of the specified @c chars.
72          * @exception   E_INVALID_ENCODING_RANGE    The specified string contains code points, which are outside the bounds specified @n
73          *                                          by the character encoding scheme.
74          *
75          * @see                         Decoder::GetCharCount()
76          */
77         virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount, int& byteCount, bool flush = false) const;
78
79         /**
80          * Encodes a specified WcharBuffer into a ByteBuffer.
81          *
82          * @since                       1.0
83          * @return              A new ByteBuffer where the resulting encoded string is stored @n
84          *                                              @c null, if an exception occurs @n
85          *                                              The buffer's limit is the position of the last encoded byte plus one in the buffer, and the position is zero
86          * @param[in]   chars The WcharBuffer to encode
87          * @param[in]   flush Set to @c true, to allow this instance to flush its state at the end of the conversion @n
88          *                              @c false, otherwise
89          * @exception   E_SUCCESS                The method was successful.
90          * @exception   E_OUT_OF_MEMORY          Insufficient memory.
91          * @exception   E_INVALID_ARG            A specified input parameter is invalid. @n
92          *                                         The specified @c chars is empty.
93          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points, which are outside the bounds specified by the character encoding scheme.
94          * @remarks             The specific error code can be accessed using the GetLastResult() method.
95          *
96          * @see       Decoder::GetCharsN()
97          */
98         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars, bool flush = false) const;
99
100         /**
101          * Encodes a range of characters from a WcharBuffer into a ByteBuffer.
102          *
103          * @since                       1.0
104          * @return              A new ByteBuffer where the resulting encoded string is stored @n
105          *                                              @c null if an exception occurs @n
106          *                                              The buffer's limit is the position of the last encoded byte in the buffer, and the position is zero
107          * @param[in]   chars The buffer containing the character array to encode
108          * @param[in]   charIndex The starting index of the WcharBuffer to encode
109          * @param[in]   charCount The number of characters to encode
110          * @param[in] flush Set to @c true, to allow this instance to flush its state at the end of the conversion @n
111          *                                              @c false, otherwise
112          * @exception   E_SUCCESS                The method was successful.
113          * @exception   E_OUT_OF_MEMORY          Insufficient memory.
114          * @exception   E_INVALID_ARG            A specified input parameter is invalid. @n
115          *                                         The specified @c chars is empty.
116          * @exception   E_OUT_OF_RANGE       The value of the argument is outside the valid range defined by the method. @n
117          *                                         The length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
118          * @exception   E_UNDERFLOW                  This operation caused an underflow. @n
119          *                                         The sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
120          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points, which are outside the bounds specified by the character encoding scheme.
121          * @remarks             The specific error code can be accessed using the GetLastResult() method.
122          * @remarks             The new ByteBuffer isn't terminated by @c null character.
123          *
124          * @see         Decoder::GetCharsN()
125          */
126         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount, bool flush = false) const;
127
128 private:
129         _EncoderImpl();
130
131         result GetBufferSize(const Tizen::Base::WcharBuffer& chars, int& charBufSize) const;
132         result CheckBufferInput(int inBufSize, int inIndex, int inCount) const;
133         result Encode(const wchar_t* pSrc, int srcLength, Tizen::Base::ByteBuffer*& pByteBuffer, int index, bool flush) const;
134
135         _EncoderImpl(const _EncoderImpl& encoderImpl);
136         _EncoderImpl& operator =(const _EncoderImpl& encoderImpl);
137
138 private:
139         std::unique_ptr<_EncodingCore> __pEncoder;
140         Tizen::Base::String __encodingType;
141
142 }; // _EncoderImpl
143
144 } } // Tizen::Text
145
146 #endif  //_FTEXT_INTERNAL_ENCODER_IMPL_H_