///--------------------------------------------------------------------------------- /// ///--------------------------------------------------------------------------------- bool DeveloperConsoleArguments::GetVector2( Vector2& vec2 ) { std::string string = ""; if (PeekString( string )) { if (IsFloat( string )) { vec2.x = strtof( string.c_str(), nullptr ); m_currentIndex++; } else return false; } if (PeekString( string )) { if (IsFloat( string )) { vec2.y = strtof( string.c_str(), nullptr ); m_currentIndex++; return true; } else return false; } return false; }
bool CTag::WriteTagToFile(CFileDataIO* file, EUtf8Str eStrEncode) const { ASSERT_VALID(this); // don't write tags of unknown types, we wouldn't be able to read them in again // and the met file would be corrupted if (IsStr() || IsInt() || IsFloat() || IsBlob() || IsInt64()) { file->WriteUInt8(m_uType); if (m_pszName) { UINT taglen = strlen(m_pszName); file->WriteUInt16((uint16)taglen); file->Write(m_pszName, taglen); } else { file->WriteUInt16(1); file->WriteUInt8(m_uName); } if (IsStr()) { file->WriteString(GetStr(), eStrEncode); } else if (IsInt()) { file->WriteUInt32((uint32)m_uVal); } else if (IsInt64(false)) { file->WriteUInt64(m_uVal); } else if (IsFloat()) { file->Write(&m_fVal, 4); } else if (IsBlob()) { // NOTE: This will break backward compatibility with met files for eMule versions prior to 0.44a file->WriteUInt32(m_nBlobSize); file->Write(m_pData, m_nBlobSize); } //TODO: Support more tag types else { TRACE("%s; Unknown tag: type=0x%02X\n", __FUNCTION__, m_uType); ASSERT(0); return false; } return true; } else { TRACE("%s; Ignored tag with unknown type=0x%02X\n", __FUNCTION__, m_uType); ASSERT(0); return false; } }
std::string ScalarSelectionDialog::GetValueString(const wxVariant& variant, std::type_index type, int precision) { std::string result; if (!variant.IsNull()) { if (IsFloat(type)) { std::stringstream strstream; if (precision > 0) { strstream << std::setprecision(precision) << std::fixed << variant.GetDouble(); } else { strstream << std::fixed << variant.GetDouble(); } auto tmpStr = strstream.str(); size_t last_not_zero = tmpStr.find_last_not_of('0'); result = tmpStr.substr(0, last_not_zero == std::string::npos ? last_not_zero : last_not_zero+1); } else if (IsIntegral(type)) { result = std::to_string(variant.GetInteger()); } } return result; }
void GUIOPTION::SetCurrentValue(const std::string & value) { if (m_values.empty()) { m_data = value; } else { size_t current_value = 0; for (LIST::iterator i = m_values.begin(); i != m_values.end(); ++i) { if (IsFloat()) { // number of trailing zeros might differ, use min match size_t len = std::min(i->first.length(), value.length()); if (!i->first.compare(0, len, value, 0, len)) break; } else { if (i->first == value) break; } ++current_value; } m_current_value = (current_value < m_values.size()) ? current_value : 0; } SignalValue(); }
double LLBC_Variant::AsDouble() const { if (IsNil()) { return 0.0; } else if (IsDict()) { return 0.0; } else if (IsStr()) { return LLBC_Str2Double(_holder.str.c_str()); } if (IsDouble() || IsFloat()) { return _holder.raw.doubleVal; } if (IsSignedRaw()) { return static_cast<double>(_holder.raw.int64Val); } return static_cast<double>(_holder.raw.uint64Val); }
float CSettings::GetFloat(String strSetting) { if(IsFloat(strSetting)) return GetSetting(strSetting)->fValue; return 0.0f; }
void GuiOption::SetCurrentValue(const std::string & value) { if (m_values.empty()) { m_data = value; } else { size_t current_value = 0; for (const auto & v : m_values) { if (IsFloat()) { // number of trailing zeros might differ, use min match size_t len = std::min(v.first.length(), value.length()); if (!v.first.compare(0, len, value, 0, len)) break; } else { if (v.first == value) break; } ++current_value; } m_current_value = (current_value < m_values.size()) ? current_value : 0; } SignalValue(); }
const LLBC_String &LLBC_Variant::AsStr() const { if (IsRaw()) { LLBC_Variant *nonConstThis = const_cast<LLBC_Variant *>(this); if (IsBool()) { nonConstThis->_holder.str = (_holder.raw.uint64Val ? "true" : "false"); } else if (IsFloat() || IsDouble()) { return nonConstThis->_holder.str = LLBC_Num2Str(_holder.raw.doubleVal); } else if (IsSignedRaw()) { nonConstThis->_holder.str = LLBC_Num2Str(_holder.raw.int64Val); } else { nonConstThis->_holder.str = LLBC_Num2Str(_holder.raw.uint64Val); } } else if (!IsStr()) { LLBC_Variant *nonConstThis = const_cast<LLBC_Variant *>(this); nonConstThis->CleanStrData(); } return _holder.str; }
int prArray_OSCBytes(VMGlobals *g, int numArgsPushed) { PyrSlot* a = g->sp; PyrObject *array = a->uo; PyrSlot* args = array->slots; int numargs = array->size; if (numargs < 1) return errFailed; big_scpacket packet; if (IsFloat(args) || IsNil(args) || IsInt(args)) { makeSynthBundle(&packet, args, numargs, false); } else if (IsSym(args) || isKindOfSlot(args, class_string)) { makeSynthMsgWithTags(&packet, args, numargs); } else { return errWrongType; } int size = packet.size(); PyrInt8Array* obj = newPyrInt8Array(g->gc, size, 0, true); obj->size = size; memcpy(obj->b, packet.data(), size); SetObject(a, (PyrObject*)obj); //for (int i=0; i<packet.size()/4; i++) post("%d %08X\n", i, packet.buf[i]); return errNone; }
void flext_base::cb_anything(flext_hdr *c,const t_symbol *s,int argc,t_atom *argv) { Locker lock(c); if(UNLIKELY(!s)) { // apparently, this happens only in one case... object is a DSP object, but has no main DSP inlet... // interpret tag from args if(!argc) s = sym_bang; else if(argc == 1) { if(IsFloat(*argv)) s = sym_float; else if(IsSymbol(*argv)) s = sym_symbol; else if(IsPointer(*argv)) s = sym_pointer; else FLEXT_ASSERT(false); } else s = sym_list; } thisObject(c)->CbMethodHandler(0,s,argc,argv); }
bool CTabLayoutUI::SelectItem(int iIndex) { if( iIndex < 0 || iIndex >= m_items.GetSize() ) return false; if( iIndex == m_iCurSel ) return true; int iOldSel = m_iCurSel; m_iCurSel = iIndex; for( int it = 0; it < m_items.GetSize(); it++ ) { if( it == iIndex ) { GetItemAt(it)->SetVisible(true); GetItemAt(it)->SetFocus(); // SetPos(m_rcItem); if (!IsFloat()) { SetPos(GetPos(), false); } else { SetPos(GetRelativePos(), false); } //SetPos(m_rcItem); } else GetItemAt(it)->SetVisible(false); } NeedParentUpdate(); if( m_pManager != NULL ) { m_pManager->SetNextTabControl(); m_pManager->SendNotify(this, DUI_MSGTYPE_TABSELECT, m_iCurSel, iOldSel); } return true; }
LLBC_Variant &LLBC_Variant::BecomeFloat() { if (!IsFloat()) { *this = AsFloat(); } return *this; }
void OutRecord::OnBnClickedSubmit() { // TODO: 在此添加控件通知处理程序代码 Records record = NULL; record = (Records)malloc(sizeof(Record)); CString card_num,info,money_num,direct; record->type = outcome; record->record_info = NULL; GetDlgItemText(OUT_TYPE_COMBOX,direct); GetDlgItemText(OUT_CARD_COMBOX,card_num); for (int i = 0;i < MAXCARD;i++) { if (cards[i] == card_num) { record->card_num = i; } } if (direct == "现金") { record->direct = cash; } else { record->direct = card; } GetDlgItemText(OUT_MONEY_NUM,money_num); if (FALSE == IsFloat(money_num,OUT_MONEY_NUM)) { MessageBox("输入的金额格式有误,请检查。","错误"); free(record); return; } record->money_num = atof(money_num); if ("" == money_num) { MessageBox("输入的金额不可为 0 。","错误"); free(record); return; } record->record_info = new CString(); GetDlgItemText(OUT_INFO,(*record->record_info)); //memset(record->record_info,0,256); // record->record_info = info.GetBuffer(info.GetLength()); //memcpy(record->record_info,info.GetBuffer(),info.GetLength()); // info.ReleaseBuffer(); //record->record_info = info; record->next = NULL; HWND hwnd = ::GetParent(m_hWnd); ::SendMessage(hwnd,WM_MyMessage1,0,(LPARAM)record); //MessageBoxA("添加记录成功!","提示"); EndDialog(0); }
retCode g__sleep(processPo P, ptrPo a) { ptrI x = deRefI(&a[1]); if (isvar(x)) return liberror(P, "sleep", eINSUFARG); else { objPo A1 = objV(x); if (!IsFloat(A1)) return liberror(P, "sleep", eNUMNEEDD); else { double f = FloatVal(A1); struct timeval now; double seconds; double fraction = modf(f, &seconds); gettimeofday(&now, NULL); if (seconds < now.tv_sec || (seconds == now.tv_sec && (fraction * 1000000) < now.tv_usec)) return Ok; else { struct timespec tm; tm.tv_sec = (long) seconds; tm.tv_nsec = (long) (fraction * NANO); /* Convert microseconds to nanoseconds */ tm.tv_sec = (long) seconds - now.tv_sec; tm.tv_nsec = (long) (fraction * NANO) - now.tv_usec * 1000; /* Convert microseconds to nanoseconds */ if (tm.tv_nsec > NANO) { tm.tv_nsec -= NANO; tm.tv_sec++; } else if (tm.tv_nsec < 0) { tm.tv_nsec += NANO; tm.tv_sec--; } switchProcessState(P, wait_timer); if (nanosleep(&tm, NULL) != 0) { setProcessRunnable(P); switch (errno) { case EINTR: return liberror(P, "sleep", eINTRUPT); case EINVAL: case ENOSYS: default: return liberror(P, "sleep", eINVAL); } } else { setProcessRunnable(P); return Ok; } } } } }
/*! \todo there is probably also a shortcut for Max and jMax \todo size checking */ FLEXT_TEMPIMPL(void FLEXT_CLASSDEF(flext))::GetAString(const t_atom &a,char *buf,size_t szbuf) { #if FLEXT_SYS == FLEXT_SYS_PD atom_string(const_cast<t_atom *>(&a),buf,(int)szbuf); #else if(IsSymbol(a)) STD::strncpy(buf,GetString(a),szbuf); else if(IsFloat(a)) STD::snprintf(buf,szbuf,"%f",GetFloat(a)); else if(IsInt(a)) STD::snprintf(buf,szbuf,"%i",GetInt(a)); else *buf = 0; #endif }
void ScalarSelectionDialog::AssignToValue() { auto valueStr = m_pTextCtrl->GetValue().ToStdString(); if (IsFloat(m_type)) { m_value = std::stod(valueStr); } else if (IsIntegral(m_type)) { m_value = std::stol(valueStr); } }
// ------------------------------------------------------------------- // ToString // ------------------------------------------------------------------- boost::shared_ptr<string> Vec3D::ToString() { char buffer[512]; if (IsFloat()) sprintf (buffer, "(%f,%f,%f)\n", fx, fy, fz); else sprintf (buffer, "(%ld,%ld,%ld)\n", ix, iy, iz); boost::shared_ptr<string> str (new string(buffer)); return str; }
///--------------------------------------------------------------------------------- /// ///--------------------------------------------------------------------------------- bool DeveloperConsoleArguments::GetFloat( float& flt ) { std::string string = ""; if (PeekString( string )) { if (IsFloat( string )) { flt = strtof( string.c_str(), nullptr ); m_currentIndex++; return true; } return false; } return false; }
bool CTag::WriteTagToFile(CFileDataIO* file, EUtf8Str WXUNUSED(eStrEncode), bool restrictive) const { // Don't write tags of unknown types, we wouldn't be able to read them in again // and the met file would be corrupted if (!restrictive || (IsStr() || IsInt() || IsFloat() || IsBlob())) { // If this fails, it'll throw. file->WriteTag(*this); return true; } else { printf("%s; Ignored tag with unknown type=0x%02X\n", __FUNCTION__, m_uType); return false; } }
bool CSettings::SetEx(String strSetting, String strValue) { if(IsBool(strSetting)) SetBool(strSetting, strValue.ToBoolean()); else if(IsInteger(strSetting)) SetInteger(strSetting, strValue.ToInteger()); else if(IsFloat(strSetting)) SetFloat(strSetting, strValue.ToFloat()); else if(IsString(strSetting)) SetString(strSetting, strValue); else if(IsList(strSetting)) AddToList(strSetting, strValue); else return false; return true; }
bool CItemParamsNode::ConvertFromXMLWithFiltering(const XmlNodeRef &root, const char * keepWithThisAttrValue) { bool filteringRequired = false; int nattributes = root->getNumAttributes(); m_attributes.reserve(nattributes); for (int a=0; a<nattributes; a++) { const char *name=0; const char *value=0; if (root->getAttributeByIndex(a, &name, &value)) { float f; int i; Vec3 v; if (!stricmp(value, "true")) SetAttribute(name, 1); else if (!stricmp(value, "false")) SetAttribute(name, 0); else if (IsInteger(value, &i)) SetAttribute(name, i); else if (IsFloat(value, &f)) SetAttribute(name, f); else if (IsVec3(value, &v)) SetAttribute(name, v); else SetAttribute(name, value); } } int nchildren = root->getChildCount(); m_children.reserve(nchildren); for (int c=0; c<nchildren; c++) { XmlNodeRef child = root->getChild(c); EXMLFilterType filterType = ShouldConvertNodeFromXML(child, keepWithThisAttrValue); filteringRequired = (filterType != eXMLFT_none) || filteringRequired ? true : false; if(filterType != eXMLFT_remove) { filteringRequired = (InsertChild(child->getTag())->ConvertFromXMLWithFiltering(child, keepWithThisAttrValue) || filteringRequired); } } return filteringRequired; }
bool CSettings::SetFloat(String strSetting, float fValue) { if(IsFloat(strSetting)) { SettingsValue * setting = GetSetting(strSetting); if(fValue < setting->fMinimumValue || fValue > setting->fMaximimValue) return false; setting->fValue = fValue; // Save the XML file Save(); return true; } return false; }
static void SendMessage(TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct>>> & _pendingMessages, const osc::ReceivedMessage & message) { const FName address(message.AddressPattern()); TArray<FOscDataElemStruct> data; const auto argBegin = message.ArgumentsBegin(); const auto argEnd = message.ArgumentsEnd(); for(auto it = argBegin; it != argEnd; ++it) { FOscDataElemStruct elem; if(it->IsFloat()) { elem.SetFloat(it->AsFloatUnchecked()); } else if(it->IsDouble()) { elem.SetFloat(it->AsDoubleUnchecked()); } else if(it->IsInt32()) { elem.SetInt(it->AsInt32Unchecked()); } else if(it->IsInt64()) { elem.SetInt(it->AsInt64Unchecked()); } else if(it->IsBool()) { elem.SetBool(it->AsBoolUnchecked()); } else if(it->IsString()) { elem.SetString(FName(it->AsStringUnchecked())); } data.Add(elem); } // save it in pending messages _pendingMessages.Enqueue(std::make_pair(address, data)); }
inline MsgBundle &Add(flext_base *th,int o,const t_atom &a) { const t_symbol *sym; if(IsSymbol(a)) sym = sym_symbol; else if(IsFloat(a)) sym = sym_float; #if FLEXT_SYS == FLEXT_SYS_MAX else if(IsInt(a)) sym = sym_int; #endif #if FLEXT_SYS == FLEXT_SYS_PD else if(IsPointer(a)) sym = sym_pointer; #endif else { error("atom type not supported"); return *this; } return Add(th,o,sym,1,&a); }
uint64 LLBC_Variant::AsUInt64() const { if (IsNil()) { return 0; } else if (IsDict()) { return 0; } else if (IsStr()) { return LLBC_Str2UInt64(_holder.str.c_str()); } if (IsDouble() || IsFloat()) { return static_cast<uint64>(_holder.raw.doubleVal); } return _holder.raw.uint64Val; }
void flext_base::ToSysAtom(int n,const t_atom &at) const { outlet *o = GetOut(n); if(LIKELY(o)) { CRITON(); if(IsSymbol(at)) outlet_symbol((t_outlet *)o,const_cast<t_symbol *>(GetSymbol(at))); else if(IsFloat(at)) outlet_float((t_outlet *)o,GetFloat(at)); #if FLEXT_SYS == FLEXT_SYS_MAX else if(IsInt(at)) outlet_flint((t_outlet *)o,GetInt(at)); #endif #if FLEXT_SYS == FLEXT_SYS_PD else if(IsPointer(at)) outlet_pointer((t_outlet *)o,GetPointer(at)); #endif else error("Atom type not supported"); CRITOFF(); } }
retCode g__delay(processPo P, ptrPo a) { ptrI x = deRefI(&a[1]); if (isvar(x)) return liberror(P, "delay", eINSUFARG); else { objPo A1 = objV(x); if (!IsFloat(A1)) return liberror(P, "delay", eNUMNEEDD); else { struct timespec tm; double seconds; double fraction = modf(FloatVal(A1), &seconds); #define NANO (1000000000) tm.tv_sec = (long) seconds; tm.tv_nsec = (long) (fraction * NANO); /* Convert microseconds to nanoseconds */ switchProcessState(P, wait_timer); if (nanosleep(&tm, NULL) != 0) { setProcessRunnable(P); switch (errno) { case EINTR: return liberror(P, "delay", eINTRUPT); case EINVAL: case ENOSYS: default: return liberror(P, "delay", eINVAL); } } else { setProcessRunnable(P); return Ok; } } } }
void serialize(PyrSlot * slot) { if (IsFloat(slot)) { emitter << slotRawFloat(slot); return; } switch (GetTag(slot)) { case tagNil: emitter << YAML::Null; return; case tagInt: emitter << slotRawInt(slot); return; case tagFalse: emitter << false; return; case tagTrue: emitter << true; return; case tagObj: serialize(slotRawObject(slot)); return; case tagSym: emitter << YAML::DoubleQuoted << slotRawSymbol(slot)->name; return; default: printf ("type: %d\n", GetTag(slot)); throw std::runtime_error("YAMLSerializer: not implementation for this type"); } }
void ExRecord::OnBnClickedSubmit() { // TODO: 在此添加控件通知处理程序代码 Records record = NULL; record = (Records)malloc(sizeof(Record)); record->record_info = NULL; CString info,money_num,from,to; int from_n,to_n; record->type = exchange; GetDlgItemText(EX_COMBOX_FROM,from); GetDlgItemText(EX_COMBOX_TO,to); from_n = FindCard(from); to_n = FindCard(to); GetDlgItemText(EX_MONEY_NUM,money_num); if (FALSE == IsFloat(money_num,IN_MONEY_NUM)) { MessageBox("输入的金额格式有误,请检查","错误"); free(record); return; } if ("" == money_num) { MessageBox("输入的金额不可为 0 ","错误"); free(record); return; } record->money_num = atof(money_num); record->record_info = new CString(); record->record_info->Format("#%s#%s#%d#%d",from,to,from_n,to_n); record->next = NULL; HWND hwnd = ::GetParent(m_hWnd); ::SendMessage(hwnd,WM_MyMessage1,0,(LPARAM)record); EndDialog(0); }
float CTag::GetFloat() const { CHECK_TAG_TYPE(IsFloat(), Float); return m_fVal; }