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

## 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. More...
int | create (indexT elementCount, int optionalHeaderCount=0)
| allow anonymous (malloc) create. More...
bool | open (const char *file, int flags=O_RDONLY)
| open a previously created mapped vector More...
bool | close ()
void | debugPrint (FILE *f)
size_t | getElementCount () const
Public Member Functions inherited from MemoryMap
void | debug_print ()
void | constructor_clear ()
void | destructor_clear ()
virtual bool | allocate ()
virtual bool | open (const char *file, int flags=O_RDONLY)
| open a previously created mapped vector More...
virtual bool | create (const char *file, size_t size)
| create the memory mapped file on disk More...
virtual bool | create (size_t size)
| store in allocated memory (malloc), not mmap: More...
bool | close ()
void | test ()
size_t | length ()
char | operator[] (unsigned int index)
int | prefetch ()
void | useMemoryMap (bool flag=true)

## Protected Attributes

arrayHeaderClass * | header
char * | data
std::string | errorStr

## Additional Inherited Members

Public Attributes inherited from MemoryMap
void * | data

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

## Constructor & Destructor Documentation

## MemoryMapArray()

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

MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::MemoryMapArray | ( |  | ) |

inline

Definition at line 154 of file MemoryMapArray.h.

{
constructorClear();
}

## ~MemoryMapArray()

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

MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::~MemoryMapArray | ( |  | ) |

inline

Definition at line 158 of file MemoryMapArray.h.

{
if (data) close();
}

## Member Function Documentation

## close()

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 >::close | ( |  | ) |

inline

Definition at line 304 of file MemoryMapArray.h.

{
constructorClear();
return MemoryMap::close();
}

## constructorClear()

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

void MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::constructorClear | ( |  | ) |

inline

Definition at line 148 of file MemoryMapArray.h.

{
header = NULL;
data = NULL;
// errorStr = "";
}

## create() [1/2]

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

{
size_t len = elementCount2BytesFunc(elementCount) +
header->getHeaderSize(optionalHeaderCount);
int rc;
rc = MemoryMap::create(file, len);
if (rc)
{
std::ostringstream buf;
buf << file << ": failed to create file";
errorStr = buf.str();
close();
return rc;
}
header = (arrayHeaderClass *) MemoryMap::data;
header->constructorClear();
header->typeCookie = cookieVal;
header->typeVersion = versionVal;
header->headerSize = header->getHeaderSize(optionalHeaderCount);
header->elementCount = elementCount;
data = (char *)((char *) MemoryMap::data + header->headerSize);
const char *env;
char hostname[256];
env = getenv("USER");
if (env) header->setCreationUser(env);
header->creationDate = time(NULL);
#if defined(_WIN32)
hostname[0] = '\0';
#else
gethostname(hostname, sizeof(hostname));
#endif
header->setCreationHost(hostname);
return 0;
}
MemoryMap::create
virtual bool create(const char *file, size_t size)
create the memory mapped file on disk
Definition: MemoryMap.cpp:243

References MemoryMap::create().

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

## create() [2/2]

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

{
return create(NULL, elementCount, optionalHeaderCount);
}
MemoryMapArray::create
int create(const char *file, indexT elementCount, int optionalHeaderCount=0)
Create a vector with elementCount memebers.
Definition: MemoryMapArray.h:208

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

## debugPrint()

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

void MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::debugPrint | ( | FILE * | f | ) |

inline

Definition at line 309 of file MemoryMapArray.h.

{
if (header) header->debugPrint(f);
}

## getElementCount()

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

size_t MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::getElementCount | ( |  | ) | const

inline

Definition at line 314 of file MemoryMapArray.h.

{
return header->elementCount;
}

## getErrorString()

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

const std::string & MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::getErrorString | ( |  | ) |

inline

Definition at line 163 of file MemoryMapArray.h.

{
return errorStr;
}

## getHeader()

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

arrayHeaderClass & MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::getHeader | ( |  | ) |

inline

Definition at line 168 of file MemoryMapArray.h.

{
return *header;
}

## open()

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.

Definition at line 269 of file MemoryMapArray.h.

{
int rc = MemoryMap::open(file, flags);
if (rc)
{
std::ostringstream buf;
buf << file << ": open() failed (error=" << strerror(errno) << ").";
errorStr = buf.str();
return true;
}
header = (arrayHeaderClass *) MemoryMap::data;
data = (char *)((char *) MemoryMap::data + header->headerSize);
if (header->typeCookie!=cookieVal)
{
std::ostringstream buf;
buf << file << ": wrong type of file (expected type "
<< cookieVal << " but got " << header->typeCookie << ")";
errorStr = buf.str();
// XXX insert better error handling
close();
return true;
}
if (header->typeVersion!=versionVal)
{
std::ostringstream buf;
buf << file << ": wrong version of file (expected version "
<< versionVal << " but got " << header->typeVersion << ")";
errorStr = buf.str();
// XXX insert better error handling
close();
return true;
}
return false;
}
MemoryMap::open
virtual bool open(const char *file, int flags=O_RDONLY)
open a previously created mapped vector
Definition: MemoryMap.cpp:156

References MemoryMap::open().

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

## operator[]()

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

elementT MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::operator[] | ( | indexT | i | ) |

inline

Definition at line 183 of file MemoryMapArray.h.

{
return accessorFunc(data, i);
}

## set()

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

void MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::set | ( | indexT | i,
|  | elementT | v
| ) |  |

inline

Definition at line 187 of file MemoryMapArray.h.

{
setterFunc(data, i, v);
}

## setContentCookie()

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

void MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::setContentCookie | ( | uint32_t | c | ) |

inline

Definition at line 173 of file MemoryMapArray.h.

{
header->contentCookie = c;
}

## setContentVersion()

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

void MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::setContentVersion | ( | uint32_t | v | ) |

inline

Definition at line 177 of file MemoryMapArray.h.

{
header->contentVersion = v;
}

## Member Data Documentation

## data

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

char* MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::data

protected

Definition at line 145 of file MemoryMapArray.h.

## errorStr

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

std::string MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::errorStr

protected

Definition at line 146 of file MemoryMapArray.h.

## header

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

arrayHeaderClass* MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::header

protected

Definition at line 144 of file MemoryMapArray.h.

The documentation for this class was generated from the following file:

- general/MemoryMapArray.h