/* ChasmBinArchive::open * Reads Chasm bin format data from a MemChunk * Returns true if successful, false otherwise *******************************************************************/ bool ChasmBinArchive::open(MemChunk& mc) { // Check given data is valid if (mc.getSize() < HEADER_SIZE) { return false; } // Read .bin header and check it char magic[4] = {}; mc.read(magic, sizeof magic); if ( magic[0] != 'C' || magic[1] != 'S' || magic[2] != 'i' || magic[3] != 'd') { wxLogMessage("ChasmBinArchive::open: Opening failed, invalid header"); Global::error = "Invalid Chasm bin header"; return false; } // Stop announcements (don't want to be announcing modification due to entries being added etc) setMuted(true); uint16_t num_entries = 0; mc.read(&num_entries, sizeof num_entries); num_entries = wxUINT16_SWAP_ON_BE(num_entries); // Read the directory theSplashWindow->setProgressMessage("Reading Chasm bin archive data"); for (uint16_t i = 0; i < num_entries; ++i) { // Update splash window progress theSplashWindow->setProgress(static_cast<float>(i) / num_entries); // Read entry info char name[NAME_SIZE] = {}; mc.read(name, sizeof name); uint32_t size; mc.read(&size, sizeof size); size = wxUINT32_SWAP_ON_BE(size); uint32_t offset; mc.read(&offset, sizeof offset); offset = wxUINT32_SWAP_ON_BE(offset); // Check offset+size if (offset + size > mc.getSize()) { wxLogMessage("ChasmBinArchive::open: Bin archive is invalid or corrupt (entry goes past end of file)"); Global::error = "Archive is invalid and/or corrupt"; setMuted(false); return false; } // Convert Pascal to zero-terminated string memmove(name, name + 1, sizeof name - 1); name[sizeof name - 1] = '\0'; // Create entry ArchiveEntry* const entry = new ArchiveEntry(name, size); entry->exProp("Offset") = static_cast<int>(offset); entry->setLoaded(false); entry->setState(0); getRoot()->addEntry(entry); } // Detect all entry types theSplashWindow->setProgressMessage("Detecting entry types"); vector<ArchiveEntry*> all_entries; getEntryTreeAsList(all_entries); MemChunk edata; for (size_t i = 0; i < all_entries.size(); ++i) { // Update splash window progress theSplashWindow->setProgress(static_cast<float>(i) / num_entries); // Get entry ArchiveEntry* const entry = all_entries[i]; // Read entry data if it isn't zero-sized if (entry->getSize() > 0) { // Read the entry data mc.exportMemChunk(edata, static_cast<int>(entry->exProp("Offset")), entry->getSize()); entry->importMemChunk(edata); } // Detect entry type EntryType::detectEntryType(entry); FixBrokenWave(entry); // Unload entry data if needed if (!archive_load_data) { entry->unloadData(); } // Set entry to unchanged entry->setState(0); } // Setup variables setMuted(false); setModified(false); announce("opened"); theSplashWindow->setProgressMessage(""); return true; }
void Beacon::setIterator(bool isDFS) { iterator->makeIndex(getRoot(), isDFS); }
bool TUIManager<T>::isTopUI( TUICore<T>* ui ) { TUICore<T>* parent = ui->getParent(); return parent == getRoot() || parent == &mRemoveUI; }
void BasicScreenObject::addChildAt(BasicScreenObject* _child, int _index){ childit=childlist.begin(); childlist.insert(childit+_index, _child); _child->setParent(this); _child->setRoot(getRoot()); }
void Category::setRootPriority(Priority::Value priority) { getRoot().setPriority(priority); }
bool planning_models::KinematicModel::addModelGroup(const planning_models::KinematicModel::GroupConfig& gc) { if(joint_model_group_map_.find(gc.name_) != joint_model_group_map_.end()) { ROS_WARN_STREAM("Already have a model group named " << gc.name_ <<". Not adding."); return false; } std::vector<const JointModel*> jointv; std::vector<const JointModel*> fixed_jointv; if(!gc.tip_link_.empty() && !gc.base_link_.empty()) { if(!gc.subgroups_.empty()) { ROS_WARN_STREAM("Ignoring subgroups as tip and base are defined for group " << gc.name_); } //if this is not a physical robot link but is the world link bool base_link_is_world_link = (gc.base_link_ == getRoot()->getParentFrameId() && getLinkModel(gc.base_link_) == NULL); const LinkModel* base_link = NULL; if(!base_link_is_world_link) { base_link = getLinkModel(gc.base_link_); if(base_link == NULL) { ROS_WARN_STREAM("Group config " << gc.name_ << " has invalid base link " << gc.base_link_); return false; } } const LinkModel* tip_link = getLinkModel(gc.tip_link_); if(tip_link == NULL) { ROS_WARN_STREAM("Group config " << gc.name_ << " has invalid tip link " << gc.tip_link_); return false; } const LinkModel* lm = tip_link; bool ok = false; while(true) { if(lm == NULL) { if(base_link_is_world_link) { ok = true; } break; } if(lm == base_link) { ok = true; break; } if(lm->getParentJointModel() == NULL) { break; } //only adding non-fixed joint models const FixedJointModel* fjm = dynamic_cast<const FixedJointModel*>(lm->getParentJointModel()); if(fjm == NULL) { jointv.push_back(lm->getParentJointModel()); } else { fixed_jointv.push_back(fjm); } lm = lm->getParentJointModel()->getParentLinkModel(); } if(!ok) { ROS_WARN_STREAM("For group " << gc.name_ << " base link " << gc.base_link_ << " does not appear to be a direct descendent of " << gc.tip_link_); return false; } //need to reverse jointv to get things in right order std::reverse(jointv.begin(), jointv.end()); } else { if(!gc.subgroups_.empty()) { std::set<const JointModel*> joint_set; for(unsigned int i = 0; i < gc.subgroups_.size(); i++) { if(joint_model_group_map_.find(gc.subgroups_[i]) == joint_model_group_map_.end()) { ROS_INFO_STREAM("Subgroup " << gc.subgroups_[i] << " not defined so can't add group " << gc.name_); return false; } const JointModelGroup* jmg = joint_model_group_map_.find(gc.subgroups_[i])->second; for(unsigned int j = 0; j < jmg->getJointModels().size(); j++) { joint_set.insert(jmg->getJointModels()[j]); } } for(std::set<const JointModel*>::iterator it = joint_set.begin(); it != joint_set.end(); it++) { jointv.push_back((*it)); } } if(gc.joints_.size() == 0 && gc.subgroups_.empty()) { ROS_WARN_STREAM("Group " << gc.name_ << " must have tip/base links, subgroups, or one or more joints"); return false; } for(unsigned int j = 0; j < gc.joints_.size(); j++) { const JointModel* joint = getJointModel(gc.joints_[j]); if(joint == NULL) { ROS_ERROR_STREAM("Group " << gc.name_ << " has invalid joint " << gc.joints_[j]); return false; } jointv.push_back(joint); } } if(jointv.size() == 0) { ROS_WARN_STREAM("Group " << gc.name_ << " must have at least one valid joint"); return false; } joint_model_group_map_[gc.name_] = new JointModelGroup(gc.name_, jointv, fixed_jointv, this); joint_model_group_config_map_[gc.name_] = gc; return true; }
string DirectoryListing::loadXML(const string& xml, bool updating) { ListLoader ll(this, getRoot(), updating); SimpleXMLReader(&ll).fromXML(xml); return ll.getBase(); }
//argc is the number of arguments, and argv is the array containing those arguments int main(int argc, char *argv[]) { // declaring area for variables int here; int amountComplex, mRoot, nPower, form, i, j; double tempRealorMag, tempImagorPhase, userInput1, userInput2; complex secondnumber, atemp, stemp, mtemp, dtemp, ptemp, rtemp, ctemp; FILE *inputf; //Pointer to the input filepath FILE *outputf; //Pointer to the output filepath // check to see that there are 2 command line arguments for input-file // and output-file switch (argc) { case 2: fprintf(stderr,"Error: Please also provide an output filename\n"); return(1); case 3: break; // have input file and output file; all is OK default: fprintf(stderr,"Error: Please provide input and output filenames respectively as command line arguments\n"); return(1); } // make sure the input file opens if((inputf=fopen(argv[1],"r"))==NULL) { fprintf(stderr,"Error opening input file file. Check permissions.\n"); return(1); } // make sure the output file opens if((outputf=fopen(argv[2],"w"))==NULL) { fprintf(stderr,"Error opening output file. Check permissions.\n"); return(1); } // reading the first four numbers from the text file fscanf(inputf, "%d", &amountComplex); fscanf(inputf, "%d", &form); fscanf(inputf, "%d", &nPower); fscanf(inputf, "%d", &mRoot); // error checking is missing in the program: // 1) number of complex numbers should be a positive integer // 2) format should be 0 for Cartesian or 1 for Polar, any other number is wrong // 3) can power be any number??? // 4) can root be any number??? // dynamically creates one array of type complex complex myCarray[amountComplex]; // reads the numbers and puts them into an array; closes inputfile for (i = 0; i < amountComplex; i++) { fscanf(inputf, "%lf", &tempRealorMag); fscanf(inputf, "%lf", &tempImagorPhase); myCarray[i].real = tempRealorMag; myCarray[i].imaginary = tempImagorPhase; } fclose(inputf); // enters the second the number to be added, can be in // cartesian (0) or polar (1) formats // cartesian format if (form == 0) { printf("\nEnter real part: "); scanf("%lf", &userInput1); printf("\nEnter imaginary part: "); scanf("%lf", &userInput2); secondnumber.real = userInput1; secondnumber.imaginary = userInput2; } // polar format if (form == 1) { printf("\nEnter Magnitude: "); scanf("%lf", &userInput1); printf("\nEnter Phase: "); scanf("%lf", &userInput2); secondnumber.real = userInput1; secondnumber.imaginary = userInput2; } // for debugging purposes /* printf("\a\a\n\tI am here!!!!\n\n"); printf("Number of complex numbers = %d\n", amountComplex); printf("Format is (0) Cartesian or (1) Polar = %d\n", form); printf("Power is = %d\n", nPower); printf("Root is = %d\n", mRoot); printf("Real or Magnitude of 2nd number is = %lf\n", secondnumber.real); printf("Imaginary of Phase of 2nd number is = %lf\n", secondnumber.imaginary); printf ("Enter an integer number to continue = "); scanf("%d", &here); */ // writes the results to the output file in either Cartesian or Polar formats // cartesian format if(form == 0) { fprintf(outputf, "This will be in Cartesian format, the order of results are:\n"); fprintf(outputf, "Real part\n"); fprintf(outputf, "Imaginary part\n"); fprintf(outputf, "Magnitude\n"); fprintf(outputf, "Phase\n"); fprintf(outputf, "Power\n"); fprintf(outputf, "Root\n"); fprintf(outputf, "Conjugate\n"); fprintf(outputf, "Addition\n"); fprintf(outputf, "Subtraction\n"); fprintf(outputf, "Multiplication\n"); fprintf(outputf, "Division\n\n"); } // polar format if(form == 1) { fprintf(outputf, "This will be in Polar format, the order of results are:\n"); fprintf(outputf, "Real part\n"); fprintf(outputf, "Imaginary part\n"); fprintf(outputf, "Magnitude\n"); fprintf(outputf, "Phase\n"); fprintf(outputf, "Power\n"); fprintf(outputf, "Root\n"); fprintf(outputf, "Conjugate\n"); fprintf(outputf, "Addition\n"); fprintf(outputf, "Subtraction\n"); fprintf(outputf, "Multiplication\n"); fprintf(outputf, "Division\n\n"); } // number crunching part of code for(j = 0; j < amountComplex; j++) { // Real part, Imaginary part, Magnitude, Phase, Power, Root, // and Conjugate of complex number input array fprintf(outputf, "%lf\n", getReal(myCarray[j], form)); fprintf(outputf, "%lf\n", getImaginary(myCarray[j], form)); fprintf(outputf, "%lf\n", getMagnitude(myCarray[j], form)); fprintf(outputf, "%lf\n", getPhase(myCarray[j], form)); ptemp = getPower(nPower, myCarray[j], form); rtemp = getRoot(mRoot, myCarray[j], form); ctemp = getConjugate(myCarray[j]); fprintf(outputf, "%lf %lf \n", ptemp.real, ptemp.imaginary); fprintf(outputf, "%lf %lf \n", rtemp.real, rtemp.imaginary); fprintf(outputf, "%lf %lf \n", ctemp.real, ctemp.imaginary); // Addition, Subtraction, Multiplication, Division with Second Number entered by user atemp = add(myCarray[j], secondnumber, form); stemp = subtract(myCarray[j], secondnumber, form); mtemp = multiply(myCarray[j], secondnumber, form); dtemp = divide(myCarray[j], secondnumber, form); fprintf(outputf, "%lf %lf \n", atemp.real, atemp.imaginary); fprintf(outputf, "%lf %lf \n", stemp.real, stemp.imaginary); fprintf(outputf, "%lf %lf \n", mtemp.real, mtemp.imaginary); fprintf(outputf, "%lf %lf \n", dtemp.real, dtemp.imaginary); fprintf(outputf, "\n\tNext Complex Number"); } fclose(outputf); return(0); } //end of main function
/* GZipArchive::open * Reads gzip format data from a MemChunk * Returns true if successful, false otherwise *******************************************************************/ bool GZipArchive::open(MemChunk& mc) { // Minimal metadata size is 18: 10 for header, 8 for footer size_t mds = 18; size_t size = mc.getSize(); if (mds > size) return false; // Read header uint8_t header[4]; mc.read(header, 4); // Check for GZip header; we'll only accept deflated gzip files // and reject any field using unknown flags if ((!(header[0] == GZIP_ID1 && header[1] == GZIP_ID2 && header[2] == GZIP_DEFLATE)) || (header[3] & GZIP_FLG_FUNKN)) return false; bool ftext, fhcrc, fxtra, fname, fcmnt; ftext = (header[3] & GZIP_FLG_FTEXT) ? true : false; fhcrc = (header[3] & GZIP_FLG_FHCRC) ? true : false; fxtra = (header[3] & GZIP_FLG_FXTRA) ? true : false; fname = (header[3] & GZIP_FLG_FNAME) ? true : false; fcmnt = (header[3] & GZIP_FLG_FCMNT) ? true : false; flags = header[3]; mc.read(&mtime, 4); mtime = wxUINT32_SWAP_ON_BE(mtime); mc.read(&xfl, 1); mc.read(&os, 1); // Skip extra fields which may be there if (fxtra) { uint16_t xlen; mc.read(&xlen, 2); xlen = wxUINT16_SWAP_ON_BE(xlen); mds += xlen + 2; if (mds > size) return false; mc.exportMemChunk(xtra, mc.currentPos(), xlen); mc.seek(xlen, SEEK_CUR); } // Skip past name, if any string name; if (fname) { char c; do { mc.read(&c, 1); if (c) name += c; ++mds; } while (c != 0 && size > mds); } else { // Build name from filename name = getFilename(false); wxFileName fn(name); if (!fn.GetExt().CmpNoCase("tgz")) fn.SetExt("tar"); else if (!fn.GetExt().CmpNoCase("gz")) fn.ClearExt(); name = fn.GetFullName(); } // Skip past comment if (fcmnt) { char c; do { mc.read(&c, 1); if (c) comment += c; ++mds; } while (c != 0 && size > mds); wxLogMessage("Archive %s says:\n %s", getFilename(true), comment); } // Skip past CRC 16 check if (fhcrc) { uint8_t* crcbuffer = new uint8_t[mc.currentPos()]; memcpy(crcbuffer, mc.getData(), mc.currentPos()); uint32_t fullcrc = Misc::crc(crcbuffer, mc.currentPos()); delete[] crcbuffer; uint16_t hcrc; mc.read(&hcrc, 2); hcrc = wxUINT16_SWAP_ON_BE(hcrc); mds += 2; if (hcrc != (fullcrc & 0x0000FFFF)) { wxLogMessage("CRC-16 mismatch for GZip header"); } } // Header is over if (mds > size || mc.currentPos() + 8 > size) return false; // Let's create the entry setMuted(true); ArchiveEntry* entry = new ArchiveEntry(name, size - mds); MemChunk xdata; if (Compression::GZipInflate(mc, xdata)) { entry->importMemChunk(xdata); } else { delete entry; setMuted(false); return false; } getRoot()->addEntry(entry); EntryType::detectEntryType(entry); entry->setState(0); setMuted(false); setModified(false); announce("opened"); // Finish return true; }
bool TreeView::searchLeafAndBuildTree(TreeView & tree2Build, const generic_string & text2Search, int index2Search) { //tree2Build.removeAllItems(); //HTREEITEM root = getRoot(); return searchLeafRecusivelyAndBuildTree(tree2Build.getRoot(), text2Search, index2Search, getRoot()); }
DisplayObject* DefineTextTag::createDisplayObject(Global_as& gl, DisplayObject* parent) const { return new StaticText(getRoot(gl), 0, this, parent); }
int getRoot(vector<int> & roots, int id) { return id == roots[id] ? id : roots[id] = getRoot(roots, roots[id]); }
void labelSegments(DARY *output, int &labels_nb){ int lab=50000; int *conn = new int[lab]; bzero(conn, sizeof(int)*lab); for(int j=1; j<lab; j++){ conn[j]=j; } lab=255; int p0,p1,p2,p3,p4,pmin; for(uint j=0; j<output->y(); j++){ output->fel[j][0]=0; output->fel[j][output->x()-1]=0; } for(uint j = 0; j<output->x(); j++){ output->fel[0][j]=0; output->fel[output->y()-1][j]=0; } for(uint j=1; j<output->y()-1; j++){ for(uint i=1; i<output->x()-1; i++){ if(output->fel[j][i]>0){ p0=output->fel[j][i]; p1=INT_MAX; p2=INT_MAX; p3=INT_MAX; p4=INT_MAX; if(output->fel[j][i-1] > 0){ p1=output->fel[j][i-1]; p1=getRoot(conn,p1); } if(output->fel[j-1][i-1]>0){ p2=output->fel[j-1][i-1]; p2=getRoot(conn,p2); } if(output->fel[j-1][i]>0){ p3=output->fel[j-1][i]; p3=getRoot(conn,p3); } if(output->fel[j-1][i+1]>0){ p4=output->fel[j-1][i+1]; p4=getRoot(conn,p4); } pmin=(p1<p2)?p1:p2; pmin=(pmin<p3)?pmin:p3; pmin=(pmin<p4)?pmin:p4; if(pmin==INT_MAX){ output->fel[j][i]=lab; lab++; } else { output->fel[j][i]=pmin; if(p1<INT_MAX){ conn[p1]=pmin; } if(p2<INT_MAX){ conn[p2]=pmin; } if(p3<INT_MAX){ conn[p3]=pmin; } if(p4<INT_MAX){ conn[p4]=pmin; } } } } } int *unique = new int[lab]; bzero(unique, sizeof(int)*lab); labels_nb=1; for(int j=255; j<lab; j++){ conn[j]=getRoot(conn,j); if(conn[j]==j){ unique[j]=labels_nb; labels_nb++; } } // int *uniquect = new int[labels_nb]; // bzero(uniquect,sizeof(int)*labels_nb); for(uint j=1; j<output->y()-1; j++){ for(uint i=1; i<output->x()-1; i++){ p0=output->fel[j][i]; if(p0>0){ output->fel[j][i]=unique[conn[p0]]; // uniquect[unique[conn[p0]]]++; } } } //for(int j=0; j<labels_nb; j++)cout << j << " count "<< uniquect[j]<< endl; delete []conn; delete []unique; // output->writePNG("labels.png"); // cout << "saved " << lab << endl;//getchar(); }
int getRoot(int x){ if(sets[x] < 0) return x; return sets[x] = getRoot(sets[x]); }
/*private*/ void Sound_as::startProbeTimer() { getRoot(owner()).addAdvanceCallback(this); }
void FileBrowserComponent::goUp() { setRoot (getRoot().getParentDirectory()); }
void Sound_as::attachCharacter(DisplayObject* attachTo) { _attachedCharacter.reset(new CharacterProxy(attachTo, getRoot(owner()))); }
int Component::idRoot() { return getRoot()->id; }
/*! Returns a QStorageInfo object that represents the system root volume. On Unix systems this call returns the root ('/') volume; in Windows the volume where the operating system is installed. \sa isRoot() */ QStorageInfo QStorageInfo::root() { return *getRoot(); }
void CMySourceParser::onDone() { LOGD("Source tree built {} assets", getRoot()->childCountRec()); _ctx._localMd5Queue.setDone(); _ctx._remoteMd5Queue.setDone(); }
void BasicScreenObject::addChild(BasicScreenObject* _child){ childlist.push_back(_child); _child->setParent(this); _child->setRoot(getRoot()); }
const typename O::ChildrenType& getRootChildren() const { return getRoot()->getChildren(); }
ofVec3f BasicScreenObject::getScreenPosition(){ Renderer* r = (Renderer*)getRoot(); ofVec3f screenpos = r->getCamera()->worldToScreen(getGlobalPosition()); screenpos.y=ofGetHeight()-screenpos.y; return screenpos; }
main(int argc, char *argv[]) { // variable declarations int here; int amountComplex, mRoot, nPower, form, i, j; double tempRealorMag, tempImagorPhase, userInput1, userInput2; complex secondnumber, atemp, stemp, mtemp, dtemp, ptemp, rtemp, ctemp; FILE *inputf; //Pointer to the input filepath FILE *outputf; //Pointer to the output filepath // check to see that there are 2 command line arguments for input-file // and output-file switch (argc) { case 2: fprintf(stderr,"Error: Please also provide an output filename\n"); return(1); case 3: break; // have input file and output file; all is OK default: fprintf(stderr,"Error: Please provide input and output filenames respectively as command line arguments\n"); return(1); } // make sure the input file opens if((inputf=fopen(argv[1],"r"))==NULL) { fprintf(stderr,"Error opening input file file. Check permissions.\n"); return(1); } // make sure the output file opens if((outputf=fopen(argv[2],"w"))==NULL) { fprintf(stderr,"Error opening output file. Check permissions.\n"); return(1); } // reading the first four numbers from the text file fscanf(inputf, "%d", &amountComplex); fscanf(inputf, "%d", &form); fscanf(inputf, "%d", &nPower); fscanf(inputf, "%d", &mRoot); if (form =! 1 || 0) { printf("Number must be in Cartesian or Polar format ONLY\n"); return(1); } if (amountComplex <= 0) { printf("Number of complex computations must be above zero.\n"); return (1); } complex myCarray[amountComplex]; // reads the numbers and puts them into an array; closes inputfile for (i = 0; i < amountComplex; i++) { fscanf(inputf, "%lf", &tempRealorMag); fscanf(inputf, "%lf", &tempImagorPhase); myCarray[i].real = tempRealorMag; myCarray[i].imaginary = tempImagorPhase; } fclose(inputf); if (form == 0) { printf("\nEnter real part of your number: "); scanf("%lf", &userInput1); printf("\nEnter imaginary part of your number: "); scanf("%lf", &userInput2); secondnumber.real = userInput1; secondnumber.imaginary = userInput2; } // polar format if (form == 1) { printf("\nEnter Magnitude of your number: "); scanf("%lf", &userInput1); printf("\nEnter Phase of your number: "); scanf("%lf", &userInput2); secondnumber.real = userInput1; secondnumber.imaginary = userInput2; } // cartesian format if(form == 0) { fprintf(outputf, "This will be in Cartesian format, the order of results are:\n"); fprintf(outputf, "Real part\n"); fprintf(outputf, "Imaginary part\n"); fprintf(outputf, "Magnitude\n"); fprintf(outputf, "Phase\n"); fprintf(outputf, "Power\n"); fprintf(outputf, "Root\n"); fprintf(outputf, "Conjugate\n"); fprintf(outputf, "Addition\n"); fprintf(outputf, "Subtraction\n"); fprintf(outputf, "Multiplication\n"); fprintf(outputf, "Division\n\n"); } // polar format if(form == 1) { fprintf(outputf, "This will be in Polar format, the order of results are:\n"); fprintf(outputf, "Real part\n"); fprintf(outputf, "Imaginary part\n"); fprintf(outputf, "Magnitude\n"); fprintf(outputf, "Phase\n"); fprintf(outputf, "Power\n"); fprintf(outputf, "Root\n"); fprintf(outputf, "Conjugate\n"); fprintf(outputf, "Addition\n"); fprintf(outputf, "Subtraction\n"); fprintf(outputf, "Multiplication\n"); fprintf(outputf, "Division\n\n"); } // number crunching part of code for(j = 0; j < amountComplex; j++) { // Real part, Imaginary part, Magnitude, Phase, Power, Root, // and Conjugate of complex number input array fprintf(outputf, "%lf\n", getReal(myCarray[j], form)); fprintf(outputf, "%lf\n", getImaginary(myCarray[j], form)); fprintf(outputf, "%lf\n", getMagnitude(myCarray[j], form)); fprintf(outputf, "%lf\n", getPhase(myCarray[j], form)); ptemp = getPower(nPower, myCarray[j], form); rtemp = getRoot(mRoot, myCarray[j], form); ctemp = getConjugate(myCarray[j]); fprintf(outputf, "%lf %lf \n", ptemp.real, ptemp.imaginary); fprintf(outputf, "%lf %lf \n", rtemp.real, rtemp.imaginary); fprintf(outputf, "%lf %lf \n", ctemp.real, ctemp.imaginary); // Addition, Subtraction, Multiplication, Division with Second Number entered by user atemp = add(myCarray[j], secondnumber, form); stemp = subtract(myCarray[j], secondnumber, form); mtemp = multiply(myCarray[j], secondnumber, form); dtemp = divide(myCarray[j], secondnumber, form); fprintf(outputf, "%lf %lf \n", atemp.real, atemp.imaginary); fprintf(outputf, "%lf %lf \n", stemp.real, stemp.imaginary); fprintf(outputf, "%lf %lf \n", mtemp.real, mtemp.imaginary); fprintf(outputf, "%lf %lf \n", dtemp.real, dtemp.imaginary); fprintf(outputf, "\n\tNext Complex Number"); } fclose(outputf); } //end of main function
Priority::Value Category::getRootPriority() throw() { return getRoot().getPriority(); }
void EntityModel::addPositionProperty() { Node& position_node = getRoot().addChild("position"); position_node.m_getter = [this]() -> QVariant { Lumix::Vec3 pos = getUniverse()->getPosition(m_entity); return QString("%1; %2; %3") .arg(pos.x, 0, 'f', 6) .arg(pos.y, 0, 'f', 6) .arg(pos.z, 0, 'f', 6); }; Node& x_node = position_node.addChild("x"); x_node.m_getter = [this]() -> QVariant { return getUniverse()->getPosition(m_entity).x; }; x_node.m_setter = [this](const QVariant& value) { setEntityPosition(0, value.toFloat()); }; Node& y_node = position_node.addChild("y"); y_node.m_getter = [this]() -> QVariant { return getUniverse()->getPosition(m_entity).y; }; y_node.m_setter = [this](const QVariant& value) { setEntityPosition(1, value.toFloat()); }; Node& z_node = position_node.addChild("z"); z_node.m_getter = [this]() -> QVariant { return getUniverse()->getPosition(m_entity).z; }; z_node.m_setter = [this](const QVariant& value) { setEntityPosition(2, value.toFloat()); }; Node& rotation_node = getRoot().addChild("rotation"); rotation_node.m_getter = [this]() -> QVariant { auto rot = getUniverse()->getRotation(m_entity).getAxisAngle(); return QString("[%1; %2; %3] %4") .arg(rot.axis.x, 0, 'f', 6) .arg(rot.axis.y, 0, 'f', 6) .arg(rot.axis.z, 0, 'f', 6) .arg(Lumix::Math::radiansToDegrees(rot.angle), 0, 'f', 6); }; { Node& x_node = rotation_node.addChild("x"); x_node.m_getter = [this]() -> QVariant { return getUniverse()->getRotation(m_entity).getAxisAngle().axis.x; }; x_node.m_setter = [this](const QVariant& value) { setEntityRotation(0, value.toFloat()); }; Node& y_node = rotation_node.addChild("y"); y_node.m_getter = [this]() -> QVariant { return getUniverse()->getRotation(m_entity).getAxisAngle().axis.y; }; y_node.m_setter = [this](const QVariant& value) { setEntityRotation(1, value.toFloat()); }; Node& z_node = rotation_node.addChild("z"); z_node.m_getter = [this]() -> QVariant { return getUniverse()->getRotation(m_entity).getAxisAngle().axis.z; }; z_node.m_setter = [this](const QVariant& value) { setEntityRotation(2, value.toFloat()); }; Node& angle_node = rotation_node.addChild("angle"); angle_node.m_getter = [this]() -> QVariant { return Lumix::Math::radiansToDegrees( getUniverse()->getRotation(m_entity).getAxisAngle().angle); }; angle_node.m_setter = [this](const QVariant& value) { setEntityRotation(3, Lumix::Math::degreesToRadians(value.toFloat())); }; DynamicObjectModel::setSliderEditor(angle_node, 0, 360, 5); } Node& scale_node = getRoot().addChild("scale"); scale_node.m_getter = [this]() -> QVariant { return getUniverse()->getScale(m_entity); }; scale_node.m_setter = [this](const QVariant& value) { setEntityScale(value.toFloat()); }; m_editor.getUniverse() ->entityTransformed() .bind<EntityModel, &EntityModel::onEntityPosition>(this); }
// solution2: divide & conquer // it is kind of filling water into the tree from the root node TreeNode* latestCommonAncestor(TreeNode* node1, TreeNode* node2){ if(node1 == NULL || node2 == NULL) return NULL; TreeNode* root = getRoot(node1); return getAncestor(root, node1, node2); }
void FocusInfoControl::notifyFrameStart(float _time) { if (getRoot()->getVisible()) updateFocusWidgetHelpers(); }
/* Wad2Archive::open * Reads wad format data from a MemChunk * Returns true if successful, false otherwise *******************************************************************/ bool Wad2Archive::open(MemChunk& mc) { // Check data was given if (!mc.hasData()) return false; // Read wad header uint32_t num_lumps = 0; uint32_t dir_offset = 0; char wad_type[4] = ""; mc.seek(0, SEEK_SET); mc.read(&wad_type, 4); // Wad type mc.read(&num_lumps, 4); // No. of lumps in wad mc.read(&dir_offset, 4); // Offset to directory // Byteswap values for big endian if needed num_lumps = wxINT32_SWAP_ON_BE(num_lumps); dir_offset = wxINT32_SWAP_ON_BE(dir_offset); // Check the header if (wad_type[0] != 'W' || wad_type[1] != 'A' || wad_type[2] != 'D' || (wad_type[3] != '2' && wad_type[3] != '3')) { LOG_MESSAGE(1, "Wad2Archive::open: Invalid header"); Global::error = "Invalid wad2 header"; return false; } if (wad_type[3] == '3') wad3 = true; // Stop announcements (don't want to be announcing modification due to entries being added etc) setMuted(true); // Read the directory mc.seek(dir_offset, SEEK_SET); UI::setSplashProgressMessage("Reading wad archive data"); for (uint32_t d = 0; d < num_lumps; d++) { // Update splash window progress UI::setSplashProgress(((float)d / (float)num_lumps)); // Read lump info wad2entry_t info; mc.read(&info, 32); // Byteswap values for big endian if needed info.offset = wxINT32_SWAP_ON_BE(info.offset); info.size = wxINT32_SWAP_ON_BE(info.size); info.dsize = wxINT32_SWAP_ON_BE(info.dsize); // If the lump data goes past the end of the file, // the wadfile is invalid if ((unsigned)(info.offset + info.dsize) > mc.getSize()) { LOG_MESSAGE(1, "Wad2Archive::open: Wad2 archive is invalid or corrupt"); Global::error = "Archive is invalid and/or corrupt"; setMuted(false); return false; } // Create & setup lump ArchiveEntry* nlump = new ArchiveEntry(wxString::FromAscii(info.name, 16), info.dsize); nlump->setLoaded(false); nlump->exProp("Offset") = (int)info.offset; nlump->exProp("W2Type") = info.type; nlump->exProp("W2Size") = (int)info.size; nlump->exProp("W2Comp") = !!(info.cmprs); nlump->setState(0); // Add to entry list getRoot()->addEntry(nlump); } // Detect all entry types MemChunk edata; UI::setSplashProgressMessage("Detecting entry types"); for (size_t a = 0; a < numEntries(); a++) { // Update splash window progress UI::setSplashProgress((((float)a / (float)num_lumps))); // Get entry ArchiveEntry* entry = getEntry(a); // Read entry data if it isn't zero-sized if (entry->getSize() > 0) { // Read the entry data mc.exportMemChunk(edata, (int)entry->exProp("Offset"), entry->getSize()); entry->importMemChunk(edata); } // Detect entry type EntryType::detectEntryType(entry); // Unload entry data if needed if (!archive_load_data) entry->unloadData(); // Set entry to unchanged entry->setState(0); } // Detect maps (will detect map entry types) UI::setSplashProgressMessage("Detecting maps"); detectMaps(); // Setup variables setMuted(false); setModified(false); announce("opened"); UI::setSplashProgressMessage(""); return true; }
bool QNodeTreeView::getBranchRecursion(const FieldContainerPtr &pFromFC, BranchType &branch ) { if(pFromFC == NullFC) { return false; } else if(pFromFC == getRoot()) { return true; } else { branch.push_front(pFromFC); Field *pParentsField = getParentsField(pFromFC, getAspect()); if(!pParentsField) { return false; } if(pParentsField->getCardinality() == FieldType::SINGLE_FIELD) { SFFieldContainerPtr *pSFParent = reinterpret_cast<SFFieldContainerPtr *>(pParentsField); if(getBranchRecursion(pSFParent->getValue(), branch)) { return true; } else { branch.pop_front(); return false; } } else { MFFieldContainerPtr *pMFParent = reinterpret_cast<MFFieldContainerPtr *>(pParentsField); MFFieldContainerPtr::iterator mfIter = pMFParent->begin(); MFFieldContainerPtr::iterator mfEnd = pMFParent->end(); for(; mfIter != mfEnd; ++mfIter) { if(getBranchRecursion(*mfIter, branch)) { return true; } else { branch.pop_front(); } } } } return false; }