bool Compressor::realloc() { if( !isGood( )) return false; impl_->plugin->deleteCompressor( impl_->instance ); impl_->instance = impl_->plugin->newCompressor( impl_->info.name ); LBASSERT( impl_->instance ); return impl_->instance; }
void Compressor::compress( void* const in, const uint64_t pvpIn[4], const uint64_t flags ) { LBASSERT( impl_->plugin ); LBASSERT( impl_->instance ); LBASSERT( in ); if( !isGood( )) return; impl_->plugin->compress( impl_->instance, impl_->info.name, in, pvpIn, flags ); }
bool InputPersistenceBlock::checkMarker(byte marker) { if (!isGood() || !checkBlockSize(1)) return false; if (*_iter++ == marker) { return true; } else { _errorState = OUT_OF_SYNC; error("Wrong type marker found in persistence block."); return false; } }
/** Requests that P2OS initialize the arm and immediately returns. The arm initialization procedure takes about 700ms to complete and a little more time for the status information to be relayed back to the client. Since there is a very noticable time delay, the user should use the ArP2Arm::setPacketCB() to set a callback so the user knows when the arm info packet has been received. Then wait about 800ms, and send a ArP2Arm::requestStatus() to get the results of the init request. While the init is proceding, P2OS will ignore all arm related commands except requests for arm status and arm info packets. ArP2Arm::checkArm() can be used to periodicly check to make sure that the arm controller is still alive and responding. @see checkArm @see setPacketCB */ AREXPORT ArP2Arm::State ArP2Arm::requestInit() { if (isGood()) { if (comArmInit()) return(SUCCESS); else return(COMM_FAILED); } else return(NOT_CONNECTED); }
int simulateGenome(char const * filename, MasonSimulateGenomeOptions const & options) { seqan::SequenceStream stream; open(stream, filename, seqan::SequenceStream::WRITE, seqan::SequenceStream::FASTA); if (!isGood(stream)) { std::cerr << "ERROR: Could not open " << filename << "for writing!\n"; return 1; } return simulateGenome(stream, options); }
/** Requests the arm status packet from P2OS and immediately returns. This packet will be sent during the next 100ms cycle of P2OS. Since there is a very noticable time delay, the user should use the ArP2Arm::setPacketCB() to set a callback so the user knows when the packet has been received. @see setPacketCB */ AREXPORT ArP2Arm::State ArP2Arm::requestStatus(StatusType status) { if (isGood()) { if (comArmStats(status)) return(SUCCESS); else return(COMM_FAILED); } else return(NOT_CONNECTED); }
/** Move the joint pos ticks from its current position. A tick is the arbitrary position value that the arm controller uses. The arm controller uses a single unsigned byte to represent all the possible positions in the range of the servo for each joint. So the range of ticks is 0-255 which is mapped to the physical range of the servo. Due to the design of the arm, certain joints range are limited by the arm itself. P2OS will bound the position to physical range of each joint. This is a lower level of controlling the arm position than using ArP2Arm::moveTo(). ArP2Arm::moveStep() uses a conversion factor which converts degrees to ticks. @param joint the joint to move @param pos the position, in ticks, to move to @see moveStep */ AREXPORT ArP2Arm::State ArP2Arm::moveStepTicks(int joint, signed char pos) { if (!isGood()) return(NOT_INITED); else if ((joint <= 0) || (joint > NumJoints)) return(INVALID_JOINT); if (!comArmPos(joint, getJoint(joint)->myPos + pos)) return(COMM_FAILED); return(SUCCESS); }
/** Powers off the arm. This should only be called when the arm is in a good position to power off. Due to the design, it will go limp when the power is turned off. A more safe way to power off the arm is to use the ArP2Arm::park() function. Which will home the arm, then power if off. @see park */ AREXPORT ArP2Arm::State ArP2Arm::powerOff() { if (isGood()) { ArLog::log(ArLog::Normal, "ArP2Arm::powerOff: Powering off arm."); if (comArmPower(false)) return(SUCCESS); else return(COMM_FAILED); } else return(NOT_CONNECTED); }
CDirectionStep::CDirectionStep( CBaseStep*pIn, CCartesian_pointStep& rCartesian_pointStep0, CCartesian_pointStep& rCartesian_pointStep1 ) : CGeometric_representation_itemStep(pIn) , m_bGood(true) { ASSERT( &rCartesian_pointStep0 != NULL); ASSERT( &rCartesian_pointStep1 != NULL); nameClass("Direction"); m_direction_ratios[0] = rCartesian_pointStep1.coordinates[0] - rCartesian_pointStep0.coordinates[0] ; m_direction_ratios[1] = rCartesian_pointStep1.coordinates[1] - rCartesian_pointStep0.coordinates[1] ; m_direction_ratios[2] = rCartesian_pointStep1.coordinates[2] - rCartesian_pointStep0.coordinates[2] ; isGood(); }
/** Tells the arm to go to the home position. While the arm is homing, the status byte will reflect it with the ArP2Arm::ArmHoming flag. If joint is set to -1, then all the joints will be homed at a safe speed. If a single joint is specified, that joint will be told to go to its home position at the current speed its set at. @param joint home only that joint */ AREXPORT ArP2Arm::State ArP2Arm::home(int joint) { if (!isGood()) return(NOT_INITED); if ((joint < 0) && !comArmHome(0xff)) return(COMM_FAILED); else if ((joint > 0) && (joint <= NumJoints) && !comArmHome(joint)) return(COMM_FAILED); else return(INVALID_JOINT); return(SUCCESS); }
/** Set the joints velocity. The arm controller has no way of controlling the speed of the servos in the arm. So to control the speed of the arm, P2OS will incrementaly send a string of position commands to the arm controller to get the joint to move to its destination. To vary the speed, the amount of time to wait between each point in the path is varied. The velocity parameter is simply the number of milliseconds to wait between each point in the path. 0 is the fastest and 255 is the slowest. A reasonable range is around 10-40. @param joint the joint to move @param vel the velocity to move at */ AREXPORT ArP2Arm::State ArP2Arm::moveVel(int joint, int vel) { if (!isGood()) return(NOT_INITED); else if ((joint <= 0) || (joint > NumJoints)) return(INVALID_JOINT); if ((vel < 0) && (!comArmSpeed(joint, 0-vel) || !comArmPos(joint, 0))) return(COMM_FAILED); else if ((vel > 0) && (!comArmSpeed(joint, vel) || !comArmPos(joint, 255))) return(COMM_FAILED); return(SUCCESS); }
/** Powers on the arm. The arm will shake for up to 2 seconds after powering on. If the arm is told to move before it stops shaking, that vibration can be amplified by moving. The default is to wait the 2 seconds for the arm to settle down. @param doSleep if true, sleeps 2 seconds to wait for the arm to stop shaking */ AREXPORT ArP2Arm::State ArP2Arm::powerOn(bool doSleep) { if (isGood()) { ArLog::log(ArLog::Normal, "ArP2Arm::powerOn: Powering arm."); if (!comArmPower(true)) return(COMM_FAILED); // Sleep for 2 seconds to wait for the arm to stop shaking from the // effort of turning on if (doSleep) ArUtil::sleep(2000); return(SUCCESS); } else return(NOT_CONNECTED); }
//executes the function and returns what it gets, or returns NULL if something is wrong PyObject* PythonHandler::execute() { if (isGood()) { py_ret_value = PyObject_CallObject(py_func, py_func_args); if (py_ret_value == NULL) { Py_DECREF(py_func); Py_DECREF(py_mod); printf("PyErr: "); PyErr_Print(); errors.push("Refer to PyErr output for more information."); } return py_ret_value; } return NULL; }
void FileInfo::_setType() { if (!isGood()) return; #ifdef WIN32 if (_findFileData.dwFileAttributes &= FILE_ATTRIBUTE_DIRECTORY) this->_type = DIR; else this->_type = FILE; #else if (S_ISDIR(this->_sb.st_mode)) this->_type = DIR; else if (S_ISREG(this->_sb.st_mode)) this->_type = FILE; #endif }
//Only effects future particle systems, of course. void WCachedParticles::Refresh() { hgeParticleSystemInfo * old = particles; int error = 0; Attempt(mFilename, loadedMode, error); if (isGood()) SAFE_DELETE(old); else { SAFE_DELETE(particles); particles = old; } return; }
int main() { // Open input stream seqan::GffStream gffIn("example.gff"); if (!isGood(gffIn)) { std::cerr << "ERROR: Could not open example.gff\n"; return 1; } // Array of counters and sequence names. seqan::String<unsigned> counters; seqan::StringSet<seqan::CharString> seqNames; // Read the file record by record. seqan::GffRecord record; while (!atEnd(gffIn)) { if (readRecord(record, gffIn) != 0) { std::cerr << "ERROR: Problem reading from example.gff\n"; return 1; } // Resize counters and write seqNames if necessary. if ((int)length(counters) <= record.rID) { resize(counters, record.rID + 1, 0); resize(seqNames, record.rID + 1); } if (counters[record.rID] == 0) seqNames[record.rID] = record.ref; // Register record with counters. counters[record.rID] += 1; } // Print result. std::cout << "RECORDS ON CONTIGS\n"; for (unsigned i = 0; i < length(seqNames); ++i) if (counters[i] > 0u) std::cout << seqNames[i] << '\t' << counters[i] << '\n'; return 0; }
/** Step the joint pos degrees from its current position at the given speed. If vel is 0, then the currently set speed will be used. See ArP2Arm::moveToTicks() for a description of how positions are defined. See ArP2Arm::moveVel() for a description of how speeds are defined. @param joint the joint to move @param pos the position in degrees to step @param vel the speed at which to move. 0 will use the currently set speed @see moveTo @see moveVel */ AREXPORT ArP2Arm::State ArP2Arm::moveStep(int joint, float pos, unsigned char vel) { unsigned char ticks; if (!isGood()) return(NOT_INITED); else if ((joint <= 0) || (joint > NumJoints)) return(INVALID_JOINT); // if ((vel < 0) && !comArmSpeed(joint, 0-vel)) // return(COMM_FAILED); else if ((vel > 0) && !comArmSpeed(joint, vel)) return(COMM_FAILED); if (!convertDegToTicks(joint, pos, &ticks)) return(INVALID_POSITION); return(moveStepTicks(joint, ticks)); }
bool WCachedSample::Attempt(const string& filename, int submode, int & error) { loadedMode = submode; string sfxFile = WResourceManager::Instance()->sfxFile(filename); sample = JSoundSystem::GetInstance()->LoadSample(sfxFile.c_str()); if (!isGood()) { SAFE_DELETE(sample); if (!fileExists(filename.c_str())) error = CACHE_ERROR_404; else error = CACHE_ERROR_BAD; return false; } error = CACHE_ERROR_NONE; return true; }
//packs args into a tuple (py_func_args) for PyObject_CallObject void PythonHandler::packArgs(PythonArgList arg_list) { if (isGood()) { if (arg_list.size() > 0) { py_func_args = PyTuple_New(arg_list.size()); for (unsigned int i = 0; i < arg_list.size(); i++) { PyObject* py_argument = arg_list.at(i); if (!py_argument) { good = false; Py_DECREF(py_func_args); Py_DECREF(py_mod); errors.push("Unable to load parameter " + std::to_string(i+1) + "\n"); } PyTuple_SetItem(py_func_args, i, py_argument); } } else { py_func_args = NULL; //runs the function with no arguments (if it can) } } }
//-- read a header(s)--------------- int32_t RceConvert::readHeader() { //every tdc header holds 10 32bit values. Important values: //value 0: Rce number //value 2: Hitbus 1 information //value 3: Hitbus 2 information //value 5: timestamp-high //value 6: timestamp-low for (int32_t rceN = 0; rceN < _numberOfRces; rceN++) { //initialise buffer with 10 integers _bufTDC = new int32_t [10]; //read from file if ( !isGood() ) throw " Error while reading a TDC block from the file. Corrupt data?"; _inFile.read( (char*) _bufTDC,40); //read a block of 10 _event->setRce(_bufTDC[0]); //this is set only on the first TDC of event 0 //Set this RCE to be the main RCE to take the timestamp from. if (_mainRce == -1) _mainRce = _event->getRce(); //if current rce is the main one, //write the timestamp of this rce to the event if (_event->getRce(rceN) == _mainRce ) _event->setTimestamp(_bufTDC[6], _bufTDC[5]);//low and high delete _bufTDC; } return 0; }
/******************************************************************* * Function Name: SkipComments * Return Type : int * Created On : Oct 6, 2013 * Created By : hrushi * Comments : Skips empty lines and comments * Arguments : *******************************************************************/ int ReadFile::SkipComments( ) { string line; bool bCommentStart = false; while(isGood() ) { line = GetLine(); const string NewWhiteSpace = StringOp<string>::GetNonWhiteSpace(0, line); if( NewWhiteSpace.length() == 0 ) { continue; } char FirstChar = NewWhiteSpace.at(0); if( FirstChar == '#' ) { cout << line << endl; char SecondChar = StringOp<string>::GetNonWhiteSpace(1, line).at(0); if( SecondChar == '*' ) { if( bCommentStart == false ) { bCommentStart = true; } else { break; } } } } return EXIT_SUCCESS; }
CompressorResult Compressor::getResult() const { LBASSERT( impl_->plugin ); LBASSERT( impl_->instance ); if( !isGood( )) return CompressorResult(); const unsigned num = impl_->plugin->getNumResults( impl_->instance, impl_->info.name ); CompressorChunks chunks; chunks.reserve( num ); for( unsigned i = 0; i < num; ++i ) { void* data; uint64_t size; impl_->plugin->getResult( impl_->instance, impl_->info.name, i, &data, &size ); chunks.push_back( CompressorChunk( data, size )); } return CompressorResult( impl_->info.name, chunks ); }
LRESULT MainWindow::onNotify(UINT msg,WPARAM wParam,LPARAM lParam) { int id=wParam; NMHDR *nm=(NMHDR*)lParam; // int i; MessageBeep(MB_OK); for(i=0;i<n_edtAns;i++){ if(nm->hwndFrom==edtAns[i]->getHWND() && nm->code==EN_ENTER){ //sendMenuClick(IDM_FUNC_ENTER); if(isGood()){ //次の問題へ rndtable.clear(qindex); updateCaption(); if(rndtable.getCurrentSize()>0){ sendMenuClick(IDM_FUNC_PASS); }else{ sndClear->play(); showCongratulation(); } }else if(rndtable.getCurrentSize()>0){ //解答チェック wchar_t *p=edtAns[i]->getTextTemp(); if(wcscmp(p, m_allList.getTotalAt(qindex).m_a.c_str())==0){ sndOk->play(); showGood(i); }else{ sndNg->play(); showBad(); } } return 0L; } } return CustomWindow::onNotify(msg,wParam,lParam); }
//configure the FunctionManager using the current config line void FunctionManager::configure() { py_args.clear(); std::string temp_cfl = config_line; std::vector<std::string> tokens; int delim_pos; while ((delim_pos = temp_cfl.find('|')) != std::string::npos) { tokens.push_back(temp_cfl.substr(0, delim_pos)); temp_cfl.erase(0, delim_pos+1); } tokens.push_back(temp_cfl); file_name = tokens[0]; function_name = tokens[1]; for (unsigned int i = 2; i < tokens.size(); i++) { PyObject* arg = convert(tokens[i]); if (arg != NULL) { py_args.push_back(arg); } else { good = false; printf("Error: unable to load argument %ld for function %s\n", i, function_name.c_str()); } } if (isGood()) { py_handler.init(file_name, function_name, py_args); if (!py_handler.isGood()) { good = false; } } }
bool OilifyFilter::runCL(const QCLImage2D & src, int w, int h, QCLImage2D & dst) { if (!isGood()) return false; #ifndef OPTIMIZED_VER m_kernel.setArg(SRC_IDX, src); m_kernel.setArg(DST_IDX, dst); m_kernel.setGlobalWorkSize(w, h); m_kernel.run(); #else if ((m_tmp_buf_w != w) || (m_tmp_buf_h != h)) { QCLImageFormat fmt(QCLImageFormat::Order_BGRA, QCLImageFormat::Type_Unnormalized_UInt8); m_tmp_buf = m_ctx->createImage2DDevice(fmt, QSize(w, h), QCLImage2D::ReadWrite); if (m_tmp_buf.isNull()) { ERRORM("Failed to create temporary buffer for Oilify Filter: " << m_ctx->lastError()); return false; } m_tmp_buf_w = w; m_tmp_buf_h = h; m_kernel_oilify_prepare.setGlobalWorkSize(w, h); m_kernel_oilify.setGlobalWorkSize(w, h); } m_kernel_oilify_prepare.setArg(SRC_IDX, src); m_kernel_oilify_prepare.setArg(DST_IDX, m_tmp_buf); m_kernel_oilify_prepare.run(); m_kernel_oilify.setArg(SRC_IDX, m_tmp_buf); m_kernel_oilify.setArg(DST_IDX, dst); m_kernel_oilify.run(); #endif return true; }
int main(int argc, char const ** argv) { double startTime = 0; // ----------------------------------------------------------------------- // Parse command line. // ----------------------------------------------------------------------- FxSamCoverageOptions options; seqan::ArgumentParser::ParseResult res = parseArgs(options, argc, argv); if (res != seqan::ArgumentParser::PARSE_OK) return res == seqan::ArgumentParser::PARSE_ERROR; // 1 on errors, 0 otherwise // ----------------------------------------------------------------------- // Show options. // ----------------------------------------------------------------------- if (options.verbosity >= 1) { std::cerr << "____OPTIONS___________________________________________________________________\n" << "\n" << "VERBOSITY " << options.verbosity << "\n" << "GENOME " << options.inGenomePath << "\n" << "SAM " << options.inSamPath << "\n" << "OUT " << options.outPath << "\n" << "WINDOW SIZE " << options.windowSize << "\n"; } // ----------------------------------------------------------------------- // Load Genome FAI Index // ----------------------------------------------------------------------- std::cerr << "\n" << "___PREPRATION_____________________________________________________________________\n" << "\n" << "Indexing GENOME file " << options.inGenomePath << " ..."; seqan::FaiIndex faiIndex; if (build(faiIndex, toCString(options.inGenomePath)) != 0) { std::cerr << "Could not build FAI index.\n"; return 1; } std::cerr << " OK\n"; // Prepare bins. seqan::String<seqan::String<BinData> > bins; resize(bins, numSeqs(faiIndex)); // ----------------------------------------------------------------------- // Compute C+G content // ----------------------------------------------------------------------- std::cerr << "\n" << "___C+G CONTENT COMPUTATION________________________________________________________\n" << "\n"; for (unsigned i = 0; i < numSeqs(faiIndex); ++i) { std::cerr << "[" << sequenceName(faiIndex, i) << "] ..."; unsigned numBins = (sequenceLength(faiIndex, i) + options.windowSize - 1) / options.windowSize; resize(bins[i], numBins); seqan::Dna5String contigSeq; if (readSequence(contigSeq, faiIndex, i) != 0) { std::cerr << "\nERROR: Could not read sequence " << sequenceName(faiIndex, i) << " from file!\n"; return 1; } for (unsigned bin = 0; bin < numBins; ++bin) { unsigned cgCounter = 0; unsigned binSize = 0; bins[i][bin].length = options.windowSize; if ((bin + 1) * options.windowSize > length(contigSeq)) bins[i][bin].length = length(contigSeq) - bin * options.windowSize; for (unsigned pos = bin * options.windowSize; pos < length(contigSeq) && pos < (bin + 1) * options.windowSize; ++pos, ++binSize) cgCounter += (contigSeq[pos] == 'C' || contigSeq[pos] == 'G'); bins[i][bin].cgContent = 1.0 * cgCounter / binSize; } std::cerr << "DONE\n"; } // ----------------------------------------------------------------------- // Compute Coverage // ----------------------------------------------------------------------- std::cerr << "\n" << "___COVERAGE COMPUATATION________________________________________________________\n" << "\n" << "Computing Coverage..."; seqan::BamStream bamStream(toCString(options.inSamPath)); if (!isGood(bamStream)) { std::cerr << "Could not open " << options.inSamPath << "!\n"; return 1; } seqan::BamAlignmentRecord record; while (!atEnd(bamStream)) { if (readRecord(record, bamStream) != 0) { std::cerr << "ERROR: Could not read record from BAM file!\n"; return 1; } if (hasFlagUnmapped(record) || hasFlagSecondary(record) || record.rId == seqan::BamAlignmentRecord::INVALID_REFID) continue; // Skip these records. int contigId = 0; seqan::CharString const & contigName = nameStore(bamStream.bamIOContext)[record.rId]; if (!getIdByName(faiIndex, contigName, contigId)) { std::cerr << "ERROR: Alignment to unknown contig " << contigId << "!\n"; return 1; } unsigned binNo = record.pos / options.windowSize; bins[contigId][binNo].coverage += 1; } std::cerr << "DONE\n"; // ----------------------------------------------------------------------- // Write Output // ----------------------------------------------------------------------- std::ostream * out = &std::cout; std::ofstream outFile; if (options.outPath != "-") { outFile.open(toCString(options.outPath), std::ios::binary | std::ios::out); if (!outFile.good()) { std::cerr << "ERROR: Could not open output file " << options.outPath << "!\n"; return 1; } out = &outFile; } (*out) << "#BIN\tREF_NAME\tREF_BIN\tBIN_BEGIN\tBIN_LENGTH\tCOVERAGE\tCG_CONTENT\n"; for (unsigned i = 0, globalBin = 0; i < length(bins); ++i) { for (unsigned refBin = 0; refBin < length(bins[i]); ++refBin, ++globalBin) { (*out) << globalBin << '\t' << sequenceName(faiIndex, i) << '\t' << refBin << '\t' << refBin * options.windowSize << '\t' << bins[i][refBin].length << '\t' << bins[i][refBin].coverage << '\t' << bins[i][refBin].cgContent << '\n'; } } if (options.verbosity >= 2) std::cerr << "Took " << (sysTime() - startTime) << " s\n"; return 0; }
bool JudgeStruct::isBad() const{ return ! isGood(); }
//--- read in a data block ------------ int32_t RceConvert::readData() { //initialise data buffer _bufData = new int32_t [_event->getDataSizeInBytes()]; //cout<<" Event data size; "<<_event->getDataSizeInBytes()<<endl; //read from file if ( !isGood() ) throw " Error while reading a data block from the file. Corrupt data?"; _inFile.read( (char*) _bufData, _event->getDataSizeInBytes() ); //initialise variables for this data block int32_t tempRce = 0; int32_t whichRce = -1; int32_t tempL1id = 0; int32_t tempBxid = 0; int32_t tempLink = 0; int32_t tempDiffBx = 0; /*Data block format: 1 x HeaderTwo for RCE1 l1bin x ( Header for l1bin1 for module 1 Data for l1bin1 for module 1 -> write hit Header for l1bin1 for module 2 Data for l1bin1 for module 2 ... -> write hit Header for l1bin2 for module 1... ) */ for (int32_t i = 0; i < _event->getDataSizeInIntegers(); i++ ) { //take one integer at a time into formatted record. unsigned buf = (unsigned)_bufData[i]; FormattedRecord rec ( buf ); //------------------------------HeaderTwo----------- //header two holds RCE information if ( rec.isHeaderTwo() ) { tempRce = rec.getRCE(); //find the RCE by its number (0 is mainRce and 1 is non-main) if (tempRce == _mainRce) whichRce = 0; else whichRce = 1; //cout<<"headerTwo"<<endl; } //-------------------------------Header-------------- //header holds information on links, l1ids and bcids. else if ( rec.isHeader() ) { tempLink = rec.getLink(); tempL1id = rec.getL1id(); tempBxid = rec.getBxid(); if( tempL1id != _oldL1id.at(whichRce) ) // if in a new trigger { _oldL1id.at(whichRce) = tempL1id; //renew the trigger number _firstBxid.at(whichRce) = tempBxid; //renew first bunch count } tempDiffBx = tempBxid - _firstBxid.at(whichRce); //account for a bxid spill over 1024 if (tempDiffBx<0) tempDiffBx+=1024; if (tempDiffBx <0 || tempDiffBx > 15) cout<<" ====================== WRONG diffbx!"<<endl; } //-------------------------------Data------------------ //data holds information on else if ( rec.isData() ) { int32_t chip=rec.getFE(); int32_t tot=rec.getToT(); int32_t col=rec.getCol(); int32_t row=rec.getRow(); //std::cout << "tempLink: " << tempLink << " tempRce: " << tempRce << std::endl; float x,y; if (chip<8){ x=18*chip+col; y=row; } else { x=(15-chip)*18+17-col; y= 319-row; } //find the mapped plane // --> hit has to be written out _event->addHit ( x, y, tot, tempDiffBx, mapPlane(tempRce, tempLink) ); //std::cout << "map to plane: " << mapPlane(tempRce, tempLink) << std::endl; } else throw "Corrupt data! Couldn't recognise data structure."; } delete _bufData; return 0; }
bool Downloader::uses( const uint32_t name ) const { return isGood() && impl_->info.name == name; }
/*Generating RecursiveMaze mazeGrid*/ ERR_ENUM RecursiveBack::generate() // Generating RecursiveMaze { if (height <= 1 || width <= 1 || mazeGrid == 0) return FAILURE; if (width > height || width == height || width < height) { for (size_t i = 0; i < width; i++) // init the grid Array { for (size_t j = 0; j < height; j++) { mazeGrid[i][j] = '0'; // Set all WALL } } } srand((unsigned int)time(0)); stack<int> xValues; // initialize stacks for X values stack<int> yValues; // initialize stacks for Y values int nGood = 0; // Number of correct moves int direction = 0; int locX = 1, locY = 1; // Base First Movement do { for (int i = 0; i < 4; i++) { if (isGood(locX, locY, i)) { nGood++; } } if (nGood == 1) // if only 1 good move, move there { if (isGood(locX, locY, NORTH)) { locX = moveUpDown(NORTH, locX); } else if (isGood(locX, locY, SOUTH)) { locX = moveUpDown(SOUTH, locX); } else if (isGood(locX, locY, EAST)) { locY = moveLeftRight(EAST, locY); } else if (isGood(locX, locY, WEST)) { locY = moveLeftRight(WEST, locY); } } else if (nGood == 0) // if no good moves, move back in stack { locX = xValues.top(); locY = yValues.top(); xValues.pop(); yValues.pop(); } else if (nGood > 1) // if more than 1 good move, push stack { xValues.push(locX); yValues.push(locY); do // direction to move randomly chosen { direction = rand() % 4; } while (!isGood(locX, locY, direction)); locX = moveUpDown(direction, locX); locY = moveLeftRight(direction, locY); } if (mazeGrid[locX][locY + 1] == '1' && // Bug Fix for the 2 x 2 square path mazeGrid[locX + 1][locY] == '1' && mazeGrid[locX + 1][locY + 1] == '1') { } else { mazeGrid[locX][locY] = '1'; // set grid } nGood = 0; // reset nGood value } while (!xValues.empty()); ofstream fout("test.txt"); if (fout.is_open()) { for (size_t i = 0; i < width; ++i) { for (size_t j = 0; j < height; ++j) { fout << mazeGrid[i][j] << ""; } fout << "\n"; } // cout << "\nArray data successfully saved into the file test.txt" << endl; } else // File could not be opened { cout << "File could not be opened. [Check C++ One]" << endl; } return SUCCESS; }