22 #ifndef Hypertable_Lib_DataGeneratorRowComponent_h
23 #define Hypertable_Lib_DataGeneratorRowComponent_h
62 unsigned length_min {};
63 unsigned length_max {};
64 uint64_t value_count {};
74 m_rng->set_seed(seed);
78 virtual bool next() = 0;
79 virtual void render(
String &dst) = 0;
88 if (length_min == 0 && length_max == 0) {
89 cout <<
"ERROR: length.min and/or length.max must be specified for row component type 'string'" << endl;
90 std::quick_exit(EXIT_FAILURE);
92 else if (length_max < length_min) {
93 cout <<
"ERROR: length.max must be less than length.min for row component" << endl;
94 std::quick_exit(EXIT_FAILURE);
98 cout <<
"ERROR: 'random' is the only currently supported row component type" << endl;
99 std::quick_exit(EXIT_FAILURE);
102 m_render_buf.reset(
new char [length_max+1] );
103 m_render_buf.get()[length_max] = 0;
111 dst.append((
const char *)m_render_buf.get());
120 m_min = (min !=
"") ? strtoll(min.c_str(), 0, 0) : 0;
123 m_max = (max !=
"") ? strtoll(max.c_str(), 0, 0) : std::numeric_limits<int64_t>::max();
127 m_rng->set_pool_min(m_min);
128 m_rng->set_pool_max(m_max);
130 m_rng->set_value_count(value_count);
133 m_render_buf =
new char [ 32 ];
136 int total_len = snprintf(tbuf, 32,
format.c_str(), (
Lld)1);
137 m_render_buf =
new char [ total_len + 32 ];
141 delete [] m_render_buf;
146 if (m_next == m_max) {
152 else if (order ==
RANDOM) {
153 m_next = m_rng->get_sample();
159 sprintf(m_render_buf,
format.c_str(), (
Lld)m_next);
161 sprintf(m_render_buf,
"%lld", (
Lld)m_next);
165 dst += (
const char *)m_render_buf;
178 strptime(min.c_str(),
format.c_str(), &tmval);
179 m_min = mktime(&tmval);
184 strptime(max.c_str(),
format.c_str(), &tmval);
185 m_max = mktime(&tmval);
188 m_max = std::numeric_limits<time_t>::max();
192 strptime(min.c_str(),
"%F %T", &tmval);
193 m_min = mktime(&tmval);
198 strptime(max.c_str(),
"%F %T", &tmval);
199 m_max = mktime(&tmval);
202 m_max = std::numeric_limits<time_t>::max();
207 m_rng->set_pool_min(m_min);
208 m_rng->set_pool_max(m_min);
210 m_rng->set_value_count(value_count);
213 m_render_buf_len = 32;
215 m_render_buf =
new char [ m_render_buf_len ];
218 int total_len = snprintf(tbuf, 32,
format.c_str(), (
Lld)1);
219 m_render_buf_len = total_len + 32;
220 m_render_buf =
new char [ m_render_buf_len ];
225 delete [] m_render_buf;
230 if (m_next == m_max) {
236 else if (order ==
RANDOM) {
237 m_next = (time_t)m_rng->get_sample();
243 const char *cformat = (
format ==
"") ?
"%F %T" :
format.c_str();
244 localtime_r(&m_next, &tm_val);
245 strftime(m_render_buf, m_render_buf_len, cformat, &tm_val);
249 dst += (
const char *)m_render_buf;
259 #endif // Hypertable_Lib_DataGeneratorRowComponent_h
virtual void render(String &dst)
std::string String
A String is simply a typedef to std::string.
virtual ~RowComponentString()
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
std::unique_ptr< char[]> m_render_buf
virtual void render(String &dst)
RowComponentInteger(RowComponentSpec &spec)
DiscreteRandomGeneratorPtr m_rng
static DiscreteRandomGeneratorPtr create(const String &spec)
Creates a new DiscreteRandomGenerator instance.
std::shared_ptr< DiscreteRandomGenerator > DiscreteRandomGeneratorPtr
RowComponent(RowComponentSpec &spec)
RowComponentString(RowComponentSpec &spec)
Factory for Discrete Random Generators.
virtual ~RowComponentInteger()
virtual void render(String &dst)
long long int Lld
Shortcut for printf formats.
void random_fill_with_chars(char *buf, size_t len, const char *charset=nullptr)
Fills a buffer with random values from a set of characters.
Random number generator for int32, int64, double and ascii arrays.
virtual ~RowComponentTimestamp()
A String class based on std::string.
RowComponentTimestamp(RowComponentSpec &spec)