VirtualBox

Changeset 13956 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Nov 7, 2008 12:41:45 PM (16 years ago)
Author:
vboxsync
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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<>
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette