HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CH_ChannelRef.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_ChannelRef.h ( CH Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __CH_ChannelRef__
12 #define __CH_ChannelRef__
13 
14 #include "CH_API.h"
15 #include "CH_Types.h"
16 #include <UT/UT_Function.h>
17 #include <UT/UT_Map.h>
18 #include <UT/UT_String.h>
19 #include <UT/UT_StringHolder.h>
20 
21 #include <iosfwd>
22 
23 class UT_StringArray;
24 
26 {
27 public:
28 
30  {
31  // this is a bit faster than calling through setChannelRef,
32  // since we avoid the allocString
33  UT_ASSERT( other.myName );
34  myNodeId = other.myNodeId;
35  myIsTrack = other.myIsTrack;
36  myName = other.myName;
37  myExternalCollectionName = other.myExternalCollectionName;
38  }
39 
40  CH_ChannelRef( int node_id, const char *name, bool is_track )
41  {
42  setChannelRef(node_id, name, is_track);
43  }
44 
46  {
47  clear();
48  }
49 
51  {
52  // do nothing for now -- maybe later free strings?
53  }
54 
55  void setChannelRef(int node_id, const char *name, bool is_track);
56 
57  void setExternalChannelRef(const char *name,
58  const UT_StringHolder &external_collection_name);
59 
60  void clear();
61 
62  int getNodeId() const { return myNodeId; }
63 
64  void setNodeId( int new_id ) { myNodeId = new_id; }
65 
66  const char *getName() const { return myName; }
67 
68  bool isTrack() const { return myIsTrack; }
69 
70  bool isGeometry() const;
71 
73  { return myExternalCollectionName; }
74 
75  bool operator==( const CH_ChannelRef &other ) const
76  {
77  return myNodeId == other.myNodeId &&
78  myIsTrack == other.myIsTrack &&
79  myName == other.myName &&
80  myExternalCollectionName == other.myExternalCollectionName;
81  }
82 
84  {
85  if (other.isGeometry())
86  setExternalChannelRef(other.myName, other.myExternalCollectionName);
87  else
88  setChannelRef(other.myNodeId, other.myName, other.myIsTrack);
89  return *this;
90  }
91 
92  bool operator<(const CH_ChannelRef &other) const
93  {
94  if (myNodeId < other.myNodeId)
95  return true;
96 
97  // if both belong to different external (geometry)
98  // collections, sort by collection name
99  if (isGeometry() && other.isGeometry()
100  && myExternalCollectionName
101  != other.myExternalCollectionName)
102  {
103  return myExternalCollectionName
104  < other.myExternalCollectionName;
105  }
106  // FIXME, we should sort by path, not by id
107  if (myNodeId == other.myNodeId &&
108  isLess(myName, other.myName))
109  return true;
110  return false;
111  }
112 
113  bool operator>(const CH_ChannelRef &other) const
114  {
115  if (myNodeId > other.myNodeId)
116  return true;
117 
118  // if both belong to different external (geometry)
119  // collections, sort by collection name
120  if (isGeometry() && other.isGeometry()
121  && myExternalCollectionName
122  != other.myExternalCollectionName)
123  {
124  return myExternalCollectionName
125  > other.myExternalCollectionName;
126  }
127  // FIXME, we should sort by path, not by id
128  if (myNodeId == other.myNodeId &&
129  isGreater(myName, other.myName))
130  return true;
131  return false;
132  }
133 
134  int compare(const CH_ChannelRef& other) const
135  {
136  if (*this < other)
137  return -1;
138  if (*this > other)
139  return 1;
140  return 0;
141  }
142 
143  unsigned int hash() const;
144 
145 private:
146  bool isLess(const char *str1, const char *str2) const
147  {
148  bool rval;
149  if( !str1 )
150  {
151  if( str2 ) rval = true;// Yes, null ptr is < str2
152  else rval = false;
153  }
154  else
155  {
156  if( !str2) rval = false;// Nope, null is < str2
157  else rval = (strcmp(str1, str2) < 0) ? true : false;
158  }
159  return rval;
160  }
161  bool isGreater(const char *str1, const char *str2) const
162  {
163  bool rval;
164  if( !str1 ) rval = false;
165  else
166  {
167  if( !str2 ) rval = true;// Yes, str1 is > null
168  else rval = (strcmp(str1, str2) > 0) ? true : false;
169  }
170  return rval;
171  }
172 
173  int myNodeId:30;
174  unsigned myIsTrack:1;
175 
176  // This is a always const char* from the
177  // static UT_SharedString chStringTable in CH_ChannelRef.C
178  // or the chSharedNullString static value.
179  const char *myName;
180 
181  UT_StringHolder myExternalCollectionName;
182 };
183 
184 
185 inline size_t hash_value(const CH_ChannelRef &ref)
186 {
187  return ref.hash();
188 }
189 
190 /// CH_ChannelRefTable maintains a set of CH_ChannelRef's along with some
191 /// flags that are from CH_ScopeMasks (see CH_Types.h)
193 
198 
199 /// Deletes all the symbols from the table that have the given node_id,
200 /// returns the number of items deleted
201 CH_API extern int
203  CH_ChannelRefTable &ref_table,
204  int node_id,
205  const CH_ChannelRefQueryCallback& should_delete_callback = nullptr,
206  const CH_ChannelRefCallback& pre_delete_callback = nullptr);
207 
208 CH_API extern void
210  const CH_ChannelRefTable &table,
211  UT_StringArray &chan_paths,
212  bool use_alias);
213 
214 CH_API extern void
216  const CH_ChannelRefTable &table,
218 
219 CH_API extern void
221  const CH_ChannelRefTable &table,
222  CH_ChannelRefList &chanrefs,
223  unsigned mask); // mask = 0 means no filtering
224 
225 CH_API extern int
227 
228 CH_API extern bool
230 
231 CH_API extern bool
233 
234 CH_API extern void
236 
237 CH_API extern std::ostream &
238 operator<<(std::ostream &os, const CH_ChannelRef &ref);
239 
240 // UTformat support.
241 CH_API size_t format(char *buffer, size_t buffer_size, const CH_ChannelRef &v);
242 CH_API size_t format(char *buffer, size_t buffer_size, const CH_ChannelRefList &v);
243 
244 #endif
void setNodeId(int new_id)
Definition: CH_ChannelRef.h:64
int compare(const CH_ChannelRef &other) const
CH_API std::ostream & operator<<(std::ostream &os, const CH_ChannelRef &ref)
UT_Map< CH_ChannelRef, unsigned > CH_ChannelRefTable
CH_API void CHaddExposedChannel(const CH_ChannelRefTable &table, CH_ChannelList &channels)
const GLdouble * v
Definition: glcorearb.h:837
CH_API bool CHchannelsToChanRefs(const CH_ChannelList &channels, CH_ChannelRefList &refs)
CH_ChannelRef & operator=(const CH_ChannelRef &other)
Definition: CH_ChannelRef.h:83
CH_ChannelRef(int node_id, const char *name, bool is_track)
Definition: CH_ChannelRef.h:40
bool operator<(const CH_ChannelRef &other) const
Definition: CH_ChannelRef.h:92
CH_API bool CHchanRefsToChannels(const CH_ChannelRefList &refs, CH_ChannelList &channels)
CH_API void CHaddFullChannelPath(const CH_ChannelRefTable &table, UT_StringArray &chan_paths, bool use_alias)
CH_API void CHaddExposedChanRef(const CH_ChannelRefTable &table, CH_ChannelRefList &chanrefs, unsigned mask)
Definition: core.h:760
UT_StringHolder getExternalCollectionName() const
Definition: CH_ChannelRef.h:72
GLint ref
Definition: glcorearb.h:124
GLint GLuint mask
Definition: glcorearb.h:124
bool isTrack() const
Definition: CH_ChannelRef.h:68
GLuint const GLchar * name
Definition: glcorearb.h:786
std::function< T > UT_Function
Definition: UT_Function.h:37
GLenum GLenum GLsizei void * table
Definition: glad.h:5129
int getNodeId() const
Definition: CH_ChannelRef.h:62
unsigned int hash() const
bool isGeometry() const
UT_Function< bool(const CH_ChannelRef &, unsigned flags)> CH_ChannelRefQueryCallback
#define CH_API
Definition: CH_API.h:10
CH_API int CHcompareChanRefs(const CH_ChannelRef *, const CH_ChannelRef *)
CH_ChannelRef(const CH_ChannelRef &other)
Definition: CH_ChannelRef.h:29
CH_API size_t format(char *buffer, size_t buffer_size, const CH_ChannelRef &v)
bool operator==(const CH_ChannelRef &other) const
Definition: CH_ChannelRef.h:75
bool operator>(const CH_ChannelRef &other) const
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
CH_API int CHdeleteRefsWithNodeId(CH_ChannelRefTable &ref_table, int node_id, const CH_ChannelRefQueryCallback &should_delete_callback=nullptr, const CH_ChannelRefCallback &pre_delete_callback=nullptr)
CH_API void CHdisplayChanRefs(const CH_ChannelRefList &refs)
size_t hash_value(const CH_ChannelRef &ref)
UT_Function< void(const CH_ChannelRef &)> CH_ChannelRefCallback
const char * getName() const
Definition: CH_ChannelRef.h:66
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)