bool DirectoryManager::getSimpleValue(const char *valueTag, char *value)
{
	if (!getStartTag(valueTag))
		return false;
	if (!getNonTag(value))
		return false;
	return getEndTag(valueTag);
}
bool DirectoryManager::getSimpleValue(const char *valueTag, char *value, int maxLen)
{
	char temp[SYNTRO_MAX_NONTAG];

	if (!getStartTag(valueTag))
		return false;
	if (!getNonTag(temp))
		return false;
	if (((int)strlen(temp) >= maxLen) || (maxLen >= SYNTRO_MAX_NONTAG)){
		strcpy(m_lastError, "getSimpleValue - value too long");
		return false;
	}
	strcpy(value, temp);
	return getEndTag(valueTag);
}
void xWebTemplateParser::parseLine(std::string line, std::ofstream& outStream) {
    if ( _parserState == Idle ) {

        std::list<std::string>::iterator it;
        for ( it = _xWebTags.begin(); it != _xWebTags.end(); ++it ) {
            std::string startTag = getStartTag(*it);
            if ( line.find(startTag) != std::string::npos ) {
                _currentElement.clear();

                _parserState = InTag;
                _currentTagIndex = it;

                std::string::size_type index = line.find(startTag);

                outStream << line.substr(0, index);

                line = line.substr(index);

                // reneter state machine
                parseLine(line, outStream);
                return;
            }
        }

        outStream << line << "\n";;
    }
    else if ( _parserState == InTag ) {
        std::string endTag = getEndTag(*_currentTagIndex);
        if ( line.find(endTag) != std::string::npos ) {

            std::string::size_type index = line.find(endTag);

            _currentElement.append(line.substr(0, index + endTag.length()));

            processCurrentElement(outStream);

            outStream << line.substr(index + endTag.length());

            _parserState = Idle;
            _currentTagIndex = _xWebTags.end();
        }
        else {
            _currentElement.append(line);
        }
    }
}
    HistoryEntry MPIConnection::recv()
    {
        int_type tmpBool = 0;

        MPI_Test(&_isFree[_currentReceiveIndex], &tmpBool, MPI_STATUS_IGNORE);
        if (tmpBool > 0)
        {
            HistoryEntry res = _buffer[_currentReceiveIndex];  // todo real copy
            _currentReceiveIndex = nextReceiveIndex();
            MPI_Irecv(_buffer[_currentReceiveIndex].data(), _buffer[_currentReceiveIndex].dataSize(), MPI_BYTE, _plan.sourceRank, getStartTag() + _currentReceiveIndex,
            MPI_COMM_WORLD,
                      &_isFree[_currentReceiveIndex]);  //keep listening for the next communication on this buffer
            return res;
        }

        return HistoryEntry::invalid();
    }
 bool MPIConnection::send(const HistoryEntry & in)
 {
     //is free?
     int_type tmpBool = 0;
     if (_buffer[_currentSendIndex].isFree())
         tmpBool = 1;
     else
         MPI_Test(&_isFree[_currentSendIndex], &tmpBool, MPI_STATUS_IGNORE);
     //yes:
     if (tmpBool > 0)
     {
         _buffer[_currentSendIndex] = in;  // todo fast copy
         MPI_Isend(_buffer[_currentSendIndex].data(), _buffer[_currentSendIndex].dataSize(), MPI_BYTE, _plan.destRank, getStartTag() + _currentSendIndex,
         MPI_COMM_WORLD,
                   &_isFree[_currentSendIndex]);
         _currentSendIndex = nextSendIndex();
         return true;
     }
     //no:
     return false;
 }
 void MPIConnection::initialize(const std::string & fmuName)
 {
     if (!isOutgoing(fmuName))
     {
         for (size_type i = 0; i < _numOpenConns; ++i)
         {
             //  // Call recv, so the corresponding MPI_Isends aren't blocked
             MPI_Irecv(_buffer[i].data(), _buffer[i].dataSize(), MPI_BYTE, _plan.sourceRank, getStartTag() + i, MPI_COMM_WORLD, &_isFree[i]);
         }
     }
 }
Exemple #7
0
bool injectXml(QString defaultFile, QStringList fileList, QString fileSuffix){
    qDebug() << "Injecting" << fileList.count() << "audio files into" << fileSuffix;
    // Open default xml file and make a list of all tags
    QFile audio_file(defaultFile);
    if(!audio_file.open(QIODevice::ReadOnly)){
        return false;
    }
    QDomDocument audio;
    audio.setContent(&audio_file);
    audio_file.close();

    QString root_tag = getRootTag(fileSuffix);
    QString start_tag = getStartTag(fileSuffix);
    QString id_tag = getIDTag(fileSuffix);

    QStringList audio_tag_list;
    QDomElement audio_tag;
    if(fileSuffix == "AudioDefines.xml"){
        audio_tag = audio.firstChildElement(root_tag).firstChildElement("SoundDatas").firstChildElement(start_tag).toElement();
    }
    else{
        audio_tag = audio.firstChildElement(root_tag).firstChildElement(start_tag).toElement();
    }
    for(;!audio_tag.isNull();audio_tag = audio_tag.nextSiblingElement()){
        // Check if tag exists in the base file
        audio_tag_list << audio_tag.firstChildElement(id_tag).firstChild().nodeValue();
    }

    // List all files with the right suffix
    int total_new = 0;
    foreach(QString fileName, fileList){
        // For each file, for each tag ID, check if exists and inject all dependencies if not.
        if(fileName.endsWith(fileSuffix)){
            QFile file(fileName);
            file.open(QIODevice::ReadOnly);
            QDomDocument xml;
            xml.setContent(&file);
            file.close();
            QDomElement entity;
            if(fileSuffix == "AudioDefines.xml"){
                entity = xml.firstChildElement(root_tag).firstChildElement("SoundDatas").firstChildElement(start_tag).toElement();
            }
            else{
                entity = xml.firstChildElement(root_tag).firstChildElement(start_tag).toElement();
            }
            QList<QDomElement> node_list;
            for(entity;!entity.isNull();entity = entity.nextSiblingElement()){
                // Check if tag exists in the base file
                QString tag = entity.firstChildElement(id_tag).firstChild().nodeValue();
                int j = 0;
                foreach(QString entry, audio_tag_list){
                    if(entry == tag){
                        j++;
                    }
                }
                if(j == 0){
                    total_new++;
                    // Inject all dependencies to the xml file
                    audio_tag_list << tag;
                    node_list << entity;
                }
            }
            foreach(QDomElement element, node_list){
            if(fileSuffix == "AudioDefines.xml"){
                audio.firstChildElement(root_tag).firstChildElement("SoundDatas").appendChild(element);
            }
            else{
                audio.firstChildElement(root_tag).appendChild(element);
            }
            }
        }
    }