本文整理汇总了C++中discard函数的典型用法代码示例。如果您正苦于以下问题:C++ discard函数的具体用法?C++ discard怎么用?C++ discard使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了discard函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: default_trim
/* Trim zero blocks of the beginning and end of the object. */
static int default_trim(int fd, uint64_t oid, const struct siocb *iocb,
uint64_t *poffset, uint32_t *plen)
{
trim_zero_blocks(iocb->buf, poffset, plen);
if (iocb->offset < *poffset) {
sd_debug("discard between %d, %ld, %" PRIx64, iocb->offset,
*poffset, oid);
if (discard(fd, iocb->offset, *poffset) < 0)
return -1;
}
if (*poffset + *plen < iocb->offset + iocb->length) {
uint64_t end = iocb->offset + iocb->length;
if (end == get_objsize(oid))
/* This is necessary to punch the last block */
end = round_up(end, BLOCK_SIZE);
sd_debug("discard between %ld, %ld, %" PRIx64, *poffset + *plen,
end, oid);
if (discard(fd, *poffset + *plen, end) < 0)
return -1;
}
return 0;
}
开发者ID:DLag,项目名称:sheepdog,代码行数:28,代码来源:plain_store.c
示例2: configstring
const char * configstring (const char * file, const char * part, const char * item, const char * text)
{
FILE *fp;
if (file && part && item) {
if ((fp = fopen (file, "rb"))) {
for (c = getc (fp); c != EOF; discard (fp)) {
while (isblank (c)) {
c = getc (fp);
}
if (c != '[') {
continue;
}
do {
c = getc (fp);
}
while (isblank (c));
if (!compare (fp, part)) {
continue;
}
if (c != ']') {
continue;
}
for (discard (fp); (c != '[') && (c != EOF); discard (fp)) {
while (isblank (c)) {
c = getc (fp);
}
if (c == ';') {
continue;
}
if (!compare (fp, item)) {
continue;
}
if (c != '=') {
continue;
}
do {
c = getc (fp);
}
while (isblank (c));
collect (fp);
text = buffer;
break;
}
break;
}
fclose (fp);
}
}
if (text) {
text = strdup(text);
}
return text;
}
开发者ID:edwacode,项目名称:qca-hostap,代码行数:56,代码来源:config.c
示例3: removeelement
/*
removes an element within the list
data data of the element to find
data_size size of data
//*/
int removeelement(const char* data, const unsigned int data_size)
{
// checks
if(NULL == data) return -1;
// find and delete
element_t* tmp = find(data, data_size);
if(NULL == tmp){
fprintf(stderr, "element \"%s\" not found in list\n", data);
return -1;
}
// element was first
if(tmp == first){
// list only has one element
if(first == last){
// TODO use discard first.. reset elements
return 0;
}
first = first->next;
if(0 != discard(&tmp)){
return -1;
}
tmp = NULL;
return 0;
}
// get prev element
element_t* prev = first;
while(prev->next){
if(prev->next == tmp){
break;
}
}
// next element
element_t* next = prev->next;
if(NULL == next){
return removelastelement();
}
// unlink
prev->next = next;
// delete
if(0 != discard(&tmp)){
return -1;
}
return 0;
}
开发者ID:Rubusch,项目名称:c,代码行数:59,代码来源:sl_list.c
示例4: mpi_plain
inline Checkpoint mpi_plain(
MPI_Comm communicator,
I&& integrand,
std::vector<std::size_t> const& iteration_calls,
Checkpoint chkpt = make_plain_chkpt<numeric_type_of<I>>(),
Callback callback = mpi_callback<Checkpoint>()
) {
using T = numeric_type_of<I>;
int rank = 0;
MPI_Comm_rank(communicator, &rank);
int world = 0;
MPI_Comm_size(communicator, &world);
auto generator = chkpt.generator();
std::vector<T> buffer;
std::size_t const usage = integrand.dimensions() *
random_number_usage<T, decltype (generator)>();
// perform iterations
for (auto calls : iteration_calls)
{
generator.discard(usage * discard_before(calls, rank, world));
// the number of function calls for each MPI process
std::size_t const sub_calls = (calls / world) +
(static_cast <std::size_t> (rank) < (calls % world) ? 1 : 0);
auto const result = plain_iteration(integrand, sub_calls, generator);
generator.discard(usage * discard_after(calls, sub_calls, rank, world));
auto const& new_result = allreduce_result(
communicator,
result,
buffer,
std::vector<T>(),
calls
);
chkpt.add(new_result, generator);
if (!callback(communicator, chkpt))
{
break;
}
}
return chkpt;
}
开发者ID:cschwan,项目名称:hep-mc,代码行数:51,代码来源:mpi_plain.hpp
示例5: fall
/*
* fall:
* Drop an item someplace around here.
*/
int
fall(struct linked_list *item, int pr)
{
register struct object *obj ;
register struct room *rp ;
static coord fpos ;
int ret;
obj = (struct object *) ldata(item) ;
rp = roomin(&hero);
if (obj->o_flags & CANRETURN) {
add_pack(item, TRUE);
return TRUE;
}
else if (fallpos(&obj->o_pos, &fpos, TRUE)) {
if (obj->o_flags & CANBURN && ntraps + 1 < MAXTRAPS + MAXTRAPS) {
mvaddch(fpos.y, fpos.x, FIRETRAP);
traps[ntraps].tr_type = FIRETRAP;
traps[ntraps].tr_flags = ISFOUND;
traps[ntraps].tr_show = FIRETRAP;
traps[ntraps].tr_pos.y = fpos.y;
traps[ntraps++].tr_pos.x = fpos.x;
if (rp != NULL)
rp->r_flags &= ~ISDARK;
discard(item);
ret = FALSE;
}
else {
mvaddch(fpos.y, fpos.x, obj->o_type) ;
obj->o_pos = fpos ;
attach(lvl_obj, item) ;
ret = TRUE;
}
if (rp != NULL &&
(!(rp->r_flags & ISDARK) ||
(rp->r_flags & HASFIRE))) {
light(&hero) ;
mvwaddch(cw, hero.y, hero.x, PLAYER) ;
}
return ret;
}
if (pr) {
if (obj->o_type == WEAPON)
addmsg("The %s", weaps[obj->o_which]);
else
addmsg(inv_name(obj, TRUE));
msg(" vanishes as it hits the ground.");
}
discard(item) ;
return FALSE;
}
开发者ID:RoguelikeRestorationProject,项目名称:urogue1.02,代码行数:55,代码来源:weapons.c
示例6: toplevel
int toplevel(pstate *state) {
UNPACK_STATE();
int found = 0;
while(curr <= eof) {
qscan3('{','[','#');
switch(*curr) {
case '{': discard(); found += new_dict(state); break;
case '[': discard(); found += new_list(state); break;
case '#': discard(); found ++; break;
default: discard(); // EOF
}
}
return found;
}
开发者ID:josephwecker,项目名称:mx,代码行数:14,代码来源:subjson.c
示例7: QToolBar
void WriteMail::init()
{
m_toolbar = new QToolBar(this);
addToolBar(m_toolbar);
m_widgetStack = new QStackedWidget(this);
m_cancelAction = new QAction(Qtmail::icon("cancel"),tr("Close"),this);
connect( m_cancelAction, SIGNAL(triggered()), this, SLOT(discard()) );
addAction(m_cancelAction);
m_draftAction = new QAction(Qtmail::icon("saveToDraft"),tr("Save in drafts"),this);
connect( m_draftAction, SIGNAL(triggered()), this, SLOT(draft()) );
m_draftAction->setWhatsThis( tr("Save this message as a draft.") );
addAction(m_draftAction);
m_sendAction = new QAction(Qtmail::icon("sendmail"),tr("Send"),this);
connect( m_sendAction, SIGNAL(triggered()), this, SLOT(sendStage()) );
m_sendAction->setWhatsThis( tr("Send the message.") );
addAction(m_sendAction);
m_accountSelection = new QComboBox(m_toolbar);
connect( m_accountSelection, SIGNAL(currentIndexChanged(int)), this, SLOT(accountSelectionChanged(int)) );
m_selectComposerWidget = new SelectComposerWidget(this);
m_selectComposerWidget->setObjectName("selectComposer");
connect(m_selectComposerWidget, SIGNAL(selected(QPair<QString,QMailMessage::MessageType>)),
this, SLOT(composerSelected(QPair<QString,QMailMessage::MessageType>)));
connect(m_selectComposerWidget, SIGNAL(cancel()), this, SLOT(discard()));
m_widgetStack->addWidget(m_selectComposerWidget);
setCentralWidget(m_widgetStack);
QMenuBar* mainMenuBar = new QMenuBar();
setMenuBar(mainMenuBar);
QMenu* file = mainMenuBar->addMenu("File");
file->addAction(m_sendAction);
file->addAction(m_draftAction);
file->addSeparator();
file->addAction(m_cancelAction);
m_toolbar->addAction(m_sendAction);
m_toolbar->addAction(m_draftAction);
m_toolbar->addWidget(m_accountSelection);
m_toolbar->addSeparator();
setWindowTitle(tr("Compose"));
setGeometry(0,0,defaultWidth,defaultHeight);
}
开发者ID:qt-labs,项目名称:messagingframework,代码行数:50,代码来源:writemail.cpp
示例8: setVisible
void QQuickDialog::click(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role)
{
setVisible(false);
m_clickedButton = static_cast<StandardButton>(button);
emit buttonClicked();
switch (role) {
case QPlatformDialogHelper::AcceptRole:
emit accept();
break;
case QPlatformDialogHelper::RejectRole:
emit reject();
break;
case QPlatformDialogHelper::DestructiveRole:
emit discard();
break;
case QPlatformDialogHelper::HelpRole:
emit help();
break;
case QPlatformDialogHelper::YesRole:
emit yes();
break;
case QPlatformDialogHelper::NoRole:
emit no();
break;
case QPlatformDialogHelper::ApplyRole:
emit apply();
break;
case QPlatformDialogHelper::ResetRole:
emit reset();
break;
default:
qWarning("unhandled Dialog button %d with role %d", (int)button, (int)role);
}
}
开发者ID:Sagaragrawal,项目名称:2gisqt5android,代码行数:34,代码来源:qquickdialog.cpp
示例9: l
// This one puts some data inside the ring buffer.
void RingBuffer::put(AudioBuffer& buf)
{
std::lock_guard<std::mutex> l(lock_);
const size_t sample_num = buf.frames();
const size_t buffer_size = buffer_.frames();
if (buffer_size == 0)
return;
size_t len = putLength();
if (buffer_size - len < sample_num)
discard(sample_num);
size_t toCopy = sample_num;
// Add more channels if the input buffer holds more channels than the ring.
if (buffer_.channels() < buf.channels())
buffer_.setChannelNum(buf.channels());
size_t in_pos = 0;
size_t pos = endPos_;
while (toCopy) {
size_t block = toCopy;
if (block > buffer_size - pos) // Wrap block around ring ?
block = buffer_size - pos; // Fill in to the end of the buffer
buffer_.copy(buf, block, in_pos, pos);
in_pos += block;
pos = (pos + block) % buffer_size;
toCopy -= block;
}
endPos_ = pos;
not_empty_.notify_all();
}
开发者ID:asadsalman,项目名称:ring-daemon,代码行数:36,代码来源:ringbuffer.cpp
示例10: fall
void
fall(struct linked_list *item, int pr)
{
struct object *obj;
struct room *rp;
static coord fpos;
obj = (struct object *) ldata(item);
if (fallpos(&obj->o_pos, &fpos, TRUE))
{
mvaddrawch(fpos.y, fpos.x, obj->o_type);
obj->o_pos = fpos;
if ((rp = roomin(&hero)) != NULL && !(rp->r_flags & ISDARK))
{
light(&hero);
mvwaddrawch(cw, hero.y, hero.x, PLAYER);
}
attach(lvl_obj, item);
return;
}
if (pr)
if (obj->o_type == WEAPON) /* BUGFUX: Identification trick */
msg("Your %s vanishes as it hits the ground.", w_names[obj->o_which]);
else
msg("%s vanishes as it hits the ground.", inv_name(obj,TRUE));
discard(item);
}
开发者ID:mikeyk730,项目名称:Game-Rogue,代码行数:27,代码来源:weapons.c
示例11: type1crypt
static int
type1crypt(i_ctx_t *i_ctx_p,
int (*proc)(byte *, const byte *, uint, ushort *))
{
os_ptr op = osp;
crypt_state state;
uint ssize;
check_type(op[-2], t_integer);
state = op[-2].value.intval;
if (op[-2].value.intval != state)
return_error(e_rangecheck); /* state value was truncated */
check_read_type(op[-1], t_string);
check_write_type(*op, t_string);
ssize = r_size(op - 1);
if (r_size(op) < ssize)
return_error(e_rangecheck);
discard((*proc)(op->value.bytes, op[-1].value.const_bytes, ssize,
&state)); /* can't fail */
op[-2].value.intval = state;
op[-1] = *op;
r_set_size(op - 1, ssize);
pop(1);
return 0;
}
开发者ID:BorodaZizitopa,项目名称:ghostscript,代码行数:25,代码来源:zmisc1.c
示例12: discard
void EditEnumerationDialog::updateCurrentItem()
{
discard();
auto const item = m_dialog->itemList->currentItem();
if (item != nullptr)
item->setText(m_dialog->currentItem->text());
}
开发者ID:DouglasHeriot,项目名称:ember-plus,代码行数:7,代码来源:EditEnumerationDialog.cpp
示例13: playhand
/*
* playhand:
* Do up one hand of the game
*/
int
playhand(bool mycrib)
{
int deckpos;
werase(Compwin);
wrefresh(Compwin);
werase(Tablewin);
wrefresh(Tablewin);
knownum = 0;
deckpos = deal(mycrib);
sorthand(chand, FULLHAND);
sorthand(phand, FULLHAND);
makeknown(chand, FULLHAND);
prhand(phand, FULLHAND, Playwin, FALSE);
discard(mycrib);
if (cut(mycrib, deckpos))
return TRUE;
if (peg(mycrib))
return TRUE;
werase(Tablewin);
wrefresh(Tablewin);
if (score(mycrib))
return TRUE;
return FALSE;
}
开发者ID:radixo,项目名称:openbsd-src,代码行数:31,代码来源:crib.c
示例14: netfront_destroy_ring
/**
* Destroy descriptor ring
*
* @v netfront Netfront device
* @v ring Descriptor ring
* @v discard Method used to discard outstanding buffer, or NULL
*/
static void netfront_destroy_ring ( struct netfront_nic *netfront,
struct netfront_ring *ring,
void ( * discard ) ( struct io_buffer * ) ){
struct xen_device *xendev = netfront->xendev;
struct xen_hypervisor *xen = xendev->xen;
struct io_buffer *iobuf;
unsigned int id;
/* Flush any outstanding buffers */
while ( ! netfront_ring_is_empty ( ring ) ) {
id = ring->ids[ ring->id_cons & ( ring->count - 1 ) ];
iobuf = netfront_pull ( netfront, ring, id );
if ( discard )
discard ( iobuf );
}
/* Unpublish shared ring reference */
netfront_rm ( netfront, ring->ref_key );
/* Revoke access from shared ring */
xengrant_invalidate ( xen, ring->ref );
/* Free page */
free_dma ( ring->sring.raw, PAGE_SIZE );
ring->sring.raw = NULL;
}
开发者ID:pipcet,项目名称:ipxe,代码行数:33,代码来源:netfront.c
示例15: printd
void qore_program_private::del(ExceptionSink* xsink) {
printd(5, "QoreProgram::del() pgm: %p (base_object: %d)\n", pgm, base_object);
if (thr_init)
thr_init->deref(xsink);
if (base_object) {
deleteThreadData(xsink);
// delete thread local storage key
delete thread_local_storage;
base_object = false;
}
// have to delete global variables first because of destructors.
// method call can be repeated
qore_root_ns_private::clearData(*RootNS, xsink);
// delete all global variables, class static vars and constants
RootNS->deleteData(xsink);
// delete defines
for (dmap_t::iterator i = dmap.begin(), e = dmap.end(); i != e; ++i)
discard(i->second, xsink);
dmap.clear();
// method call can be repeated
sb.del();
//printd(5, "QoreProgram::~QoreProgram() this: %p deleting root ns %p\n", this, RootNS);
delete RootNS;
RootNS = 0;
}
开发者ID:temnoregg,项目名称:qore,代码行数:33,代码来源:QoreProgram.cpp
示例16: fall
void
fall(THING *obj, int pr)
{
PLACE *pp;
coord fpos;
if (fallpos(&obj->o_pos, &fpos))
{
pp = INDEX(fpos.y, fpos.x);
pp->p_ch = obj->o_type;
obj->o_pos = fpos;
if (cansee(fpos.y, fpos.x))
{
if (pp->p_monst != NULL)
pp->p_monst->t_oldch = obj->o_type;
else
mvaddch(fpos.y, fpos.x, obj->o_type);
}
attach(lvl_obj, obj);
return;
}
if (pr)
{
if (has_hit)
{
endmsg();
has_hit = FALSE;
}
msg("the %s vanishes as it hits the ground",
weap_info[obj->o_which].oi_name);
}
discard(obj);
}
开发者ID:RoguelikeRestorationProject,项目名称:rogue5.4,代码行数:33,代码来源:weapons.c
示例17: close
void HttpClient::reset(FXbool forceclose){
if (forceclose)
close();
else
discard();
clear();
}
开发者ID:sophom,项目名称:gogglesmm,代码行数:7,代码来源:ap_http_client.cpp
示例18: discard
void Sprite::copyFrom(const Sprite &sprite) {
discard();
if (sprite._surfacePaletted.pixels) {
_surfacePaletted.copyFrom(sprite._surfacePaletted);
_transparencyMap = new uint8[_surfacePaletted.w * _surfacePaletted.h];
memcpy(_transparencyMap, sprite._transparencyMap, _surfacePaletted.w * _surfacePaletted.h);
}
if (sprite._surfaceTrueColor.pixels)
_surfaceTrueColor.copyFrom(sprite._surfaceTrueColor);
_palette = sprite._palette;
_fileName = sprite._fileName;
_fromCursor = sprite._fromCursor;
_defaultX = sprite._defaultX;
_defaultY = sprite._defaultY;
_feetX = sprite._feetX;
_feetY = sprite._feetY;
_flippedHorizontally = sprite._flippedHorizontally;
_flippedVertically = sprite._flippedVertically;
_scale = sprite._scale;
_scaleInverse = sprite._scaleInverse;
}
开发者ID:DrMcCoy,项目名称:OLDscummvm-darkseed2,代码行数:30,代码来源:sprite.cpp
示例19: checkGreatHall
int checkGreatHall(int player, struct gameState *post)
{
int old_numActions = post->numActions;
struct gameState pre;
memcpy(&pre, post, sizeof(struct gameState));
int r = great_hall(player, post, 0);
//what great_hall is supposed to do
if(pre.deckCount[player] < 1)
{
shuffle( player, &pre);
}
pre.hand[player][pre.handCount[player]] = pre.deck[player][pre.deckCount[player]-1];
pre.handCount[player]++;
pre.deckCount[player]--;
pre.numActions++:
discard(0, player, &pre, 0);
// check if post and pre are the same
if( pre.deckCount[player] == post->deckCount[player])
{
if (pre.handCount[player] == post->handCount[player])
{
if(pre.dicardCount[player] == post->discardCount[player])
{ if(pre.numActions == post->numActions)
{
return 0;
}
}
}
}
return -1;
}
开发者ID:orst-iqbald,项目名称:cs362s15,代码行数:33,代码来源:cardtest4.c
示例20: getBufferSize
gl::Error StreamingIndexBufferInterface::reserveBufferSpace(unsigned int size, GLenum indexType)
{
unsigned int curBufferSize = getBufferSize();
unsigned int writePos = getWritePosition();
if (size > curBufferSize)
{
gl::Error error = setBufferSize(std::max(size, 2 * curBufferSize), indexType);
if (error.isError())
{
return error;
}
setWritePosition(0);
}
else if (writePos + size > curBufferSize || writePos + size < writePos)
{
gl::Error error = discard();
if (error.isError())
{
return error;
}
setWritePosition(0);
}
return gl::Error(GL_NO_ERROR);
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:25,代码来源:IndexBuffer.cpp
注:本文中的discard函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论