// ----------------------------------------------------------------------- int main(int Argc_, char *Argv_[]) { struct THelper { static void normalizeFolderName(QString &Value_) { QDir Folder(Value_); Value_ = QDir::toNativeSeparators(Folder.absolutePath()); Q_ASSERT(!Value_.endsWith(QDir::separator())); Value_ += QDir::separator(); } }; QCoreApplication HPro(Argc_, Argv_); // TParameters Parameters; if(!ParseParameters(Argc_, Argv_, Parameters)) { std::cerr << '\n' << std::endl; Usage(); return RETCODE_INVALID_PARAMETERS; } // THelper::normalizeFolderName(Parameters.InputFolder); THelper::normalizeFolderName(Parameters.OutputFolder); TProcessor Processor(Parameters); if(!ProcessFolder(Parameters.InputFolder, Parameters.OutputFolder, Processor)) return RETCODE_PROCESS_ERROR; return RETCODE_OK; }
// ----------------------------------------------------------------------- bool ParseVariables(const char *FileName_, TParameters &Parameters_) { struct TProcessor { TParameters &m_Parameters; QRegExp m_VariableWithValue; QRegExp m_VariableWithoutValue; // TProcessor(TParameters &Parameters_): m_Parameters(Parameters_), m_VariableWithValue("([A-Za-z0-9_]+)\\s*=(.+)"), m_VariableWithoutValue("[A-Za-z0-9_]+") {} // bool processString(const QString &WLine_) { if(m_VariableWithValue.exactMatch(WLine_)) { m_Parameters.Variables.insert(m_VariableWithValue.cap(1), m_VariableWithValue.cap(2)); return true; } if(m_VariableWithoutValue.exactMatch(WLine_)) { m_Parameters.Variables.insert(m_VariableWithValue.cap(0), QString()); return true; } return false; } }; // --- QFile VariablesFile(QString::fromLocal8Bit(FileName_)); if(!VariablesFile.open(QIODevice::ReadOnly | QIODevice::Text)) { std::cerr << "Can't open file: '" << FileName_ << "'."; return false; } // TProcessor Processor(Parameters_); QByteArray Line; QString WLine; while(!VariablesFile.atEnd()) { Line = VariablesFile.readLine(); WLine = QString::fromUtf8(Line.trimmed()); if(WLine.isEmpty() || WLine[0] == QLatin1Char('#')) continue; if(!Processor.processString(WLine)) return false; } return true; }
//逐个处理链表中的每个Segment。要求传递一个函数指针过来,作为处理函数,函数中要求具有 bool fun(Segment *)签名。 //非线程安全版本 void SegmentList::ProcessSegment(bool (*Processor)(Segment *)) { SegmentNode *p = m_lpRoot;//,*p2; while(NULL != p) { //p2 = p->Next; p->Segment->m_Lock->on(); if(false == Processor(p->Segment)) { p->Segment->m_Lock->off(); break; } p->Segment->m_Lock->off(); p = p->Next ; } }
void WaitableSingleJobManager::WaitForJobProcessed() { Processor()->PrioritizeJobAndWait(this, false); }
void WaitableSingleJobManager::AddJobToProcessor(const bool prioritize) { AutoOptionalCriticalSection lock(Processor()->GetCriticalSection()); Processor()->AddJob(&job, prioritize); }