/* * Deal the stacks into separated files and append them. */ void dealStack(const fs::path &outdir, const std::string &prefix, const fs::path &imgPath, const uint16_t nLayer) { TIFF *in, *out; static uint16_t iLayer = 0; // Suppress the warnings. TIFFErrorHandler oldhandler = TIFFSetWarningHandler(NULL); // Open the file. in = TIFFOpen(imgPath.string().c_str(), "r"); if (in == NULL) { std::cerr << "Unable to read " << imgPath.filename() << std::endl; return; } // Identify the read mode. static char mode[3] = { 'x', 'b', 0 }; // Overwrite on the first run, and append for rest of the page. mode[0] = (mode[0] == 'x') ? 'w' : 'a'; mode[1] = (TIFFIsBigEndian(in)) ? 'b' : 'l'; // Iterate through the directories. int iFile = 0; do { std::string s = genPath(outdir, prefix, iFile); out = TIFFOpen(s.c_str(), mode); try { if (out == NULL) { throw -1; } else if (!cpTiff(in, out, iLayer, nLayer)) { throw -2; } } catch (int e) { if (e == -1) { std::cerr << "Unable to create output file" << std::endl; } else if (e == -2) { std::cerr << "Unable to copy the layer" << std::endl; } else { std::cerr << "Unknown error" << std::endl; } TIFFClose(in); TIFFClose(out); return; } TIFFClose(out); iFile++; } while (TIFFReadDirectory(in)); // Increment the layer variable for next write. iLayer++; TIFFClose(in); // Restore the warning. TIFFSetWarningHandler(oldhandler); }
void helper(TreeNode* root, vector<int>& path, vector<string>& result) { path.push_back(root->val); if (root->left == nullptr && root->right == nullptr) { result.push_back(genPath(path)); } if (root->left) helper(root->left, path, result); if (root->right) helper(root->right, path, result); path.pop_back(); }
void genPath(string &s, vector<vector<bool> > &prev, int curr, vector<string> &r, vector<string> &p) { if(curr==0) { string str; for(int i=p.size()-1;i>=0;--i) str+=(p[i]+" "); str.erase(str.size()-1, 1); r.push_back(str); } for(int i=0;i<curr;++i) { if(prev[curr][i]) { p.push_back(s.substr(i, curr-i)); genPath(s, prev, i, r, p); p.pop_back(); } } }
//-----% Generate The Level %------- int lvlGen (lvl *level){ int numRooms = rb(MIN_ROOMS,MAX_ROOMS); char temp; int showGen = 0; int x1,x2,y1,y2; room rooms[numRooms]; //Make the entire level solid for (int i = 0; i < MAX_H; i++){ for (int j = 0; j < MAX_W; j++){ level->nodeSet(i,j,'#'); } } printf("Do you want to be shown the generation process? y/n"); temp=getch(); if (temp == 'y') showGen = 1; while (!validLevel(level)){ for (int i = 0; i < MAX_H; i++){ for (int j = 0; j < MAX_W; j++){ level->nodeSet(i,j,'#'); } } for (int i = 0; i < numRooms; i++) { printf("Trynna make a new room\n"); if (addRoom(level, showGen, &rooms[i],0)){ x1 = (rooms[i].x1Get()+rooms[i].x2Get())/2; x2 = (rooms[i-1].x1Get()+rooms[i-1].x2Get())/2; y1 = (rooms[i].y1Get()+rooms[i].y2Get())/2; y2 = (rooms[i-1].y1Get()+rooms[i-1].y2Get())/2; if (i>0 ) genPath(level,x1,y1,x2,y2); if (i == 0) level->nodeSet(y1,x1,'e'); else if(i==numRooms-1) level->nodeSet(y1,x1,'E'); } } printf("Bad level..."); //getch(); } return 1; }
vector<string> wordBreak(string s, unordered_set<string> &dict) { vector<string> r; int n=s.size(); bool f[n+1]; vector<vector<bool> > prev(n+1, vector<bool>(n+1, false)); fill_n(&f[0],n+1,false); f[0]=true; for(int i=1;i<=n;++i) { for(int j=i-1; j>=0; --j) { if(f[j] && dict.find(s.substr(j, i-j))!=dict.end()) { f[i]=true; prev[i][j]=true; } } } vector<string> p; genPath(s, prev, n, r, p); return r; }
mqd_t mq_open(const char* path, int flags, int mode){ int fd, i; struct mq_attr* attr; if(!started) { for( i = 0; i < 20 ; i++ ) hashLink[i]=NULL; started=1; } if((fd = shm_open(path, flags, mode)) == -1) return (mqd_t) -1; if(flags & O_CREAT && ftruncate(fd, sizeof(struct mq_attr))) return (mqd_t) -1; if((attr = mmap(NULL, sizeof(struct mq_attr), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) return (mqd_t) -1; if(flags & O_CREAT) { //Setting up message queue attr->mq_maxmsg = 32; attr->mq_msgsize = sizeof(msg); attr->mq_curmsgs = 0; attr->subscriber = 0; attr->first = NULL; //attr->last = NULL; //All the msg struct isn't alloc at first. for(i = 0; i < attr->mq_maxmsg ; i++) attr->queue[i].used = 0; /** Creating semaphore. **/ //Writer initialised at maxmsg for(i = 0; SEM_FAILED==(localinfo[fd].blocked_writers = sem_open(genPath("BLOCKED_WRITERS_PATH",i), O_CREAT | O_EXCL, 0600, attr->mq_maxmsg)) && i < 1000; i++ ) if(localinfo->blocked_writers == SEM_FAILED && errno != EEXIST) return -1; strcpy(attr->blocked_writers, genPath("BLOCKED_WRITERS_PATH",i)); //Reader initialised at 0 for(i = 0; SEM_FAILED==(localinfo[fd].blocked_readers = sem_open(genPath("BLOCKED_READERS_PATH",i), O_CREAT | O_EXCL, 0600, 0)) && i < 1000; i++ ) if(localinfo->blocked_readers == SEM_FAILED && errno != EEXIST) return -1; strcpy(attr->blocked_readers, genPath("BLOCKED_READERS_PATH",i)); //Mutex for queue operation (send, receive and notify) for(i = 0; SEM_FAILED==(localinfo[fd].queue_sem = sem_open(genPath("QUEUE_SEM_PATH",i), O_CREAT | O_EXCL, 0600, 1)) && i < 1000; i++ ) if(localinfo->queue_sem == SEM_FAILED && errno != EEXIST) return -1; strcpy(attr->queue_sem, genPath("QUEUE_SEM_PATH",i)); //Mutex for allocation of msg in the shared memory. for(i = 0; SEM_FAILED==(localinfo[fd].search_sem = sem_open(genPath("SEARCH_SEM_PATH",i) , O_CREAT | O_EXCL, 0600, 1)) && i < 1000; i++ ) if(localinfo->search_sem == SEM_FAILED && errno != EEXIST) return -1; strcpy(attr->search_sem, genPath("SEARCH_SEM_PATH",i)); errno = 0; } else { if(SEM_FAILED == (localinfo->blocked_writers = sem_open(attr->blocked_writers, 0))) return -1; if(SEM_FAILED == (localinfo->blocked_readers = sem_open(attr->blocked_readers, 0))) return -1; if(SEM_FAILED == (localinfo->queue_sem = sem_open(attr->queue_sem, 0))) return -1; if(SEM_FAILED == (localinfo->search_sem = sem_open(attr->search_sem, 0))) return -1; } //Setting local info localinfo[fd].mq_flags = O_NONBLOCK & flags; hashLink[fd] = attr; return (mqd_t) fd; }
void QGeoTiledMapPolylineObjectInfo::pathChanged(const QList<QGeoCoordinate> &/*path*/) { genPath(); updateItem(); }