Implement raising exceptions
[platform/core/connectivity/smartcard-service.git] / common / NumberStream.cpp
1 /*
2 * Copyright (c) 2012, 2013 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 #include "NumberStream.h"
19
20 namespace smartcard_service_api
21 {
22         NumberStream::NumberStream(const ByteArray &T)
23         {
24                 setBuffer(T.getBuffer(), T.getLength());
25         }
26
27         unsigned int NumberStream::getBigEndianNumber()
28         {
29                 return getBigEndianNumber(*this);
30         }
31
32         unsigned int NumberStream::getLittleEndianNumber()
33         {
34                 return getLittleEndianNumber(*this);
35         }
36
37         NumberStream &NumberStream::operator =(const ByteArray &T)
38         {
39                 if (this != &T)
40                 {
41                         setBuffer(T.getBuffer(), T.getLength());
42                 }
43
44                 return *this;
45         }
46
47         NumberStream &NumberStream::operator =(const NumberStream &T)
48         {
49                 if (this != &T)
50                 {
51                         setBuffer(T.getBuffer(), T.getLength());
52                 }
53
54                 return *this;
55         }
56
57         unsigned int NumberStream::getBigEndianNumber(const ByteArray &T)
58         {
59                 int i, len;
60                 unsigned int result = 0;
61
62                 len = (T.getLength() < 4) ? T.getLength() : 4;
63
64                 for (i = 0; i < len; i++)
65                 {
66                         result = (result << 8) | T.getAt(i);
67                 }
68
69                 return result;
70         }
71
72         unsigned int NumberStream::getLittleEndianNumber(const ByteArray &T)
73         {
74                 int i, len;
75                 unsigned int result = 0;
76
77                 len = (T.getLength() < 4) ? T.getLength() : 4;
78
79                 for (i = 0; i < len; i++)
80                 {
81                         result = result | (T.getAt(i) << (i * 8));
82                 }
83
84                 return result;
85         }
86
87 } /* namespace smartcard_service_api */