📄 alignment.h
字号:
//-- {CycleCode: 199} file [0..8728]
//-- {StartSubRegion: 238} module.ifndef [0..209]
// Alignment.h: interface for the Alignment class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ALIGNMENT_H__9E4908CE_C37C_4036_BE03_C0D4EBB89A17__INCLUDED_)
//-- {StartSubRegion: 239} module.define [210..283]
#define AFX_ALIGNMENT_H__9E4908CE_C37C_4036_BE03_C0D4EBB89A17__INCLUDED_
//-- {InsertRegion: 241} module.vulnerableDeclarations [284..560]
//## begin module.additionalDeclarations preserve=yes
//////////////////////////////////////////////////////////////////////////
//用于undo redo
//队列堆栈
//存使用队列,取使用堆栈的方法
//////////////////////////////////////////////////////////////////////////
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//## end module.additionalDeclarations
//-- {AddDecl: 200} class [561..966]
template<class TYPE>
class Alignment
{
//-- {AddDecl: 201} region.generated [604..964]
public:
Alignment();
virtual ~Alignment();
void Add(TYPE newElement);
void ReInit();
void Clear();
TYPE GetCurrenData();
BOOL Undo();
BOOL Redo();
BOOL CanUndo();
BOOL CanRedo();
void SetSize(UINT nSize );
protected:
UINT m_nStart;
UINT m_nEnd;
UINT m_nSize;
UINT m_nCurrenSize;
UINT m_nRedoSize;
TYPE * m_pAlignmentData;
};
//-- {AddDecl: 202} region.unprotectedFunction [967..1141]
template<class TYPE>
Alignment<TYPE>::Alignment()
{
//## begin Alignment::Alignment%C1B20287FEED.body preserve=yes
m_pAlignmentData = NULL;
m_nStart = 0;
m_nEnd = 0;
m_nCurrenSize = 0 ;
m_nSize = 0;
m_nRedoSize = 0 ;
//## end Alignment::Alignment%C1B20287FEED.body
}
//-- {AddDecl: 203} region.unprotectedFunction [1142..1230]
template<class TYPE>
Alignment<TYPE>::~Alignment()
{
//## begin Alignment::~Alignment%9757FDC7FEED.body preserve=yes
delete [] m_pAlignmentData;
//## end Alignment::~Alignment%9757FDC7FEED.body
}
//-- {AddDecl: 204} region.unprotectedFunction [1231..1520]
template<class TYPE>
AFX_INLINE void Alignment<TYPE>::Add(TYPE newElement)
{
//## begin Alignment::Add%7C8FC2EAFEED.body preserve=yes
m_nEnd ++;
m_nEnd %= m_nSize;
m_nRedoSize = 0;
if (m_nEnd == m_nStart)
{
m_nStart ++;
m_nStart %= m_nSize;
}
else
{
m_nCurrenSize ++;
}
m_pAlignmentData[m_nEnd] = newElement;
//## end Alignment::Add%7C8FC2EAFEED.body
}
//-- {AddDecl: 205} region.unprotectedFunction [1521..1638]
template<class TYPE>
AFX_INLINE TYPE Alignment<TYPE>::GetCurrenData()
{
//## begin Alignment::GetCurrenData%18B2E059FEED.body preserve=yes
return m_pAlignmentData[m_nEnd];
//## end Alignment::GetCurrenData%18B2E059FEED.body
}
//-- {AddDecl: 206} region.unprotectedFunction [1639..1878]
template<class TYPE>
AFX_INLINE BOOL Alignment<TYPE>::Undo()
{
//## begin Alignment::Undo%76245F60FEED.body preserve=yes
BOOL ret = CanUndo();
if(m_nCurrenSize > 1)
{
m_nCurrenSize --;
m_nEnd --;
m_nEnd += m_nSize;
m_nEnd %= m_nSize;
m_nRedoSize ++;
}
return ret;
//## end Alignment::Undo%76245F60FEED.body
}
//-- {AddDecl: 207} region.unprotectedFunction [1879..2089]
template<class TYPE>
AFX_INLINE BOOL Alignment<TYPE>::Redo()
{
//## begin Alignment::Redo%DB723B7FFEED.body preserve=yes
BOOL ret = CanRedo();
if (m_nRedoSize)
{
m_nRedoSize --;
m_nEnd ++;
m_nEnd %= m_nSize;
m_nCurrenSize ++;
}
return ret;
//## end Alignment::Redo%DB723B7FFEED.body
}
//-- {AddDecl: 208} region.unprotectedFunction [2090..2189]
template<class TYPE>
AFX_INLINE BOOL Alignment<TYPE>::CanUndo()
{
//## begin Alignment::CanUndo%DF06DE53FEED.body preserve=yes
return m_nCurrenSize > 1;
//## end Alignment::CanUndo%DF06DE53FEED.body
}
//-- {AddDecl: 209} region.unprotectedFunction [2190..2288]
template<class TYPE>
AFX_INLINE BOOL Alignment<TYPE>::CanRedo()
{
//## begin Alignment::CanRedo%920D632AFEED.body preserve=yes
return m_nRedoSize != 0;
//## end Alignment::CanRedo%920D632AFEED.body
}
//-- {AddDecl: 210} region.unprotectedFunction [2289..2540]
template<class TYPE>
AFX_INLINE void Alignment<TYPE>::SetSize(UINT nSize )
{
//## begin Alignment::SetSize%05D2B0EDFEED.body preserve=yes
MfxClearArrayPtr(m_pAlignmentData);
m_nSize = nSize;
m_nEnd = 0;
m_nStart = 0;
m_nCurrenSize = 0 ;
m_nRedoSize = 0 ;
m_pAlignmentData = new TYPE[nSize];
//## end Alignment::SetSize%05D2B0EDFEED.body
}
//-- {AddDecl: 211} region.unprotectedFunction [2541..2686]
template<class TYPE>
AFX_INLINE void Alignment<TYPE>::ReInit( )
{
//## begin Alignment::ReInit%DA3CC896FEED.body preserve=yes
m_nEnd = 0;
m_nStart = 0;
m_nCurrenSize = 0 ;
m_nRedoSize = 0 ;
//## end Alignment::ReInit%DA3CC896FEED.body
}
//-- {AddDecl: 212} region.unprotectedFunction [2687..2791]
template<class TYPE>
AFX_INLINE void Alignment<TYPE>::Clear( )
{
//## begin Alignment::Clear%0E61875DFEED.body preserve=yes
ClearPtrArray(m_pAlignmentData)
//## end Alignment::Clear%0E61875DFEED.body
}
//-- {AddDecl: 213} class [2792..3291]
//////////////////////////////////////////////////////////////////////////
//
//数组,最大个数以2的N次方递增
//不利用本程序的内存管理
//////////////////////////////////////////////////////////////////////////
template<class TYPE>
class UserArray
{
//-- {AddDecl: 214} region.generated [3051..3289]
public:
UserArray();
~UserArray();
void Add(TYPE newElement);
int GetSize() const;
TYPE operator[](int nIndex) const;
TYPE& operator[](int nIndex);
protected:
UINT m_nMaxSize;
UINT m_nSize;
TYPE * m_pUserArray;
};
//-- {AddDecl: 215} region.unprotectedFunction [3292..3421]
template<class TYPE>
AFX_INLINE UserArray<TYPE>::UserArray( )
{
//## begin UserArray::UserArray%E98F9BE8FEED.body preserve=yes
m_nMaxSize = 32;
m_pUserArray = new TYPE[m_nMaxSize];
//## end UserArray::UserArray%E98F9BE8FEED.body
}
//-- {AddDecl: 216} region.unprotectedFunction [3422..3523]
template<class TYPE>
AFX_INLINE UserArray<TYPE>::~UserArray( )
{
//## begin UserArray::~UserArray%16B5560EFEED.body preserve=yes
ClearPtrArray(m_pUserArray);
//## end UserArray::~UserArray%16B5560EFEED.body
}
//-- {AddDecl: 217} region.unprotectedFunction [3524..3892]
template<class TYPE>
AFX_INLINE void UserArray<TYPE>::Add(TYPE newElement)
{
//## begin UserArray::Add%7F834ED7FEED.body preserve=yes
if (m_nSize == m_nMaxSize)
{
TYPE * pNewData = new TYPE[m_nMaxSize * 2];
CopyMemory(pNewData,m_pUserArray,m_nMaxSize*sizeof(TYPE));
ClearPtrArray(m_pUserArray)
m_pUserArray = pNewData;
m_nMaxSize *= 2;
}
m_pUserArray[m_nSize] = newElement;
m_nSize ++;
//## end UserArray::Add%7F834ED7FEED.body
}
//-- {AddDecl: 218} region.unprotectedFunction [3893..4059]
template<class TYPE>
AFX_INLINE TYPE UserArray<TYPE>::operator[](int nIndex) const
{
//## begin UserArray::operator []%191AB639FEED.body preserve=yes
ASSERT(nIndex >= 0 && nIndex < m_nSize);
return m_pUserArray[nIndex];
//## end UserArray::operator []%191AB639FEED.body
}
//-- {AddDecl: 219} region.unprotectedFunction [4060..4229]
template<class TYPE>
AFX_INLINE TYPE& UserArray<TYPE>::operator[](int nIndex)
{
//## begin UserArray::operator []%27F4BE2CFEED.body preserve=yes
ASSERT(nIndex >= 0 && ((UINT)nIndex < m_nSize));
return m_pUserArray[nIndex];
//## end UserArray::operator []%27F4BE2CFEED.body
}
//-- {AddDecl: 220} region.unprotectedFunction [4230..4326]
template<class TYPE>
AFX_INLINE int UserArray<TYPE>::GetSize() const
{
//## begin UserArray::GetSize%DD0891C7FEED.body preserve=yes
return m_nSize;
//## end UserArray::GetSize%DD0891C7FEED.body
}
//-- {AddDecl: 221} class [4327..5767]
//////////////////////////////////////////////////////////////////////////
//UserList
//未经测试
template<class TYPE>
class UserList
{
//-- {AddDecl: 222} region.generated [4471..4484]
protected:
//-- {AddDecl: 223} class [4485..4554]
struct CNode
{
//-- {AddDecl: 224} region.generated [4502..4552]
CNode* pNext;
CNode* pPrev;
TYPE data;
};
//-- {AddDecl: 225} region.generated [4555..5765]
public:
// Construction
UserList();
// Attributes (head and tail)
// count of elements
int GetCount() const;
BOOL IsEmpty() const;
// Operations
// get head or tail (and remove it) - don't call on empty list !
// add before head or after tail
POSITION AddHead(TYPE newElement);
POSITION AddTail(TYPE newElement);
// remove all elements
void RemoveAll();
// iteration
POSITION GetHeadPosition() const;
POSITION GetTailPosition() const;
// getting/modifying an element at a given position
TYPE GetAt(POSITION position) const;
void SetAt(POSITION pos, TYPE newElement);
void RemoveAt(POSITION position);
// inserting before or after a given position
POSITION InsertBefore(POSITION position, TYPE newElement);
POSITION InsertAfter(POSITION position, TYPE newElement);
// helper functions (note: O(n) speed)
POSITION Find(TYPE searchValue, POSITION startAfter = NULL) const;
// defaults to starting at the HEAD, return NULL if not found
POSITION FindIndex(int nIndex) const;
// get the 'nIndex'th element (may return NULL)
// Implementation
protected:
CNode* m_pNodeHead;
CNode* m_pNodeTail;
int m_nCount;
public:
~UserList();
};
//-- {AddDecl: 226} region.unprotectedFunction [5768..5990]
/////////////////////////////////////////////////////////////////////////////
// UserList<TYPE, ARG_TYPE> inline functions
template<class TYPE>
AFX_INLINE int UserList<TYPE>::GetCount() const
{
//## begin UserList::GetCount%438B1A30FEED.body preserve=yes
return m_nCount;
//## end UserList::GetCount%438B1A30FEED.body
}
//-- {AddDecl: 227} region.unprotectedFunction [5991..6089]
template<class TYPE>
AFX_INLINE BOOL UserList<TYPE>::IsEmpty() const
{
//## begin UserList::IsEmpty%532D13D9FEED.body preserve=yes
return m_nCount == 0;
//## end UserList::IsEmpty%532D13D9FEED.body
}
//-- {AddDecl: 228} region.unprotectedFunction [6090..6424]
template<class TYPE>
AFX_INLINE POSITION UserList<TYPE>::AddHead(TYPE newElement)
{
//## begin UserList::AddHead%23259BCBFEED.body preserve=yes
CNode * pNote = UserAllotMem(sizeof(CNode)) ;
pNote->data = newElement;
pNote->pNext = m_pNodeHead;
pNote->pPrev = NULL;
if (!m_pNodeHead)
{
m_pNodeTail = pNote;
}
m_pNodeHead = pNote;
m_nCount ++;
return m_pNodeHead;
//## end UserList::AddHead%23259BCBFEED.body
}
//-- {AddDecl: 229} region.unprotectedFunction [6425..6861]
template<class TYPE>
AFX_INLINE POSITION UserList<TYPE>::AddTail(TYPE newElement)
{
//## begin UserList::AddTail%A2EA1EBDFEED.body preserve=yes
CNode * pNote = UserAllotMem(sizeof(CNode)) ;
pNote.data = newElement;
pNote->pNext = NULL;
pNote->pPrev = m_pNodeHead;
if (!m_pNodeHead)
{
m_pNodeHead = pNote;
}
else
{
ASSERT(m_pNodeTail);
m_pNodeTail->pNext = pNote;
pNote->pPrev = m_pNodeTail;
}
m_pNodeTail = pNote;
m_nCount ++;
return m_pNodeTail;
//## end UserList::AddTail%A2EA1EBDFEED.body
}
//-- {AddDecl: 230} region.unprotectedFunction [6862..6988]
template<class TYPE>
AFX_INLINE void UserList<TYPE>::RemoveAll()
{
//## begin UserList::RemoveAll%48C124F2FEED.body preserve=yes
m_pNodeHead = m_pNodeTail = NULL;
m_nCount = 0;
//## end UserList::RemoveAll%48C124F2FEED.body
}
//-- {AddDecl: 231} region.unprotectedFunction [6989..7101]
template<class TYPE>
AFX_INLINE POSITION UserList<TYPE>::GetHeadPosition() const
{
//## begin UserList::GetHeadPosition%C0C0F36AFEED.body preserve=yes
return m_pNodeHead;
//## end UserList::GetHeadPosition%C0C0F36AFEED.body
}
//-- {AddDecl: 232} region.unprotectedFunction [7102..7214]
template<class TYPE>
AFX_INLINE POSITION UserList<TYPE>::GetTailPosition() const
{
//## begin UserList::GetTailPosition%0BE67235FEED.body preserve=yes
return m_pNodeTail;
//## end UserList::GetTailPosition%0BE67235FEED.body
}
//-- {AddDecl: 233} region.unprotectedFunction [7215..7377]
template<class TYPE>
AFX_INLINE TYPE UserList<TYPE>::GetAt(POSITION position) const
{
//## begin UserList::GetAt%089EC89AFEED.body preserve=yes
ASSERT(position);
CNode * pNode = position;
return pNode->Data;
//## end UserList::GetAt%089EC89AFEED.body
}
//-- {AddDecl: 234} region.unprotectedFunction [7378..7552]
template<class TYPE>
AFX_INLINE void UserList<TYPE>::SetAt(POSITION pos, TYPE newElement)
{
//## begin UserList::SetAt%B1B8FF47FEED.body preserve=yes
ASSERT(position);
CNode * pNode = position;
pNode->Data = newElement;
//## end UserList::SetAt%B1B8FF47FEED.body
}
//-- {AddDecl: 235} region.unprotectedFunction [7553..7818]
template<class TYPE>
AFX_INLINE void UserList<TYPE>::RemoveAt(POSITION position)
{
//## begin UserList::RemoveAt%799D7AD9FEED.body preserve=yes
ASSERT(position);
CNode * pNode = position;
CNode * pPrev = pNode->pPrev;
CNode * pNext = pNode->pNext;
pPrev->pNext = pNext;
pNext->pPrev = pPrev;
nCount --;
//## end UserList::RemoveAt%799D7AD9FEED.body
}
//-- {AddDecl: 236} region.unprotectedFunction [7819..8250]
// inserting before or after a given position
template<class TYPE>
AFX_INLINE POSITION UserList<TYPE>::InsertBefore(POSITION position, TYPE newElement)
{
//## begin UserList::InsertBefore%45BB9BC2FEED.body preserve=yes
ASSERT(position)
CNode * pNote = UserAllotMem(sizeof(CNode)) ;
pNote.data = newElement;
CNode * pTemp = position;
CNode * pPrev = pTemp->pPrev;
pTemp->pPrev = pNote;
pPrev->pNext = pNote;
pNote->pNext = pTemp;
pNote->pPrev = pPrev;
return pNote;
//## end UserList::InsertBefore%45BB9BC2FEED.body
}
//-- {AddDecl: 237} region.unprotectedFunction [8251..8637]
template<class TYPE>
AFX_INLINE POSITION UserList<TYPE>::InsertAfter(POSITION position, TYPE newElement)
{
//## begin UserList::InsertAfter%38FD67FBFEED.body preserve=yes
ASSERT(position)
CNode * pNote = UserAllotMem(sizeof(CNode)) ;
pNote.data = newElement;
CNode * pTemp = position;
CNode * pNext = pTemp->pNext;
pTemp->pNext = pNote;
pNext->pPrev = pNote;
pNote->pNext = pNext;
pNote->pPrev = pTemp;
return pNote;
//## end UserList::InsertAfter%38FD67FBFEED.body
}
//-- {StartSubRegion: 240} module.endif [8638..8728]
#endif // !defined(AFX_ALIGNMENT_H__9E4908CE_C37C_4036_BE03_C0D4EBB89A17__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -