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