Example #1
0
void Persistence::addProperty(short propertyId, short dataSize)
{
    if ( _count < MAX_VARIABLES )
    {
        if (_count > 0)
        {
            _size += sizeof(Property) + dataSize;
            _properties = (Property *) realloc(_properties, _size);
            _mallocSize = _size;
        }
        else
        {
            _size = sizeof(Property) + dataSize;
            if ( _mallocSize < _size )
            {
                _properties = (Property *) malloc(_size);
                _mallocSize = _size;
            }
        }

        setPosition(_count);
        _currProperty->propertyId = propertyId;
        _currProperty->valueSize = dataSize;
        _currProperty->value = (_currProperty) + 1; //the value is at end of structure
        _count++;
        fixPointers();
    }
}
Example #2
0
bool Persistence::load()
{
    //free any previous loaded data
    flush();

    //load variable count
    readEEPROM(_mainPosition, (byte *)&_count, sizeof(_count));

    //validate variable count
    if ( _count > 0 && _count < MAX_VARIABLES )
    {
        //load data size
        readEEPROM(_mainPosition + sizeof(_count), (byte *)&_size, sizeof(_size));

        //copy data
        if (_size > 0)
        {
            _properties = (Property *) malloc(_size);
            readEEPROM(_mainPosition + sizeof(_count) + sizeof(_size), (byte *)_properties, _size);
            fixPointers();
        }

        return true;
    }
    else
    {
        _count = 0;
        return false;
    }
}
Example #3
0
void Persistence::remove(short propertyId)
{
    if (findProperty(propertyId))
    {
        _size -= (_currProperty->valueSize + sizeof(Property));

        if (_count > 1)
        {
            //move data if needed
            if (_index < _count - 1)
            {
                //copy destination location
                _moveProperty = _currProperty;

                //calculate data size to move
                short moveSize = 0;
                for (; _index < (_count - 1); _index++)
                {
                    _currProperty = (Property *) (((unsigned short)_currProperty) + sizeof(Property) + _currProperty->valueSize);
                    moveSize += sizeof(Property) + _currProperty->valueSize;
                }

                memmove(_moveProperty, (void *) ((unsigned short)_moveProperty + sizeof(Property) + _moveProperty->valueSize), moveSize);
            }
        }

        _count--;

        if (_size <= 0)
            flush();

        fixPointers();
    }
}
Example #4
0
void SATParser::read(istream *s)
{
    string name;

    m_stream = s;

    m_header.version = readInt();
    m_header.n_data_records = readInt();
    m_header.n_entities = readInt();
    m_header.has_history = readBool();
    finishLine();

    m_header.product_id = readString();
    m_header.acis_version = readString();
    m_header.date = readString();
    finishLine();

    m_header.unit = readDouble();
    m_header.resabs = readDouble();
    m_header.resnor = readDouble();
    MSG_DEBUG("SATParser::read", "resnor = " << m_header.resnor);
    finishLine();

    //    cout << readString() << endl;

    name = readWord();
    while (!m_stream->eof() && name != END_OF_DATA_STR) {
        SATEntity *e;

        if (SATEntity_Factory::exists(name)) {
            e = SATEntity_Factory::byName(name).instantiate();
        } else {
            MSG_DEBUG("SATParser::read", "Unknown entity: '" << name << "'");

            e = new SATUnknown();
        }

        e->read(this);

        m_entities.push_back(e);

        finishLine();

        name = readWord();
    }

    fixPointers();
}