Пример #1
0
      /// <summary>Parses the page identifier</summary>
      /// <param name="pageid">The pageid</param>
      /// <param name="v">The associated game version</param>
      /// <returns>Normalised page ID</returns>
      /// <exception cref="Logic::InvalidValueException">Invalid pageID</exception>
      UINT  LanguageFileReader::ParsePageID(const wstring&  pageid, GameVersion&  v)
      {
         // X2: nnnn 
         if (pageid.length() <= 4)
         {
            v = GameVersion::Threat;
            return _wtoi(pageid.c_str());
         }
         // X3: NNnnnn
         else if (pageid.length() != 6)
            throw InvalidValueException(HERE, VString(L"Invalid page ID '%s'", pageid.c_str()) );

         // X3R: 30nnnn
         else if (pageid.compare(0, 2, L"30") == 0)
            v = GameVersion::Reunion;
         
         // X3TC: 35nnnn
         else if (pageid.compare(0, 2, L"35") == 0)
            v = GameVersion::TerranConflict;

         // X3AP: 38nnnn
         else if (pageid.compare(0, 2, L"38") == 0)
            v = GameVersion::AlbionPrelude;
         else
            throw InvalidValueException(HERE, VString(L"Invalid page ID '%s'", pageid.c_str()) );

         // Convert last four digits of page ID
         return _wtoi(pageid.substr(2).c_str());
      }
Пример #2
0
    Table(const std::vector<std::vector<unsigned>> &initValues):
        size(static_cast<unsigned>(initValues.size())),
        rowCounts(size, std::vector<unsigned>(size + 1, 0)),
        columnCounts(size, std::vector<unsigned>(size + 1, 0)),
        unknownCellCount(size * size),
        deletedTrees(size * size + 1) {

        auto actRow = 0U;
        for (const auto &row : initValues) {
            if (row.size() != size) {
                throw InvalidShapeException();
            }

            std::vector<Cell> rowCells;
            auto actColumn = 0U;
            for (auto value : row) {
                if (value == 0 || value > size) {
                    throw InvalidValueException();
                }
                rowCells.emplace_back(value);

                rowCounts[actRow][value]++;
                columnCounts[actColumn][value]++;

                actColumn++;
            }
            cells.push_back(std::move(rowCells));

            actRow++;
        }
    }
Пример #3
0
void Stsz::ReadContents(Util::Stream& stream) {
  auto startPosition = stream.GetPosition();

  m_version = stream.ReadInteger<uint32_t>();
  m_sampleSize = stream.ReadInteger<uint32_t>();
  m_sampleCount = stream.ReadInteger<uint32_t>();

  if (m_sampleSize == 0) {
    m_entries.reserve(m_sampleCount);

    auto bytesLeft = m_bodySize - (stream.GetPosition() - startPosition);

    while (bytesLeft > 0) {
      // parse entries and add them
      m_entries.push_back(stream.ReadInteger<uint32_t>());
      bytesLeft -= sizeof(uint32_t);
    }

    ARC_ASSERT_MSG(bytesLeft == 0, "Read a different number of entries as the bytes would indicate!");
  }

  // now check that the counts are equal
  if (m_sampleCount != m_entries.size()) {
    throw InvalidValueException("The count in the table and the count reported are not equal!");
  }
}
Пример #4
0
void InstructionStack::checkParam(std::vector<std::string> & tokens, std::string const & param, std::string const & line)
{
	if (param.find(")") == std::string::npos)
		throw SyntacticErrorExceptionException(line, m_countLine);
	split(tokens, param, ')');
	split(tokens, tokens[0], '(');
	if (tokens.size() != 3)
		throw SyntacticErrorExceptionException(line, m_countLine);
	if (!isNumber(tokens[2]))
		throw InvalidValueException(tokens[2], m_countLine);
}
string TextInputWidget::getValue()
{
	if ( this->isValid() )
	{
		this->setValid( true );
		return this->text;
	}
	else
	{
		this->setValid( false );
		throw InvalidValueException();
	}
}
Пример #6
0
void mitk::pa::VolumeManipulator::Log10Image(Volume::Pointer image)
{
  for (unsigned int z = 0; z < image->GetZDim(); z++)
    for (unsigned int y = 0; y < image->GetYDim(); y++)
      for (unsigned int x = 0; x < image->GetXDim(); x++)
      {
        if (image->GetData(x, y, z) < 0)
        {
          MITK_ERROR << "Signal was smaller than 0. There is an error in the input image file.";
          throw InvalidValueException("Signal was smaller than 0. There is an error in the input image file.");
        }
        image->SetData(log10(image->GetData(x, y, z)), x, y, z);
      }
}
Пример #7
0
      /// <summary>Parses the language ID of a language file</summary>
      /// <param name="id">The language identifier</param>
      /// <returns>Game language</returns>
      /// <exception cref="Logic::InvalidValueException">Invalid language ID</exception>
      GameLanguage  LanguageFilenameReader::ParseLanguageID(const wstring& id)
      {
         switch (GameLanguage val = (GameLanguage)_wtoi(id.c_str()))
         {
         case GameLanguage::English:
         case GameLanguage::French:
         case GameLanguage::Italian:
         case GameLanguage::Spanish:
         case GameLanguage::Russian:
         case GameLanguage::Polish:
         case GameLanguage::German:
         case GameLanguage::Czech:
            return val; 

         default:
            // "'%s' is not a valid language ID"
            throw InvalidValueException(HERE, VString(ERR_LANGUAGE_ID_INVALID, id.c_str()));
         }
      }
Пример #8
0
void Alac::ReadContents(Util::Stream& stream) {
  auto initialPosition = stream.GetPosition();
  // first 6 bytes are reserved
  stream.Advance(6);

  m_index = stream.ReadInteger<uint16_t>();

  // 8 bytes reserved
  stream.Advance(8);

  m_numChannels = stream.ReadInteger<uint16_t>();
  m_sampleSize = stream.ReadInteger<uint16_t>();

  // 4 bytes reserved
  stream.Advance(4);

  // Note: documentation claims it is a 32 bit unsigned integer, encoding
  // suggests that is is either a 16 bit integer or a 16.16 floating point
  // number, assuming 16 bit integer.
  // TODO::JT resolve this ambiguity!
  m_sampleRate = stream.ReadInteger<uint16_t>();

  // 2 bytes of unknown or reserved, see previous note about sample rate
  stream.Advance(2);

  // next begins the inner ALAC box, note: not using normal parsing means due to identical tags!
  // note: assuming 32 bit numbers only! hypothetically this could be 64 bit extended
  // but I'm assuming that this never occurs given the box is not supposed to be more that 48
  // bytes long.
  uint32_t innerSize = stream.ReadInteger<uint32_t>();

  std::string tag = stream.ReadString(4);

  if (innerSize > 0 && tag.compare("alac") == 0) {
    // this box can be either 28 bytes or 52 bytes depending upon whether the channel info is also provided
    // however the first 24 bytes are required and will always be there.
    m_version = stream.ReadInteger<uint32_t>();
    m_samplePerFrame = stream.ReadInteger<uint32_t>();
    m_compatibleVersion = stream.ReadInteger<uint8_t>();

    // sample size is repeated here
    auto otherSampleSize = stream.ReadInteger<uint8_t>();
    m_sampleSize = otherSampleSize;  // not asserting and just assuming mismatch should result in overwrite of value

    // these next 3 are unspecified tuning values, parsing just in case they are ever needed
    m_pb = stream.ReadInteger<uint8_t>();
    m_mb = stream.ReadInteger<uint8_t>();
    m_kb = stream.ReadInteger<uint8_t>();

    // channel count is repeated here
    auto otherChannelCount = stream.ReadInteger<uint8_t>();
    m_numChannels = otherChannelCount;  // assigning anyways as we assume that the inner box is the most truthful

    // maxRun, presently unused but required to be 0x00FF, parse and ignore value
    m_maxRun = stream.ReadInteger<uint16_t>();

    m_maxFrameSize = stream.ReadInteger<uint32_t>();
    m_avgBitRate = stream.ReadInteger<uint32_t>();

    // sample rate is now repeated, ignoring value
    auto otherSampleRate = stream.ReadInteger<uint32_t>();
    m_sampleRate = otherSampleRate;  // same as earlier, assuming inner box is most truthful value

    // I do not have any samples of the channel layout info section that may
    // occupy the remaining bits, simply assuming that it must run to the end
    // of the tag.
    auto bytesRead = stream.GetPosition() - initialPosition;
    if (bytesRead != m_bodySize) {
      // then assuming that there is more data, otherwise we would be at the end
      // of the tag.
      uint32_t channelLayoutSize = stream.ReadInteger<uint32_t>();
      std::string channelTag = stream.ReadString(4);

      // verify tag
      ARC_ASSERT_MSG(channelTag.compare("chan"), "Warning: Encountered unknown tag while parsing ALAC!");
      if (channelLayoutSize > 0 && channelTag.compare("chan") == 0) {
        // then carry on
        // first 4 bytes are version, just ignore
        stream.Advance(4);
        uint32_t channelLayout = stream.ReadInteger<uint32_t>();

        // convert int to enum
        auto enumItr = NumToAlacChannelLayout.find(channelLayout);

        if (enumItr != NumToAlacChannelLayout.end()) {
          m_channelLayout = enumItr->second;
        } else {
          m_channelLayout = AlacChannelLayout::UNKNOWN;
        }

        // remainder is reserved
        stream.Advance(8);
      } else {
        // else ignore, this isn't a very important piece of data
      }
    }
  } else {
    throw InvalidValueException("Encountered unexpected tag while parsing ALAC box!");
  }
}
Пример #9
0
const string& IPAddress::getIP() throw( InvalidValueException )
{
	if( !valid_) throw InvalidValueException();
	return ip_;
}