自处理list
来源:互联网 发布:公交查询什么软件好用 编辑:程序博客网 时间:2024/05/21 14:58
一个自处理的list 用途多多
1 1 //子项
2 2 class autoItem
3 3 {
4 4 public:
5 5 //处理
6 6 virtual bool proces() = 0;
7 7 //弹出
8 8 virtual bool ok() = 0;
9 9 //处理顺序
10 10 virtual int Order(){return 0;}
11 11 };
12 12 enum sortType
13 13 {
14 14 ST_Input,
15 15 ST_Custom
16 16 };
17 17 //自处理list
18 18 class _autolist
19 19 {
20 20 public:
21 21 _autolist( sortType _type );
22 22 ~_autolist();
23 23
24 24 //继承函数
25 25 public:
26 26 //加入处理序列
27 27 virtual bool push(autoItem *p);
28 28 //执行处理序列
29 29 virtual bool go();
30 30 //清理所有
31 31 virtual bool clear();
32 32
33 33 //
34 34 protected:
35 35 std::list<autoItem*> itemList;
36 36 sortType _sortType;
37 37 };
38 38
39 39
40 40 _autolist::_autolist( sortType _type )
41 41 {
42 42 _sortType = _type;
43 43 }
44 44
45 45 _autolist::~_autolist()
46 46 {
47 47 clear();
48 48 }
49 49
50 50 bool _autolist::push( autoItem *p )
51 51 {
52 53 if (p == NULL) return false;
53 54 switch (_sortType)
54 55 {
55 56 case ST_Input:
56 57 {
57 58 itemList.insert(itemList.end(),p);
58 59 return true;
59 60 }
60 61 case ST_Custom:
61 62 {
62 63 if (itemList.size() == 0)
63 64 {
64 65 itemList.push_back(p);
65 66 return true;
66 67 }
67 68 static std::list<autoItem*>::iterator it;
68 69 it= itemList.begin();
69 70 for (; it != itemList.end();it++)
70 71 {
71 72 if ((*it)->Order() < p->Order())continue;
72 73 itemList.insert(it,p);
73 74 break;
74 75 }
75 76 return true;
76 77 }
77 78 default:
78 80 return false;
79 82 }
80 83 return false;
81 84 }
82 85
83 86 bool _autolist::go()
84 87 {
85 88 static std::list<autoItem*>::iterator it;
86 89 int nsize = itemList.size();
87 90 it= itemList.begin();
88 91 for (; it != itemList.end();)
89 92 {
90 93 (*it)->proces();
91 94 if ( (*it)->ok())
92 95 it = itemList.erase(it);
93 96 else
94 97 it++;
95 98 }
96 99 return true;
97 100 }
98 101
99 102 bool _autolist::clear()
100 103 {
101 104 itemList.clear();
102 105 return true;
103 106 }
104 107
105
1 1 //子项
2 2 class autoItem
3 3 {
4 4 public:
5 5 //处理
6 6 virtual bool proces() = 0;
7 7 //弹出
8 8 virtual bool ok() = 0;
9 9 //处理顺序
10 10 virtual int Order(){return 0;}
11 11 };
12 12 enum sortType
13 13 {
14 14 ST_Input,
15 15 ST_Custom
16 16 };
17 17 //自处理list
18 18 class _autolist
19 19 {
20 20 public:
21 21 _autolist( sortType _type );
22 22 ~_autolist();
23 23
24 24 //继承函数
25 25 public:
26 26 //加入处理序列
27 27 virtual bool push(autoItem *p);
28 28 //执行处理序列
29 29 virtual bool go();
30 30 //清理所有
31 31 virtual bool clear();
32 32
33 33 //
34 34 protected:
35 35 std::list<autoItem*> itemList;
36 36 sortType _sortType;
37 37 };
38 38
39 39
40 40 _autolist::_autolist( sortType _type )
41 41 {
42 42 _sortType = _type;
43 43 }
44 44
45 45 _autolist::~_autolist()
46 46 {
47 47 clear();
48 48 }
49 49
50 50 bool _autolist::push( autoItem *p )
51 51 {
52 53 if (p == NULL) return false;
53 54 switch (_sortType)
54 55 {
55 56 case ST_Input:
56 57 {
57 58 itemList.insert(itemList.end(),p);
58 59 return true;
59 60 }
60 61 case ST_Custom:
61 62 {
62 63 if (itemList.size() == 0)
63 64 {
64 65 itemList.push_back(p);
65 66 return true;
66 67 }
67 68 static std::list<autoItem*>::iterator it;
68 69 it= itemList.begin();
69 70 for (; it != itemList.end();it++)
70 71 {
71 72 if ((*it)->Order() < p->Order())continue;
72 73 itemList.insert(it,p);
73 74 break;
74 75 }
75 76 return true;
76 77 }
77 78 default:
78 80 return false;
79 82 }
80 83 return false;
81 84 }
82 85
83 86 bool _autolist::go()
84 87 {
85 88 static std::list<autoItem*>::iterator it;
86 89 int nsize = itemList.size();
87 90 it= itemList.begin();
88 91 for (; it != itemList.end();)
89 92 {
90 93 (*it)->proces();
91 94 if ( (*it)->ok())
92 95 it = itemList.erase(it);
93 96 else
94 97 it++;
95 98 }
96 99 return true;
97 100 }
98 101
99 102 bool _autolist::clear()
100 103 {
101 104 itemList.clear();
102 105 return true;
103 106 }
104 107
105
0 0
- 自处理list
- list--ID自增
- list control自绘
- mybatis处理自关联
- javascript 处理List 对象
- DWR中处理List
- 处理两个list
- 处理string list
- Erlang list处理
- Linq处理List数据
- 多线程分组处理list
- Python 列表(List)处理
- java分批处理list
- list处理字符串
- Gson list处理
- JAVA LIST分批处理
- 分批次处理List
- List<Getmsgres.DataBean.ListBean> list如何处理
- win7_win8
- 意想不到的有趣linux命令
- Windows 7 Visual Studio 2008配置OpenGL开发环境
- Spring数据源配置方式
- ASP.NET MVC3学习笔记五(Controller)
- 自处理list
- mysql导入报 Error Code: 2006 - MySQL 服务器已离线错误
- IOS 内部购买
- OpenCV成长之路(6):数学形态学基本操作及其应用
- 关于ffmpeg如何提取视频的关键帧的问题
- repo新的下载地址
- make file中ifneq含义
- Revit二次开发首次使用
- Swap Nodes in Pairs