hime_lsize_t Win32Stream::size() { if (m_hFile == INVALID_HANDLE_VALUE) throw InvalidObject("Win32Stream::size"); ULARGE_INTEGER li; li.LowPart = GetFileSize(m_hFile, &li.HighPart); if (li.LowPart == INVALID_FILE_SIZE) Win32ThrowLastError("Win32Stream::seek"); return (hime_lsize_t)li.QuadPart; }
PyObject* Table::cell(quint32 colIndex, quint32 rec){ if(this->ptr()->as<Ilwis::Table>()->isDataLoaded()){ QVariant ret = this->ptr()->as<Ilwis::Table>()->cell(colIndex, rec,false); if (!ret.isValid()) throw std::out_of_range(QString("No attribute in '%1.' column found or record %2 out of bound").arg(colIndex).arg(rec).toStdString()); return QVariant2PyObject(ret); } else { throw InvalidObject("Data of the table is not loaded. Access a feature first."); } }
hime_lsize_t PosixStream::write(const void* src, hime_lsize_t bytes) { if (!m_file) throw InvalidObject("PosixStream::size"); hime_lsize_t ret = fwrite(src, bytes, 1, (FILE*)m_file); ret *= bytes; Stats::IncrementAmount(Stats::BytesWritten, (int64_t)ret); return bytes; }
hime_lsize_t PosixStream::read(void* dst, hime_lsize_t bytes) { if (!m_file) throw InvalidObject("PosixStream::read"); hime_lsize_t ret = fread(dst, bytes, 1, (FILE*)m_file); ret *= bytes; Stats::IncrementAmount(Stats::BytesRead, (int64_t)ret); return bytes; }
hime_lsize_t Win32Stream::write(const void* src, hime_lsize_t bytes) { if (m_hFile == INVALID_HANDLE_VALUE) throw InvalidObject("Win32Stream::write"); DWORD written; if (!WriteFile(m_hFile, src, (DWORD)bytes, &written, NULL)) Win32ThrowLastError("NativeStream::write"); Stats::IncrementAmount(Stats::BytesWritten, (int64_t)written); return (hime_lsize_t)written; }
hime_lsize_t Win32Stream::read(void* dst, hime_lsize_t bytes) { if (m_hFile == INVALID_HANDLE_VALUE) throw InvalidObject("Win32Stream::read"); DWORD read; if (!ReadFile(m_hFile, dst, (DWORD)bytes, &read, NULL)) Win32ThrowLastError("Win32Stream::read '%S'", m_path.c_str()); Stats::IncrementAmount(Stats::BytesRead, (int64_t)read); return (hime_lsize_t)read; }
PyObject* Catalog::items(){ if (this->__bool__()){ std::vector<Ilwis::Resource> itms = this->_catalog->items(); PyObject* ret = newPyTuple(itms.size()); int i = 0; for(auto it = itms.begin(); it < itms.end(); it++ ){ if (!setTupleItem(ret, i, PyUnicodeFromString(it->name().toStdString().data()))){ throw InvalidObject("invalid recource in catalog items"); } i++; } return ret; }else{ return newPyTuple(0); } }
hime_lsize_t Win32Stream::seek(hime_lpos_t offset, IO::SeekOrigin org) { static DWORD worg[] = { FILE_BEGIN, FILE_CURRENT, FILE_END }; if (m_hFile == INVALID_HANDLE_VALUE) throw InvalidObject("Win32Stream::seek"); LARGE_INTEGER li; li.QuadPart = offset; li.LowPart = SetFilePointer(m_hFile, li.LowPart, &li.HighPart, worg[org]); if (li.LowPart == INVALID_SET_FILE_POINTER) Win32ThrowLastError("Win32Stream::seek"); return (hime_lsize_t)li.QuadPart; }
Table* Table::toTable(Object *obj){ Table* ptr = dynamic_cast<Table*>(obj); if(!ptr) throw InvalidObject("cast to Table not possible"); return ptr; }
Catalog *Catalog::toCatalog(IObject *obj){ Catalog* ptr = dynamic_cast<Catalog*>(obj); if(!ptr) throw InvalidObject("cast to Catalog not possible"); return ptr; }
Ilwis::PixelIterator& PixelIterator::ptr() const{ if (!this->__bool__()) throw InvalidObject("use of invalid PixelIterator (ptr)"); return (*this->_ilwisPixelIterator); }
template<typename OutputType, typename RangeType, typename IlwOutput, typename IlwRange> Ilwis::RangeIterator<IlwOutput, IlwRange>& RangeIterator<OutputType, RangeType, IlwOutput, IlwRange>::ptr() const{ if (!this->__bool__()) throw InvalidObject("use of invalid RangeIterator (ptr)"); return (*this->_ilwisRangeIterator); }