1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 
14 
15 #ifndef _GroupManager_h
16 #define _GroupManager_h
17 
18 
19 #include "Base.h"
20 #include "Dictionary.h"
21 #include "DXStrings.h"
22 
23 //
24 // Class name definition:
25 //
26 #define ClassGroupManager	"GroupManager"
27 
28 class List;
29 class DXApplication;
30 class Network;
31 class GroupedObject;
32 
33 
34 //
35 // The class to hold the group info
36 //
37 class GroupRecord
38 {
39   friend class GroupManager;
40   friend class GroupedObject;
41   private:
42 
43     Network *network;
44     boolean dirty;
45     char *name;
46 
47   protected:
48 
GroupRecord(Network * network,const char * name)49     GroupRecord(Network *network, const char *name) {
50 	this->network = network;
51         this->dirty   = FALSE;
52 	this->name    = DuplicateString(name);
53     };
54 
55   public:
isDirty()56     	    boolean  isDirty () { return this->dirty; }
57     	    void     setDirty (boolean dirty = TRUE) { this->dirty = dirty; }
getNetwork()58     	    Network *getNetwork () { return this->network; }
changesWhere()59     virtual boolean  changesWhere () { return FALSE; }
60 
getName()61     const   char    *getName() { return this->name; }
62 
~GroupRecord()63     virtual ~GroupRecord() {
64 	if (this->name) delete this->name;
65     }
66 };
67 
68 
69 //
70 // GroupManager class definition:
71 //
72 class GroupManager : public Base
73 {
74   private:
75     //
76     // Private member data:
77     //
78 
79   protected:
80     //
81     // Protected member data:
82     //
83     boolean  dirty;
84     //
85     // The host-argument dictionary
86     //
87     Dictionary	arguments;
88     //
89     // A dictionary of lists of GroupRecord.
90     //
91     Dictionary	groups;
92 
93     DXApplication *app;
94 
95     Network* network;
96 
97     //
98     // Constructor:
99     //
100     GroupManager(Network*, Symbol groupID);
101 
102     virtual GroupRecord *recordAllocator(Network *net, const char *name) = 0;
103 
104     Symbol groupID;
105 
106   public:
107     //
108     // Destructor:
109     //
110     ~GroupManager();
111 
112     //
113     // Remove all nodes from all groups and all groups from this manager.
114     //
115     virtual void clear();
116 
117     //
118     // Return the number of groups.
119     //
getGroupCount()120     int getGroupCount() { return this->groups.getSize(); }
121 
122     //
123     // Check if the given group exists.
124     //
hasGroup(const char * name)125     boolean hasGroup(const char *name)
126     {
127 	return (boolean)
128 	    ((GroupRecord*)this->groups.findDefinition(name) != NUL(GroupRecord*));
129     }
130 
131     //
132     // Return the group record
133     //
getGroup(const char * name)134     GroupRecord *getGroup(const char *name)
135     {
136 	return (GroupRecord*)this->groups.findDefinition(name);
137     }
138 
139     //
140     // Return the Nth group's name (1 based).
141     //
getGroupName(int n)142     const char* getGroupName(int n)
143     {
144 	return this->groups.getStringKey(n);
145     }
146 
147     //
148     // Create a new group of nodes with the given name.
149     // If name is already active, then return FALSE.
150     //
151     boolean 	createGroup(const char *name, Network *net);
152 
153     //
154     // Add more modules to the existing group.
155     //
156     boolean 	addGroupMember(const char *name, Network *net);
157 
158     //
159     // Remove modules from the existing group.
160     //
161     virtual boolean 	removeGroupMember(const char *name, Network *net);
162 
163     //
164     // Called when reading a network.
165     //
166     boolean 	registerGroup(const char *name, Network *net);
167     //
168     // Removes the nodes from the named group.
169     // Return FALSE if the group does not exist.
170     //
171     boolean 	removeGroup(const char *name,Network *net);
172 
173     //
174     // return the network a group resides.
175     //
176     Network *getGroupNetwork(const char* name);
177 
178     //
179     // Select nodes in the group.
180     //
181     boolean selectGroupNodes(const char *name);
182 
183     //
184     //
185     //
isDirty()186     boolean isDirty() { return this->dirty; }
187     void setDirty(boolean set = TRUE) { this->dirty = set; }
188 
189     //
190     // Parse/Print the  group assignment comment.
191     //
parseComment(const char *,const char *,int,Network *)192     virtual boolean parseComment(const char *,
193 			const char *,
194 			int ,
195 			Network *){ return TRUE; }
printComment(FILE *)196     virtual boolean printComment(FILE *){ return TRUE; }
printAssignment(FILE *)197     virtual boolean printAssignment(FILE *){ return TRUE; }
198 
199     const char *getManagerName();
getManagerSymbol()200     Symbol getManagerSymbol() { return this->groupID; }
201 
survivesMerging()202     virtual boolean survivesMerging() { return FALSE; }
203 
204     //
205     // Returns a pointer to the class name.
206     //
getClassName()207     const char* getClassName()
208     {
209 	return ClassGroupManager;
210     }
211 };
212 
213 
214 #endif // _GroupManager_h
215