VirtualBox

Changeset 16671 in vbox for trunk/include/VBox/com


Ignore:
Timestamp:
Feb 11, 2009 3:29:00 PM (16 years ago)
Author:
vboxsync
Message:

Main/SafeArray: Added SafeArray and SafeIfaceArray constructors taking std::map references for deep copying.

File:
1 edited

Legend:

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

    r15051 r16671  
    649649
    650650    /**
    651      * Creates a deep copy of the given standard C++ container.
     651     * Creates a deep copy of the given standard C++ container that stores
     652     * T objects.
    652653     *
    653654     * @param aCntr Container object to copy.
     
    669670#else
    670671            Copy (*it, m.raw [i]);
     672#endif
     673    }
     674
     675    /**
     676     * Creates a deep copy of the given standard C++ map that stores T objects
     677     * as values.
     678     *
     679     * @param aMap  Map object to copy.
     680     *
     681     * @param C     Standard C++ map template class (normally deduced from
     682     *              @c aCntr).
     683     * @param L     Standard C++ compare class (deduced from @c aCntr).
     684     * @param A     Standard C++ allocator class (deduced from @c aCntr).
     685     * @param K     Map key class (deduced from @c aCntr).
     686     */
     687    template <template <typename, typename, typename, typename>
     688              class C, class L, class A, class K>
     689    SafeArray (const C <K, T, L, A> & aMap)
     690    {
     691        typedef C <K, T, L, A> Map;
     692
     693        resize (aMap.size());
     694        AssertReturnVoid (!isNull());
     695
     696        int i = 0;
     697        for (typename Map::const_iterator it = aMap.begin();
     698             it != aMap.end(); ++ it, ++ i)
     699#if defined (VBOX_WITH_XPCOM)
     700            Copy (it->second, m.arr [i]);
     701#else
     702            Copy (it->second, m.raw [i]);
    671703#endif
    672704    }
     
    15331565#endif
    15341566    }
     1567
     1568    /**
     1569     * Creates a deep copy of the given standard C++ map whose values are
     1570     * interface pointers stored as objects of the ComPtr <I> class.
     1571     *
     1572     * @param aMap  Map object to copy.
     1573     *
     1574     * @param C     Standard C++ map template class (normally deduced from
     1575     *              @c aCntr).
     1576     * @param L     Standard C++ compare class (deduced from @c aCntr).
     1577     * @param A     Standard C++ allocator class (deduced from @c aCntr).
     1578     * @param K     Map key class (deduced from @c aCntr).
     1579     * @param OI    Argument to the ComPtr template (deduced from @c aCntr).
     1580     */
     1581    template <template <typename, typename, typename, typename>
     1582              class C, class L, class A, class K, class OI>
     1583    SafeIfaceArray (const C <K, ComPtr <OI>, L, A> & aMap)
     1584    {
     1585        typedef C <K, ComPtr <OI>, L, A> Map;
     1586
     1587        Base::resize (aMap.size());
     1588        AssertReturnVoid (!Base::isNull());
     1589
     1590        int i = 0;
     1591        for (typename Map::const_iterator it = aMap.begin();
     1592             it != aMap.end(); ++ it, ++ i)
     1593#if defined (VBOX_WITH_XPCOM)
     1594            Copy (it->second, Base::m.arr [i]);
     1595#else
     1596            Copy (it->second, Base::m.raw [i]);
     1597#endif
     1598    }
     1599
     1600    /**
     1601     * Creates a deep copy of the given standard C++ map whose values are
     1602     * interface pointers stored as objects of the ComObjPtr <I> class.
     1603     *
     1604     * @param aMap  Map object to copy.
     1605     *
     1606     * @param C     Standard C++ map template class (normally deduced from
     1607     *              @c aCntr).
     1608     * @param L     Standard C++ compare class (deduced from @c aCntr).
     1609     * @param A     Standard C++ allocator class (deduced from @c aCntr).
     1610     * @param K     Map key class (deduced from @c aCntr).
     1611     * @param OI    Argument to the ComObjPtr template (deduced from @c aCntr).
     1612     */
     1613    template <template <typename, typename, typename, typename>
     1614              class C, class L, class A, class K, class OI>
     1615    SafeIfaceArray (const C <K, ComObjPtr <OI>, L, A> & aMap)
     1616    {
     1617        typedef C <K, ComObjPtr <OI>, L, A> Map;
     1618
     1619        Base::resize (aMap.size());
     1620        AssertReturnVoid (!Base::isNull());
     1621
     1622        int i = 0;
     1623        for (typename Map::const_iterator it = aMap.begin();
     1624             it != aMap.end(); ++ it, ++ i)
     1625#if defined (VBOX_WITH_XPCOM)
     1626            Copy (it->second, Base::m.arr [i]);
     1627#else
     1628            Copy (it->second, Base::m.raw [i]);
     1629#endif
     1630    }
    15351631};
    15361632
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