LightWrap++
AC++wrapperfortheLightWave3DSDK
generic_handler.h
Go to the documentation of this file.
1 #ifndef LWPP_GENERIC_HANDLER_H
2 #define LWPP_GENERIC_HANDLER_H
3 
4 #include "lwpp/item.h"
5 #include <sstream>
6 #include <lwgeneric.h>
7 #include "lwpp/plugin_handler.h"
8 
9 namespace lwpp
10 {
11  /*
12  XCALL_( int ) MyGeneric( long version, GlobalFunc *global,
13  LWLayoutGeneric *local, void *serverData );
14  */
17  {
18  protected:
19  LWLayoutGeneric *layoutGeneric;
20  int saveScene(const char *file)
21  {
22  return layoutGeneric->saveScene(file);
23  }
24  int loadScene(const char *file, const char *name)
25  {
26  return layoutGeneric->loadScene(file, name);
27  }
28  LWCommandCode lookup (const char *cmdName)
29  {
30  return layoutGeneric->lookup(layoutGeneric->data, cmdName);
31  }
32  int execute (LWCommandCode cmd, int argc, const DynaValue *argv, DynaValue *result)
33  {
34  return layoutGeneric->execute(layoutGeneric->data, cmd, argc, argv, result);
35  }
36  int evaluate (const char *command)
37  {
38  return layoutGeneric->evaluate(layoutGeneric->data, command);
39  }
40  int evaluate (const std::string &command)
41  {
42  return layoutGeneric->evaluate(layoutGeneric->data, command.c_str());
43  }
44  void editServer(const char *type, const char *name, LWItemID id = 0)
45  {
46  lwpp::ItemInfo ii;
47  int index = ii.findServer(type, name, id);
48  if (index == 0)
49  {
50  std::ostringstream cmd;
51  cmd << "ApplyServer " << type << " " << name;
52  evaluate(cmd.str());
53  }
54  index = ii.findServer(type, name, id);
55  std::ostringstream cmd;
56  cmd << "EditServer " << type << " " << index;
57  evaluate(cmd.str());
58  }
59  static int findServer(const char *type, const char *name, LWItemID id = 0)
60  {
61  lwpp::ItemInfo ii;
62  return ii.findServer(type, name, id);
63  }
64  void addServer(const char *type, const char *name)
65  {
66  std::ostringstream cmd;
67  cmd << "ApplyServer " << type << " " << name;
68  evaluate(cmd.str());
69  }
70  void addUniqueServer(const char *type, const char *name, LWItemID id = 0)
71  {
72  if (findServer(type, name, id) > 0) return;
73  std::ostringstream cmd;
74  cmd << "ApplyServer " << type << " " << name;
75  evaluate(cmd.str());
76  }
77  void removeServer(const char *type, const int index)
78  {
79  if (index != 0)
80  {
81  std::ostringstream cmd;
82  cmd << "RemoveServer " << type << " " << index;
83  evaluate(cmd.str());
84  }
85  }
86  void removeServer(const char *type, const char *name, LWItemID id = 0)
87  {
88  while (int index = (findServer(type, name, id)))
89  {
90  std::ostringstream cmd;
91  cmd << "RemoveServer " << type << " " << index;
92  evaluate(cmd.str());
93  }
94  }
95 
96  public:
98  : layoutGeneric(0)
99  {
100  ;
101  }
102  virtual ~LayoutGenericHandler() {;}
103  void setLG (LWLayoutGeneric *local)
104  {
105  layoutGeneric = local;
106  }
107  virtual int Activate() = 0;
108  };
109 
111  template <class T>
113  {
114  public:
115  LayoutGenericAdaptor(const char *name, ServerTagInfo *tags = 0)
116  {
117  LWServer::AddPlugin(LWLAYOUTGENERIC_CLASS, name, Activate, tags);
118  }
120 
121  static int Activate(int version, GlobalFunc *global, LWInstance inst, void *serverData)
122  {
123  UNUSED(serverData);
124  UNUSED(version);
125  LWLayoutGeneric *local = static_cast<LWLayoutGeneric *>(inst);
126  SetSuperGlobal(global);
127  T plugin;
128  plugin.setLG(local);
129  return plugin.Activate();
130  }
131  };
132 
134  {
135  };
136 
137 
139  {
140  public:
143  };
144 
145 
146  // IMPLEMENT_LWPANELHANDLER(LayoutGeneric);
147 
149  template <class T>
151  {
152  private:
153  static T *plugin;
154  public:
155  LayoutNonModalGenericAdaptor(const char *name, ServerTagInfo *tags = 0)
156  {
157  LWServer::AddPlugin(LWLAYOUTGENERIC_CLASS, name, Activate, tags);
158  }
160 
161  static int Activate(int version, GlobalFunc *global, LWInstance inst, void *serverData)
162  {
163  UNUSED(serverData);
164  UNUSED(version);
165  LWLayoutGeneric *local = static_cast<LWLayoutGeneric *>(inst);
166  SetSuperGlobal(global);
167  if (plugin == 0) plugin = new T();
168  plugin->setLG(local);
169  return plugin->Activate();
170  }
171  };
172 
173  #define IMPLEMENT_NONMODAL_GENERIC(className) template<> className *lwpp::LayoutNonModalGenericAdaptor< className >::plugin = 0;
174 }
175 
176 #endif //LWPP_GENERIC_HANDLER_H