objectslist.h revision ad27e1d5e48ca41245120c331cc88b50464813ce
/** @file
*
* List of COM objects
*/
/*
* Copyright (C) 2009 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef ____H_OBJECTSLIST
#define ____H_OBJECTSLIST
#include <list>
/**
* Implements a "flat" objects list with a lock. Since each such list
* has its own lock it is not a good idea to implement trees with this.
*
* ObjectList<T> is designed to behave as if it were a std::list of
* COM pointers of class T; in other words,
* ObjectList<Medium> behaves like std::list< ComObjPtr<Medium> > but
* it's less typing. Iterators, front(), size(), begin() and end()
* are implemented.
*
* In addition it automatically includes an RWLockHandle which can be
* accessed with getLockHandle().
*
* If you need the raw std::list for some reason you can access it with
* getList().
*
* The destructor automatically calls uninit() on every contained
* COM object. If this is not desired, clear the member list before
* deleting the list object.
*/
{
// typename is necessary to disambiguate "::iterator" in templates; see
// the "this might hurt your head" part in
// http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18
: m_lock(lockHandle)
{ }
~ObjectsList()
{
uninitAll();
}
// prohibit copying and assignment
ObjectsList(const ObjectsList &d);
/**
* Returns the lock handle which protects this list, for use with
* AutoReadLock or AutoWriteLock.
*/
{
return m_lock;
}
/**
* Calls m_ll.push_back(p) with locking.
* @param p
*/
{
}
/**
* Calls m_ll.remove(p) with locking. Does NOT call uninit()
* on the contained object.
* @param p
*/
void removeChild(MyType p)
{
}
/**
* Appends all objects from another list to the member list.
* Locks the other list for reading but does not lock "this"
* (because it might be on the caller's stack and needs no
* locking).
* @param ll
*/
{
++it)
{
}
}
/**
* Calls uninit() on every COM object on the list and then
* clears the list, with locking.
*/
void uninitAll()
{
++it)
{
q->uninit();
}
}
/**
* Returns the no. of objects on the list (std::list compatibility)
* with locking.
*/
{
}
/**
* Returns a raw pointer to the member list of objects.
* Does not lock!
* @return
*/
{
return m_ll;
}
/**
* Returns the first object on the list (std::list compatibility)
* with locking.
*/
{
}
/**
* Returns the begin iterator from the list (std::list compatibility).
* Does not lock!
* @return
*/
{
}
/**
* Returns the end iterator from the list (std::list compatibility).
* Does not lock!
*/
{
}
{
}
{
}
};
#endif