in ahnlehnung an diesen thread in dem im ich nicht mehr rumpfuschen kann...
http://forum.the-arena.de/viewtopic.php?...&highlight=
CS war heute irgendwie zu langweilig und da hab ich das listenerstellteil nochmal neu geschrieben diesmal mit brauchbareren quellcode und nicht in diesem furchtbaren c-c++ mix
auslöser war das eine allyübergreifende liste erstellt werden sollte, also wenn eine Hauptally aus mehreren Unterlallys besteht gings vorher nicht das der auch daraus eine Komplettliste bastelt...
Vielliecht hat Toxic ja Lust das ganze noch für Html hübsch zu machen funzen tuts erstmal auch so...
Hab mich an den ANSI-Standard gehalten, sollte also mit jedem Brauchbaren C++ kompiler zu übersetzen sein...
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
class gladiator;
class gladiatorDB;
bool cmp_by_ruhm(const gladiator* a, const gladiator* b);
bool cmp_by_rlp(const gladiator* a, const gladiator* b);
std::ostream& operator<<(std::ostream& , gladiator&);
std::ostream& operator<<(std::ostream& , gladiatorDB&);
class gladiator{
public :
gladiator(gladiator& g):nick(g.nick),ruhm(g.ruhm),rlp(g.rlp){gladiator::HtmlVsTxt=0;gladiator::RuhmVsRlp=0;}
gladiator(std::string _nick, size_t _ruhm, size_t _rlp):nick(_nick),ruhm(_ruhm),rlp(_rlp){}
friend std::ostream& operator<<(std::ostream& os , gladiator& g);
friend bool cmp_by_ruhm(const gladiator* a, const gladiator* b);
friend bool cmp_by_rlp(const gladiator* a, const gladiator* b);
static void setHtmlVsTxt(size_t _HtmlVsTxt){HtmlVsTxt=_HtmlVsTxt;}
static void setRuhmVsRlp(size_t _RuhmVsRlp){RuhmVsRlp=_RuhmVsRlp;}
static size_t getHtmlVsTxt(){return HtmlVsTxt;}
static size_t getRuhmVsRlp(){return RuhmVsRlp;}
private:
static size_t HtmlVsTxt, RuhmVsRlp;
std::string nick;
size_t ruhm;
size_t rlp;
};
size_t gladiator::HtmlVsTxt=0;
size_t gladiator::RuhmVsRlp=0;
std::ostream& operator<<(std::ostream& os, gladiator& g){
if(gladiator::HtmlVsTxt)
os<<"</td><td width=\"250\">"<<g.nick<<"</td><td width=\"250\" align=\"center\">"<<(gladiator::RuhmVsRlp?g.ruhm:g.rlp)<<"</td></tr>";
else
os<<g.nick<<'\t'<<(gladiator::RuhmVsRlp?g.ruhm:g.rlp)<<std::endl;
return os;
}
bool cmp_by_ruhm(const gladiator* a, const gladiator* b){return a->ruhm > b->ruhm;}
bool cmp_by_rlp(const gladiator* a, const gladiator* b){return a->rlp > b->rlp;}
class gladiatorDB{
public:
gladiatorDB(){};
~gladiatorDB();
friend std::ostream& operator<<(std::ostream& , gladiatorDB&);
void addFromFile(std::string filename);
void save(size_t RuhmVsRlp=gladiator::getRuhmVsRlp(), size_t HtmlVsTxt=gladiator::getHtmlVsTxt());
void save(std::string filename,size_t RuhmVsRlp=gladiator::getRuhmVsRlp(), size_t HtmlVsTxt=gladiator::getHtmlVsTxt());
void saveAll();
private:
void sort(size_t RuhmVsRlp=gladiator::getRuhmVsRlp());
void addFromFile(std::string filename,std::string start_keyword[3]);
std::vector<gladiator*> gdb;
};
gladiatorDB::~gladiatorDB(){for(size_t i=0;i<gdb.size();++i)delete gdb[i];}
void gladiatorDB::saveAll(){save(0,0);save(0,1);save(1,0);save(1,1);}
void gladiatorDB::save(size_t RuhmVsRlp, size_t HtmlVsTxt){save(std::string(RuhmVsRlp?"ruhm":"rlp") + std::string(".") + std::string(HtmlVsTxt?"html":"txt"),RuhmVsRlp,HtmlVsTxt);}
void gladiatorDB::save(std::string filename,size_t RuhmVsRlp, size_t HtmlVsTxt){
gladiator::setRuhmVsRlp(RuhmVsRlp);
gladiator::setHtmlVsTxt(HtmlVsTxt);
sort(RuhmVsRlp);
std::ofstream ofs(filename.c_str());
ofs<<*this;
}
void gladiatorDB::sort(size_t RuhmVsRlp){std::sort(gdb.begin(),gdb.end(),(RuhmVsRlp?cmp_by_ruhm:cmp_by_rlp));}
void gladiatorDB::addFromFile(std::string filename){
std::string keyword[3];
keyword[0]="antwortennick=";
keyword[1]="<td align=\"right\">";
keyword[2]="<td align=\"right\">";
addFromFile(filename,keyword);
keyword[0]="emphname\">";
addFromFile(filename,keyword);
}
void gladiatorDB::addFromFile(std::string filename,std::string keyword[3]){
std::string nick,file,line;
size_t ruhm,rlp,x,y;
std::ifstream ifs(filename.c_str());
while(std::getline(ifs,line))file+=line;
for(x=0; std::string::npos!=(x=file.find(keyword[0],x));x=y){
x+=keyword[0].size();
y=file.find_first_of("<\"",x);
nick=file.substr(x,y-x);
x=file.find(keyword[1],x=y);
x+=keyword[1].size();
y=file.find_first_of("<\"",x);
ruhm=atoi(file.substr(x,y-x).c_str());
x=file.find(keyword[2],x=y);
x+=keyword[2].size();
y=file.find_first_of("<\"",x);
rlp=atoi(file.substr(x,y-x).c_str());
gdb.push_back(new gladiator(nick,ruhm,rlp));
}
}
std::ostream& operator<<(std::ostream& os, gladiatorDB& gdb){
size_t i;
if(gladiator::getHtmlVsTxt()){
os<<"<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"><table width=\"420\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" background=\"images/tab_bg.jpg\"><tr><td colspan=\"3\"><img src=\"images/tab_o.gif\" width=\"420\" height=\"8\"></td></tr><tr><td background=\"images/tab_li.gif\" width=\"5\"> </td><td width=\"410\"><table width=\"410\" border=\"0\" cellspacing=\"0\" align=\"center\"><tr><td colspan=\"3\" class=\"headline\">Ruhm der Allianz</td></tr><tr><td colspan=\"3\"> </td></tr>";
for(i=0;i<gdb.gdb.size();++i)
os<<"<tr><td width=\"40\" align=\"center\">"<<i+1<<'.'<<*(gdb.gdb[i]);
}else
for(i=0;i<gdb.gdb.size();++i)
os<<i+1<<".\t"<<*(gdb.gdb[i]);
return os;
}
int main(int argc,char**argv){
gladiatorDB gdb;
gdb.addFromFile("allianzen.html");
gdb.addFromFile("allianzen2.html");
gdb.saveAll();
// std::cout<<gdb;
}