Here are some quite use-full functions to part-ion a list of values
for example.
1,0,0,0,0,1,0
will part-ion to a vector of bools
255,255,255,255,255
will part-ion to a vector of ints
1.5,2.5,3.6
will part-ion to a vector of floats.
vector<bool> xmlmapeng::partcsvbool(string cvs,int numframes)
{
int pos=0,chrpos=0,cnt=0;
cvs=cvs+','+'\0';
bool cvspart=0;
bool neg=false;
char post[256];
bool myfloat=0;
vector<bool>pvec;
char tempchr[10],tc[10];
while(cvs[cnt]!='\0'&&cvs[cnt]!='\n'&&pos<numframes)
{
if(cvs[cnt]=='-')
{
neg=true;
}
if(cvs[cnt]!=','&&cvs[cnt]!=' '&&cvs[cnt]!='-'&&cvs[cnt]!='\0')
{
post[chrpos]=cvs[cnt];
// cout<<cvs[cnt]<<"\n"<<cnt;
chrpos++;
}
if(cvs[cnt]==','||cvs[cnt]==' ')
{
//system("pause");
// charpos=0;
post[chrpos]='\0';
cvspart=atoi(post);
//sprintf(post, "%f", myfloat);
//cvspart=myfloat;
if(neg)
{
cvspart=myfloat*-1;
neg=false;
}
// post="";
pvec.push_back(cvspart);
chrpos=0;
//system("pause");
}
cnt++;
}
return pvec;
}
vector<int> xmlmapeng::partcsvint(string cvs,int numframes)
{
int pos=0,chrpos=0,cnt=0;
cvs=cvs+','+'\0';
int cvspart=0;
bool neg=false;
char post[256];
int myfloat=0;
vector<int>pvec;
char tempchr[10],tc[10];
while(cvs[cnt]!='\0'&&cvs[cnt]!='\n'&&pos<numframes)
{
if(cvs[cnt]=='-')
{
neg=true;
}
if(cvs[cnt]!=','&&cvs[cnt]!=' '&&cvs[cnt]!='-'&&cvs[cnt]!='\0')
{
post[chrpos]=cvs[cnt];
// cout<<cvs[cnt]<<"\n"<<cnt;
chrpos++;
}
if(cvs[cnt]==','||cvs[cnt]==' ')
{
//system("pause");
// charpos=0;
post[chrpos]='\0';
cvspart=atoi(post);
//sprintf(post, "%f", myfloat);
//cvspart=myfloat;
if(neg)
{
cvspart=myfloat*-1;
neg=false;
}
// post="";
pvec.push_back(cvspart);
chrpos=0;
//system("pause");
}
cnt++;
}
return pvec;
}
vector<float> xmlmapeng::partcsv(string cvs,int numframes)
{
int pos=0,chrpos=0,cnt=0;
cvs=cvs+','+'\0';
float cvspart=0;
bool neg=false;
char post[256];
float myfloat=0;
vector<float>pvec;
char tempchr[10],tc[10];
while(cvs[cnt]!='\0'&&cvs[cnt]!='\n'&&pos<numframes)
{
if(cvs[cnt]=='-')
{
neg=true;
}
if(cvs[cnt]!=','&&cvs[cnt]!=' '&&cvs[cnt]!='-'&&cvs[cnt]!='\0')
{
post[chrpos]=cvs[cnt];
// cout<<cvs[cnt]<<"\n"<<cnt;
chrpos++;
}
if(cvs[cnt]==','||cvs[cnt]==' ')
{
//system("pause");
// charpos=0;
post[chrpos]='\0';
cvspart=atof(post);
//sprintf(post, "%f", myfloat);
//cvspart=myfloat;
if(neg)
{
cvspart=myfloat*-1;
neg=false;
}
// post="";
pvec.push_back(cvspart);
chrpos=0;
//system("pause");
}
cnt++;
}
return pvec;
}
Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.