Ejemplo n.º 1
0
 scanner::token scanner::read_quoted_symbol() {
     SASSERT(curr() == '|');
     bool escape = false;
     m_string.reset();
     next();
     while (true) {
         char c = curr();
         if (c == EOF) {
             throw scanner_exception("unexpected end of quoted symbol", m_line, m_spos);
         }
         else if (c == '\n') {
             new_line();
         }
         else if (c == '|' && !escape) {
             next();
             m_string.push_back(0);
             m_id = m_string.begin();
             TRACE("scanner", tout << "new quoted symbol: " << m_id << "\n";);
             return SYMBOL_TOKEN;
         }
Ejemplo n.º 2
0
void scanner::read_comment_block() {
    unsigned nesting = 1;
    while (true) {
        char c = curr();
        check_not_eof("unexpected end of comment block");
        next();
        if (c == '/') {
            if (curr() == '-') {
                next();
                nesting++;
            }
        } else if (c == '-') {
            if (curr() == '/') {
                next();
                nesting--;
                if (nesting == 0)
                    return;
            }
        }
    }
}
Ejemplo n.º 3
0
char scanner::read_quoted_char(char const * error_msg) {
    lean_assert(curr() == '\\');
    next();
    check_not_eof(error_msg);
    char c = curr();
    if (c != '\\' && c != '\"' && c != 'n' && c != '\'' && c != 'x')
        throw_exception("invalid escape sequence");
    if (c == 'n') {
        return '\n';
    } else if (c == 'x') {
        next();
        char c = curr();
        unsigned v = hex_to_unsigned(c);
        next();
        c = curr();
        v = 16*v + hex_to_unsigned(c);
        return static_cast<char>(v);
    } else {
        return c;
    }
}
Ejemplo n.º 4
0
/**
==================== Decl =============================================
   Grammar:
      decl : type id ';' 
*/
static TreeDecl p_decl(void) {
   TreeDecl decl = 0; // set null by default
   TokenCode code = curr()->code;
   // body
   TreeType l0type = p_type();
   TreeId l1id = p_id();
   eat(';');
   decl = t_decl_type(l0type, l1id);

   
   return decl;
}
Ejemplo n.º 5
0
/**
==================== Block ============================================
   Grammar:
      block : '{' decls stmts '}' 
*/
static TreeBlock p_block(void) {
   TreeBlock block = 0; // set null by default
   TokenCode code = curr()->code;
   // body
   eat('{');
   TreeDecls l1decls = p_decls();
   TreeStmts l2stmts = p_stmts();
   eat('}');
   block = t_block_decls(l1decls, l2stmts);

   
   return block;
}
Ejemplo n.º 6
0
    //
    // Stop all movies
    //
    void StopMovies()
    {
      for (NList<Cineractive>::Iterator curr(&cineractives); *curr; curr++)
      {
        Cineractive *cin = *curr;

        if (cin->moviePrim)
        {
          delete cin->moviePrim;
          cin->moviePrim = NULL;
        }
      }
    }
Ejemplo n.º 7
0
bool proof_checker::check(proof* p, expr_ref_vector& side_conditions) {
    proof_ref curr(m);
    m_todo.push_back(p);
    
    bool result = true;
    while (result && !m_todo.empty()) {
        curr = m_todo.back();
        m_todo.pop_back();
        result = check1(curr.get(), side_conditions);
        if (!result) {
            IF_VERBOSE(0, ast_ll_pp(verbose_stream() << "Proof check failed\n", m, curr.get()););            
            UNREACHABLE();
        }        
Ejemplo n.º 8
0
void GR_skigImp::loadDataset(const string &path)
{
    train.push_back(vector< Ptr<Object> >());
    test.push_back(vector< Ptr<Object> >());
    validation.push_back(vector< Ptr<Object> >());

    for (unsigned int i=1; i<=6; ++i)
    {
        char number[2];
        sprintf(number, "%u", i);
        string pathDatasetRgb(path + "subject" + number + "_rgb/");
        string pathDatasetDep(path + "subject" + number + "_dep/");

        vector<string> fileNames;
        getDirList(pathDatasetRgb, fileNames);
        for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it)
        {
            string &file = *it;

            Ptr<GR_skigObj> curr(new GR_skigObj);
            curr->rgb = pathDatasetRgb + file;
            curr->dep = file;
            curr->dep[0] = 'K';
            curr->dep = pathDatasetDep + curr->dep;

            size_t posPerson = file.find("person_");
            size_t posBackground = file.find("backgroud_");
            size_t posIllumination = file.find("illumination_");
            size_t posPose = file.find("pose_");
            size_t posType = file.find("actionType_");
            if (string::npos != posPerson &&
                string::npos != posBackground &&
                string::npos != posIllumination &&
                string::npos != posPose &&
                string::npos != posType)
            {
                curr->person = (unsigned char)atoi( file.substr(posPerson + strlen("person_"), 1).c_str() );
                curr->background = (backgroundType)atoi( file.substr(posBackground + strlen("backgroud_"), 1).c_str() );
                curr->illumination = (illuminationType)atoi( file.substr(posIllumination + strlen("illumination_"), 1).c_str() );
                curr->pose = (poseType)atoi( file.substr(posPose + strlen("pose_"), 1).c_str() );
                curr->type = (actionType)atoi( file.substr(posType + strlen("actionType_"), 2).c_str() );

                train.back().push_back(curr);
            } else
            {
                printf("incorrect file name: %s", file.c_str());
            }
        }
    }
}
Ejemplo n.º 9
0
  void IpoptData::SetTrialBoundMultipliersFromStep(Number alpha,
      const Vector& delta_z_L,
      const Vector& delta_z_U,
      const Vector& delta_v_L,
      const Vector& delta_v_U)
  {
    DBG_ASSERT(have_prototypes_);

    SmartPtr<IteratesVector> newvec = trial()->MakeNewContainer();
    newvec->create_new_z_L();
    newvec->z_L_NonConst()->AddTwoVectors(1., *curr()->z_L(), alpha, delta_z_L, 0.);

    newvec->create_new_z_U();
    newvec->z_U_NonConst()->AddTwoVectors(1., *curr()->z_U(), alpha, delta_z_U, 0.);

    newvec->create_new_v_L();
    newvec->v_L_NonConst()->AddTwoVectors(1., *curr()->v_L(), alpha, delta_v_L, 0.);

    newvec->create_new_v_U();
    newvec->v_U_NonConst()->AddTwoVectors(1., *curr()->v_U(), alpha, delta_v_U, 0.);

    set_trial(newvec);
  }
Ejemplo n.º 10
0
void firstAndOthers(const string &line, string &first, string &others)
{ // skip whitespace before first
  string::const_iterator curr(line.begin()), cue(line.end());
  for(; (curr!=cue) && (*curr<=' '); curr++);

  // find the end of first
  string::const_iterator fbeg=curr;
  for(; (curr!=cue) && (*curr>' '); curr++);
  first=string(fbeg, curr);

  // skip the whitespace before others
  for(; (curr!=cue) && (*curr<=' '); curr++);
  others=string(curr, cue);
}
Ejemplo n.º 11
0
static ssize_t store_charge_property(struct device *dev,
				     struct device_attribute *attr,
				     const char *buf, size_t count)
{
	struct charge_control *control = (struct charge_control*)(attr);
	unsigned int val;

	if (sscanf(buf, "%u", &val) != 1)
		return -EINVAL;

	switch (control->type) {
		case INPUT:
			curr(control->index).input_current_limit = val;
			break;
		case CHARGE:
			curr(control->index).fast_charging_current = val;
			break;
		default:
			break;
	}

	return count;
}
Ejemplo n.º 12
0
    DiskLoc RocksRecordStore::Iterator::getNext() {
        if ( !_iterator->Valid() ) {
            return DiskLoc();
        }

        DiskLoc toReturn = curr();

        if ( _forward() )
            _iterator->Next();
        else
            _iterator->Prev();

        return toReturn;
    }
Ejemplo n.º 13
0
 vector<vector<int>> generate(int numRows) {
     if (numRows < 1) { return result; }
     for (int i = 0; i < numRows; ++i) {
         vector<int> curr(1, 1);
         if (i > 0) {
             for (int j = 0; j < result[i - 1].size() - 1; ++j) {
                 curr.push_back(result[i - 1][j] + result[i - 1][j + 1]);
             }
             curr.push_back(1);
         }
         result.push_back(curr);
     }
     return result;
 }
Ejemplo n.º 14
0
/// Return number of matching keys, and pos of first one as arg
int c4_View::Locate(const c4_RowRef& crit_, int* pos_) const
{
    // Dec 2001: fixed a problem with searching of partial rows.
    //
    // There is an *extremely* tricky issue in here, in that the
    // comparison operator for rows is not symmetric.  So in the
    // general case, "a == b" is not euivalent to "b == a".  This
    // is without doubt a design mistake (and should have at least
    // been named differently).
    //
    // The reason is that the number of properties in both rowrefs
    // need not be the same.  Only the properties of the leftmost
    // rowref are compared against the other one.  This also applies
    // to the other comparisons, i.e. !=, <, >, <=, and >=.
    //
    // All Compare calls below have been changed to use comparisons
    // in the proper order and now use "rowref <op> rowref" syntax.

  c4_Cursor curr (*(c4_Sequence*) _seq, 0); // loses const

  int l = -1, u = GetSize();
  while (l + 1 != u) {
    curr._index = (l + u) >> 1;
    if (crit_ > *curr)
      l = curr._index;
    else
      u = curr._index;
  }

  if (pos_ != 0)
    *pos_ = u;

    // only look for more if the search hit an exact match
  curr._index = u;
  if (u == GetSize() || crit_ != *curr)
    return 0;

    // as Jon Bentley wrote in DDJ Apr 2000, setting l2 to -1 is better than u
  int l2 = -1, u2 = GetSize();
  while (l2 + 1 != u2) {
    curr._index = (l2 + u2) >> 1;
    if (crit_ >= *curr)
      l2 = curr._index;
    else
      u2 = curr._index;
  }

  return u2 - u;
}
Ejemplo n.º 15
0
   TemplateTracker::Result TemplateTracker::track(const Img8u &image, 
                                                  const Result *initialResult,
                                                  std::vector<Result> *allResults){
     Result last = initialResult ? *initialResult : data->lastResult;
     if(last.pos == Point32f(-1,-1)){
       last.pos = Point(image.getWidth()/2,image.getHeight()/2); 
     }
     
     const double angle = last.angle;
     const int X = last.pos.x;
     const int Y = last.pos.y;
     const int lutSize = (int)data->lut.size();
     const int angleIndex = angle / (2*M_PI) * (lutSize-1);
     const int ROI = getPropertyValue("tracking.position range");
     const float rotationRange = getPropertyValue("tracking.rotation range");
     const int step1 = getPropertyValue("tracking.coarse steps");
     //const int step2 = getPropertyValue("tracking.fine steps");
     //const float angleStepSize = 360./lutSize;
 
     const Rect roi(X - ROI/2, Y-ROI/2, ROI, ROI);
     
     SmartPtr<const Img8u> roiImageTmp = image.shallowCopy(roi);
     SmartPtr<Img8u> roiImage = roiImageTmp->deepCopyROI();
 
     const int stepRadius = lutSize * rotationRange/720;
 
     Result bestResult = last;
     for(int i = -stepRadius; i <= stepRadius; i+= step1){
       int curIndex = angleIndex + i;
       while(curIndex >= lutSize) curIndex -= lutSize;
       while(curIndex < 0) curIndex += lutSize;
       
       data->prox->apply(roiImage.get(),data->lut.at(curIndex).get(),&data->buf);
       
       Point maxPos;
       float maxValue = data->buf->getMax(0,&maxPos);
     
       Result curr(maxPos+last.pos,
                   (float(curIndex)/lutSize) * 2 * M_PI, 
                   maxValue,
                   data->lut.at(curIndex).get());
       if(curr.proximityValue > bestResult.proximityValue){
         bestResult = curr;
       }
       if(allResults) allResults->push_back(curr);
     }
     data->lastResult = bestResult;
     return bestResult;
   }
Ejemplo n.º 16
0
	bool poseTracker::newPose(tf::StampedTransform transform){
		
		Eigen::Vector3f curr(transform.getOrigin().x(), transform.getOrigin().y(), transform.getOrigin().z());
		pose.push(curr);
		if(pose.size() < 50){
			return true;
		}

		float squaredNorm = (pose.front() - curr).squaredNorm();
		pose.pop();
		bool tmp = squaredNorm > 0.2;
		std::cout << tmp << "  Max: " << squaredNorm << std::endl;
		return squaredNorm > 0.2;

	}
Ejemplo n.º 17
0
vector<Action> Board::GetPossibleActions(Turn turn)
{
    vector<Action> actions;
    for (int y=0 ; y<kStageHeight ; y++) {
        for (int x=0 ; x<kStageWidth ; x++) {
            if ( IsMovableUnit(stage[y][x], turn) ) {
                Pos curr(x,y);
                vector<Pos> candidates = GetMovableCanditates(curr);
                for (Pos p : candidates)
                    actions.push_back(Action(curr, p));
            }
        }
    }
    return actions;
}
Ejemplo n.º 18
0
    /// run all tests
    void run_tests(void) throw() {

        printf("\nTesting...\n");

        for(detail::TestBase *curr(detail::TestBase::first_test);
            0 != curr;
            curr = curr->next) {
            curr->run_test();
        }

        printf("\n");
        printf("Number of tests: %u\n", detail::TestBase::num_tests);
        printf("         passed: %u\n", detail::TestBase::num_passed);
        printf("         failed: %u\n\n", detail::TestBase::num_failed);
    }
Ejemplo n.º 19
0
int main(int, char**){
    test curr = tests[0];
    int i = 0;
    std::cout << "Running tests" << std::endl;
    while (curr != NULL)
    {
        curr();
        ++i;
        curr = tests[i];
        std::cout << ".";
    }
    std::cout << std::endl;
    std::cout << "Ran " << i << " tests" << std::endl;
    return 0;
}
Ejemplo n.º 20
0
void splittext(const char *text, u32t width, TStrings &lst, u32t flags) {
   lst.Clear();
   if (!text || width<8) return;
   const char *ps = text, *pps;
   char    softcr = flags&SplitText_HelpMode?'&':0;
   int         ln = 0;
   spstr linehead;
   lst.Add(spstr());
   do {
      while (*ps && (strchr(AllowSet,*ps) || *ps==softcr)) {
         register char cr=*ps++;
         if (cr!=' ') {
            if (cr==softcr) {
               pps = ps;
               if (*pps) pps++;
               while (*pps==' ' || *pps=='\t') pps++;
               /* get 1 char after eol and all spaces after it and use result
                  as a header for all next lines until real cr */
               linehead = spstr(ps, pps-ps).expandtabs(4);
               ps = pps;
            } else {
               lst.Add(spstr());
               if (cr=='\r' && *ps=='\n') ps++;
               linehead.clear();
               if (lst[ln].lastchar()==' ') lst[ln].dellast();
               ln++;
            }
         }
      }
      if (*ps==0) break;
      pps = strpbrk(ps, softcr ? CarrySet AllowSet "&" : CarrySet AllowSet);
      int carry = pps&&strchr(CarrySet,*pps)?1:0;
      spstr curr(ps,pps?pps-ps+carry:0), sum;
      sum = lst[ln]+curr;
      sum.expandtabs(4);

      if ((flags&SplitText_NoAnsi?strlen:str_length)(sum())<width-2)
         lst[ln]=sum;
      else {
         lst.Add(linehead+curr);
         if (lst[ln].lastchar()==' ') lst[ln].dellast();
         ln++;
      }
      if (!carry||pps&&pps[1]==' ') lst[ln]+=' ';
      ps=pps;
      if (carry) ps++;
   } while (pps);
}
Ejemplo n.º 21
0
int64_t Problem71::solve()
{
    Fraction limit(3, 7);
    Fraction max(0, 1);
    Primes primes(PROBLEM_SIZE);
    
    for(int i = 8; i <= PROBLEM_SIZE; ++i)
    {
        Fraction curr(limit * i, i);
        if(curr < max)
            continue;
        else if(curr.isProperFraction(primes))
            max = curr;
    }
    return max.getNumerator();
}
Ejemplo n.º 22
0
/**
==================== Stmts ============================================
   Grammar:
      stmts : stmt stmts |  e
*/
static TreeStmts p_stmts(void) {
   TreeStmts stmts = 0; // set null by default
   TokenCode code = curr()->code;
   // body
   TreeStmt l0stmt = p_stmt()
   
   // check if we have next production
   if ( l0stmt == 0 ) 
      return stmts;

   TreeStmts l1stmts = p_stmts();
   stmts = t_stmts_stmt(l0stmt, l1stmts);

   
   return stmts;
}
Ejemplo n.º 23
0
bool FlingAnimator::update()
{
    JNIEnv* env = m_javaScroller.env();
    if (!env->CallBooleanMethod(m_javaScroller.obj(), m_computeMethodId)) {
        CheckException(env);
        stop();
        return false;
    }
    WebCore::IntSize curr(env->CallIntMethod(m_javaScroller.obj(), m_getXMethodId),
                 env->CallIntMethod(m_javaScroller.obj(), m_getYMethodId));
    CheckException(env);

    m_scrollController->scrollBy(curr - m_last);
    m_last = curr;
    return true;
}
Ejemplo n.º 24
0
bool DropScriptTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
{
	size_t nFiles = filenames.GetCount();
    for ( size_t n = 0; n < nFiles; n++ ) 
	{
		wxFileName curr(filenames[n]);
		if( (curr.GetExt().CmpNoCase(_T("smil")) == 0)
			|| (curr.GetExt().CmpNoCase(_T("apml")) == 0) )
		{
			m_pOwner->LoadScriptFile(curr);
			return true;
		}
    }
	
	return false;
}
Ejemplo n.º 25
0
void BVH::buildAccelStructure(const std::vector<Shape*>& sceneData){
    Assert(scene.empty());

    //Get bounding boxes for each shape
    scene.reserve(sceneData.size()); //Reserve space ahead of time to avoid realloc's
    for(size_t i = 0; i < sceneData.size(); i++){
        //Bound current primitive
        BoundingBox currBBox = sceneData[i]->worldSpaceBound();
        //Add bbox and shape to list
        BVH::ShapeWBound curr(sceneData[i], currBBox);
        scene.push_back(curr);
    }

    //Build tree recursively in a top down manner
    root = buildTreeRecursive(0, scene.begin(), scene.end());
}
Ejemplo n.º 26
0
/**
==================== Decls ============================================
   Grammar:
      decls : decl decls |  e
*/
static TreeDecls p_decls(void) {
   TreeDecls decls = 0; // set null by default
   TokenCode code = curr()->code;
   // body
   TreeDecl l0decl = p_decl()
   
   // check if we have next production
   if ( l0decl == 0 ) 
      return decls;

   TreeDecls l1decls = p_decls();
   decls = t_decls_decl(l0decl, l1decls);

   
   return decls;
}
Ejemplo n.º 27
0
inline void TR_charsImp::convert(vector<int> &from, vector< Ptr<Object> > &to, vector<int> &allLabels, vector<string> &allNames)
{
    for (vector<int>::iterator it=from.begin(); it!=from.end(); ++it)
    {
        if (*it>=(int)allNames.size() || *it>=(int)allLabels.size())
        {
            printf("incorrect index: %u\n", *it);
            continue;
        }

        Ptr<TR_charsObj> curr(new TR_charsObj);
        curr->imgName = allNames[*it];
        curr->label = allLabels[*it];
        to.push_back(curr);
    }
}
Ejemplo n.º 28
0
    int uniquePaths(int m, int n) {
        if (m==0||n==0) return 0;
        vector<int> prev(m);
        prev[0]=1;
        for (int i=1; i<n; i++) {
        	vector<int> curr(m);
        	for (int j=0; j<m; j++) {
        		if (j>0) curr[j]+=prev[j-1];
        		if (j<m-1) curr[j]+=prev[j+1];
        		curr+=prev[j];
        	}
        	prev=curr;
        }

        return prev[0];
    }
Ejemplo n.º 29
0
void scanner::move_back(unsigned offset, unsigned u_offset) {
    lean_assert(m_uskip == 0);
    if (offset != 0) {
        if (curr() == EOF) {
            m_curr = 0;
            m_spos--;
            m_upos--;
            offset--;
            u_offset--;
        }
        if (offset != 0) {
            m_spos -= offset;
            m_upos -= u_offset;
        }
        next();
    }
}
Ejemplo n.º 30
0
void DictEngine::getDicts()
{
    QMap<QString, QString> theHash;
    m_tcpSocket->readAll();
    QByteArray ret;

    m_tcpSocket->write(QByteArray("SHOW DB\n"));;
    m_tcpSocket->flush();

    m_tcpSocket->waitForReadyRead();
    while (!ret.contains("250")) {
        m_tcpSocket->waitForReadyRead();
        ret += m_tcpSocket->readAll();
    }

    QList<QByteArray> retLines = ret.split('\n');
    QString tmp1, tmp2;

    while (!retLines.empty()) {
        QString curr(retLines.takeFirst());

        if (curr.startsWith(QLatin1String("554"))) {
            //TODO: What happens if no DB available?
            //TODO: Eventually there will be functionality to change the server...
            break;
        }

        // ignore status code and empty lines
        if (curr.startsWith(QLatin1String("250")) || curr.startsWith(QLatin1String("110"))
                || curr.isEmpty()) {
            continue;
        }

        if (!curr.startsWith('-') && !curr.startsWith('.')) {
            curr = curr.trimmed();
            tmp1 = curr.section(' ', 0, 0);
            tmp2 = curr.section(' ', 1);
            //          theHash.insert(tmp1, tmp2);
            //qDebug() << tmp1 + "  " + tmp2;
            setData(QStringLiteral("list-dictionaries"), tmp1, tmp2);
        }
    }

    m_tcpSocket->disconnectFromHost();
//    setData("list-dictionaries", "dictionaries", QByteArray(theHash);
}