コード例 #1
0
int CompositeChannelBuffer::getBytes(int index, const ChannelBufferPtr& dst, int dstIndex, int length) const {
    int componentId = getComponentId(index);

    if (index > (capacity() - length) || dstIndex > (dst->capacity() - length)) {
        CETTY_NDC_SCOPE();
        throw RangeException("CompositeChannelBuffer getBytes out of range.");
    }

    int i = componentId;
    int transferredBytes = length;

    while (length > 0) {
        const ChannelBufferPtr& s = components[i];
        int adjustment = indices[i];
        int localLength = std::min(length, s->capacity() - (index - adjustment));

        s->getBytes(index - adjustment, dst, dstIndex, localLength);

        index += localLength;
        dstIndex += localLength;
        length -= localLength;
        ++i;
    }

    return transferredBytes;
}
コード例 #2
0
Tetris::Tetromino * Tetris::Tetromino::RandomTetromino(int x, int y)
{
	int randomNum = 7;
	while(randomNum > 6)
	{
		randomNum = rand() % 10;
	}

	switch (randomNum)
	{
	case 0:
		  return new TetrominoI(x, y);
	case 1:
		  return new TetrominoJ(x, y);
	case 2:
		  return new TetrominoL(x, y);
	case 3:
		  return new TetrominoO(x, y);
	case 4:
		  return new TetrominoT(x, y);
	case 5:
		  return new TetrominoS(x, y);
	case 6:
		  return new TetrominoZ(x, y);
	default:
		throw RangeException();
	}
}
コード例 #3
0
void Range::throwException(int exceptioncode) const
{
    if (!exceptioncode)
        return;

    // ### also check for CSS & other exceptions?
    if (exceptioncode >= RangeException::_EXCEPTION_OFFSET && exceptioncode <= RangeException::_EXCEPTION_MAX)
        throw RangeException(static_cast<RangeException::RangeExceptionCode>(exceptioncode-RangeException::_EXCEPTION_OFFSET));
    else
        throw DOMException(exceptioncode);
}
コード例 #4
0
const int Tetris::Tetromino::GetBlockPositionY(int i) const
{
	if (i >= 0 && i < BlockCount)
	{
		return offsetY - blocks[i].y;
	}
	else
	{
		throw RangeException();
	}
	//return 0;
}
コード例 #5
0
ファイル: Var.cpp プロジェクト: Chingliu/poco
Var& Var::getAt(std::size_t n)
{
	if (isVector())
		return holderImpl<std::vector<Var>,
			InvalidAccessException>("Not a vector.")->operator[](n);
	else if (isList())
		return holderImpl<std::list<Var>,
			InvalidAccessException>("Not a list.")->operator[](n);
	else if (isDeque())
		return holderImpl<std::deque<Var>,
			InvalidAccessException>("Not a deque.")->operator[](n);
	else if (isStruct())
		return structIndexOperator(holderImpl<Struct<int>,
			InvalidAccessException>("Not a struct."), static_cast<int>(n));
	else if (!isString() && !isEmpty() && (n == 0))
		return *this;
	
	throw RangeException("Index out of bounds.");
}
コード例 #6
0
ファイル: RecordSet.cpp プロジェクト: RobertAcksel/poco
Row& RecordSet::row(std::size_t pos)
{
	std::size_t rowCnt = rowCount();
	if (0 == rowCnt || pos > rowCnt - 1)
		throw RangeException("Invalid recordset row requested.");

	RowMap::const_iterator it = _rowMap.find(pos);
	Row* pRow = 0;
	std::size_t columns = columnCount();
	if (it == _rowMap.end())
	{
		if (_rowMap.size())
		{
			//reuse first row column names and sorting fields to save some memory 
			pRow = new Row(_rowMap.begin()->second->names(),
				_rowMap.begin()->second->getSortMap(),
				getRowFormatter());

			for (std::size_t col = 0; col < columns; ++col)
				pRow->set(col, value(col, pos));
		}
		else 
		{
			pRow = new Row;
			pRow->setFormatter(getRowFormatter());
			for (std::size_t col = 0; col < columns; ++col)
				pRow->append(metaColumn(static_cast<UInt32>(col)).name(), value(col, pos));
		}

		_rowMap.insert(RowMap::value_type(pos, pRow));
	}
	else 
	{
		pRow = it->second;
		poco_check_ptr (pRow);
	}

	return *pRow;
}
コード例 #7
0
ファイル: range.hpp プロジェクト: benjones/cppitertools
 Range<T> range(T start, T stop, T step) {
     if (step == 0) {
         throw RangeException();
     }
     return {start, stop, step};
 }
コード例 #8
0
ファイル: linearAlgebra.cpp プロジェクト: jpouderoux/core
double& Vector::operator[](int i) {
   if (i < 0 || i >= dim) throw RangeException();
   return _rep[i];
}