Exemplo n.º 1
0
IteratorBase::IteratorBase(const pdal::drivers::oci::Reader& reader)
    : m_initialQueryStatement(Statement())
    , m_at_end(false)
    , m_at_end_of_blocks(false)
    , m_at_end_of_clouds(false)
    , m_block(BlockPtr(new Block(reader.getConnection())))
    , m_active_cloud_id(0)
    , m_oracle_buffer(BufferPtr())
    , m_buffer_position(0)
    , m_orientation(schema::POINT_INTERLEAVED)
    , m_reader(reader)
{

    m_querytype = reader.getQueryType();

    if (m_querytype == QUERY_SDO_PC)
    {
        m_initialQueryStatement = getNextCloud(m_block, m_active_cloud_id);
    }

    if (m_querytype == QUERY_SDO_BLK_PC_VIEW)
    {
        m_initialQueryStatement = reader.getInitialQueryStatement();
        m_block = reader.getBlock();

        m_active_cloud_id = m_initialQueryStatement->GetInteger(&m_block->pc->pc_id);
    }

    return;
}
BlockPtr LocalBlockReader::getBlock(const uint64_t blockStart, const uint64_t numBytes)
{
    if(!configured_) {
        throw std::runtime_error("need to configure");
    }

    if(numBytes == 0) {
        throw std::runtime_error("requested 0 numBytes");
    }

    if (blockStart >= fileSize_) {
        // return empty buffer
        boost::shared_ptr<std::vector<uint8_t> > v = boost::shared_ptr<std::vector<uint8_t> >(new std::vector<u_int8_t>);
        BlockPtr block = BlockPtr(new Block(v));
        return block;
    }

    //DLOG(INFO) << "blockStart: " << blockStart << " numBytes: " << numBytes;
    f_->seek(blockStart);

    boost::shared_ptr<std::vector<uint8_t> > v = boost::shared_ptr<std::vector<uint8_t> >(new std::vector<u_int8_t>);
    v->resize(numBytes);
    size_t bytesRead = f_->read(v->data(), numBytes);
    if(bytesRead != numBytes) {
        //error
        switch(bytesRead) {
            case 0: {
                if(f_->eof()) throw std::runtime_error("eof");
                else throw std::runtime_error("error reading");
                break;
            }
            default: {
                throw std::runtime_error("read less bytes than expected");
            }
        }
    }

    BlockPtr block = BlockPtr(new Block(v));
    return block;
}