guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gproptype.hpp
1 
2 //
3 // Prop Type
4 // guit GUI Toolkit
5 // Copyright © 2020 Eric Lecolinet. All rights reserved.
6 // http://www.telecom-paris.fr/~elc
7 //
8 
9 #ifndef Guit_PropType_hpp
10 #define Guit_PropType_hpp
11 #include <gobject.hpp>
12 namespace guit {
13 
14 
16 class GPropType {
17 public:
18  // NOTE: props with a negative role are never equivalent (see GProp::isEquivalent()).
19  enum Role {
20  Modes = -8, States = -7, Holder = -6, Expr = -5, ExprWrapper = -4,
21  Notifier = -3, Cond = -2, Abstract = -1,
22  Align, Background, Border, Color, Flex, Flow, Font, Format, Gap, Hotkey,
23  Icon, Margin, Pos, Size, Text, Tip, RenderCount,
24  Bool, Number, Choice, Anim,
25  Auto // number is auto set
26  };
27 
30  GString const& name() const {return name_;}
31  int role() const {return role_;}
33 
37  virtual GProp& newInstance() noexcept(false);
38  virtual GProp& newInstance(GString const& arg) noexcept(false);
40 
42  static GProp* createInstance(GString const& type_name, GString const& arg,
43  bool css_style = false);
44 
46  static GPropType* findType(GString const& type_name);
47 
48  bool operator==(GPropType const& other) const;
49  bool operator!=(GPropType const& other) const;
50 
52  void operator delete(void*);
53 
56  virtual ~GPropType() = default;
57  GPropType(GString const& name, int role);
58  GPropType(GString const& name, GPropType& parent);
60 
61 protected:
62  friend class GProp;
63  friend class GPropList;
64 
65  GPropType(GPropType&) = delete;
66  GPropType(GPropType&&) = delete;
67  GPropType& operator=(GPropType const&) = delete;
68  void addType();
69 
70  GString name_;
71  mutable int role_{};
72  GPropType* parent_{};
73 };
74 
75 
77 template <class P, class Super>
78 class GPropType_ : public Super::GType {
79 public:
80  using Value = P;
81 
82  P& newInstance() override {return *new P();}
83  P& newInstance(GString const& arg) override {return *new P(arg);}
84 
86  template <typename O>
87  P& operator<<=(O& other) {P& p{(*this)()}; p <<= other; return p;}
88 
91  GPropType_(GString const& name, int role) : Super::GType(name, role) {}
92  GPropType_(GString const& name, GPropType& parent) : Super::GType(name, parent) {}
94 };
95 
96 }
97 #endif