00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _OP_Depdency_h_
00021 #define _OP_Depdency_h_
00022
00023 #include "OP_API.h"
00024 #include <stdio.h>
00025 #include <string.h>
00026 #include <UT/UT_Assert.h>
00027 #include "OP_DataTypes.h"
00028
00029 class UT_String;
00030 class CH_Channel;
00031 class PRM_ParmList;
00032
00033 class OP_API OP_RefId
00034 {
00035 public:
00036 OP_RefId()
00037 {
00038 myParmIndex = -1;
00039 myParmSubIndex = -1;
00040 }
00041 ~OP_RefId()
00042 {
00043 }
00044
00045 OP_RefId( const OP_RefId © )
00046 {
00047 myParmIndex = copy.myParmIndex;
00048 myParmSubIndex = copy.myParmSubIndex;
00049 }
00050 const OP_RefId &operator =( const OP_RefId © )
00051 {
00052 if( © != this )
00053 {
00054 myParmIndex = copy.myParmIndex;
00055 myParmSubIndex = copy.myParmSubIndex;
00056 }
00057 return *this;
00058 }
00059
00060 bool isValid() const
00061 { return myParmIndex >= 0; }
00062
00063 void setParmRef( int parm_index, int sub_index = -1 )
00064 {
00065 myParmIndex = parm_index;
00066 myParmSubIndex = sub_index;
00067 }
00068 int getParmRef() const
00069 {
00070 UT_ASSERT_P( isValid() );
00071 return myParmIndex;
00072 }
00073 int getParmSubIndex() const
00074 {
00075 UT_ASSERT_P( isValid() );
00076 return myParmSubIndex;
00077 }
00078
00079 int operator==( const OP_RefId &other) const
00080 {
00081 return( myParmIndex == other.myParmIndex &&
00082 myParmSubIndex == other.myParmSubIndex );
00083 }
00084
00085
00086 bool matches(const OP_RefId &other) const
00087 {
00088 if (myParmIndex != other.myParmIndex)
00089 return false;
00090 if (myParmSubIndex == -1 || other.myParmSubIndex == -1)
00091 return true;
00092 return (myParmSubIndex == other.myParmSubIndex);
00093 }
00094
00095 void getToken(const PRM_ParmList &parmlist, UT_String &token) const;
00096 void getAlias(const PRM_ParmList &parmlist, UT_String &alias) const;
00097
00098 private:
00099 int myParmIndex;
00100 int myParmSubIndex;
00101 };
00102
00103 class OP_API OP_Reference
00104 {
00105 public:
00106 OP_Reference()
00107 {
00108 myRefOpId = -1;
00109 myRefCount = 0;
00110 }
00111 explicit OP_Reference( int ref_op_id )
00112 {
00113 myRefOpId = ref_op_id;
00114 myRefCount = 1;
00115 }
00116
00117 void addRef()
00118 {
00119 UT_ASSERT_P( myRefCount >= 0 );
00120 myRefCount++;
00121 }
00122 int removeRef(int count = 1)
00123 {
00124 UT_ASSERT_P( myRefCount >= count );
00125 if( myRefCount >= count )
00126 myRefCount -= count;
00127 else
00128 myRefCount = 0;
00129 return myRefCount;
00130 }
00131
00132 void clearRefOpId() { myRefOpId = -1; }
00133 int getRefOpId() const { return myRefOpId; }
00134 void setRefOpId(int op_id) { myRefOpId = op_id; }
00135
00136 int getRefCount() const { return myRefCount; }
00137
00138 int operator==( const OP_Reference &other )
00139 {
00140 return myRefOpId == other.myRefOpId;
00141 }
00142
00143 private:
00144 int myRefOpId;
00145 int myRefCount;
00146 };
00147
00148 class OP_API OP_Dependency
00149 {
00150 public:
00151 OP_Dependency()
00152 {
00153 myRefOpId = -1;
00154 myInterestType = OP_INTEREST_NONE;
00155 }
00156
00157
00158
00159
00160
00161
00162
00163 OP_Dependency(int ref_op_id, const OP_RefId &source_ref,
00164 const OP_RefId &ref, OP_InterestType interest)
00165 {
00166 myRefOpId = ref_op_id;
00167 myRef = ref;
00168 myInterestType = interest;
00169 mySourceRef = source_ref;
00170 }
00171
00172 const OP_Dependency &operator=(const OP_Dependency &other);
00173
00174 void addInterest( OP_InterestType type )
00175 {
00176 myInterestType = (OP_InterestType) ((int) myInterestType | type);
00177 }
00178 OP_InterestType getInterest() const
00179 {
00180 return myInterestType;
00181 }
00182
00183 int matches( int ref_op_id, const OP_RefId &ref,
00184 OP_InterestType mask = OP_INTEREST_ALL ) const
00185 {
00186 return (myRefOpId == ref_op_id && myRef.matches(ref)
00187 && hasInterest(mask));
00188 }
00189 int matches( int ref_op_id, const OP_RefId &source_ref,
00190 const OP_RefId &ref,
00191 OP_InterestType mask = OP_INTEREST_ALL ) const
00192 {
00193 return myRefOpId == ref_op_id && mySourceRef == source_ref &&
00194 myRef == ref && hasInterest(mask);
00195 }
00196 int operator==( const OP_Dependency &other ) const
00197 {
00198 return matches( other.myRefOpId, other.mySourceRef, other.myRef );
00199 }
00200
00201
00202 bool fixRemovedSourceRefParmIndex(int removed_parm_idx)
00203 {
00204 if (!mySourceRef.isValid())
00205 return false;
00206
00207 if (mySourceRef.getParmRef() == removed_parm_idx)
00208 {
00209 UT_ASSERT_P(false);
00210 mySourceRef.setParmRef(-1, -1);
00211 return true;
00212 }
00213 else if (mySourceRef.getParmRef() > removed_parm_idx)
00214 {
00215 mySourceRef.setParmRef(mySourceRef.getParmRef() - 1,
00216 mySourceRef.getParmSubIndex());
00217 }
00218 return false;
00219 }
00220
00221 int getRefOpId() const { return myRefOpId; }
00222 void clearRefOpId() { myRefOpId = -1; }
00223 void setRefOpId( int op_id ) { myRefOpId = op_id; }
00224 const OP_RefId &getRefId() const { return myRef; }
00225 const OP_RefId &getSourceRefId() const { return mySourceRef; }
00226 OP_InterestType getInterestType() const { return myInterestType; }
00227 int hasInterest(OP_InterestType interest) const
00228 { return (myInterestType & interest) != 0; }
00229
00230 private:
00231 int myRefOpId;
00232 OP_RefId mySourceRef;
00233 OP_RefId myRef;
00234 OP_InterestType myInterestType;
00235 };
00236
00237 #endif // _OP_Depdency_h_