Exemple #1
0
void StringBuilder::TruncateRightBy( size_t _removeCount )
{
	if( (int)m_pos - (int)_removeCount < 0 ) 
		throw OutOfRangeException("StringBuilder::TruncateRightBy() is longer than the string!");
	m_pos -= _removeCount;
	zeroTerminateIfDebug();
}
Exemple #2
0
void Binder::Translate(BindParameter parameter, int & rootParamIndex, int & rootTableIndex) const {
	auto result = FindMapping(parameter);
	if (result.second != true) {
		throw OutOfRangeException("Parameter was not found.");
	}
	rootParamIndex = result.first->rootParamIndex;
	rootTableIndex = result.first->rootTableIndex;
}
Exemple #3
0
/*
 * vislib::sys::FileNameSequence::FileNameCountElement::SetCounterIndex
 */
void vislib::sys::FileNameSequence::FileNameCountElement::SetCounterIndex(
        unsigned int idx) {
    if (idx >= this->Count()) {
        throw OutOfRangeException(idx, 0, this->Count(), __FILE__, __LINE__);
    }
    this->value = this->minVal + this->step * idx;
    ASSERT(this->value <= this->maxVal);
}
Exemple #4
0
BitArray::BitArrayIterator &BitArray::BitArrayIterator::operator[](size_t index)
{
	if(index >= pArray->arrayBitLength())
		throw OutOfRangeException("BitArrayIterator::operator[]",pArray->arrayLength,byteIndex);
	byteIndex = (size_t)index/8;
	bitIndex = index%8;
	return *this;
}
 void OutOfRangeException::CheckArray(const std::string& file, int line, const std::string& function,
         int index, int max) {
     if (index < 0 || index >= max) {
         std::stringstream ss;
         ss << "index=" << index << " and maximum value is " << max - 1;
         throw OutOfRangeException(file, line, function, ss.str());
     }
 }
Exemple #6
0
void BitArray::BitArrayIterator::SetBitArray(BitArray *bar)
{
	byteIndex = 0;
	bitIndex = 0;
	pArray = bar;
	if(((byteIndex >= pArray->arrayLength) && pArray->arrayLength) || bitIndex > 7)
		throw OutOfRangeException("BitArrayIterator::SetBitArray()",pArray->arrayLength,byteIndex);
}
Exemple #7
0
BitArray::BitArrayIterator::BitArrayIterator(size_t byte, size_t bit, BitArray  *par) throw(OutOfRangeException)
{
	byteIndex = byte;
	bitIndex = bit;
	pArray = par;
	enableOORException = true;
	if(((byteIndex >= pArray->arrayLength) && pArray->arrayLength) || bitIndex > 7)
		throw OutOfRangeException("BitArrayIterator::BitArrayIterator(...)",pArray->arrayLength,byteIndex);
}
Exemple #8
0
void StringBuilder::appendingReplace( size_t _index, const StringBuilder &_string )
{
	if( _index > m_pos ) throw OutOfRangeException("appendingReplace() call index is outside the current array bounds!");
	size_t endIndex = _index + _string.m_pos;
	while( endIndex > m_alloc ) growCapacity();
	if( endIndex > m_pos ) m_pos = endIndex;
	memcpy(&m_buffer[_index],_string.m_buffer,_string.m_pos);
	zeroTerminateIfDebug();
}
Exemple #9
0
void StringBuilder::appendingReplace( size_t _index, char _withChar, size_t _count )
{
	if( _index > m_pos ) throw OutOfRangeException("appendingReplace() call index is outside the current array bounds!");
	size_t endIndex = _index + _count;
	while( endIndex > m_alloc ) growCapacity();
	if( endIndex > m_pos ) m_pos = endIndex;
	memset(&m_buffer[_index],_withChar,_count);
	zeroTerminateIfDebug();
}
Exemple #10
0
void StringBuilder::append( const StringBuilder &_string, size_t _index, size_t _length )
{
	size_t strLen = _string.size();
	if( strLen < (_index+_length) ) throw OutOfRangeException("Range given is outside of the range of the given string!");
	while( (m_pos + _length) > m_alloc ) growCapacity();
	memcpy(&m_buffer[m_pos],&_string.m_buffer[_index],_length);
	m_pos += _length;
	zeroTerminateIfDebug();
}
 /**
  * Sets the coordinate at position @a row and @a col with the value @a v.
  */
 void ForcePlatform::SetCorner(int row, int col, double v)
 {
   if ((row > 3) || (col > 4))
     throw OutOfRangeException("ForcePlatform::SetCorner");
   if (std::fabs(this->m_Corners.coeff(row, col) - v) <= Eigen::NumTraits<Corner::Scalar>::dummy_precision())
     return;
   this->m_Corners.coeffRef(row, col) = v;
   this->Modified();
 };
Exemple #12
0
void StringBuilder::toScreen( size_t _index, size_t _length ) const
{
	if( (_index + _length) > m_pos ) throw OutOfRangeException("toString( size_t _index, size_t _length ) call is outside of current array bounds!");
	if( _length == 0 ) return;
	if( _index+_length == m_alloc ) growCapacity((size_t)1); // make sure we have enough room for the following temproary '/0' termination
	char store = m_buffer[_index+_length]; // store the value
	m_buffer[_index+_length] = '\0'; // *must* zero terminate
	printf("%s",&m_buffer[_index]); // perform the print operation on the now terminated string
	m_buffer[_index+_length] = store;
}
Exemple #13
0
void StringBuilder::erase( size_t _index, size_t _count )
{
	if( (_index + _count) > m_pos ) throw OutOfRangeException("erase() call is outside of current array bounds!");
	m_pos -= _count;
	for( size_t i = _index; i < m_pos; i++ )
	{
		m_buffer[i] = m_buffer[i+_count];
	}
	zeroTerminateIfDebug();
}
Exemple #14
0
void StringBuilder::erase( size_t _index )
{
	if( m_pos == 0 || _index >= m_pos ) throw OutOfRangeException("erase() call is outside of current array bounds!");
	m_pos--;
	for( size_t i = _index; i < m_pos; i++ )
	{
		m_buffer[i] = m_buffer[i+1];
	}
	zeroTerminateIfDebug();
}
Exemple #15
0
void PickResidueRange::setRange(const MoleculeBase &molecule, size_t _StartRes, size_t _EndRes)
{
	if( _StartRes > _EndRes ) throw OutOfRangeException("PickResidueRange requires that the end residue index is after the start index!");
	m_StartResidueIndex = _StartRes;
	m_NResidues = _EndRes - m_StartResidueIndex + 1;
	assertRangeCore(molecule);
	m_StartAtomIndex=molecule.res[_StartRes].ifirst;
	m_NAtoms=molecule.res[_EndRes].ilast - m_StartAtomIndex + 1;
	PickAtomRange::assertRange(molecule);
}
Exemple #16
0
bool StringBuilder::compare( char _c, size_t _index, bool _ignoreCase )const
{
	if( _index >= m_pos ) throw OutOfRangeException("StringBuilder::Compare()");
	if( _ignoreCase )
	{
		return isSameCharIgnoringCase(_c,m_buffer[_index]);
	}
	else
	{
		return _c == m_buffer[_index];
	}
}
Exemple #17
0
std::string StringBuilder::toString( size_t _index, size_t _length ) const
{
	if( (_index + _length) > m_pos ) throw OutOfRangeException("toString( size_t _index, size_t _length ) call is outside of current array bounds!");
	if( m_pos == 0 || _length == 0 )
	{
		return std::string("");
	}
	else
	{
		return std::string(&m_buffer[_index],_length);
	}
}
 /**
  * Set the coordinates of the corner @a idx.
  */
 void ForcePlatform::SetCorner(int idx, double x, double y, double z)
 {
   if (idx >= 4)
     throw OutOfRangeException("ForcePlatform::SetCorner");
   if ((std::fabs(this->m_Corners.coeff(0, idx) - x) <= Eigen::NumTraits<Corner::Scalar>::dummy_precision())
       && (std::fabs(this->m_Corners.coeff(1, idx) - y) <= Eigen::NumTraits<Corner::Scalar>::dummy_precision())
       && (std::fabs(this->m_Corners.coeff(2, idx) - z) <= Eigen::NumTraits<Corner::Scalar>::dummy_precision()))
     return;
   this->m_Corners.coeffRef(0, idx) = x;
   this->m_Corners.coeffRef(1, idx) = y;
   this->m_Corners.coeffRef(2, idx) = z;
   this->Modified();
 };
inline EnumT EnumConverter<EnumT, Generator>::FromString(const std::string & arg) {
	const std::unordered_set<const Record*, FmtHash, FmtHash>* byFmt;
	const std::unordered_set<const Record*, StrHash, StrHash>* byStr;

	GetMaps(&byFmt, &byStr);

	Record key{ {}, arg };
	auto it = byStr->find(&key);
	if (it != byStr->end()) {
		return (*it)->first;
	}
	else {
		throw OutOfRangeException("Could not translate string. Update table or user error.");
	}
}
inline std::string EnumConverter<EnumT, Generator>::ToString(const EnumT & arg) {
	const std::unordered_set<const Record*, FmtHash, FmtHash>* byFmt;
	const std::unordered_set<const Record*, StrHash, StrHash>* byStr;

	GetMaps(&byFmt, &byStr);

	Record key{ arg, {} };
	auto it = byFmt->find(&key);
	if (it != byFmt->end()) {
		return (*it)->second;
	}
	else {
		throw OutOfRangeException("Could not translate format. Update table.");
	}
}
/* returns a list of random movies from repo, throws OutOfRangeException */
DynamicVector<Movie> Controller::getRandomMovies(int howMany)
{
	if (howMany<0 || howMany > this->repository.movies.size())
	{
		throw OutOfRangeException("Size is " + this->repository.movies.size());
	}
	DynamicVector<Movie> list;
	DynamicVector<Movie> shuffledOriginalList = this->repository.movies.clone();
	shuffledOriginalList.shuffle();
	for (int i = 0; i < howMany; i++)
	{
		list.add(shuffledOriginalList[i]);
	}
	return list;
}
Exemple #22
0
BYTE BitArray::GetBit(size_t byte, size_t bit)
{
	if(!arrayLength)
		throw Exception("Throwed from BitArray::GetBit(): Memory has not allocated");
	if(((byte>=arrayLength) && arrayLength) || bit>7)
		throw OutOfRangeException("BitArray::GetBit()",	arrayLength, byte);
	BYTE c = Array::array[byte];
	c = c << bit;
	c = (c & 0x80)>>7;

	//debug
#ifdef _DEBUG
	//cerr << (int)c;
#endif
	return c;
}
    void ClimateByData::UpdateWeather( float time, float dt, RANDOMBASE* pRNG )
    {
        LOG_DEBUG_F("UpdateWeather: time = %f", time);
        int index = 0;

        // Figure out index based on time and number of years of data
        float adjusted_time = time - (DAYSPERYEAR * num_years * int(time / (DAYSPERYEAR * num_years))); // adjust into n-year window

        // now adjust based on number of data points spread over n years, unless monthly, in which case use old way with specific months (28-day February, etc...)
        if(resolution_correction == 1.0f / 30) // monthly
        {
            if(int(adjusted_time)%DAYSPERYEAR < 31)       { index = 0; }
            else if(int(adjusted_time)%DAYSPERYEAR < 59)  { index = 1; }
            else if(int(adjusted_time)%DAYSPERYEAR < 90)  { index = 2; }
            else if(int(adjusted_time)%DAYSPERYEAR < 120) { index = 3; }
            else if(int(adjusted_time)%DAYSPERYEAR < 151) { index = 4; }
            else if(int(adjusted_time)%DAYSPERYEAR < 181) { index = 5; }
            else if(int(adjusted_time)%DAYSPERYEAR < 212) { index = 6; }
            else if(int(adjusted_time)%DAYSPERYEAR < 243) { index = 7; }
            else if(int(adjusted_time)%DAYSPERYEAR < 273) { index = 8; }
            else if(int(adjusted_time)%DAYSPERYEAR < 304) { index = 9; }
            else if(int(adjusted_time)%DAYSPERYEAR < 334) { index = 10; }
            else if(int(adjusted_time)%DAYSPERYEAR < DAYSPERYEAR) { index = 11; }
            index += int(adjusted_time / DAYSPERYEAR) * 12;
        }
        else // everything except monthly
        {
            index = int(adjusted_time * resolution_correction);
        }

        // verify the index is not out of range
        if(index >= num_datapoints)
        {
            //std::cerr << "Climate-By-Data index (" << index << ") is outside data-array range. (num_datapoints = " << num_datapoints << ")." << std::endl;
            throw OutOfRangeException( __FILE__, __LINE__, __FUNCTION__, "index", index, num_datapoints );
        }

        //Now set data-values
        m_airtemperature = airtemperature_data[index];
        m_landtemperature = landtemperature_data[index];
        m_accumulated_rainfall = rainfall_data[index] * resolution_correction * dt; // just the mean rainfall each day
        m_humidity = humidity_data[index];

        Climate::UpdateWeather( time, dt, pRNG ); // call base-class UpdateWeather() to add stochasticity and check values are within valid bounds
    }
Exemple #24
0
bool StringBuilder::compare( const char *_stringB, size_t _indexA, size_t _length, size_t _indexB, bool _ignoreCase ) const
{
	if( ((_indexA + _length) > m_pos) || (_indexB+_length) > strlen(_stringB) ) 
		throw OutOfRangeException("StringBuilder::Compare() bad range");
	if( _ignoreCase )
	{
		for( size_t i = 0; i < _length; i++ )
			if( !isSameCharIgnoringCase(_stringB[_indexB+i],m_buffer[_indexA+i]) ) 
				return false;
	}
	else
	{
		for( size_t i = 0; i < _length; i++ )
			if( _stringB[_indexB+i] != m_buffer[_indexA+i] ) 
				return false;
	}
	return true;
}
Exemple #25
0
/************!!!!!!!!!!!!!!!!!!!*****************/
void BitArray::SetBit(size_t byte, size_t bit, BYTE b)
{
	if(!arrayLength)
		throw Exception("Throwed from BitArray::SetBit(): Memory has not allocated");
	if(((byte>=arrayLength) && arrayLength) || bit>7)
		throw OutOfRangeException("BitArray::SetBit()",arrayLength,byte);

	BYTE c = Array::array[byte];
	BYTE bb = b << 7-bit;
	c = c | bb;
	Array::array[byte] = c;
	//if is the last bit of the last byte
	//if(freeLength==0&&bit==7)
	//{
	//	Array::addMemory(16);			//Add to the array new 16 bytes
	//	//maxByteIndex++;
	//}
}
Exemple #26
0
int StringBuilder::compareValue(const StringBuilder &_stringB, size_t _indexA, size_t _length, size_t _indexB, bool _ignoreCase ) const
{
	if( ((_indexA+_length) > m_pos) || (_indexB+_length) > _stringB.m_pos ) 
		throw OutOfRangeException("StringBuilder::Compare() bad range");
	if( _ignoreCase )
	{
		for( size_t i = 0; i < _length; i++ )
			if( !isSameCharIgnoringCase(_stringB[_indexB+i],m_buffer[_indexA+i]) ) 
				return _stringB[_indexB+i] > m_buffer[_indexA+i] ? -1 : 1;
	}
	else
	{
		for( size_t i = 0; i < _length; i++ )
			if( _stringB[_indexB+i] != m_buffer[_indexA+i] )
				return _stringB[_indexB+i] > m_buffer[_indexA+i] ? -1 : 1;
	}
	return 0;
}
Exemple #27
0
void StringBuilder::replace( size_t _index, const StringBuilder &_string )
{
	if( (_index + _string.m_pos) > m_pos ) throw OutOfRangeException("replace() call is outside of current array bounds!");
	memcpy(&m_buffer[_index],_string.m_buffer,_string.m_pos);
}
Exemple #28
0
void StringBuilder::TruncateLeftBy( size_t _removeCount )
{
	if( (int)m_pos - (int)_removeCount < 0 ) 
		throw OutOfRangeException("StringBuilder::TruncateLeftBy() is longer than the string!"); 
	erase(0,_removeCount);
}
Exemple #29
0
void StringBuilder::replace( size_t _index, const std::string &_string )
{
	size_t length = _string.length();
	if( (_index + length) > m_pos ) throw OutOfRangeException("replace() call is outside of current array bounds!");
	memcpy(&m_buffer[_index],_string.c_str(),length);
}
 /**
  * Returns the corner at index @a idx.
  */
 const ForcePlatform::Corner ForcePlatform::GetCorner(int idx) const
 {
   if (idx >= 4)
     throw OutOfRangeException("ForcePlatform::GetCorner");
   return this->m_Corners.col(idx);
 };