?? mydata.cpp
字號:
// mydata.cpp: implementation of the mydata class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
//#include "richtest.h"
#include "mydata.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
mydata::mydata()
{AFX_MANAGE_STATE(AfxGetStaticModuleState());
pcom=NULL;
the_type=type_dou;
empty=TRUE;
outer=FALSE;
fushu=FALSE;
line_count=1;
info=NULL;
pdata.ch=NULL;
pdata.dou=NULL;
pdata.in=NULL;
pdata.sh=NULL;
pcom=NULL;
pdata.mw=NULL;
buffer=NULL;
the_length=0;
for(int i=0;i<MAX_MWARRAY;i++)
matrix_name[i]=NULL;
//mwArray* data.mw;
}
mydata::mydata(int in_length,mwArray* in)
{AFX_MANAGE_STATE(AfxGetStaticModuleState());
mydata();
the_type=type_mw;
the_length=in_length;
line_count=1;
pcom=NULL;
pdata.mw=new mwArray[the_length];
for(int i=0;i<the_length;i++)
*(pdata.mw+i)=*(in+i);
};
mydata::mydata(int in_length,mytype in_type,int info_length)
{AFX_MANAGE_STATE(AfxGetStaticModuleState());
mydata();
the_length=in_length;
the_type=in_type;
the_info_length=info_length;
buffer=new char[the_info_length+1];
line_count=1;
switch(in_type){
case type_char:
pdata.ch=new char[the_length];
case type_short:
pdata.sh=new short[the_length];
case type_int:
pdata.in=new int[the_length];
case type_dou:
pdata.dou=new double[the_length];
case type_com:
pcom=new command[the_length];
};
};
mydata::~mydata()
{AFX_MANAGE_STATE(AfxGetStaticModuleState());
if(!outer)
{if(pdata.ch!=NULL)
delete[] pdata.ch;
if(pdata.dou!=NULL)
delete[] pdata.dou;
if(pdata.in!=NULL)
delete[] pdata.in;
if(pdata.sh!=NULL)
delete[] pdata.sh;
if(pcom!=NULL)
delete[] pcom;
if(info!=NULL)
delete[] info;
if(pdata.mw!=NULL)
{
for(int i=0;i<the_length;i++)
{
(pdata.mw+i)->~mwArray();
if(matrix_name[i]!=NULL)
{
delete[] matrix_name[i];
matrix_name[i]=NULL;
}
}
}
if(pcom!=NULL)
{
for(int i=0;i<the_length;i++)
(pcom+i)->~command();
}
}
empty=TRUE;
pdata.ch=NULL;
pdata.dou=NULL;
pdata.in=NULL;
pdata.sh=NULL;
pdata.mw=NULL;
}
BOOL mydata::set_data(char* info,int info_length,mytype in_type,int in_count,double* in_data)
{ AFX_MANAGE_STATE(AfxGetStaticModuleState());
outer=FALSE;
int i;
if(in_count>=1)
empty=FALSE;
the_type=in_type;
the_length=in_count;
the_info_length=info_length;
buffer=new char[the_info_length-4+1];
for(i=0;i<the_info_length-4;i++)
*(buffer+i)=*(info++);
*(buffer+i)='\0';
if(in_type==type_char)
{
pdata.ch=new char[the_length];
for(i=0;i<the_length;i++)
*(pdata.ch+i)=*(in_data+i);
}
else if( in_type==type_short)
{
pdata.sh=new short[the_length];
for(i=0;i<the_length;i++)
*(pdata.sh+i)=*(in_data+i);
}
else if( in_type==type_int)
{
pdata.in=new int[the_length];
for(i=0;i<the_length;i++)
*(pdata.in+i)=*(in_data+i);
}
else if( in_type==type_dou)
{
pdata.dou=new double[the_length];
for(i=0;i<the_length;i++)
*(pdata.dou+i)=*(in_data+i);
};
return TRUE;
}
BOOL mydata::mset_data(char* info,int info_length,mytype in_type,char* name[],int name_length[],int line[],int column[],int in_count,double data[])
{AFX_MANAGE_STATE(AfxGetStaticModuleState());
outer=FALSE;
int i,j,k=0;
for(i=0;i<in_count;i++)
k+=line[i]*column[i];
// double* data=new double[k];
// for(i=0;i<k;i++)
// data1[i]=data[i];
int where=0;
if(in_count>=1)
empty=FALSE;
the_type=in_type;
// line_count=line;
// column_count=column;
// if(in_count<line*column)
// {AfxMessageBox("輸入數據不足");
// return FALSE;
// }
the_length=in_count;
the_info_length=info_length;
buffer=new char[the_info_length-4+1];
for(i=0;i<the_info_length-4;i++)
*(buffer+i)=*(info++);
*(buffer+i)='\0';
// mxArray* hhhhh;
int ii=sizeof(mwArray);
pdata.mw=new mwArray[the_length];
// matrix_line=new int[the_length];
// matrix_column=new int[the_length];
for(i=0;i<the_length;i++)
{
int ccc=line[i]*column[i];
double* ip=new double[ccc];
memset(ip,0,sizeof(double)*ccc);
mwArray bag(line[i],column[i],data+where,ip);
*(pdata.mw+i)=bag;
matrix_name[i]=new char[128];
this->name_length[i]=name_length[i];
matrix_line[i]=line[i];
matrix_column[i]=column[i];
for(j=0;j<name_length[i];j++)
{*(matrix_name[i]+j)=*(name[i]+j);
}
where+=column[i]*line[i];
}
return TRUE;
}
mydata mydata::eq(mydata op1)
{
return op1; };
int mydata::get_length()
{
return the_length;
}
mytype mydata::get_type()
{
return (mytype)the_type;
}
datao& mydata::get_data()
{
return pdata;
}
char* mydata::get_info()
{
return buffer;
}
mwArray& mydata::operator[](int i)
{
return pdata.mw[i];
}
BOOL mydata::mset_data(char *info, int info_length,mytype in_type,char *name[], int name_length[],int in_count, mwArray *data)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
outer=FALSE;
int i,j,where=0;
if(!empty)
this->~mydata();
if(in_count>=1)
empty=FALSE;
the_type=in_type;
the_length=in_count;
the_info_length=info_length;
buffer=new char[the_info_length+1];
for(i=0;i<the_info_length;i++)
*(buffer+i)=*(info++);
*(buffer+i)='\0';
pdata.mw=new mwArray[the_length];
// matrix_line=new int[the_length];
// matrix_column=new int[the_length];
for(i=0;i<the_length;i++)
{
*(pdata.mw+i)=*(data+i);
*(matrix_line+i)=(pdata.mw+i)->Size(1);
*(matrix_column+i)=(pdata.mw+i)->Size(2);
if(name!=NULL)
for(j=0;j<name_length[i];j++)
{*(matrix_name[i]+j)=*(name[i]+j);
}
else
{matrix_name[i]=NULL;
this->name_length[i]=NULL;
}
}
return TRUE;
}
BOOL mydata::mset_data(char *info, int info_length,mytype in_type,char *name[], int name_length[],int in_count, mxArray data[])
{AFX_MANAGE_STATE(AfxGetStaticModuleState());
outer=FALSE;
int i,j,where=0;
if(in_count>=1)
empty=FALSE;
the_type=in_type;
the_length=in_count;
the_info_length=info_length;
buffer=new char[the_info_length+1];
for(i=0;i<the_info_length;i++)
*(buffer+i)=*(info++);
*(buffer+i)='\0';
pdata.mw=new mwArray[the_length];
// matrix_line=new int[the_length];
// matrix_column=new int[the_length];
for(i=0;i<the_length;i++)
{
// *(data.mw+i)=mwArray(*(data+i));
// *(matrix_line+i)=(data.mw+i)->Size(1);
// *(matrix_column+i)=(data.mw+i)->Size(2);
if(name!=NULL)
for(j=0;j<name_length[i];j++)
{*(matrix_name[i]+j)=*(name[i]+j);
}
else
{matrix_name[i]=NULL;
this->name_length[i]=NULL;
}
}
return TRUE;
}
//double r[100],im[100];
void operator<<(CArchive& ar,mydata& it)
{
ar<<it.outer;
ar<<it.empty;
if(!it.empty)
{
ar<<(int)it.the_type;
if(it.the_type<=type_dou)
{ ar<<it.the_info_length;
for(int i=0;i<it.the_info_length;i++)
ar<<it.buffer[i];
ar<<it.the_length;
if(it.the_type==type_char)
{
it.pdata.ch=new char[it.the_length];
for(i=0;i<it.the_length;i++)
ar<<it.pdata.ch[i];
}
else if(it.the_type==type_short)
{
it.pdata.sh=new short[it.the_length];
for(i=0;i<it.the_length;i++)
ar<<it.pdata.sh[i];
}
else if(it.the_type==type_int)
{
it.pdata.in=new int[it.the_length];
for(i=0;i<it.the_length;i++)
ar<<it.pdata.in[i];
}
else if(it.the_type==type_dou)
{
it.pdata.dou=new double[it.the_length];
for(i=0;i<it.the_length;i++)
ar<<it.pdata.dou[i];
}
else if(it.the_type==type_com)
{
it.pcom=new command[it.the_length];
for(i=0;i<it.the_length;i++)
ar<<it.pdata.dou[i];
}
}
else if(it.the_type==type_info)
{ ar<<it.the_length;
for(int i=0;i<it.the_length;i++)
ar<<it.info[i];
}
else if(it.the_type==type_mw)
{
CString filename=it.docname;
filename+=".mat";
char lth=filename.GetLength();
char* head=filename.GetBuffer(lth);
ar<<it.the_info_length;
for(int i=0;i<it.the_info_length;i++)
ar<<it.buffer[i];
ar<<it.the_length;
for(i=0;i<it.the_length;i++)
ar<<it.name_length[i];
for(i=0;i<it.the_length;i++)
for(int j=0;j<it.name_length[i];j++)
ar<<it.matrix_name[i][j];
for(i=0;i<it.the_length;i++)
{
ar<<it.matrix_column[i];
ar<<it.matrix_line[i];
}
ar<<filename;
ar<<it.fushu;
// mwArray os(head),mode("w");
// os=fopen(os,mode);
// ofstream os(head,ios::out);
double r[10],ii[10];
for(i=0;i<it.the_length;i++)
{ it.pdata.mw[i].ExtractData(r,ii);
int l=it.pdata.mw[i].Size(1)+it.pdata.mw[i].Size(2);
ar<<l;
if(l>0)
it.os<<it.pdata.mw[i];
}
// mwArray ENDS;
// it.os<<ENDS<<ends;
//UINT GetBufferPtr(UINT nCommand, UINT nCount = 0,
// void** ppBufStart = NULL, void** ppBufMax = NULL);
}
}
}
void operator>>(CArchive& ar,mydata& it)
{AFX_MANAGE_STATE(AfxGetStaticModuleState());
CString docname;
ar>>it.outer;
ar>>it.empty;
if(!it.empty)
{ int bag;
ar>>bag;
it.the_type=(mytype)bag;
if(it.the_type<=type_dou)
{ ar>>it.the_info_length;
for(int i=0;i<it.the_info_length;i++)
ar>>it.buffer[i];
ar>>it.the_length;
if(it.the_type==type_char)
{
it.pdata.ch=new char[it.the_length];
for(i=0;i<it.the_length;i++)
ar>>it.pdata.ch[i];
}
else if(it.the_type==type_short)
{
it.pdata.sh=new short[it.the_length];
for(i=0;i<it.the_length;i++)
ar>>it.pdata.sh[i];
}
else if(it.the_type==type_int)
{
it.pdata.in=new int[it.the_length];
for(i=0;i<it.the_length;i++)
ar>>it.pdata.in[i];
}
else if(it.the_type==type_dou)
{
it.pdata.dou=new double[it.the_length];
for(i=0;i<it.the_length;i++)
ar>>it.pdata.dou[i];
}
else if(it.the_type==type_com)
{
it.pcom=new command[it.the_length];
for(i=0;i<it.the_length;i++)
ar>>it.pdata.dou[i];
}
}
else if(it.the_type==type_info)
{ ar>>it.the_length;
it.info=new CString[it.the_length];
for(int i=0;i<it.the_length;i++)
ar>>it.info[i];
}
else if(it.the_type==type_mw)
{
CString filename;
ar>>it.the_info_length;
it.buffer= new char[it.the_info_length+1];
for(int i=0;i<it.the_info_length;i++)
ar>>it.buffer[i];
it.buffer[i]='\0';
ar>>it.the_length;
for(i=0;i<it.the_length;i++)
ar>>it.name_length[i];
for(i=0;i<it.the_length;i++)
{
it.matrix_name[i]=new char[it.name_length[i]];
for(int j=0;j<it.name_length[i];j++)
ar>>it.matrix_name[i][j];
}
// it.matrix_column=new int[it.the_length];
// it.matrix_line=new int[it.the_length];
for(i=0;i<it.the_length;i++)
{
ar>>it.matrix_column[i];
ar>>it.matrix_line[i];
}
ar>>filename;
ar>>it.fushu;
unsigned lth=filename.GetLength();
char* head=filename.GetBuffer(lth);
// mwArray is(head),mode("r");
// is=fopen(is,mode);
it.pdata.mw=new mwArray[it.the_length];
// ifstream is(head,ios::in);
for(i=0;i<it.the_length;i++)
{int l;
ar>>l;
if(l>0)
{
it.is>>it.pdata.mw[i];
if(!it.fushu)
{ int d[2];
d[0]=it.pdata.mw[i].Size(1);
d[1]=it.pdata.mw[i].Size(2);
double* bag=new double[d[0]*d[1]];
double* ibag=new double[d[0]*d[1]];
memset(ibag,0,sizeof(double)*d[0]*d[1]);
it.pdata.mw[i].ExtractData(bag);
it.pdata.mw[i]=mwArray(d[0],d[1],bag,ibag);
}
}
}
//it.is.close();
//UINT GetBufferPtr(UINT nCommand, UINT nCount = 0,
// void** ppBufStart = NULL, void** ppBufMax = NULL);
}
}
}
void mydata::Serialize(CArchive& ar)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (ar.IsStoring())
{
ar<<*this;
}
else
{
// TODO: add loading code
ar>>*this;
}
}
void mydata::setdocname(const char *docname)
{AFX_MANAGE_STATE(AfxGetStaticModuleState());
this->docname=CString(docname);
}
mydata::mydata(char *pinfo, int info_length,CString *data, int cnt)
{ the_info_length=info_length;
buffer=new char[the_info_length+1];
for(unsigned int i=0;i<the_info_length;i++)
*(buffer+i)=*(pinfo++);
*(buffer+i)='\0';
the_length=cnt;
the_type=type_info;
info=new CString[cnt];
while(cnt>0)
{ --cnt;
info[cnt].Empty();
unsigned int lth=data[cnt].GetLength();
for(unsigned int i=0;i<lth;i++)
info[cnt]=info[cnt]+data[cnt].GetAt(i);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -