void Kandy::fileSaveAs() { QString filename = KFileDialog::getSaveFileName(); save(filename); }
void IntegerEdit::setValue(int value) { edit = value; save(); }
void save(void *_obj, const cfgParam *params, ostream &out) { const cfgParam *saveParam = params; char *obj = (char*)_obj; string *s; string v; list<unsigned long> *l; list<unsigned long>::iterator it; for (;;){ const cfgParam *p; for (p = params; *p->name; p++){ const cfgParam *pp = saveParam; for (;;){ for (; *pp->name; pp++) if (strcmp(pp->name, p->name) == 0) break; if (*pp->name) break; if (pp->defValue == 0) break; pp = (const cfgParam*)(pp->defValue); } if (pp != p) continue; bool writeEmpty = false; string value; switch (p->type){ case PARAM_ULONG: if (*((unsigned long*)(obj + p->offs)) != p->defValue){ char buf[32]; snprintf(buf, sizeof(buf), "%lu", *((unsigned long*)(obj + p->offs))); value = buf; } break; case PARAM_USHORT: if (*((unsigned short*)(obj + p->offs)) != (unsigned short)(p->defValue)){ char buf[32]; snprintf(buf, sizeof(buf), "%u", *((unsigned short*)(obj + p->offs))); value = buf; } break; case PARAM_SHORT: if (*((short*)(obj + p->offs)) != (short)(p->defValue)){ char buf[32]; snprintf(buf, sizeof(buf), "%u", *((short*)(obj + p->offs))); value = buf; } break; case PARAM_STRING: s = (string*)(obj + p->offs); v = ""; if (p->defValue) v = (const char*)(p->defValue); if (*s != v){ value = *s; writeEmpty = true; } break; case PARAM_BOOL: if (*((bool*)(obj + p->offs)) != (bool)(p->defValue)) value = *((bool*)(obj + p->offs)) ? "true" : "false"; break; case PARAM_I18N: s = (string*)(obj + p->offs); v = ""; if (p->defValue) v = i18n((const char*)(p->defValue)).local8Bit(); if (*s != v) value = v; break; case PARAM_ULONGS: l = (list<unsigned long>*)(obj + p->offs); if (l->size()){ for (it = l->begin(); it != l->end(); ++it){ char b[15]; snprintf(b, sizeof(b), "%lu", *it); if (value.length()) value += ","; value += b; } } break; case PARAM_CHAR: if (obj[p->offs] != (char)(p->defValue)){ char buf[32]; snprintf(buf, sizeof(buf), "%u", *((char*)(obj + p->offs))); value = buf; } break; default: l = (list<unsigned long>*)(obj + p->offs); for (it = l->begin(); it != l->end(); ++it){ out << "[" << p->name << "]\n"; save((void*)(*it), (const cfgParam*)(p->defValue), out); } if (l->size()) out << "[]\n"; } if ((value.size() == 0) && !writeEmpty) continue; value = quoteString(value); out << p->name << "=" << value << "\n"; } if (p->defValue == 0) break; params = (const cfgParam*)(p->defValue); if (p->offs) obj = *((char**)(obj + p->offs)); } }
//! Creates a list of files and directories in the current working directory IFileList* CFileSystem::createFileList() { FileEntry e2; FileEntry e3; if ( FileSystemType == FILESYSTEM_NATIVE ) return new CFileList(); CFileList* r = new CFileList( "virtual" ); r->Path = WorkingDirectory [ FILESYSTEM_VIRTUAL ]; for ( u32 i = 0; i != FileArchives.size(); ++i) { CFileList* flist[2] = { 0, 0 }; //! merge relative folder file archives if ( FileArchives[i]->getArchiveType() == "mount" ) { EFileSystemType currentType = setFileListSystem ( FILESYSTEM_NATIVE ); core::string<c16> save ( getWorkingDirectory () ); core::string<c16> current; current = FileArchives[i]->getArchiveName() + WorkingDirectory [ FILESYSTEM_VIRTUAL ]; flattenFilename ( current ); if ( changeWorkingDirectoryTo ( current ) ) { flist[0] = new CFileList( "mountpoint" ); flist[0]->constructNative (); changeWorkingDirectoryTo ( save ); } setFileListSystem ( currentType ); } else if ( FileArchives[i]->getArchiveType() == "zip" ) { flist[0] = new CFileList( "zip" ); flist[1] = new CFileList( "zip directory" ); // add relative navigation e2.isDirectory = 1; e2.Name = "."; e2.FullName = r->Path + e2.Name; e2.Size = 0; flist[1]->Files.push_back ( e2 ); e2.Name = ".."; e2.FullName = r->Path + e2.Name; flist[1]->Files.push_back ( e2 ); for ( u32 g = 0; g < FileArchives[i]->getFileCount(); ++g) { const SZipFileEntry *e = (SZipFileEntry*) FileArchives[i]->getFileInfo(g); s32 test = isInSameDirectory ( r->Path, e->zipFileName ); if ( test < 0 || test > 1 ) continue; e2.Size = e->header.DataDescriptor.UncompressedSize; e2.isDirectory = e2.Size == 0; // check missing directories if ( !e2.isDirectory && test == 1 ) { e3.Size = 0; e3.isDirectory = 1; e3.FullName = e->path; e3.Name = e->path.subString ( r->Path.size(), e->path.size() - r->Path.size() - 1 ); if ( flist[1]->Files.binary_search ( e3 ) < 0 ) flist[1]->Files.push_back ( e3 ); } else { e2.FullName = e->zipFileName; e2.Name = e->simpleFileName; if ( !e2.isDirectory ) core::deletePathFromFilename ( e2.Name ); flist[0]->Files.push_back ( e2 ); } } } // add file to virtual directory for ( u32 g = 0; g < 2; ++g ) { if ( !flist[g] ) continue; for ( u32 j = 0; j != flist[g]->Files.size(); ++j ) r->Files.push_back ( flist[g]->Files[j] ); flist[g]->drop(); } } r->Files.sort(); return r; }
static void read_string (LexState *LS, int del, SemInfo *seminfo) { lua_State *L = LS->L; size_t l = 0; checkbuffer(L, 10, l); save_and_next(L, LS, l); while (LS->current != del) { checkbuffer(L, 10, l); switch (LS->current) { case EOZ: case '\n': save(L, '\0', l); luaX_error(LS, "unfinished string", TK_STRING); break; /* to avoid warnings */ case '\\': next(LS); /* do not save the '\' */ switch (LS->current) { case 'a': save(L, '\a', l); next(LS); break; case 'b': save(L, '\b', l); next(LS); break; case 'f': save(L, '\f', l); next(LS); break; case 'n': save(L, '\n', l); next(LS); break; case 'r': save(L, '\r', l); next(LS); break; case 't': save(L, '\t', l); next(LS); break; case 'v': save(L, '\v', l); next(LS); break; case '\n': save(L, '\n', l); inclinenumber(LS); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { int c = 0; int i = 0; do { c = 10*c + (LS->current-'0'); next(LS); } while (++i<3 && isdigit(LS->current)); if (c != (unsigned char)c) { save(L, '\0', l); luaX_error(LS, "escape sequence too large", TK_STRING); } save(L, c, l); break; } default: /* handles \\, \", \', and \? */ save_and_next(L, LS, l); } break; default: save_and_next(L, LS, l); } } save_and_next(L, LS, l); /* skip delimiter */ save(L, '\0', l); seminfo->ts = luaS_newlstr(L, L->Mbuffer+1, l-3); }
void save(const version_type & t){ save(static_cast<const unsigned int>(t)); }
void c_hoice(){ str_in1 = strlen(in1); str_in2 = strlen(in2); str_in3 = strlen(in3); var_in(); if (chosen == 1) return ; else { if (str_in1 == 1) { if (str_in2 == 0) { if (in1[0] >= 'A' && in1[0] <= 'Z') { for (int i = 0; i <= 9; i ++) { if (in1[0] == var[i]) { begin_chosen = i; printf(" = "); comma(var_var[begin_chosen]); chosen = 1; return; } else begin_chosen = 100; } } else if (in1[0] >= 'a' && in1[0] <= 'z') { in1[0] -= 32; for (int i = 0; i <= 9; i ++) { if (in1[0] == var[i]) { begin_chosen = i; printf(" = "); comma(var_var[begin_chosen]); chosen = 1; return; } else begin_chosen = 100; } } }} else { choice = strcmp (in1, c_lear); if (choice == 0) {system("clear"); chosen = 1; return ;} else { choice = strcmp (in1, e_nd); if (choice == 0) exit(1); else { choice = strcmp (in1, V_AR); if (choice == 0) {VAR(); chosen = 1; return ;} else { choice = strcmp (in1, s_ave); if (choice == 0) {save(); chosen = 1; return;} else { choice = strcmp (in1, l_oad); if (choice == 0) {load(); chosen = 1; return;} }}}} } if (begin_chosen == 100) {printf(" = undefined."); chosen = 1; return;} } } // choice 함수
void Sim::SFM::Airframe::save(Variant & variant, const Desc & desc) { save(variant["force"], desc.force); save(variant["torque"], desc.torque); }
void LogSensorStream::save(const std::string& _filename){ std::ofstream outfile; outfile.open(_filename.c_str()); save(outfile); outfile.close(); }
void MainWindow::createActions() { newAction = new QAction(tr("&New"), this); newAction->setIcon(QIcon(":/images/new.png")); newAction->setShortcut(QKeySequence::New); newAction->setStatusTip(tr("Create a new spreadsheet file")); connect(newAction, SIGNAL(triggered()), this, SLOT(newFile())); openAction = new QAction(tr("&Open..."), this); openAction->setIcon(QIcon(":/images/open.png")); openAction->setShortcut(QKeySequence::Open); openAction->setStatusTip(tr("Open an existing spreadsheet file")); connect(openAction, SIGNAL(triggered()), this, SLOT(open())); saveAction = new QAction(tr("&Save"), this); saveAction->setIcon(QIcon(":/images/save.png")); saveAction->setShortcut(QKeySequence::Save); saveAction->setStatusTip(tr("Save the spreadsheet to disk")); connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); saveAsAction = new QAction(tr("Save &As..."), this); saveAsAction->setStatusTip(tr("Save the spreadsheet under a new " "name")); connect(saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs())); for (int i = 0; i < MaxRecentFiles; ++i) { recentFileActions[i] = new QAction(this); recentFileActions[i]->setVisible(false); connect(recentFileActions[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); } exitAction = new QAction(tr("E&xit"), this); exitAction->setShortcut(tr("Ctrl+Q")); exitAction->setStatusTip(tr("Exit the application")); connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); cutAction = new QAction(tr("Cu&t"), this); cutAction->setIcon(QIcon(":/images/cut.png")); cutAction->setShortcut(QKeySequence::Cut); cutAction->setStatusTip(tr("Cut the current selection's contents " "to the clipboard")); connect(cutAction, SIGNAL(triggered()), spreadsheet, SLOT(cut())); copyAction = new QAction(tr("&Copy"), this); copyAction->setIcon(QIcon(":/images/copy.png")); copyAction->setShortcut(QKeySequence::Copy); copyAction->setStatusTip(tr("Copy the current selection's contents " "to the clipboard")); connect(copyAction, SIGNAL(triggered()), spreadsheet, SLOT(copy())); pasteAction = new QAction(tr("&Paste"), this); pasteAction->setIcon(QIcon(":/images/paste.png")); pasteAction->setShortcut(QKeySequence::Paste); pasteAction->setStatusTip(tr("Paste the clipboard's contents into " "the current selection")); connect(pasteAction, SIGNAL(triggered()), spreadsheet, SLOT(paste())); deleteAction = new QAction(tr("&Delete"), this); deleteAction->setShortcut(QKeySequence::Delete); deleteAction->setStatusTip(tr("Delete the current selection's " "contents")); connect(deleteAction, SIGNAL(triggered()), spreadsheet, SLOT(del())); selectRowAction = new QAction(tr("&Row"), this); selectRowAction->setStatusTip(tr("Select all the cells in the " "current row")); connect(selectRowAction, SIGNAL(triggered()), spreadsheet, SLOT(selectCurrentRow())); selectColumnAction = new QAction(tr("&Column"), this); selectColumnAction->setStatusTip(tr("Select all the cells in the " "current column")); connect(selectColumnAction, SIGNAL(triggered()), spreadsheet, SLOT(selectCurrentColumn())); selectAllAction = new QAction(tr("&All"), this); selectAllAction->setShortcut(QKeySequence::SelectAll); selectAllAction->setStatusTip(tr("Select all the cells in the " "spreadsheet")); connect(selectAllAction, SIGNAL(triggered()), spreadsheet, SLOT(selectAll())); findAction = new QAction(tr("&Find..."), this); findAction->setIcon(QIcon(":/images/find.png")); findAction->setShortcut(QKeySequence::Find); findAction->setStatusTip(tr("Find a matching cell")); connect(findAction, SIGNAL(triggered()), this, SLOT(find())); goToCellAction = new QAction(tr("&Go to Cell..."), this); goToCellAction->setIcon(QIcon(":/images/gotocell.png")); goToCellAction->setShortcut(tr("Ctrl+G")); goToCellAction->setStatusTip(tr("Go to the specified cell")); connect(goToCellAction, SIGNAL(triggered()), this, SLOT(goToCell())); recalculateAction = new QAction(tr("&Recalculate"), this); recalculateAction->setShortcut(tr("F9")); recalculateAction->setStatusTip(tr("Recalculate all the " "spreadsheet's formulas")); connect(recalculateAction, SIGNAL(triggered()), spreadsheet, SLOT(recalculate())); sortAction = new QAction(tr("&Sort..."), this); sortAction->setStatusTip(tr("Sort the selected cells or all the " "cells")); connect(sortAction, SIGNAL(triggered()), this, SLOT(sort())); showGridAction = new QAction(tr("&Show Grid"), this); showGridAction->setCheckable(true); showGridAction->setChecked(spreadsheet->showGrid()); showGridAction->setStatusTip(tr("Show or hide the spreadsheet's " "grid")); connect(showGridAction, SIGNAL(toggled(bool)), spreadsheet, SLOT(setShowGrid(bool))); #if QT_VERSION < 0x040102 // workaround for a QTableWidget bug in Qt 4.1.1 connect(showGridAction, SIGNAL(toggled(bool)), spreadsheet->viewport(), SLOT(update())); #endif autoRecalcAction = new QAction(tr("&Auto-Recalculate"), this); autoRecalcAction->setCheckable(true); autoRecalcAction->setChecked(spreadsheet->autoRecalculate()); autoRecalcAction->setStatusTip(tr("Switch auto-recalculation on or " "off")); connect(autoRecalcAction, SIGNAL(toggled(bool)), spreadsheet, SLOT(setAutoRecalculate(bool))); aboutAction = new QAction(tr("&About"), this); aboutAction->setStatusTip(tr("Show the application's About box")); connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); aboutQtAction = new QAction(tr("About &Qt"), this); aboutQtAction->setStatusTip(tr("Show the Qt library's About box")); connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); }
void FrameState::update(const IRInstruction* inst) { if (auto* taken = inst->taken()) { save(taken); } auto const opc = inst->op(); getLocalEffects(inst, *this); switch (opc) { case DefInlineFP: trackDefInlineFP(inst); break; case InlineReturn: trackInlineReturn(inst); break; case Call: m_spValue = inst->dst(); m_frameSpansCall = true; // A call pops the ActRec and pushes a return value. m_spOffset -= kNumActRecCells; m_spOffset += 1; assert(m_spOffset >= 0); clearCse(); break; case CallArray: m_spValue = inst->dst(); m_frameSpansCall = true; // A CallArray pops the ActRec an array arg and pushes a return value. m_spOffset -= kNumActRecCells; assert(m_spOffset >= 0); clearCse(); break; case ContEnter: clearCse(); break; case DefFP: case FreeActRec: m_fpValue = inst->dst(); break; case ReDefGeneratorSP: m_spValue = inst->dst(); break; case ReDefSP: m_spValue = inst->dst(); m_spOffset = inst->extra<ReDefSP>()->spOffset; break; case DefInlineSP: case DefSP: m_spValue = inst->dst(); m_spOffset = inst->extra<StackOffset>()->offset; break; case AssertStk: case AssertStkVal: case CastStk: case CoerceStk: case CheckStk: case GuardStk: case ExceptionBarrier: m_spValue = inst->dst(); break; case SpillStack: { m_spValue = inst->dst(); // Push the spilled values but adjust for the popped values int64_t stackAdjustment = inst->src(1)->getValInt(); m_spOffset -= stackAdjustment; m_spOffset += spillValueCells(inst); break; } case SpillFrame: case CufIterSpillFrame: m_spValue = inst->dst(); m_spOffset += kNumActRecCells; break; case InterpOne: case InterpOneCF: { m_spValue = inst->dst(); auto const& extra = *inst->extra<InterpOneData>(); int64_t stackAdjustment = extra.cellsPopped - extra.cellsPushed; // push the return value if any and adjust for the popped values m_spOffset -= stackAdjustment; break; } case AssertLoc: case GuardLoc: case CheckLoc: m_fpValue = inst->dst(); break; case LdThis: m_thisAvailable = true; break; default: break; } if (inst->modifiesStack()) { m_spValue = inst->modifiedStkPtr(); } // update the CSE table if (m_enableCse && inst->canCSE()) { cseInsert(inst); } // if the instruction kills any of its sources, remove them from the // CSE table if (inst->killsSources()) { for (int i = 0; i < inst->numSrcs(); ++i) { if (inst->killsSource(i)) { cseKill(inst->src(i)); } } } }
void BookmarkGroup::reparent( BookmarkGroupPtr parent ) { m_parent = parent; save(); }
void BookmarkGroup::setDescription( const QString &description ) { m_description = description; save(); }
void BookmarkGroup::rename(const QString & name) { m_name = name; save(); }
void SimpleDBStorage::save(void) { save(table); }
/** *\fn int main(int argc, char *argv[]) * Main *\param[in,out] argc argc *\param[in,out] argv argv */ int main(int argc, char *argv[]) { SDL_Surface *screen = NULL; int go = 1; int ret,ret1, ret2 = 0, ret3, ret4; char level_name[MAX_SIZE_FILE_NAME]; char player_name[MAX_SIZE_FILE_NAME]; int nb_lvl; /*sound*/ Sound *sound_system; sound_system = createSound(); /*keyboard config*/ SDLKey kc[NB_KEY-1]; /*input*/ Input in; SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK); Player *current_player; current_player = (Player *)malloc(sizeof(Player)); /*screen initialization*/ screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); initInput(&in); /*configurations loading */ loadSoundOptions("configuration/sound.conf",sound_system); SDL_WM_SetCaption("Super Martin", NULL); //window name SDL_ShowCursor(SDL_DISABLE); //delete the mouse while (go) //main loop { if(titleMenu(screen,&go,sound_system, &in)) { while( (ret3 = menuPlayers(screen, player_name, &go, sound_system, &in)) != -1 && go) { switch(ret3) { case -1: break; case 2 : ret2 = newPlayer(screen, player_name, sound_system, &go); if(ret2 == 1) { current_player->levelMax = 1; current_player->nbCoins = 0; current_player->nbLifes = 3; current_player->nbProjectile = 5; savePlayer("save/.save", player_name, current_player); loadInputOptions("default",kc,&in); saveInputOptions(player_name, kc, &in); } else break; case 1 : loadPlayer("save/.save", player_name, current_player); loadInputOptions(player_name,kc,&in); while(go && (ret1 = mainMenu(screen,&go,sound_system, player_name, &in)) != -1) { switch(ret1) { case -1: break; case 0: while( (ret4 = menuLevel(screen,level_name,sound_system, player_name, current_player, &go, &nb_lvl, &in)) != -1 && go) { while(play(screen,level_name,sound_system,&go,kc, &in, current_player, player_name, ret4+1, nb_lvl) && go); } break; case 1 : save(screen, "save/.save", player_name, current_player, &go); loadPlayer("save/.save", player_name, current_player); break; case 2 : while((ret = optionMenu(screen,&go,sound_system,kc, &in)) != -1 && go) { switch(ret) { case -1: break; case 0: soundOptions(screen,&go,sound_system, &in); break; case 1: keyBoardOptions(screen,&go,kc,&in,player_name); break; default:; } } break; case 3 : deletePlayer(screen, "save/players", player_name); go = 0; break; default: ; } } go = 1; break; default : ; } } } SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,255,255,255)); //clear screen SDL_Flip(screen); } freeSound(sound_system); free((void*)current_player); freeInput(&in); SDL_Quit(); return EXIT_SUCCESS; }
void ItemShortcut::setItem(const int index) { mItems[index] = mItemSelected; mItemColors[index] = mItemColorSelected; save(); }
int split_quoted (const char *s, int *argc, char *argv[], int argv_sz) { char arg_buff[MAX_ARG_LEN]; /* current argument buffer */ char *ap, *ae; /* arg_buff current ptr & end-guard */ const char *c; /* current input charcter ptr */ char qc; /* current quote character */ enum states state; /* current state */ enum err_codes err; /* error end-code */ int flags; /* warning flags */ ap = &arg_buff[0]; ae = &arg_buff[MAX_ARG_LEN - 1]; c = &s[0]; state = ST_DELIM; err = ERR_OK; flags = 0; qc = SQ; /* silence compiler waring */ while ( state != ST_END ) { switch (state) { case ST_DELIM: while ( is_delim(*c) ) c++; if ( *c == SQ || *c == DQ ) { qc = *c; c++; state = ST_QUOTE; break; } if ( *c == EOS ) { state = ST_END; break; } if ( *c == BS ) { c++; if ( *c == NL ) { c++; break; } if ( *c == EOS ) { state = ST_END; err = ERR_BS_AT_EOS; break; } } /* All other cases incl. character after BS */ save(); c++; state = ST_ARG; break; case ST_QUOTE: while ( *c != qc && ( *c != BS || qc == SQ ) && *c != EOS ) { save(); c++; } if ( *c == qc ) { c++; state = ST_ARG; break; } if ( *c == BS ) { assert (qc == DQ); c++; if ( *c == NL) { c++; break; } if (*c == EOS) { state = ST_END; err = ERR_BS_AT_EOS; break; } if ( ! is_dq_escapable(*c) ) { c--; save(); c++; } save(); c++; break; } if ( *c == EOS ) { state = ST_END; err = ERR_SQ_OPEN_AT_EOS; break; } assert(0); case ST_ARG: if ( *c == SQ || *c == DQ ) { qc = *c; c++; state = ST_QUOTE; break; } if ( is_delim(*c) || *c == EOS ) { push(); state = (*c == EOS) ? ST_END : ST_DELIM; c++; break; } if ( *c == BS ) { c++; if ( *c == NL ) { c++; break; } if ( *c == EOS ) { state = ST_END; err = ERR_BS_AT_EOS; break; } } /* All other cases, incl. character after BS */ save(); c++; break; default: assert(0); } } return ( err != ERR_OK ) ? -1 : flags; }
void save(const lslboost::serialization::item_version_type & t){ save(static_cast<const unsigned int>(t)); }
void CCellView::ResizeCol(BPoint where, int colNr) { float x, minX, maxRow; BPoint newP, lastP; BRect bounds(Bounds()), r, b; ulong buttons, cnt; bool multi; int mCol = colNr; CRunArray backup(fCellWidths); StPenState save(this); ClearAnts(); cnt = fSelection.right - fSelection.left + 1; while (fCellWidths[colNr + 1] == fCellWidths[colNr]) colNr++; multi = fSelection.left != fSelection.right && colNr >= fSelection.left && colNr <= fSelection.right; if (colNr <= fFrozen.h) { x = fBorderWidth + fCellWidths[colNr]; minX = fBorderWidth + fCellWidths[multi?fSelection.left - 1 : colNr - 1]; } else { x = fBorderWidth + fCellWidths[colNr] + fCellWidths[fFrozen.h] - fCellWidths[fPosition.h - 1]; minX = fBorderWidth + fCellWidths[fFrozen.h] - fCellWidths[fPosition.h - 1] + fCellWidths[multi?fSelection.left - 1 : colNr - 1]; } r.top = 1; r.bottom = fBorderHeight - 1; r.left = minX + 1; if (multi) r.right = minX + fCellWidths[fSelection.right] - fCellWidths[fSelection.left - 1] - 1; else r.right = minX + fCellWidths[colNr] - fCellWidths[colNr - 1] - 1; b = bounds; b.left = r.right; maxRow = fPosition.v; while (fCellHeights[++maxRow] - fCellHeights[fPosition.v] < bounds.bottom - fBorderHeight) ; lastP = where; newP = where; do { if (newP.x != lastP.x) { float dx; int k = colNr; dx = newP.x - lastP.x; if (lastP.x + dx < bounds.left + fBorderWidth) dx = std::min(lastP.x - bounds.left - fBorderWidth, (float)0); if (lastP.x + dx > bounds.right) dx = std::max(bounds.right - lastP.x, (float)0); if (multi && x + dx < minX) dx = minX - x; if (multi) { float w, t; w = x + dx - minX; if (w > 0) w = Round(w / (colNr - fSelection.left + 1)); t = fCellWidths[fSelection.right]; fCellWidths.SetValue(fSelection.left, fSelection.right, w); dx = fCellWidths[fSelection.right] - t; } else if (x + dx < minX) { int t = k; fCellWidths.SetValue(colNr, 0); while (k > 1 && backup[k - 1] + fBorderWidth >= x + dx) k--; ASSERT(k<colNr); if (k <= mCol) while (mCol > k) fCellWidths.SetValue(mCol--, 0); else { t = mCol; for (;mCol<k;mCol++) fCellWidths.SetValue(mCol, backup[mCol] - backup[mCol - 1]); } float kw = x + dx - fBorderWidth; kw -= backup[k - 1]; fCellWidths.SetValue(k, std::max(kw, (float)0)); mCol = k; k = t; } else { k = mCol; for (; mCol < colNr; mCol++) fCellWidths.SetValue(mCol, backup[mCol] - backup[mCol - 1]); fCellWidths.SetValue(colNr, x + dx - minX); } if (dx != 0) { x += dx; lastP.x += dx; if (dx < 0) b.left += dx; StPenState save(this); StClipCells clip(this); ScrollRect(b, dx, 0); Window()->UpdateIfNeeded(); if (dx > 0) b.left += dx; if (multi) { int h = fSelection.left, v; do { for (v = 1; v < fFrozen.v; v++) DrawCell(cell(h, v)); for (v = fPosition.v; v < maxRow; v++) DrawCell(cell(h, v)); DrawBorderCell(h++, true); } while (h <= fSelection.right && bounds.left + fCellWidths[h] + fBorderWidth < bounds.right); } else { int v; for (v = 1; v < fFrozen.v; v++) DrawCell(cell(mCol, v)); for (v = fPosition.v; v < maxRow; v++) DrawCell(cell(mCol, v)); DrawBorderCell(mCol, true); } for (; k < colNr; k++) { int v; for (v = 1; v < fFrozen.v; v++) DrawCell(cell(k, v)); for (v = fPosition.v; v < maxRow; v++) DrawCell(cell(k, v)); DrawBorderCell(k, true); } } if (dx < 0) { float X; int h; X = bounds.right + dx - fBorderWidth; h = fSelection.right; do h++; while (fCellWidths[h] < X); while (h <= kColCount && bounds.left + fCellWidths[h] + fBorderWidth < bounds.right) { int v; for (v = 1; v < fFrozen.v; v++) DrawCell(cell(h, v)); for (v = fPosition.v; v < maxRow; v++) DrawCell(cell(h, v)); DrawBorderCell(h++, true); } } if (dx && fFirstGraphic) fFirstGraphic->HandleUpdate(bounds); } GetMouse(&newP, &buttons); } while (buttons); if (!(backup == fCellWidths)) { CRunArray temp(fCellWidths); fCellWidths = backup; ((CCellWindow*)Window())->RegisterCommand(new CResizeCommand(this, temp, false)); ((CCellWindow*)Window())->SetDirty(true); } } /* ResizeCol */
/* save before trying to parse something that may fail */ void save() { save(s); }
void CCellView::ResizeRow(BPoint where, int rowNr) { float y, minY; BPoint newP, lastP; BRect bounds(Bounds()), r, b; BRegion rgn; ulong buttons, cnt; bool multi; int mRow = rowNr; CRunArray backup(fCellHeights); StPenState save(this); ClearAnts(); rgn.Include(bounds); cnt = fSelection.bottom-fSelection.top+1; while (where.y > fCellHeights[rowNr+1]+2) rowNr++; multi = fSelection.top != fSelection.bottom && rowNr >= fSelection.top && rowNr <= fSelection.bottom; if (rowNr <= fFrozen.v) { y = fBorderHeight+fCellHeights[rowNr]; minY = fBorderHeight+fCellHeights[multi?fSelection.top-1:rowNr-1]; } else { y = fBorderHeight+fCellHeights[rowNr]+fCellHeights[fFrozen.v]- fCellHeights[fPosition.v-1]; minY = fBorderHeight+fCellHeights[fFrozen.v]-fCellHeights[fPosition.v-1]+ fCellHeights[multi?fSelection.top-1:rowNr-1]; } r.left = 0; r.right = fBorderWidth-1; r.top = minY+1; if (multi) r.bottom = minY+fCellHeights[fSelection.bottom]- fCellHeights[fSelection.top-1]-1; else r.bottom = minY+fCellHeights[rowNr]-fCellHeights[rowNr-1]-1; b = bounds; b.top = r.bottom; lastP = where; newP = where; do { if (newP.y != lastP.y) { float dy; int k = rowNr; dy = newP.y - lastP.y; if (lastP.y + dy < bounds.top + fBorderHeight) dy = std::min(lastP.y - bounds.top - fBorderHeight, (float)0); if (lastP.y + dy > bounds.bottom) dy = std::max(bounds.bottom - lastP.y, (float)0); if (multi && y + dy < minY) dy = minY - y; if (multi) { float h, t; h = y + dy - minY; if (h > 0) h = Round(h/(rowNr-fSelection.top+1)); t = fCellHeights[fSelection.bottom]; fCellHeights.SetValue(fSelection.top, fSelection.bottom, h); dy = fCellHeights[fSelection.bottom] - t; } else if (y + dy < minY) { int t = k; fCellHeights.SetValue(rowNr, 0); while (k > 1 && backup[k - 1] + fBorderHeight >= y + dy) k--; ASSERT(k<rowNr); if (k <= mRow) while (mRow > k) fCellHeights.SetValue(mRow--, 0); else { t = mRow; for (; mRow < k; mRow++) fCellHeights.SetValue(mRow, backup[mRow] - backup[mRow - 1]); } float kh = y + dy - fBorderHeight; kh -= backup[k - 1]; fCellHeights.SetValue(k, std::max(kh, (float)0)); mRow = k; k = t; } else { k = mRow; for (; mRow < rowNr; mRow++) fCellHeights.SetValue(mRow, backup[mRow] - backup[mRow - 1]); fCellHeights.SetValue(rowNr, y + dy - minY); } if (dy != 0) { y += dy; lastP.y += dy; if (dy < 0) b.top += dy; StPenState save(this); StClipCells clip(this); ScrollRect(b, 0, dy); Window()->UpdateIfNeeded(); if (dy > 0) b.top += dy; if (multi) { int v = fSelection.top; do { TouchLine(v); DrawBorderCell(v++, false); } while (v <= fSelection.bottom && bounds.top + fCellHeights[v] + fBorderHeight < bounds.bottom); } else { TouchLine(mRow); DrawBorderCell(mRow, false); } for (; k < rowNr; k++) { TouchLine(k); DrawBorderCell(k, false); } } if (dy < 0) { float Y; int v; Y = bounds.bottom + dy - fBorderHeight; v = fSelection.bottom; do v++; while (fCellHeights[v] < Y) ; StPenState save(this); while (v <= kRowCount && bounds.top + fCellHeights[v] + fBorderHeight < bounds.bottom) { TouchLine(v); DrawBorderCell(v++, false); } } if (dy) { DrawAllLines(); if (fFirstGraphic) fFirstGraphic->HandleUpdate(bounds); } } GetMouse(&newP, &buttons); } while (buttons); if (!(backup == fCellHeights)) { CRunArray temp(fCellHeights); fCellHeights = backup; ((CCellWindow*)Window())->RegisterCommand(new CResizeCommand(this, temp, true)); ((CCellWindow*)Window())->SetDirty(true); } } /* ResizeRow */
void save(size_t sz) { void* bp; get_bp(bp); save(sz, bp); }
bool GurlsClassificationInterface::read(yarp::os::ConnectionReader& connection) { yarp::os::idl::WireReader reader(connection); reader.expectAccept(); if (!reader.readListHeader()) { reader.fail(); return false; } yarp::os::ConstString tag = reader.readTag(); while (!reader.isError()) { // TODO: use quick lookup, this is just a test if (tag == "add_sample") { std::string className; yarp::sig::Vector sample; if (!reader.readString(className)) { reader.fail(); return false; } if (!reader.read(sample)) { reader.fail(); return false; } bool _return; _return = add_sample(className,sample); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "save") { std::string className; if (!reader.readString(className)) { reader.fail(); return false; } bool _return; _return = save(className); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "train") { bool _return; _return = train(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "forget") { std::string className; if (!reader.readString(className)) { reader.fail(); return false; } bool _return; _return = forget(className); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "classList") { std::vector<std::string> _return; _return = classList(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; { if (!writer.writeListBegin(BOTTLE_TAG_STRING, static_cast<uint32_t>(_return.size()))) return false; std::vector<std::string> ::iterator _iter16; for (_iter16 = _return.begin(); _iter16 != _return.end(); ++_iter16) { if (!writer.writeString((*_iter16))) return false; } if (!writer.writeListEnd()) return false; } } reader.accept(); return true; } if (tag == "stop") { bool _return; _return = stop(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "recognize") { bool _return; _return = recognize(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "classify_sample") { yarp::sig::Vector sample; if (!reader.read(sample)) { reader.fail(); return false; } std::string _return; _return = classify_sample(sample); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeString(_return)) return false; } reader.accept(); return true; } if (tag == "get_scores_for_sample") { yarp::sig::Vector sample; if (!reader.read(sample)) { reader.fail(); return false; } std::vector<ClassScore> _return; _return = get_scores_for_sample(sample); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; { if (!writer.writeListBegin(BOTTLE_TAG_LIST, static_cast<uint32_t>(_return.size()))) return false; std::vector<ClassScore> ::iterator _iter17; for (_iter17 = _return.begin(); _iter17 != _return.end(); ++_iter17) { if (!writer.writeNested((*_iter17))) return false; } if (!writer.writeListEnd()) return false; } } reader.accept(); return true; } if (tag == "get_parameter") { std::string parameterName; if (!reader.readString(parameterName)) { reader.fail(); return false; } std::string _return; _return = get_parameter(parameterName); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeString(_return)) return false; } reader.accept(); return true; } if (tag == "set_parameter") { std::string parameterName; std::string parameterValue; if (!reader.readString(parameterName)) { reader.fail(); return false; } if (!reader.readString(parameterValue)) { reader.fail(); return false; } bool _return; _return = set_parameter(parameterName,parameterValue); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (reader.noMore()) { reader.fail(); return false; } yarp::os::ConstString next_tag = reader.readTag(); if (next_tag=="") break; tag = tag + "_" + next_tag; } return false; }
void IntegerEdit::accept() { save(); }
void AcceptDialog::apply(ICQUser*) { save(pClient->owner); }
QString Path::save(int game) { return save(QString::number(game) + ".xml"); }
int main_train(int argc, char **argv) { char *posSplFile = NULL; char *negSplFile = NULL; char *modelFile = NULL; int stage = 15; int width = 0, height = 0; int numPos = 0, numNeg = 0; const int numVal = 400; float tarfpr = 0.05; float maxfnr = 0.05; std::vector<std::string> negImgList; if((argc - 1) / 2 != 10) { print_train_usage(argv[0]); return 1; } for(int i = 1; i < argc; i++) { if(strcmp(argv[i], "--stage") == 0) stage = atoi(argv[++i]); else if(strcmp(argv[i], "-X") == 0) width = atoi(argv[++i]); else if(strcmp(argv[i], "-Y") == 0) height = atoi(argv[++i]); else if(strcmp(argv[i], "--false_alarm_rate") == 0) tarfpr = atof(argv[++i]); else if(strcmp(argv[i], "--missing_rate") == 0) maxfnr = atof(argv[++i]); else if(strcmp(argv[i], "--pos") == 0) posSplFile = argv[++i]; else if(strcmp(argv[i], "--neg") == 0) negSplFile = argv[++i]; else if(strcmp(argv[i], "-m") == 0) modelFile = argv[++i]; else if(strcmp(argv[i], "--numPos")) numPos = atoi(argv[++i]); else if(strcmp(argv[i], "--numNeg")) numNeg = atoi(argv[++i]); else { printf("Can't recognize params %s\n", argv[i]); print_train_usage(argv[0]); return 1; } } if(posSplFile == NULL || negSplFile == NULL || width == 0 || height == 0 || numPos <= 0 || numNeg <= 0){ print_train_usage(argv[0]); return 1; } std::list<float *> positiveSet, negativeSet, validateSet; int ret; std::vector<Feature*> featureSet; float *stepFPR; float npRatio = 1.0 * numNeg / numPos; CascadeClassifier *cc = new CascadeClassifier(); StrongClassifier* sc; float maxfpr = 1.0; std::list<StrongClassifier *> scs; init_cascade_classifier(cc, scs, width, height); printf("GENERATE POSITIVE SAMPLES\n"); ret = generate_positive_samples(posSplFile, positiveSet, width, height, numPos); if(ret != 0) return 2; printf("GENERATE NEGATIVE SAMPLES\n"); read_image_list(negSplFile, negImgList); for(int i = 0; i < numNeg; i ++) { float *data = NULL; read_neg_sample_from_file(negImgList, width, height, &data); #ifdef USE_HAAR_FEATURE integral_image(data, width, height); #endif negativeSet.push_back(data); } printf("GENERATE VALIDATE SAMPLES\n"); generate_validate_samples(negImgList, width, height, validateSet, numPos); printf("Positive sample size: %ld\n", positiveSet.size()); printf("Negative sample size: %ld\n", negativeSet.size()); printf("Validate sample size: %d\n", numVal); printf("GENERATE FEATURE TEMPLATE\n"); generate_feature_set(featureSet, width, height); printf("SELECT FEATURE TEMPLATE\n"); select_feature(featureSet, positiveSet, validateSet, width); init_steps_false_positive(&stepFPR, stage, tarfpr); clock_t startTime = clock(); char outname[128]; for(int i = 0; i < stage; i++) { printf("\n--------------cascade stage %d-----------------\n", i+1); int correctSize = 0; std::list<float*>::iterator iter, iterEnd; numNeg = numPos * npRatio; printf("READ NEGATIVE SAMPLES\n"); ret = generate_negative_samples(negImgList, width, height, cc, negativeSet, numNeg); if(ret != numNeg) { printf("Can't generate enough negatvie samples %d:%d\n", ret, numNeg); break; } printf("READ VALIDATE SAMPLES\n"); ret = generate_negative_samples(negImgList, width, height, cc, validateSet, numVal); if(ret != numVal) { printf("Can't generate enough validate samples %d:%d\n", ret, numVal); break; } maxfpr *= stepFPR[i]; printf("Positive sample size: %d\n", numPos); printf("Negative sample size: %d\n", numNeg); printf("Target false positive rate: %f\n", maxfpr); printf("Target false negative rate: %f\n", maxfnr); sc = adaboost_learning(cc, positiveSet, numPos, negativeSet, numNeg, validateSet, featureSet, maxfpr, maxfnr); add(cc, sc); iter = positiveSet.begin(); iterEnd = positiveSet.end(); while(iter != iterEnd) { if(classify(cc, *iter, width, 0, 0) == 0) { std::list<float*>::iterator iterTmp = iter; iter++; delete[] (*iterTmp); positiveSet.erase(iterTmp); iter--; } iter++; } numPos = positiveSet.size(); printf("cascade TP: %d\n", numPos); iter = negativeSet.begin(); iterEnd = negativeSet.end(); correctSize = negativeSet.size(); while(iter != iterEnd) { if(classify(cc, *iter, width, 0, 0) == 0) { std::list<float*>::iterator iterTmp = iter; iter++; delete[] (*iterTmp); negativeSet.erase(iterTmp); iter--; } iter++; } printf("cascade TN: %ld\n", correctSize - negativeSet.size()); iter = validateSet.begin(); iterEnd = validateSet.end(); while(iter != iterEnd) { if(classify(cc, *iter, width, 0, 0) == 0) { std::list<float*>::iterator iterTmp = iter; iter++; delete[] (*iterTmp); validateSet.erase(iterTmp); iter--; } iter++; } printf("----------------------------------------\n"); sprintf(outname, "model/cascade_%d.dat", i+1); save(cc, outname); #ifdef SHOW_FEATURE print_feature(cc); #endif } save(cc, modelFile); clock_t trainTime = clock() - startTime; printf("Train time:"); print_time(trainTime); printf("\n"); clear(cc); clear_list(positiveSet); clear_list(negativeSet); clear_list(validateSet); clear_features(featureSet); return 0; }
static void read_string (LexState *LS, int del, SemInfo *seminfo) { size_t l = 0; checkbuffer(LS, l); save_and_next(LS, l); while (LS->current != del) { checkbuffer(LS, l); switch (LS->current) { case EOZ: save(LS, '\0', l); luaX_lexerror(LS, "unfinished string", TK_EOS); break; /* to avoid warnings */ case '\n': save(LS, '\0', l); luaX_lexerror(LS, "unfinished string", TK_STRING); break; /* to avoid warnings */ case '\\': next(LS); /* do not save the `\' */ switch (LS->current) { case 'a': save(LS, '\a', l); next(LS); break; case 'b': save(LS, '\b', l); next(LS); break; case 'f': save(LS, '\f', l); next(LS); break; case 'n': save(LS, '\n', l); next(LS); break; case 'r': save(LS, '\r', l); next(LS); break; case 't': save(LS, '\t', l); next(LS); break; case 'v': save(LS, '\v', l); next(LS); break; case '\n': save(LS, '\n', l); inclinenumber(LS); break; case EOZ: break; /* will raise an error next loop */ default: { if (!isdigit(LS->current)) save_and_next(LS, l); /* handles \\, \", \', and \? */ else { /* \xxx */ int c = 0; int i = 0; do { c = 10*c + (LS->current-'0'); next(LS); } while (++i<3 && isdigit(LS->current)); if (c > UCHAR_MAX) { save(LS, '\0', l); luaX_lexerror(LS, "escape sequence too large", TK_STRING); } save(LS, c, l); } } } break; default: save_and_next(LS, l); } } save_and_next(LS, l); /* skip delimiter */ save(LS, '\0', l); seminfo->ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff) + 1, l - 3); }
void Kandy::fileSave() { if(mFilename.isEmpty()) fileSaveAs(); else save(mFilename); }