void CXmlMorphAnnot::GetAsSetOfProperties(vector<string>& Result) const { Result.clear(); StringTokenizer tok2(m_GrammemsStr.c_str(), " \t,|; "); while (tok2()) Result.push_back(tok2.val()); sort(Result.begin(), Result.end()); };
void TransfersDialog::OnbtnAddTransferClick(wxCommandEvent& event) { wxString wxstrId = TextCtrl1->GetValue(); // c wxString wxstrDescr = TextCtrl2->GetValue(); // consumption //string strId = string(TextCtrl2->GetValue().mb_str(wxConvISO8859_1)); //string strDescr = string(TextCtrl1->GetValue().mb_str(wxConvISO8859_1)); wxString wxstrFrom = ddFrom->GetString(ddFrom->GetCurrentSelection()); wxStringTokenizer tok1(wxstrFrom, _("\t")); wxString wxstrFromShort = tok1.GetNextToken(); wxString wxstrFromLong = tok1.GetNextToken(); wxString wxstrTo = ddTo->GetString(ddTo->GetCurrentSelection()); wxStringTokenizer tok2(wxstrTo, _("\t")); wxString wxstrToShort = tok2.GetNextToken(); wxString wxstrToLong= tok2.GetNextToken(); //wxString wxstrTo = ddTo->GetData(ddTo->GetCurrentSelection()); string strVar = ws2s(wxstrId); string strDescr = ws2s(wxstrDescr); string strFrom = ws2s(wxstrFromShort); string strTo = ws2s(wxstrToShort); // USE CREATETRANSFER FUNCTION AND REMOVE CALL ON GETTRANSFERS createTransfer(wxstrToShort, wxstrFromShort, wxstrId, wxstrDescr); // Expression::makeToken(strVar); // moved to Transfer::create(...) populateList(); TextCtrl1->Clear(); TextCtrl2->Clear(); TextCtrl1->SetFocus(); }
bool IncronTabEntry::Parse(const std::string& rStr, IncronTabEntry& rEntry) { unsigned long u; std::string s1, s2, s3; StringTokenizer tok(rStr, " \t", '\\'); if (!tok.HasMoreTokens()) return false; s1 = tok.GetNextToken(true); if (!tok.HasMoreTokens()) return false; s2 = tok.GetNextToken(true); if (!tok.HasMoreTokens()) return false; tok.SetNoPrefix(); s3 = tok.GetRemainder(); SIZE len = s3.length(); if (len > 0 && s3[len-1] == '\n') s3.resize(len-1); rEntry.m_path = s1; rEntry.m_cmd = s3; rEntry.m_uMask = 0; rEntry.m_fNoLoop = true; rEntry.m_fNoRecursion = false; rEntry.m_fDotDirs = false; if (sscanf(s2.c_str(), "%lu", &u) == 1) { rEntry.m_uMask = (uint32_t) u; } else { StringTokenizer tok2(s2); while (tok2.HasMoreTokens()) { std::string s(tok2.GetNextToken()); if (s == IN_NO_LOOP_OLD) rEntry.m_fNoLoop = true; else if (s == CT_LOOPABLE) rEntry.m_fNoLoop = false; else if (s == CT_NORECURSION) rEntry.m_fNoRecursion = true; else if (s == CT_DOTDIRS) rEntry.m_fDotDirs = true; else rEntry.m_uMask |= InotifyEvent::GetMaskByName(s); } } return true; }
string format(const string& str1, const unsigned int& arg1, const unsigned int& arg2, const string& arg3, const string& arg4) { string tok1("{0}"); string tok2("{1}"); string tok3("{2}"); string tok4("{2}"); string newString(str1); newString = substitute(newString, tok1, arg1); newString = substitute(newString, tok2, arg2); newString = substitute(newString, tok3, arg3); newString = substitute(newString, tok4, arg4); return newString; }
static wxString ParseWildCard( const wxString& wild ) { #if wxDEBUG_LEVEL static const char *msg = "Motif file dialog does not understand this wildcard syntax"; #endif wxArrayString wildDescriptions, wildFilters; const size_t count = wxParseCommonDialogsFilter(wild, wildDescriptions, wildFilters); wxCHECK_MSG( count, wxT("*.*"), wxT("wxFileDialog: bad wildcard string") ); wxCHECK_MSG( count == 1, wxT("*.*"), msg ); // check for *.txt;*.rtf wxStringTokenizer tok2( wildFilters[0], wxT(";") ); wxString wildcard = tok2.GetNextToken(); wxCHECK_MSG( tok2.CountTokens() <= 1, wildcard, msg ); return wildcard; }
static std::vector<mm::mastermind_t::remote_t> parse_remotes(const std::string &remotes) { typedef boost::char_separator<char> separator_t; typedef boost::tokenizer<separator_t> tokenizer_t; std::vector<mm::mastermind_t::remote_t> result; separator_t sep1(","); tokenizer_t tok1(remotes, sep1); separator_t sep2(":"); for (auto it = tok1.begin(), end = tok1.end(); it != end; ++it) { tokenizer_t tok2(*it, sep2); auto jt = tok2.begin(); if (tok2.end() == jt) { throw std::runtime_error("remotes are malformed"); } auto host = *jt++; uint16_t port = 10053; if (tok2.end() != jt) { port = boost::lexical_cast<uint16_t>(*jt++); } if (tok2.end() != jt) { throw std::runtime_error("remotes are malformed"); } result.emplace_back(std::make_pair(std::move(host), port)); } return result; }
int main( int argc , char ** argv ) { std::map<std::string,std::string> args; std::set<std::string> skip; args["ID"] = "ID"; args["REF"] = "REF"; args["ALT"] = "ALT"; args["QUAL"] = "QUAL"; args["FILTER"] = "FILTER"; std::map<std::string,std::string> types; std::map<std::string,std::string> number; std::map<std::string,std::string> desc; for (int i=1; i<argc; i++) { int t; char_tok tok( argv[i] , &t , '=' ); if ( t == 2 ) { if ( strcmp( tok(0) , "SKIP" ) == 0 || strcmp( tok(0) , "skip" ) == 0 ) skip.insert(tok(1)); else args[ tok(0) ] = tok(1); } else if ( t == 1 ) { int t2; char_tok tok2( argv[i] , &t2 , ':' ); if ( t2 == 4 ) { number[ tok2(0) ] = tok2(1); types[ tok2(0) ] = tok2(2); desc[ tok2(0) ] = tok2(3); } } } // take a file with HEADERs from STDIN; // write as a VCF to STDOUT // Get header LINE std::string hdr; std::getline( std::cin , hdr ); if ( hdr == "" ) exit(1); // remove a leading '#' if ( hdr.substr(0,1) == "#" ) hdr = hdr.substr(1); // get fields int n; char_tok tok( hdr , &n , '\t' ); // find positional fields // either POS, or CHR and BP (or BP1 and BP2) int pos = -1 , chr = -1 , bp1 = -1 , bp2 = -1; // other special fields int qual = -1 , id = -1 , ref = -1 , alt = -1 , filter = -1; std::vector<std::string> field(n); std::vector<int> info; for (int i=0; i<n; i++) { bool special_field = false; field[i] = tok(i); if ( field[i] == "VAR" ) { special_field = true; pos = i; } else if ( field[i] == "LOC" ) { special_field = true; pos = i; } else if ( field[i] == "CHR" ) { special_field = true; chr = i; } else if ( field[i] == "CHROM" ) { special_field = true; chr = i; } else if ( field[i] == "BP" ) { special_field = true; bp1 = i; } else if ( field[i] == "BP1" ) { special_field = true; bp1 = i; } else if ( field[i] == "BP2" ) { special_field = true; bp2 = i; } else if ( field[i] == "POS" ) { special_field = true; bp1 = i; } else if ( field[i] == "POS1" ) { special_field = true; bp1 = i; } else if ( field[i] == "POS2" ) { special_field = true; bp2 = i; } std::map<std::string,std::string>::iterator ii = args.begin(); while ( ii != args.end() ) { if ( ii->second == field[i] ) { if ( ii->first == "QUAL" || ii->first == "qual" ) { special_field = true; qual = i; } else if ( ii->first == "FILTER" || ii->first == "filter" ) { special_field = true; filter = i; } else if ( ii->first == "ID" || ii->first == "id" ) { special_field = true; id = i; } else if ( ii->first == "REF" || ii->first == "ref" ) { special_field = true; ref = i; } else if ( ii->first == "ALT" || ii->first == "alt" ) { special_field = true; alt = i; } } ++ii; } // skip this field? if ( skip.find( field[i] ) != skip.end() ) special_field = true; // normal INFO field? if ( ! special_field ) info.push_back(i); } // next header entry // does this contain valid positional information? if ( pos == -1 && ( chr == -1 || bp1 == -1 ) ) exit(1); bool use_chr_bp = chr != -1 && bp1 != -1; bool use_bp2 = use_chr_bp && bp2 != -1; const int s = info.size(); // write VCF header std::cout << "##fileformat=VCFv4.1\n" << "##source=tab2vcf\n"; for (int i=0; i<s; i++) { if ( types.find( field[ info[i] ] ) != types.end() ) { std::cout << "##INFO=<ID=" << field[info[i]] << ",Number=" << number[field[info[i]]] << ",Type=" << types[field[info[i]]] << ",Description=\"" << desc[field[info[i]]] << "\">\n"; } else std::cout << "##INFO=<ID=" << field[info[i]] << ",Number=1,Type=Float,Description=\"n/a\">\n"; } // also display any additional headers from the command line but not seen in the file (i.e. // to describe Flags in the body of the text that are not in the headers std::set<std::string> fset; for (int i=0; i<s; i++) fset.insert( field[info[i]] ); std::map<std::string,std::string>::iterator ii = types.begin(); while ( ii != types.end() ) { if ( fset.find( ii->first ) == fset.end() ) std::cout << "##INFO=<ID=" << ii->first << ",Number=" << number[ii->first] << ",Type=" << types[ii->first] << ",Description=\"" << desc[ii->first] << "\">\n"; ++ii; } // second header std::cout << "#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n"; // information while ( ! std::cin.eof() ) { std::string l; int m; std::getline( std::cin , l ); // replace spaces with ';' unless they are quoted char_tok tok( l , &m , '\t' ); if ( l == "" ) continue; if ( m != n ) { std::cout << "unequal number of fields for line\n" << l << "\n(expecting " << n << " found " << m << ")\n"; exit(1); } if ( use_chr_bp ) { // chromosome std::cout << tok(chr) << "\t"; // position std::cout << tok(bp1) ; if ( bp2 != -1 ) std::cout << ".." << tok(bp2); std::cout << "\t"; } else { std::string pstr = tok( pos ); // expect 'chr:1234' // expect 'chr:1234..4596' // or 'chr:1234-5674' int k; char_tok stok( pstr , &k , ':' ); if ( k == 0 ) std::cout << ".\t.\t"; else if ( k == 1 ) std::cout << stok(0) << "\t.\t"; else if ( k >= 2 ) { std::cout << stok(0) << "\t" << stok(1) << "\t"; } } // id if ( id == -1 ) std::cout << ".\t"; else std::cout << tok(id) << "\t"; // ref if ( ref == -1 ) std::cout << ".\t"; else std::cout << tok(ref) << "\t"; // alt if ( alt == -1 ) std::cout << ".\t"; else std::cout << tok(alt) << "\t"; // qual if ( qual == -1 ) std::cout << ".\t"; else std::cout << tok(qual) << "\t"; // filter if ( filter == -1 ) std::cout << ".\t"; else std::cout << replace_space( tok(filter) , ';' ) << "\t"; // info for (int i=0; i<s; i++) { if ( i ) std::cout << ";"; std::cout << field[info[i]] << "=" << opt_quote( replace_space( tok(info[i]) , ',' ) ); } std::cout << "\n"; } }
void wxGenericPrintSetupDialog::Init(wxPrintData* data) { if ( data ) m_printData = *data; m_targetData = data; wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); // printer selection wxStaticBoxSizer *printer_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Printer") ), wxVERTICAL ); main_sizer->Add( printer_sizer, 0, wxALL|wxGROW, 10 ); m_printerListCtrl = new wxListCtrl( this, wxPRINTID_PRINTER, wxDefaultPosition, wxSize(wxDefaultCoord,100), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER ); wxImageList *image_list = new wxImageList; image_list->Add( wxBitmap(check_xpm) ); m_printerListCtrl->AssignImageList( image_list, wxIMAGE_LIST_SMALL ); m_printerListCtrl->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT, 20 ); m_printerListCtrl->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT, 150 ); m_printerListCtrl->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT, 150 ); m_printerListCtrl->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT, 80 ); wxListItem item; item.SetMask( wxLIST_MASK_TEXT ); item.SetColumn( 1 ); item.SetText( _("Default printer") ); item.SetId( m_printerListCtrl->InsertItem( item ) ); if (data->GetPrinterName().empty()) { wxListItem item2; item2.SetId( item.GetId() ); item2.SetMask( wxLIST_MASK_IMAGE ); item2.SetImage( 0 ); m_printerListCtrl->SetItem( item2 ); // also select item m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); } item.SetId( 1+ item.GetId() ); wxArrayString errors; wxArrayString output; long res = wxExecute( wxT("lpstat -v"), output, errors, wxEXEC_NODISABLE ); if (res >= 0 && errors.GetCount() == 0) { size_t i; for (i = 0; i < output.GetCount(); i++) { wxStringTokenizer tok( output[i], wxT(" ") ); wxString tmp = tok.GetNextToken(); // "device" if (tmp != wxT("device")) break; // the lpstat syntax must have changed. tmp = tok.GetNextToken(); // "for" if (tmp != wxT("for")) break; // the lpstat syntax must have changed. tmp = tok.GetNextToken(); // "hp_deskjet930c:" if (tmp[tmp.Len()-1] == wxT(':')) tmp.Remove(tmp.Len()-1,1); wxString name = tmp; item.SetText( name ); item.SetId( m_printerListCtrl->InsertItem( item ) ); tmp = tok.GetNextToken(); // "parallel:/dev/lp0" item.SetColumn( 2 ); item.SetText( tmp ); m_printerListCtrl->SetItem( item ); if (data->GetPrinterName() == name) { wxListItem item2; item2.SetId( item.GetId() ); item2.SetMask( wxLIST_MASK_IMAGE ); item2.SetImage( 0 ); m_printerListCtrl->SetItem( item2 ); // also select item m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); } wxString command = wxT("lpstat -p "); command += name; wxArrayString errors2; wxArrayString output2; res = wxExecute( command, output2, errors2, wxEXEC_NODISABLE ); if (res >= 0 && errors2.GetCount() == 0 && output2.GetCount() > 0) { tmp = output2[0]; // "printer hp_deskjet930c is idle. enable since ..." int pos = tmp.Find( wxT('.') ); if (pos != wxNOT_FOUND) tmp.Remove( (size_t)pos, tmp.Len()-(size_t)pos ); wxStringTokenizer tok2( tmp, wxT(" ") ); tmp = tok2.GetNextToken(); // "printer" tmp = tok2.GetNextToken(); // "hp_deskjet930c" tmp = wxEmptyString; while (tok2.HasMoreTokens()) { tmp += tok2.GetNextToken(); tmp += wxT(" "); } item.SetColumn( 3 ); item.SetText( tmp ); m_printerListCtrl->SetItem( item ); } item.SetColumn( 1 ); item.SetId( 1+ item.GetId() ); } } printer_sizer->Add( m_printerListCtrl, 0, wxALL|wxGROW, 5 ); wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL ); main_sizer->Add( item1, 0, wxALL, 5 ); // printer options (on the left) wxBoxSizer *item2 = new wxBoxSizer( wxVERTICAL ); wxStaticBox *item4 = new wxStaticBox( this, wxPRINTID_STATIC, _("Paper size") ); wxStaticBoxSizer *item3 = new wxStaticBoxSizer( item4, wxVERTICAL ); m_paperTypeChoice = CreatePaperTypeChoice(); item3->Add( m_paperTypeChoice, 0, wxALIGN_CENTER|wxALL, 5 ); item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 ); wxString strs6[] = { _("Portrait"), _("Landscape") }; m_orientationRadioBox= new wxRadioBox( this, wxPRINTID_ORIENTATION, _("Orientation"), wxDefaultPosition, wxDefaultSize, 2, strs6, 1, wxRA_SPECIFY_ROWS ); item2->Add( m_orientationRadioBox, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); wxStaticBox *item8 = new wxStaticBox( this, wxID_ANY, _("Options") ); wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxHORIZONTAL ); m_colourCheckBox = new wxCheckBox( this, wxPRINTID_PRINTCOLOUR, _("Print in colour") ); item7->Add( m_colourCheckBox, 0, wxALIGN_CENTER|wxALL, 5 ); item2->Add( item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); item1->Add( item2, 0, wxALIGN_CENTER_HORIZONTAL, 5 ); // spooling options (on the right) wxStaticBox *item11 = new wxStaticBox( this, wxID_ANY, _("Print spooling") ); wxStaticBoxSizer *item10 = new wxStaticBoxSizer( item11, wxVERTICAL ); wxStaticText *item12 = new wxStaticText( this, wxID_ANY, _("Printer command:") ); item10->Add( item12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); wxBoxSizer *item13 = new wxBoxSizer( wxHORIZONTAL ); item13->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 ); m_printerCommandText = new wxTextCtrl( this, wxPRINTID_COMMAND, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) ); item13->Add( m_printerCommandText, 0, wxALIGN_CENTER|wxALL, 5 ); item10->Add( item13, 0, wxALIGN_CENTER|wxALL, 0 ); wxStaticText *item15 = new wxStaticText( this, wxID_ANY, _("Printer options:") ); item10->Add( item15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); wxBoxSizer *item16 = new wxBoxSizer( wxHORIZONTAL ); item16->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 ); m_printerOptionsText = new wxTextCtrl( this, wxPRINTID_OPTIONS, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) ); item16->Add( m_printerOptionsText, 0, wxALIGN_CENTER|wxALL, 5 ); item10->Add( item16, 0, wxALIGN_CENTER|wxALL, 0 ); item1->Add( item10, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 ); #if wxUSE_STATLINE // static line main_sizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); #endif // buttons main_sizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxEXPAND|wxALL, 10 ); SetAutoLayout( true ); SetSizer( main_sizer ); main_sizer->Fit( this ); Centre(wxBOTH); Fit(); Centre(wxBOTH); InitDialog(); }
void read_level(unsigned short**& level, unsigned& LEVEL_X, unsigned& LEVEL_Y, std::vector<Entity*>& entities, Entity& player, Entity& flag, GLuint sprites, std::string fn){ std::ifstream file(fn); std::string line; float x = 0; float y = 0; Entity* newEnt = nullptr; EntType enm_type; while (std::getline(file, line)){ if (line == "[header]"){ while (!line.empty()){ if (!std::getline(file, line))break; if (!line.compare(0, 6, "width=")){ LEVEL_X = atoi(line.substr(6).c_str()); } else if (!line.compare(0, 7, "height=")){ LEVEL_Y = atoi(line.substr(7).c_str()); } } level = new unsigned short*[LEVEL_Y]; for (size_t i = 0; i < LEVEL_Y; ++i){ level[i] = new unsigned short[LEVEL_X]; } } else if (line == "[layer]"){ while (!line.empty()){ if (!std::getline(file, line)) break; if (!line.compare(0, 5, "data=")){ for (size_t y = 0; y < LEVEL_Y; ++y){ if (!getline(file, line)) exit(1); std::stringstream tok(line); std::string tokstring; for (size_t x = 0; x < LEVEL_X; ++x){ getline(tok, tokstring, ','); level[y][x] = atoi(tokstring.c_str()) - 1; } } } } } else if (line == "[Objects]"){ while (!line.empty()){ if (!std::getline(file, line)) break; if (!line.compare(0, 5, "type=")){ line = line.substr(5); if (line == "bee"){ enm_type = BEE; } else if (line == "mouse"){ enm_type = MOUSE; } else if (line == "bat"){ enm_type = BAT; } else if (line == "player"){ enm_type = PLAYER; } else if (line == "flag"){ enm_type = FLAG; } } else if (!line.compare(0, 9, "location=")){ line = line.substr(9); std::stringstream tok2(line); std::string tokstring; if (!getline(tok2, tokstring, ',')) break; x = (-TILE_SIZE) + atoi(tokstring.c_str()); if (!getline(tok2, tokstring, ','))break; y = (-TILE_SIZE) + atoi(tokstring.c_str()); } } switch (enm_type){ case BEE: newEnt = new Entity(sprites, 692.0f, 692.0f, 30,30, 2, 354.0f, 21.0f, 21.0f, 0.5f, 2); newEnt->x = x*TILE_SIZE; newEnt->y = y*-TILE_SIZE; newEnt->isflying = true; newEnt->acceleration_x = -3.0f; newEnt->add_animation("moving", { 354, 355 }); newEnt->set_animation("moving"); entities.push_back(newEnt); break; case MOUSE: newEnt = new Entity(sprites, 692.0f, 692.0f, 30, 30, 2, 384.0f, 21.0f, 21.0f, 0.5f, 1); newEnt->x = x*TILE_SIZE; newEnt->y = y*-TILE_SIZE; newEnt->acceleration_x = 3.0f; newEnt->add_animation("moving", { 384, 385 }); newEnt->set_animation("moving"); entities.push_back(newEnt); break; case BAT: newEnt = new Entity(sprites, 692.0f, 692.0f, 30, 30, 2, 440.0f, 21.0f, 21.0f, 0.5f, 3); newEnt->x = x*TILE_SIZE; newEnt->y = y*-TILE_SIZE; newEnt->acceleration_x = 3.0f; newEnt->isflying = true; newEnt->add_animation("moving", { 440, 441, 442}); newEnt->set_animation("moving"); entities.push_back(newEnt); break; case PLAYER: player.x = x*TILE_SIZE; player.y = y*-TILE_SIZE; break; case FLAG: flag.x = x*TILE_SIZE; flag.y = y*-TILE_SIZE; break; default: break; } } } file.close(); }
string Lsystem::parse_lsystem(char const* filename, int iteration) { //Falls Datei noch nicht geparsed if(lsystem_.empty() == true){ //Datei einlesen file_iterator<> first = load(filename); file_iterator<> last = first.make_end(); typedef char char_t; typedef file_iterator <char_t> iterator_t; string input(first, last); // std::cout << "Eingabe:" << "\n" << input << "\n" << std::endl; lsystem_grammer lsys; //Parsevorgang parse_info<iterator_t> pi = parse(first, last, lsys, space_p); if (pi.hit) { if (pi.full) { std::cout << "LSystem: file reading successfully" << std::endl; std::cout << "LSystem: " << pi.length << "characters read" << std::endl; std::cout << "LSystem: parsing ..." << std::endl; // std::cout << "Vektor:" << gl_lsys_file.size() << "\n" << std::endl; //Eingabe splitten typedef boost::tokenizer<boost::char_separator<char> > tokenizer; //Axiom //string s1 = get_axiom(); //boost::char_separator<char> sep1(": "); //tokenizer tok(s1, sep1); //tokenizer::iterator it = tok.begin(); //string start = *(++it); boost::char_separator<char> sep1(": "); string start = get_axiom(); std::string ret; //Produkion(en) vector<string> s2 = get_production(); // int last_pos = 0; int left = 1; //Zufallszahlen bis 100 // srand(j * time(0)); //int prob = rand() % 100 + 1; // std::cout << "ZZ:" << prob << std::endl; // std::cout<<s2.size()<<std::endl; std::map<int, string> mapProbToProd; int zaehler=0; for (int i = 0; i < s2.size(); i++) { int position; tokenizer tok2(s2[i], sep1); tokenizer::iterator it = tok2.begin(); string temp = *(++it); //Alles nach dem Doppelpunkt boost::char_separator<char> sep2("="); tokenizer tok3(temp, sep2); tokenizer::iterator it2 = tok3.begin(); string temp1 = *(it2); //Alles vor dem Gleichheitszeichen string temp2 = *(++it2); //Alles nach dem Gleichheitszeichen if (temp2.find(",") == string::npos) { //DOL stochastic_ = false; //Ersetzung boost::replace_all(start, temp1, temp2); lsystem_.push_back(start); lsystem_.push_back(start); //DOL mit meherere Produktionen existieren } else if (temp2.find(",") != string::npos) { //stochastische L-Systeme stochastic_ = true; boost::char_separator<char> sep3(","); tokenizer tok4(temp2, sep3); tokenizer::iterator it3 = tok4.begin(); string sto = *(it3); //Alles vor Komma (Wahrscheinlichkeit) string temp3 = *(++it3); //Alles nach Komma (Regel) int cur_pos = atof(sto.data()) * 100; //aktuelle Wahrscheinlichkeit int right = last_pos + cur_pos; //Bereich rechts for(int k = 0; k < cur_pos ; ++k ) { mapProbToProd.insert ( std::pair<int, string>(zaehler,temp3)); ++zaehler; } // } } for (int j = 1; j <= iteration * 2; j++) { std::string result; // result.reserve(14*start.size()); for(int i = 0 ; i < start.size() ; ++i) { srand(i*time(0)); int k = rand() % 100; if(start[i]=='F') result += mapProbToProd[k]; else result += start[i]; } lsystem_.push_back(result); start=result; } std::cout << "LSystem: parsing finished\n\n"; //} if (stochastic_ == false) { // std::cout << "Ergebnis: " << lsystem_[(s2.size()) * iteration - 1] << std::endl; return lsystem_[(s2.size() * iteration - 1)]; } else if (stochastic_ == true) { // std::cout << "Ergebnis: " << lsystem_[iteration - 1] << std::endl; return lsystem_[iteration - 1]; } } else { std::cout << "LSystem: ERROR parsing data partially" << std::endl; std::cout << "LSystem: ERROR " << pi.length << "characters parsed \n\n" << std::endl; } } else std::cout << "LSystem: ERROR parsing failed; stopped at '" << pi.stop << "'\n\n" << std::endl; } //erneutes Parsen verhindern else if(iteration <= lsystem_.size()) { if (stochastic_ == false) { // std::cout << "Ergebnis: " << lsystem_[(get_production().size()) * iteration - 1] << std::endl; return lsystem_[(get_production().size() * iteration - 1)]; } else if (stochastic_ == true) { // std::cout << "Ergebnis: " << lsystem_[iteration - 1] << std::endl; return lsystem_[iteration - 1]; } } //Vektor vergrößern else if(iteration > lsystem_.size()){ erase_old(); parse_lsystem(filename, iteration); if (stochastic_ == false) { // std::cout << "Ergebnis: " << lsystem_[(get_production().size()) * iteration - 1] << std::endl; return lsystem_[(get_production().size() * iteration - 1)]; } else if (stochastic_ == true) { // std::cout << "Ergebnis: " << lsystem_[iteration - 1] << std::endl; return lsystem_[iteration - 1]; } } return std::string(); }