OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / dtinfogen / infolib / etc / Task.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: Task.h /main/2 1996/07/18 15:23:13 drk $ */
24
25 #ifndef __Task_h
26 #define __Task_h
27
28 #include <stddef.h>
29
30 #include "Exceptions.hh"
31
32 class Unexpected : public Exception{
33 public:
34   /* BEWARE! we keep a pointer to the string without copying it! */
35   Unexpected(const char *msg)  { msg_ = msg; };
36
37   const char *msg(void) { return msg_; };
38
39   DECLARE_EXCEPTION(Unexpected, Exception)
40   
41 private:
42   const char *msg_;
43 };
44
45
46 class Token;
47
48 class Task{
49 public:
50   virtual ~Task() {};
51   
52   virtual void markup(const Token& t) = 0 /* throw(Unexpected) */;
53
54   virtual void data(const char *chars,
55                     size_t len) = 0;
56
57 };
58
59 class ComplexTask: public Task{
60
61 public:
62   virtual void markup(const Token& t) /* throw(Unexpected) */;
63
64   virtual void data(const char *chars,
65                     size_t len);
66 protected:
67   ComplexTask();
68   ~ComplexTask();
69
70   void removeAllSubTasks();
71   void addSubTask(Task *);
72
73   void stopSubTask(Task *);
74
75 #define KILLSUBTASK(t) { if(t) { stopSubTask(t); delete t; t = NULL; } }
76
77   Task *subtask(int i) { return subtasks[i]; };
78
79 protected:
80   Task **subtasks;
81   int    used;
82
83 private:
84   int    alloc;
85
86   void grow(int);
87 };
88
89 #define TEST_TASK 0
90 #if TEST_TASK
91
92 class TestTask : public Task{
93
94 public:
95   virtual void markup(const Token& t) /* throw(Unexpected) */;
96
97   virtual void data(const char *chars,
98                     size_t len);
99 };
100
101 class TestTask2: public ComplexTask{
102
103 protected:
104   int f_base;
105   
106 public:
107   virtual void markup(const Token& t) /* throw(Unexpected) */;
108
109   virtual void data(const char *chars,
110                     size_t len);
111   TestTask2();
112 };
113 #endif /* TEST_TASK */
114
115 #endif /* __Task_h */