void Buffer::BlockCopy(T src[], int srcOffset, T dst[], int dstOffset, int count) { if (src == null) throw ArgumentNullException("src"); if (dst == null) throw ArgumentNullException("dst"); if (srcOffset < 0) throw ArgumentOutOfRangeException("srcOffset", "Non-negative number required."); if (dstOffset < 0) throw ArgumentOutOfRangeException("dstOffset", "Non-negative number required."); if (count < 0) throw ArgumentOutOfRangeException("count", "Non-negative number required."); if ((srcOffset > ByteLength(src) - count) || (dstOffset > ByteLength(dst) - count)) throw ArgumentException("Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection."); for(int i = srcOffset, j = dstOffset; i < (srcOffset + count); i++, j++) { dst[j] = src[i]; } }
const char& String::operator[](int index) const { if (index >= _length) { throw ArgumentOutOfRangeException("index exceeds string length"); } else if (index < 0) { throw ArgumentOutOfRangeException("index must be greater than zero"); } return (_data[index]); }
String String::Substring(int startIndex) const { if (startIndex >= _length) { throw ArgumentOutOfRangeException("startIndex exceeds string length"); } else if (startIndex < 0) { throw ArgumentOutOfRangeException("startIndex must be greater than or equal to zero"); } return String(_data + startIndex); }
String String::Substring(int startIndex, int count) const { if ((startIndex + count) >= _length) { throw ArgumentOutOfRangeException("startIndex exceeds string length"); } else if (startIndex < 0) { throw ArgumentOutOfRangeException("startIndex must be greater than or equal to zero"); } else if (count <= 0) { throw ArgumentOutOfRangeException("length must be greater than zero"); } return String(_data, startIndex, count); }
void MemoryStream::Position(int64 value) { CheckIfClosedThrowDisposed (); if(value < 0) throw ArgumentOutOfRangeException (L"value", L"Position cannot be negative" ); if(value > Int32::MaxValue) throw ArgumentOutOfRangeException(L"value", L"Position must be non-negative and less than 2^31 - 1 - origin"); _position = _initialIndex + (int32)value; }
void String::RemoveAt(int index) { // check arguments if (index >= _length) { throw ArgumentOutOfRangeException("index exceeds string length"); } else if (index < 0) { throw ArgumentOutOfRangeException("index must be greater than zero"); } for (int i = index; i < _length; i++) { _data[i] = _data[i + 1]; } _length -= 1; }
char String::operator[](unsigned int index) const { if (index >= Length()) throw ArgumentOutOfRangeException(); return buff[index]; }
void Buffer::SetByte(T array[], int index, byte value) { if (index < 0 || index >= ByteLength(array)) throw ArgumentOutOfRangeException ("index", "Value must be non-negative and less than the size of the collection."); SetByteInternal(array, index, value); }
byte Buffer::GetByte(T array[], int index) { if (index < 0 || index >= ByteLength(array)) throw ArgumentOutOfRangeException("index", "Value must be non-negative and less than the size of the collection."); return ((byte *) &array[index]); }
void MemoryStream::Write(ByteArray& buffer, int32 offset, int32 count) { if(buffer.IsNull()) throw ArgumentNullException(L"buffer"); if (offset < 0 || count < 0) throw ArgumentOutOfRangeException (); if((int32)buffer.Length() - offset < count) throw ArgumentException(L"offset+count", L"The size of the buffer is less than offset + count."); CheckIfClosedThrowDisposed (); if(!CanWrite()) throw NotSupportedException(L"Cannot write to this stream."); // reordered to avoid possible integer overflow if(_position > _length - count) Expand(_position + count); Buffer::BlockCopy(buffer, offset, (*_internalBuffer), _position, count); _position += count; if(_position >= _length) _length = _position; }
void MemoryStream::SetLength(int64 value) { if(!_expandable && value > _capacity) throw NotSupportedException(L"Expanding this MemoryStream is not supported"); CheckIfClosedThrowDisposed (); if(!_canWrite) { throw NotSupportedException (L"Cannot write to this MemoryStream"); } // LAMESPEC: AGAIN! It says to throw this exception if value is // greater than "the maximum length of the MemoryStream". I haven't // seen anywhere mention what the maximum length of a MemoryStream is and // since we're this far this memory stream is expandable. if (value < 0 || (value + _initialIndex) > (int64)Int32::MaxValue) throw ArgumentOutOfRangeException (); int32 newSize = (int32)value + _initialIndex; if(newSize > _length) Expand(newSize); else if(newSize < _length) // Postpone the call to Array.Clear till expand time _dirty_bytes += _length - newSize; _length = newSize; if(_position > _length) _position = _length; }
int64 MemoryStream::Seek(int64 offset, SeekOrigin loc) { CheckIfClosedThrowDisposed (); if(offset > (int64)Int32::MaxValue) throw ArgumentOutOfRangeException(L"Offset out of range. " + offset); int32 refPoint; switch(loc) { case SeekOrigin::Begin: if(offset < 0) throw IOException(L"Attempted to seek before start of MemoryStream."); refPoint = _initialIndex; break; case SeekOrigin::Current: refPoint = _position; break; case SeekOrigin::End: refPoint = _length; break; default: throw ArgumentException(L"loc", L"Invalid SeekOrigin"); } refPoint += (int32)offset; if(refPoint < _initialIndex) throw IOException(L"Attempted to seek before start of MemoryStream."); _position = refPoint; return _position; }
void RtzCountdownEvent::AddCount(int count) { int num; if(count <= 0) { throw gcnew ArgumentOutOfRangeException("count"); } if(_disposed) { throw gcnew ObjectDisposedException("RtzCountdownEvent"); } addLoop: num = _currentCount; if(Interlocked::CompareExchange(_currentCount, num + count, num) != num) { Thread::SpinWait(1); goto addLoop; } if(num == count) { _event->Reset(); } }
array<System::Byte>^ zDBBinaryReader::ToBytes(int offset, int length) { const unsigned char* puData; // Pointer into raw data array<System::Byte>^ rg; // Managed byte array of data PinnedBytePtr pinRg; // Pinned pointer into rg[] CHECK_DISPOSED(m_disposed); if(offset < 0) throw gcnew ArgumentException(); if(length < 0) throw gcnew ArgumentException(); if((offset + length) > m_cb) throw gcnew ArgumentOutOfRangeException(); // Special case: If the caller wants zero bytes, don't go pinning // pointers and copying nothing. Just return what they want if(length == 0) return gcnew array<System::Byte>(0); rg = gcnew array<System::Byte>(length); // Create return array pinRg = &rg[0]; // Pin and get a pointer // Only copy the amount of data that the caller is looking for puData = reinterpret_cast<const unsigned char*>(sqlite3_column_blob(m_pStatement->Handle, m_ordinal)); memcpy_s(pinRg, length, puData + offset, length); return rg; }
void String::Resize(int count) { // check argument if (count < 0) { throw ArgumentOutOfRangeException("count must be greater than zero"); } if (count <= _capacity) { _data[count] = 0; // check for new length if (count < _length) { _length = count; } } else { // new buffer char* buffer = new char[count]; // copy old buffer delete it afterwards strncpy(buffer, _data, _length); delete[] _data; // set internal buffer and length _data = buffer; _length = _capacity = count; } }
bool RtzCountdownEvent::Signal(int count) { int num; if(count <= 0) { throw gcnew ArgumentOutOfRangeException("count"); } if(_disposed) { throw gcnew ObjectDisposedException("RtzCountdownEvent"); } signalLoop: num = _currentCount; int newCount = Math::Max(0, num - count); if(Interlocked::CompareExchange(_currentCount, newCount, num) != num) { Thread::SpinWait(1); goto signalLoop; } if(num <= count) { _event->Set(); return true; } return false; }
Shape^ RigidActor::GetShape(int index) { if (index < 0 || index >= _shapes->Count) throw gcnew ArgumentOutOfRangeException("index"); return _shapes[index]; }
String String::Substring(unsigned int startIndex) const { if (!buff || startIndex > Length()) throw ArgumentOutOfRangeException(); int length = Length() - startIndex; return Substring(startIndex, length); }
Visual* UIElement::GetChild(size_t index) { if (index > 0 || get_ShadowTree() == nullptr) { raise(ArgumentOutOfRangeException()); } return get_ShadowTree(); }
void String::Insert(int index, const char& ch) { // check arguments if (index > _length) { throw ArgumentOutOfRangeException("index exceeds string length"); } else if (index < 0) { throw ArgumentOutOfRangeException("index must be greater than zero"); } // variables String string(_length + 1); // set result CopyTo(0, string, 0, index); string[index] = ch; CopyTo(index, string, index + 1, _length - index); Lupus::Swap(string, *this); }
File* Archive::GetFile(uint index) { if (index >= m_p->m_files.size()) { raise(ArgumentOutOfRangeException()); } return m_p->m_files[index]; }
/** * @brief Constructs the Simple Cubic System Builder * * @param data Lattice data */ SCSystemBuilder::SCSystemBuilder(const LatticeData& data) : SystemBuilder(), latticeData_(data) { if(data.latticeConstant <= 0) { BOOST_THROW_EXCEPTION(ArgumentOutOfRangeException() << errinfo("Lattice constant must be strictly positive")); } }
String String::Insert(unsigned int startIndex, String value) const { if (startIndex > Length()) throw ArgumentOutOfRangeException(); String ret = Substring(0, startIndex); String end = Substring(startIndex); ret += value + end; return ret; }
SByte zDBBinaryReader::ToSByte(int offset) { const char* pu; // Pointer into the data CHECK_DISPOSED(m_disposed); if(offset < 0) throw gcnew ArgumentException(); if(offset > (m_cb - 1)) throw gcnew ArgumentOutOfRangeException(); pu = reinterpret_cast<const char*>(sqlite3_column_blob(m_pStatement->Handle, m_ordinal)); return *(pu + offset); }
zDBBinaryReader::zDBBinaryReader(StatementHandle* pStatement, int ordinal) : m_pStatement(pStatement), m_ordinal(ordinal) { if(!m_pStatement) throw gcnew ArgumentNullException(); if(ordinal < 0) throw gcnew ArgumentOutOfRangeException(); // Get how much data there is to work with now, so we don't have to // do it each and every time. This is supposed to be an OPTIMIZED // way of working with binary values, after all. m_cb = sqlite3_column_bytes(m_pStatement->Handle, m_ordinal); m_pStatement->AddRef(this); }
void String::CopyTo(int sourceIndex, Vector<char>& vector, int destinationIndex, int count) const { // check argument if ((sourceIndex + count) > _length) { throw ArgumentOutOfRangeException("sourceIndex plus count exceedes string length"); } else if (sourceIndex < 0) { throw ArgumentOutOfRangeException("sourceIndex must be greater than zero"); } else if (count < 0) { throw ArgumentOutOfRangeException("count must be greater than zero"); } else if ((destinationIndex + count) > vector.Count()) { throw ArgumentOutOfRangeException("destinationIndex plus count exceedes collection length"); } else if (destinationIndex < 0) { throw ArgumentOutOfRangeException("destinationIndex must be greater than zero"); } // variables int limit = sourceIndex + count; // copy values for (int i = sourceIndex, j = destinationIndex; i < limit; i++, j++) { vector[j] = _data[i]; } }
String String::Substring(unsigned int startIndex, unsigned int length) const { if (!buff || (startIndex + length) > Length()) throw ArgumentOutOfRangeException(); char *tmpBuff = new char[length + 1]; strncpy(tmpBuff, buff + startIndex, length); tmpBuff[length] = 0; String ret(tmpBuff); delete[] tmpBuff; return ret; }
Vector<String> String::Split(const String& delimiter, int count, StringSplitOptions splitOptions) const { // check argument if (count < 0) { throw ArgumentOutOfRangeException("count is negativ"); } switch (splitOptions) { case StringSplitOptions::None: return SplitEmptyEntries(*this, delimiter, count); case StringSplitOptions::RemoveEmptyEntries: return SplitNoEmptyEntries(*this, delimiter, count); } return Vector<String>(); }
X3DField* Script::getField(uint index) { uint bcount = X3DNode::getFieldCount(); if (index < bcount) { return X3DNode::getField(index); } index -= bcount; if (index >= m_addfields.size()) { raise(ArgumentOutOfRangeException()); } return m_addfields[index]; }
// This is logical child Object* UIElement::ReplaceChild(size_t position, Object* newChild) { raise(ArgumentOutOfRangeException()); return nullptr; /* VisualCollection* visuals = get_Children(); Visual* oldChild = visuals->m_items[position]; oldChild->set_Parent(NULL); oldChild->set_ChildPosition(-1); visuals->m_items[position] = newChild; newChild->set_Parent(this); newChild->set_ChildPosition(position); */ }