Ignore:
Timestamp:
01/03/13 19:09:46 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Made all the single query operation work for all types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/xplra/GetDataRefTask.cc

    r4 r6  
    3030
    3131#include "GetDataRefTask.h"
     32#include "Protocol.h"
    3233
    3334#include "xplcommon/Util.h"
     
    3536//------------------------------------------------------------------------------
    3637
     38using xplra::GetDataRefTask;
     39using xplra::GetIntDataRefTask;
     40using xplra::GetFloatDataRefTask;
     41using xplra::GetDoubleDataRefTask;
     42
     43using xplcommon::DataStream;
     44
     45using std::string;
     46
     47//------------------------------------------------------------------------------
     48
     49GetDataRefTask* GetDataRefTask::create(uint8_t& result, DataStream& stream)
     50{
     51    result = Protocol::RESULT_OK;
     52
     53    string name = stream.readString();
     54    uint8_t type = stream.readU8();
     55    if (!stream) return 0;
     56
     57    if (type==Protocol::TYPE_INT) {
     58        return new GetIntDataRefTask(name);
     59    } else if (type==Protocol::TYPE_FLOAT) {
     60        return new GetFloatDataRefTask(name);
     61    } else if (type==Protocol::TYPE_DOUBLE) {
     62        return new GetDoubleDataRefTask(name);
     63    } else if (type==Protocol::TYPE_FLOAT_ARRAY ||
     64               type==Protocol::TYPE_INT_ARRAY ||
     65               type==Protocol::TYPE_BYTE_ARRAY)
     66    {
     67        int length = stream.readS32();
     68        int offset = stream.readS32();
     69        if (!stream) return 0;
     70
     71        if (type==Protocol::TYPE_FLOAT_ARRAY) {
     72            return new GetFloatArrayDataRefTask(name, length, offset);
     73        } else if (type==Protocol::TYPE_INT_ARRAY) {
     74            return new GetIntArrayDataRefTask(name, length, offset);
     75        } else {
     76            return new GetByteArrayDataRefTask(name, length, offset);
     77        }
     78    } else {
     79        result = Protocol::RESULT_INVALID_TYPE;
     80        return 0;
     81    }
     82}
     83
     84//------------------------------------------------------------------------------
     85//------------------------------------------------------------------------------
     86
     87void GetIntDataRefTask::writeValue(DataStream& stream)
     88{
     89    stream.writeS32(getValue());
     90}
     91
     92//------------------------------------------------------------------------------
     93
     94void GetFloatDataRefTask::writeValue(DataStream& stream)
     95{
     96    stream.writeFloat(getValue());
     97}
     98
     99//------------------------------------------------------------------------------
     100
     101void GetDoubleDataRefTask::writeValue(DataStream& stream)
     102{
     103    stream.writeDouble(getValue());
     104}
    37105
    38106//------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.