Beispiel #1
0
void AlignmentElement::Shift(int shift)
{
	ContainerType  newColl;

	ContainerType::const_iterator iter;
	for (iter = m_collection.begin() ; iter != m_collection.end() ; ++iter){
		if (*iter!=-1) newColl.insert(*iter + shift);	
		else newColl.insert(*iter);	
	}
	m_collection = newColl;
}
Beispiel #2
0
void Storage::loadDataFromStream(ContainerType& container, std::istream& stream)
{
    std::string line;
    while (!stream.eof() && !stream.fail())
    {
        std::getline( stream, line );
        if (!line.empty() && *line.rbegin() == '\r')
            line.resize(line.size() - 1);

        if (!line.empty())
        {
            line = mEncoder->getUtf8(line);

            size_t tab_pos = line.find('\t');
            if (tab_pos != std::string::npos && tab_pos > 0 && tab_pos < line.size() - 1)
            {
                std::string key = line.substr(0, tab_pos);
                std::string value = line.substr(tab_pos + 1);

                if (!key.empty() && !value.empty())
                    container.insert(std::make_pair(key, value));
            }
        }
    }
}
Beispiel #3
0
 void parse(std::istream& ) override
 {
   // ignore istream, just enter something into the map
   elements_.insert(std::make_pair("hydrogen", 1.0));
   elements_.insert(std::make_pair("oxygen", 16.0));
 }
Beispiel #4
0
QVariant QJson::parseObject(const QString &json, int &index, DecodeOptions options, bool &success, QString *errorMessage)
{
	Q_ASSERT(json[index] == '{');
	index++;
	skipWhitespace(json, index);

	ContainerType object;

	while (checkAvailable(json, index, success, errorMessage))
	{
		if (json[index] == QChar::fromLatin1('}'))
		{
			index++;
			return object;
		}
		else
		{
			QString key = QJson::parseValue(json, index, options, success, errorMessage).toString();
			if (!success)
				return QVariant();

			skipWhitespace(json, index);
			checkAvailable(json, index, success, errorMessage);

			if (json[index] == QChar::fromLatin1(':'))
				index++;
			else
			{
				success = false;
				if (errorMessage)
					*errorMessage = QString("Expected colon at position %1").arg(index);
				return QVariant();
			}

			skipWhitespace(json, index);

			QVariant value = QJson::parseValue(json, index, options, success, errorMessage);
			if (!success)
				return QVariant();

			// Add the key / value pair to the object
			object.insert(key, value);

			int skippedWhitespaces = skipWhitespace(json, index);
			checkAvailable(json, index, success, errorMessage);

			switch (json[index].toLatin1())
			{
			case ',':
				index++;
				skipWhitespace(json, index);
				break;

			case '}':
				//'}' will be processed in the next iteration
				break;

			default:
				// Only allow missing comma if there is at least one whitespace instead of the comma!
				if ((options & AllowMissingComma) && skippedWhitespaces > 0)
					break;
				else
				{
					success = false;
					if (errorMessage)
						*errorMessage = QString("Unexpected character at index %1").arg(index);
					return QVariant();
				}
			}
		}
	}

	return QVariant();
}
 virtual void parse(std::istream& )
 {
   // ignore istream, just enter something into the map
   elements_.insert(std::make_pair("A", 71.03711));
   elements_.insert(std::make_pair("R", 156.10111));
 }
Beispiel #6
0
    TyErrorId
    extractConfigOptionListImpl(
            const AnnotatorContext& crclConfig,
            const UnicodeString* cpclConfigGroup,
            const ConfigOptionInfo::StOptionInfo& crclOptionInfo,
            ContainerType& rclTargetContainer,
            ElementType* /*not used, just for type information since ContainerType::value_type does not work with HP compiler*/
    ) {
        assert(crclOptionInfo.bOptionIsMultiValued);
        TyErrorId utErrId = UIMA_ERR_NONE;
        size_t i;
#if defined(__HPX_ACC__) || defined(__xlC__) || defined(__GNUC__)
        ElementType tTemp;
#else
    ContainerType::value_type tTemp;
#endif

#if defined(__SUNPRO_CC)
    std::vector<ContainerType::value_type> elements;
#else
        std::vector<ElementType> elements;
#endif

        if (EXISTS(cpclConfigGroup)) {
            crclConfig.extractValue(*cpclConfigGroup, crclOptionInfo.cpszOptionName, elements);
        } else {
            crclConfig.extractValue(crclOptionInfo.cpszOptionName, elements);
        }

        for (i = 0; i < elements.size(); ++i) {
            rclTargetContainer.insert(rclTargetContainer.end(), elements[i]);
        }

        if (utErrId != UIMA_ERR_NONE || (elements.size() == 0)) { // could not find option or value(s)
            if (crclOptionInfo.uiNbrOfValuesRequired != 0
                || crclOptionInfo.cpszDefaultValueAsString == NULL) {
                // required value not there: return error we got from config
                return utErrId;
            }
            std::vector<std::string> vecTmpStrings;
            delimitedString2Vector(
                    vecTmpStrings,
                    (std::string) crclOptionInfo.cpszDefaultValueAsString,
                    ",",
                    true,   // trim strings
                    false   // insert empty strings
            );
            // our default value too must have the required nbr of values
            assert(vecTmpStrings.size() >= crclOptionInfo.uiNbrOfValuesRequired);

            for (i = 0; i < vecTmpStrings.size(); ++i) {
                convertFromString(vecTmpStrings[i], tTemp);
                // assumes rclTargetContainer to be an STL container
                rclTargetContainer.insert(rclTargetContainer.end(), tTemp);
            }
        }
        if (i < crclOptionInfo.uiNbrOfValuesRequired) {
            /* taph 8/6/1999: ?? maybe we should have a more precise error id:
               UIMA_ERR_CONFIG_REQUIRED_OPTION_HAS_NOT_ENOUGH_VALUES
            */
            return UIMA_ERR_CONFIG_REQUIRED_OPTION_IS_EMPTY;
        }
        return utErrId;
    }