mirror of
https://github.com/MeowLynxSea/ceditor.git
synced 2025-07-09 10:54:37 +00:00
为MyVector增加了必须的迭代器操作
This commit is contained in:
parent
959c73bfc6
commit
b20d8aa6d0
@ -15,10 +15,10 @@ private:
|
||||
std::string content_;
|
||||
RichText coloredContent_;
|
||||
std::string ruleName_;
|
||||
std::vector<std::string> lineedContent_;
|
||||
MyVector<std::string> lineedContent_;
|
||||
|
||||
std::vector<std::string> split(std::string content) {
|
||||
std::vector<std::string> lineedContent;
|
||||
MyVector<std::string> split(std::string content) {
|
||||
MyVector<std::string> lineedContent;
|
||||
std::string tempStr = content_ + "\n";
|
||||
size_t pos = tempStr.find("\n");
|
||||
lineedContent.clear();
|
||||
@ -30,7 +30,7 @@ private:
|
||||
return lineedContent;
|
||||
}
|
||||
|
||||
std::string assemble(std::vector<std::string> lineedContent) {
|
||||
std::string assemble(MyVector<std::string> lineedContent) {
|
||||
std::string content = "";
|
||||
for(auto line : lineedContent) {
|
||||
content += line + "\n";
|
||||
|
@ -173,6 +173,57 @@ public:
|
||||
}
|
||||
return m_data[index];
|
||||
}
|
||||
|
||||
//实现迭代器
|
||||
struct iterator {
|
||||
T* ptr;
|
||||
|
||||
iterator(T* ptr) : ptr(ptr) {}
|
||||
T& operator*() const { return *ptr; }
|
||||
T* operator->() const { return ptr; }
|
||||
iterator& operator++() { ++ptr; return *this; }
|
||||
iterator operator++(int) { iterator tmp = *this; ++ptr; return tmp; }
|
||||
bool operator==(const iterator& other) const { return ptr == other.ptr; }
|
||||
bool operator!=(const iterator& other) const { return ptr != other.ptr; }
|
||||
|
||||
iterator& operator+(size_t n) {
|
||||
ptr += n;
|
||||
return *this;
|
||||
}
|
||||
iterator operator+(size_t n) const {
|
||||
iterator tmp = *this;
|
||||
tmp.ptr += n;
|
||||
return tmp;
|
||||
}
|
||||
long long operator+(iterator other) const {
|
||||
return ptr + other.ptr;
|
||||
}
|
||||
|
||||
iterator& operator-(size_t n) {
|
||||
ptr -= n;
|
||||
return *this;
|
||||
}
|
||||
iterator operator-(size_t n) const {
|
||||
iterator tmp = *this;
|
||||
tmp.ptr -= n;
|
||||
return tmp;
|
||||
}
|
||||
long long operator-(iterator other) const {
|
||||
return ptr - other.ptr;
|
||||
}
|
||||
};
|
||||
|
||||
iterator begin() {
|
||||
return iterator(m_data);
|
||||
}
|
||||
|
||||
iterator end() {
|
||||
return iterator(m_data + m_size);
|
||||
}
|
||||
|
||||
void erase(iterator target) {
|
||||
erase(target - begin());
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MY_VECTOR_H
|
||||
|
14
utils/ActionManager.h
Normal file
14
utils/ActionManager.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef ACTIONMANAGER_H
|
||||
#define ACTIONMANAGER_H
|
||||
|
||||
enum class EditAction {
|
||||
Initialize,
|
||||
Insert,
|
||||
Delete,
|
||||
};
|
||||
|
||||
class ActionManager {
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user