diff options
author | chai <chaifix@163.com> | 2018-10-19 08:36:44 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-10-19 08:36:44 +0800 |
commit | 7d5f055547e70fa93ee9ac944e62f8d657b9dc55 (patch) | |
tree | 081782a1541854db4b8eb69c4b43081f52711286 /src/libjin/Common/je_array.hpp | |
parent | 02dd1f38008594048f0e28bad01e7c6d18844198 (diff) |
*修改文件名
Diffstat (limited to 'src/libjin/Common/je_array.hpp')
-rw-r--r-- | src/libjin/Common/je_array.hpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/libjin/Common/je_array.hpp b/src/libjin/Common/je_array.hpp new file mode 100644 index 0000000..eadd36f --- /dev/null +++ b/src/libjin/Common/je_array.hpp @@ -0,0 +1,86 @@ +#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: + /// + /// http://blog.jobbole.com/106923/ + /// new ڴ洴 + /// 1. new ڴ + /// 2. ù캯 + /// + /// new, deleteڷͷڴ棬 + /// + void* operator new(size_t t); + + /// + /// Disable delete. + /// + void operator delete(void* ptr); + + T * data; + unsigned int length; + + }; + +} // namespace jin + +#endif
\ No newline at end of file |