HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CH_Group.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: CH library (C++)
7  *
8  * COMMENTS: Channel Group container
9  *
10  */
11 
12 #ifndef __CH_Group_h__
13 #define __CH_Group_h__
14 
15 #include "CH_API.h"
16 #include "CH_ChannelRef.h"
17 #include "CH_Collection.h"
18 #include <UT/UT_String.h>
19 #include <UT/UT_ValArray.h>
20 
21 #include <iosfwd>
22 
23 class UT_StringArray;
24 class CH_GroupEntry;
25 class CH_Channel;
26 class CH_Collection;
27 class CH_Manager;
28 
29 /*
30  * IMPORTANT: CH_Group pointers are persistent
31  * that means, CH_Manager functions go to great lengths to
32  * ensure that channel groups preserve their CH_Group pointers
33  * philosophy:
34  * 1. a group stores channels and patterns
35  * 2. channels are added through all the usual channel addition means
36  * 3. channels are deleted through usual channel deletion means, or when a
37  * channel is deleted
38  * 4. renaming a channel or chaning its alias has no effect on its membership
39  * 5. groups are warned by the channel manager when channels get deleted or
40  * renamed (TODO if necessary)
41  * 6. channel pointers are guaranteed to stay the same for the duration of the
42  * existence of the channel.
43  * - this means that deleting and re-adding a channel is not a null
44  * operation, as the group will lose it. Moreover, this is bad style
45  * because deleting a channel will send out events that may not be cheap.
46  * - if this becomes too hard to maintain, then it is easy to go back to
47  * storing channel names instead of pointers, by simply modifying the
48  * channel add/remove functions
49  * 7. patterns are TODO, but will remain even when the pattern no longer
50  * matches any channels
51  * 8. when a channel is created, the channel manager notifies groups so that
52  * they can perform the pattern match. Hence, patterns may be slow.
53  */
54 
55 /*
56  * - the marking (CHM) indicates that functions in this section should only be
57  * called from the channel manager.
58  * - the marking (*) indicates that anyone can call this function
59  * - the section labelled INTERNAL should only be called from within CH_Group
60  */
61 
63 {
64 friend class CH_Manager;
66 
67 public:
68  static char getGroupChar() { return '@'; }
69  static int cmp( const CH_Group *a, const CH_Group *b );
70 
71 private:
72  // CONSTRUCTORS AND DESTRUCTOR (CHM)
73  CH_Group();
74  ~CH_Group();
75 
76  // (CHM)
77  void setName(const char *name);
78  CH_Group *clone();
79 
80 public:
81  // INFO FUNCTIONS(*)
82  const UT_String &getName() const { return myName; }
83  void getFullPath(UT_String &str) const;
84  bool isInTree() const { return myIsInTree; }
85  bool isRoot() const { return myIsInTree && myParent==NULL; }
86  bool isEmpty() const;
87  int getTotalEntries() const;
88 
89  void clear();
90  void displayInfo(int indent = 0) const;
91 
92  // ORDERING (*)
93  void makeLast();
94  void changeIndex( int new_index );
95 
96  // GROUP TREE ITERATION (*)
97  CH_Group *getParentGroup() { return myParent; }
98  int getSubGroupEntries() { return myGroups.entries(); }
99  const UT_ValArray<CH_Group*> &getSubGroups() { return myGroups; }
100  bool isEventualParentOf( CH_Group *other );
101  int findIndex( CH_Group *subgroup );
102 
103  // CHANNEL QUERY FUNCTIONS (*) (no undos)
104  int getEntries() const { return myChannels.size(); }
105  bool strictContains( const CH_Channel *chp) const;
106  bool strictContains( const CH_ChannelRef &chref) const;
107  bool contains(const CH_Channel *chp) const;
108  bool contains(const CH_ChannelRef &chref) const;
109  int strictGetChannels(CH_ChannelList &channels) const;
110  int strictGetChanRefs(CH_ChannelRefList &chanrefs) const;
111  int getChannels(CH_ChannelList &channels) const;
112  int getChanRefs(CH_ChannelRefList &chanrefs) const;
113  int getFullChannelPaths(UT_StringArray &channel_paths,
114  bool use_alias=false) const;
115 
116  // CHANNEL FUNCTIONS (*)
117  // return values: number of channels added/removed
118  int addChannel(const CH_Channel *chp);
119  int addChannel( const CH_ChannelRef &chref );
120 
121  int removeChannel( const CH_Channel *chp);
122  int removeChannel( const CH_ChannelRef &chref );
123 
124  int addChannels(const CH_ChannelList &channels);
125  int addChannels(const CH_ChannelRefList &chanrefs);
126 
127  int removeChannels(const CH_ChannelList &channels);
128  int removeChannels(const CH_ChannelRefList &chanrefs);
129  void changeReferencesToNodeId(int old_id, int new_id);
130  void removeChannelsWithNodeId(int node_id);
131 
132  // PATTERN FUNCTIONS (*)
133  //bool addPattern(const char *pattern); // returns exists
134  //bool removePattern(const char *pattern); // returns found
135 
136  // FLAGS FUNCTIONS (*)
137  unsigned getScopeFlags( unsigned flags );
138  void dirtyScopeFlags( unsigned flags );
139  void dirtySubtreeScopeFlags( unsigned flags );
140  // for passive flags only
141  // this function updates passive flags to respond to parameter state changes
142  bool updateScopeFlags( unsigned flags );
143  void dirtyAllScopeFlags();
144 
145 private:
146  // INTERNAL FUNCTIONS
147  void getChanRefsInternal(CH_ChannelRefTable &table) const;
148  int addChannelInternal(const CH_ChannelRef &chref);
149  int removeChannelInternal(const CH_ChannelRef &chref);
150  void removeMeFromMyParent();
151  CH_Group *createGroupInternal(const char *name);
152  bool removeGroupInternal(CH_Group *sub_group);
153  void removeChanRefFromParents(const CH_ChannelRef &chref);
154 
155  // MESSAGE FUNCTIONS (CHM)
156  void channelDeleted( const CH_Channel *chp );
157  void channelCreated( const CH_Channel *chp );
158 
159  // GROUP TREE FUNCTIONS (CHM)
160  void findValidGroupName( UT_String &name );
161  CH_Group *findGroup(const char *name, bool create);
162  void findGroups( UT_ValArray< CH_Group* > &groups,
163  const char *pattern, bool minimal );
164  void insertGroup( CH_Group *source,
165  const char *new_name=0 );
166  bool getGroupsFromChannels(
167  const CH_ChannelRefTable& channels,
168  CH_GroupList& groups);
169  void propagateInTreeFlag();
170 
171 public:
172  // IO FUNCTIONS (*)
173  void save(std::ostream &os, int binary) const;
174  bool load(UT_IStream &is);
175 
176 private:
177  UT_String myName;
178  CH_Group *myParent;
179  unsigned myScopeFlags: CH_NUM_FLAGS;
180  unsigned myDirtyScopeFlags: CH_NUM_FLAGS;
181  unsigned myIsInTree: 1;
182 
183  CH_ChannelRefTable myChannels;
184  //UT_ValArray<CH_GroupEntry *> myPatterns;
185  UT_ValArray<CH_Group *> myGroups;
186 };
187 
188 #endif
static char getGroupChar()
Definition: CH_Group.h:68
int getEntries() const
Definition: CH_Group.h:104
bool isRoot() const
Definition: CH_Group.h:85
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
const UT_ValArray< CH_Group * > & getSubGroups()
Definition: CH_Group.h:99
GLbitfield flags
Definition: glcorearb.h:1595
CH_Group * getParentGroup()
Definition: CH_Group.h:97
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
bool isInTree() const
Definition: CH_Group.h:84
GLuint const GLchar * name
Definition: glcorearb.h:785
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
int cmp(T a, T b)
Definition: ImathFun.h:119
const UT_String & getName() const
Definition: CH_Group.h:82
#define CH_API
Definition: CH_API.h:10
int getSubGroupEntries()
Definition: CH_Group.h:98