void set_field(const char *field, StringVector &list, IncrementMode &mode, IncrementMode set, IncrModeParser::LiteralArray &literals, size_t offset) { switch (list.at(offset).at(0)) { case '+': mode |= set; DSAY(DEBUG_MEDIUM, field, "set to 'increment'"); break; case '*': mode |= IncrementMode::None; DSAY(DEBUG_MEDIUM, field, "set to 'ignore'"); break; default: mode |= IncrementMode::None; literals.at(offset) = extract_literal(list.at(offset)); DSAY(DEBUG_MEDIUM, field, "set to literal:", literals.at(offset).second); break; } }
Boole CreateDirectoryPath(const String& DirectoryPath) { Boole Result = true; StringVector FolderNames; StringVector FolderVec = StringTools::Split(DirectoryPath,"/\\"); size_t StartIndex = 0; String PathAttempt; Char8 SysSlash = GetDirectorySeparator(); #ifdef MEZZ_WINDOWS // For windows and windows like machines, see if the first entry is a drive, because attempting to make a drive is silly. if( FolderVec.at(0).find(':') != String::npos ) { PathAttempt.append( FolderVec.at(0) ); PathAttempt.append( 1, SysSlash ); StartIndex++; } #else PathAttempt.append( 1, SysSlash ); #endif for( size_t VecIndex = StartIndex ; VecIndex < FolderVec.size() ; ++VecIndex ) { PathAttempt.append( FolderVec.at(VecIndex) ); PathAttempt.append( 1, SysSlash ); Result = CreateDirectory( PathAttempt ); } return Result; }
int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QScriptEngine eng; // register our custom types qScriptRegisterMetaType<IntVector>(&eng, toScriptValue, fromScriptValue); qScriptRegisterMetaType<StringVector>(&eng, toScriptValue, fromScriptValue); QScriptValue val = eng.evaluate("[1, 4, 7, 11, 50, 3, 19, 60]"); fprintf(stdout, "Script array: %s\n", qPrintable(val.toString())); IntVector iv = qscriptvalue_cast<IntVector>(val); fprintf(stdout, "qscriptvalue_cast to QVector<int>: "); for (int i = 0; i < iv.size(); ++i) fprintf(stdout, "%s%d", (i > 0) ? "," : "", iv.at(i)); fprintf(stdout, "\n"); val = eng.evaluate("[9, 'foo', 46.5, 'bar', 'Qt', 555, 'hello']"); fprintf(stdout, "Script array: %s\n", qPrintable(val.toString())); StringVector sv = qscriptvalue_cast<StringVector>(val); fprintf(stdout, "qscriptvalue_cast to QVector<QString>: "); for (int i = 0; i < sv.size(); ++i) fprintf(stdout, "%s%s", (i > 0) ? "," : "", qPrintable(sv.at(i))); fprintf(stdout, "\n"); return 0; }
void VideoRegionsConfigDialog::updateUI() { StringVector *videoClasses = m_config->getVideoClassNames(); std::vector<Rect> *videoRects = m_config->getVideoRects(); StringStorage textAreaData; TCHAR endLine[3] = {13, 10, 0}; { AutoLock al(m_config); textAreaData.setString(_T("")); for (size_t i = 0; i < videoClasses->size(); i++) { textAreaData.appendString(videoClasses->at(i).getString()); textAreaData.appendString(&endLine[0]); } TCHAR buffer[32]; _ltot(m_config->getVideoRecognitionInterval(), &buffer[0], 10); m_videoRecognitionInterval.setText(buffer); } m_videoClasses.setText(textAreaData.getString()); { AutoLock al(m_config); textAreaData.setString(_T("")); for (size_t i = 0; i < videoRects->size(); i++) { Rect r = videoRects->at(i); StringStorage s; RectSerializer::toString(&r, &s); textAreaData.appendString(s.getString()); textAreaData.appendString(&endLine[0]); } } m_videoRects.setText(textAreaData.getString()); }
void formatHeader() { indent() << "/*" << std::endl; indent() << "** qiLang generated file. DO NOT EDIT" << std::endl; indent() << "*/" << std::endl; indent() << "#include <qi/type/objecttypebuilder.hpp>" << std::endl; for (unsigned i = 0; i < _includes.size(); ++i) { indent() << "#include " << _includes.at(i) << std::endl; } indent() << std::endl; }
/** 1 / Check for missing or multiple package declaration * 2 / Check that the directory path and package name match * 3 / register the content of the file to the package */ bool PackageManager::addFileToPackage(const std::string& absfile, const FileReaderPtr& file, ParseResultPtr& pr) { // 1 NodePtrVector result; result = findNode(pr->ast, NodeType_Package); if (result.size() == 0) { pr->addDiag(Diagnostic(DiagnosticType_Error, "missing package declaration", Location(file->filename()))); return false; } if (result.size() > 1) { for (unsigned i = 1; i < result.size(); ++i) { pr->addDiag(Diagnostic(DiagnosticType_Error, "extra package declaration", result.at(i)->loc())); } pr->addDiag(Diagnostic(DiagnosticType_Info, "previous declared here", result.at(0)->loc())); return false; } std::string pkgname = extractPackageName(result.at(0)); // 2 qi::Path pf(file->filename()); StringVector leafs = splitPkgName(pkgname); qi::Path dirname; qi::Path cur = pf.parent().absolute(); for (unsigned i = 0; i < leafs.size(); ++i) { dirname = qi::Path(cur.filename()) / dirname; cur = cur.parent(); if (cur.isEmpty()) break; } qi::Path p = pf.parent().absolute(); for (int i = leafs.size() - 1; i >= 0; --i) { std::string par = p.filename(); if (par != leafs.at(i)) { pr->addDiag(Diagnostic(DiagnosticType_Error, "package name '" + pkgname + "' do not match parent directory name '" + (std::string)dirname + "'", result.at(0)->loc())); return false; } p = p.parent(); } std::string pkgpath = p.absolute().str(); addInclude(pkgpath); addPackage(pkgname); pr->package = pkgname; package(pkgname)->setContent(absfile, pr); return true; }
/*! * For a given directory name, extract all the files from that directory as well as * from all its sub-directories and store the filenames in the fileList vector. * * \param folder folder to list * \param fileExtList list of file extensions to search * \param fileList list of files in folder * \param symLinks follow Unix links? * * \return path exists and is a directory */ bool CUtil::ListAllFiles(string &folder, StringVector &fileExtList, StringVector &fileList, bool symLinks) { StringVector tmpList; string file; size_t i, n; folder = CUtil::TrimString(folder); #ifdef UNIX // skip links if user specified struct stat inodeData; if (!symLinks && (lstat(folder.c_str(), &inodeData) < 0 || S_ISLNK(inodeData.st_mode))) return(false); #endif // process folder if (!GetFileList(tmpList, folder, symLinks)) return(false); // read through tmpList and get the names of all the files in the directory mentioned for (n = 0; n < tmpList.size(); n++) { file = tmpList.at(n); // if no-extension filtering, each file is pushed into the fileList if (fileExtList.at(0) == "*.*" || fileExtList.at(0) == "*") fileList.push_back(file); else { // for each extension, if file extension matches with the extension, the file is pushed into the fileList for (i = 0; i < fileExtList.size(); i++) { if (MatchFilename(ExtractFilename(file), fileExtList.at(i))) fileList.push_back(file); } } } tmpList.clear(); return(true); }
void CompositionHandler::ExecuteServersShaderRequest(const StringVector ¶meters) { std::string effect_number = parameters.at(0); std::string enable = parameters.at(1); std::string effect_name; if(enable == "True") { effect_name = MapNumberToEffectName(effect_number); if (!effect_name.empty()) AddCompositorForViewport(effect_name); } else if(enable == "False") { effect_name = MapNumberToEffectName(effect_number); if (!effect_name.empty()) RemoveCompositorFromViewport(effect_name); } //12 (default, bloom (?)) //4 (water) }
void formatHeader() { indent() << "/*" << std::endl; indent() << "** qiLang generated file. DO NOT EDIT" << std::endl; indent() << "*/" << std::endl; indent() << "#pragma once" << std::endl; std::string headGuard = filenameToCppHeaderGuard(_pr->package, _pr->filename); indent() << "#ifndef " << headGuard << std::endl; indent() << "#define " << headGuard << std::endl; indent() << std::endl; for (unsigned i = 0; i < _includes.size(); ++i) { indent() << "#include " << _includes.at(i) << std::endl; } indent() << std::endl; }
void PackageManager::parseDir(const std::string& dirname) { qiLogVerbose() << "parsing dir: " << dirname; qi::Path fsp(dirname); if (!fsp.isDir()) throw std::runtime_error(dirname + " is not a directory"); StringVector resdir; std::unordered_set<std::string> resfile; locateFileInDir(dirname, &resfile, &resdir); for (const auto& currResfile : resfile) parseFile(newFileReader(currResfile)); for (unsigned i = 0; i < resdir.size(); ++i) parseDir(dirname + "/" + resdir.at(i)); }
bool EnvironmentModule::HandleNetworkEvent(event_id_t event_id, Foundation::EventDataInterface* data) { ProtocolUtilities::NetworkEventInboundData *netdata = checked_static_cast<ProtocolUtilities::NetworkEventInboundData *>(data); assert(netdata); switch(event_id) { case RexNetMsgLayerData: { if(terrain_.get()) { static int count = 0; bool kill_event = terrain_->HandleOSNE_LayerData(netdata); if (environment_editor_) environment_editor_->UpdateTerrain(); return kill_event; } } case RexNetMsgGenericMessage: { ProtocolUtilities::NetInMessage &msg = *netdata->message; std::string methodname = ProtocolUtilities::ParseGenericMessageMethod(msg); if (methodname == "RexPostP") { OgreRenderer::Renderer *renderer = framework_->GetService<OgreRenderer::Renderer>(); if (renderer) { StringVector vec = ProtocolUtilities::ParseGenericMessageParameters(msg); //Since postprocessing effect was enabled/disabled elsewhere, we have to notify the dialog about the event. //Also, no need to put effect on from the CompositionHandler since the dialog will notify CompositionHandler when //button is checked if (postprocess_dialog_) { QString effect_name = renderer->GetCompositionHandler()->MapNumberToEffectName(vec.at(0)).c_str(); bool enabled = true; if (vec.at(1) == "False") enabled = false; postprocess_dialog_->EnableEffect(effect_name,enabled); } } } else if(methodname == "RexSky" && sky_.get()) { return GetSkyHandler()->HandleRexGM_RexSky(netdata); } else if (methodname == "RexWaterHeight") { msg.ResetReading(); msg.SkipToFirstVariableByName("Parameter"); // Variable block begins, should have currently (at least) 1 instances. size_t instance_count = msg.ReadCurrentBlockInstanceCount(); if (instance_count < 1) return false; if (water_.get() != 0) { std::string message = msg.ReadString(); // Convert to float. try { float height = boost::lexical_cast<float>(message); water_->SetWaterHeight(height); } catch(boost::bad_lexical_cast&) { } } } else if (methodname == "RexDrawWater") { msg.ResetReading(); msg.SkipToFirstVariableByName("Parameter"); // Variable block begins, should have currently (at least) 1 instances. size_t instance_count = msg.ReadCurrentBlockInstanceCount(); if (instance_count < 1 ) return false; std::string message = msg.ReadString(); bool draw = ParseBool(message); if (draw) if (water_.get()) water_->CreateWaterGeometry(); else CreateWater(); else water_->RemoveWaterGeometry(); } else if (methodname == "RexFog") { StringVector parameters = ProtocolUtilities::ParseGenericMessageParameters(msg); if ( parameters.size() < 5) return false; // may have , instead of . so replace ReplaceCharInplace(parameters[0], ',', '.'); ReplaceCharInplace(parameters[1], ',', '.'); ReplaceCharInplace(parameters[2], ',', '.'); ReplaceCharInplace(parameters[3], ',', '.'); ReplaceCharInplace(parameters[4], ',', '.'); float fogStart = 0.0, fogEnd = 0.0, fogC_r = 0.0, fogC_g = 0.0, fogC_b = 0.0; try { fogStart = boost::lexical_cast<float>(parameters[0]); fogEnd = boost::lexical_cast<float>(parameters[1]); fogC_r = boost::lexical_cast<float>(parameters[2]); fogC_g = boost::lexical_cast<float>(parameters[3]); fogC_b = boost::lexical_cast<float>(parameters[4]); } catch(boost::bad_lexical_cast&) { return false; } if (environment_ != 0) { // Adjust fog. QVector<float> color; color<<fogC_r<<fogC_g<<fogC_b; environment_->SetWaterFog(fogStart, fogEnd, color); } } else if (methodname == "RexAmbientL") { /** * Deals RexAmbientLight message. **/ StringVector parameters = ProtocolUtilities::ParseGenericMessageParameters(msg); if ( parameters.size() < 3) return false; // may have , instead of . so replace ReplaceCharInplace(parameters[0], ',', '.'); ReplaceCharInplace(parameters[1], ',', '.'); ReplaceCharInplace(parameters[2], ',', '.'); const QChar empty(' '); StringVector sun_light_direction = SplitString(parameters[0].c_str(), empty.toAscii() ); StringVector sun_light_color = SplitString(parameters[1].c_str(), empty.toAscii()); StringVector ambient_light_color = SplitString(parameters[2].c_str(), empty.toAscii()); if ( environment_ != 0 ) { environment_->SetSunDirection(environment_->ConvertToQVector<float>(sun_light_direction)); environment_->SetSunColor(environment_->ConvertToQVector<float>(sun_light_color)); environment_->SetAmbientLight(environment_->ConvertToQVector<float>(ambient_light_color)); } } } case RexNetMsgSimulatorViewerTimeMessage: { if (environment_!= 0) return environment_->HandleSimulatorViewerTimeMessage(netdata); break; } case RexNetMsgRegionHandshake: { bool kill_event = HandleOSNE_RegionHandshake(netdata); if (environment_editor_) environment_editor_->UpdateTerrainTextureRanges(); return kill_event; } case RexNetMsgRegionInfo: { if (waiting_for_regioninfomessage_) { currentWorldStream_->SendTextureCommitMessage(); waiting_for_regioninfomessage_ = false; } } } return false; }