A class generating a stream of words; the words are retrieved from a file and can be randomized. More...
#include <WordStream.h>
Classes | |
struct | word_info |
Internal structure for a single word. More... | |
Public Member Functions | |
WordStream (const String &word_file, unsigned seed, size_t words_per_record, bool random=false, const char *separator=" ") | |
Constructor. More... | |
virtual | ~WordStream () |
Releases internal resources. More... | |
const char * | next () |
Retrieves the next word, or an empty string if EOF is reached. More... | |
Private Attributes | |
std::mt19937 | ms_rng |
Random number generator. More... | |
char * | m_base |
Base pointer for the memory mapped file. More... | |
const char * | m_end |
End pointer for the memory mapped file. More... | |
const char * | m_separator |
The separator, as specified by the user. More... | |
size_t | m_words_per_record |
Words per record, as specified by the user. More... | |
off_t | m_len |
Length of the memory mapped file. More... | |
std::vector< struct word_info > | m_words |
All words from the mapped file. More... | |
std::vector< size_t > | m_offset |
Helper for parsing the words. More... | |
String | m_record |
The current string. More... | |
bool | m_random |
Whether to return random strings or not. More... | |
A class generating a stream of words; the words are retrieved from a file and can be randomized.
Definition at line 46 of file WordStream.h.
WordStream::WordStream | ( | const String & | word_file, |
unsigned | seed, | ||
size_t | words_per_record, | ||
bool | random = false , |
||
const char * | separator = " " |
||
) |
Constructor.
word_file | The file with all the words |
seed | The seed for the random number generator; if 0 then no seed will be set |
words_per_record | Number of words to retrieve when calling next |
random | If true, words will be in random order |
separator | The word separator |
Definition at line 46 of file WordStream.cc.
|
virtual |
Releases internal resources.
Definition at line 83 of file WordStream.cc.
const char * WordStream::next | ( | ) |
Retrieves the next word, or an empty string if EOF is reached.
Definition at line 87 of file WordStream.cc.
|
private |
Base pointer for the memory mapped file.
Definition at line 79 of file WordStream.h.
|
private |
End pointer for the memory mapped file.
Definition at line 82 of file WordStream.h.
|
private |
Length of the memory mapped file.
Definition at line 91 of file WordStream.h.
|
private |
Helper for parsing the words.
Definition at line 97 of file WordStream.h.
|
private |
Whether to return random strings or not.
Definition at line 103 of file WordStream.h.
|
private |
The current string.
Definition at line 100 of file WordStream.h.
|
private |
The separator, as specified by the user.
Definition at line 85 of file WordStream.h.
|
private |
All words from the mapped file.
Definition at line 94 of file WordStream.h.
|
private |
Words per record, as specified by the user.
Definition at line 88 of file WordStream.h.
|
private |
Random number generator.
Definition at line 76 of file WordStream.h.