VirtualBox

Changeset 13956

Show
Ignore:
Timestamp:
11/07/08 13:41:45 (2 months ago)
Author:
vboxsync
Message:

Main, FE/Qt: Added support for safe arrays of enums.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/com/array.h

    r13908 r13956  
    373373    static ULONG VarCount (size_t aSize); 
    374374 
    375     // Returns the number of elements of T that occupy the given number of 
     375    // Returns the number of elements of T that fit into the given number of 
    376376    // VarType() elements (opposite to VarCount (size_t aSize)). 
    377377    static size_t Size (ULONG aVarCount); 
     
    383383struct SafeArrayTraits 
    384384{ 
    385     // Arbitrary types are not supported -- no helpers 
    386 }; 
     385    // Arbitrary types are treated as passed by value and each value is 
     386    // represented by a number of VT_Ix type elements where VT_Ix has the 
     387    // biggest possible bitness necessary to represent T w/o a gap. COM enums 
     388    // fall into this category. 
     389 
     390    static VARTYPE VarType() 
     391    { 
     392        if (sizeof (T) % 8 == 0) return VT_I8; 
     393        if (sizeof (T) % 4 == 0) return VT_I4; 
     394        if (sizeof (T) % 2 == 0) return VT_I2; 
     395        return VT_I1; 
     396    } 
     397 
     398    static ULONG VarCount (size_t aSize) 
     399    { 
     400        if (sizeof (T) % 8 == 0) return (ULONG) (sizeof (T) / 8) * aSize; 
     401        if (sizeof (T) % 4 == 0) return (ULONG) (sizeof (T) / 4) * aSize; 
     402        if (sizeof (T) % 2 == 0) return (ULONG) (sizeof (T) / 2) * aSize; 
     403        return (ULONG) sizeof (T) * aSize; 
     404    } 
     405 
     406    static size_t Size (ULONG aVarCount) 
     407    { 
     408        if (sizeof (T) % 8 == 0) return (size_t) (aVarCount * 8) / sizeof (T); 
     409        if (sizeof (T) % 4 == 0) return (size_t) (aVarCount * 4) / sizeof (T); 
     410        if (sizeof (T) % 2 == 0) return (size_t) (aVarCount * 2) / sizeof (T); 
     411        return (size_t) aVarCount / sizeof (T); 
     412    } 
     413 
     414    static void Copy (T aFrom, T &aTo) { aTo = aFrom; } 
     415}; 
     416 
     417template <typename T> 
     418struct SafeArrayTraits <T *> 
     419
     420    // Arbitrary pointer types are not supported 
     421}; 
     422 
     423/* Although the generic SafeArrayTraits template would work for all integers, 
     424 * we specialize it for some of them in order to use the correct VT_ type */ 
    387425 
    388426template<> 
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r13950 r13956  
    28252825            com::SafeArray <BSTR> propertyNames; 
    28262826            com::SafeArray <BSTR> propertyDescriptions; 
    2827             com::SafeArray <ULONG> propertyTypes; 
     2827            com::SafeArray <DataType_T> propertyTypes; 
    28282828            com::SafeArray <ULONG> propertyFlags; 
    28292829            com::SafeArray <BSTR> propertyDefaults; 
  • trunk/src/VBox/Frontends/VirtualBox/include/COMDefs.h

    r13580 r13956  
    287287    static void FromSafeArray (const com::SafeGUIDArray &aArr, 
    288288                               QValueVector <QUuid> &aVec); 
     289 
     290    /* Arrays of enums. Does a cast similar to what ENUMOut does. */ 
     291 
     292    template <typename QE, typename CE> 
     293    static void ToSafeArray (const QVector <QE> &aVec, 
     294                             com::SafeIfaceArray <CE> &aArr) 
     295    { 
     296        aArr.reset (static_cast <int> (aVec.size())); 
     297        for (int i = 0; i < aVec.size(); ++i) 
     298            aArr [i] = static_cast <CE> (aVec.at (i)); 
     299    } 
     300 
     301    template <typename CE, typename QE> 
     302    static void FromSafeArray (const com::SafeIfaceArray <CE> &aArr, 
     303                               QVector <QE> &aVec) 
     304    { 
     305        aVec.resize (static_cast <int> (aArr.size())); 
     306        for (int i = 0; i < aVec.size(); ++i) 
     307            aVec [i] = static_cast <QE> (aArr [i]); 
     308    } 
    289309 
    290310    /* Arrays of interface pointers. Note: we need a separate pair of names 
  • trunk/src/VBox/Frontends/VirtualBox4/include/COMDefs.h

    r13580 r13956  
    283283    static void FromSafeArray (const com::SafeGUIDArray &aArr, 
    284284                               QVector <QUuid> &aVec); 
     285 
     286    /* Arrays of enums. Does a cast similar to what ENUMOut does. */ 
     287 
     288    template <typename QE, typename CE> 
     289    static void ToSafeArray (const QVector <QE> &aVec, 
     290                             com::SafeIfaceArray <CE> &aArr) 
     291    { 
     292        aArr.reset (static_cast <int> (aVec.size())); 
     293        for (int i = 0; i < aVec.size(); ++i) 
     294            aArr [i] = static_cast <CE> (aVec.at (i)); 
     295    } 
     296 
     297    template <typename CE, typename QE> 
     298    static void FromSafeArray (const com::SafeIfaceArray <CE> &aArr, 
     299                               QVector <QE> &aVec) 
     300    { 
     301        aVec.resize (static_cast <int> (aArr.size())); 
     302        for (int i = 0; i < aVec.size(); ++i) 
     303            aVec [i] = static_cast <QE> (aArr [i]); 
     304    } 
    285305 
    286306    /* Arrays of interface pointers. Note: we need a separate pair of names 
  • trunk/src/VBox/Main/HardDiskFormatImpl.cpp

    r13950 r13956  
    240240STDMETHODIMP HardDiskFormat::DescribeProperties(ComSafeArrayOut (BSTR, aNames), 
    241241                                                ComSafeArrayOut (BSTR, aDescriptions), 
    242                                                 ComSafeArrayOut (ULONG, aTypes), 
     242                                                ComSafeArrayOut (DataType_T, aTypes), 
    243243                                                ComSafeArrayOut (ULONG, aFlags), 
    244244                                                ComSafeArrayOut (BSTR, aDefaults)) 
     
    257257    com::SafeArray <BSTR> propertyNames (mData.properties.size()); 
    258258    com::SafeArray <BSTR> propertyDescriptions (mData.properties.size()); 
    259     com::SafeArray <ULONG> propertyTypes (mData.properties.size()); 
     259    com::SafeArray <DataType_T> propertyTypes (mData.properties.size()); 
    260260    com::SafeArray <ULONG> propertyFlags (mData.properties.size()); 
    261261    com::SafeArray <BSTR> propertyDefaults (mData.properties.size()); 
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r13950 r13956  
    73747374        <desc>Array of property descriptions.</desc> 
    73757375      </param> 
    7376       <param name="types" type="unsigned long" safearray="yes" dir="out"> 
     7376      <param name="types" type="DataType" safearray="yes" dir="out"> 
    73777377        <desc>Array of property types.</desc> 
    73787378      </param> 
  • trunk/src/VBox/Main/include/HardDiskFormatImpl.h

    r13950 r13956  
    7272    STDMETHOD(DescribeProperties) (ComSafeArrayOut (BSTR, aNames), 
    7373                                   ComSafeArrayOut (BSTR, aDescriptions), 
    74                                    ComSafeArrayOut (ULONG, aTypes), 
     74                                   ComSafeArrayOut (DataType_T, aTypes), 
    7575                                   ComSafeArrayOut (ULONG, aFlags), 
    7676                                   ComSafeArrayOut (BSTR, aDefaults)); 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy