Loading...
Searching...
No Matches
generate.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003-2023, John Wiegley. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of New Artisans LLC nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
42#pragma once
43
44#include "iterators.h"
45
46namespace ledger {
47
48class session_t;
49
51 : public iterator_facade_base<generate_posts_iterator, post_t *,
52 boost::forward_traversal_tag>
53{
54 session_t& session;
55 unsigned int seed;
56 std::size_t quantity;
57 date_t next_date;
58 date_t next_aux_date;
59
60 mt19937 rnd_gen;
61
62 typedef variate_generator<mt19937&, uniform_int<> > int_generator_t;
63 typedef variate_generator<mt19937&, uniform_real<> > real_generator_t;
64
65 uniform_int<> year_range;
66 int_generator_t year_gen;
67 uniform_int<> mon_range;
68 int_generator_t mon_gen;
69 uniform_int<> day_range;
70 int_generator_t day_gen;
71
72 uniform_int<> upchar_range;
73 int_generator_t upchar_gen;
74 uniform_int<> downchar_range;
75 int_generator_t downchar_gen;
76 uniform_int<> numchar_range;
77 int_generator_t numchar_gen;
78
79 uniform_int<> truth_range;
80 int_generator_t truth_gen;
81 uniform_int<> three_range;
82 int_generator_t three_gen;
83 uniform_int<> six_range;
84 int_generator_t six_gen;
85 uniform_int<> two_six_range;
86 int_generator_t two_six_gen;
87
88 uniform_int<> strlen_range;
89 int_generator_t strlen_gen;
90
91 uniform_real<> neg_number_range;
92 real_generator_t neg_number_gen;
93 uniform_real<> pos_number_range;
94 real_generator_t pos_number_gen;
95
97
98public:
100 unsigned int _seed = 0,
101 std::size_t _quantity = 100);
102
106
107 virtual void increment();
108
109protected:
110 void generate_string(std::ostream& out, int len, bool only_alpha = false);
111 bool generate_account(std::ostream& out, bool no_virtual = false);
112 void generate_commodity(std::ostream& out, const string& exclude = "");
113 string generate_amount(std::ostream& out,
115 bool no_negative = false,
116 const string& exclude = "");
117 bool generate_post(std::ostream& out, bool no_amount = false);
118 void generate_cost(std::ostream& out, value_t amount);
119 void generate_date(std::ostream& out);
120 void generate_state(std::ostream& out);
121 void generate_code(std::ostream& out);
122 void generate_payee(std::ostream& out);
123 void generate_note(std::ostream& out);
124 void generate_xact(std::ostream& out);
125};
126
127} // namespace ledger
#define TRACE_DTOR(cls)
Definition utils.h:144
#define NULL_VALUE
Definition value.h:947
boost::gregorian::date date_t
Definition times.h:60
T & downcast(U &object)
Definition utils.h:468
void generate_state(std::ostream &out)
void generate_payee(std::ostream &out)
void generate_code(std::ostream &out)
void generate_cost(std::ostream &out, value_t amount)
void generate_string(std::ostream &out, int len, bool only_alpha=false)
bool generate_account(std::ostream &out, bool no_virtual=false)
void generate_commodity(std::ostream &out, const string &exclude="")
generate_posts_iterator(session_t &_session, unsigned int _seed=0, std::size_t _quantity=100)
string generate_amount(std::ostream &out, value_t not_this_amount=(value_t()), bool no_negative=false, const string &exclude="")
bool generate_post(std::ostream &out, bool no_amount=false)
void generate_xact(std::ostream &out)
void generate_note(std::ostream &out)
void generate_date(std::ostream &out)
Dynamic type representing various numeric types.
Definition value.h:83