Example #1
0
// --------------------------------------------------------------------------
void Property::load(const FileGroupPtr &db, const BitArray &objMask) {
    // Open the chunk specified by "P$" + mChunkName
    FilePtr fprop;

    string pchn = "P$" + mChunkName;

    try {
        fprop = db->getFile(pchn);

        const DarkDBChunkHeader &hdr = db->getFileHeader(pchn);

        // compare the versions, log differences
        if (hdr.version_high != mVerMaj || hdr.version_low != mVerMin) {
            LOG_ERROR("Property %s version mismatch : %d.%d expected, %d.%d "
                      "encountered",
                      pchn.c_str(), mVerMaj, mVerMin, hdr.version_high,
                      hdr.version_low);
        }
    } catch (const BasicException &) {
        LOG_ERROR("Property::load : Could not find the property chunk %s",
                  pchn.c_str());
        return;
    }

    // Can't calculate the count of the properties, as they can have any size
    // load. Each record has: OID, size (32 bit uint's)
    int id = 0xDEADBABE;

    while (!fprop->eof()) {
        // load the id
        fprop->readElem(&id, sizeof(uint32_t));

        // if the object is not in the mask, skip the property
        if (!objMask[id]) {
            LOG_DEBUG("Property::load: skipping object %d, not in bitmap", id);
            // prop has length and data - so skip according to that
            uint32_t size;
            fprop->read(&size, sizeof(uint32_t));
            fprop->seek(size, File::FSEEK_CUR);
            continue;
        }

        // Use property storage to load the property
        if (mPropertyStorage->readFromFile(fprop, id, true)) {
            _addProperty(id);
        } else {
            LOG_ERROR("There was an error loading property %s for object %d. "
                      "Property was not loaded",
                      mName.c_str(), id);
        }
    }
}
//------------------------------------------------------
std::string DatabaseService::loadFileNameFromTag(const Opde::FileGroupPtr &db,
                                                 const char *tagname) {
    FilePtr fdm = db->getFile(tagname);

    size_t gft_size = fdm->size();

    std::string res;

    char *data = NULL;

    data = new char[gft_size + 1];
    data[0] = 0x0;
    data[gft_size] = 0x0;

    fdm->read(data, fdm->size()); // TODO: Catch exception

    res = std::string(data);

    delete[] data;

    return res;
}