64,647
社区成员
发帖
与我相关
我的任务
分享
Disk Disk::operator=(const Disk& dk)
{
strcpy(m_mode,dk.m_mode);
sg_num_max=dk.sg_num_max;
sg_num=dk.sg_num;
if(sg)
delete []sg;
sg=new Segment[dk.sg_num_max];
memcpy(sg,dk.get_all_Segments(),sizeof(Segment)*sg_num);
for(int i=0;i<sg_num;i++)
{
for(int j=0;j<NUM_MAX;j++)
{
char temp[41];
dk.sg[i].get_word(temp,j);
sg[i].set_word(temp,j);
}
}
return *this;
}
#include<vector>
//segment.h;
class Segment
{
std::vector<char*> m_vecStrData;
int m_ivecSize;
public:
Segment(){};
Segment(const char strBuf[ ][2000], int iCount);
~Segment();
int match(const char strBuf[ ]) const;
void get_word(char strBuf[ ], int iIndex) const;
char get_char(int iStr, int iIndex) const;
}
//segment.cpp
Segment::Segment(const char strBuf[ ][2000], int iCount)
{
m_ivecSize = iCount;
for(int i = 0; i< iCount; i++)
{
char* pBuf = new char[2000];
if(NULL != pBuf)
{
strncpy( pBuf,&strBuf[i],2000);
m_vecStrData.push_back(pBuf);
}
}
}
int Segment::match(const char strBuf[ ]) const
{
int iRet = -1;
for(int i = 0; i< m_ivecSize; i++)
{
if (i > m_vecStrData.size())
{
return iRet;
}
char* pBuf = m_vecStrData[i];
if ( 0 == strcmp(pBuf,strBuf))
{
iRet = i;
return iRet;
}
}
return iRet;
}
void Segment::get_word(char strBuf[ ], int iIndex) const
{
if (iIndex > m_ivecSize)
{
return ;
}
char* pBuf = m_vecStrData[iIndex];
strncpy(strBuf,pBuf,2000);
}
char Segment::get_char(int iStr, int iIndex) const
{
if (iIndex > m_ivecSize)
{
return 0;
}
char* pBuf = m_vecStrData[iIndex];
return *(pBuf+iStr);
}
Segment::~Segment()
{
for(int i = 0; i< m_ivecSize; i++)
{
char* pBuf = m_vecStrData[i];
if (NULL != pBuf)
{
delete pBuf;
pBuf = NULL;
}
}
m_vecStrData.clear();
}
#include <vector>
class Segment
{
std::vector <char*> m_vecStrData;
int ivecSize;
public:
Segment(){};
Segment(const char strBuf[ ][2000], int iCount);
~Segment()
int match(const char strBuf[ ]) const;
void get_word(char strBuf[ ], int iIndex) const;
char get_char(int iStr, int iIndex) const;
}
代码放这儿