int PokerData::GetUserIdByName(_String sUserName){ if( !m_pDataMan || !m_pDataMan->IsOpen() || sUserName.IsEmpty() ) return 0; _String sSQL; sSQL.Format(_T("SELECT ID from dbo.TB_USER where [USER_NAME] = '%s'"), sUserName.GetBuffer()); EnumerableObject<PokerUser> listUsers; if( m_pDataMan->LoadTableBySql((EnumerableObject<Serializable>*)&listUsers, sSQL, true) ){ PokerUser* pUser = listUsers.GetAt(0); return pUser->m_nId; // UserId } return 0; }
//__________________________________________________________________ void _HYPlatformPullDown::_AddMenuItem (_String& newItem, long index) { if (theMenu) { GList * singleItem = g_list_alloc(); singleItem->prev = singleItem->next = nil; if (newItem.Equal(&menuSeparator)) { GtkWidget * itemContents = gtk_separator_menu_item_new (); gtk_widget_show (itemContents); singleItem->data = gtk_list_item_new(); gtk_container_add((GtkContainer*)singleItem->data,itemContents); gtk_combo_set_item_string (GTK_COMBO (theMenu), GTK_ITEM (singleItem->data), ""); gtk_widget_set_sensitive((GtkWidget*)singleItem->data,false); widgetList.InsertElement ((BaseRef)itemContents,2*index,false,false); } else { _String inItem = newItem; if (newItem.beginswith ("(")) { inItem.Trim (1,-1); } GtkWidget * itemContents = gtk_menu_item_new_with_label (inItem.sData); gtk_widget_show (itemContents); singleItem->data = gtk_list_item_new(); gtk_container_add((GtkContainer*)singleItem->data,itemContents); gtk_combo_set_item_string (GTK_COMBO (theMenu), GTK_ITEM (singleItem->data), inItem.sData); gtk_widget_set_sensitive((GtkWidget*)singleItem->data,inItem.sLength == newItem.sLength); widgetList.InsertElement ((BaseRef)itemContents,2*index,false,false); } widgetList.InsertElement ((BaseRef)singleItem->data,2*index,false,false); GdkColor convColor = HYColorToGDKColor(_hyGTKMenuBackground); gtk_widget_modify_bg ((GtkWidget*)singleItem->data, GTK_STATE_INSENSITIVE, &convColor); gtk_widget_show ((GtkWidget*)singleItem->data); if (index<0) { gtk_list_append_items (GTK_LIST (GTK_COMBO (theMenu)->list), singleItem); } else { gtk_list_insert_items (GTK_LIST (GTK_COMBO (theMenu)->list), singleItem, index); } /*printf ("\nAdding menu item %s at %d\n", newItem.sData, index); for (long k = 0; k<widgetList.lLength; k++) printf ("%d %s\n", k, GTK_OBJECT_TYPE_NAME (GTK_WIDGET (widgetList(k))));*/ } if (((_HYPullDown*)this)->MenuItemCount()==1||selection==index) { cbSelection = -1; _RefreshComboBox(); } }
//__________________________________________________________________ void _HYGraphicPane::DrawInfoBox (_HYRect theBox, _String boxName) { long stringWidth, avWidth = theBox.right-theBox.left-20; theBox.width = 1; DrawRect (theBox); if (boxName.sLength) { stringWidth = GetVisibleStringWidth (boxName, font); while (stringWidth>avWidth && boxName.sLength) { boxName.Trim (0, boxName.sLength-2); stringWidth = GetVisibleStringWidth (boxName, font); } // measure string length _HYRect textRect = theBox; textRect.left += 8; textRect.right = textRect.left+stringWidth+4; textRect.top-=6; textRect.bottom = textRect.top+9; EraseRect (textRect); DisplayText (boxName, textRect.bottom, textRect.left+2, true); } }
bool PushFilePath (_String& pName, bool trim) { char c = GetPlatformDirectoryChar(); long f = pName.FindBackwards(_String(c),0,-1); if (f>=0) { _String newP = pName.Cut(0,f); pathNames && & newP; if (trim) pName.Trim (f+1,-1); return true; } else if (pathNames.lLength) { pathNames && pathNames(pathNames.lLength-1); } else { pathNames && & empty; } return false; }
inline bool getline (_Stream &stream_, _String &line_, const _String &delim_ = ax::util::to_string<typename _String::value_type> ("\r\n")) { std::array<_Ctype, 2048> temp_; line_ = _String (); auto avail_ = decltype (stream_.peek (temp_.data (), temp_.size ())) {}; while ((avail_ = stream_.peek (temp_.data (), temp_.size ())) > 0) { auto sbuff_ = _String (temp_.data (), avail_); auto stpos_ = sbuff_.find (delim_); if (stpos_ != sbuff_.npos) { auto trunc_ = stpos_ + delim_.size (); line_.append (temp_.data (), stpos_); stream_.ignore (trunc_); return true; } stream_.ignore (avail_); line_.append (temp_.data (), avail_); } return false; }
long StoreDataFilter (_String const& name, _DataSetFilter* object, bool handle_errors) { if (name.IsValidIdentifier(true)) { long exists_already = FindDataFilter(name); /*printf ("[StoreDataFilter] %s %d\n", name.sData, exists_already); _SimpleList history; long locked_index = _data_filter_locks.Next (-1, history); while (locked_index >= 0) { printf ("\tLOCKED %s\n", GetFilterName((long)_data_filter_locks.Retrieve(locked_index))->sData); locked_index = _data_filter_locks.Next (locked_index, history); } */ if (exists_already >= 0L) { if (_IsObjectLocked(exists_already, HY_BL_DATASET_FILTER)) { if (handle_errors) { WarnError (_String ("DataSetFilter ") & name.Enquote() & " could not be created because an existing filter of the same name is locked"); } return -1; } //DeleteObject ((_DataSetFilter*)_data_filters.GetXtra (exists_already)); _data_filters.SetXtra(exists_already, object, false); // this will delete the existing object _NotifyDataFilterListeners (exists_already, kNotificationTypeChange); } else { exists_already = _data_filters.Insert (new _String(name), (long)object, false, false); } _SetDataFilterParameters (name, *object); return exists_already; } else { if (handle_errors) { WarnError (_String ("The name ") & name.Enquote() & " is not a valid HyPhy id in call to " & __PRETTY_FUNCTION__); } } return -1; }
void StringToConsole (_String & s) { #ifdef __HYPHYMPI__ if (_hy_mpi_node_rank == 0) #endif { #ifdef __HEADLESS__ if (globalInterfaceInstance) globalInterfaceInstance->PushOutString(&s); #else printf ("%s",s.getStr()); #endif } }
void WriteBitsToString (_String&s, long& bitAt, char lengthToWrite) { long leftOver = 8-bitAt%8, curPos = bitAt/8; if (leftOver >= lengthToWrite) { // will fit in current byte unsigned char value = s.getUChar(curPos); value += powersOf2[leftOver-1]-powersOf2[leftOver-lengthToWrite]; s[curPos]=value; } else { unsigned char value = (unsigned char)s[curPos]; value += powersOf2[leftOver-1]+1; s[curPos]=value; char fullBytes = (lengthToWrite-leftOver-1)/8; while (fullBytes) { s[++curPos]=255; fullBytes--; } s[++curPos]=254-powersOf2[8-(lengthToWrite-leftOver)%8]; } bitAt+=lengthToWrite; }
_Parameter _CString::FrequencyCompress(unsigned char theAlpha,bool doit) { _String* theAlphabet = SelectAlpha (theAlpha); if (theAlphabet->sLength>31) { return 1.; // can't do much - the alphabet is too large } char codeLength[256]; long freqs [256],j,t; long maxOccurences[256], locationsOfMaxSymbols[256] ; //simply ensures that we // won't have symbols out of the alphabet //analyze the frequency distribution of alphabetic symbols for (j=0; j<256; freqs[j]=0,codeLength[j]=0,maxOccurences[j]=0, j++ ) {} for (j=0; j<sLength; j++) { freqs[getUChar(j)]++; } t = 0; for (j=0; j<theAlphabet->sLength; j++) { freqs[NuclAlphabet.getUChar(j)]*=-1; } //make sure that the alphabet is "large" enough for the nucleotide case // NEW 03/29/98 for (j=0; j<256; j++) if (freqs[j]>0) { t = 1; break; } else { freqs[j]*=-1; } if (t) { if (theAlphabet == &NuclAlphabet) { return FrequencyCompress (FULLNUCLALPHABET, doit); } else { return 1; } } // now build the prefix code for the alphabet // fisrt find four most frequently occurring symbols for (j=0; j<(*theAlphabet).sLength; j++) { for (long k = 0; k<(*theAlphabet).sLength; k++) if (freqs[theAlphabet->getUChar(j)]>=maxOccurences[k]) { for (long l=(*theAlphabet).sLength-1; l>=k+1; l--) { maxOccurences[l]=maxOccurences[l-1]; locationsOfMaxSymbols[l]=locationsOfMaxSymbols[l-1]; } maxOccurences[k]=freqs[theAlphabet->getUChar(j)]; locationsOfMaxSymbols[k]=(*theAlphabet)[j]; break; } } // compute efficiency //j will store the predicted bit length of the compressed string j = (*theAlphabet).sLength*5; // translation table size j=8*((j%8)?(j/8+1):j/8); // we are also ready to build the code table for (long k = 0; k<(*theAlphabet).sLength; k++) { long l; for (l=0; l<(*theAlphabet).sLength; l++) if ((*theAlphabet)[k]==locationsOfMaxSymbols[l]) { j+=(l+1)*freqs[theAlphabet->getUChar(k)]; codeLength [locationsOfMaxSymbols[l]] = l+1; break; } } // if (j>Length()*8) return 1; // no compression could be performed if (!doit) { return j/8.0/sLength; } _String result ((unsigned long)(j%8?j/8+1:j/8)); // allocate output string // let's roll!! long csize = 0; //will indicate the current bit position in the target string t = 0; // current position in the string //first we must write out the encoding table as 5 bits of length per each for (j=0; j<(*theAlphabet).sLength; j++, csize+=5, t = csize/8) { long leftover = 8-csize%8; if (leftover>=5) { unsigned char value = result[t]; switch (leftover) { case 5: value+=codeLength[theAlphabet->getUChar(j)]; break; case 6: value+=codeLength[theAlphabet->getUChar(j)]*2; break; case 7: value+=codeLength[theAlphabet->getUChar(j)]*4; break; default: value+=codeLength[theAlphabet->getUChar(j)]*8; } result[t]=value; } else { result[t]+=codeLength[theAlphabet->getUChar(j)]/realPowersOf2[5-leftover]; result[++t]=(codeLength[theAlphabet->getUChar(j)]%realPowersOf2[5-leftover])*realPowersOf2[3+leftover]; } } // result[++t]=0; // mark the end of tabular encoding t++; // now encode the actual sequence t*=8; //t+=8; for (j=0; j<sLength; j++) { WriteBitsToString (result,t,codeLength[(unsigned char)sData[j]]); } // pad the rest of the last byte in the string by ones if (t%8) { unsigned char value = result [t/8]; value += powersOf2[7-t%8]+1; result[t/8]=value; t++; } // yahoo! we are done - store compression flag and replace the string with compressed string _Parameter factor = result.sLength/(_Parameter)sLength; if (factor<1) { // compression took place DuplicateErasing(&result); SetFlag( FREQCOMPRESSION); SetFlag (theAlpha); } return factor; }
char* _THyPhyGetStringStatus (void) { return _tHYPHYCurrentStatus.getStr(); }