![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsDatabaseDowkerNotation.cpp 00003 00005 00006 SUKITTI PUNAK (04/25/2008) 00007 UPDATE (12/09/2010) 00008 ******************************************************************************/ 00009 #include "TAPsDatabaseDowkerNotation.hpp" 00010 // Using Inclusion Model (i.e. definitions are included in declarations) 00011 // (this name.cpp is included in name.hpp) 00012 // Each friend is defined directly inside its declaration. 00013 00014 BEGIN_NAMESPACE_TAPs__Data 00015 //============================================================================= 00016 // Static Data Members 00017 //----------------------------------------------------------------------------- 00018 const unsigned int DatabaseDowkerNotation::LIST_SIZE = 8 + 4 + 8; 00019 // -8 for the number of "fixing/forming the knot shape" that don't need to be checked 00020 const unsigned int DatabaseDowkerNotation::DATA_LIST_SIZE = DatabaseDowkerNotation::LIST_SIZE - 8; 00021 // +1 for undefined 00022 const std::string DatabaseDowkerNotation::KnotNames[LIST_SIZE + 1] = { 00023 "Single", "Single", "Double", "Double", 00024 "Square", "Square", "Surgeon's", "Surgeon's", 00025 00026 "Single", // HalfNeg_WithA_CrossNeg 00027 "Single", // HalfNeg_WithA_CrossPos 00028 "Single", // HalfPos_WithA_CrossNeg 00029 "Single", // HalfPos_WithA_CrossPos 00030 00031 // For fixing/forming the knot shape 00032 "Granny", 00033 "Square", 00034 "Square", 00035 "Granny", 00036 "Granny Surgeon's", 00037 "Surgeon's", 00038 "Surgeon's", 00039 "Granny Surgeon's", 00040 00041 "Undefined" 00042 }; 00043 const int DatabaseDowkerNotation::HalfNeg[] = { 3, -4,-6,-2, 0 }; 00044 const int DatabaseDowkerNotation::HalfPos[] = { 3, 4, 6, 2, 1 }; 00045 const int DatabaseDowkerNotation::DoubleNeg[] = { 5, -6,-8,-10,-2,-4, 2 }; 00046 const int DatabaseDowkerNotation::DoublePos[] = { 5, 6, 8, 10, 2, 4, 3 }; 00047 const int DatabaseDowkerNotation::SquareNeg[] = { 6, -10,-12, 8, 4, 6,-2, 4 }; 00048 const int DatabaseDowkerNotation::SquarePos[] = { 6, 10, 12,-8,-4,-6, 2, 5 }; 00049 const int DatabaseDowkerNotation::SurgeonsKnotNeg[] = { 8, -14,-16, 10, 12, 4, 6, 8,-2, 6 }; 00050 const int DatabaseDowkerNotation::SurgeonsKnotPos[] = { 8, 14, 16,-10,-12,-4,-6,-8, 2, 7 }; 00051 00052 const int DatabaseDowkerNotation::HalfNeg_WithA_CrossNeg[] = { 4, -6,-8,-4,-2, 8 }; 00053 const int DatabaseDowkerNotation::HalfPos_WithA_CrossNeg[] = { 4, 6, 8,-4, 2, 9 }; 00054 const int DatabaseDowkerNotation::HalfNeg_WithA_CrossPos[] = { 4, -6,-8, 4,-2, 10 }; 00055 const int DatabaseDowkerNotation::HalfPos_WithA_CrossPos[] = { 4, 6, 8, 4, 2, 11 }; 00056 00057 const int DatabaseDowkerNotation::UndefinedData[] = { 0 }; 00058 00059 // +1 for undefined 00060 int const * const DatabaseDowkerNotation::EntryAccess[DATA_LIST_SIZE + 1] = { 00061 HalfNeg, HalfPos, 00062 DoubleNeg, DoublePos, 00063 SquareNeg, SquarePos, 00064 SurgeonsKnotNeg, SurgeonsKnotPos, 00065 00066 // A single knot with extra cross 00067 HalfNeg_WithA_CrossNeg, 00068 HalfNeg_WithA_CrossPos, 00069 HalfPos_WithA_CrossNeg, 00070 HalfPos_WithA_CrossPos, 00071 00072 UndefinedData 00073 }; 00074 00075 //----------------------------------------------------------------------------- 00076 //============================================================================= 00077 00078 //============================================================================= 00079 //----------------------------------------------------------------------------- 00080 // Return a string of the Dowker notation of the entry number (knot id) argument. 00081 std::string DatabaseDowkerNotation::GetStrEntry ( unsigned int i ) 00082 { 00083 if ( i >= LIST_SIZE ) return "Undefined Knot"; 00084 00085 // Include the Dowker notation in the return string 00086 //if ( true ) { 00087 if ( false ) { 00088 if ( i < DATA_LIST_SIZE ) { 00089 char val[16]; 00090 std::string str( "Dowker: " ); 00091 str += "#"; 00092 str += _itoa( EntryAccess[i][0], val, 10 ); // number of crossing pairs 00093 str += " --"; 00094 int n = 1; 00095 for ( ; n <= EntryAccess[i][0]; ++n ) { 00096 str += " "; 00097 str += _itoa( EntryAccess[i][n], val, 10 ); 00098 } 00099 str += " -- " + KnotNames[ EntryAccess[i][n] ] + " Knot"; 00100 return str; 00101 } 00102 } 00103 else { 00104 return KnotNames[ EntryAccess[i][EntryAccess[i][0]+1] ] + " Knot"; 00105 } 00106 } // EOF: StrEntry (...) 00107 //----------------------------------------------------------------------------- 00108 // Find the knot with the given Dowker notation 00109 int DatabaseDowkerNotation::FindKnotOfDowkerNotation ( 00110 unsigned int numPairs, int * dowkerNotation, 00111 std::string * knotName 00112 ) 00113 { 00114 // Traverse the Dowker notation database 00115 for ( unsigned int i = 0; i < DATA_LIST_SIZE; ++i ) { 00116 // Match the size 00117 if ( numPairs == EntryAccess[i][0] ) { 00118 // Check the notation 00119 unsigned int j; 00120 for ( j = 0; j < numPairs; ++j ) { 00121 // If not match, exit this inner loop 00122 if ( dowkerNotation[j] != EntryAccess[i][j+1] ) j = numPairs*2; 00123 } 00124 // Found the matched knot name 00125 if ( j == numPairs ) { 00126 if ( knotName ) *knotName = KnotNames[ EntryAccess[i][j+1] ] + " Knot"; 00127 return EntryAccess[i][j+1]; 00128 } 00129 } 00130 } 00131 00132 // no matched Dowker notation found 00133 if ( knotName ) *knotName = "n/a"; 00134 return -1; 00135 } // EOF: FindKnotOfDowkerNotation (...) 00136 //----------------------------------------------------------------------------- 00137 //============================================================================= 00138 END_NAMESPACE_TAPs__Data 00139 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00140 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----