OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Basic / FolioObject.hh
1 /*      Copyright (c) 1995 FUJITSU LIMITED      */
2 /*      All Rights Reserved                     */
3
4 /*
5  * $XConsortium: FolioObject.hh /main/5 1996/09/10 17:26:30 barstow $
6  *
7  * Copyright (c) 1991 HaL Computer Systems, Inc.  All rights reserved.
8  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
9  * States.  Use of a copyright notice is precautionary only and does not
10  * imply publication or disclosure.
11  * 
12  * This software contains confidential information and trade secrets of HaL
13  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
14  * without the prior express written permission of HaL Computer Systems, Inc.
15  * 
16  *                         RESTRICTED RIGHTS LEGEND
17  * Use, duplication, or disclosure by the Government is subject to
18  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
19  * Technical Data and Computer Software clause at DFARS 252.227-7013.
20  *                        HaL Computer Systems, Inc.
21  *                  1315 Dell Avenue, Campbell, CA  95008
22  * 
23  */
24
25 // Base Object for ALL Folio Objects
26
27 class Dependent;
28 class DependOnList;
29 class FolioObject;
30
31 typedef void (FolioObject::* notify_handler_t)
32   (FolioObject *object, u_int notify_type,
33    void *call_data, void *client_data);
34
35 #if defined(__STDC__) || defined(hpux) || defined(__osf__)
36 #define DEF_CLASS(C) \
37   virtual ClassType type() const; \
38   static ClassType C##Class
39 #define INIT_CLASS(C) \
40   ClassType C::type() const { return (C##Class); } \
41   ClassType C::C##Class = (size_t) &C::C##Class
42 #else
43 #define DEF_CLASS(C) \
44   virtual ClassType type() const; \
45   static ClassType C/**/Class
46 #define INIT_CLASS(C) \
47   ClassType C::type() const { return (C/**/Class); } \
48   ClassType C::C/**/Class = (ClassType) &C::C/**/Class
49 #endif
50
51 #ifdef __osf__
52   typedef char * ClassType;
53 #else
54   typedef int ClassType;
55 #endif
56
57 class FolioObject
58 {
59 public: // enums
60 #define FolioObjectLast 1
61   enum notify_types { DESTROYED = 0, _LAST = FolioObjectLast };
62   DEF_CLASS (FolioObject);
63
64 public: // functions
65   FolioObject();
66   virtual ~FolioObject();
67
68   virtual const char *display_as();
69
70 #define AddDependent(CB, TYPE) \
71   add_dependent (this, (notify_handler_t)CB, TYPE)
72 #define AddDependentd(CB, TYPE, DATA) \
73   add_dependent (this, (notify_handler_t)CB, TYPE, DATA)
74
75 #if defined(SC3) || defined(__osf__) || defined(USL) || defined(__SunOS)
76   void add_dependent (FolioObject *dependent, notify_handler_t handler,
77                       u_int notify_type, void *dependent_data = NULL);
78 #else
79   void add_dependent (void *dependent, notify_handler_t handler,
80                       u_int notify_type, void *dependent_data = NULL);
81 #endif
82
83 #define RemoveDependent(CB, TYPE) \
84   remove_dependent(this, (notify_handler_t)CB, TYPE)
85 #define RemoveDependentd(CB, TYPE, DATA) \
86   remove_dependent(this, (notify_handler_t)CB, TYPE, DATA)
87
88 #if defined(SC3) || defined(__osf__) || defined(USL) || defined(__SunOS)
89   void remove_dependent (FolioObject *dependent, notify_handler_t handler,
90                          u_int notify_type, void *dependent_data = NULL);
91 #else
92   void remove_dependent (void *dependent, notify_handler_t handler,
93                          u_int notify_type, void *dependent_data = NULL);
94 #endif
95   void remove_depend_on (FolioObject *target, Dependent *d);
96   void release_dependents();
97   void release_depend_on_list();
98
99 #define Observe(TARG, TYPE, CB) \
100   observe (this, TARG, (notify_handler_t) CB, TYPE)
101 #define Observed(TARG, TYPE, CB, DATA) \
102   observe (this, TARG, (notify_handler_t) CB, TYPE, DATA)
103
104 #if defined(SC3) || defined(__osf__) || defined(USL) || defined(__SunOS)
105   void observe (FolioObject *real_this, FolioObject *target,
106                 notify_handler_t callback, u_int notify_type,
107                 void *client_data = NULL);
108 #else
109   void observe (void *real_this, FolioObject *target,
110                 notify_handler_t callback, u_int notify_type,
111                 void *client_data = NULL);
112 #endif
113   
114   bool initialized()
115     { return (f_initialized); }
116   ErrorCode status()
117     { return (f_status); }
118
119 protected: // functions
120   // Object states that it has changed - dependents notified.
121   // notify_type should be an enum provided by the object.  Dependents
122   // should know about various object change types that it cares about.
123   // Dependents should ignore change types that it doesn't care about. 
124   void notify (u_int notify_type, void *notify_data = NULL);
125
126   void self_destruct();
127   void setInitialized()
128     { f_initialized = TRUE; }
129   void unsetInitialized()
130     { f_initialized = FALSE; }
131   void setStatus (ErrorCode status)
132     { f_status = status; }
133
134 protected: // variables
135   ErrorCode      f_status;
136   bool   f_initialized;
137   Dependent     *f_dependents;
138   DependOnList  *f_depend_on_list;
139 };