HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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_Map.h>
17 #include <UT/UT_String.h>
18 
19 #include <functional>
20 #include <iosfwd>
21 
22 class UT_StringArray;
23 
25 {
26 public:
27 
29  {
30  // this is a bit faster than calling through setChannelRef,
31  // since we avoid the allocString
32  UT_ASSERT( other.myName );
33  myNodeId = other.myNodeId;
34  myIsTrack = other.myIsTrack;
35  myName = other.myName;
36  }
37 
38  CH_ChannelRef( int node_id, const char *name, bool is_track )
39  {
40  setChannelRef(node_id, name, is_track);
41  }
42 
44  {
45  clear();
46  }
47 
49  {
50  // do nothing for now -- maybe later free strings?
51  }
52 
53  void setChannelRef(int node_id, const char *name, bool is_track);
54 
55  void clear();
56 
57  int getNodeId() const { return myNodeId; }
58 
59  void setNodeId( int new_id ) { myNodeId = new_id; }
60 
61  const char *getName() const { return myName; }
62 
63  bool isTrack() const { return myIsTrack; }
64 
65  bool operator==( const CH_ChannelRef &other ) const
66  {
67  return myNodeId == other.myNodeId &&
68  myIsTrack == other.myIsTrack &&
69  myName == other.myName;
70  }
71 
73  {
74  setChannelRef(other.myNodeId, other.myName,
75  other.myIsTrack);
76  return *this;
77  }
78 
79  bool operator<(const CH_ChannelRef &other) const
80  {
81  if (myNodeId < other.myNodeId)
82  return true;
83  // FIXME, we should sort by path, not by id
84  if (myNodeId == other.myNodeId &&
85  isLess(myName, other.myName))
86  return true;
87  return false;
88  }
89 
90  bool operator>(const CH_ChannelRef &other) const
91  {
92  if (myNodeId > other.myNodeId)
93  return true;
94  // FIXME, we should sort by path, not by id
95  if (myNodeId == other.myNodeId &&
96  isGreater(myName, other.myName))
97  return true;
98  return false;
99  }
100 
101  int compare(const CH_ChannelRef& other) const
102  {
103  if (*this < other)
104  return -1;
105  if (*this > other)
106  return 1;
107  return 0;
108  }
109 
110  unsigned int hash() const;
111 
112 private:
113  bool isLess(const char *str1, const char *str2) const
114  {
115  bool rval;
116  if( !str1 )
117  {
118  if( str2 ) rval = true;// Yes, null ptr is < str2
119  else rval = false;
120  }
121  else
122  {
123  if( !str2) rval = false;// Nope, null is < str2
124  else rval = (strcmp(str1, str2) < 0) ? true : false;
125  }
126  return rval;
127  }
128  bool isGreater(const char *str1, const char *str2) const
129  {
130  bool rval;
131  if( !str1 ) rval = false;
132  else
133  {
134  if( !str2 ) rval = true;// Yes, str1 is > null
135  else rval = (strcmp(str1, str2) > 0) ? true : false;
136  }
137  return rval;
138  }
139 
140  int myNodeId:30;
141  unsigned myIsTrack:1;
142  const char *myName;
143 };
144 
145 
146 inline size_t hash_value(const CH_ChannelRef &ref)
147 {
148  return ref.hash();
149 }
150 
151 /// CH_ChannelRefTable maintains a set of CH_ChannelRef's along with some
152 /// flags that are from CH_ScopeMasks (see CH_Types.h)
154 
155 typedef std::function<bool(const CH_ChannelRef&, unsigned flags)>
157 typedef std::function<void(const CH_ChannelRef&)>
159 
160 /// Deletes all the symbols from the table that have the given node_id,
161 /// returns the number of items deleted
162 CH_API extern int
164  CH_ChannelRefTable &ref_table,
165  int node_id,
166  CH_ChannelRefQueryCallback should_delete_callback = nullptr,
167  CH_ChannelRefCallback pre_delete_callback = nullptr);
168 
169 CH_API extern void
171  const CH_ChannelRefTable &table,
172  UT_StringArray &chan_paths,
173  bool use_alias);
174 
175 CH_API extern void
177  const CH_ChannelRefTable &table,
178  CH_ChannelList &channels);
179 
180 CH_API extern void
182  const CH_ChannelRefTable &table,
183  CH_ChannelRefList &chanrefs,
184  unsigned mask); // mask = 0 means no filtering
185 
186 CH_API extern int
188 
189 CH_API extern bool
191 
192 CH_API extern bool
194 
195 CH_API extern void
197 
198 CH_API extern std::ostream &
199 operator<<(std::ostream &os, const CH_ChannelRef &ref);
200 
201 #endif
void setNodeId(int new_id)
Definition: CH_ChannelRef.h:59
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)
CH_API bool CHchannelsToChanRefs(const CH_ChannelList &channels, CH_ChannelRefList &refs)
CH_ChannelRef & operator=(const CH_ChannelRef &other)
Definition: CH_ChannelRef.h:72
CH_ChannelRef(int node_id, const char *name, bool is_track)
Definition: CH_ChannelRef.h:38
bool operator<(const CH_ChannelRef &other) const
Definition: CH_ChannelRef.h:79
GLint GLuint mask
Definition: glcorearb.h:123
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 int CHdeleteRefsWithNodeId(CH_ChannelRefTable &ref_table, int node_id, CH_ChannelRefQueryCallback should_delete_callback=nullptr, CH_ChannelRefCallback pre_delete_callback=nullptr)
CH_API void CHaddExposedChanRef(const CH_ChannelRefTable &table, CH_ChannelRefList &chanrefs, unsigned mask)
GLint ref
Definition: glcorearb.h:123
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
bool isTrack() const
Definition: CH_ChannelRef.h:63
GLuint const GLchar * name
Definition: glcorearb.h:785
int getNodeId() const
Definition: CH_ChannelRef.h:57
std::function< bool(const CH_ChannelRef &, unsigned flags)> CH_ChannelRefQueryCallback
std::function< void(const CH_ChannelRef &)> CH_ChannelRefCallback
unsigned int hash() const
#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:28
bool operator==(const CH_ChannelRef &other) const
Definition: CH_ChannelRef.h:65
bool operator>(const CH_ChannelRef &other) const
Definition: CH_ChannelRef.h:90
CH_API void CHdisplayChanRefs(const CH_ChannelRefList &refs)
size_t hash_value(const CH_ChannelRef &ref)
const char * getName() const
Definition: CH_ChannelRef.h:61