Guest User

Untitled

a guest
Jul 9th, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <vector>
  2. #include <memory>
  3. #include <string>
  4. #include <utility>
  5. #include <any>
  6. #include <variant>
  7.  
  8. namespace Org {
  9.  
  10. class Node;
  11. class Headline;
  12.  
  13. using OrgType = std::variant<Node, Headline>;
  14. using OrgTypePtr = std::shared_ptr<OrgType>;
  15. using OrgTypeVector = std::vector<std::shared_ptr<std::variant<Node, Headline>>>;
  16.  
  17. /* test to play from
  18. https://www.fluentcpp.com/2021/01/29/inheritance-without-pointers/
  19. /*
  20. //template <Interface>
  21. class NodeImplementation
  22.   {
  23. public:
  24.   template<typename NodeType>
  25.   NodeImplementation(NodeType &&node)
  26.     : storage{std::forward<NodeType>(node)},
  27.       getter{[](std::any &storage)->Node& { return std::any_cast<NodeType&>(storage);}}
  28.   { }
  29.  
  30.   Node *operator->() { return &getter(storage); }
  31.  
  32. private:
  33.   std::any storage;
  34.   Node& (*getter)(std::any&);
  35. };
  36. */
  37. class Node
  38. {
  39.   enum NodeType {ROOT, HEADLINE, LIST, TABLE, TAG}; //?
  40. public:
  41.  
  42.   Node(OrgTypePtr parent=nullptr, std::string content={}) :
  43.     m_parent(parent),
  44.     m_content(content)
  45.   {}
  46.   //private:
  47.   OrgTypePtr m_parent;
  48.   OrgTypeVector m_children;
  49.   std::string m_content;
  50.   //virtual void parse_content()=0;
  51. };
  52.  
  53. class Headline: public Node
  54. {
  55. public:
  56.  
  57.   Headline(OrgTypePtr parent=nullptr, std::string content={})
  58.    : Node(parent, content) {};
  59.  
  60.   enum State { EMPTY, TODO, DONE, WAITING } state;
  61.   int level;
  62. };
  63.  
  64. class List: public Node
  65. {
  66. public:
  67.   int blyat;
  68. };
  69.  
  70. }; // end of namespace
  71.  
Advertisement
Add Comment
Please, Sign In to add comment