Exemplo n.º 1
0
Storable* Storable::createByCode(std::int32_t id)
{
    Storable* storable = nullptr;
    std::int32_t subCode = 0;
    switch (id) {
    case StoreInt8::code:
        storable = new StoreInt8();
        break;
    case StoreInt16::code:
        storable = new StoreInt16();
        break;
    case StoreInt32::code:
        storable = new StoreInt32();
        break;
    case StoreInt64::code:
        storable = new StoreInt64();
        break;
    case StoreVocab::code:
        storable = new StoreVocab();
        break;
    case StoreFloat32::code:
        storable = new StoreFloat32();
        break;
    case StoreFloat64::code:
        storable = new StoreFloat64();
        break;
    case StoreString::code:
        storable = new StoreString();
        break;
    case StoreBlob::code:
        storable = new StoreBlob();
        break;
    case StoreList::code:
        storable = new StoreList();
        yAssert(storable != nullptr);
        storable->asList()->implementation->setNested(true);
        break;
    default:
        if ((id & GROUP_MASK) != 0) {
            // typed list
            subCode = (id & UNIT_MASK);
            if (id & BOTTLE_TAG_DICT) {
                storable = new StoreDict();
                yAssert(storable != nullptr);
            } else {
                storable = new StoreList();
                yAssert(storable != nullptr);
                storable->asList()->implementation->specialize(subCode);
                storable->asList()->implementation->setNested(true);
            }
        }
        break;
    }
    return storable;
}
Exemplo n.º 2
0
void BottleImpl::synch() {
    if (dirty) {
        if (!nested) {
            subCode();
            YMSG(("bottle code %d\n",StoreList::code + subCode()));
        }
        data.clear();
        BufferedConnectionWriter writer;
        if (!nested) {
            writer.appendInt(StoreList::code + speciality);
            YMSG(("wrote bottle code %d\n",StoreList::code + speciality));
        }
        YMSG(("bottle length %d\n",size()));
        writer.appendInt((int)size());
        for (unsigned int i=0; i<content.size(); i++) {
            Storable *s = content[i];
            if (speciality==0) {
                YMSG(("subcode %d\n",s->getCode()));
                writer.appendInt(s->getCode());
            } else {
                YMSG(("skipped subcode %d\n",s->getCode()));
                YARP_ASSERT(speciality==s->getCode());
            }
            if (s->isList()) {
                s->asList()->setNested(true);
            }
            s->writeRaw(writer);
        }
        data.resize(writer.dataSize(),' ');
        MemoryOutputStream m(&data[0]);
        writer.write(m);
        dirty = false;
    }
}
Exemplo n.º 3
0
Storable *Storable::createByCode(int id) {
    Storable *storable = NULL;
    int subCode = 0;
    switch (id) {
    case StoreInt::code:
        storable = new StoreInt();
        break;
    case StoreVocab::code:
        storable = new StoreVocab();
        break;
    case StoreDouble::code:
        storable = new StoreDouble();
        break;
    case StoreString::code:
        storable = new StoreString();
        break;
    case StoreBlob::code:
        storable = new StoreBlob();
        break;
    case StoreList::code:
        storable = new StoreList();
        YARP_ASSERT(storable!=NULL);
        storable->asList()->setNested(true);
        break;
    default:
        if ((id&GROUP_MASK)!=0) {
            // typed list
            subCode = (id&UNIT_MASK);
            if (id&BOTTLE_TAG_DICT) {
                storable = new StoreDict();
                YARP_ASSERT(storable!=NULL);
            } else {
                storable = new StoreList();
                YARP_ASSERT(storable!=NULL);
                storable->asList()->specialize(subCode);
                storable->asList()->setNested(true);
            }
        }
        break;
    }
    return storable;
}