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 <PRM/PRM_RefId.h>
00028 #include "OP_DataTypes.h"
00029
00030 class OP_API OP_Reference
00031 {
00032 public:
00033 OP_Reference()
00034 {
00035 myRefOpId = -1;
00036 myRefCount = 0;
00037 }
00038 explicit OP_Reference( int ref_op_id )
00039 {
00040 myRefOpId = ref_op_id;
00041 myRefCount = 1;
00042 }
00043
00044 void addRef()
00045 {
00046 UT_ASSERT_P( myRefCount >= 0 );
00047 myRefCount++;
00048 }
00049 int removeRef(int count = 1)
00050 {
00051 UT_ASSERT_P( myRefCount >= count );
00052 if( myRefCount >= count )
00053 myRefCount -= count;
00054 else
00055 myRefCount = 0;
00056 return myRefCount;
00057 }
00058
00059 void clearRefOpId() { myRefOpId = -1; }
00060 int getRefOpId() const { return myRefOpId; }
00061 void setRefOpId(int op_id) { myRefOpId = op_id; }
00062
00063 int getRefCount() const { return myRefCount; }
00064
00065 int operator==( const OP_Reference &other )
00066 {
00067 return myRefOpId == other.myRefOpId;
00068 }
00069
00070 private:
00071 int myRefOpId;
00072 int myRefCount;
00073 };
00074
00075 class OP_API OP_Dependency
00076 {
00077 public:
00078 OP_Dependency()
00079 {
00080 myRefOpId = -1;
00081 myInterestType = OP_INTEREST_NONE;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090 OP_Dependency(int ref_op_id, const PRM_RefId &source_ref,
00091 const PRM_RefId &ref, OP_InterestType interest)
00092 {
00093 myRefOpId = ref_op_id;
00094 myRef = ref;
00095 myInterestType = interest;
00096 mySourceRef = source_ref;
00097 }
00098
00099 const OP_Dependency &operator=(const OP_Dependency &other);
00100
00101 void addInterest( OP_InterestType type )
00102 {
00103 myInterestType = (OP_InterestType) ((int) myInterestType | type);
00104 }
00105 OP_InterestType getInterest() const
00106 {
00107 return myInterestType;
00108 }
00109
00110 int matches( int ref_op_id, const PRM_RefId &ref,
00111 OP_InterestType mask = OP_INTEREST_ALL ) const
00112 {
00113 return (myRefOpId == ref_op_id && myRef.matches(ref)
00114 && hasInterest(mask));
00115 }
00116 int matches( int ref_op_id, const PRM_RefId &source_ref,
00117 const PRM_RefId &ref,
00118 OP_InterestType mask = OP_INTEREST_ALL ) const
00119 {
00120 return myRefOpId == ref_op_id && mySourceRef == source_ref &&
00121 myRef == ref && hasInterest(mask);
00122 }
00123 int operator==( const OP_Dependency &other ) const
00124 {
00125 return matches( other.myRefOpId, other.mySourceRef, other.myRef );
00126 }
00127
00128
00129 bool fixRemovedSourceRefParmIndex(int removed_parm_idx)
00130 {
00131 if (!mySourceRef.isValid())
00132 return false;
00133
00134 if (mySourceRef.getParmRef() == removed_parm_idx)
00135 {
00136 UT_ASSERT_P(false);
00137 mySourceRef.setParmRef(-1, -1);
00138 return true;
00139 }
00140 else if (mySourceRef.getParmRef() > removed_parm_idx)
00141 {
00142 mySourceRef.setParmRef(mySourceRef.getParmRef() - 1,
00143 mySourceRef.getParmSubIndex());
00144 }
00145 return false;
00146 }
00147
00148 int getRefOpId() const { return myRefOpId; }
00149 void clearRefOpId() { myRefOpId = -1; }
00150 void setRefOpId( int op_id ) { myRefOpId = op_id; }
00151 const PRM_RefId &getRefId() const { return myRef; }
00152 const PRM_RefId &getSourceRefId() const { return mySourceRef; }
00153 OP_InterestType getInterestType() const { return myInterestType; }
00154 int hasInterest(OP_InterestType interest) const
00155 { return (myInterestType & interest) != 0; }
00156
00157 private:
00158 int myRefOpId;
00159 PRM_RefId mySourceRef;
00160 PRM_RefId myRef;
00161 OP_InterestType myInterestType;
00162 };
00163
00164 #endif // _OP_Depdency_h_