/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 *
 * The iWear Framework is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the
 * Free Software Foundation as in version 2 of the License.

 * 
 * The iWear Framework is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __IWEAR_SHMEMORY_H
#define __IWEAR_SHMEMORY_H

extern "C" {
#include <sys/types.h>
}

#include <string>
using std::string;

namespace iwear
{
/**
 * This class is a basic access to a certain type of shared memory. The goal is
 * to have access to posix shared memory, sysv shared memory and shared mapped
 * files.
 *
 * As a further step we will create allocators using the memory in an efficient
 * way to store objects in them. For that we will explicitly not overload new
 * in any way to store the memory there, but provide functions to allocate
 * certain objects from that memory, as well as arrays of them.
 *
 * Ideally the allocator we use to get the memory can be "plugged in" so we can
 * choose between fast ones, memory efficient ones etc. So we one day even
 * might use those allocators for other objects to be more memory efficient
 * than standard implementations. Of course we should not forget to make them valgrind aware.
 */
class shared_memory
{
private:
protected:
    void* segment;
    size_t size;
    string key;
    void* open_shm( const string& k, size_t s );

public:
    shared_memory();
    shared_memory( const string& key_, size_t size_ );
    shared_memory( const shared_memory& );
    ~shared_memory();

    shared_memory& operator=( const shared_memory& );
    //operator void* (void) { return segment; }
    template<class T>
    operator T* (void) { return (T*)segment; }
    void* operator[] ( size_t v );

    void unlink( void );
};    

}
#endif
