Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : */
8 :
9 : #ifndef ELEKTRA_KDB_GEN_HIGHLEVEL_ENUMS_HPP
10 : #define ELEKTRA_KDB_GEN_HIGHLEVEL_ENUMS_HPP
11 :
12 : #include <gen/template.hpp>
13 : #include <map>
14 : #include <set>
15 :
16 : enum class EnumConversion
17 : {
18 : Auto,
19 : Trie,
20 : Strcmp
21 : };
22 :
23 232 : class EnumTrie
24 : {
25 : public:
26 : explicit EnumTrie (const std::set<std::pair<std::string, std::string>> & values);
27 :
28 192 : EnumTrie () : children (), stringValue (), name ()
29 : {
30 : }
31 :
32 : std::string createSwitch ();
33 :
34 : size_t getDepth ();
35 :
36 : private:
37 : std::map<char, std::unique_ptr<EnumTrie>> children;
38 : std::string stringValue;
39 : std::string name;
40 :
41 : void insert (const std::string & prefix, const std::set<std::pair<std::string, std::string>> & values);
42 : bool createSwitch (std::stringstream & ss, size_t index);
43 : };
44 :
45 54 : class EnumProcessor
46 : {
47 : private:
48 : std::unordered_map<std::string, std::pair<std::string, std::string>> enumTypes;
49 :
50 : static kainjow::mustache::list getValues (const std::string & prefix, const kdb::Key & key, std::string & fromStringSwitch,
51 : std::string & valuesString, size_t & trieDepth);
52 :
53 : static inline bool shouldGenerateTypeDef (const kdb::Key & key);
54 :
55 : EnumConversion conversion;
56 :
57 : public:
58 54 : explicit EnumProcessor (EnumConversion conversion_) : conversion (conversion_)
59 : {
60 : }
61 :
62 : kainjow::mustache::object process (const kdb::Key & key, const std::string & tagName);
63 : static std::string getType (const kdb::Key & key, const std::string & tagName, bool & genType);
64 : };
65 :
66 :
67 : #endif // ELEKTRA_KDB_GEN_HIGHLEVEL_ENUMS_HPP
|