Ejemplo n.º 1
0
size_t fromString(PVScalarArrayPtr const &pv, StringArray const & from, size_t fromStartIndex = 0)
{
	int processed = 0;
	size_t fromValueCount = from.size();

	// first get count
	if (fromStartIndex >= fromValueCount)
		throw std::runtime_error("not enough of values");

	size_t count;
	istringstream iss(from[fromStartIndex]);
	iss >> count;
	// not fail and entire value is parsed (e.g. to detect 1.2 parsing to 1)
	if (iss.fail() || !iss.eof())
    	throw runtime_error("failed to parse element count value (uint) of field '" + pv->getFieldName() + "' from string value '" + from[fromStartIndex] + "'");
	fromStartIndex++;
	processed++;

	if ((fromStartIndex+count) > fromValueCount)
	{
    	throw runtime_error("not enough array values for field " + pv->getFieldName());
	}

    PVStringArray::svector valueList(count);
    std::copy(from.begin() + fromStartIndex, from.begin() + fromStartIndex + count, valueList.begin());
    processed += count;

    pv->putFrom<string>(freeze(valueList));

    return processed;
}