00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CH_ChannelRef__
00020 #define __CH_ChannelRef__
00021
00022 #include "CH_API.h"
00023 #include <UT/UT_Algorithm.h>
00024 #include <UT/UT_String.h>
00025 #include <UT/UT_Hash.h>
00026 #include "CH_Types.h"
00027
00028 class UT_StringArray;
00029 class UT_Thing;
00030
00031 class CH_API CH_ChannelRef
00032 {
00033 public:
00034
00035 CH_ChannelRef(const CH_ChannelRef &other)
00036 {
00037
00038
00039 UT_ASSERT( other.myName );
00040 myNodeId = other.myNodeId;
00041 myIsTrack = other.myIsTrack;
00042 myName = other.myName;
00043 }
00044
00045 CH_ChannelRef( int node_id, const char *name, bool is_track )
00046 {
00047 setChannelRef(node_id, name, is_track);
00048 }
00049
00050 CH_ChannelRef()
00051 {
00052 clear();
00053 }
00054
00055 ~CH_ChannelRef()
00056 {
00057
00058 }
00059
00060 void setChannelRef(int node_id, const char *name, bool is_track);
00061
00062 void clear();
00063
00064 int getNodeId() const { return myNodeId; }
00065
00066 void setNodeId( int new_id ) { myNodeId = new_id; }
00067
00068 const char *getName() const { return myName; }
00069
00070 bool isTrack() const { return myIsTrack; }
00071
00072 bool operator==( const CH_ChannelRef &other ) const
00073 {
00074 return myNodeId == other.myNodeId &&
00075 myIsTrack == other.myIsTrack &&
00076 myName == other.myName;
00077 }
00078
00079 CH_ChannelRef &operator=( const CH_ChannelRef &other )
00080 {
00081 setChannelRef(other.myNodeId, other.myName,
00082 other.myIsTrack);
00083 return *this;
00084 }
00085
00086 bool operator<(const CH_ChannelRef &other) const
00087 {
00088 if (myNodeId < other.myNodeId)
00089 return true;
00090
00091 if (myNodeId == other.myNodeId &&
00092 isLess(myName, other.myName))
00093 return true;
00094 return false;
00095 }
00096
00097 bool operator>(const CH_ChannelRef &other) const
00098 {
00099 if (myNodeId > other.myNodeId)
00100 return true;
00101
00102 if (myNodeId == other.myNodeId &&
00103 isGreater(myName, other.myName))
00104 return true;
00105 return false;
00106 }
00107
00108 unsigned int hash() const;
00109
00110 private:
00111 bool isLess(const char *str1, const char *str2) const
00112 {
00113 bool rval;
00114 if( !str1 )
00115 {
00116 if( str2 ) rval = true;
00117 else rval = false;
00118 }
00119 else
00120 {
00121 if( !str2) rval = false;
00122 else rval = (strcmp(str1, str2) < 0) ? true : false;
00123 }
00124 return rval;
00125 }
00126 bool isGreater(const char *str1, const char *str2) const
00127 {
00128 bool rval;
00129 if( !str1 ) rval = false;
00130 else
00131 {
00132 if( !str2 ) rval = true;
00133 else rval = (strcmp(str1, str2) > 0) ? true : false;
00134 }
00135 return rval;
00136 }
00137
00138 int myNodeId:30;
00139 unsigned myIsTrack:1;
00140 const char *myName;
00141 };
00142
00143 UT_SWAPPER_SIMPLE( CH_ChannelRef );
00144
00145 class CH_API CH_HashChRef: public UT_Hash
00146 {
00147 public:
00148 CH_HashChRef( const CH_ChannelRef &ref )
00149 : myRef(ref)
00150 { myHash = myRef.hash(); }
00151
00152 virtual int compare( const UT_Hash & a) const;
00153 virtual void copy( const UT_Hash & a);
00154
00155 virtual unsigned hash() const { return myHash; }
00156
00157
00158
00159 virtual UT_Hash *copy() const;
00160
00161 const CH_ChannelRef &getRef() const { return myRef; }
00162
00163 private:
00164 CH_ChannelRef myRef;
00165 unsigned myHash;
00166 };
00167
00168 class CH_API CH_AddChanPathParms
00169 {
00170 public:
00171 CH_AddChanPathParms( UT_StringArray *chan_paths,
00172 bool use_alias )
00173 {
00174 myPaths = chan_paths;
00175 myUseAlias = use_alias;
00176 }
00177
00178 UT_StringArray *myPaths;
00179 unsigned myUseAlias;
00180 };
00181
00182 class CH_API CH_AddChanRefParms
00183 {
00184 public:
00185 CH_AddChanRefParms( CH_ChannelRefList *chanrefs,
00186 unsigned mask )
00187 {
00188 myChanRefs = chanrefs;
00189 myMask = mask;
00190 }
00191
00192 CH_ChannelRefList *myChanRefs;
00193 unsigned myMask;
00194 };
00195
00196 CH_API extern int
00197 CHaddFullChannelPath(UT_Thing &, const UT_Hash &hash, void *data);
00198
00199 CH_API extern int
00200 CHaddExposedChannel(UT_Thing &, const UT_Hash &hash, void *data);
00201
00202 CH_API extern int
00203 CHaddExposedChanRef(UT_Thing &thing, const UT_Hash &hash, void *data);
00204
00205 CH_API extern int
00206 CHcompareChanRefs(const CH_ChannelRef*, const CH_ChannelRef*);
00207
00208 CH_API extern bool
00209 CHchannelsToChanRefs(const CH_ChannelList &channels, CH_ChannelRefList &refs);
00210
00211 CH_API extern bool
00212 CHchanRefsToChannels(const CH_ChannelRefList &refs, CH_ChannelList &channels);
00213
00214 CH_API extern void
00215 CHdisplayChanRefs(const CH_ChannelRefList &refs);
00216
00217 CH_API extern ostream &
00218 operator<<(ostream &os, const CH_ChannelRef &ref);
00219
00220 #endif