183 lines
4.1 KiB
C++
183 lines
4.1 KiB
C++
#ifndef _TEST_PAGE_HPP_
|
|
#define _TEST_PAGE_HPP_
|
|
#ifndef _COMMON_SMARTPOINTER_HPP_
|
|
#include <common/pointer.hpp>
|
|
#endif
|
|
#ifndef __SGI_STL_VECTOR_H
|
|
#include <sgi_stl/vector.h>
|
|
#endif
|
|
|
|
typedef vector<char> CharRow;
|
|
typedef vector<Attribute> AttributeRow;
|
|
typedef vector<CharRow> PageData;
|
|
typedef vector<AttributeRow> PageAttributes;
|
|
typedef SmartPointer<CharRow> CharRowPointer;
|
|
typedef SmartPointer<AttributeRow> AttributeRowPointer;
|
|
typedef SmartPointer<PageData> PageDataPointer;
|
|
typedef SmartPointer<PageAttributes> PageAttributesPointer;
|
|
|
|
class PurePage
|
|
{
|
|
public:
|
|
enum{InitialRows=25,InitialCols=80};
|
|
enum State{Created=0x0001,Updated=0x0002,Clear=0x0004,Published=0x0008};
|
|
PurePage(unsigned rows=InitialRows,unsigned cols=InitialCols);
|
|
PurePage(const PurePage &somePurePage);
|
|
virtual ~PurePage();
|
|
PurePage &operator=(const PurePage &somePurePage);
|
|
bool operator==(const PurePage &somePurePage)const;
|
|
unsigned getRows(void);
|
|
unsigned getCols(void);
|
|
|
|
bool getAt(unsigned row,unsigned col,char &charData,Attribute &attribute);
|
|
bool getAt(unsigned row,CharRowPointer &charRowPointer,AttributeRowPointer &attributeRowPointer);
|
|
bool setAt(unsigned row,unsigned col,char &charData);
|
|
bool setAt(unsigned row,CharRowPointer &charRowPointer,AttributeRowPointer &attributeRowPointer);
|
|
|
|
bool queryState(State state)const;
|
|
void setState(State state);
|
|
void clearState(State state);
|
|
void clearPage(void);
|
|
private:
|
|
void createPage(unsigned rows,unsigned cols);
|
|
bool copyPage(PurePage &purePage);
|
|
|
|
unsigned mRows;
|
|
unsigned mCols;
|
|
int mState;
|
|
PageData mPageData;
|
|
PageAttributes mPageAttributes;
|
|
};
|
|
|
|
inline
|
|
PurePage::PurePage(unsigned rows,unsigned cols)
|
|
{
|
|
createPage(rows,cols);
|
|
setState(Created);
|
|
}
|
|
|
|
inline
|
|
PurePage::PurePage(const PurePage &somePurePage)
|
|
{
|
|
*this=somePurePage;
|
|
}
|
|
|
|
inline
|
|
PurePage::~PurePage()
|
|
{
|
|
}
|
|
|
|
inline
|
|
PurePage &PurePage::operator=(const PurePage &somePurePage)
|
|
{
|
|
copyPage(somePurePage);
|
|
return *this;
|
|
}
|
|
|
|
inline
|
|
bool PurePage::operator==(const PurePage &somePurePage)const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
inline
|
|
unsigned PurePage::getRows(void)
|
|
{
|
|
return mRows;
|
|
}
|
|
|
|
inline
|
|
unsigned PurePage::getCols(void)
|
|
{
|
|
return mCols;
|
|
}
|
|
|
|
inline
|
|
bool PurePage::getAt(unsigned row,unsigned col,char &charData,Attribute &attribute)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
inline
|
|
bool PurePage::getAt(unsigned row,CharRowPointer &charRowPointer,AttributeRowPointer &attributeRowPointer)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
inline
|
|
bool PurePage::setAt(unsigned row,unsigned col,char &charData)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
inline
|
|
bool PurePage::setAt(unsigned row,CharRowPointer &charRowPointer,AttributeRowPointer &attributeRowPointer)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
inline
|
|
void PurePage::setState(State state)
|
|
{
|
|
mState|=int(state);
|
|
}
|
|
|
|
inline
|
|
void PurePage::clearState(State state)
|
|
{
|
|
mState|=int(~state);
|
|
}
|
|
|
|
inline
|
|
bool PurePage::queryState(State state)const
|
|
{
|
|
return mState&state;
|
|
}
|
|
|
|
inline
|
|
void PurePage::createPage(unsigned rows,unsigned cols)
|
|
{
|
|
unsigned row;
|
|
unsigned col;
|
|
|
|
mPageData.empty();
|
|
mPageAttributes.empty();
|
|
for(row=0;row<rows;row++){mPageData.push_back();for(col=0;col<cols;col++)mPageData[row].push_back();}
|
|
for(row=0;row<rows;row++){mPageData.push_back();for(col=0;col<cols;col++)mPageAttributes[row].push_back();}
|
|
mRows=rows;
|
|
mCols=cols;
|
|
}
|
|
|
|
inline
|
|
void PurePage::clearPage(void)
|
|
{
|
|
unsigned row;
|
|
|
|
for(row=0;row<getRows();row++)
|
|
{
|
|
::memset(mPageData[row].begin(),' ',mPageData[row].end()-mPageData[row].begin());
|
|
::memset(mPageAttributes[row].begin(),0,mPageAttributes[row].end()-mPageAttributes[row].begin());
|
|
}
|
|
}
|
|
|
|
inline
|
|
bool PurePage::copyPage(PurePage &purePage)
|
|
{
|
|
unsigned row;
|
|
|
|
createPage(purePage.getRows(),purePage.getCols());
|
|
for(row=0;row<getRows();row++)
|
|
{
|
|
::memcpy(mPageData[row].begin(),purePage[row].begin(),purePage.getCols());
|
|
::memcpy(mPageAttributes[row].begin(),purePage[row].begin(),purePage.getCols());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
//bool getAt(unsigned row,unsigned col,char &charData,Attribute &attribute);
|
|
// bool getAt(unsigned row,CharRowPointer &charRowPointer,AttributeRowPointer &attributeRowPointer);
|
|
// bool setAt(unsigned row,unsigned col,char &charData);
|
|
// bool setAt(unsigned row,CharRowPointer &charRowPointer,AttributeRowPointer &attributeRowPointer);
|
|
#endif
|