LightWrap++
AC++wrapperfortheLightWave3DSDK
wrapper.h
Go to the documentation of this file.
1 
5 #ifndef LWPP_WRAPPER_H
6 #define LWPP_WRAPPER_H
7 
8 #include <lwpp/xpanel.h>
9 
10 namespace lwpp
11 {
13 
18  {
19  protected:
20  int index;
22 
25  virtual size_t popCount() = 0;
27 
31  virtual const char *popName(int n) = 0;
32  public:
34  : index(0)
35  {
36  ;
37  }
38  virtual ~PopUpCallback() {;}
40  static int PopCount(void *inst)
41  {
42  if (inst)
43  {
44  PopUpCallback *puc = static_cast<PopUpCallback *>(inst);
45  return (int) puc->popCount();
46  }
47  return 0;
48  }
50  static const char* PopName(void *inst, int n)
51  {
52  if (inst)
53  {
54  PopUpCallback *puc = static_cast<PopUpCallback *>(inst);
55  return puc->popName(n);
56  }
57  return 0;
58  }
59  const char *GetSelectedName()
60  {
61  return popName(index);
62  }
63  };
65 
69  {
70  protected:
72  virtual size_t count(void) = 0;
74  virtual const char *name(int n) = 0;
75  public:
77  static size_t countFn (void *inst);
79  static char* nameFn (void *inst, int n);
80  };
81 
82  template <class T>
84  {
85  private:
86  template <class C>
87  class popupEntry
88  {
89  public:
90  C value;
91  const char *name;
92  popupEntry(const char *_title, C _value) : name(_title), value(_value) {;}
93  const char *getName() const {return name;}
94  C getValue() const {return value;}
95  bool equals(C _value) {return value == _value;}
96  };
97 
98  std::vector< popupEntry<T> > Entries;
99 
100  protected:
101  virtual size_t popCount(void)
102  {
103  return Entries.size();
104  }
105  virtual const char *popName(int n)
106  {
107  if (n < 0) return "(none)";
108  else return Entries.at(n).getName();
109  }
110 
111  public:
113  virtual ~ExtendedPopUp() {;}
114  virtual void AddEntry (const char *entry, T id)
115  {
116  Entries.push_back(popupEntry<T>(entry, id));
117  }
118  virtual T GetEntry (int n)
119  {
120  return Entries.at(n).getValue();
121  }
123  virtual size_t GetIndex (T val)
124  {
125  for (size_t n = 0; n < Entries.size(); ++n)
126  {
127  if (Entries.at(n).equals(val)) return n;
128  }
129  return 0; // not found
130  }
131  };
132 
133  template<class T>
135  {
136  public:
137  static void PopCommand (LWXPanelID pan, int cid, int cmd)
138  {
139  XPanelFuncs xpf;
140  T *pcc = static_cast<T *>(xpf.getUserData(pan, cid));
141  if (pcc) pcc->popCommand(cid, cmd);
142  }
143  };
144 
146  template <typename T>
147  class doPop
148  {
149  public:
150  static int PopCount(void *inst)
151  {
152  if (inst)
153  {
154  T *puc = static_cast<T *>(inst);
155  return puc->popCount();
156  }
157  return 0;
158  }
160  static const char* PopName(void *inst, int n)
161  {
162  if (inst)
163  {
164  T *puc = static_cast<T *>(inst);
165  return puc->popName(n);
166  }
167  return 0;
168  }
169  };
170 }
171 #endif // LWPP_WRAPPER_H