QVariant LogTableModel::data (QModelIndex const & index, int role) const
{
	if (!index.isValid())
		return QVariant();

	int const col = index.column();
	int const row = index.row();
	proto::Record const * rec = nullptr;
	proto::Attrs const * attrs = nullptr;
	if (checkExistence(index))
	{
		rec = m_data.getRecord(row);
		attrs = m_data.getAttrs(row);
	}

	if (rec == nullptr)
	{
		if (role == Qt::BackgroundRole)
			return QVariant::fromValue<QColor>(Qt::gray);
		return QVariant();
	}

	if (role == Qt::DisplayRole)
	{
		QVariant const ret = m_data.getRecordData(rec->m_values, col);
		return ret;
	}
	else if (role == Qt::ToolTipRole)
	{
		QVariant const ret = m_data.getRecordData(rec->m_values, col);
		QString ttip("<pre>");
		ttip.append(ret.toString());
		ttip.append(QString("</pre>"));
		return ttip;
	}
	else if (role == Qt::BackgroundRole)
	{
// 		QVariant const col_flags_qv = m_data.getRecordData(attrs->m_flags, col);
// 		proto::Flags col_flags = col_flags_qv.value<proto::Flags>();
// 
// 		if (col_flags.m_scope_type == LogScopeType_scopeEntry)
// 			return QVariant::fromValue<QColor>(QColor(0xEFEDFC));
// 		if (col_flags.m_scope_type == LogScopeType_scopeExit)
// 			return QVariant::fromValue<QColor>(QColor(0xEAF1FB));
		
		QVariant const col_rgba = m_data.getRecordData(attrs->m_bgcols, col);
		if (col_rgba.isValid())
			if (unsigned const rgba = col_rgba.toUInt())
				return QVariant::fromValue<QColor>(QColor(rgba));
	}
	else if (role == Qt::ForegroundRole)
	{
		QVariant const col_rgba = m_data.getRecordData(attrs->m_fgcols, col);
		if (col_rgba.isValid())
			if (unsigned const rgba = col_rgba.toUInt())
				return QVariant::fromValue<QColor>(QColor(rgba));
	}
	return QVariant();
}
Esempio n. 2
0
/*==============================================================================
 Метод возвращает флаг существования текущей модели в БД
==============================================================================*/
bool Model::isExists()
{
    if(!exists)
    {
        exists = checkExistence();
    }
    return exists;
}
Esempio n. 3
0
int
PlatformBase::makeDir (std::string dir)
{
	if (checkExistence(dir, IS_FILE)) 
	{ 
        return 1;
	}

	if (checkExistence(dir, DIRECTORY)) 
	{ 
        return 0;
	}

	std::string::size_type pos = dir.find_last_of("/\\");
	int err = makeDir(dir.substr(0, pos));
	if(err)
	{
		return err;
	}

#ifdef _WIN32
	DWORD dw;
	if( !CreateDirectory(dir.c_str(), NULL))
	{
		dw = GetLastError();
		std::cerr << "Problem creating the directory " << dir << std::endl;
		return 2;
	}
#else
	err = mkdir(dir.c_str(), 0755);
	if(err)
	{
		std::cerr << "Problem creating the directory " << dir << std::endl;
		return 2;
	}
#endif

	return 0;
}
void tui::ResourceCenter::appendMenu(const std::string &menuItem, const std::string &hotKey, callbackMethod cbMethod, const std::string &helpString)
{
   int ID = TMDUMMY + _menuCount;

   //Set first character in top menu into uppercase
   //it need for simplicity
   std::string str = menuItem;
   str[0] = toupper(str[0]);
  
   MenuItemHandler* mItem= new MenuItem(ID, str, hotKey, cbMethod, helpString);
   if (!checkExistence(*mItem))
   {
      _menus.push_back(mItem);
      _menuCount++;
   }
   
};
Esempio n. 5
0
int 
PlatformBase::removeFileOrDirectory(std::string object) 
{
	// if the last symbol is a delimiter, remove it
	std::string object_name = object;
#ifdef _WIN32
	if (object_name[object_name.size() - 1] == '\\')
#else
	if (object_name[object_name.size() - 1] == '/')
#endif
	{
		object_name.erase(object_name.size() - 1, 1);
	}
    
    //
    // check whether the object exists
    //
    if (checkExistence(object_name, DIRECTORY_OR_FILE)) 
	{
#ifdef _WIN32
        char dummy[256];
        strcpy(dummy, object_name.c_str());
        dummy[strlen(dummy) + 1] = '\0';

        SHFILEOPSTRUCT fileOp;
        fileOp.hwnd = NULL;
        fileOp.wFunc = FO_DELETE;
        fileOp.pFrom = dummy;
        fileOp.pTo = NULL;
        fileOp.fFlags = FOF_NOCONFIRMATION;
        int error =  SHFileOperation(&fileOp);
        if (error)
        {
            return 1;
        }
#else
		std::string command = std::string("\\rm -rf ") + object_name;
		system(command.c_str());
#endif
		return 0;
	}

    // no such object
    return 1;
}
Esempio n. 6
0
/*
 * Checks if there are arguments problems
 *	
 * @return 0 if there are no problems, 1 otherwise.
 * 
 */
int checkArguments(){
	int c,err = 0;
	int response;

	while ((c = getopt(g_argc, g_argv, "qr")) != -1){
		switch (c) { 
			case 'q': 
				qflag = 1;
				break;
			case 'r': 
				rflag = 1;
				break;
			case '?': 
				err = 1; 
				break;
		}
	}

	if((optind+2) > g_argc){

		fprintf(stderr, "At least two arguments must be introduced.\n");
		return -1;

	}else if (err){

		fprintf(stderr, "Given options are invalid..\n");
		return -1;
	}

	if (!checkExistence(g_argv[g_argc-1]))
	{
		fprintf(stderr, "Given directory doesn't exist. [%s]\n", g_argv[g_argc-1]);
		return -1;
	}


	if (!isDirectory(g_argv[g_argc-1]))
	{
		fprintf(stderr, "Last argument is not a directory. [%s]\n", g_argv[g_argc-1]);
		return -1;
	}
	return 0;
}
main(){
	char main[100];
	char query[100];
	
	int T; //number of test cases

	printf("Enter number of Test Cases\n");
	scanf("%d",&T);

	printf("Enter main String\n");
	scanf("%s",main);
	
	while(T--){
		printf("Enter Query String\n");
		scanf("%s",query);
		if(checkExistence(main,query)){
			printf("Exists\n");
		}else{
			printf("Does not Exist\n");
		}
	}
}
char* 
ComponentInstallationImpl::upload (const char* implUUID, const ::CORBA::OctetSeq& package)
throw (Components::Deployment::InstallationFailure)
{
	std::string theName(implUUID);
	std::string theFile = packageDirectory_ + "/" + theName;

    //
	// check if already uploaded
    //
	if (checkExistence(theFile, IS_FILE))
    {
        return CORBA::string_dup(theName.c_str());
    }

	//
	// save to disk
	//
	std::ofstream file(theFile.c_str(), std::ios::binary|std::ios::app);
    if (!file)
    {
		std::cerr << "Package " << theName << " can not be locally saved !!!" << std::endl;
        throw Components::Deployment::InstallationFailure();
    }
    const CORBA::Octet* it = package.get_buffer();
    file.write((char*)it, package.length());
    file.close();

	//
	// ensure the file is stored
	//
#ifdef _WIN32
	Sleep(1000);
#else
  sleep(1);
#endif
  
    return CORBA::string_dup(theName.c_str());
}
bool LogTableModel::setData (QModelIndex const & index, QVariant const & value, int role)
{
	if (!index.isValid()) return false;
	if (!checkExistence(index)) return false;

	int const x = index.column();
	int const y = index.row();
	if (role == Qt::DisplayRole)
		return false;
	else if (role == Qt::EditRole)
	{
		//m_rows.at(y).at(x).m_value = value;
	}
	else if (role == Qt::BackgroundRole)
	{
		QVariant const bg_val = value;
		QColor const col = bg_val.value<QColor>();
		qtcolor const qtcol = col.rgba();

		proto::rw_rowdata_t rowdata = m_data.getRecordDataForRowReadWrite(index.row());
		proto::Attrs * attrs = std::get<1>(rowdata);
		m_data.setRecordData(attrs->m_bgcols, index.column(), qtcol);
	}
	else if (role == Qt::ForegroundRole)
	{
		QVariant const fg_val = value;
		QColor const col = fg_val.value<QColor>();
		qtcolor const qtcol = col.rgba();

		proto::rw_rowdata_t rowdata = m_data.getRecordDataForRowReadWrite(index.row());
		proto::Attrs * attrs = std::get<1>(rowdata);
		m_data.setRecordData(attrs->m_fgcols, index.column(), qtcol);
	}

	emit dataChanged(index, index);
	return true;
}
void
ComponentImplementation::buildServants()
throw(Components::CreateFailure)
{
	data_.servant_module = installation_path_ + data_.uuid + "_servants." + DLL_EXT;
	data_.servant_entry_point = "create_" + data_.home_name + "S";

#ifdef _WIN32
	makefile_ = g_qedo_dir + "\\etc\\makefile";
#else
	makefile_ = g_qedo_dir + "/etc/makefile";
#endif

	if ( !checkExistence(makefile_, IS_FILE)) 
	{
		std::cerr << "missing makefile : " << makefile_ << std::endl;
		throw Components::CreateFailure();
	}

#ifdef _WIN32
	std::string command = "nmake /f " + makefile_;
	command += " SOURCE=" + data_.idl.location.file;
	command += " TARGET=" + data_.home_repid;
	command += " DLL=" + data_.servant_module;
	std::cout << command << std::endl;

	{
	char* command_line = strdup(command.c_str());
	char* command_dir = strdup(build_path_.c_str());

	STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    // Start the child process. 
    if( !CreateProcess( NULL, // No module name (use command line). 
        command_line,     // Command line. 
        NULL,             // Process handle not inheritable. 
        NULL,             // Thread handle not inheritable. 
        FALSE,            // Set handle inheritance to FALSE. 
        0,                // No creation flags. 
        NULL,             // Use parent's environment block. 
        command_dir,      // Use parent's starting directory. 
        &si,              // Pointer to STARTUPINFO structure.
        &pi )             // Pointer to PROCESS_INFORMATION structure.
    ) 
    {
		LPVOID lpMsgBuf;
		FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
			NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
			(LPTSTR) &lpMsgBuf, 0, NULL);
		std::cerr << "CreateProcess failed: " << (LPCTSTR)lpMsgBuf << std::endl;
		
		// Free the buffer.
		LocalFree( lpMsgBuf );
		throw Components::CreateFailure();
    }

    // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );

    //
    // get exit code
    //
    DWORD exitCode;
    if (GetExitCodeProcess(pi.hProcess, &exitCode))
    {
        if (exitCode)
        {
			std::cerr << "Servant code generation failed !!!" << std::endl;
            throw Components::CreateFailure();
        }
    }
    else 
    {
        std::cerr << "GetExitCodeProcess() failed !!!" << std::endl;
        throw Components::CreateFailure();
    }

    // Close process and thread handles. 
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );

	delete command_line;
	delete command_dir;
	}
#else
	std::string command = "cd " + build_dir_ + ";make -f " + makefile_;
	command += " SOURCE=" + data_.idl.location.file;
	command += " TARGET=" + data_.servant_module;
	std::cout << command << std::endl;
	int ret=system(command.c_str());
	if(!WIFEXITED(ret))
	{
		std::cerr << "Error while making: "  << ret << std::endl;
        throw Components::CreateFailure();
	}
#endif
}
Esempio n. 11
0
ReturnCode getPoint(const TixiDocumentHandle handle, const char* parentPath, const int pointIndex,
                    int ignoreMissingElements, double* x, double* y, double* z)
{
  ReturnCode error = -1;
  ReturnCode errorX = -1;
  ReturnCode errorY = -1;
  ReturnCode errorZ = -1;

  TixiDocument* document = getDocument(handle);
  xmlDocPtr xmlDocument = NULL;
  xmlXPathObjectPtr xpathParentObject = NULL;
  xmlNodePtr parent = NULL;
  char* pointPath = NULL;
  char* coordinatePathBuffer = NULL;
  int nPointElements = 0;

  if (!document) {
    printMsg(MESSAGETYPE_ERROR, "Error: Invalid document handle.\n");
    return INVALID_HANDLE;
  }

  if (pointIndex < 1) {
    printMsg(MESSAGETYPE_ERROR, "Error: Invalid point index %d\n", pointIndex);
    return INDEX_OUT_OF_RANGE;
  }

  xmlDocument = document->docPtr;

  error = checkElement(xmlDocument, parentPath, &parent, &xpathParentObject);
  xmlXPathFreeObject(xpathParentObject);

  if (!error) {

    xmlXPathObjectPtr xpathPointObject = NULL;

    size_t lengthPointPath = (strlen(parentPath) +      /* length of path to parent   */
                              1);      				    /* trailing \0                */

    pointPath = (char*) malloc(sizeof(char) * lengthPointPath);

    strcpy(pointPath, parentPath);

    /* pad with trailing blanks, so we can check for the size in getCoordinateValue */

    error = checkExistence(xmlDocument, pointPath, &xpathPointObject);

    if (xpathPointObject) {
      nPointElements = xpathPointObject->nodesetval->nodeNr;
      xmlXPathFreeObject(xpathPointObject);
    }

    if (error == ELEMENT_NOT_FOUND) {
      printMsg(MESSAGETYPE_ERROR, "Error: No point element found in element \"%s\".\n", parentPath);
      error = NO_POINT_FOUND;
    }
    else if (!error) {
      if (pointIndex > nPointElements) {
        printMsg(MESSAGETYPE_ERROR, "Error: Index (%d) larger than number of point elements.\n", pointIndex);
        error = INDEX_OUT_OF_RANGE;
      }
      else {
        errorX = getCoordinateValue(xmlDocument, pointPath, pointIndex, "x", ignoreMissingElements, x);
        errorY = getCoordinateValue(xmlDocument, pointPath, pointIndex, "y", ignoreMissingElements, y);
        errorZ = getCoordinateValue(xmlDocument, pointPath, pointIndex, "z", ignoreMissingElements, z);

        if( errorX && errorY && errorZ) {
          error = NO_POINT_FOUND;
        }
        else {
          error = SUCCESS;
        }
      }

    }
  }

  free(coordinatePathBuffer);
  free(pointPath);
  return error;
}
void SearchEng::add_parse_page(std::string filename, PageParser* parser){
	MySet<std::string> temp_all_words;
	MySet<std::string> temp_all_links;

	parser->parse(filename, temp_all_words, temp_all_links);
	

	if(!map_all_webpages.count(filename) ){//this filename isn't in the map
		//create a new webpage and store a pointer to it in our map
		WebPage* wp = new WebPage(filename);
		map_all_webpages.insert ( std::pair<std::string, WebPage*>(filename, wp) );

		map_all_webpages[filename]->all_words(temp_all_words);//same as wp->all_words(temp_all_words)

		std::set<std::string>::iterator it;
		for(it = temp_all_links.begin(); it != temp_all_links.end(); ++it){
			std::ifstream checkExistence( (*it).c_str() );
			if(!checkExistence.fail() ){
				if(!map_all_webpages.count(*it) ){//add the link to our map if its not in there
					WebPage* wp2 = new WebPage(*it);
					map_all_webpages.insert ( std::pair<std::string, WebPage*>(*it, wp2) );
				}
				wp->add_outgoing_link(map_all_webpages[*it]);
				map_all_webpages[*it]->add_incoming_link(wp);
			}
			if(checkExistence.is_open() ){
				checkExistence.close();
			}
		}


		//fill second map
		std::set<std::string>::iterator it2;
		for(it2 = temp_all_words.begin(); it2 != temp_all_words.end(); ++it2){
			std::string tmp = *it2;
			str_to_lower(tmp);
			if(!word_to_setofwps.count(tmp) ){// curr word not inside map
				
				MySet<WebPage*> set_wp;
				set_wp.insert(wp);
				word_to_setofwps.insert( std::make_pair(tmp, set_wp) );
			}
			else{// curr word is inside map
				word_to_setofwps[tmp].insert(wp);
			}
		}

	}else{//webpage is in the map but hasnt had its member set filled in
		WebPage* wp = map_all_webpages[filename];

		wp->all_words(temp_all_words);

		//populate filename's 
		std::set<std::string>::iterator it;
		for(it = temp_all_links.begin(); it != temp_all_links.end(); ++it){
			std::ifstream checkExistence( (*it).c_str() );
			if(!checkExistence.fail() ){
				if(!map_all_webpages.count(*it) ){//add the link to our map if its not in there
					WebPage* wp2 = new WebPage(*it);
					map_all_webpages.insert ( std::pair<std::string, WebPage*>(*it, wp2) );
				}
				wp->add_outgoing_link(map_all_webpages[*it]);
				map_all_webpages[*it]->add_incoming_link(wp);
			}
			if(checkExistence.is_open() ){
				checkExistence.close();
			}
		}


		//fill second map
		std::set<std::string>::iterator it2;
		for(it2 = temp_all_words.begin(); it2 != temp_all_words.end(); ++it2){
			std::string tmp = *it2;
			str_to_lower(tmp);
			if(!word_to_setofwps.count(tmp) ){// curr word not inside map
				
				MySet<WebPage*> set_wp;
				set_wp.insert(wp);
				word_to_setofwps.insert( std::make_pair(tmp, set_wp) );
			}
			else{// curr word is inside map
				word_to_setofwps[tmp].insert(wp);
			}
		}
	}

	
}
void 
ComponentInstallationImpl::install (const char* implUUID, const char* component_loc)
throw (Components::Deployment::InvalidLocation, Components::Deployment::InstallationFailure)
{
	//
	// The description may have 2 forms:
	//
	// 1) servant_module:servant_entry_point:executor_module:executor_entry_point
	// 2) PACKAGE=<packagename>
	//

	std::cout << "..... installing Component type with UUID: " << implUUID << std::endl;

	// First test for duplicate UUIDs
	std::vector < ComponentImplementation >::const_iterator inst_iter;
	for (inst_iter = installed_components_.begin(); inst_iter != installed_components_.end(); inst_iter++)
	{
		if ((*inst_iter).uuid_ == implUUID)
		{
			std::cout << ".......... already installed !" << std::endl;
			return;
		}
	}

	//
	// component_loc contains PACKAGE location
	//
	std::string::size_type pos;
	std::string desc = component_loc;
	if( !desc.compare(0, 8, "PACKAGE="))
	{
		//
		// check whether the package exists
		//
		std::string comp_loc = packageDirectory_ + "/" + desc.substr(8);
		if (!checkExistence(comp_loc, IS_FILE))
		{
			std::cerr << ".......... missing package " << comp_loc << std::endl;
			std::cerr << ".......... upload before installing" << std::endl;
			throw Components::Deployment::InvalidLocation();
		}

		//
		// create new implementation
		//
		ComponentImplementation newComponentImplementation(implUUID, installationDirectory_, comp_loc);
		bool ok = newComponentImplementation.install();
		// remove the package
		removeFileOrDirectory(comp_loc);
		
		if (ok)
		{
			installed_components_.push_back(newComponentImplementation);
			addInstalledComponent(&newComponentImplementation);
		}
		else
		{
			throw Components::Deployment::InstallationFailure();
		}
	}
	//
	// component_loc contains local code location
	//
	else
	{
		pos = desc.find (";");
		if (pos == std::string::npos)
		{
			std::cerr << "ComponentInstallationImpl: Cannot extract servant module name" << std::endl;
			throw Components::Deployment::InvalidLocation();
		}
		std::string servant_module = desc.substr (0, pos);

		desc = desc.substr (pos + 1);
		pos = desc.find (";");
		if (pos == std::string::npos)
		{
			std::cerr << "ComponentInstallationImpl: Cannot extract servant entry point" << std::endl;
			throw Components::Deployment::InvalidLocation();
		}
		std::string servant_entry_point = desc.substr (0, pos);

		desc = desc.substr (pos + 1);
		pos = desc.find (";");
		if (pos == std::string::npos)
		{
			std::cerr << "ComponentInstallationImpl: Cannot extract executor module name" << std::endl;
			throw Components::Deployment::InvalidLocation();
		}
		std::string executor_module = desc.substr (0, pos);

		desc = desc.substr (pos + 1);
		std::string executor_entry_point = desc;

		//
		// create new implementation
		//
		ComponentImplementation newComponentImplementation(implUUID, servant_module, servant_entry_point, executor_module, executor_entry_point);
		installed_components_.push_back (newComponentImplementation);
		addInstalledComponent(&newComponentImplementation);
	}

	std::cout << "..... done (" << implUUID << ")" << std::endl;
}
bool
ComponentInstallationImpl::readInstalledComponents ()
{
	//
	// is there already a deployment file ?
	//
	if ( ! checkExistence(inst_file_.c_str(), IS_FILE)) 
	{
		std::ofstream deployment_file(inst_file_.c_str());
		if ( ! deployment_file)
		{
			std::cerr << "..... Cannot open file " << inst_file_ << std::endl;
			return false;
		}
		deployment_file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n";
		deployment_file << "<deployed>\n";
		deployment_file << "</deployed>" << std::endl;
		deployment_file.close();

		return true;
	}
	
	//
	// parse the descriptor file
    //
	DOMXMLParser* parser = new DOMXMLParser();
    if (parser->parse(strdup(inst_file_.c_str())) != 0) 
    {
		std::cerr << "Error during parsing " << inst_file_ << std::endl;
        return false;
    }

	DOMDocument* doc = parser->getDocument();
	DOMElement* root = doc->getDocumentElement();
	DOMNodeList* aNodeList = root->getElementsByTagName(X("implementation"));
	for (unsigned int i = 0; i < aNodeList->getLength(); i++)
	{
		DOMElement* iElement = (DOMElement*) aNodeList->item(i);
		DOMElement* sElement = (DOMElement*) (iElement->getElementsByTagName(X("servants"))->item(0));
		DOMElement* bElement = (DOMElement*) (iElement->getElementsByTagName(X("business"))->item(0));
		
        //
        // extract descriptions
		//
		std::string uu_id = XMLString::transcode(iElement->getAttribute(X("id")));
		std::string servants_DLL_name = XMLString::transcode(sElement->getAttribute(X("code")));
		std::string servants_DLL_entry_point_function = XMLString::transcode(sElement->getAttribute(X("entry")));
		std::string executors_DLL_name = XMLString::transcode(bElement->getAttribute(X("code")));
		std::string executors_DLL_entry_point_function = XMLString::transcode(bElement->getAttribute(X("entry")));
		
		//
		// create new ComponentImplementation
		//
		ComponentImplementation newImplementation(uu_id, servants_DLL_name, servants_DLL_entry_point_function,
			                                      executors_DLL_name, executors_DLL_entry_point_function);
		installed_components_.push_back(newImplementation);
	}

	// delete parser
    delete parser;

	return true;
}