Mercurial > thymian
comparison templates/template_struct.h @ 0:a4671277546c tip
created the repository for the thymian project
| author | ferencd |
|---|---|
| date | Tue, 17 Aug 2021 11:19:54 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a4671277546c |
|---|---|
| 1 #ifndef TEMPLATE_STRUCT_H | |
| 2 #define TEMPLATE_STRUCT_H | |
| 3 | |
| 4 #include <string> | |
| 5 #include <vector> | |
| 6 #include <map> | |
| 7 | |
| 8 /** | |
| 9 * @brief The template_struct class represents a logical structure that can be inserted into the | |
| 10 * template's content in order to have a logical grouping of various data. | |
| 11 */ | |
| 12 class template_struct | |
| 13 { | |
| 14 public: | |
| 15 | |
| 16 template_struct() = default; | |
| 17 explicit template_struct(const std::string& t) : name("name"), type(t) {} | |
| 18 template_struct(const std::string& n, const std::string& t) : name(n), type(t) {} | |
| 19 | |
| 20 virtual ~template_struct() = default; | |
| 21 | |
| 22 std::string& operator[] (const char* p) | |
| 23 { | |
| 24 return struct_members[std::string(p)]; | |
| 25 } | |
| 26 | |
| 27 const std::string& operator[] (const char* p) const | |
| 28 { | |
| 29 return struct_members.at(std::string(p)); | |
| 30 } | |
| 31 | |
| 32 std::string& operator[] (const std::string& p) | |
| 33 { | |
| 34 return struct_members[std::string(p)]; | |
| 35 } | |
| 36 | |
| 37 const std::string& operator[] (const std::string& p) const | |
| 38 { | |
| 39 return struct_members.at(std::string(p)); | |
| 40 } | |
| 41 | |
| 42 std::vector<std::string> keys() const | |
| 43 { | |
| 44 std::vector<std::string> v; | |
| 45 for(const auto& it : struct_members) | |
| 46 { | |
| 47 v.push_back(it.first); | |
| 48 } | |
| 49 return v; | |
| 50 } | |
| 51 | |
| 52 bool has_key(const std::string& k) | |
| 53 { | |
| 54 for(const auto& it : struct_members) | |
| 55 { | |
| 56 if(it.first == k) return true; | |
| 57 } | |
| 58 return false; | |
| 59 } | |
| 60 | |
| 61 std::string name; | |
| 62 std::string type; | |
| 63 std::map<std::string, std::string> struct_members; | |
| 64 }; | |
| 65 | |
| 66 #endif // TEMPLATE_STRUCT_H |
