C++ Forever
my feeling and C++'s
posts - 5, comments - 12, trackbacks - 0, articles - 0
導(dǎo)航
C++博客
首頁(yè)
新隨筆
聯(lián)系
聚合
管理
<
2008年7月
>
日
一
二
三
四
五
六
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
常用鏈接
我的隨筆
我的評(píng)論
我參與的隨筆
留言簿
(1)
給我留言
查看公開(kāi)留言
查看私人留言
隨筆檔案
2008年7月 (1)
2008年6月 (2)
2008年5月 (1)
2008年4月 (1)
friends
楊鵬
搜索
最新評(píng)論
1.?re: 有關(guān)一個(gè)Redo和Undo的一個(gè)框架
微軟有個(gè)Undo接口,按照這個(gè)接口實(shí)現(xiàn)應(yīng)該好一些,畢竟經(jīng)過(guò)實(shí)踐了的。
--萬(wàn)連文
2.?re: 有關(guān)一個(gè)Redo和Undo的一個(gè)框架
@夢(mèng)在天涯
前一個(gè)我是用模板做的,不是很好,邏輯上有問(wèn)題
--HYin
3.?re: 有關(guān)一個(gè)Redo和Undo的一個(gè)框架
好東東!超有用啊!
如果更模塊化下會(huì)更好啊,以后讓大家都可以用哦!
--夢(mèng)在天涯
4.?re: 有關(guān)一個(gè)Redo和Undo的一個(gè)框架[未登錄](méi)
評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
--NAME
5.?re: 有關(guān)一個(gè)Redo和Undo的一個(gè)框架
不錯(cuò),學(xué)習(xí)了!
--cexer
閱讀排行榜
1.?使用QTcpSocket實(shí)現(xiàn)FTP客戶端的一個(gè)beta1.0版本(Qt4.3)(6051)
2.?C語(yǔ)言中strtok與strpbrk的區(qū)別(轉(zhuǎn))(5534)
3.?有關(guān)一個(gè)Redo和Undo的一個(gè)框架(2551)
4.?為什么在QRubberBand出現(xiàn)問(wèn)題(1643)
5.?原來(lái)最好的就是最簡(jiǎn)單的(656)
評(píng)論排行榜
1.?有關(guān)一個(gè)Redo和Undo的一個(gè)框架(5)
2.?C語(yǔ)言中strtok與strpbrk的區(qū)別(轉(zhuǎn))(4)
3.?使用QTcpSocket實(shí)現(xiàn)FTP客戶端的一個(gè)beta1.0版本(Qt4.3)(2)
4.?原來(lái)最好的就是最簡(jiǎn)單的(1)
5.?為什么在QRubberBand出現(xiàn)問(wèn)題(0)
有關(guān)一個(gè)Redo和Undo的一個(gè)框架
Posted on 2008-07-08 15:00
HYin
閱讀(2551)
評(píng)論(5)
編輯
收藏
引用
前不久看了 敏捷軟件開(kāi)發(fā) 原則、模式與實(shí)踐,有點(diǎn)想法,所以就把我以前寫(xiě)得一個(gè)RedoUndo的框架改了一下,成了下面的情況。
我將操作RedoUndo的模塊的接口獨(dú)立了出來(lái),這樣在將來(lái)的擴(kuò)展上就不會(huì)有太大的困難,并且將他獨(dú)立與顯示模塊很大程度上避免了耦合。
在使用的時(shí)候可以有選擇的使用RedoUndo的功能,如果某個(gè)工具需要RedoUndo的功能則直接繼承與TransactionCommand即可。這樣避免了冗余,在一些工具中不用承擔(dān)一些不需要的永遠(yuǎn)不會(huì)用到的方法。
RedoUndo模塊是使用標(biāo)準(zhǔn)的C++寫(xiě)的,為了測(cè)試這個(gè)模塊我使用了Qt庫(kù),用于圖形顯示,這樣產(chǎn)生了一個(gè)新的模塊DrawTransaction。
1
/**/
/*
**********************************************************************
2
* \file TransactionCommand.h
3
* \date 2008-07-06
4
* \author HYin
5
*********************************************************************
*/
6
7
#ifndef TRANSACTIONCOMMAND_H
8
#define
TRANSACTIONCOMMAND_H
9
10
namespace
hy
11
{
12
class
TransactionCommand
13
{
14
public
:
15
TransactionCommand();
16
virtual
~
TransactionCommand();
17
18
virtual
bool
redo()
=
0
;
19
virtual
bool
undo()
=
0
;
20
21
}
;
22
}
23
24
#endif
25
1
/**/
/*
**********************************************************************
2
* \file RedoUndo.h
3
* \date 2008-07-06
4
* \author HYin
5
*********************************************************************
*/
6
7
#ifndef REDOUNDOTOOL_H
8
#define
REDOUNDOTOOL_H
9
10
//
---------------------------------------------------------------------------------------------------------------
11
#include
"
TransactionCommand.h
"
12
#include
<
vector
>
13
//
---------------------------------------------------------------------------------------------------------------
14
15
namespace
hy
16
{
17
class
TransactionCommand;
18
19
class
RedoUndoTool :
public
TransactionCommand
20
{
21
typedef TransactionCommand Command;
22
public
:
23
explicit
RedoUndoTool(
int
depth
=
10
);
24
25
void
setDepth(
int
depth )
26
{ m_iRedoUndoDepth
=
depth; }
27
28
void
add( Command
*
command );
29
30
void
clear()
31
{ m_aCommandStack.clear(); }
32
33
virtual
bool
redo();
34
virtual
bool
undo();
35
36
private
:
37
//
depth for undo transaction
38
int
m_iRedoUndoDepth;
39
40
//
current step
41
int
m_iCurrentStep;
42
43
//
Command stack to store
44
std::vector
<
Command
*
>
m_aCommandStack;
45
46
}
;
47
48
}
49
50
#endif
51
1
/**/
/*
**********************************************************************
2
* \file RedoUndo.cpp
3
* \date 2008-07-06
4
* \author HYin
5
*********************************************************************
*/
6
7
//
---------------------------------------------------------------------------------------------------------------
8
#include
"
RedoUndoTool.h
"
9
#include
<
iostream
>
10
#include
<
assert.h
>
11
using
namespace
std;
12
//
---------------------------------------------------------------------------------------------------------------
13
14
//
---------------------------------------------------------------------------------------------------------------
15
#define
hy_assert_error(str) { std::cerr << str << endl; assert(false); }
16
#define
hy_assert_warning(str) { std::cout << str << endl; }
17
//
---------------------------------------------------------------------------------------------------------------
18
19
namespace
hy
20
{
21
RedoUndoTool::RedoUndoTool(
int
depth )
22
: m_iRedoUndoDepth(depth), m_iCurrentStep(
-
1
)
23
{
24
m_aCommandStack.clear();
25
}
26
27
void
RedoUndoTool::add( RedoUndoTool::Command
*
command )
28
{
29
int
num
=
m_aCommandStack.size();
30
31
if
( m_iCurrentStep
==
num
-
1
||
m_iCurrentStep
==
-
1
)
32
{
33
m_aCommandStack.push_back(command);
34
m_iCurrentStep
++
;
35
}
36
else
if
( m_iCurrentStep
<
num
-
1
)
37
{
38
m_aCommandStack.erase(
39
m_aCommandStack.begin()
+
m_iCurrentStep
+
1
, m_aCommandStack.end()
40
);
41
m_aCommandStack.push_back(command);
42
m_iCurrentStep
++
;
43
}
44
else
45
{
46
hy_assert_error(
"
error : RedoUndoTool::add( const RedoUndoTool::Command & command ) :
"
47
<<
"
invalid m_iCurrentStep
"
);
48
}
49
50
//
keep the depth
51
num
=
m_aCommandStack.size();
52
if
( num
>
m_iRedoUndoDepth )
53
{
54
m_aCommandStack.erase( m_aCommandStack.begin(),
55
m_aCommandStack.begin()
+
num
-
m_iRedoUndoDepth );
56
m_iCurrentStep
=
m_iRedoUndoDepth
-
1
;
57
}
58
}
59
60
bool
RedoUndoTool::redo()
61
{
62
int
num
=
m_aCommandStack.size();
63
if
( m_iCurrentStep
==
num
-
1
)
64
{
65
hy_assert_warning(
"
warning : RedoUndoTool::redo() :
"
66
<<
"
out of range: default to return directively!!
"
);
67
}
68
else
if
( m_iCurrentStep
<
num
-
1
&&
m_iCurrentStep
>=
-
1
)
69
{
70
return
m_aCommandStack[
++
m_iCurrentStep]
->
redo();
71
}
72
else
73
{
74
hy_assert_error(
"
error : RedoUndoTool::redo() :
"
75
<<
"
invalid m_iCurrentStep
"
);
76
}
77
return
false
;
78
}
79
80
bool
RedoUndoTool::undo()
81
{
82
int
num
=
m_aCommandStack.size();
83
if
( m_iCurrentStep
==
-
1
)
84
{
85
hy_assert_warning(
"
warning : RedoUndoTool::undo() :
"
86
<<
"
out of range: default to return directively!!
"
);
87
}
88
else
if
( m_iCurrentStep
<=
num
-
1
&&
m_iCurrentStep
>
-
1
)
89
{
90
return
m_aCommandStack[m_iCurrentStep
--
]
->
undo();
91
}
92
else
93
{
94
hy_assert_error(
"
error : RedoUndoTool::undo() :
"
95
<<
"
invalid m_iCurrentStep
"
);
96
}
97
return
false
;
98
}
99
100
}
101
這是顯示模塊,在這里只顯示接口
1
/**/
/*
**********************************************************************
2
* \file DrawTransaction.h
3
* \date 2008-07-07
4
* \author HYin
5
*********************************************************************
*/
6
7
#ifndef DRAWTRANSACTION_H
8
#define
DRAWTRANSACTION_H
9
10
//
---------------------------------------------------------------------------------------------------------------
11
//
---------------------------------------------------------------------------------------------------------------
12
13
namespace
hy
14
{
15
class
DrawTransaction
16
{
17
public
:
18
DrawTransaction();
19
virtual
~
DrawTransaction();
20
21
virtual
void
draw()
=
0
;
22
}
;
23
}
24
25
#endif
26
Feedback
#
re: 有關(guān)一個(gè)Redo和Undo的一個(gè)框架
回復(fù)
更多評(píng)論
2008-07-09 09:22 by
cexer
不錯(cuò),學(xué)習(xí)了!
#
re: 有關(guān)一個(gè)Redo和Undo的一個(gè)框架[未登錄](méi)
回復(fù)
更多評(píng)論
2008-07-09 16:46 by
NAME
http://topic.csdn.net/u/20080709/16/7e145829-588c-4962-9a95-bd784becb120.html
#
re: 有關(guān)一個(gè)Redo和Undo的一個(gè)框架
回復(fù)
更多評(píng)論
2008-07-10 23:02 by
夢(mèng)在天涯
好東東!超有用啊!
如果更模塊化下會(huì)更好啊,以后讓大家都可以用哦!
#
re: 有關(guān)一個(gè)Redo和Undo的一個(gè)框架
回復(fù)
更多評(píng)論
2008-07-12 22:11 by
HYin
@夢(mèng)在天涯
前一個(gè)我是用模板做的,不是很好,邏輯上有問(wèn)題
#
re: 有關(guān)一個(gè)Redo和Undo的一個(gè)框架
回復(fù)
更多評(píng)論
2008-07-12 23:37 by
萬(wàn)連文
微軟有個(gè)Undo接口,按照這個(gè)接口實(shí)現(xiàn)應(yīng)該好一些,畢竟經(jīng)過(guò)實(shí)踐了的。
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
【推薦】100%開(kāi)源!大型工業(yè)跨平臺(tái)軟件C++源碼提供,建模,組態(tài)!
網(wǎng)站導(dǎo)航:
博客園
IT新聞
BlogJava
博問(wèn)
Chat2DB
管理
Powered by:
C++博客
Copyright © HYin
国产成人久久精品一区二区三区
|
色欲综合久久中文字幕网
|
久久精品一本到99热免费
|
91久久香蕉国产熟女线看
|
国产亚洲美女精品久久久2020
|
久久国产高清一区二区三区
|
久久国产乱子伦免费精品
|
久久狠狠爱亚洲综合影院
|
久久高清一级毛片
|
国产AV影片久久久久久
|
久久国产乱子伦精品免费午夜
|
日韩人妻无码精品久久久不卡
|
久久久久亚洲AV无码专区体验
|
四虎影视久久久免费
|
国产精品亚洲综合专区片高清久久久
|
久久夜色精品国产噜噜麻豆
|
69SEX久久精品国产麻豆
|
中文字幕久久精品无码
|
久久久久久A亚洲欧洲AV冫
|
伊人久久免费视频
|
亚洲国产二区三区久久
|
国产麻豆精品久久一二三
|
久久久久人妻一区精品色
|
亚洲午夜久久久影院伊人
|
久久精品青青草原伊人
|
久久这里只精品99re66
|
人人妻久久人人澡人人爽人人精品
|
思思久久99热免费精品6
|
亚洲国产综合久久天堂
|
青青热久久国产久精品
|
色婷婷噜噜久久国产精品12p
|
久久中文字幕视频、最近更新
|
久久久精品久久久久特色影视
|
欧美成a人片免费看久久
|
日批日出水久久亚洲精品tv
|
亚洲国产综合久久天堂
|
成人综合久久精品色婷婷
|
亚洲色大成网站WWW久久九九
|
国产激情久久久久久熟女老人
|
亚洲国产美女精品久久久久∴
|
久久久噜噜噜久久熟女AA片
|