//----------------------------------------------------------- // Read gauge tags //----------------------------------------------------------- int CTexturedGauge::Read(SStream *str, Tag tag) { int ph = panel->GetHeight(); switch (tag) { //--- Define projector ----------------- case 'cadr': DecodeCADR(str,quad,1); return TAG_READ; case 'proj': DecodePROJ(str,quad,0); return TAG_READ; //--- Define the needle ---------------- case 'nedl': nedl.SetGauge(this); ReadFrom(&nedl,str); return TAG_READ; //--- Define underlay ----------------- case 'back': under.SetGauge(this); ReadFrom(&under,str); return TAG_READ; case 'undr': under.Init(str,this); return TAG_READ; //--- Define overlay ------------------ case 'ovrl': overl.Init(str,this); return TAG_READ; //--- Define a cover ------------------ case 'covr': overl.SetGauge(this); ReadFrom(&overl,str); return TAG_READ; } return CGauge::Read (str, tag); }
double Element::GetDataAsNumber(void) { if (data_lines.size() == 1) { double number=0; if (is_number(trim(data_lines[0]))) number = atof(data_lines[0].c_str()); else { cerr << ReadFrom() << "Expected numeric value, but got: " << data_lines[0] << endl; exit(-1); } return number; } else if (data_lines.size() == 0) { cerr << ReadFrom() << "Expected numeric value, but got no data" << endl; exit(-1); } else { cerr << ReadFrom() << "Attempting to get single data value in element " << "<" << name << ">" << endl << " from multiple lines:" << endl; for(unsigned int i=0; i<data_lines.size(); ++i) cerr << data_lines[i] << endl; exit(-1); } }
FGColumnVector3 Element::FindElementTripletConvertTo( const string& target_units) { FGColumnVector3 triplet; Element* item; double value=0.0; string supplied_units = GetAttributeValue("unit"); if (!supplied_units.empty()) { if (convert.find(supplied_units) == convert.end()) { std::stringstream error; error << ReadFrom() << "Supplied unit: \"" << supplied_units << "\" does not exist (typo?)." << endl; throw std::runtime_error(error.str()); } if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) { std::stringstream error; error << ReadFrom() << "Supplied unit: \"" << supplied_units << "\" cannot be converted to " << target_units << endl; throw std::runtime_error(error.str()); } } item = FindElement("x"); if (!item) item = FindElement("roll"); if (item) { value = item->GetDataAsNumber(); if (!supplied_units.empty()) value *= convert[supplied_units][target_units]; triplet(1) = DisperseValue(item, value, supplied_units, target_units); } else { triplet(1) = 0.0; } item = FindElement("y"); if (!item) item = FindElement("pitch"); if (item) { value = item->GetDataAsNumber(); if (!supplied_units.empty()) value *= convert[supplied_units][target_units]; triplet(2) = DisperseValue(item, value, supplied_units, target_units); } else { triplet(2) = 0.0; } item = FindElement("z"); if (!item) item = FindElement("yaw"); if (item) { value = item->GetDataAsNumber(); if (!supplied_units.empty()) value *= convert[supplied_units][target_units]; triplet(3) = DisperseValue(item, value, supplied_units, target_units); } else { triplet(3) = 0.0; } return triplet; }
double Element::FindElementValueAsNumberConvertTo(const string& el, const string& target_units) { Element* element = FindElement(el); if (!element) { std::stringstream error; error << ReadFrom() << "Attempting to get non-existent element " << el << endl; throw std::runtime_error(error.str()); } string supplied_units = element->GetAttributeValue("unit"); if (!supplied_units.empty()) { if (convert.find(supplied_units) == convert.end()) { std::stringstream error; error << element->ReadFrom() << "Supplied unit: \"" << supplied_units << "\" does not exist (typo?)." << endl; throw std::runtime_error(error.str()); } if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) { std::stringstream error; error << element->ReadFrom() << "Supplied unit: \"" << supplied_units << "\" cannot be converted to " << target_units << endl; throw std::runtime_error(error.str()); } } double value = element->GetDataAsNumber(); // Sanity check for angular values if ((supplied_units == "RAD") && (fabs(value) > 2 * M_PI)) { cerr << element->ReadFrom() << "The value " << value << " RAD is outside the range [ -2*M_PI RAD ; +2*M_PI RAD ]" << endl; } if ((supplied_units == "DEG") && (fabs(value) > 360.0)) { cerr << element->ReadFrom() << "The value " << value << " DEG is outside the range [ -360 DEG ; +360 DEG ]" << endl; } if (!supplied_units.empty()) { value *= convert[supplied_units][target_units]; } if ((target_units == "RAD") && (fabs(value) > 2 * M_PI)) { cerr << element->ReadFrom() << "The value " << value << " RAD is outside the range [ -2*M_PI RAD ; +2*M_PI RAD ]" << endl; } if ((target_units == "DEG") && (fabs(value) > 360.0)) { cerr << element->ReadFrom() << "The value " << value << " DEG is outside the range [ -360 DEG ; +360 DEG ]" << endl; } value = DisperseValue(element, value, supplied_units, target_units); return value; }
uint32_t RrepHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; m_flags = i.ReadU8 (); m_prefixSize = i.ReadU8 (); m_hopCount = i.ReadU8 (); ReadFrom (i, m_dst); m_dstSeqNo = i.ReadNtohU32 (); ReadFrom (i, m_origin); m_lifeTime = i.ReadNtohU32 (); uint32_t dist = i.GetDistanceFrom (start); NS_ASSERT (dist == GetSerializedSize ()); return dist; }
void NodesPropertyControl::UpdateFieldsForCurrentNode() { if(currentSceneNode) { currentSceneNode->Retain(); ReadFrom(currentSceneNode); currentSceneNode->Release(); } }
//------------------------------------------------------------------------------- // Decode this file //------------------------------------------------------------------------------- bool CPlaneIdent::ScanInfoFile(const char *filname) { SStream s; make[0] = 0; icon[0] = 0; if (OpenRStream((char *)filname,s) == 0) return false; item = 0; ReadFrom (this, &s); CloseStream (&s); return true; }
GlChain::GlChain(const BMessage* config) : mData(new GlChainPrivate()), mStatus(B_OK), mKey(0), mIo(0), mParent(0), mDynamic(0), mDynamicCount(0) { if (!mData) { mStatus = B_NO_MEMORY; return; } if (config) mStatus = ReadFrom(*config); }
void Mesh::ReadFrom(char *filename) { FILE *in = fopen(filename, "rb"); if(!in) { cout << "ERROR: Couldn't open file " << filename << " to read from.\n"; return; } ReadFrom(in); fclose(in); }
void *File::Mmap(void *addr, size_t length, int prot, int flags, off_t offset, bool isPriv) { void *res = internal_mmap(addr, length, prot, flags, this, offset, false); if (res) { ASSERT(res == addr); bool ok = ReadFrom(addr, length, offset); ASSERT(ok); } return res; }
double Element::FindElementValueAsNumber(const string& el) { Element* element = FindElement(el); if (element) { double value = element->GetDataAsNumber(); value = DisperseValue(element, value); return value; } else { cerr << ReadFrom() << "Attempting to get non-existent element " << el << endl; exit(-1); } }
double Element::GetAttributeValueAsNumber(const string& attr) { string attribute = GetAttributeValue(attr); if (attribute.empty()) { cerr << ReadFrom() << "Expecting numeric attribute value, but got no data" << endl; exit(-1); } else { double number=0; if (is_number(trim(attribute))) number = atof(attribute.c_str()); else { cerr << ReadFrom() << "Expecting numeric attribute value, but got: " << attribute << endl; exit(-1); } return (number); } }
double Element::FindElementValueAsNumber(const string& el) { Element* element = FindElement(el); if (element) { double value = element->GetDataAsNumber(); value = DisperseValue(element, value); return value; } else { std::stringstream error; error << ReadFrom() << "Attempting to get non-existent element " << el << endl; throw std::runtime_error(error.str()); } }
int plBufferedSocketReader::ReadBlock(char * buf, int buflen, plTcpSocket & sck) { if(GetBlock(buf, buflen)) return kSuccessWithData; int ans = ReadFrom(sck); if(ans<=0) return ans; if(GetBlock(buf, buflen)) return kSuccessWithData; return kSuccessNoData; }
int32 CFile::ReadFrom(void* pBuf, int32 nBufLen, CString &oFileName, uint32 nTimeOut) { CFileName oFileName2; int32 nRet = ReadFrom(pBuf, nBufLen, oFileName2, nTimeOut); if(nRet) return nRet; oFileName.Clear(); CStringFormatter oFormatter(&oFileName); oFormatter.Print("%s://", oFileName2.oProtocol.GetStr()); oFormatter.Print("%s", oFileName2.oConnectName.GetStr()); if(!oFileName2.oBindName.Empty()) oFormatter.Print("|%s", oFileName2.oBindName.GetStr()); return nRet; }
double Element::GetAttributeValueAsNumber(const string& attr) { string attribute = GetAttributeValue(attr); if (attribute.empty()) { std::stringstream error; error << ReadFrom() << "Expecting numeric attribute value, but got no data" << endl; throw std::runtime_error(error.str()); } else { double number=0; if (is_number(trim(attribute))) number = atof(attribute.c_str()); else { std::stringstream error; error << ReadFrom() << "Expecting numeric attribute value, but got: " << attribute << endl; throw std::runtime_error(error.str()); } return (number); } }
uint8_t IePerr::DeserializeInformationField (Buffer::Iterator start, uint8_t length) { Buffer::Iterator i = start; i.Next (1); //Mode flags is not used now uint8_t numOfDest = i.ReadU8 (); NS_ASSERT ((2 + 10 * numOfDest ) == length); length = 0; //to avoid compiler warning in optimized builds for (unsigned int j = 0; j < numOfDest; j++) { HwmpProtocol::FailedDestination unit; ReadFrom (i, unit.destination); unit.seqnum = i.ReadLsbtohU32 (); m_addressUnits.push_back (unit); } return i.GetDistanceFrom (start); }
double Element::DisperseValue(Element *e, double val, const std::string& supplied_units, const std::string& target_units) { double value=val; bool disperse = false; try { char* num = getenv("JSBSIM_DISPERSE"); if (num) { disperse = (atoi(num) == 1); // set dispersions } } catch (...) { // if error set to false disperse = false; std::cerr << "Could not process JSBSIM_DISPERSE environment variable: Assumed NO dispersions." << endl; } if (e->HasAttribute("dispersion") && disperse) { double disp = e->GetAttributeValueAsNumber("dispersion"); if (!supplied_units.empty()) disp *= convert[supplied_units][target_units]; string attType = e->GetAttributeValue("type"); if (attType == "gaussian" || attType == "gaussiansigned") { double grn = FGJSBBase::GaussianRandomNumber(); if (attType == "gaussian") { value = val + disp*grn; } else { // Assume gaussiansigned value = (val + disp*grn)*(fabs(grn)/grn); } } else if (attType == "uniform" || attType == "uniformsigned") { double urn = ((((double)rand()/RAND_MAX)-0.5)*2.0); if (attType == "uniform") { value = val + disp * urn; } else { // Assume uniformsigned value = (val + disp * urn)*(fabs(urn)/urn); } } else { std::stringstream error; error << ReadFrom() << "Unknown dispersion type" << attType << endl; throw std::runtime_error(error.str()); } } return value; }
int plBufferedSocketReader::ReadStringInPlace(char ** buf, char * termChars, plTcpSocket & sck) { if(GetStringInPlace(buf, termChars)) return kSuccessWithData; int ans = kSuccessNoData; while ( ans>=0 ) { ans = ReadFrom(sck); if(ans>0) { if ( GetStringInPlace(buf, termChars) ) return kSuccessWithData; } } return ans; }
uint32_t RerrHeader::Deserialize (Buffer::Iterator start ) { Buffer::Iterator i = start; m_flag = i.ReadU8 (); m_reserved = i.ReadU8 (); uint8_t dest = i.ReadU8 (); m_unreachableDstSeqNo.clear (); Ipv4Address address; uint32_t seqNo; for (uint8_t k = 0; k < dest; ++k) { ReadFrom (i, address); seqNo = i.ReadNtohU32 (); m_unreachableDstSeqNo.insert (std::make_pair (address, seqNo)); } uint32_t dist = i.GetDistanceFrom (start); NS_ASSERT (dist == GetSerializedSize ()); return dist; }
void NodesPropertyControl::OnCellSelected(UIList *, UIListCell *selectedCell) { if(currentSceneNode) { int32 index = selectedCell->GetIndex(); KeyedArchive *customProperties = currentSceneNode->GetCustomProperties(); Map<String, VariantType*> propsData = customProperties->GetArchieveData(); int32 i = 0; for (Map<String, VariantType*>::iterator it = propsData.begin(); it != propsData.end(); ++it, ++i) { if(i == index) { customProperties->DeleteKey(it->first); OnCancel(NULL, NULL, NULL); ReadFrom(currentSceneNode); break; } } } }
void CEeprom::EepromCommand(uint8_t * Command) { time_t curtime_time; struct tm curtime; if (g_System->m_SaveUsing == SaveChip_Auto) { g_System->m_SaveUsing = SaveChip_Eeprom_4K; } switch (Command[2]) { case 0: // check if (g_System->m_SaveUsing != SaveChip_Eeprom_4K && g_System->m_SaveUsing != SaveChip_Eeprom_16K) { Command[1] |= 0x80; break; } if (Command[1] != 3) { Command[1] |= 0x40; if ((Command[1] & 3) > 0) { Command[3] = 0x00; } if ((Command[1] & 3) > 1) { Command[4] = (g_System->m_SaveUsing == SaveChip_Eeprom_4K) ? 0x80 : 0xC0; } if ((Command[1] & 3) > 2) { Command[5] = 0x00; } } else { Command[3] = 0x00; Command[4] = g_System->m_SaveUsing == SaveChip_Eeprom_4K ? 0x80 : 0xC0; Command[5] = 0x00; } break; case 4: // Read from Eeprom if (Command[0] != 2 && bHaveDebugger()) { g_Notify->DisplayError("What am I meant to do with this Eeprom Command"); } if (Command[1] != 8 && bHaveDebugger()) { g_Notify->DisplayError("What am I meant to do with this Eeprom Command"); } ReadFrom(&Command[4], Command[3]); break; case 5: //Write to Eeprom if (Command[0] != 10 && bHaveDebugger()) { g_Notify->DisplayError("What am I meant to do with this Eeprom Command"); } if (Command[1] != 1 && bHaveDebugger()) { g_Notify->DisplayError("What am I meant to do with this Eeprom Command"); } WriteTo(&Command[4], Command[3]); break; case 6: //RTC Status query Command[3] = 0x00; Command[4] = 0x10; Command[5] = 0x00; break; case 7: //Read RTC block switch (Command[3]) { case 0: //Block number Command[4] = 0x00; Command[5] = 0x02; Command[12] = 0x00; break; case 1: //read block, Command[2], Unimplemented break; case 2: //Set RTC Time time(&curtime_time); memcpy(&curtime, localtime(&curtime_time), sizeof(curtime)); // fd's fix Command[4] = byte2bcd(curtime.tm_sec); Command[5] = byte2bcd(curtime.tm_min); Command[6] = 0x80 + byte2bcd(curtime.tm_hour); Command[7] = byte2bcd(curtime.tm_mday); Command[8] = byte2bcd(curtime.tm_wday); Command[9] = byte2bcd(curtime.tm_mon + 1); Command[10] = byte2bcd(curtime.tm_year); Command[11] = byte2bcd(curtime.tm_year / 100); Command[12] = 0x00; // status break; } break; case 8: //Write RTC, unimplemented if (g_Settings->LoadDword(Debugger_ShowPifErrors)) { g_Notify->DisplayError("Write RTC, unimplemented"); } break; default: if (g_Settings->LoadDword(Debugger_ShowPifErrors)) { g_Notify->DisplayError(stdstr_f("Unknown EepromCommand %d", Command[2]).c_str()); } } }
/*************************************************************************** * GL-PLANE-NODE ***************************************************************************/ GlPlaneNode::GlPlaneNode(const GlNodeAddOn* addon, const BMessage* config) : inherited(addon, 0), mPixelTargets(GL_PIXEL_RGB) { if (config) ReadFrom(*config); }
GlAbstractNode::GlAbstractNode(const BMessage* config) : mData(new GlNodePrivate()) { if (mData && config) ReadFrom(*config); }
Dictionary::Dictionary(istream& is) { ReadFrom(is); }
//--------------------------------------------------------------------- // Read the knob parameters //--------------------------------------------------------------------- int CNeedleMark::ReadKNOB(SStream *stream) { knob.SetGauge(mgg); ReadFrom(&knob,stream); return TAG_READ; }
inline size_type ValidateStrictCount(const Packed &count) { const auto result = ReadFrom(count); return (result != 0) ? result : -1; }