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
bool close ()
void debugPrint (FILE *f)
size_t getElementCount () const

Protected Attributes

arrayHeaderClass * header
char * 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 135 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 244 of file MemoryMapArray.h.

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

00245     {
00246         return create(NULL, elementCount, optionalHeaderCount);
00247     }

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 202 of file MemoryMapArray.h.

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

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

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 263 of file MemoryMapArray.h.

Referenced by GenomeSequence::loadDBSNP(), and GenomeSequence::open().

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


The documentation for this class was generated from the following file:
Generated on Mon Feb 11 13:45:22 2013 for libStatGen Software by  doxygen 1.6.3