aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Common/Array.hpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-08 14:52:17 +0800
committerchai <chaifix@163.com>2018-09-08 14:52:17 +0800
commit7c3609b04eabc79db0c0b245a155fc3c5e875053 (patch)
tree9333f727863c8fed738bd16eaf6d9e2f0d4f53b5 /src/libjin/Common/Array.hpp
parent1ccc798ca383fc941d624751293ed88e012900d1 (diff)
*update
Diffstat (limited to 'src/libjin/Common/Array.hpp')
-rw-r--r--src/libjin/Common/Array.hpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/libjin/Common/Array.hpp b/src/libjin/Common/Array.hpp
new file mode 100644
index 0000000..de22961
--- /dev/null
+++ b/src/libjin/Common/Array.hpp
@@ -0,0 +1,72 @@
+#ifndef __LIBJIN_COMMON_ARRAY_H
+#define __LIBJIN_COMMON_ARRAY_H
+
+namespace jin
+{
+
+ /* ԶͷŶڴĶ̬ */
+ template<typename T>
+ class Array
+ {
+ public:
+ Array() : length(0), data(nullptr) {}
+
+ Array(int l)
+ {
+ length = l;
+ data = new T[l];
+ }
+
+ ~Array()
+ {
+ delete[] data;
+ length = 0;
+ }
+
+ T* operator &()
+ {
+ return data;
+ }
+
+ T operator[](int index)
+ {
+ return data[index];
+ }
+
+ /* ڴ */
+ void bind(T* d, int len)
+ {
+ if (data != nullptr)
+ delete data;
+ data = d;
+ length = len;
+ }
+
+ void add(T v)
+ {
+ int len = length + 1;
+ T* d = new T[len];
+ memcpy(d, data, size());
+ d[length] = v;
+ bind(d, len);
+ }
+
+ int size()
+ {
+ return sizeof(T) * length;
+ }
+
+ int count()
+ {
+ return length;
+ }
+
+ private:
+ T * data;
+ unsigned int length;
+
+ };
+
+}
+
+#endif \ No newline at end of file