void Envelope::testMe() { double t0=0, t1=0; SetInterpolateDB(false); Mirror(false); Flatten(0.5); checkResult( 1, Integral(0.0,100.0), 50); checkResult( 2, Integral(-10.0,10.0), 10); Flatten(0.5); checkResult( 3, Integral(0.0,100.0), 50); checkResult( 4, Integral(-10.0,10.0), 10); checkResult( 5, Integral(-20.0,-10.0), 5); Flatten(0.5); Insert( 5.0, 0.5 ); checkResult( 6, Integral(0.0,100.0), 50); checkResult( 7, Integral(-10.0,10.0), 10); Flatten(0.0); Insert( 0.0, 0.0 ); Insert( 5.0, 1.0 ); Insert( 10.0, 0.0 ); t0 = 10.0 - .1; t1 = 10.0 + .1; double result = Integral(0.0,t1); double resulta = Integral(0.0,t0); double resultb = Integral(t0,t1); // Integrals should be additive checkResult( 8, result - resulta - resultb, 0); Flatten(0.0); Insert( 0.0, 0.0 ); Insert( 5.0, 1.0 ); Insert( 10.0, 0.0 ); t0 = 10.0 - .1; t1 = 10.0 + .1; checkResult( 9, Integral(0.0,t1), 5); checkResult( 10, Integral(0.0,t0), 4.999); checkResult( 11, Integral(t0,t1), .001); WX_CLEAR_ARRAY(mEnv); Insert( 0.0, 0.0 ); Insert( 5.0, 1.0 ); Insert( 10.0, 0.0 ); checkResult( 12, NumberOfPointsAfter( -1 ), 3 ); checkResult( 13, NumberOfPointsAfter( 0 ), 2 ); checkResult( 14, NumberOfPointsAfter( 1 ), 2 ); checkResult( 15, NumberOfPointsAfter( 5 ), 1 ); checkResult( 16, NumberOfPointsAfter( 7 ), 1 ); checkResult( 17, NumberOfPointsAfter( 10 ), 0 ); checkResult( 18, NextPointAfter( 0 ), 5 ); checkResult( 19, NextPointAfter( 5 ), 10 ); }
size_t DisplayTags(FILE *fp, Tag *tagList) { size_t len = 0; if(tagList) { Tag *tag; len += fprintf(fp, "["); for(tag = tagList; tag; tag = tag->link) { len += fprintf(fp, "%s", Parser::inenglish(tag->tok)); if(tag->expr) { len += fprintf(fp, "("); len += Flatten(fp, tag->expr); len += fprintf(fp, ")"); } if(tag->link) len += fprintf(fp, ", "); } len += fprintf(fp, "]"); } return len; }
// // TPreferences::~TPreferences // // Write the preferences to disk. // TPreferences::~TPreferences() { BFile file; if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE) == B_OK) { Flatten(&file); } }
status_t DefaultCatalog::WriteToResource(const entry_ref &appOrAddOnRef) { BFile file; status_t res = file.SetTo(&appOrAddOnRef, B_READ_WRITE); if (res != B_OK) return res; BResources rsrc; res = rsrc.SetTo(&file); if (res != B_OK) return res; BMallocIO mallocIO; mallocIO.SetBlockSize(max(fCatMap.Size() * 20, (int32)256)); // set a largish block-size in order to avoid reallocs res = Flatten(&mallocIO); int mangledLanguage = CatKey::HashFun(fLanguageName.String(), 0); if (res == B_OK) { res = rsrc.AddResource('CADA', mangledLanguage, mallocIO.Buffer(), mallocIO.BufferLength(), BString(fLanguageName)); } return res; }
status_t DefaultCatalog::WriteToFile(const char *path) { BFile catalogFile; if (path) fPath = path; status_t res = catalogFile.SetTo(fPath.String(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); if (res != B_OK) return res; BMallocIO mallocIO; mallocIO.SetBlockSize(max(fCatMap.Size() * 20, (int32)256)); // set a largish block-size in order to avoid reallocs res = Flatten(&mallocIO); if (res == B_OK) { ssize_t wsz; wsz = catalogFile.Write(mallocIO.Buffer(), mallocIO.BufferLength()); if (wsz != (ssize_t)mallocIO.BufferLength()) return B_FILE_ERROR; // set mimetype-, language- and signature-attributes: UpdateAttributes(catalogFile); } if (res == B_OK) UpdateAttributes(catalogFile); return res; }
BVH::BVH(ObjMesh& _mesh) { mesh = _mesh; //build work list workList.reserve(mesh.faces.size()); for(auto i = 0; i < mesh.faces.size(); ++i) workList.push_back(BVHPrimitiveInfo(i, BBox(mesh.vertices[mesh.faces[i].x], mesh.vertices[mesh.faces[i].y], mesh.vertices[mesh.faces[i].z]))); //recursive build std::cout<<"Building BVH..."<<std::endl; orderedPrims.reserve(mesh.faces.size()); root = RecursiveBuild(0, workList.size()); std::cout<<"Totoal nodes: "<<totalNodes<<std::endl; std::cout<<"Max depth: "<<maxDepth<<std::endl; //replace mesh faces order with ordered one mesh.faces.swap(orderedPrims); //build linear bvh lbvh.reserve(totalNodes); for(auto i = 0; i < totalNodes; ++i) lbvh.push_back(LBVHNode()); uint32_t offset = 0; Flatten(root, &offset); std::cout<<"Root max: ("<<lbvh[0].bMax.x<<", "<<lbvh[0].bMax.y<<", "<<lbvh[0].bMax.z<<")"<<std::endl; std::cout<<"Root min: ("<<lbvh[0].bMin.x<<", "<<lbvh[0].bMin.y<<", "<<lbvh[0].bMin.z<<")"<<std::endl; }
bool ExprTree:: Flatten( Value& val, ExprTree *&tree ) const { EvalState state; state.SetScopes( parentScope ); return( Flatten( state, val, tree ) ); }
Map RasterMapData2( MapData& md ) { Map map(md.config.map_width, md.config.map_height); Fill( map, Map::BLOCK_SOLID ); RasterRooms( md.rooms, map ); RasterPaths( md.rooms, map ); return Decorate(Flatten(map)); }
status_t BContactField::Flatten(void* buffer, ssize_t size) const { if (buffer == NULL) return B_BAD_VALUE; BMemoryIO flatData(buffer, size); return Flatten(&flatData, size); }
void Preferences::WriteSettings () { /* Serialize contents of "prefs" to a file on disk */ RemoveName ("presetVerifyCode"); AddFloat ("presetVerifyCode", PresetVerifyCode); BFile file (prefsPath.Path(), B_CREATE_FILE | B_WRITE_ONLY); Flatten (&file); }
bool PSettings::Save(const char *file) { BFile out; if(out.SetTo(file,B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE)!=B_OK)return false; if(Flatten(&out)!=B_OK)return false;; out.Unset(); return true; }
int32_t HTTPFormatter::Length(void) { if (fDirty) { Flatten(); } return fFlattened.size(); }
TreeNode * Flatten(TreeNode *r){ if(r==NULL) return NULL; if(r->left==NULL && r->right==NULL) return r; TreeNode * rr = r->right; TreeNode * ll; if(r->left!=NULL){ r->right=r->left; r->left=NULL; ll = Flatten(r->right); if(ll!=NULL) ll->right = rr; if(rr==NULL) return ll; else return Flatten(rr); }else{ return Flatten(r->right); } }
void Flatten(TreeNode *root) { if( root != NULL) { Flatten(root->left); Flatten(root->right); TreeNode * p = root; if( p->left != NULL) { p = p->left; while(p->right) p = p->right; p->right = root->right; root->right = root->left; root->left = NULL; } } }
uint32_t BVH::Flatten(BVHNode *node, uint32_t* offset) { LBVHNode* linearNode = &lbvh[*offset]; linearNode->bMax = node->bounds.bmax; linearNode->bMin = node->bounds.bmin; uint32_t myOffset = (*offset)++; if(node->nPrims > 0) { linearNode->primitiveOffset = node->firstPrimOffset; linearNode->nPrimitives = node->nPrims; } else { linearNode->nPrimitives = 0; Flatten(node->left, offset); linearNode->rightChildOffset = Flatten(node->right, offset); } return myOffset; }
TreeNode * Flatten(TreeNode *root) { if (root == NULL) return NULL; TreeNode * left = Flatten(root->left); TreeNode * right = Flatten(root->right); if (root->left) { left->right = root->right; root->right = root->left; } root->left = NULL; if (right != NULL) return right; else if (left != NULL) return left; else return root; }
void P2PContents::Debug(void) { char *buff = Flatten(); int32 len = FlattenedLength(); for (int32 i = 0; i < len; i++) { if ((buff[i] == '\n') || (buff[i] == '\r')) printf("%c", buff[i]); else if ((buff[i] < 0x20) || (buff[i] > 0x7e)) printf("0x%x", (unsigned char)buff[i]); else printf("%c", buff[i]); }; };
/*! \brief Saves the data in the cursor set to a file \param path Path of the file to save to. \param saveflags BFile open file flags. B_READ_WRITE is implied. \return - \c B_OK: Everything went fine. - \c B_BAD_VALUE: path is NULL - \c other value: See BFile::SetTo and BMessage::Flatten return codes */ status_t CursorSet::Save(const char *path, int32 saveFlags) { if (!path) return B_BAD_VALUE; BFile file; status_t status = file.SetTo(path, B_READ_WRITE | saveFlags); if (status != B_OK) return status; return Flatten(&file); }
bool HandleAttributes(var &result, Var expression, const attr_t &attributes, var head, var &body) { if(attributes.count(SequenceHold)) { body = Body(expression); } else { body = FlattenSequence(Body(expression), false); } size_t n = Size(body); // FIXME: in mathematica, OneIdentity means "x == f[x]" only for PATTERN MATCHING purposes // if(n == 1 && attributes.count(OneIdentity)) // { // result = Eval(At(body,0)); // return true; // } if(!attributes.count(HoldAll)) { if(n > 0 && !attributes.count(HoldFirst)) At(body,0) = Eval(At(body,0)); if(n > 1 && !attributes.count(HoldRest)) for(size_t i = 1; i < n; ++i) At(body,i) = Eval(At(body,i)); } if(attributes.count(Listable)) { // TODO: handle the case where all list must be of same length, e.g. CoprimeQ var t = Thread(head,body); if(t) { result = Eval(t); return true; } } if(attributes.count(Flat)) { var t = body; body = Vec(); Reserve(body,n); Flatten(body,head,t); } if(attributes.count(Orderless)) Sort(body); return false; }
status_t SettingsFile::Save() const { status_t ret; BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); ret = file.InitCheck(); if (ret != B_OK) { // try to create the parent directory if creating the file fails the first time BPath parent; ret = path.GetParent(&parent); if (ret != B_OK) { return ret; } ret = create_directory(parent.Path(), 0777); if (ret != B_OK) { return ret; } ret = file.SetTo(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); } if (ret != B_OK) { return ret; } ret = file.Lock(); // lock the file to do atomic attribute transactions on it. if (ret != B_OK) { return ret; } if (vision_app->fDebugSettings) PrintToStream(); ret = Flatten(&file); if (ret != B_OK) { file.Unlock(); return ret; } /* ret=_StoreAttributes(this,&file); if (ret!=B_OK) { file.Unlock(); return ret; } */ file.Unlock(); return B_OK; }
// Generate the Hills // ---------------------------------------------------------------------------- void generateHillTerrain(FuncParam* param) { m_pMap = param->heightMap; m_uXSize = param->xsize ; m_uZSize = param->zsize ; m_uSeed = param->seed; m_uHeightScale = param->scale; // check the parameters assert( m_uXSize > 0 ); assert( m_uZSize > 0 ); assert( m_uSeed != 0 ); assert(m_pMap != NULL); if(!m_uSeed) m_uSeed=1; m_fHillMin = 2.0f ; m_fHillMax = 40.0f ; m_uNumHills = 200; m_uFlattening = 1 ; m_bIsland = false; m_uZSize++ ; m_uXSize++; Clear(); // set the seed srand( m_uSeed ); // add as many hills as needed for( int i = 0; i < m_uNumHills; ++i ) { AddHill(); } // now clean it up Normalize(); Flatten(); }
Preferences::~Preferences() { if (fSavePreferences) { BFile file; status_t set = B_ERROR; if (fSettingsFile) file.SetTo(fSettingsFile, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); else { BPath prefpath; if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath, true) == B_OK) { BDirectory prefdir(prefpath.Path()); set = prefdir.CreateFile(fName, &file, false); } } if (file.InitCheck () == B_OK) { Flatten(&file); if (fSignature) { file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0, fSignature, strlen(fSignature) + 1); } } else { // implement saving somewhere else! BString error; snprintf(error.LockBuffer(256), 256, B_TRANSLATE("Your setting file could not be saved!\n(%s)"), strerror(file.InitCheck())); error.UnlockBuffer(); BAlert *alert = new BAlert(B_TRANSLATE("Error saving file"), error.String(), B_TRANSLATE("Damned!"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->SetShortcut(0, B_ESCAPE); alert->Go(); } } delete fSettingsFile; free(fName); free(fSignature); }
/* * this method is not currently being used, but it may be useful in the * future... */ status_t DefaultCatalog::WriteToAttribute(const entry_ref &appOrAddOnRef) { BNode node; status_t res = node.SetTo(&appOrAddOnRef); if (res != B_OK) return res; BMallocIO mallocIO; mallocIO.SetBlockSize(max(fCatMap.Size() * 20, (int32)256)); // set a largish block-size in order to avoid reallocs res = Flatten(&mallocIO); if (res == B_OK) { ssize_t wsz; wsz = node.WriteAttr(BLocaleRoster::kEmbeddedCatAttr, B_MESSAGE_TYPE, 0, mallocIO.Buffer(), mallocIO.BufferLength()); if (wsz < B_OK) res = wsz; else if (wsz != (ssize_t)mallocIO.BufferLength()) res = B_ERROR; } return res; }
/* ********************************************************************** */ void States (const State_1D *state, int beg, int end, Grid *grid) /*! * * \param [in] state pointer to State_1D structure * \param [in] beg initial index of computation * \param [in] end final index of computation * \param [in] grid pointer to an array of Grid structures * ************************************************************************ */ { int i, nv; double dv, **v; double dvp, cp, *wp, *hp, **vp; double dvm, cm, *wm, *hm, **vm; PPM_Coeffs ppm_coeffs; PLM_Coeffs plm_coeffs; /* --------------------------------------------------------- 1. Set pointers, compute geometrical coefficients --------------------------------------------------------- */ v = state->v; vm = state->vm; vp = state->vp; PPM_CoefficientsGet(&ppm_coeffs, g_dir); #if SHOCK_FLATTENING == MULTID PLM_CoefficientsGet(&plm_coeffs, g_dir); #endif hp = ppm_coeffs.hp; hm = ppm_coeffs.hm; /* --------------------------------------------------------- 2. Define unlimited left and right interface values and make sure they lie between adjacent cell averages. --------------------------------------------------------- */ #if PPM_VERSION == PPM3 || PPM_VERSION == PPM5 for (i = beg; i <= end; i++) { wp = ppm_coeffs.wp[i]; wm = ppm_coeffs.wm[i]; VAR_LOOP(nv){ #if PPM_VERSION == PPM3 vp[i][nv] = wp[-1]*v[i-1][nv] + wp[0]*v[i][nv] + wp[1]*v[i+1][nv]; vm[i][nv] = wm[-1]*v[i-1][nv] + wm[0]*v[i][nv] + wm[1]*v[i+1][nv]; #elif PPM_VERSION == PPM5 vp[i][nv] = wp[-2]*v[i-2][nv] + wp[-1]*v[i-1][nv] + wp[ 0]*v[i][nv] + wp[ 1]*v[i+1][nv] + wp[ 2]*v[i+2][nv]; vm[i][nv] = wm[-2]*v[i-2][nv] + wm[-1]*v[i-1][nv] + wm[0]*v[i][nv] + wm[ 1]*v[i+1][nv] + wm[ 2]*v[i+2][nv]; #endif dvp = vp[i][nv] - v[i][nv]; dvm = vm[i][nv] - v[i][nv]; dv = v[i+1][nv] - v[i][nv]; vp[i][nv] = v[i][nv] + MINMOD(dvp, dv); dv = v[i][nv] - v[i-1][nv]; vm[i][nv] = v[i][nv] + MINMOD(dvm, -dv); } } #elif PPM_VERSION == PPM4 /* -- set a unique interface value -- */ for (i = beg-1; i <= end; i++) { wp = ppm_coeffs.wp[i]; VAR_LOOP(nv){ vp[i][nv] = wp[-1]*v[i-1][nv] + wp[0]*v[i][nv] + wp[ 1]*v[i+1][nv] + wp[2]*v[i+2][nv]; dv = v[i+1][nv] - v[i][nv]; dvp = vp[i][nv] - v[i][nv]; vp[i][nv] = v[i][nv] + MINMOD(dvp, dv); } } for (i = beg; i <= end; i++) VAR_LOOP(nv) vm[i][nv] = vp[i-1][nv]; #endif /* --------------------------------------------------------- 3. Apply parabolic limiter: no new extrema should appear in the parabola defined by vp, vm and v. --------------------------------------------------------- */ for (i = beg; i <= end; i++) { #if SHOCK_FLATTENING == MULTID if (CheckZone (i, FLAG_MINMOD)) { wp = plm_coeffs.wp; wm = plm_coeffs.wm; VAR_LOOP(nv) { dvp = (v[i+1][nv] - v[i][nv])*wp[i]; dvm = (v[i][nv] - v[i-1][nv])*wm[i]; dv = MINMOD(dvp, dvm); vp[i][nv] = v[i][nv] + dv*plm_coeffs.dp[i]; vm[i][nv] = v[i][nv] - dv*plm_coeffs.dm[i]; } #if PHYSICS == RHD || PHYSICS == RMHD VelocityLimiter (v[i], vp[i], vm[i]); #endif continue; } #endif #if PPM_VERSION == PPM0 cm = cp = 2.0; #else cm = (hm[i] + 1.0)/(hp[i] - 1.0); cp = (hp[i] + 1.0)/(hm[i] - 1.0); #endif for (nv = 0; nv < NVAR; nv++){ dvp = vp[i][nv] - v[i][nv]; dvm = vm[i][nv] - v[i][nv]; if (dvp*dvm >= 0.0) dvp = dvm = 0.0; else{ if (fabs(dvp) >= cm*fabs(dvm)) dvp = -cm*dvm; else if (fabs(dvm) >= cp*fabs(dvp)) dvm = -cp*dvp; } vp[i][nv] = v[i][nv] + dvp; vm[i][nv] = v[i][nv] + dvm; } #if PHYSICS == RHD || PHYSICS == RMHD VelocityLimiter (v[i], vp[i], vm[i]); #endif } /* -------------------------------------------------------- 1D shock flattening -------------------------------------------------------- */ #if SHOCK_FLATTENING == YES Flatten (state, beg, end, grid); #endif /* ------------------------------------------- Assign face-centered magnetic field ------------------------------------------- */ #ifdef STAGGERED_MHD for (i = beg-1; i <= end; i++) { state->vR[i][BXn] = state->vL[i][BXn] = state->bn[i]; } #endif #if TIME_STEPPING == CHARACTERISTIC_TRACING CharTracingStep(state, beg, end, grid); #endif /* ------------------------------------------- compute states in conservative variables ------------------------------------------- */ PrimToCons (state->vp, state->up, beg, end); PrimToCons (state->vm, state->um, beg, end); }
void SODL::WriteSODL(INXString sodlfile) { ofstream datafile(sodlfile); ConData *blob; INXPOSITION pos; INXString funcName; int funcArg = -1; int startFunc = 0; UINT i; UINT j; UINT funcInPortNum = 0, funcOutPortNum = 0, funcFinPortNum = 0; // *** lineID is an array of unsigned ints. However, it needs to store the value -1 if // a port is not connected. Could use a CArray of type int, but this gives a smaller range // of line IDs than using a CUIntArray. Using such an array means -1 is stored as 4294967295. // This value should never be reached. INXObjArray<unsigned int> lineType; CArray<long,long> lineID; vector<Group> vGroups; TagProjMetaSupportData_t tagData; INXString csTargetFileName = "", csMessage = ""; if (!datafile.good()) { AfxMessageBox("File could not be written"); } //AfxMessageBox( "Get ready to call Copy2Flattened" ); // Flatten encapsulated blocks Copy2Flattened(); //AfxMessageBox( "Get ready to call Flatten" ); Flatten(); //SaveProg2("tmp.prg"); // 1. Assign a unique incremental integer (within its data type) to each line //AfxMessageBox( "Get ready to call AssignLineIDNum" ); AssignLineIDNum(); // First write the number of groups to the sodl file. // Turn off scheduling //datafile << 0 << endl; //AfxMessageBox( "Get ready to call generate SODL proper" ); //@todo - add the following datafile << "hashmark" << Project << endl; /************* The following is where everything is written out. This should be a new function *******************/ // Write out the parameters for each group WriteVersionInformation(&datafile); /************ Now add the group data **********************/ pProject->pProjMData->getGroupVec(vGroups); datafile << vGroups.size() << endl; for (i=0; i<vGroups.size(); i++) { datafile << vGroups.at(i).ID << '\t'; datafile << vGroups.at(i).Period << '\t'; datafile << vGroups.at(i).Alloc << endl; } /***** Now add the programme body *******************/ // 2. For each icon pos = flattened->GetHeadPosition(); while(pos) { blob = (ConData *) (flattened->GetNext(pos)); // check that a startport is connected or an internalport exists or it is the new style constant without a startport bool writeObject = FALSE; for (i=0; i<blob->startport_num; i++) { if (blob->startport[i]->line.exist || blob->startport[i]->initialise) { writeObject = true; } } if (blob->internalport_num > 0) { writeObject = true; } if (writeObject) { // 3. Write the tag and class name. datafile << "BEGIN "; datafile << (CString)blob->className << endl; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // Write the parameter string. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (blob->iParamNum == 1) { datafile << NOPARAMS; } else { for (i=1; i<blob->iParamNum; i++) { // if the parameter is an empty string and there is only 1 parameter // then write out "" else write out "NULL" if (blob->iconParam[i]->value == "_") { if (blob->iParamNum == 2) { datafile << "" << " "; } else { datafile << "NULL" << " "; } } // for string constants don't append a space else if (blob->m_csIconType == "const_s") { datafile << (CString)blob->iconParam[i]->value; } // for gui components prepend %%%_ else if (i==1 && (blob->isGuiWidget())) { datafile << "%%%_" << (CString)blob->iconParam[i]->value << " "; } // for screen tags write out the target filename else if (blob->iconParam[i]->dataType == 4) { LucidErrEnum err = pProject->pProjMData->getScreenTagMetas((CString &)blob->iconParam[i]->value, tagData); assert (err == kErr_NoErr); datafile << (CString)tagData.tgtFilename << " "; } // write out target filename for data files else if (blob->m_csIconType.Find("file_ro") != -1 && blob->iconParam[i]->name == "File name") { if (pProject->pProjMData->getTargetFileNameForDataHostFileName(blob->iconParam[i]->value, csTargetFileName)) { csMessage.Format("File \"%s\" does not exist in the project. Your application may not work as expected.", blob->iconParam[i]->value); // Don't display message because IPlayer demo runs a script which relies on host filenames //AfxMessageBox(csMessage); datafile << (CString)blob->iconParam[i]->value << " "; } else { datafile << (CString)csTargetFileName << " "; } } else { datafile << (CString)blob->iconParam[i]->value << " "; } } } // (blob->iParamNum != 1) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // <ENDOF> Write the parameter string. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! datafile << endl; // 5. Write the tag to begin listing functions // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // For each start trigger port // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! for (i=0; i<blob->startport_num; i++) { funcInPortNum = 0; funcOutPortNum = 0, funcFinPortNum = 0; // if the start port is initialised SODL requires a start function if (blob->startport[i]->initialise) { startFunc = 1; } // if the start port is connected or initialised if (blob->startport[i]->line.exist || blob->startport[i]->initialise) { // 7.1 Write its function name. Is there only 1 function? funcName = blob->startport[i]->funcName->GetAt(0); datafile << (CString)funcName << '\t'; // Write out atomic flag //datafile << blob->startport[i]->atomicFlag << '\t'; datafile << 1 << '\t'; // Write out group ID for start port datafile << blob->startport[i]->groupID << '\t'; // Write out start trigger line ID datafile << blob->startport[i]->line.idNum << '\t'; // 7.2 Search through all other ports to find any other references // to the function name lineID.RemoveAll(); lineType.RemoveAll(); for (j=0; j<blob->inputport_num; j++) { for (int k=0; k<blob->inputport[j]->funcName->GetSize(); k++) { if (blob->inputport[j]->funcName->GetAt(k) == funcName) { funcInPortNum++; funcArg = blob->inputport[j]->funcArg->GetAt(k); //store the line id and type in a temp. array // check if a line is connected if (blob->inputport[j]->line.exist) { lineID.SetAtGrow(funcArg, blob->inputport[j]->line.idNum); } else { lineID.SetAtGrow(funcArg, -1); } lineType.SetAtGrow(funcArg, blob->inputport[j]->datatype); } } } // write out inputs datafile << funcInPortNum << " "; for (j=1; j<=funcInPortNum; j++) { datafile << convert.DataType2Char(lineType.GetAt(j)) << " "; // Originally wrote out a * for uncoonected ports. Now writes out -1. /*if (lineID.GetAt(j) == -1) { datafile << "* "; } else {*/ datafile << lineID.GetAt(j) << " "; //} } for (j=0; j<blob->outputport_num; j++) { for (int k=0; k<blob->outputport[j]->funcName->GetSize(); k++) { if (blob->outputport[j]->funcName->GetAt(k) == funcName) { funcOutPortNum++; funcArg = blob->outputport[j]->funcArg->GetAt(k); //store the line id and type in a temp. array // check if a line is connected if (blob->outputport[j]->lineID > -1) { lineID.SetAtGrow(funcArg, blob->outputport[j]->lineID); } else { lineID.SetAtGrow(funcArg, -1); } lineType.SetAtGrow(funcArg, blob->outputport[j]->datatype); } } } // write out outputs datafile << '\t' << funcOutPortNum << " "; for (j=(funcInPortNum + 1); j<=(funcInPortNum + funcOutPortNum); j++) { datafile << convert.DataType2Char(lineType.GetAt(j)) << " "; datafile << lineID.GetAt(j) << " "; } for (j=0; j<blob->finishport_num; j++) { for (int k=0; k<blob->finishport[j]->funcName->GetSize(); k++) { if (blob->finishport[j]->funcName->GetAt(k) == funcName) { funcFinPortNum++; funcArg = blob->finishport[j]->funcArg->GetAt(k); //store the line id and type in a temp. array // check if a line is connected if (blob->finishport[j]->lineID > -1) { lineID.SetAtGrow(funcArg, blob->finishport[j]->lineID); } else { lineID.SetAtGrow(funcArg, -1); } } } } // write out finish ports datafile << '\t' << funcFinPortNum << " "; // Only write out the finish line numbers if there is at least one connection if (funcFinPortNum > 0) { for (int m=(funcInPortNum + funcOutPortNum + 1); m<lineID.GetSize(); m++) { datafile << lineID.GetAt(m) << " "; } } datafile << endl; } } // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // <ENDOF> For each start trigger port // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // For each internal trigger port // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! for (i=0; i<blob->internalport_num; i++) { funcInPortNum = 0; funcOutPortNum = 0, funcFinPortNum = 0; // ***REVISIT. Write its function name. Is there only 1 function? funcName = blob->internalport[i]->funcName->GetAt(0); datafile << (CString)funcName << '\t'; // Write out atomic flag //datafile << blob->internalport[i]->atomicFlag << '\t'; datafile << 1 << '\t'; // Write out group ID for internal port datafile << blob->internalport[i]->groupID << '\t'; // The internal trigger does not have a line ID so write out 0 if it is the // Start function and -1 otherwise. if (funcName == START) { datafile << 0 << '\t'; } else { datafile << -1 << '\t'; } // 7.2 Search through all other ports to find any other references // to the function name lineID.RemoveAll(); lineType.RemoveAll(); for (j=0; j<blob->inputport_num; j++) { for (int k=0; k<blob->inputport[j]->funcName->GetSize(); k++) { if (blob->inputport[j]->funcName->GetAt(k) == funcName) { funcInPortNum++; funcArg = blob->inputport[j]->funcArg->GetAt(k); //store the line id and type in a temp. array // check if a line is connected if (blob->inputport[j]->line.exist) { lineID.SetAtGrow(funcArg, blob->inputport[j]->line.idNum); } else { lineID.SetAtGrow(funcArg, -1); } lineType.SetAtGrow(funcArg, blob->inputport[j]->datatype); } } } // write out inputs datafile << funcInPortNum << " "; for (j=1; j<=funcInPortNum; j++) { datafile << convert.DataType2Char(lineType.GetAt(j)) << " "; datafile << lineID.GetAt(j) << " "; } for (j=0; j<blob->outputport_num; j++) { for (int k=0; k<blob->outputport[j]->funcName->GetSize(); k++) { if (blob->outputport[j]->funcName->GetAt(k) == funcName) { funcOutPortNum++; funcArg = blob->outputport[j]->funcArg->GetAt(k); //store the line id and type in a temp. array // check if a line is connected if (blob->outputport[j]->lineID > -1) { lineID.SetAtGrow(funcArg, blob->outputport[j]->lineID); } else { lineID.SetAtGrow(funcArg, -1); } lineType.SetAtGrow(funcArg, blob->outputport[j]->datatype); } } } // write out outputs datafile << '\t' << funcOutPortNum << " "; for (j=(funcInPortNum + 1); j<=(funcInPortNum + funcOutPortNum); j++) { int tmp = lineType.GetAt(j); datafile << convert.DataType2Char(lineType.GetAt(j)) << " "; datafile << lineID.GetAt(j) << " "; } for (j=0; j<blob->finishport_num; j++) { for (int k=0; k<blob->finishport[j]->funcName->GetSize(); k++) { if (blob->finishport[j]->funcName->GetAt(k) == funcName) { funcFinPortNum++; funcArg = blob->finishport[j]->funcArg->GetAt(k); //store the line id and type in a temp. array // check if a line is connected if (blob->finishport[j]->lineID > -1) { lineID.SetAtGrow(funcArg, blob->finishport[j]->lineID); } else { lineID.SetAtGrow(funcArg, -1); } } } } // write out finish ports datafile << '\t' << funcFinPortNum << " "; for (int m=(funcInPortNum + funcOutPortNum + 1); m<lineID.GetSize(); m++) { datafile << lineID.GetAt(m) << " "; } datafile << endl; } // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // <ENDOF> For each internal trigger port // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // 8. Write out end of icon tags datafile << "END" << endl; //datafile << endl; } //if (writeObject) } // Always Write out start function -- even if no other functions need initialising. //if (startFunc) { datafile << "BEGIN Start" << endl; datafile << "*" << endl; datafile << "Run_Start 1 1 0 0 0 1 1" << endl; datafile << "END" << endl; //} datafile.close(); }
int32 P2PContents::FlattenedLength(void) { if (fDirty) Flatten(); return fFlattened.BufferLength(); };
bool LevelHandler::Load(const char filePath[]) { for(int q=0; q<128; q++) { for(int w=0; w<128; w++) { f[q][w]=0; } } Flatten(1); for(int e=0; e<16; e++) { enemy[e][0]=64; enemy[e][1]=64; } if(filePath[0]!=NULL) { FILE *filein; int errnum; filein=fopen(filePath, "rt"); //Error checking if(!filein) { //Error Logging goes here. std::cerr << "LevelHandler: failed to open file:" << filePath << std::endl; errnum = errno; fprintf(stderr, "Value of errno: %d\n", errno); perror("Error printed by perror"); fprintf(stderr, "Error opening file: %s\n", strerror( errnum )); char path[1024]; uint32_t size = sizeof(path); if (_NSGetExecutablePath(path, &size) == 0) printf("executable path is %s\n", path); else printf("buffer too small; need size %u\n", size); return false; } else { //fileName=new char[Strlen(filePath)+1]; //fileName[Strlen(filePath)]='\n'; for(int k=Strlen(filePath); k>-1; k--) { fileName[k]=filePath[k]; } //These two lines get the map size //The last two characters in the file's name are the map's size. //Ex: //[email protected] //That means that sizeX=64 and sizeZ=48 //This is not yet implimented because we're using static arrays //sizeX=2*filePath[Strlen(filePath)-6]; //sizeZ=2*filePath[Strlen(filePath)-5]; sizeX=128; sizeZ=128; // TankHandler::GetSingleton().numberTanks=sizeX/16; /* t = new int*[sizeX]; //Recall that ap[i] is a pointer to an array of int's t[0]=new int[sizeX*sizeZ]; // This "connects" the array of pointers to the arrays of ints for (int m=1;m<sizeX;m++) { t[m]=t[m-1]+sizeZ; }*/ int cdepth=sizeZ; char* oneline = new char[cdepth]; //Storage per line //Get first line //fgets(oneline, cdepth, filein); for(int i=0; i<sizeX; i++) { //Get next line fgets(oneline, cdepth, filein); for(int j=0; j<sizeZ; j++) { t[i][j]=oneline[j]; if(t[i][j]==33) { start[0]=i; start[1]=j; t[i][j]=t[i-1][j]; } else if(t[i][j]>=48 && t[i][j]<58) { enemy[t[i][j]-48][0]=i; enemy[t[i][j]-48][1]=j; t[i][j]=t[i-1][j]; } else { t[i][j]=oneline[j]-100; if(t[i][j]==-1) { if(App::GetSingleton().gameTask->versus) { t[i][j]=10; } else { t[i][j]=-20; } } if(t[i][j]>26) t[i][j]=0; if(i==0 || i==(sizeX-1) || j==0 || j==(sizeZ-1)) t[i][j]=26; } } fgets(oneline, cdepth, filein); } delete [] oneline; fclose(filein); return true; } } levelNumber=fileName[5]; return false; }
void RequestParser::Test() { assert(ExtractMethod("GET / HTTP1.1") == GET); assert(ExtractMethod("HEAD / HTTP1.1") == HEAD); assert(ExtractMethod("POST / HTTP1.1") == POST); assert(ExtractMethod("Error / HTTP1.1") == UNKNOWN); assert(ExtractTarget("GET / HTTP1.1") == ""); assert(ExtractTarget("GET // HTTP1.1") == ""); assert(ExtractTarget("GET /// HTTP1.1") == ""); assert(ExtractTarget("GET /dir/file.txt HTTP1.1") == "dir/file.txt"); assert(ExtractTarget("GET /dir/file.txt?params HTTP1.1") == "dir/file.txt"); assert(ExtractTarget("GET /?params HTTP1.1") == ""); assert(ExtractTarget("GET //?params HTTP1.1") == ""); assert(Flatten(ExtractQueryParams("GET / HTTP1.1")) == ""); assert(Flatten(ExtractQueryParams("GET // HTTP1.1")) == ""); assert(Flatten(ExtractQueryParams("GET /// HTTP1.1")) == ""); assert(Flatten(ExtractQueryParams("GET /dir/file.txt HTTP1.1")) == ""); assert(Flatten(ExtractQueryParams("GET /dir/file.txt? HTTP1.1")) == ""); assert(Flatten(ExtractQueryParams("GET /dir/file.txt?params HTTP1.1")) == "params=''"); assert(Flatten(ExtractQueryParams("GET /dir/file.txt?param1¶m2¶m3 HTTP1.1")) == "param1='' param2='' param3=''"); assert(Flatten(ExtractQueryParams("GET /dir/file.txt?param1=val1¶m2=val2¶m3=val3 HTTP1.1")) == "param1='val1' param2='val2' param3='val3'"); assert(Flatten(ExtractQueryParams("GET /?params HTTP1.1")) == "params=''"); assert(Flatten(ExtractQueryParams("GET /? HTTP1.1")) == ""); assert(Flatten(ExtractQueryParams("GET //?params HTTP1.1")) == "params=''"); assert(TestRange(true, "Range: bytes=0-1024", 0, 1024)); assert(TestRange(false, "Range: time=0-1024", 0, 0)); assert(TestRange(true, "Range: bytes=0-", 0, -1)); assert(TestRange(true, "Range: bytes=1024-", 1024, -1)); assert(TestRange(true, "Range: bytes=232128512-", 232128512, -1)); }
void flatten(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function Flatten(root); }
void flatten(TreeNode *root) { Flatten(root); }