43 while (ptr < m_end && isspace(*ptr)) \
47 size_t words_per_record,
bool random,
const char *separator)
48 : m_separator(separator), m_words_per_record(words_per_record),
51 ms_rng.seed((uint32_t)seed);
54 m_offset.resize(words_per_record, 0);
61 for (
const char *ptr =
m_base; ptr <
m_end; ++ptr) {
72 for (; ptr <
m_end; ++ptr) {
88 std::uniform_int_distribution<> dist {0, (int)(
m_words.size()-1)};
99 if (i < (m_words_per_record - 1))
std::string String
A String is simply a typedef to std::string.
const char * m_separator
The separator, as specified by the user.
const char * m_end
End pointer for the memory mapped file.
A class generating a stream of words; the words are retrieved from a file and can be randomized...
Program options handling.
std::mt19937 ms_rng
Random number generator.
size_t m_words_per_record
Words per record, as specified by the user.
off_t m_len
Length of the memory mapped file.
std::vector< struct word_info > m_words
All words from the mapped file.
File system utility functions.
String m_record
The current string.
char * m_base
Base pointer for the memory mapped file.
Internal structure for a single word.
Compatibility Macros for C/C++.
std::vector< size_t > m_offset
Helper for parsing the words.
virtual ~WordStream()
Releases internal resources.
static void * mmap(const String &fname, off_t *lenp)
Maps a full file into memory using mmap; the mapping will be released when the application terminates...
const char * next()
Retrieves the next word, or an empty string if EOF is reached.
WordStream(const String &word_file, unsigned seed, size_t words_per_record, bool random=false, const char *separator=" ")
Constructor.
bool m_random
Whether to return random strings or not.