cgma
|
00001 #ifndef DAG_TYPE_HPP 00002 #define DAG_TYPE_HPP 00003 00004 00005 00006 class DagType 00007 { 00008 00009 public: 00010 00011 enum FunctionalType { 00012 BasicTopologyEntity_TYPE = 0, 00013 SenseEntity_TYPE = 1, 00014 GroupingEntity_TYPE = 2 }; 00015 00016 // Constructor 00017 // 00018 // Construct invalid DagType 00019 inline DagType() 00020 : intType(-1) 00021 {} 00022 00023 // Constructor 00024 // 00025 // GroupingEntities and SenseEntities have the same 00026 // dimension as their child BasicTopologyEntity type. 00027 // Dimension may be outside the range [0,3], but 00028 // if so is_valid() will return false. (i.e. it is 00029 // possible to construct invalid DagType objects.) 00030 inline DagType( int dimensionIn, FunctionalType func ) 00031 : intType( 3 * dimensionIn + func ) 00032 { } 00033 00034 00035 // Return the dimension of this type. 00036 // 00037 // GroupingEntities and SenseEntities have the same 00038 // dimension as their child BasicTopologyEntity type. 00039 inline int dimension() const 00040 { return intType / 3; } 00041 00042 // Return the base type of this subtype. 00043 // 00044 // Return values are one of GroupingEntity_TYPE, 00045 // SenseEntity_TYPE, or BasicTopologyEntity_TYPE. 00046 inline FunctionalType functional_type() const 00047 { return (FunctionalType)(intType % 3); } 00048 00049 00050 // Is this a valid DagType? 00051 // 00052 // An invalid type can be obtained by constructing 00053 // a DagType object with a dimension not in the 00054 // range [0,3], or using the operators below to 00055 // move above a Body or below a RefVertex in the DAG. 00056 inline bool is_valid() const 00057 { 00058 const unsigned bodyType = 11; 00059 return (unsigned)intType <= bodyType; 00060 } 00061 00062 // get parent of this type 00063 inline DagType parent() const 00064 { return DagType(intType + 1); } 00065 00066 00067 // Comparison Operators. 00068 // 00069 // An entity higher in the DAG (closer to Body) is 00070 // considered greater than an entity lower in the 00071 // DAG (closer to RefVertex). 00072 00073 inline bool operator==( DagType other ) const 00074 { return intType == other.intType; } 00075 00076 inline bool operator!=( DagType other ) const 00077 { return intType != other.intType; } 00078 00079 inline bool operator<=( DagType other ) const 00080 { return intType <= other.intType; } 00081 00082 inline bool operator>=( DagType other ) const 00083 { return intType >= other.intType; } 00084 00085 inline bool operator< ( DagType other ) const 00086 { return intType < other.intType; } 00087 00088 inline bool operator> ( DagType other ) const 00089 { return intType > other.intType; } 00090 00091 00092 // Addition operators. 00093 // 00094 // Increasing the value of the type moves the 00095 // type up the DAG (closer to Body). No bounds 00096 // checking is done on the value. Moving upwards 00097 // from Body or downwards past RefVertex results 00098 // in a DagType for which is_valid() returns false. 00099 00100 inline DagType operator++() 00101 { return DagType(++intType); } 00102 00103 inline DagType operator--() 00104 { return DagType(--intType); } 00105 00106 inline DagType operator++(int) 00107 { return DagType(intType++); } 00108 00109 inline DagType operator--(int) 00110 { return DagType(intType--); } 00111 00112 inline DagType operator+=( int i ) 00113 { return DagType(intType += i); } 00114 00115 inline DagType operator-=( int i ) 00116 { return DagType(intType -= i); } 00117 00118 inline DagType operator+( int i ) const 00119 { return DagType(intType + i); } 00120 00121 inline DagType operator-( int i ) const 00122 { return DagType(intType - i); } 00123 00124 00125 // Cast to bool. 00126 // 00127 // Same as is_valid(). 00128 inline operator bool() const 00129 { return is_valid(); } 00130 00131 00132 // Get distance between types in DAG. 00133 // 00134 // Return value is negative if the passed type 00135 // is higher (closer to Body) in the DAG than 00136 // this type is. The return value is 1 (one) 00137 // if the passed type is an immediate child of 00138 // this type. The return value is 0 (zero) if 00139 // the types are the same. 00140 inline int operator-( DagType other ) const 00141 { return intType - other.intType; } 00142 00143 // Constants 00144 inline static DagType body_type() {return DagType(3,GroupingEntity_TYPE);} 00145 inline static DagType co_volume_type() {return DagType(3,SenseEntity_TYPE);} 00146 inline static DagType ref_volume_type() {return DagType(3,BasicTopologyEntity_TYPE);} 00147 inline static DagType shell_type() {return DagType(2,GroupingEntity_TYPE);} 00148 inline static DagType co_face_type() {return DagType(2,SenseEntity_TYPE);} 00149 inline static DagType ref_face_type() {return DagType(2,BasicTopologyEntity_TYPE);} 00150 inline static DagType loop_type() {return DagType(1,GroupingEntity_TYPE);} 00151 inline static DagType co_edge_type() {return DagType(1,SenseEntity_TYPE);} 00152 inline static DagType ref_edge_type() {return DagType(1,BasicTopologyEntity_TYPE);} 00153 inline static DagType chain_type() {return DagType(0,GroupingEntity_TYPE);} 00154 inline static DagType co_vertex_type() {return DagType(0,SenseEntity_TYPE);} 00155 inline static DagType ref_vertex_type() {return DagType(0,BasicTopologyEntity_TYPE);} 00156 inline static DagType invalid_type() {return DagType(-1);} 00157 private: 00158 00159 inline explicit DagType( int value ) 00160 : intType( value ) {} 00161 00162 int intType; 00163 }; 00164 00165 00166 #endif 00167