Example #1
0
int FileSystem::remove(FileNode* node) {
  if (!write_support) return ENOTSUP;

  // Odstraň všechny synovské uzly
  if (node->type == FileNode::DIR_NODE) {
    while (!node->children.empty()) {
      remove(node->children.front());
    }
  }

  take(node);

  // Smazaný soubor se nachází v archivu
  if (node->data != NULL)
    removed_nodes.push_back(node);
  else
    delete node;

  changed = true;
  return 0;
}
int main(int argc,char *argv[])
{
    poly head1,head2,headadd;
    printf("第一个多项式的创建\n");
    head1 = creat();
    printf("第一个多项式: ");
    print(head1);
    printf("第二个多项式的创建\n");
    head2 = creat();
    printf("第二个多项式: ");
    print(head2);
    printf("多项式的加法\n");
    headadd = add(head1,head2);
    print(headadd);
    printf("多项式的减法\n");
    headadd = minus(head1,head2);
    print(headadd);
    printf("多项式的乘法\n");
    headadd = take(head1,head2);
    print(headadd);
}
Example #3
0
void AIPlayer::makeTurn(Game * g){
	int randPick = rand() % 4;
	if(randPick==0 && this->myHand.getSize()<7){
		//take
		int r= rand() % g->market().getSize();
		take(g, r);
	}
	else if(randPick==1){
		//trade
		trade(g);		//CHECK ONCE ALEX IS DONE
	}
	else if(randPick==2){
		//sell one 
	}
	else if(randPick==3){ //&& check is valid to sell mult){
		//sell multiple 
	}
	else{
		std::cout<<"Error in picking a move"<<std::endl;
	}
}
Example #4
0
void commut(char op)
{
	int x, y;

	take(2);

	x = stack[top];
	y = stack[top + 1];

	if (x == 0)
		printf("%c %s\n", op, fmt[y]);
	else if (y == 0)
		printf("%c %s\n", op, fmt[x]);
	else
		printf("L %s\n%c %s\n", fmt[x], op, fmt[y]);

	use[x] = 0;
	use[y] = 0;

	stack[top++] = 0;
}
Example #5
0
int go(int v)
{
    if(!v)num=0;
    if(v>=81)
    {
        num++;
        return 1;
    }
    int x=v/9,y=v%9;
    if(s[x][y]!='.')
        return go(v+1);
    int i,sum=0,tmp,last=0;
    for(int i=1;num<2 && i<=9;i++)
        if(check(x,y,i))
        {
            put(x,y,i);
            sum+=go(v+1);
            take(x,y,i);
        }
    return sum;
}
Example #6
0
// Return the number of occurrences of the designated object.
size_t UtlSList::occurrencesOf(const UtlContainable* containableToMatch) const
{
   int count = 0;
   UtlLink* listNode;
   UtlContainable* visitNode = NULL;

   OsLock take(mContainerLock);

   LIST_SANITY_CHECK;
   for(listNode = head(); listNode; listNode = listNode->next())
   {
      visitNode = (UtlContainable*)listNode->data;
      if(visitNode && visitNode->compareTo(containableToMatch) == 0)
      {
         count++;
      }
   }
   LIST_SANITY_CHECK;

   return(count);
}
Example #7
0
void sub()
{
	int x, y;

	take(2);

	x = stack[top];
	y = stack[top + 1];

	if (x == 0)
		printf("S %s\n", fmt[y]);
	else if (y == 0)
		printf("N\nA %s\n", fmt[x]);
	else
		printf("L %s\nS %s\n", fmt[x], fmt[y]);

	use[x] = 0;	
	use[y] = 0;

	stack[top++] = 0;
}
Example #8
0
/* =============================================================================
 * FUNCTION: opotion
 *
 * DESCRIPTION:
 * Function to handle finding a potion.
 *
 * PARAMETERS:
 *
 *   pot : The potion type found.
 *
 * RETURN VALUE:
 *
 *   None.
 */
static void opotion(int pot, int ans)
{
  switch(ans)
  {
    case ESC:
    case 'i':
      break;

    case 'd':
      forget(); /*  destroy potion  */
      quaffpotion(pot);
      break;

    case 't':
      if (take(OPOTION,pot)==0)  forget();
      break;

    default:
      break;
  }
}
bool ColorSchemePresets::initialize(const QJsonObject & presets)
{
    static const auto warning = QString("Cannot retrieve color scheme category \"%1\" from Json object: ");

    auto categoryNamesByIndex = QMultiMap<int, QString>();

    static const auto CATEGORY_INDEX = QString{ "index" };

    for (const auto & identifier : presets.keys())
    {
        auto schemes = presets.value(identifier).toObject();
        if (schemes.isEmpty())
        {
            qWarning() << qPrintable(warning.arg(identifier) + "value object is empty.");
            return false;
        }

        if (!schemes.contains(CATEGORY_INDEX))
        {
            qWarning() << qPrintable(warning.arg(identifier) + "value object is missing category index.");
            return false;
        }

        const auto index = schemes.value(CATEGORY_INDEX).toInt();
        categoryNamesByIndex.insertMulti(index, identifier);
    }

    for (const auto index : categoryNamesByIndex.keys())
    {
        for (const auto & identifier : categoryNamesByIndex.values(index))
        {
            auto schemes = presets.value(identifier).toObject();
            schemes.take(CATEGORY_INDEX);

            push_back(new ColorSchemeGroup(identifier, schemes));
        }
    }

    return !isEmpty();
}
Example #10
0
/// ParseINTRINSICStmt - Parse the INTRINSIC statement.
///
///   [R1216]:
///     intrinsic-stmt :=
///         INTRINSIC [::] intrinsic-procedure-name-list
Parser::StmtResult Parser::ParseINTRINSICStmt(bool IsActuallyExternal) {
  // Check if this is an assignment.
  if (IsNextToken(tok::equal))
    return StmtResult();

  auto Loc = ConsumeToken();
  ConsumeIfPresent(tok::coloncolon);

  SmallVector<Stmt *,8> StmtList;

  while(true) {
    auto IDLoc = Tok.getLocation();
    auto II = Tok.getIdentifierInfo();
    if(!ExpectAndConsume(tok::identifier)) {
      if(!SkipUntil(tok::comma, tok::identifier, true, true)) break;
      if(ConsumeIfPresent(tok::comma)) continue;
      else {
        IDLoc = Tok.getLocation();
        II = Tok.getIdentifierInfo();
        ConsumeToken();
      }
    }

    auto Stmt = IsActuallyExternal?
                  Actions.ActOnEXTERNAL(Context, Loc, IDLoc,
                                        II, nullptr):
                  Actions.ActOnINTRINSIC(Context, Loc, IDLoc,
                                         II, nullptr);
    if(Stmt.isUsable())
      StmtList.push_back(Stmt.take());

    if(Tok.isAtStartOfStatement()) break;
    if(!ExpectAndConsume(tok::comma)) {
      if(!SkipUntil(tok::comma)) break;
    }
  }

  return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel);
}
Example #11
0
void UtlHashBag::removeAll()
{
   OsLock take(mContainerLock);

   size_t i;
   size_t toBeRemoved;
   for (i = 0, toBeRemoved = mElements;
        i < numberOfBuckets() && toBeRemoved;
        i++
        ) // for each bucket
   {
      while(!mpBucket[i].isUnLinked()) // bucket is not empty yet
      {
         UtlLink* link = static_cast<UtlLink*>(mpBucket[i].head());
         notifyIteratorsOfRemove(link);
         link->detachFromList(&mpBucket[i]);
         link->release();
         toBeRemoved--;
      }
   }
   mElements = 0;
}
Example #12
0
/**
 * Search for the designated object by reference.
 * @return the object if found, otherwise NULL.
 */
UtlContainable* UtlHashBag::findReference(const UtlContainable* object) const
{
   UtlContainable* found = NULL;

   if (object)
   {
      OsLock take(mContainerLock);

      UtlLink*  link = NULL;
      UtlChain* bucket;
      UtlLink* check;

      // walk the buckets
      for (size_t i = 0; link == NULL && i < numberOfBuckets(); i++)
      {
         bucket = &mpBucket[i];

         for (link = NULL, check = static_cast<UtlLink*>(bucket->listHead());
              (   !link                  // not found
               && check                  // not end of list
                 );
              check = check->next()
            )
         {
            if (check->data == object)
            {
               link = check; // found it
            }
         }
      }

      if (link)
      {
         found = link->data;
      }
   }

   return found;
}
Example #13
0
/// ParseDIMENSIONStmt - Parse the DIMENSION statement.
///
///   [R535]:
///     dimension-stmt :=
///         DIMENSION [::] array-name ( array-spec ) #
///         # [ , array-name ( array-spec ) ] ...
Parser::StmtResult Parser::ParseDIMENSIONStmt() {
  // Check if this is an assignment.
  if (IsNextToken(tok::equal))
    return StmtResult();

  auto Loc = ConsumeToken();
  ConsumeIfPresent(tok::coloncolon);

  SmallVector<Stmt*, 8> StmtList;
  SmallVector<ArraySpec*, 4> Dimensions;
  while (true) {
    auto IDLoc = Tok.getLocation();
    auto II = Tok.getIdentifierInfo();
    if(!ExpectAndConsume(tok::identifier)) {
      if(!SkipUntil(tok::comma, tok::identifier, true, true)) break;
      if(ConsumeIfPresent(tok::comma)) continue;
      else {
        IDLoc = Tok.getLocation();
        II = Tok.getIdentifierInfo();
        ConsumeToken();
      }
    }

    // FIXME: improve error recovery
    Dimensions.clear();
    if(ParseArraySpec(Dimensions)) return StmtError();

    auto Stmt = Actions.ActOnDIMENSION(Context, Loc, IDLoc, II,
                                       Dimensions, nullptr);
    if(Stmt.isUsable()) StmtList.push_back(Stmt.take());

    if(Tok.isAtStartOfStatement()) break;
    if(!ExpectAndConsume(tok::comma)) {
      if(!SkipUntil(tok::comma)) break;
    }
  }

  return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel);
}
Example #14
0
static bool convertToInProjectMidi(RprItemCtrPtr &ctr)
{
    bool hasMidiFile = false;
    for(int i = 0; i < ctr->size(); i++) {
        RprTake take(ctr->getAt(i).getActiveTake());
        if(!take.isMIDI())
            continue;
        if(take.isFile()) {
            hasMidiFile = true;
            break;
        }
    }
    if(hasMidiFile) {
        if(MessageBox(GetMainHwnd(),
            __LOCALIZE("Current selection has takes with MIDI files.\r\nTo apply this action these takes must be converted to in-project takes.\r\nDo you want to continue?","sws_mbox"),
            __LOCALIZE("FNG - Warning","sws_mbox"), MB_YESNO) == IDNO) {
            return false;
        }
        Main_OnCommandEx(40684, 0 , 0);
    }
    return true;
}
Example #15
0
// return the current data
UtlContainable* UtlListIterator::item() const
{
   UtlContainable* currentItem = NULL;

   UtlContainer::acquireIteratorConnectionLock();
   OsLock take(const_cast<OsBSem&>(mContainerRefLock));

   UtlList* myList = dynamic_cast<UtlList*>(mpMyContainer);
   if (myList)
   {
      OsLock container(myList->mContainerLock);
      UtlContainer::releaseIteratorConnectionLock();

      currentItem = static_cast<UtlContainable*>(mpCurrentNode->data);
   }
   else
   {
      UtlContainer::releaseIteratorConnectionLock();
   }   

    return currentItem;
}
Example #16
0
// Is the iterator positioned at the last element? 
UtlBoolean UtlListIterator::atLast() const 
{
   UtlBoolean isAtLast = false;
   
   UtlContainer::acquireIteratorConnectionLock();

   OsLock take(const_cast<OsBSem&>(mContainerRefLock));
   UtlList* myList = dynamic_cast<UtlList*>(mpMyContainer);
   if (myList)
   {
      OsLock container(myList->mContainerLock);
      UtlContainer::releaseIteratorConnectionLock();
      
      isAtLast = (mpCurrentNode && mpCurrentNode == myList->tail());
   }
   else
   {
      UtlContainer::releaseIteratorConnectionLock();
   }   

   return isAtLast;
}       
Example #17
0
UtlContainable* UtlListIterator::toLast() 
{
   UtlContainable* last = NULL;
   
   UtlContainer::acquireIteratorConnectionLock();
   OsLock take(mContainerRefLock);
   UtlList* myList = dynamic_cast<UtlList*>(mpMyContainer);
   if (myList)
   {
      OsLock container(myList->mContainerLock);
      UtlContainer::releaseIteratorConnectionLock();

      mpCurrentNode = myList->tail();
      last = static_cast<UtlContainable*>(mpCurrentNode ? mpCurrentNode->data : NULL);
   }
   else
   {
      UtlContainer::releaseIteratorConnectionLock();
   }   

   return last;
}
Example #18
0
/*
	function to say what object we found and ask if player wants to take it
 */
void finditem(int itm)
{
	int tmp,i;
	lprintf("\n\nYou find %s",objectname[itm]);
	tmp=iarg[playerx][playery];
	switch(itm)
	{
	case ODIAMOND:		
	case ORUBY:			
	case OEMERALD:
	case OSAPPHIRE:		
	case OSPIRITSCARAB:	
	case OORBOFDRAGON:
	case OORB:
	case OHANDofFEAR:
	case OWWAND:
	case OCUBEofUNDEAD:	
	case ONOTHEFT:
		lprcat(".");
		break;

	default:
		if (tmp>0) 
			lprintf(" + %d",(long)tmp); 
		else if (tmp<0) lprintf(" %d",(long)tmp);
	}
	lprcat("\nDo you want to (t) take it"); 
	iopts();
	i=0; 
	while (i!='t' && i!='i' && i!=ESC) i=getcharacter();
	if (i == 't') {	
		lprcat("take.");
		if (take(itm,tmp)==0)  
			forget();	
		return;	
	}
	ignore();
}
Example #19
0
/*
	*******
	OPOTION
	*******

	function to process a potion
 */
void opotion(int pot)
{
	lprcat("\nDo you (d) drink it, (t) take it"); 
	iopts();
	while (1) switch(getcharacter())
	{
	case ESC:
	case 'i':	
		ignore();  
		return;

	case 'd':	
		lprcat("drink.\n");
		forget();	/*	destroy potion	*/
		quaffpotion(pot);		
		return;

	case 't':	
		lprcat("take.\n");
		if (take(OPOTION,pot)==0)  forget();
		return;
	};
}
Example #20
0
/* Finds best solution candidate from neighbourhood. */
SolutionCandidate getBestSolution(std::vector<SolutionCandidate>& neighbourhood, std::vector<TabuItem>& tabuList)
{
	SolutionCandidate bestCandidate = neighbourhood[0];
	float lowestCost = getRoutesLength(bestCandidate.solution);
	int bestCandidateIndex = 0;

	for (int i=1; i<neighbourhood.size(); i++)
	{
		if (getRoutesLength(neighbourhood[i].solution) < lowestCost)
		{
			if (!isTabu(neighbourhood[i], tabuList))
			{
				bestCandidateIndex = i;
				bestCandidate = neighbourhood[i];
				lowestCost = getRoutesLength(bestCandidate.solution);
			}
		}
	}

	take(neighbourhood,bestCandidateIndex);

	return bestCandidate;
}
Example #21
0
// Return the number of occurrences of the designated object.
size_t UtlSortedList::occurrencesOf(const UtlContainable* containableToMatch) const 
{
   int count = 0;
   UtlLink* listNode;
   UtlContainable* visitNode = NULL;
   int             comparison;

   OsLock take(const_cast<OsBSem&>(mContainerLock));
   
   for (listNode = head(), comparison = 0;
        comparison <= 0 && listNode;
        listNode = listNode->next()
        )
   {
      visitNode = (UtlContainable*)listNode->data;
      if(visitNode && visitNode->compareTo(containableToMatch) == 0)
      {
         count++;
      }
   }

   return(count);
}
Example #22
0
// Destructor
UtlHashBag::~UtlHashBag()
{
   UtlContainer::acquireIteratorConnectionLock();
   OsLock take(mContainerLock);

   invalidateIterators();

   UtlContainer::releaseIteratorConnectionLock();

   // still holding the mContainerLock
   // walk the buckets
   for (size_t i = 0; i < numberOfBuckets(); i++)
   {
      // empty each bucket and release each UtlPair back to the pool
      while (!mpBucket[i].isUnLinked())
      {
         UtlLink* link = static_cast<UtlLink*>(mpBucket[i].listHead());
         link->detachFromList(&mpBucket[i]);
         link->release();
      }
   }
   delete [] mpBucket;   // free the bucket headers
}
Example #23
0
uint32_t instruction_extract(struct instruction *inst, unsigned int from,
			     unsigned int to)
{
	unsigned int bits = to - from, i;
	uint32_t value = 0;

	if (to < from || bits > 32) {
		fprintf(stderr, "WARNING: invalid bitfield: %u-%u\n", from,
			to);
		return 0;
	}

	if (to >= inst->length) {
		fprintf(stderr, "WARNING: bit out of range: %u\n", to);
		return 0;
	}

	for (i = from; i <= to; i++)
		if (take(inst, i))
			value |= 1u << (i - from);

	return value;
}
Example #24
0
MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow),
	logic(this),
	connectDialog(new ZeroconfConnectDialog(this)),
	ipConnectDialog(new IPConnectDialog(this))
{
	ui->setupUi(this);

	ui->centralwidget->setClientLogic(&logic);
/*
	connect(connectDialog, SIGNAL(connectedTo(QHostAddress,quint16)),
			this,		   SLOT(newServerConnection(QHostAddress,quint16)));
*/
	connect(ipConnectDialog, SIGNAL(setLocalAddress(QHostAddress)),
			&logic,			 SLOT(setLocalAddress(QHostAddress)));

	connect(ipConnectDialog, SIGNAL(connectedTo(QHostAddress,quint16)),
			this,		   SLOT(newServerConnection(QHostAddress,quint16)));



	connect(ui->centralwidget, SIGNAL(take(QString)),
			this,			   SLOT(takeNode(QString)));

	connect(ui->centralwidget, SIGNAL(give(QString)),
			this,			   SLOT(giveNode(QString)));

	connect(&logic,			   SIGNAL(serverPoolChanged()),
			ui->centralwidget, SLOT(updateServerPool()));

	connect(&logic,			   SIGNAL(localPoolChanged()),
			ui->centralwidget, SLOT(updateLocalPool()));

	connect(&logic,			   SIGNAL(sendLog(QString)),
			ui->centralwidget, SLOT(addLog(QString)));
}
Example #25
0
// Return the list position of the designated object.
size_t UtlSortedList::index(const UtlContainable* obj) const 
{
   size_t          index = UTL_NOT_FOUND;
   size_t          thisIndex;
   UtlLink*        listNode;
   unsigned        keyHash = obj->hash();
   
   OsLock take(const_cast<OsBSem&>(mContainerLock));
   
   for (listNode = head(), thisIndex = 0;
        listNode && index == UTL_NOT_FOUND;
        listNode = listNode->next(), thisIndex++)
   {
      if (   listNode->data                      // there is an object (for safety sake)
          && listNode->hash == keyHash           // quick test for possible equality
          && listNode->data->compareTo(obj) == 0 // real (but slower) test for equality
          )
      {
         index = thisIndex;
      }
   }
    
   return index;
}
Example #26
0
/* =============================================================================
 * FUNCTION: obook
 *
 * DESCRIPTION:
 * Function to process finding a book.
 *
 * PARAMETERS:
 *
 *   None.
 *
 * RETURN VALUE:
 *
 *   None.
 */
void obook(int ans)
{
  switch (ans)
  {
    case ESC:
    case 'i':
      return;

    case 'r':
      if (c[BLINDCOUNT]) break;
      readbook(iarg[playerx][playery]);
      /* no more book */
      forget();
      return;

    case 't':
      if (take(OBOOK,iarg[playerx][playery])==0)
        forget(); /* no more book */
      return;

    default:
      break;
  }
}
Example #27
0
/* =============================================================================
 * FUNCTION: ochest
 *
 * DESCRIPTION:
 * Function to handle finding a chest.
 *
 * PARAMETERS:
 *
 *   None.
 *
 * RETURN VALUE:
 *
 *   None.
 */
void ochest(int ans)
{
  switch (ans)
  {
    case 'o':
      oopenchest();
      break;

    case 't':
      if (take(OCHEST,iarg[playerx][playery])==0)
      {
        item[playerx][playery] = ONOTHING;
      }
      break;

    case 'i':
    case ESC:
      break;

    default:
      break;
  }

}
Example #28
0
void div()
{
	int x, y;

	take(2);

	x = stack[top];
	y = stack[top + 1];

	if (x == 0) {
		printf("D %s\n", fmt[y]);
	} else if (y == 0) {
		/* reg <- x / reg */
		y = store();
		printf("L %s\nD %s\n", fmt[x], fmt[y]);
	} else {
		printf("L %s\nD %s\n", fmt[x], fmt[y]);
	}

	use[x] = 0;	
	use[y] = 0;

	stack[top++] = 0;
}
Example #29
0
void ThreadPool::runInThread() {
	try {
		while (m_bRunning) {
			Task task(take());
			if (task) {
				task();
			}
		}
	} catch (const Exception &except) {
		fprintf(stderr, "exception caught in ThreadPool %s\n", m_StrName.c_str());
		fprintf(stderr, "reason: %s\n", except.what());
		fprintf(stderr, "stack trace: %s\n", except.StackTrace());
		abort();
		
	} catch (const std::exception& except) {
		fprintf(stderr, "exception caught in ThreadPool %s\n", m_StrName.c_str());
		fprintf(stderr, "reason: %s\n", except.what());
		abort();

	} catch (...) {
		fprintf(stderr, "unknown exception caught in ThreadPool %s\n", m_StrName.c_str());
		abort();
	}
}
Example #30
0
UtlContainable* UtlSListIterator::insertAfterPoint(UtlContainable* insertedObject) 
{
   UtlContainable*    result = NULL;

   UtlContainer::acquireIteratorConnectionLock();
   OsLock takeContainer(mContainerRefLock);
   UtlSList* myList = static_cast<UtlSList*>(mpMyContainer);

   OsLock take(myList->mContainerLock);
   UtlContainer::releaseIteratorConnectionLock();

   if (mpCurrentNode == UtlListIterator::OFF_LIST_END)
   {
      mpCurrentNode = UtlLink::listBefore(myList, NULL, insertedObject); /* append to tail */
   }
   else
   {
      UtlLink::listAfter(myList, mpCurrentNode, insertedObject);
   }
   
   result = insertedObject; 
   
   return result;
}