Changeset 452

Show
Ignore:
Timestamp:
04/09/07 02:06:44 (16 years ago)
Author:
ppalmers
Message:

libosc
- add type conversion functions to convert between the argument

type and the wanted data type


Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/libosc/OscArgument.cpp

    r445 r452  
    9191} 
    9292 
     93int32_t  
     94OscArgument::toInt() { 
     95    if(m_isInt) { 
     96        return m_intVal; 
     97    } else if(m_isInt64) { 
     98        return (int32_t)(m_int64Val & 0xFFFFFFFF); 
     99    } else if(m_isFloat) { 
     100        return (int32_t)(m_floatVal); 
     101    } else { 
     102        return 0; 
     103    } 
     104} 
     105 
     106int64_t  
     107OscArgument::toInt64() { 
     108    if(m_isInt) { 
     109        return (int64_t)(m_intVal); 
     110    } else if(m_isInt64) { 
     111        return m_int64Val; 
     112    } else if(m_isFloat) { 
     113        return (int64_t)(m_floatVal); 
     114    } else { 
     115        return 0; 
     116    } 
     117} 
     118 
     119float  
     120OscArgument::toFloat() { 
     121    if(m_isInt) { 
     122        return (float)(m_intVal); 
     123    } else if(m_isInt64) { 
     124        return (float)(m_int64Val); 
     125    } else if(m_isFloat) { 
     126        return m_floatVal; 
     127    } else { 
     128        return 0; 
     129    } 
     130} 
     131 
    93132void 
    94133OscArgument::print() 
  • trunk/libffado/src/libosc/OscArgument.h

    r445 r452  
    4545    bool operator == ( const OscArgument& rhs ); 
    4646 
     47    /** 
     48     * @brief Returns the argument's integer value 
     49     * @return 32 bit integer argument value 
     50     */ 
    4751    int32_t getInt() { return m_intVal;}; 
     52    /** 
     53     * @brief Returns the argument's value converted to integer. 
     54     * if the argument type is float or int64 it will be  
     55     * cast (and trunctacted) to 32bit integer 
     56     * @return  
     57     */ 
     58    int32_t toInt(); 
     59    /** 
     60     * @brief Is the argument a 32 bit integer? 
     61     * @return true if the argument is a 32 bit integer  
     62     */ 
    4863    bool isInt() { return m_isInt;}; 
     64     
     65    /** 
     66     * @brief Returns the argument's 64 bit integer value 
     67     * @return 64 bit integer argument value  
     68     */ 
    4969    int64_t getInt64() { return m_int64Val;}; 
     70    /** 
     71     * @brief Returns the argument's value converted to a 64bit integer. 
     72     * if the argument type is float or int it will be  
     73     * cast to a 64 bit integer 
     74     * @return  
     75     */ 
     76    int64_t toInt64(); 
     77    /** 
     78     * @brief Is the argument a 64 bit integer? 
     79     * @return true if the argument is a 64 bit integer  
     80     */ 
    5081    bool isInt64() { return m_isInt64;}; 
     82     
     83    /** 
     84     * @brief Returns the argument's float value 
     85     * @return float argument value  
     86     */ 
    5187    float getFloat() { return m_floatVal;}; 
     88    /** 
     89     * @brief Returns the argument's value converted to float. 
     90     * if the argument type is int32 or int64 it will be  
     91     * cast to a float 
     92     * @return  
     93     */ 
     94    float toFloat(); 
     95    /** 
     96     * @brief Is the argument a float? 
     97     * @return true if the argument is a float  
     98     */ 
    5299    bool isFloat() { return m_isFloat;}; 
     100     
     101    /** 
     102     * @brief Returns the argument's string value 
     103     * @return string argument value  
     104     */ 
    53105    string& getString() { return m_stringVal;}; 
     106    /** 
     107     * @brief Is the argument a string? 
     108     * @return true if the argument is a string  
     109     */ 
    54110    bool isString() { return m_isString;}; 
     111     
     112     
     113    /** 
     114     * @brief Is the argument a numeric? 
     115     * @return true if the argument is a numeric value  
     116     */ 
     117    bool isNumeric() { return (m_isInt|| m_isInt64 || m_isFloat);}; 
     118     
    55119 
    56120    void print(); 
  • trunk/libffado/src/libosc/unittests.cpp

    r445 r452  
    6363    result &= TEST_SHOULD_RETURN_TRUE(m.getArgument(1).getString()==string("teststring")); 
    6464    result &= TEST_SHOULD_RETURN_TRUE(m.getArgument(2).getInt()==1); 
    65  
     65     
     66    result &= TEST_SHOULD_RETURN_TRUE(m.getArgument(0).toInt()==1); 
     67     
    6668    return result; 
    6769}