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