Changeset 16:1d329bbc0303 in xplra for src/client/c/hu


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

Added the functions to handle the array queries

Location:
src/client/c/hu/varadiistvan/xplra
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/client/c/hu/varadiistvan/xplra/XPlane.cc

    r15 r16  
    4949
    5050using std::auto_ptr;
     51using std::string;
    5152
    5253//------------------------------------------------------------------------------
     
    181182//------------------------------------------------------------------------------
    182183
     184size_t XPlane::getArray(const char* name, uint8_t type,
     185                        ssize_t length, size_t offset) throw(Exception)
     186{
     187    checkStream();
     188
     189    stream->writeU8(Protocol::COMMAND_GET_SINGLE);
     190    stream->writeString(name, strlen(name));
     191    stream->writeU8(type);
     192    stream->writeS32(static_cast<int32_t>(length));
     193    stream->writeS32(static_cast<int32_t>(offset));
     194    if (!stream->flush()) checkStream();
     195
     196    uint8_t result = stream->readU8();
     197    length = stream->readS32();
     198    checkStream();
     199    checkResult(result);
     200
     201    return length;
     202}
     203
     204//------------------------------------------------------------------------------
     205
     206size_t XPlane::getFloatArray(const char* name, float* dest,
     207                             size_t length, size_t offset) throw(Exception)
     208{
     209    length = getArray(name, Protocol::TYPE_FLOAT_ARRAY, length, offset);
     210
     211    if (!stream->read(dest, length*sizeof(float))) checkStream();
     212
     213    return length;
     214}
     215
     216//------------------------------------------------------------------------------
     217
     218float* XPlane::getFloatArray(const char* name, size_t& length,
     219                             size_t offset) throw(Exception)
     220{
     221    length = getArray(name, Protocol::TYPE_FLOAT_ARRAY, -1, offset);
     222
     223    auto_ptr<float> data(new float[length]);
     224    if (!stream->read(data.get(), length*sizeof(float))) checkStream();
     225    return data.release();
     226}
     227
     228//------------------------------------------------------------------------------
     229
     230size_t XPlane::getIntArray(const char* name, int32_t* dest,
     231                           size_t length, size_t offset) throw(Exception)
     232{
     233    length = getArray(name, Protocol::TYPE_INT_ARRAY, length, offset);
     234
     235    if (!stream->read(dest, length*sizeof(int32_t))) checkStream();
     236
     237    return length;
     238}
     239
     240//------------------------------------------------------------------------------
     241
     242int32_t* XPlane::getIntArray(const char* name, size_t& length,
     243                             size_t offset) throw(Exception)
     244{
     245    length = getArray(name, Protocol::TYPE_INT_ARRAY, -1, offset);
     246
     247    auto_ptr<int32_t> data(new int32_t[length]);
     248    if (!stream->read(data.get(), length*sizeof(int32_t))) checkStream();
     249    return data.release();
     250}
     251
     252//------------------------------------------------------------------------------
     253
     254size_t XPlane::getByteArray(const char* name, uint8_t* dest,
     255                            size_t length, size_t offset) throw(Exception)
     256{
     257    length = getArray(name, Protocol::TYPE_BYTE_ARRAY, length, offset);
     258
     259    if (!stream->read(dest, length*sizeof(uint8_t))) checkStream();
     260
     261    return length;
     262}
     263
     264//------------------------------------------------------------------------------
     265
     266uint8_t* XPlane::getByteArray(const char* name, size_t& length,
     267                              size_t offset) throw(Exception)
     268{
     269    length = getArray(name, Protocol::TYPE_BYTE_ARRAY, -1, offset);
     270
     271    auto_ptr<uint8_t> data(new uint8_t[length]);
     272    if (!stream->read(data.get(), length*sizeof(uint8_t))) checkStream();
     273    return data.release();
     274}
     275
     276//------------------------------------------------------------------------------
     277
     278string XPlane::getString(const char* name, size_t offset) throw(Exception)
     279{
     280    size_t length = 0;
     281    auto_ptr<uint8_t> data(getByteArray(name, length, offset));
     282    return string(reinterpret_cast<char*>(data.get()));
     283}
     284
     285//------------------------------------------------------------------------------
     286
    183287// Local Variables:
    184288// mode: C++
  • src/client/c/hu/varadiistvan/xplra/XPlane.h

    r15 r16  
    118118    double getDouble(const char* name) throw(Exception);
    119119
     120    /**
     121     * Get a possibly partial array of floats.
     122     *
     123     * @param length the length of the destination buffer
     124     * @param offset the offset from which to get the array
     125     *
     126     * @return the number of values acquired actually
     127     */
     128    size_t getFloatArray(const char* name, float* dest,
     129                         size_t length, size_t offset = 0) throw(Exception);
     130
     131    /**
     132     * Get a possibly partial array of floats. The result array will
     133     * be created with a length needed to hold the returned value.
     134     *
     135     * @param offset the offset from which to get the array
     136     */
     137    float* getFloatArray(const char* name, size_t& length,
     138                         size_t offset = 0) throw(Exception);
     139
     140    /**
     141     * Get a possibly partial array of integers.
     142     *
     143     * @param length the length of the destination buffer
     144     * @param offset the offset from which to get the array
     145     *
     146     * @return the number of values acquired actually
     147     */
     148    size_t getIntArray(const char* name, int32_t* dest,
     149                       size_t length, size_t offset = 0) throw(Exception);
     150
     151    /**
     152     * Get a possibly partial array of integers. The result array will
     153     * be created with a length needed to hold the returned value.
     154     *
     155     * @param offset the offset from which to get the array
     156     */
     157    int32_t* getIntArray(const char* name, size_t& length,
     158                         size_t offset = 0) throw(Exception);
     159
     160    /**
     161     * Get a possibly partial array of bytes.
     162     *
     163     * @param length the length of the destination buffer
     164     * @param offset the offset from which to get the array
     165     *
     166     * @return the number of values acquired actually
     167     */
     168    size_t getByteArray(const char* name, uint8_t* dest,
     169                        size_t length, size_t offset = 0) throw(Exception);
     170
     171    /**
     172     * Get a possibly partial array of bytes. The result array will
     173     * be created with a length needed to hold the returned value.
     174     *
     175     * @param offset the offset from which to get the array
     176     */
     177    uint8_t* getByteArray(const char* name, size_t& lengyh,
     178                          size_t offset = 0) throw(Exception);
     179
     180    /**
     181     * Get a string. A string is a byte array.
     182     */
     183    std::string getString(const char* name, size_t offset = 0) throw(Exception);
     184
    120185private:
    121186    /**
     
    135200     */
    136201    void getScalar(const char* name, uint8_t type) throw(Exception);
     202
     203    /**
     204     * Issue the command to get an array of values of the given
     205     * type. It checks the result and retrieves the number of value
     206     * items available.
     207     *
     208     * @return the number of value items available
     209     */
     210    size_t getArray(const char* name, uint8_t type,
     211                    ssize_t length, size_t offset) throw(Exception);
     212
    137213};
    138214
Note: See TracChangeset for help on using the changeset viewer.