Ejemplo n.º 1
0
bool BinarySearchTree<T>::addRecursive(T data, BinaryTreeNode<T> *node){
    BinaryTreeNode<T> *n = new BinaryTreeNode<T>(data);
    if(node){
        //add to left
        if(node->getData() > data){

            if(node->getLeft()) {
                addRecursive(data, node->getLeft());
            }
            else{
                node->setLeft(n);
            }
        }

            //add to right
        else if(node->getData() < data){

            if(node->getRight()) {
                addRecursive(data, node->getRight());
            }
            else{
                node->setRight(n);
            }
        }

        else{
            std::cout << "Error! We do not yet support duplicate entries" << std::endl;
        }
    }

    else{
        std::cout << "At the end, weird error" << std::endl;
        return node;
    }
}
Ejemplo n.º 2
0
bool addRecursive(CuckooMap* map, uint64_t key, uint64_t value, int depth)
{
	if(depth > MAX_LOOP)
	{
		return false;
	}
	//if its empty in the first table, add it there
	if(getKey1(map, key) == NONE)
	{
		set1(map, key, value);
	}
	//if its empty in the second table, add it there
	else if(getKey2(map, key) == NONE)
	{
		set2(map, key, value);
	}
	//if both are occupied, randomly displace one and re-add the displaced one
	else if((xorshf96() & 1) == 0)
	{
		uint64_t pushedKey = getKey1(map, key);
		uint64_t pushedValue = getValue1(map, key);
		set1(map, key, value);
		return addRecursive(map, pushedKey, pushedValue, depth + 1);
	}
	else
	{
		uint64_t pushedKey = getKey2(map, key);
		uint64_t pushedValue = getValue2(map, key);
		set2(map, key, value);
		return addRecursive(map, pushedKey, pushedValue, depth + 1);
	}
	return true;
}
Ejemplo n.º 3
0
GtkTreeIter* 
EntityClassTreePopulator::addRecursive(const std::string& pathName)
{
    // Lookup pathname in map, and return the GtkTreeIter* if it is
    // found
    DirIterMap::iterator iTemp = _dirIterMap.find(pathName);
    if (iTemp != _dirIterMap.end()) { // found in map
        return iTemp->second;
    }
    
    // Split the path into "this directory" and the parent path
    std::size_t slashPos = pathName.rfind("/");
    const std::string parentPath = pathName.substr(0, slashPos);
    const std::string thisDir = pathName.substr(slashPos + 1);

    // Recursively add parent path
    GtkTreeIter* parIter = NULL;
    if (slashPos != std::string::npos)
        parIter = addRecursive(parentPath);

    // Now add "this directory" as a child, saving the iter in the map
    // and returning it.
    GtkTreeIter iter;
    gtk_tree_store_append(_store, &iter, parIter);
    gtk_tree_store_set(_store, &iter, 
                       NAME_COLUMN, thisDir.c_str(),
                       ICON_COLUMN, GlobalUIManager().getLocalPixbuf(FOLDER_ICON),
                       DIR_FLAG_COLUMN, TRUE,
                       -1);
    GtkTreeIter* dynIter = gtk_tree_iter_copy(&iter); // get a heap-allocated iter
    
    // Cache the dynamic iter and return it
    _dirIterMap[pathName] = dynIter;
    return dynIter;
}
Ejemplo n.º 4
0
/**
 * @brief RsCollectionDialog::eventFilter: Proccess event in object
 * @param obj: object where event occured
 * @param event: event occured
 * @return If we don't have to process event in parent.
 */
bool RsCollectionDialog::eventFilter(QObject *obj, QEvent *event)
{
	if (obj == ui._fileEntriesTW) {
		if (event->type() == QEvent::KeyPress) {
			QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
			if (keyEvent && (keyEvent->key() == Qt::Key_Space)) {
				// Space pressed

				// get state of current item
				QTreeWidgetItem *item = ui._fileEntriesTW->currentItem();
				if (item) {
					Qt::CheckState checkState = (item->checkState(COLUMN_FILE) == Qt::Checked) ? Qt::Unchecked : Qt::Checked;

					// set state of all selected items
					QList<QTreeWidgetItem*> selectedItems = ui._fileEntriesTW->selectedItems();
					QList<QTreeWidgetItem*>::iterator it;
					for (it = selectedItems.begin(); it != selectedItems.end(); ++it) {
						if ((*it)->checkState(COLUMN_FILE) != checkState)
							(*it)->setCheckState(COLUMN_FILE, checkState);
					}//for (it
				}//if (item)

				return true; // eat event
			}//if (keyEvent && keyEvent->key() == Qt::Key_Space)

			if (keyEvent && (keyEvent->key() == Qt::Key_Delete)) {
				// Delete pressed
				remove();
				return true; // eat event
			}//if (keyEvent && keyEvent->key() == Qt::Key_Delete)

			if (keyEvent && (keyEvent->key() == Qt::Key_Plus)) {
				// Plus pressed
				makeDir();
				return true; // eat event
			}//if (keyEvent && keyEvent->key() == Qt::Key_Plus)

		}//if (event->type() == QEvent::KeyPress)
	}//if (obj == ui._fileEntriesTW)

	if (obj == ui._systemFileTW) {
		if (event->type() == QEvent::KeyPress) {
			QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
			if (keyEvent && ((keyEvent->key() == Qt::Key_Enter)
			                 || keyEvent->key() == Qt::Key_Return)) {
				// Enter pressed
				if (keyEvent->modifiers() == Qt::ShiftModifier)
					addRecursive();
				else if(keyEvent->modifiers() == Qt::NoModifier) {
					add();
				}

				return true; // eat event
			}//if (keyEvent && keyEvent->key() == Qt::Key_Enter...
		}//if (event->type() == QEvent::KeyPress)
	}//if (obj == ui._systemFileTW)

	// pass the event on to the parent class
	return QDialog::eventFilter(obj, event);
}
Ejemplo n.º 5
0
unsigned int VFSDirZip::load(bool /*ignored*/)
{
    close();

    if(!zip_reader_init_vfsfile(&_zip, _zf, 0))
        return 0;

    unsigned int files = mz_zip_reader_get_num_files(&_zip);

    mz_zip_archive_file_stat fs;
    for (unsigned int i = 0; i < files; ++i)
    {
        // FIXME: do we want empty dirs in the tree?
        if(mz_zip_reader_is_file_a_directory(&_zip, i))
            continue;
        if(mz_zip_reader_is_file_encrypted(&_zip, i))
            continue;
        if(!mz_zip_reader_file_stat(&_zip, i, &fs))
            continue;
        if(getFile(fs.m_filename))
            continue;

        VFSFileZip *vf = new VFSFileZip(&_zip);
        vf->_setOrigin(this);
        memcpy(vf->getZipFileStat(), &fs, sizeof(mz_zip_archive_file_stat));
        vf->_init();
        addRecursive(vf, true, VFSDir::NONE);
        vf->ref--;
    }

    // Not necessary to keep open all the time, VFSFileZip will re-open the archive if needed
    //close();

    return files;
}
Ejemplo n.º 6
0
bool BinarySearchTree<T>::add(T data){
    BinaryTreeNode<T> *node = new BinaryTreeNode<T>(data);
    if(!root){
        root = node;
    }
        //recursive case
    else{
        addRecursive(data, root);
    }
};
Ejemplo n.º 7
0
// Add the display folder for the given entity class
GtkTreeIter* EntityClassTreePopulator::addDisplayFolder(IEntityClassPtr e) {

    // Get the parent folder from the entity class (which may be blank). We
    // prepend this with the entity class' mod name, to ensure that top-level
    // directories are created for each mod
    std::string folderPath = e->getAttribute(_folderKey).value;
    if (!folderPath.empty())
        folderPath = "/" + folderPath;
    
    std::string parentFolder = e->getModName() + folderPath;
       
    // Call the recursive function to add the folder
    return addRecursive(parentFolder);
}
Ejemplo n.º 8
0
// Dato un elenco di file e cartelle, viene espanso in modo da
// contenere tutti i file e le cartelle contenuti
QStringList* DuktoProtocol::expandTree(QStringList files)
{
    // Percorso base
    QString bp = files.at(0);
    if (bp.right(1) == "/") bp.chop(1);
    mBasePath = QFileInfo(bp).absolutePath();
    if (mBasePath.right(1) == "/") mBasePath.chop(1);

    // Iterazione sugli elementi
    QStringList* expanded = new QStringList();
    for (int i = 0; i < files.count(); i++)
        addRecursive(expanded, files.at(i));

    return expanded;
}
Ejemplo n.º 9
0
// Dato un elenco di file e cartelle, viene espanso in modo da
// contenere tutti i file e le cartelle contenuti
QStringList DuktoProtocol::expandTree(const QStringList& files)
{
    // Percorso base
    QString bp = files.first();
    if (bp.right(1) == "/") bp.chop(1);
    mBasePath = QFileInfo(bp).absolutePath();
    if (mBasePath.right(1) == "/") mBasePath.chop(1);

    // Iterazione sugli elementi
    QStringList expanded;
    for(QStringList::const_iterator iter = files.constBegin(); iter != files.constEnd(); ++iter)
        addRecursive(expanded, *iter);

    return expanded;
}
Ejemplo n.º 10
0
// Aggiunge ricorsivamente tutte le cartelle e file contenuti in una cartella
void DuktoProtocol::addRecursive(QStringList& e, QString path)
{
    path.replace("//", "/");
    path.replace("\\", "/");
    if (path.right(1) == "/") path.chop(1);
    e.append(path);

    QString tempPath = path + "/";
    if (QFileInfo(path).isDir())
    {
        QStringList entries = QDir(path).entryList(QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
        for(QStringList::const_iterator iter = entries.constBegin(); iter != entries.constEnd(); ++iter)
            addRecursive(e, tempPath + *iter);
    }
}
Ejemplo n.º 11
0
// Aggiunge ricorsivamente tutte le cartelle e file contenuti in una cartella
void DuktoProtocol::addRecursive(QStringList *e, QString path)
{

    path.replace("//", "/");
    path.replace("\\", "/");
    if (path.right(1) == "/") path.chop(1);
    e->append(path);

    QFileInfo fi(path);
    if (fi.isDir())
    {
        QStringList entries = QDir(path).entryList(QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
        for (int i = 0; i < entries.count(); i++)
            addRecursive(e, path + "/" + entries.at(i));
    }
}
Ejemplo n.º 12
0
/// Add a top-level term.  It invokes ibis::selectClause::addRecursive to
/// do the actual work.  The final expression returned by addRecursive is
/// added to  xtms_.
void ibis::selectClause::addTerm(ibis::math::term *tm, const std::string* al) {
    if (tm == 0) return;
    ibis::math::term *xtm = addRecursive(tm);
    if (xtm != 0) {
        if (al != 0 && !al->empty())
            xalias_[*al] = xtms_.size();
        xtms_.push_back(xtm);
    }
    else {
        LOGGER(ibis::gVerbose >= 0)
            << "Warning -- selectClause::addTerm(" << *tm
            << ") encountered an ill-formed arithmetic expression";
        throw "selectClause encountered an ill-formed expression"
            IBIS_FILE_LINE;
    }
} // ibis::selectClause::addTerm
Ejemplo n.º 13
0
void StateTreeNode::add(AbstractState *state){
	TBTKAssert(
		state->getCoordinates().size() == center.size(),
		"StateTreeNode::add()",
		"Incompatible dimenstions. The StateTreeNode has stores states"
		<< " with dimension '" << center.size() << "', but a state"
		<< " with dimension '" << state->getCoordinates().size() << "'"
		<< " was encountered.",
		""
	);

	if(!addRecursive(state)){
		const vector<double> &stateCoordinates = state->getCoordinates();

		stringstream centerStr;
		centerStr << "{";
		for(unsigned int n = 0; n < center.size(); n++){
			if(n != 0)
				centerStr << ", ";
			centerStr << center.at(n);
		}
		centerStr << "}";

		stringstream stateStr;
		stateStr << "{";
		for(unsigned int n = 0; n < stateCoordinates.size(); n++){
			if(n != 0)
				stateStr << ", ";
			stateStr << stateCoordinates.at(n);
		}
		stateStr << "}";

		TBTKExit(
			"StateTreeNode::add()",
			"Unable to add state to state tree. The StateTreeNode"
			<< " center is '" << centerStr.str() << "' and the"
			<< " half size is '" << halfSize << "'. Tried to add"
			<< " State with coordinate '" << stateStr.str()
			<< "' and extent '" << state->getExtent() << "'.",
			"Make sure the StateTreeNode is large enough to"
			<< " contain every state with finite extent."
		);
	}
}
Ejemplo n.º 14
0
// Aggiunge ricorsivamente tutte le cartelle e file contenuti in una cartella
void DuktoProtocol::addRecursive(QStringList *e, QString path)
{

    path.replace("//", "/");
    if (path.right(1) == "/") path.chop(1);
    e->append(path);

    QFileInfo fi(path);
    if (fi.isDir())
    {
        QStringList entries = QDir(path).entryList();
        for (int i = 0; i < entries.count(); i++)
        {
            QString entry = entries.at(i);
            if ((entry != ".") && (entry != ".."))
                addRecursive(e, path + "/" + entry);
        }
    }
}
Ejemplo n.º 15
0
inline void cgfxVaryingParameter::addRecursive(
    CGparameter parameter,
    cgfxVaryingParameter**& nextParameter
)
{
	if( cgGetParameterVariability( parameter) == CG_VARYING)
	{
		if( cgGetParameterType( parameter) == CG_STRUCT)
		{
			CGparameter input = cgGetFirstStructParameter( parameter);
			while( input)
			{
				addRecursive( input, nextParameter);
				input = cgGetNextParameter( input);
			}
		}
		else if( cgIsParameterReferenced( parameter))
		{
			*nextParameter = new cgfxVaryingParameter( parameter);
			nextParameter = &(*nextParameter)->fNext;
		}
	}
}
Ejemplo n.º 16
0
/**
 * @brief RsCollectionDialog::add:  */
void RsCollectionDialog::add()
{
	addRecursive(false);
}
Ejemplo n.º 17
0
bool add(CuckooMap* map, uint64_t key, uint64_t value)
{
	return addRecursive(map, key, value, 0);
}
Ejemplo n.º 18
0
/**
 * @brief RsCollectionDialog::addRecursive:
 */
void RsCollectionDialog::addRecursive()
{
	addRecursive(true);
}
Ejemplo n.º 19
0
/**
 * @brief RsCollectionDialog::RsCollectionDialog
 * @param collectionFileName: Filename of RSCollection saved
 * @param colFileInfos: Vector of ColFileInfo to be add in intialization
 * @param creation: Open dialog as RsColl Creation or RsColl DownLoad
 * @param readOnly: Open dialog for RsColl as ReadOnly
 */
RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName
                                       , const std::vector<ColFileInfo>& colFileInfos
                                       , const bool& creation /* = false*/
                                       , const bool& readOnly)
  : _fileName(collectionFileName), _creationMode(creation) ,_readOnly(readOnly)
{
	ui.setupUi(this) ;

	uint32_t size = colFileInfos.size();
	for(uint32_t i=0;i<size;++i)
	{
		const ColFileInfo &colFileInfo = colFileInfos[i];
		_newColFileInfos.push_back(colFileInfo);
	}

	setWindowFlags(Qt::Window); // for maximize button
	setWindowFlags(windowFlags() & ~Qt::WindowMinimizeButtonHint);

	setWindowTitle(QString("%1 - %2").arg(windowTitle()).arg(QFileInfo(_fileName).completeBaseName()));
	
	
	ui.headerFrame->setHeaderImage(QPixmap(":/images/library64.png"));
	ui.headerFrame->setHeaderText(tr("Collection Editor"));

	// 1 - add all elements to the list.

	ui._fileEntriesTW->setColumnCount(COLUMN_COUNT) ;

	QTreeWidgetItem *headerItem = ui._fileEntriesTW->headerItem();
	headerItem->setText(COLUMN_FILE, tr("File"));
	headerItem->setText(COLUMN_SIZE, tr("Size"));
	headerItem->setText(COLUMN_HASH, tr("Hash"));
	headerItem->setText(COLUMN_FILEC, tr("File Count"));

	bool wrong_chars = !updateList();

	// 2 - connect necessary signals/slots

	connect(ui._changeFile, SIGNAL(clicked()), this, SLOT(changeFileName()));
	connect(ui._add_PB, SIGNAL(clicked()), this, SLOT(add()));
	connect(ui._addRecur_PB, SIGNAL(clicked()), this, SLOT(addRecursive()));
	connect(ui._remove_PB, SIGNAL(clicked()), this, SLOT(remove()));
	connect(ui._makeDir_PB, SIGNAL(clicked()), this, SLOT(makeDir()));
	connect(ui._cancel_PB, SIGNAL(clicked()), this, SLOT(cancel()));
	connect(ui._save_PB, SIGNAL(clicked()), this, SLOT(save()));
	connect(ui._download_PB, SIGNAL(clicked()), this, SLOT(download()));
	connect(ui._hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
	connect(ui._fileEntriesTW, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*,int)));

	// 3 Initialize List
	_dirModel = new QFileSystemModel(this);
	_dirModel->setRootPath("/");
	_dirModel->setFilter(QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot);
	_dirLoaded = false;
	connect(_dirModel, SIGNAL(directoryLoaded(QString)), this, SLOT(directoryLoaded(QString)));

	_tree_proxyModel = new FSMSortFilterProxyModel(this);
	_tree_proxyModel->setDynamicSortFilter(true);
	_tree_proxyModel->setSourceModel(_dirModel);
	_tree_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
	_tree_proxyModel->setSortRole(Qt::DisplayRole);

	ui._systemFileTW->setModel(_tree_proxyModel);
	//Selection Setup
	_selectionProxy = ui._systemFileTW->selectionModel();

	// 4 Restore Configuration
	// load settings
	processSettings(true);

	// 5 Activate button follow creationMode
	ui._changeFile->setVisible(_creationMode && !_readOnly);
	ui._makeDir_PB->setVisible(_creationMode && !_readOnly);
	ui._save_PB->setVisible(_creationMode && !_readOnly);
	ui._treeViewFrame->setVisible(_creationMode && !_readOnly);
	ui._download_PB->setVisible(!_creationMode && !_readOnly);

	ui._fileEntriesTW->installEventFilter(this);
	ui._systemFileTW->installEventFilter(this);

	// 6 Add HashBox
	setAcceptDrops(true);
	ui._hashBox->setDropWidget(this);
	ui._hashBox->setAutoHide(true);
	ui._hashBox->setDefaultTransferRequestFlags(RS_FILE_REQ_ANONYMOUS_ROUTING) ;

	if(wrong_chars)
		QMessageBox::warning(NULL,tr("Bad filenames have been cleaned"),tr("Some filenames or directory names contained forbidden characters.\nCharacters <b>\",|,/,\\,&lt;,&gt;,*,?</b> will be replaced by '_'.\n Concerned files are listed in red.")) ;
}
Ejemplo n.º 20
0
ibis::math::term* ibis::selectClause::addRecursive(ibis::math::term*& tm) {
    if (tm == 0) return tm;

    switch (tm->termType()) {
    default:
    case ibis::math::NUMBER:
    case ibis::math::STRING:
        break; // nothing to do
    case ibis::math::VARIABLE: {
        ibis::selectClause::variable *var =
            dynamic_cast<ibis::selectClause::variable *>(tm);
        if (var == 0) { // a bare variable
            const char* vname =
                static_cast<ibis::math::variable*>(tm)->variableName();
            if (ordered_.find(vname) == ordered_.end()) {
                const unsigned pos = atms_.size();
                aggr_.push_back(ibis::selectClause::NIL_AGGR);
                atms_.push_back(tm->dup());
                ordered_[vname] = pos;

                LOGGER(ibis::gVerbose > 5)
                    << "selectClause::addRecursive -- adding term "
                    << pos << ": " << vname;
            }
        }
        break;}
    case ibis::math::STDFUNCTION1:
    case ibis::math::CUSTOMFUNCTION1:
    case ibis::math::STRINGFUNCTION1: {
        ibis::math::term *nxt =
            reinterpret_cast<ibis::math::term*>(tm->getLeft());
        if (nxt == 0) {
            return nxt;
        }
        else if (hasAggregation(nxt)) {
            ibis::math::term *tmp = addRecursive(nxt);
            if (tmp != nxt)
                tm->getLeft() = tmp;
        }
        else {
            const unsigned pos = atms_.size();
            aggr_.push_back(ibis::selectClause::NIL_AGGR);
            atms_.push_back(tm);
            LOGGER(ibis::gVerbose > 5)
                << "selectClause::addRecursive -- adding term "
                << pos << ": " << aggDescription(pos);

            std::ostringstream oss;
            oss << "__" << std::hex << pos;
            ordered_[oss.str()] = pos;
            return new ibis::selectClause::variable(oss.str().c_str(), this);
        }
        break;}
    case ibis::math::OPERATOR:
    case ibis::math::STDFUNCTION2:
    case ibis::math::CUSTOMFUNCTION2:
    case ibis::math::STRINGFUNCTION2: {
        ibis::math::term *left =
            reinterpret_cast<ibis::math::term*>(tm->getLeft());
        ibis::math::term *right =
            reinterpret_cast<ibis::math::term*>(tm->getRight());
        if (left == 0) {
            if (right == 0) {
                return 0;
            }
            else if (dynamic_cast<ibis::selectClause::variable*>(right) == 0) {
                tm->getRight() = addRecursive(right);
            }
        }
        else if (dynamic_cast<ibis::selectClause::variable*>(left) != 0) {
            if (dynamic_cast<ibis::selectClause::variable*>(right) == 0) {
                tm->getRight() = addRecursive(right);
            }
        }
        else if (dynamic_cast<ibis::selectClause::variable*>(right) != 0) {
            tm->getLeft() = addRecursive(left);
        }
        else if (hasAggregation(tm)) {
            tm->getLeft() = addRecursive(left);
            tm->getRight() = addRecursive(right);
        }
        else {
            const unsigned pos = atms_.size();
            aggr_.push_back(ibis::selectClause::NIL_AGGR);
            atms_.push_back(tm);
            LOGGER(ibis::gVerbose > 5)
                << "selectClause::addRecursive -- adding term "
                << pos << ": " << aggDescription(pos);

            std::ostringstream oss;
            oss << "__" << std::hex << pos;
            ordered_[oss.str()] = pos;
            return new ibis::selectClause::variable(oss.str().c_str(), this);
        }
        break;}
    }
    return tm;
} // ibis::selectClause::addRecursive