source: libcf++/trunk/include/cf/bin.h@ 11

Last change on this file since 11 was 11, checked in by cheese, 9 years ago

#1 add new interfaces for bin and task

File size: 3.2 KB
Line 
1/**
2 * @file bin.h
3 * @author myusgun@gmail.com
4 * @brief bin
5 */
6#ifndef __bin_h__
7#define __bin_h__
8
9#include "cf/types.h"
10#include "cf/exception.h"
11
12#include <vector>
13#include <string>
14#include <stdio.h>
15
16namespace cf
17{
18 /**
19 * binary
20 */
21 class bin
22 {
23 private:
24 typedef std::vector<cf::uint8_t> bin_t;
25
26 bin_t mBin;
27
28 public:
29 /**
30 * shallow-copy constructor(default constructor)
31 * @param in binary
32 * @param length binary size
33 */
34 bin(const cf::uint8_t * in = NULL,
35 const cf::size_t length = 0);
36
37 /**
38 * asciiz-byte shallow-copy constructor
39 * @param in asciiz-byte
40 */
41 bin(const std::string & in);
42
43 /**
44 * copy constructor
45 * @param in an instance of bin(not constant)
46 */
47 bin(const bin & in);
48
49 /**
50 * reset binary. fill with zero
51 */
52 cf::void_t clear();
53
54 /**
55 * get binary
56 * @return address of binary
57 */
58 cf::uint8_t * buffer() const;
59
60 /**
61 * get binary size
62 * @return size of binary
63 */
64 cf::size_t size() const;
65
66 /**
67 * is empty
68 * @return is empty ?
69 */
70 cf::bool_t empty() const;
71
72 /**
73 * resize
74 * @param size new size
75 */
76 cf::void_t resize(const cf::size_t size);
77
78 /**
79 * set
80 * @param in data
81 * @param length size
82 */
83 cf::void_t set(const cf::uint8_t * in,
84 const cf::size_t length);
85
86 /**
87 * copy to rear of buffer
88 * @param in binary
89 * @param appendedSize binary size
90 */
91 cf::void_t append(const cf::uint8_t * in,
92 const cf::size_t appendedSize);
93
94 /**
95 * copy to rear of buffer
96 * @param in bin instance
97 * @see bin::operator +=()
98 */
99 cf::void_t append(const bin & in);
100
101 /**
102 * compare binary
103 * @return true; false
104 * @param in bin instance
105 * @see bin::operator ==()
106 */
107 cf::bool_t equal(const bin & in) const;
108
109 /**
110 * find in binary
111 * @return on success, position; otherwise, (cf::size_t)-1
112 * @param in binary
113 * @param length binary size
114 */
115 cf::size_t find(const cf::uint8_t * in,
116 const cf::size_t length) const;
117
118 /**
119 * set
120 * @param in bin
121 */
122 bin & operator =(const bin & in);
123
124 /**
125 * set
126 * @param in string
127 */
128 bin & operator =(const std::string & in);
129
130 /**
131 * copy to rear of buffer
132 * @param in bin instance
133 * @see bin::append()
134 */
135 cf::void_t operator +=(const bin & in);
136
137 /**
138 * combine binary
139 * @return combined instance
140 */
141 bin operator +(const bin & in) const;
142
143 /**
144 * compare binary
145 * @return true; false
146 * @param in bin instance
147 * @see bin::equal()
148 */
149 cf::bool_t operator ==(const bin & in) const;
150
151 /**
152 * compare binary
153 * @return true; false
154 * @param in bin instance
155 * @see bin::equal()
156 */
157 cf::bool_t operator !=(const bin & in) const;
158
159 /**
160 * get a byte
161 * @return a byte
162 * @param index index
163 */
164 cf::uint8_t operator [](const cf::size_t index) const;
165
166 /**
167 * get as string
168 * @return string
169 */
170 std::string toString() const;
171
172 /**
173 * dump binary to file-pointer
174 * @param prefix prefix for output
175 * @param limit [option] limit
176 * @param fp [option] file-pointer
177 */
178 cf::void_t print(const cf::char_t * prefix = "",
179 const cf::size_t limit = -1,
180 FILE * fp = stdout) const;
181 };
182}
183
184#endif // #ifndef __bin_h__
Note: See TracBrowser for help on using the repository browser.