lipsum-cpp 0.5.4
A basic library written in C++ for generating placeholder Lorem Ipsum text.
Loading...
Searching...
No Matches
generator.hpp
Go to the documentation of this file.
1
13
14#pragma once
15
16#include "core/argvec2.hpp"
17#include "core/core.hpp"
18#include "core/source.hpp"
19#include "generatorsettings.hpp"
20
21namespace lipsum
22{
23
31 enum GeneratorFlags : bool
32 {
33 USELIPSUM = true,
34 NO_USELIPSUM = false,
35 HTML = true,
36 MARKDOWN = false,
37 OBJECT = true,
38 ARRAY = false,
39 BOLD = true,
40 ITALIC = false,
41 ORDERED = true,
42 UNORDERED = false,
43 IPV4 = false,
44 IPV6 = true,
45 NOPORT = false,
46 PORT = true
47 };
48
57 enum class CaseSlugCase : int
58 {
59 CamelCase = 0,
60 PascalCase,
61 SnakeCase,
62 ShoutyCase,
63 KebabCase,
64 TrainCase,
65 };
66
75 enum class CodeLanguage : int
76 {
77 Cpp = 0,
78 Python,
79 Rust,
80 C,
81 JavaScript
82 };
83
92 {
93 public:
101 Generator();
102
112 Generator(int seed);
113
126 Generator(const std::string& path, int seed);
127
135 ~Generator();
136
150 Generator(const std::string& path);
151
165 void load_source(const std::string& path);
166
176 void load_seed(int seed);
177
191 void change_setting(const std::string& setting, const ArgVec2& value);
192
204 void
205 change_setting(const std::string& setting, int minValue, int maxValue);
206
215 void toggle_lazy();
216
217 /*
218 * CORE
219 */
220
233 std::string word(int num = 1);
234
245 std::string fragment();
246
265 std::string sentence(int num = 1, bool useLipsum = true);
266
283 std::string paragraph(int num = 1, bool useLipsum = true);
284
298 std::string text(bool useLipsum = true);
299
300 /*
301 * MISC
302 */
303
321 std::string
322 scramble(int length = 16, char minChar = ' ', char maxChar = '~');
323
337 std::string url();
338
349 std::string plain_url();
350
361 std::string email();
362
375 std::string slug(char separator = '-');
376
389 std::string case_slug(CaseSlugCase case_ = CaseSlugCase::CamelCase);
390
403 std::string code(CodeLanguage lang = CodeLanguage::Cpp);
404
422 std::string ip_addr(bool useIpv6 = false, bool usePort = false);
423
433 std::string phone_number();
434
435 /*
436 * FORMATS
437 */
438
456 std::string
457 fmt_paragraph(int num = 1, bool useLipsum = true, bool useHtml = false);
458
484 std::string fmt_text(int numElements = 15, bool useHtml = false);
485
505 std::string fmt_header(int level = 1, bool useHtml = false);
506
526 std::string fmt_emphasis(bool isBold = true, bool useHtml = false);
527
548 std::string fmt_link(bool useHtml = false);
549
572 std::string fmt_list(bool ordered = false, bool useHtml = false);
573
594 std::string xml(int choices = 30);
595
610 std::string json(int maxDepth = 3, bool isObject = true);
611
625 std::string json_value(int maxDepth = 3);
626
640 std::string csv();
641
642 private:
662 std::string single_sentence(const ArgVec2& wordArg,
663 const ArgVec2& frag);
664
682 std::string single_paragraph(bool useLipsum);
683
709 std::string single_fmt_paragraph(bool useLipsum, bool useHtml);
710
721 std::string json_string();
722
734 std::string json_number();
735
754 template <internal::UniformDistributionType T>
755 T random_number(T min, T max)
756 {
757 if (min > max)
758 {
759 T tempMax = max;
760 max = min;
761 min = tempMax;
762 }
763 if constexpr (std::is_integral_v<T>)
764 {
765 std::uniform_int_distribution<T> dist(min, max);
766 return dist(m_Gen);
767 }
768 else
769 {
770 std::uniform_real_distribution<T> dist(min, max);
771 return dist(m_Gen);
772 }
773 }
774
787 char random_number(char min, char max);
788
801 bool random_number(bool min, bool max);
802
816 int weighted_random_idx(const std::vector<int>& weights);
817
830 std::string tld();
831
833
834 std::mt19937 m_Gen;
835
845 };
846} // namespace lipsum
Declaration of lipsum::ArgVec2.
void change_setting(const std::string &setting, const ArgVec2 &value)
Change a setting.
Definition generatorcore.inl:131
std::string xml(int choices=30)
Generate an XML document.
Definition generatorformats.inl:222
std::string ip_addr(bool useIpv6=false, bool usePort=false)
Generate an IP address.
Definition generator.inl:442
std::string fmt_emphasis(bool isBold=true, bool useHtml=false)
Generate an emphasized Markdown or HTML sentence.
Definition generatorformats.inl:145
GeneratorSettings m_Settings
Settings for generation.
Definition generator.hpp:832
std::string plain_url()
Generate a plain URL.
Definition generator.inl:190
std::string scramble(int length=16, char minChar=' ', char maxChar='~')
Generate a random character scramble.
Definition generator.inl:162
std::string fmt_paragraph(int num=1, bool useLipsum=true, bool useHtml=false)
Generate Markdown or HTML paragraphs.
Definition generatorformats.inl:27
std::string sentence(int num=1, bool useLipsum=true)
Generate sentences.
Definition generator.inl:98
std::string json_value(int maxDepth=3)
Generate a JSON value.
Definition generatorformats.inl:322
void load_seed(int seed)
Reload a seed.
Definition generatorcore.inl:125
std::string fmt_header(int level=1, bool useHtml=false)
Generate a Markdown or HTML header.
Definition generatorformats.inl:110
void toggle_lazy()
Toggle the lazy flag.
Definition generatorcore.inl:114
std::string word(int num=1)
Generate words.
Definition generator.inl:67
std::string single_sentence(const ArgVec2 &wordArg, const ArgVec2 &frag)
Generate a single sentence.
Definition generatorcore.inl:181
std::string fmt_list(bool ordered=false, bool useHtml=false)
Generate a Markdown or HTML list.
Definition generatorformats.inl:186
std::string single_fmt_paragraph(bool useLipsum, bool useHtml)
Generate a single Markdown or HTML paragraph.
Definition generatorcore.inl:210
void load_source(const std::string &path)
Reload a source.
Definition generatorcore.inl:119
std::string text(bool useLipsum=true)
Generate a random number of random paragraphs.
Definition generator.inl:151
std::string json_string()
Generate a random JSON string.
Definition generatorcore.inl:260
Source m_Source
Source used for generation.
Definition generator.hpp:844
std::string json(int maxDepth=3, bool isObject=true)
Generate a JSON object or array.
Definition generatorformats.inl:293
Generator()
Default constructor for Generator.
Definition generatorcore.inl:80
T random_number(T min, T max)
Generate a random number.
Definition generator.hpp:755
std::string fmt_link(bool useHtml=false)
Generate a Markdown or HTML link.
Definition generatorformats.inl:173
std::string url()
Generate a URL.
Definition generator.inl:184
std::string phone_number()
Generate a phone number.
Definition generator.inl:474
std::string email()
Generate an email.
Definition generator.inl:196
std::string fmt_text(int numElements=15, bool useHtml=false)
Generate a Markdown or HTML document.
Definition generatorformats.inl:53
std::string fragment()
Generate a sentence fragment.
Definition generator.inl:92
std::string csv()
Generate a CSV document.
Definition generatorformats.inl:392
std::string single_paragraph(bool useLipsum)
Generate a single paragraph.
Definition generatorcore.inl:317
std::string json_number()
Generate a random JSON number.
Definition generatorcore.inl:266
std::string code(CodeLanguage lang=CodeLanguage::Cpp)
Generate a code block.
Definition generator.inl:269
std::string slug(char separator='-')
Generate a slug.
Definition generator.inl:203
std::mt19937 m_Gen
Random number generator.
Definition generator.hpp:834
std::string case_slug(CaseSlugCase case_=CaseSlugCase::CamelCase)
Generate a case slug.
Definition generator.inl:212
std::string paragraph(int num=1, bool useLipsum=true)
Generate paragraphs.
Definition generator.inl:125
Class for multi-source generation.
Definition source.hpp:27
Core macros for lipsum-cpp.
#define LIPSUM_API
Macro for shared libraries.
Definition core.hpp:71
Struct lipsum::GeneratorSettings.
This is the main namespace of lipsum-cpp.
CodeLanguage
Languages used by lipsum::Generator::code().
Definition generator.hpp:76
GeneratorFlags
Flags for lipsum-cpp.
Definition generator.hpp:32
CaseSlugCase
Cases used by lipsum::Generator::case_slug().
Definition generator.hpp:58
Mutli-source generation for lipsum-cpp.
Store data for inputting into functions.
Definition argvec2.hpp:29
Settings for lipsum::Generator.
Definition generatorsettings.hpp:27