MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass > Class Template Reference

Inheritance diagram for MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >:
Inheritance graph
[legend]
Collaboration diagram for MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void constructorClear ()
const std::string & getErrorString ()
arrayHeaderClass & getHeader ()
void setContentCookie (uint32_t c)
void setContentVersion (uint32_t v)
elementT operator[] (indexT i)
void set (indexT i, elementT v)
int create (const char *file, indexT elementCount, int optionalHeaderCount=0)
 Create a vector with elementCount memebers.
int create (indexT elementCount, int optionalHeaderCount=0)
 allow anonymous (malloc) create.
bool open (const char *file, int flags=O_RDONLY)
 open a previously created mapped vector
void close ()
void debugPrint (FILE *f)
size_t getElementCount ()

Protected Attributes

arrayHeaderClass * header
void * data
std::string errorStr

Detailed Description

template<class elementT, typename indexT, unsigned int cookieVal, unsigned int versionVal, elementT accessorFunc, void setterFunc, size_t elementCount2BytesFunc, class arrayHeaderClass>
class MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >

Definition at line 133 of file MemoryMapArray.h.


Member Function Documentation

template<class elementT , typename indexT , unsigned int cookieVal, unsigned int versionVal, elementT accessorFunc, void setterFunc, size_t elementCount2BytesFunc, class arrayHeaderClass >
int MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::create ( indexT  elementCount,
int  optionalHeaderCount = 0 
) [inline]

allow anonymous (malloc) create.

we do this when we don't expect to save the results.

The single use case so far is in GenomeSequence::populateDBSNP.

Definition at line 242 of file MemoryMapArray.h.

References MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::create().

00243     {
00244         return create(NULL, elementCount, optionalHeaderCount);
00245     }

template<class elementT , typename indexT , unsigned int cookieVal, unsigned int versionVal, elementT accessorFunc, void setterFunc, size_t elementCount2BytesFunc, class arrayHeaderClass >
int MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::create ( const char *  file,
indexT  elementCount,
int  optionalHeaderCount = 0 
) [inline]

Create a vector with elementCount memebers.

Does administrative setup of the header and populating this class members. User will need to finish populating the contents of the metaData and data sections.

If file==NULL, the underlying allocation is done via malloc(), so that the results of write access to this vecor are not saved in a file.

If file!=NULL, a file will be created on disk, and all write accesses done via the method set will be persistent in that file.

Definition at line 200 of file MemoryMapArray.h.

Referenced by MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::create(), and GenomeSequence::loadDBSNP().

00201     {
00202         size_t len = elementCount2BytesFunc(elementCount) +
00203                      header->getHeaderSize(optionalHeaderCount);
00204         int rc;
00205         rc = MemoryMap::create(file, len);
00206         if (rc)
00207         {
00208             std::ostringstream buf;
00209             buf << file << ": failed to create file";
00210             errorStr = buf.str();
00211             close();
00212             return rc;
00213         }
00214         header = (arrayHeaderClass *) MemoryMap::data;
00215         header->constructorClear();
00216         header->typeCookie = cookieVal;
00217         header->typeVersion = versionVal;
00218         header->headerSize = header->getHeaderSize(optionalHeaderCount);
00219         header->elementCount = elementCount;
00220         data = (elementT *)((char *) MemoryMap::data + header->headerSize);
00221 
00222         const char *env;
00223         char hostname[256];
00224         env = getenv("USER");
00225         if (env) header->setCreationUser(env);
00226         header->creationDate = time(NULL);
00227 #if defined(WIN32)
00228         hostname[0] = '\0';
00229 #else
00230         gethostname(hostname, sizeof(hostname));
00231 #endif
00232         header->setCreationHost(hostname);
00233         return 0;
00234     }

template<class elementT , typename indexT , unsigned int cookieVal, unsigned int versionVal, elementT accessorFunc, void setterFunc, size_t elementCount2BytesFunc, class arrayHeaderClass >
bool MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::open ( const char *  file,
int  flags = O_RDONLY 
) [inline, virtual]

open a previously created mapped vector

useMemoryMapFlag will determine whether it uses mmap() or malloc()/read() to populate the memory

Reimplemented from MemoryMap.

Reimplemented in GenomeSequence.

Definition at line 261 of file MemoryMapArray.h.

Referenced by GenomeSequence::loadDBSNP().

00262     {
00263         int rc = MemoryMap::open(file, flags);
00264         if (rc)
00265         {
00266             std::ostringstream buf;
00267             buf << file << ": open() failed (error=" << strerror(errno) << ").";
00268             errorStr = buf.str();
00269             return true;
00270         }
00271         header = (arrayHeaderClass *) MemoryMap::data;
00272         data = (elementT *)((char *) MemoryMap::data + header->headerSize);
00273         if (header->typeCookie!=cookieVal)
00274         {
00275             std::ostringstream buf;
00276             buf << file << ": wrong type of file (expected type "
00277             << cookieVal << " but got " << header->typeCookie << ")";
00278             errorStr = buf.str();
00279             // XXX insert better error handling
00280             close();
00281             return true;
00282         }
00283         if (header->typeVersion!=versionVal)
00284         {
00285             std::ostringstream buf;
00286             buf << file << ": wrong version of file (expected version "
00287             << versionVal << " but got " << header->typeVersion << ")";
00288             errorStr = buf.str();
00289             // XXX insert better error handling
00290             close();
00291             return true;
00292         }
00293         return false;
00294     }


The documentation for this class was generated from the following file:
Generated on Wed Nov 17 15:38:35 2010 for StatGen Software by  doxygen 1.6.3