Exemple #1
0
//-------------------------------------------------------------------------------------------------
inline void_t
Dir::create() const
{
    bool_t bRv = isExists();
    xCHECK_DO(bRv, return);

    _create_impl();
    xTEST_EQ(isExists(), true);
}
Exemple #2
0
bool FileManager::mkdir(const URL &sDir)
{
	if (!sDir.isAbsolutePath())
	{
		SCError("cannot mkdir: %s", sDir.c_str());
		return false;
	}
	URL dir(sDir);
	dir.trim();
	if (dir.empty() || isExists(dir))
	{
		return true;
	}
	
	// create upper directory
	if (!mkdir(URL(dir).deleteLastPathComponent()))
	{
		SCError("failed to create upper dir: %s", sDir.c_str());
		return false;
	}
	
	if (mkdir_(dir))
	{
		return true;
	}
	else
	{
		SCError("failed to mkdir: %s", dir.c_str());
		return false;
	}
}
Exemple #3
0
bool FileManager::move(const URL &sSourcePath, const URL &sTargetPath)
{
	if (!isExists(sSourcePath) || !isWritable(URL(sTargetPath).deleteLastPathComponent()))
	{
		SCError("cannot move file %s to %s", sSourcePath.c_str(), sTargetPath.c_str());
		return false;
	}
	
	if (rename(sSourcePath.c_str(), sTargetPath.c_str()) == 0)
	{
		return true;
	}
	SCLog("cannot rename %s to %s, try copying...", sSourcePath.c_str(), sTargetPath.c_str());
	
	// cannot rename, try copy
	if (!copy(sSourcePath, sTargetPath))
	{
		SCError("failed to copy file %s to %s", sSourcePath.c_str(), sTargetPath.c_str());
		return false;
	}
	
	if (!remove(sSourcePath))
	{
		SCWarning("cannot remove old file: %s", sSourcePath.c_str());
		return false;
	}
	
	return true;
}
 bool BST<T1, T2>::search(T2 searchWord)
 {
	 bool found;
	 if(isExists(wordLength))
	 {
		 BST<T1, T2> *tmp;

	     tmp = mRootNode;
	     while (tmp != NULL)
	     {
		    if (tmp->mData == wordLength)
		    {		  	   
		  	   break;
		    }
		    else if (tmp->mData > wordLength)
			   tmp = tmp->mLeft;
		    else
			   tmp = tmp->mRight;
	     }

		 if(tmp != NULL)
		 {
			 found = tmp->findWord(word);
		 }
	}

	else 
		found = false;

	return found;
 }
void BST<T1, T2>::pushWord(string &word, int wordLength)
{
	if(isExists(wordLength))
	{
		 BST<T1, T2> *tmp;

	     tmp = mRootNode;
	     while (tmp != NULL)
	     {
		    if (tmp->mData == wordLength)
		    {		  	   
		  	   break;
		    }
		    else if (tmp->mData > wordLength)
			   tmp = tmp->mLeft;
		    else
			   tmp = tmp->mRight;
	     }

		 if(tmp != NULL)
		 {
			 tmp->insertWord(word);
		 }
	}

	else 
		cout << "There is no tree to put the word " << word << " into." << endl;

	return;
}
Exemple #6
0
//-------------------------------------------------------------------------------------------------
inline std::ctstring_t &
File::path() const
{
    xTEST_EQ(_filePath.empty(), false);
    xTEST_EQ(isExists(_filePath), true);

    return _filePath;
}
void BST<T1, T2>::remove(T1 searchKey)
{
	if(isEmpty())
		return;
	else if (!isExists(searchKey))
		return;

	remove(mRootNode, searchKey);
}
Exemple #8
0
Bool simplest::Simple::destroy()  {
    if(!isExists())
        return false;
    onDestroy();
    pushFreeSimple(*this);
    setExists(false);
    resetID();
    return true;
}
Exemple #9
0
Bool testlist::Parent::destroy()  {
    if(!isExists())
        return false;
    onDestroy();
    cascadeRemoveChild();
    pushFreeParent(*this);
    setExists(false);
    resetID();
    return true;
}
Exemple #10
0
/*==============================================================================
 Метод сохраняет модель в БД
==============================================================================*/
bool Model::save()
{
    if(isExists())
    {
        QString res = generateUpdate();
        return execQuery(res);
    }
    QString res = generateInsert();
    setExists(true);
    return execQuery(res);
}
Exemple #11
0
Bool testlist::Child::destroy()  {
    if(!isExists())
        return false;
    onDestroy();
    if ( getParent().isValid() )
        getParent().removeChild(*this);
    pushFreeChild(*this);
    setExists(false);
    resetID();
    return true;
}
Exemple #12
0
Bool testhash::Parent::destroy()  {
    if(!isExists())
        return false;
    onDestroy();
    cascadeRemoveTableListChild();
    cascadeRemoveChild();
    Parent::remove__ChildTableBlock__Parent(*this);
    pushFreeParent(*this);
    setExists(false);
    resetID();
    return true;
}
void BST<T1, T2>::printPath(T1 searchKey)
{
	//Format so it looks like tree

	if(isExists(searchKey))
	{
		int printLocation = 20;
		int printIncrement = 5;
		BST<T1, T2> *tmp;
	 
		tmp = mRootNode;
		while (tmp != NULL)
		{
			if (tmp->mData == searchKey)
			{
				cout << right << setw(printLocation) << tmp->mData << endl;
				break;
			}
			else if (tmp->mData > searchKey)
			{
				//Print the node and line to next
				cout << right << setw(printLocation) << tmp->mData << endl;
				
				//change location of cursor, print last line to node
				printLocation -= printIncrement;

				//set temp to the left node
				tmp = tmp->mLeft;
			}
			else
			{
				//Print the node and line to next
				cout << right << setw(printLocation) << tmp->mData << endl;
				
				//change location of cursor, print last line to node
				printLocation += printIncrement; 

				//set temp to the right node
				tmp = tmp->mRight;
			}
		}
		tmp->displayWords();
	}

	else //If search key does not exist
	{
		cout << "Search key not found.." << endl;
	}
}
Exemple #14
0
cFileInfo::cFileInfo(char *file)
{
  MYDEBUG("FileInfo: %s", file);
  File = (file && !isempty(file)) ? strdup(file) : NULL;

  if(File && File[strlen(File) - 1] == '/')
      File[strlen(File) - 1] = '\0';

  buffer = NULL;

  if(isExists())
    stat64(File, &Info);

  size = 0;
}
Exemple #15
0
bool FileManager::remove(const URL &sFilePath)
{
	if (!isExists(sFilePath) || !isWritable(URL(sFilePath).deleteLastPathComponent()))
	{
		SCError("cannot remove file: %s", sFilePath.c_str());
		return false;
	}
	if (unlink(sFilePath.c_str()) == 0)
	{
		return true;
	}
	else
	{
		SCError("failed to remove file: %s", sFilePath.c_str());
		return false;
	}
}
Exemple #16
0
void workHard(int hashSize)
{
	FILE *input1 = fopen("input1.txt", "r");
	HashTable *table = createTable(hashSize);
	int counter = 0;
	while (!feof(input1))
	{
		char string[1000] = {};
		fgets(string, 1000, input1);
		if (strlen(string) < 1)
			break;
		if (counter > 0.7 * hashSize)
		{
			destroyHashTable(table);
			delete table;
			fclose(input1);
			//printf("REBUILD!\n");
			workHard(2 * hashSize);
			return;
		}
		buildTable(table, string);
		memset(string, '\0', 1000);
		counter++;
	}
	fclose(input1);
	//printTable(table);
	FILE *input2 = fopen("input2.txt", "r");
	FILE *output = fopen("output.txt", "w");
	while (!feof(input2))
	{
		char string[1000] = {};
		fgets(string, 1000, input1);
		if (strlen(string) < 1)
			break;
		if (isExists(table, string))
		{
			fputs(string, output);
		}
		memset(string, '\0', 1000);
	}

	destroyHashTable(table);
	delete table;
	fclose(input2);
	fclose(output);
}
Exemple #17
0
bool FileManager::copy(const URL &sSourcePath, const URL &sTargetPath)
{
	if (!isExists(sSourcePath) || !isWritable(URL(sTargetPath).deleteLastPathComponent()))
	{
		SCError("failed to copy file %s to %s", sSourcePath.c_str(), sTargetPath.c_str());
		return false;
	}
	
	File file;
	if (!file.read(sSourcePath.c_str()))
	{
		SCError("failed to read file: %s", sSourcePath.c_str());
		return false;
	}
	if (!file.write(sTargetPath.c_str()))
	{
		SCError("failed to write file: %s", sTargetPath.c_str());
		return false;
	}
	
	return true;
}
Exemple #18
0
Dir::pathCreate() const
{
    std::vec_tstring_t pathParts;
    std::tstring_t     buildPath;

    // split dirPath into parts
     String::split( Path(dirPath()).toNative(false), Const::slash(), &pathParts );

    // create dirs by steps
    xFOREACH_CONST(std::vec_tstring_t, it, pathParts) {
        buildPath.append(*it).append(Const::slash());

        Dir(buildPath).create();
    }

    xTEST_EQ(isExists(), true);
}
//-------------------------------------------------------------------------------------------------
inline void_t
Dir::copy(
    std::ctstring_t &a_dirPathTo,
    cbool_t         &a_failIfExists
) const
{
    xTEST_EQ(isExists(), true);
    xTEST_EQ(a_dirPathTo.empty(), false);
    xTEST_NA(a_failIfExists);

    // sets attribute "normal"
    bool_t bRv = Dir(a_dirPathTo).isExists();
    if (bRv) {