revise exported headers and cleanup headers
[platform/core/connectivity/smartcard-service.git] / common / include / ByteArray.h
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 #ifndef BYTEARRAY_H_
18 #define BYTEARRAY_H_
19
20 #include <string>
21 #include <stdint.h>
22 #include <stddef.h>
23
24 #include "Debug.h"
25
26 #define ARRAY_AND_SIZE(x) (uint8_t *)(&x), sizeof(x)
27
28 using namespace std;
29
30 namespace smartcard_service_api
31 {
32         class EXPORT ByteArray //: public Serializable
33         {
34         protected:
35                 uint8_t *buffer;
36                 size_t length;
37
38                 bool _assign(uint8_t *array, size_t size);
39                 void save(const char *filePath);
40
41         public:
42                 static ByteArray EMPTY;
43
44                 ByteArray();
45                 ByteArray(const uint8_t *array, size_t size);
46                 ByteArray(const ByteArray &T);
47                 ~ByteArray();
48
49 //              ByteArray serialize();
50 //              void deserialize(ByteArray buffer);
51
52                 bool assign(const uint8_t *array, size_t size);
53                 inline bool setBuffer(const uint8_t *array, size_t size) { return assign(array, size); }
54                 void clear();
55
56                 size_t size() const;
57                 inline size_t getLength() const { return size(); }
58                 uint8_t *getBuffer();
59                 const uint8_t *getBuffer() const;
60                 uint8_t *getBuffer(size_t offset);
61                 const uint8_t *getBuffer(size_t offset) const;
62
63                 uint8_t at(size_t index) const;
64                 uint8_t reverseAt(size_t index) const;
65
66                 size_t extract(uint8_t *array, size_t size) const;
67
68                 const ByteArray sub(size_t offset, size_t size) const;
69
70                 /* operator overloading */
71                 ByteArray &operator =(const ByteArray &T);
72                 ByteArray operator +(const ByteArray &T);
73                 ByteArray &operator +=(const ByteArray &T);
74                 bool operator ==(const ByteArray &T) const;
75                 bool operator !=(const ByteArray &T) const;
76                 bool operator <(const ByteArray &T) const;
77                 bool operator >(const ByteArray &T) const;
78                 uint8_t operator [](size_t index) const;
79
80                 inline bool isEmpty() const { return (buffer == (void *)0 || length == 0); }
81                 const string toString() const;
82         };
83
84 } /* namespace smartcard_service_api */
85 #endif /* BYTEARRAY_H_ */