LightWrap++
AC++wrapperfortheLightWave3DSDK
monitor.h
Go to the documentation of this file.
1 #ifndef LWPP_MONITOR_H
2 #define LWPP_MONITOR_H
3 
4 #include <lwpp/global.h>
5 #include <lwmonitor.h>
6 
7 namespace lwpp
8 {
9 
10  class BaseMonitor
11  {
12  public:
13  virtual ~BaseMonitor(void)
14  {
15  ;
16  }
17 
18  virtual void Setup(const std::string title, unsigned int flags = 0, const char *histfile = 0) = 0;
19 
20  virtual void init(unsigned int total, std::string message = std::string("Processing...")) = 0;
21 
22  virtual bool step(unsigned int incr = 1, std::string message = std::string("Processing...")) = 0;
23 
24  virtual bool step(std::string message)
25  {
26  return step(0, message);
27  }
28 
29  virtual void done(void) = 0;
30 
31  virtual void close(void) = 0;
32  };
33 
35  class Monitor : public BaseMonitor, protected GlobalBase<LWLMonFuncs>
36  {
37  LWLMonID id;
38  public:
39  Monitor(const std::string title, unsigned int flags = LMO_IMMUPD, const char *histfile = 0)
40  : id(0)
41  {
42  id = globPtr->create();
43  if (id) globPtr->setup(id, const_cast<char *>(title.c_str()), flags, histfile);
44  }
45 
47  : id(0)
48  {
49  ;
50  }
51 
52  void Setup(const std::string title, unsigned int flags = LMO_IMMUPD, const char *histfile = 0)
53  {
54  close();
55  if (globPtr)
56  {
57  id = globPtr->create();
58  if (id) globPtr->setup(id, const_cast<char *>(title.c_str()), flags, histfile);
59  }
60  }
61 
62  void setwinpos(int x, int y, int w, int h)
63  {
64  if (globPtr) globPtr->setwinpos(id, x, y, w, h);
65  }
66 
67  void init(unsigned int total, std::string message)
68  {
69  if (globPtr) globPtr->init(id, total, message.c_str());
70  }
71 
72  void init(unsigned int total = 1)
73  {
74  if (globPtr) globPtr->init(id, total, 0);
75  }
76 
77  bool step(unsigned int incr, std::string message)
78  {
79  if (globPtr) return (globPtr->step(id, incr, message.c_str()) == 1);
80  return false;
81  }
82  bool step(unsigned int incr = 1)
83  {
84  if (globPtr) return (globPtr->step(id, incr, 0) == 1);
85  return false;
86  }
87  bool step(std::string message)
88  {
89  if (globPtr) return (globPtr->step(id, 0, message.c_str()) == 1);
90  return false;
91  }
92 
93  void done(void)
94  {
95  if (id)
96  {
97  if (globPtr) globPtr->done(id);
98  }
99  }
100  void close(void)
101  {
102  if (id)
103  {
104  if (globPtr) globPtr->destroy(id);
105  id = 0;
106  }
107  }
108  ~Monitor(void)
109  {
110  close();
111  }
112  };
113 
115  {
116  private:
117  LWMonitor *monitor;
118  public:
119  SimpleMonitor(LWMonitor *mon) : monitor(mon) {}
120  SimpleMonitor(const SimpleMonitor &mon) : monitor(mon.monitor) {}
121  virtual ~SimpleMonitor()
122  {
123  Done();
124  }
125  void setMonitor (LWMonitor *mon)
126  {
127  monitor = mon;
128  }
129  void Init(int total)
130  {
131  if (monitor) monitor->init(monitor->data, total);
132  }
133  bool Step(int step = 1)
134  {
135  if (monitor) return (monitor->step(monitor->data, step) != 0);
136  return true;
137  }
138  void Done()
139  {
140  if (monitor) monitor->done(monitor->data);
141  monitor = 0;
142  }
143  };
144 }
145 #endif // LWPP_MONITOR_H