diff options
author | jmpoep <OriginalEntryPoint@qq.com> | 2023-12-07 16:51:07 +0800 |
---|---|---|
committer | jmpoep <OriginalEntryPoint@qq.com> | 2023-12-07 16:51:07 +0800 |
commit | 28008a746a31abb7909dd86cb0cd413ac8943b0b (patch) | |
tree | a30b74b8cad548048c3c1551d652828ab76fa9bd /runtime/objects.h | |
download | vmprotect-3.5.1-master.tar vmprotect-3.5.1-master.tar.gz vmprotect-3.5.1-master.tar.bz2 vmprotect-3.5.1-master.zip |
Diffstat (limited to 'runtime/objects.h')
-rw-r--r-- | runtime/objects.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/runtime/objects.h b/runtime/objects.h new file mode 100644 index 0000000..66f4877 --- /dev/null +++ b/runtime/objects.h @@ -0,0 +1,78 @@ +#ifndef OBJECTS_H +#define OBJECTS_H + +template<class T> +class vector +{ +public: + vector() : data_(NULL), total_(0), size_(0) {} + ~vector() { delete [] data_; } + size_t size() const { return size_; } + bool empty() const { return size_ == 0; } + const T &operator[] (size_t index) const { return data_[index]; } + T &operator[] (size_t index) {return data_[index]; } + void push_back(const T &t) + { + if (size_ == total_) { + // no free space + size_t new_total = (total_ == 0) ? 1 : total_ * 2; + T *new_data = new T[new_total]; + for (size_t i = 0; i < size_; i++) { + new_data[i] = data_[i]; + } + delete [] data_; + data_ = new_data; + total_ = new_total; + } + data_[size_++] = t; + } + void pop_back() + { + if (size_) + size_--; + } + + void erase(size_t pos) + { + if (pos >= size_) + return; // error + for (size_t i = pos; i < size_ - 1; i++) { + data_[i] = data_[i + 1]; + } + size_--; + } + + template <typename X> + size_t find(const X &v) const + { + for (size_t i = 0; i < size_; i++) { + if (data_[i] == v) + return i; + } + return -1; + } + + void clear() + { + size_ = total_ = 0; + delete [] data_; + data_ = NULL; + } +private: + T *data_; + size_t total_; + size_t size_; +}; + +class CriticalSection +{ +public: + CriticalSection(CRITICAL_SECTION &critical_section); + ~CriticalSection(); + static void Init(CRITICAL_SECTION &critical_section); + static void Free(CRITICAL_SECTION &critical_section); +private: + CRITICAL_SECTION &critical_section_; +}; + +#endif
\ No newline at end of file |