Example #1
0
int toInt( const char* in, const char** out/*=0*/ )
{
  if (!in)
  {
    if (out)
      *out = in;
    return 0;
  }

  const bool negative = ('-' == *in);
  if (negative || ('+' == *in))
    ++in;

  const unsigned int unsignedValue = toUint( in, out );
  if (unsignedValue > (unsigned int)INT_MAX)
  {
    if (negative)
      return INT_MIN;
    else
      return INT_MAX;
  }
  else
  {
    if (negative)
      return -((int)unsignedValue);
    else
      return (int)unsignedValue;
  }
}
Example #2
0
NITFAPI(NITF_BOOL) nitf_Field_get(nitf_Field * field,
                                  NITF_DATA * outValue,
                                  nitf_ConvType convType,
                                  size_t length, nitf_Error * error)
{
    NITF_BOOL status = NITF_FAILURE;
    switch (convType)
    {
        case NITF_CONV_UINT:
            status = toUint(field, outValue, length, error);
            break;

        case NITF_CONV_INT:
            status = toInt(field, outValue, length, error);
            break;

        case NITF_CONV_STRING:
            status = toString(field, (char *) outValue, length, error);
            break;

        case NITF_CONV_RAW:
            status = toRaw(field, (char *) outValue, length, error);
            break;

        case NITF_CONV_REAL:
            status = toReal(field, outValue, length, error);
            break;
    }
    return status;
}
Example #3
0
uint ConfigDomain::getUint(const UString &key, uint def) const {
	UString value;
	if (!getKey(key, value))
		return def;

	return toUint(value);
}
std::vector<std::pair<float, unsigned int> > convertBranches(
    std::vector<std::string> branches) {
  std::vector<std::pair<float, unsigned int> > pairs;
  for (unsigned i = 0; i < branches.size(); i++) {
    std::string s = branches[i];
    pairs.push_back(std::make_pair(toFloat(s.substr(0, s.find("% of"))),
                                   toUint(s.substr(s.find("% of") + 5))));
  }
  return pairs;
}
Example #5
0
unsigned int toUint(const std::string& in)
{
  return toUint( in.c_str(), 0 );
}