Esempio n. 1
0
void insertPriceMenu(Tree tree, Element element, char szParentId[])
{
    NodeT *p;
    p = findId(tree->pRoot, element.szId);
    //the Id already exists
    if (p != NULL)
    {
        printf("DEFINE ERROR: %s already exists\n", element.szId);
        return;
    }
    p = findId(tree->pRoot, szParentId);
    //parent was not found
    if (p == NULL)
    {
        printf("DEFINE ERROR: parent %s not found\n", szParentId);
        return;
    }

    //value into a value
    if (element.cNodeType == 'V' && p->element.cNodeType == 'V' )
    {
        printf("DEFINE ERROR: Inserting value node into a value node\n");
        return;
    }
    //option into an option
    if (element.cNodeType == 'O' && p->element.cNodeType == 'O' )
    {
        printf("DEFINE ERROR: Inserting option node into a option node\n");
        return;
    }
    insertT(tree->pRoot,element,szParentId);
}
Esempio n. 2
0
bool KeyValueTagFilter::p_rebuildCache()
{
	m_KeyId = findId(m_Key);

	m_ValueId = findId(m_Value);

	if (!m_PBI) return true;
	if (m_PBI->isNull()) return false;

	return m_KeyId && m_ValueId;
}
bool CocaSystemTree::moveDown( const coca::INode& node )
{
    wxTreeItemId id = findId( node );
    if ( !id.IsOk() ) { return false; }

    wxTreeItemId parentId = GetItemParent( id );
    if ( !parentId.IsOk() ) { return false; }

    wxTreeItemId nextId = GetNextSibling( id );
    if ( !nextId.IsOk() ) { return false; }

    // ready to move
    bool wasSelected = ( id == GetSelection() );

    Delete( id );
    id = InsertItem( parentId, nextId,
                         EditorTools::getName( node ), EditorTools::getImageIndex( node ),
                         -1, new ItemData( node ) );
    COCA_ASSERT( id.IsOk() );
    SetItemTextColour( id, EditorTools::getTextColour( node ) );

    addChildren( node, id );

    if ( wasSelected ) { SelectItem( id ); }

    return true;
}
NeuralInterface::Interface& NeuralInterface::InterfaceManager::find(std::string name)
{
	int id = findId(name);
	if(id < 0)
		throw std::string("Error. Name not found.");//Normally I don't do this.
	return *interfaces[id];
}
Esempio n. 5
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  main
 *  Description:  
 * =====================================================================================
 */
    int
main ()
{
    int i,n,m,j;
    int idNum,idMax;
    int num[2000][5]={(0,0,0,0,0)};
    int numLook[2000]={0};
    int numOrder[4];
    char ch[5] = "ACME";
    scanf ( "%d %d", &n, &m );
    
    for ( i = 0; i < n; i += 1 ) {
        scanf ( "%d %d %d %d", num[i], num[i]+2, num[i]+3, num[i]+4 );
        num[i][1] = (num[i][4]+num[i][2]+num[i][3])/3;
    }

    for ( i = 0; i < m; i += 1 ) {
        scanf ( "%d", &numLook[i] );
        idNum = findId(num,numLook[i], n);
        if(idNum == -1)
            printf ( "N/A\n" );
        else
        {
            
            for ( j = 1; j < 5; j += 1 ) {
                numOrder[j-1] = calOrder(num,idNum, j, n);
            }
            idMax = calMax(numOrder);
           printf ( "%d %c\n",numOrder[idMax], ch[idMax] );
        }

    }
    return EXIT_SUCCESS;
}				/* ----------  end of function main  ----------*/
Esempio n. 6
0
NodeT *insertT(NodeT *pRoot,Element value,char szSubId[])
{
    // p contains the root's ID
    NodeT *p = findId(pRoot,szSubId);

    if (p == NULL)
        return NULL;
    
    //if child is not null, traverses sibling chain until null is found
    if (p->pChild != NULL)
    {
        p = p->pChild;
        while (p->pSibling != NULL)
            p = p->pSibling;

        //sticks node on the end of the sibling chain
        p->pSibling = allocateNodeT(value);
        return p->pSibling;
    }

    //parent node is found and child is empty
    else
    {
        p->pChild = allocateNodeT(value);
        return p->pChild;
    }

    return NULL;
}
Esempio n. 7
0
void EnergyTracker::add(const Real& val, const std::string& name, int &id, int flg){
	// if ZeroDontCreate is set, the value is zero and no such energy exists, it will not be created and id will be still negative
	if(id<0) findId(name,id,flg,/*newIfNotFound*/!(val==0. && (flg&ZeroDontCreate)));
	if(id>=0){
		if(isnan(val)){ LOG_WARN("Ignoring attempt to add NaN to energy '"<<name<<"'."); return; }
		energies.add(id,val);
	}
}
Esempio n. 8
0
void KeyMultiValueTagFilter::addValue(const std::string & value)
{
	m_ValueSet.insert(value);

	uint32_t valueId = findId(value);

	if (valueId)
		m_IdSet.insert(valueId);
}
Esempio n. 9
0
    /** Accept's handler. */
    void Network::acceptHandler(const ClientSPtr &client, const boost::system::error_code &ec, ev_executer_arg(acceptClient))
    {
        if (ec) BOOST_THROW_EXCEPTION(boost::system::system_error(ec));

        client->setId(findId());
        clients.insert(ClientMap::value_type(client->getId(), client));

        execute_event(clientConnected)(client->getId());
    }
Esempio n. 10
0
File: filter.cpp Progetto: 8enny/OSM
bool KeyOnlyTagFilter::rebuildCache()
{
	m_KeyId = findId(m_Key);
	m_KeyIdIsDirty = false;

	if (!m_PBI) return true;
	if (m_PBI->isNull()) return false;

	return  m_KeyId;
}
Esempio n. 11
0
/****************************** printOne **********************************
 void printOne(Tree tree, char szId[])
 Purpose:
    Prints specific attributes of a node.
        -   szTitle
        -   dCost
 Parameters:
 I      Tree tree       Struct containing the Root and Nodes of a tree
 IO     char szId[]     Element Identification
 Returns:
 N/A
**************************************************************************/
void printOne(Tree tree, char szId[])
{
    NodeT *p = findId(tree->pRoot,szId);
    if (p == NULL)
        printf("PRINT ERROR: Id %s not found\n", szId);
    else
        printf("\nTitle: %s\nCost: %.2lf\n"
                ,p->element.szTitle
                ,p->element.dCost);
}
int NeuralInterface::InterfaceManager::remove(std::string name)
{
	int result = findId(name);
	if(result < 0)
		return -1;
	delete interfaces[result];

	interfaces.erase(interfaces.begin() + result);
	names.erase(names.begin() + result);
}
Esempio n. 13
0
bool KeyMultiValueTagFilter::p_rebuildCache()
{
	m_KeyId = findId(m_Key);

	updateValueIds();

	if (!m_PBI) return true;
	if (m_PBI->isNull()) return false;

	return m_KeyId && m_IdSet.size();
}
Esempio n. 14
0
 int IptcData::add(const Iptcdatum& iptcDatum)
 {
     if (!IptcDataSets::dataSetRepeatable(
            iptcDatum.tag(), iptcDatum.record()) &&
            findId(iptcDatum.tag(), iptcDatum.record()) != end()) {
          return 6;
     }
     // allow duplicates
     iptcMetadata_.push_back(iptcDatum);
     return 0;
 }
Esempio n. 15
0
File: filter.cpp Progetto: 8enny/OSM
bool IntTagFilter::rebuildCache()
{
	m_KeyId = findId(m_Key);
	m_KeyIdIsDirty = false;

	findValueId();

	if (!m_PBI) return true;
	if (m_PBI->isNull()) return false;

	return m_KeyId && m_ValueId;
}
int NeuralInterface::InterfaceManager::add(std::string name, int* dimensionSize, int size)
{
	//int size = interfaces.size();
	//if name alread exist
	int result = findId(name);
	if(result >= 0)
		return -1;

	interfaces.push_back(new Interface(dimensionSize,size));
	names.push_back(name);
	return 1;
}
void TemplightEntryPrinter::readBlacklists(const std::string& BLFilename) {
  if ( BLFilename.empty() ) {
    CoRegex.reset();
    IdRegex.reset();
    return;
  }
  
  std::string CoPattern, IdPattern;
  
  llvm::ErrorOr< std::unique_ptr<llvm::MemoryBuffer> >
    file_epbuf = llvm::MemoryBuffer::getFile(llvm::Twine(BLFilename));
  if(!file_epbuf || (!file_epbuf.get())) {
    llvm::errs() << "Error: [Templight-Action] Could not open the blacklist file!\n";
    CoRegex.reset();
    IdRegex.reset();
    return;
  }
  
  llvm::Regex findCo("^context ");
  llvm::Regex findId("^identifier ");
  
  const char* it      = file_epbuf.get()->getBufferStart();
  const char* it_mark = file_epbuf.get()->getBufferStart();
  const char* it_end  = file_epbuf.get()->getBufferEnd();
  
  while( it_mark != it_end ) {
    it_mark = std::find(it, it_end, '\n');
    if(*(it_mark-1) == '\r')
      --it_mark;
    llvm::StringRef curLine(&(*it), it_mark - it);
    if( findCo.match(curLine) ) {
      if(!CoPattern.empty())
        CoPattern += '|';
      CoPattern += '(';
      CoPattern.append(&(*(it+8)), it_mark - it - 8);
      CoPattern += ')';
    } else if( findId.match(curLine) ) {
      if(!IdPattern.empty())
        IdPattern += '|';
      IdPattern += '(';
      IdPattern.append(&(*(it+11)), it_mark - it - 11);
      IdPattern += ')';
    }
    while( (it_mark != it_end) && 
           ((*it_mark == '\n') || (*it_mark == '\r')) )
      ++it_mark;
    it = it_mark;
  }
  
  CoRegex.reset(new llvm::Regex(CoPattern));
  IdRegex.reset(new llvm::Regex(IdPattern));
  return;
}
Esempio n. 18
0
/******************************* findId ***********************************
 NodeT *findId(NodeT *p, char szId[])
 Purpose:
    Recursively going through the tree to find the specific Id we are looking for.
 Parameters:
    NodeT *p        Node that is being Id searched.
    char szId[]     Character array containing the Id we are searching
                        for.
 Returns:
    Returns the child we are looking that has the specified Id.
 **************************************************************************/
NodeT *findId(NodeT *p, char szId[])
{
    NodeT *pFound = NULL;
    //base case
    if (p == NULL)
        return NULL;

    //szId is found
    if (strcmp(p->element.szId,szId)==0)
        return p;

    //iterate through the rest of the tree
    if (p->pSibling != NULL)
        pFound = findId(p->pSibling, szId);
    if (pFound != NULL)
        return pFound;
    if (p->pChild != NULL)
        pFound =findId(p->pChild, szId);

    return pFound;
}
Esempio n. 19
0
void KeyMultiValueTagFilter::updateValueIds()
{
	m_IdSet.clear();

	uint32_t valueId = 0;
	for (ValueSet::const_iterator it = m_ValueSet.cbegin(); it != m_ValueSet.cend(); ++it)
	{
		valueId = findId(*it);

		if (valueId)
			m_IdSet.insert(valueId);
	}
}
Esempio n. 20
0
bool CocaSystemTree::selectNode( const coca::INode& node )
{
    if ( &node == getSelectedNode() ) { return true; }

    wxTreeItemId id = findId( node );
    if ( id.IsOk() )
    {
        SelectItem( id );
        EnsureVisible( id );
    }

    return id.IsOk();
}
Esempio n. 21
0
/******************** findId ****************************************
 NodeT *findId(NodeT *p, char szId[])
 Purpose: Finds and returns a pointer to the requested location based on element type

 Parameters:
 I/O     NodeT *p                Pointer to node for requested Id.
 I       char szId[]             Element to be compared

 Returns:
 p       Returns a pointer to the node of the requested item

 Notes:
 -Will traverse entire tree if necessary.
 **************************************************************************/
NodeT *findId(NodeT *p, char szId[])
{
    //temp NodeT to not over write pointer
    NodeT *pFound = NULL;

    //base case
    if (p == NULL)
        return NULL;

    //if element is found, return node
    if(strcmp(p->element.szId,szId)== 0)
        return p;

    //recurse through the tree to find the element
    //search for element in the children
    pFound = findId(p->pChild, szId);

    if (pFound != NULL)
        return pFound;

    //search through the siblings
    pFound = findId(p->pSibling, szId);
    return pFound;
}
Esempio n. 22
0
void
AccountList::performRefresh()
{
    bool showInactive = _inactive->isChecked();
    Id account_id = currentId();
    QListViewItem* current = NULL;
    clearLists();

    AccountSelect conditions;
    conditions.activeOnly = !showInactive;
    _quasar->db()->selectChart(_accounts, conditions);

    Company company;
    _quasar->db()->lookup(company);

    QDate date = QDate::currentDate();
    _quasar->db()->accountBalances(date, _account_ids, _balances);

    ListViewItem* after = NULL;
    for (unsigned int i = 0; i < _accounts.size(); ++i) {
	const Account& account = _accounts[i];
	fixed balance = getBalance(account);

	AccountListItem* lvi = NULL;
	if (account.parentId() == INVALID_ID) {
	    lvi = new AccountListItem(_list, after, account.id());
	    after = lvi;
	} else {
	    AccountListItem* li = (AccountListItem*)findId(account.parentId());
	    assert(li != NULL);
	    lvi = new AccountListItem(li, li->after, account.id());
	    li->after = lvi;
	}

	lvi->setValue(0, account.name());
	lvi->setValue(1, account.number());
	lvi->setValue(2, account.typeName());
	lvi->setValue(3, balance);
	if (showInactive) lvi->setValue(4, !account.isActive());
	lvi->setOpen(true);
	if (account.id() == account_id) current = lvi;
    }

    if (current == NULL) current = _list->firstChild();

    _list->setCurrentItem(current);
    _list->setSelected(current, true);
}
Esempio n. 23
0
wxTreeItemId CocaSystemTree::findId( const void* nodePointer, wxTreeItemId id ) const
{
    if ( !id.IsOk() ) { return id; }

    if ( nodePointer == getNode( id ) ) { return id; }

    wxTreeItemIdValue cookie = 0;
    id = GetFirstChild( id, cookie );
    for ( ; id.IsOk(); id = GetNextSibling( id ) )
    {
        wxTreeItemId foundId = findId( nodePointer, id );
        if ( foundId.IsOk() ) { return foundId; }
    }

    return id; // is invalid
}
void SELMainLibraryWidget::emitIdGetData(QListWidgetItem * item)
{
    EntertainmentItem * eItem;
    unsigned long long id;
    unsigned long long itemType;
    
    id = findId(item);
    if (id > 0) {
        eItem = controller.retrieveItem(id, itemType);
        if (eItem != 0) {
            updateItemInfo(*eItem, itemType);
            delete eItem;
        }
    } else {
        Error::raiseError(Error::ERROR_ITEM_ID_NOT_FOUND);
    }
}
Esempio n. 25
0
bool CocaSystemTree::removeNode( const void* nodePointer )
{
    wxTreeItemId id = findId( nodePointer );
    if ( !id.IsOk() ) { return false; }

    wxTreeItemId parentId;
    if ( id == GetSelection() ) { parentId = GetItemParent( id ); }

    Delete( id );

    if ( parentId.IsOk() )
    {
        SelectItem( parentId );
        EnsureVisible( parentId );
    }

    return true;
}
Esempio n. 26
0
wxTreeItemId CocaSystemTree::add( const coca::INode& node, bool select )
{
    wxTreeItemId id;
    const coca::INode* parent = node.getParent();
    if ( !parent ) { return id; }

    id = findId( *parent );
    if ( !id.IsOk() ) { return id; }

    id = add( node, id );

    if ( select )
    {
        SelectItem( id );
        EnsureVisible( id );
    }

    return id;
}
void SELMainLibraryWidget::tryAddToLibrary()
{
    QList<QListWidgetItem *> selectedItems = libraryListWidget->selectedItems();
    EntertainmentItem * item;
    unsigned long long id, itemType;
    int size = selectedItems.size();
    
    if (size == 1) {
        id = findId(selectedItems[0]);
        item = controller.retrieveItem(id, itemType);
        if (item != 0) {
            showAddItemConfirmDialog(item);
            delete item;
        }
    } else if (size > 1) {
        Error::raiseError(Error::ERROR_ITEM_SELECTION_ERROR);
    } else {
        Error::raiseError(Error::ERROR_NO_ITEM_SELECTED);
    }
}
void ProcessingPipeline::upClicked( int id )
{
	if( !isVeryTopElement( id ) )
	{
		int actualID = findId( currentProcessingStepOrder, id );
		int oneButtonUpID = actualID - 1;
		std::swap( currentProcessingStepOrder[ actualID ], currentProcessingStepOrder[ oneButtonUpID ] );
		actualID = getActualID( actualID );
		oneButtonUpID = getActualID( oneButtonUpID );
		// swap the down button positions
		QPushButton * clickedButtonDown = processingPipelineConfigWidget->getDownButtonById( actualID );
		QRect tempPosDown = clickedButtonDown->geometry();
		QPushButton * toSwapWithButtonDown = processingPipelineConfigWidget->getDownButtonById( oneButtonUpID );
		clickedButtonDown->setGeometry( toSwapWithButtonDown->geometry() );
		toSwapWithButtonDown->setGeometry( tempPosDown );
		// swap the up button position
		QPushButton * clickedButtonUp = processingPipelineConfigWidget->getUpButtonByID( actualID );
		QRect tempPosUp = clickedButtonUp->geometry();
		QPushButton * toSwapWithButtonUp = processingPipelineConfigWidget->getUpButtonByID( oneButtonUpID );
		clickedButtonUp->setGeometry( toSwapWithButtonUp->geometry() );
		toSwapWithButtonUp->setGeometry( tempPosUp );
		// swap labels
		QLabel * clickedLabel = processingPipelineConfigWidget->getLabelByID( actualID );
		QRect tempPosLabel = clickedLabel->geometry();
		QLabel * toSwapWithLabel = processingPipelineConfigWidget->getLabelByID( oneButtonUpID );
		clickedLabel->setGeometry( toSwapWithLabel->geometry() );
		toSwapWithLabel->setGeometry( tempPosLabel );
		// config button
		QPushButton * clickedButtonConfig = processingPipelineConfigWidget->getConfigButtonByID( actualID );
		QRect tempPosConfig = clickedButtonConfig->geometry();
		QPushButton * toSwapWithButtonConfig = processingPipelineConfigWidget->getConfigButtonByID( oneButtonUpID );
		clickedButtonConfig->setGeometry( toSwapWithButtonConfig->geometry() );
		toSwapWithButtonConfig->setGeometry( tempPosConfig );
		// checkbox
		QCheckBox * clickedCheckBox = processingPipelineConfigWidget->getCheckBoxByID( actualID );
		QRect tempPosCheckbox = clickedCheckBox->geometry();
		QCheckBox * toSwapWithCheckbox = processingPipelineConfigWidget->getCheckBoxByID( oneButtonUpID );
		clickedCheckBox->setGeometry( toSwapWithCheckbox->geometry() );
		toSwapWithCheckbox->setGeometry( tempPosCheckbox );
	}
}
void SELMainLibraryWidget::setupRequestDialog()
{
    QList<QListWidgetItem *> selectedItems = libraryListWidget->selectedItems();
    OwnedItem * items = 0;
    unsigned long long id;
    int numItems, size = selectedItems.size();
    
    if (size == 1) {
        id = findId(selectedItems[0]);
        /// @todo   Prevent member from receiving a loan twice.
        items = controller.retrieveOwners(id, numItems);
        if (items != 0) {
            showRequestDialog(id, items, numItems);
            delete [] items;
        } else if (numItems == 0) {
            Error::raiseError(Error::ERROR_NO_USER_OWNS);
        }
    } else if (size > 1) {
        Error::raiseError(Error::ERROR_ITEM_SELECTION_ERROR);
    } else {
        Error::raiseError(Error::ERROR_NO_ITEM_SELECTED);
    }
}
NeuralInterface::Interface* NeuralInterface::InterfaceManager::findPtr(std::string name)
{
	int id = findId(name);
	return (id < 0 ? NULL : interfaces[id]);
}