void realloc_(size_type new_capacity) { size_type new_size = std::min(new_capacity, size()); T* new_data = new T[new_capacity]; std::memcpy(new_data, begin_, new_size * sizeof(T)); delete_(); begin_ = data_ = new_data; end_ = new_data + new_size; limit_ = new_data + new_capacity; }
void TileStampsDock::keyPressEvent(QKeyEvent *event) { switch (event->key()) { case Qt::Key_Delete: case Qt::Key_Backspace: { delete_(); return; } } QDockWidget::keyPressEvent(event); }
int main() { char str[] = "They are students."; char deleted_char[] = "aeiou"; char *result = delete_(str, deleted_char); if (result == NULL) { fprintf(stderr, "delete failed.\n"); return -1; } printf("%s\n", result); return 0; }
/// Resizes the vector to n elements. /// The contents is undefined. /// The pointer returned is the same as /// would be returned from mut_data(). T* assign(size_type n) { if(capacity() < n) { delete_(); alloc_(n); } else { end_ = begin_ + n; } return begin_; }
void UnitySupportGui::loadImage() { delete_(image); if ( !(image = new QImage(filename,"PNG"))->isNull()) { if(corrupted = !image->allGray()) {MGS("ERROR: The image is not grayscaled!"); return;} } else { MGS("ERROR: Failed to load image. Please reload."); corrupted = true; return; } IMGS(tr("Image successfully loaded")); reset(); }
/// Tries to enqueue a new element to the mailbox. /// @warning Call only from the reader (owner). enqueue_result enqueue(pointer new_element) { CAF_ASSERT(new_element != nullptr); pointer e = stack_.load(); for (;;) { if (! e) { // if tail is nullptr, the queue has been closed delete_(new_element); return enqueue_result::queue_closed; } // a dummy is never part of a non-empty list new_element->next = is_dummy(e) ? nullptr : e; if (stack_.compare_exchange_strong(e, new_element)) { return (e == reader_blocked_dummy()) ? enqueue_result::unblocked_reader : enqueue_result::success; } // continue with new value of e } }
void clear(F f) { for (auto& range : ranges()) { auto i = range.first; auto e = range.second; while (i != e) { auto ptr = i.ptr; ++i; f(*ptr); delete_(ptr); } } if (head_.next != &separator_) { head_.next = &separator_; separator_.prev = &head_; } if (separator_.next != &tail_) { separator_.next = &tail_; tail_.prev = &separator_; } }
void command(void) { char buffer[100]; printf(">"); fscanf( stdin, "%s", buffer ); if ( !strcmp( buffer, "insert" ) ) { insert(); return; } else if ( !strcmp( buffer, "update" ) ) { update(); return; } else if ( !strcmp( buffer, "delete" ) ) { delete_(); return; } else if ( !strcmp( buffer, "sort" ) ) { sort_(); return; } else if ( !strcmp( buffer, "show" ) ) { show(); return; } else if ( !strcmp( buffer, "save" ) ) { save(); return; } else if ( !strcmp( buffer, "exit" ) ) { exit_(); return; } else { printf("Wrong command!\n"); return; } }
// JPEGの 'erroneous header' (0xFF 0xD9 0xFF 0xD8) を先頭に追加 // 参考: SWF V10 仕様書 P.148 void addErroneousHeader_ImageFile(ImageData *this_){ if(this_->type != Type_JPEG) return; unsigned int i; // 新しく領域確保 byte *data = (byte*)new_(this_->data_size + 4); // 先頭4バイトにヘッダをいれる data[0] = 0xFF; data[1] = 0xD9; data[2] = 0xFF; data[3] = 0xD8; // JPEGデータをそのままコピー for( i=0 ; i<this_->data_size ; i++ ){ data[i+4] = this_->raw_data[i]; } // 古い領域を削除 byte *tmp = this_->raw_data; delete_(tmp); // ポインタつなぎ変え this_->raw_data = data; // 長さ更新 this_->data_size += 4; }
QxFileBrowser::QxFileBrowser(QWidget* parent) : QWidget(parent), gotoMenu_(0), recentMenu_(0), showHidden_(false), showDetails_(true), createFileDialog_(0), createDirDialog_(0), renameDialog_(0) { //-------------------------------------------------------------------------- // setup primary model and view cwdModel_ = new QFileSystemModel(this); cwdModel_->setReadOnly(false); QModelIndex root = cwdModel_->setRootPath(QDir::currentPath()); connect( cwdModel_, SIGNAL(fileRenamed(const QString&, const QString&, const QString&)), this, SLOT(fileRenamed(const QString&, const QString&, const QString&)) ); dirView_ = new QxFileSystemView(this); dirView_->setModel(cwdModel_); dirView_->header()->hide(); dirView_->setRootIndex(root); dirView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); dirView_->setDragDropMode(QAbstractItemView::DragOnly); connect(dirView_, SIGNAL(activated(const QModelIndex&)), this, SLOT(cwdSet(const QModelIndex&))); connect(dirView_, SIGNAL(escape()), this, SIGNAL(escape())); connect(dirView_, SIGNAL(cdUp()), this, SLOT(cdUp())); connect(cwdModel_, SIGNAL(layoutChanged()), dirView_, SLOT(resizeColumnsToContents())); setFocusProxy(dirView_); // dirView_->setTextElideMode(Qt::ElideMiddle); dirView_->setFrameStyle(QFrame::NoFrame); // dirView_->setIndentation(18); // together with a branch pixmap could improve branch alignment dirView_->setLineWidth(0); dirView_->setMidLineWidth(0); #ifdef Q_WS_MAC dirView_->setStyleSheet( "QTreeView {" " font-size: 12px;" "}" "QTreeView::item {" " padding-top: 1px;" "}" ); #endif { QPalette pal = dirView_->palette(); pal.setColor(QPalette::Base, styleManager()->color("fileBrowserDirViewBgColor")); dirView_->setPalette(pal); } //-------------------------------------------------------------------------- // setup navigation bar / panel head gotoButton_ = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserGotoButton"))); gotoButton_->setMode(QxControl::MenuMode); gotoButton_->visual()->setText(QDir::current().dirName()); gotoButton_->setMinimumWidth(10); // design HACK gotoButton_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); { QPixmap folderIcon = QFileIconProvider().icon(QFileInfo(QDir::currentPath())).pixmap(QSize(16, 16)); gotoButton_->visual()->setLeadingIcon(folderIcon); } #ifdef Q_WS_MAC #ifdef QT_MAC_USE_COCOA connect(gotoButton_, SIGNAL(toggled(bool)), this, SLOT(blockFloating(bool))); #endif // QT_MAC_USE_COCOA #endif // Q_WS_MAC updateGotoMenu(); class QxCdUpButton: public QxControl { public: QxCdUpButton(QWidget* parent) : QxControl(parent, new QxVisual(styleManager()->style("fileBrowserCdUpButton"))) {} private: // workaround HACK, prevent undocking, map double click event to single click virtual void mouseDoubleClickEvent(QMouseEvent* event) { press(); event->accept(); } }; QxControl* cdUpButton = new QxCdUpButton(this); cdUpButton->setMode(QxControl::TouchMode); connect(cdUpButton, SIGNAL(pressed()), this, SLOT(cdUp())); //-------------------------------------------------------------------------- // define context actions contextMenu_ = new QMenu(this); // QxDesignHack::beautify(contextMenu_); openDefaultAction_ = new QAction(tr("Open in Default App."), this); openDefaultAction_->setShortcut(tr("Ctrl+D")); openDefaultAction_->setShortcutContext(Qt::WidgetShortcut); openFileAction_ = new QAction(tr("Open in %1").arg(qApp->applicationName()), this); createFileAction_ = contextMenu_->addAction(tr("New File")); createDirAction_ = contextMenu_->addAction(tr("New Folder")); contextMenu_->addSeparator(); contextMenu_->addAction(openFileAction_); contextMenu_->addAction(openDefaultAction_); contextMenu_->addSeparator(); renameAction_ = contextMenu_->addAction(tr("Rename")); deleteAction_ = contextMenu_->addAction(tr("Move To Trash")); contextMenu_->addSeparator(); bookmarkAction_ = contextMenu_->addAction(tr("Bookmark")); contextMenu_->addSeparator(); showHiddenAction_ = contextMenu_->addAction(tr("Show Hidden")); showDetailsAction_ = contextMenu_->addAction(tr("Show Details")); connect(createFileAction_, SIGNAL(triggered()), this, SLOT(createFile())); connect(createDirAction_, SIGNAL(triggered()), this, SLOT(createDir())); connect(openDefaultAction_, SIGNAL(triggered()), this, SLOT(openDefault())); connect(openFileAction_, SIGNAL(triggered()), this, SLOT(openFile())); connect(renameAction_, SIGNAL(triggered()), this, SLOT(rename())); connect(deleteAction_, SIGNAL(triggered()), this, SLOT(delete_())); connect(dirView_, SIGNAL(delKeyPressed()), this, SLOT(delete_())); connect(showHiddenAction_, SIGNAL(toggled(bool)), this, SLOT(showHidden(bool))); connect(showDetailsAction_, SIGNAL(toggled(bool)), this, SLOT(showDetails(bool))); connect(bookmarkAction_, SIGNAL(triggered()), this, SLOT(bookmark())); showHiddenAction_->setCheckable(true); showDetailsAction_->setCheckable(true); showHiddenAction_->setChecked(false); showDetailsAction_->setChecked(false); //-------------------------------------------------------------------------- // setup toolbar QxControl* plusButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserPlusButton"))); plusButton->setMode(QxControl::TouchMode); connect(plusButton, SIGNAL(pressed()), this, SLOT(createFile())); QxControl* wheelButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserWheelButton"))); wheelButton->setMenu(contextMenu_); wheelButton->setMenuPopupMode(QxControl::DownsideMenuPopup|QxControl::UpsideMenuPopup|QxControl::PreferUpsideMenuPopup); QxControl* recentButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserRecentButton"))); recentButton->setMode(QxControl::TouchMode); connect(recentButton, SIGNAL(pressed()), this, SLOT(recentShowOrHide())); QxControl* bookmarksButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserBookmarksButton"))); bookmarksButton->setMode(QxControl::TouchMode); connect(bookmarksButton, SIGNAL(pressed()), this, SLOT(bookmarksShowOrHide())); statusBar_ = new QxStatusBar(this); showHidden(false); showDetails(false); //-------------------------------------------------------------------------- // setup bottom views recentModel_ = new QxUrlListModel(this); recentView_ = new QxUrlListView(this); // recentView_->header()->hide(); // recentView_->setViewMode(QListView::IconMode); // recentView_->setIconSize(QSize(16, 16)); recentView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); recentView_->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); recentView_->setTextElideMode(Qt::ElideLeft); recentView_->setFrameStyle(QFrame::NoFrame); recentView_->setLineWidth(0); recentView_->setMidLineWidth(0); recentView_->setStyleSheet( "QListView::item {" " padding-top: 1px;" "}" ); // recentView_->setAlternatingRowColors(true); recentView_->setModel(recentModel_); connect(recentView_, SIGNAL(activated(const QModelIndex&)), this, SLOT(gotoRecent(const QModelIndex&))); recentContextMenu_ = new QMenu(this); recentContextMenu_->addAction(tr("Goto"), this, SLOT(gotoRecent())); recentContextMenu_->addAction(tr("Add To Bookmarks"), this, SLOT(recentAddToBookmarks())); bookmarksModel_ = new QxUrlListModel(this); bookmarksModel_->setPathReduction(1); bookmarksView_ = new QxUrlListView(this); bookmarksView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); bookmarksView_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); bookmarksView_->setTextElideMode(Qt::ElideLeft); bookmarksView_->setFrameStyle(QFrame::NoFrame); bookmarksView_->setLineWidth(0); bookmarksView_->setMidLineWidth(0); bookmarksView_->setStyleSheet( "QListView::item {" " padding-top: 1px;" "}" ); bookmarksView_->setModel(bookmarksModel_); bookmarksView_->setDragDropMode(QAbstractItemView::InternalMove); bookmarksView_->setDragEnabled(true); bookmarksView_->setAcceptDrops(true); bookmarksView_->setDropIndicatorShown(true); connect(bookmarksView_, SIGNAL(activated(const QModelIndex&)), this, SLOT(gotoBookmark(const QModelIndex&))); bookmarksContextMenu_ = new QMenu(this); bookmarksContextMenu_->addAction(tr("Add Current Directory"), this, SLOT(cwdAddToBookmark())); bookmarksContextMenu_->addAction(tr("Add Other Directory"), this, SLOT(addDirBookmark())); bookmarksContextMenu_->addSeparator(); bookmarksContextMenu_->addAction(tr("Goto Here"), this, SLOT(gotoBookmark())); bookmarksContextMenu_->addAction(tr("Remove From List"), this, SLOT(removeBookmark())); bookmarksContextMenu_->addSeparator(); bookmarksShowFullPathAction_ = bookmarksContextMenu_->addAction(tr("Show Full Path")); bookmarksShowFullPathAction_->setCheckable(true); bookmarksShowFullPathAction_->setChecked(bookmarksModel_->pathReduction() == -1); connect(bookmarksShowFullPathAction_, SIGNAL(toggled(bool)), this, SLOT(bookmarksShowFullPath(bool))); #ifdef Q_WS_MAC { QProxyStyle* proxyStyle = qobject_cast<QProxyStyle*>(style()); QMacStyle* macStyle = qobject_cast<QMacStyle*>((proxyStyle) ? proxyStyle->baseStyle() : style()); if (macStyle) { macStyle->setFocusRectPolicy(dirView_, QMacStyle::FocusDisabled); macStyle->setFocusRectPolicy(recentView_, QMacStyle::FocusDisabled); macStyle->setFocusRectPolicy(dirView_, QMacStyle::FocusDisabled); macStyle->setFocusRectPolicy(bookmarksView_, QMacStyle::FocusDisabled); } } #endif //-------------------------------------------------------------------------- // layout widgets handle_ = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserSplitter"))); handle_->visual()->setText(""); handleTextRecent_ = tr("Recent Places"); handleTextBookmarks_ = tr("Bookmarks"); bottomStack_ = new QxControl(this); bottomStackLayout_ = new QStackedLayout; bottomStackLayout_->addWidget(recentView_); bottomStackLayout_->addWidget(bookmarksView_); bottomStack_->setLayout(bottomStackLayout_); bottomStack_->setVisible(false); splitter_ = new QxSplitter(this); splitter_->setOrientation(Qt::Vertical); splitter_->setHandle(1, handle_); splitter_->setHandleWidth(styleManager()->constant("fileBrowserSplitterWidth")); splitter_->addWidget(dirView_); /*{ QxControl* carrier = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserDirView"))); QGridLayout* layout = new QGridLayout; layout->setSpacing(0); layout->setMargin(0); layout->addWidget(dirView_); carrier->setLayout(layout); splitter_->addWidget(carrier); }*/ splitter_->addWidget(bottomStack_); // make dirView_ grow/shrink dynamically, while bottomStack_ keeps user-defined size splitter_->setStretchFactor(0, 1); splitter_->setStretchFactor(1, 0); QDockWidget* dock = qobject_cast<QDockWidget*>(parent); if (dock) { dock->setWidget(this); // connect(dock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(adaptToDockLocation(Qt::DockWidgetArea))); } QVBoxLayout* col = new QVBoxLayout; col->setSpacing(0); col->setMargin(0); { QxControl* carrier = new QxControl(parent, new QxVisual(styleManager()->style("fileBrowserNavCarrier"))); QHBoxLayout* row = new QHBoxLayout; row->setSpacing(0); row->setMargin(0); row->addWidget(gotoButton_); row->addStretch(); row->addWidget(cdUpButton); carrier->setLayout(row); if (dock) dock->setTitleBarWidget(carrier); else col->addWidget(carrier); } col->addWidget(splitter_); col->addWidget(styleManager()->hl(this)); { QBoxLayout* row = new QBoxLayout(QBoxLayout::LeftToRight); row->setSpacing(0); row->setMargin(0); row->addWidget(plusButton); row->addWidget(styleManager()->vl(this)); row->addWidget(wheelButton); row->addWidget(styleManager()->vl(this)); row->addWidget(recentButton); row->addWidget(styleManager()->vl(this)); row->addWidget(bookmarksButton); row->addWidget(styleManager()->vl(this)); row->addWidget(statusBar_); col->addLayout(row); bottomToolLayout_ = row; } setLayout(col); }
int command_loop(solutionp root) { char command[MAX_BUF]; char *token; int start,end,i; printf("Enter Command : "); fgets(command,MAX_BUF,stdin); switch(command[0]) { case 'l': printf(" BR PT TY LAB NEW\n"); token = strtok(&command[1]," \n"); if(token != NULL) { /*If there are further arguements use them*/ expandtoken(token,&start,&end); for(i=start;i<=end;i++){ print(root, i); } token = strtok(NULL," "); while(token != NULL) { expandtoken(token,&start,&end); for(i=start;i<=end;i++){ print(root, i); } token = strtok(NULL," "); } } else { /*Otherwise print them all*/ print(root,-1); } break; case 'd': token = strtok(&command[1]," \n"); if(token != NULL) { /*If there are further arguements use them*/ expandtoken(token,&start,&end); for(i=start;i<=end;i++){ delete_(root, i); } token = strtok(NULL," "); while(token != NULL) { expandtoken(token,&start,&end); for(i=start;i<=end;i++){ delete_(root, i); } token = strtok(NULL," "); } } else { /*Otherwise delete them all*/ delete_(root,-1); } break; case 'r': token = strtok(&command[1]," \n"); if(token != NULL) { /*If there are further arguements use them*/ expandtoken(token,&start,&end); for(i=start;i<=end;i++){ relabel(root, i); } token = strtok(NULL," "); while(token != NULL) { expandtoken(token,&start,&end); for(i=start;i<=end;i++){ relabel(root, i); } token = strtok(NULL," "); } } else { /*Otherwise relabel them all*/ relabel(root,-1); } break; case 'w': write8(root); write7(root); printf("Writing files...\n"); return 0; break; case 'q': return 0; break; case 'h': help(); break; default: printf("Invalid Command. Type 'h' for help.\n"); } return 1; }
/// Destroy thread local store static void destroy() { delete_(&inst()); pthread_setspecific(_key, nullptr); }
UnitySupportGui::~UnitySupportGui() { delete_(ui); delete_(image); }
void *cs_hash_del(cs_hash_tab *tab, const char *key) { void *val = delete_(tab, key); if (tab->cleanup) tab->cleanup(key, val); return val; }
/* * delete_big_tree - call recursive function delete_ to * delete target. * */ void delete_big_free(FREE target) { delete_(target,address_tree); return; }
void LocalStore::destroy() { delete_(&inst()); TlsSetValue(_index, nullptr); }
TileStampsDock::TileStampsDock(TileStampManager *stampManager, QWidget *parent) : QDockWidget(parent) , mTileStampManager(stampManager) , mTileStampModel(stampManager->tileStampModel()) , mNewStamp(new QAction(this)) , mAddVariation(new QAction(this)) , mDelete(new QAction(this)) { setObjectName(QLatin1String("TileStampsDock")); mTileStampView = new TileStampView(this); mTileStampView->setModel(mTileStampModel); mTileStampView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); mTileStampView->header()->setStretchLastSection(false); #if QT_VERSION >= 0x050000 mTileStampView->header()->setSectionResizeMode(0, QHeaderView::Stretch); mTileStampView->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents); #else mTileStampView->header()->setResizeMode(0, QHeaderView::Stretch); mTileStampView->header()->setResizeMode(1, QHeaderView::ResizeToContents); #endif mTileStampView->setContextMenuPolicy(Qt::CustomContextMenu); connect(mTileStampView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenu(QPoint))); mNewStamp->setIcon(QIcon(QLatin1String(":images/16x16/document-new.png"))); mAddVariation->setIcon(QIcon(QLatin1String(":/images/16x16/add.png"))); mDelete->setIcon(QIcon(QLatin1String(":images/16x16/edit-delete.png"))); Utils::setThemeIcon(mNewStamp, "document-new"); Utils::setThemeIcon(mAddVariation, "add"); Utils::setThemeIcon(mDelete, "edit-delete"); connect(mNewStamp, SIGNAL(triggered()), stampManager, SLOT(newStamp())); connect(mAddVariation, SIGNAL(triggered()), SLOT(addVariation())); connect(mDelete, SIGNAL(triggered()), SLOT(delete_())); mDelete->setEnabled(false); mAddVariation->setEnabled(false); QWidget *widget = new QWidget(this); QVBoxLayout *layout = new QVBoxLayout(widget); layout->setMargin(5); QToolBar *buttonContainer = new QToolBar; buttonContainer->setFloatable(false); buttonContainer->setMovable(false); buttonContainer->setIconSize(QSize(16, 16)); buttonContainer->addAction(mNewStamp); buttonContainer->addAction(mAddVariation); buttonContainer->addAction(mDelete); QVBoxLayout *listAndToolBar = new QVBoxLayout; listAndToolBar->setSpacing(0); listAndToolBar->addWidget(mTileStampView); listAndToolBar->addWidget(buttonContainer); layout->addLayout(listAndToolBar); QItemSelectionModel *selectionModel = mTileStampView->selectionModel(); connect(selectionModel, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(currentRowChanged(QModelIndex))); setWidget(widget); retranslateUi(); }
void operator() (T* t) const { delete_(t); }
iterator erase(iterator pos) { auto next = pos->next; delete_(take(pos)); return next; }