Esempio n. 1
0
void Engine::InjectCollective(istream& X, bool diversifyFlag)
{
    if (phase != fresh)
        throw Exception("The phase must be fresh to call Engine::InjectCollective().");
    stringstream *Xt = new stringstream[Pi];
    while(hasMore(X)) {
        UINT8 x = X.get();
        for(unsigned int i=0; i<Pi; i++)
            Xt[i].put(x);
    }
    if (diversifyFlag) {
        for(unsigned int i=0; i<Pi; i++) {
            Xt[i].put(enc8(Pi));
            Xt[i].put(enc8(i));
        }
    }
    for(unsigned int i=0; i<Pi; i++)
        Xt[i].seekg(0, ios_base::beg);
    while(hasMore(Xt[0])) {
        for(unsigned int i=0; i<Pi; i++)
            Pistons[i].Inject(Xt[i], 0);
        if (hasMore(Xt[0]))
            Spark(false, vector<unsigned int>(Pi, 0));
    }
    phase = endOfMessage;
    delete[] Xt;
}
Esempio n. 2
0
void Preprocessor::parseMultiLineComment()
{
  advance(2);
  setFirstOnLine(false);

  for (;;)
  {
    if (!hasMore())
    {
      logError("%s:%u: Unexpected end of file in multi-line comment",
               files.back().name,
               files.back().line);

      throw Exception("Unexpected end of file in multi-line comment");
    }

    if (c(0) == '*' && c(1) == '/')
    {
      advance(2);
      break;
    }
    else if (isNewLine())
      parseNewLine();
    else
      advance(1);
  }

  appendToOutput();
}
Esempio n. 3
0
std::string BinaryInput::readStringEven() {
    std::string x = readString();
    if (hasMore() && (G3D::isOdd(x.length() + 1))) {
        skip(1);
    }
    return x;
}
void lemur::parse::BasicTokenDoc::skipToEnd() const
{
  startTermIteration();
  while (hasMore()) {
    nextTerm();
  }
}
Esempio n. 5
0
/**
 * \brief Populates \a s with chars from \a cache or stdin.
 *
 * First, if there are characters in the \a cache, they are moved to
 * \a s. Then gets chars from stdin until a \a newline or EOF is
 * encountered.
 * \param[in,out] s The current line.
 * \param[in]   max The maximum size of the current line.
 */
void getLine(char s[], int max)
{
    int c;
    int i = 0;
    int len = strLen(cache);
    if (len > 0) {
        for ( ; i < len; i++) {
            s[i] = cache[i];
            cache[i] = '\0';
        }
    }

    while (i < max && hasMore()) {
        c = getchar();
        if (c == EOF) {
            more = FALSE;
            break;
        } else if (c == '\n' && i == 0) {
            break;
        } else if (c == '\n') {
            c = s[i-1];
            break;
        } else {
            s[i] = c;
        }
        i++;
    }
    s[i] = '\0';
}
Esempio n. 6
0
String Preprocessor::passShaderName()
{
  char terminator;
  if (c(0) == '<')
    terminator = '>';
  else if (c(0) == '\"')
    terminator = '\"';
  else
  {
    logError("%s:%u: Expected \'<\' or \'\"\' after #include",
             files.back().name,
             files.back().line);

    throw Exception("Expected \'<\' or \'\"\' after #include");
  }

  advance(1);

  String name;

  while (hasMore())
  {
    if (!hasMore() || isNewLine())
    {
      logError("%s:%u: Expected \'%c\' after shader name",
               files.back().name,
               files.back().line,
               terminator);

      throw Exception("Expected \'<\' or \'\"\' after shader name");
    }

    if (c(0) == terminator)
    {
      advance(1);
      break;
    }
    else
    {
      name.append(1, c(0));
      advance(1);
    }
  }

  return name;
}
Esempio n. 7
0
ChEXPORT EshOpt::PID EshOpt::PIDEnumerator::getNext ()
{
    ChLOG_DEBUG_START_FN;
    ChASSERT(hasMore());
    PID pid = (PID) m_crt->first;
    m_crt++;
    return pid;
}
Esempio n. 8
0
void BinaryInput::beginBits() {
    debugAssert(beginEndBits == 0);
    beginEndBits = 1;
    bitPos = 0;

    debugAssertM(hasMore(), "Can't call beginBits when at the end of a file");
    bitString = readUInt8();
}
Esempio n. 9
0
bool Motorist::Wrap(istream& I, stringstream& O, istream& A, stringstream& T, bool unwrapFlag, bool forgetFlag)
{
    if (phase != riding)
        throw Exception("The phase must be riding to call Motorist::Wrap().");
    if ((!hasMore(I)) && (!hasMore(A)))
        engine.Inject(A);
    while(hasMore(I)) {
        engine.Crypt(I, O, unwrapFlag);
        engine.Inject(A);
    }
    while(hasMore(A))
        engine.Inject(A);
    if ((Pi > 1) || forgetFlag)
        MakeKnot();
    bool res = HandleTag(true, T, unwrapFlag);
    if (!res)
        O.str(string(""));
    return res;
}
Esempio n. 10
0
    /**
     * @param buf Destination buffer
     * @param n   Maximum number of characters to read
     * @return    The number of characters read
     */
    int read(char *buf, int n) {
		int pos = 0;
		while (pos<n && hasMore()) {
			for (; nxt<bn && pos<n; ++pos, ++nxt) {
				buf[pos] = internal_buf[nxt];
			}
		}

		return pos;
    }
Esempio n. 11
0
String
StreamReader::read ()
{
	String ret;
	while (hasMore ()) {
		ret += readChar ();
	}

	return ret;
}
Esempio n. 12
0
 void debug()
 {
     cout << "---- query ----" << endl;
     startIteration();
     while (hasMore()) {
         lemur::api::QueryTerm *qt = nextTerm();
         cerr << qt->id() << ":" << ind.term(qt->id()) << ":" << qt->weight() << endl;
         delete qt;
     }  
 }
/** Finds if there are any more instances to be returned by NextL()

Checks if there are any more instances in the cached instance list
if there is not it does a next instance call to find id there are more
instances after the cache

@return ETrue if there are more instances to be returned and EFalse if not or if there was a problem.

@internalComponent
*/
TBool CCalInstanceIteratorAll::HasMore() const
	{
	TBool hasMore(ETrue);
	// HasMore can't leave so we simply return EFalse if there is an error
	TRAPD(err, hasMore = HasMoreL());
	if (err != KErrNone)
		{
		hasMore = EFalse;
		}
	return hasMore;
	}
Esempio n. 14
0
                void expandQueryByMap(std::map<int,double>& fb, double origModCoeff) {
                    if (!qm) {
                        qm = new lemur::api::IndexedRealVector();
                    } else {
                        qm->clear();
                    }
                   
                    cout << "stage 1" << endl;
                    debug();

					std::map<int,double>::iterator it;
					for(it=fb.begin();it!=fb.end();++it)
					{
						int termID = it->first;
                        IndexedReal entry;
 
                        if(!include(termID))   {
                            entry.ind = termID;
                            entry.val = 0;
                            qm->push_back(entry);
                        }
					}    
                    
                    cout << "stage 2" << endl;
                    debug();

                    // get original query term count
                    double countSum = totalCount();
                    startIteration();
                    while (hasMore()) {
                        lemur::api::QueryTerm *qt = nextTerm();
                        setCount(qt->id(), qt->weight()*origModCoeff/countSum);
                        delete qt;
                    }    
                    
                    cout << "stage 3" << endl;
                    debug();


					for(it=fb.begin();it!=fb.end();++it)
					{
						int termID = it->first;
						double score = it->second;
						incCount(termID, score*(1.0-origModCoeff));
					}
                    
                    cout << "stage 4" << endl;
                    debug();

                    //Sum w in Q qtf * log(qtcf/termcount);
                    colQLikelihood = 0;
                    colQueryLikelihood();
                    colKLComputed = false;     
				}
Esempio n. 15
0
void Engine::Crypt(istream& I, ostream& O, bool unwrapFlag)
{
    if (phase != fresh)
        throw Exception("The phase must be fresh to call Engine::Crypt().");
    for(unsigned int i=0; i<Pi; i++)
        Pistons[i].Crypt(I, O, Et[i], unwrapFlag);
    if (hasMore(I))
        phase = crypted;
    else
        phase = endOfCrypt;
}
Esempio n. 16
0
int main()
{
    char line[MAX] = {0}; /**<  */

    while (hasMore()) {
        getLine(line, MAX);
        if (strLen(line) > SIZE)
            fold(line, SIZE, HOT);
        printf("%s\n", line);
    }
    return 0;
}
Esempio n. 17
0
                void expandQuery(MyQueryModel &exRep, double origModCoeff) {
                    if (!qm) {
                        qm = new lemur::api::IndexedRealVector();
                    } else {
                        qm->clear();
                    }

                    // get original query term count
                    double countSum = totalCount();

                    // add expand query's term, init weight as zero
                    exRep.startIteration();
                    while (exRep.hasMore()) {
                        lemur::api::QueryTerm *qt = exRep.nextTerm();
                        IndexedReal entry;
                        if(!include(qt->id()))   {
                            entry.ind = qt->id();
                            //entry.val = qt->weight();
                            entry.val = 0;
                            qm->push_back(entry);
                        }
                        delete qt;
                    }
                    qm->Sort();
                    // cout << "after push words" << endl;
                    // cout << "original total count = " << totalCount() << endl;
                    // debug();

                    // discounting the original model
                    startIteration();
                    while (hasMore()) {
                        lemur::api::QueryTerm *qt = nextTerm();
                        setCount(qt->id(), qt->weight()*origModCoeff/countSum);
                        delete qt;
                    }    
                    // debug();

                    // now adding the new model
                    double exCountSum = exRep.totalCount();
                    exRep.startIteration();
                    while (exRep.hasMore()) {
                        lemur::api::QueryTerm *qt = exRep.nextTerm();
                        incCount(qt->id(), qt->weight()*(1.0-origModCoeff)/exCountSum);
                        delete qt;
                    }
                    debug();

                    //Sum w in Q qtf * log(qtcf/termcount);
                    colQLikelihood = 0;
                    colQueryLikelihood();
                    colKLComputed = false;      
                }
Esempio n. 18
0
 bool include(int termId)
 {
     startIteration();
     while (hasMore()) {
         lemur::api::QueryTerm *qt = nextTerm();
         if(qt->id() == termId) {
             delete qt;
             return true;
         }
         delete qt;
     }  
     return false;
 }
Esempio n. 19
0
void Piston::Crypt(istream& I, ostream& O, unsigned int omega, bool unwrapFlag)
{
    while(hasMore(I) && (omega < Rs)) {
        UINT8 x = I.get();
        O.put(state.get()[omega] ^ x);
        if (unwrapFlag)
            state.get()[omega] = x;
        else
            state.get()[omega] ^= x;
        omega++;
    }
    state.get()[CryptEnd] ^= enc8(omega);
}
Esempio n. 20
0
void ThreadQueue::onStarted()
{
    Runnable* r;

    // qDebug() << "has started";

    while ((r = hasMore()) != NULL)
    {
        //qDebug() << "executing next from list" << r->name();
        QVariant result = r->run();
        emit     finished(r, result);
    }
    thread()->quit();
}
Esempio n. 21
0
                void interpolateWith(const lemur::langmod::UnigramLM &qModel,
                            double origModCoeff,
                            int howManyWord,
                            double prSumThresh,
                            double prThresh) {
                    if (!qm) {
                        qm = new lemur::api::IndexedRealVector();
                    } else {
                        qm->clear();
                    }

                    qModel.startIteration();
                    while (qModel.hasMore()) {
                        IndexedReal entry;
                        qModel.nextWordProb((TERMID_T &)entry.ind,entry.val);
                        qm->push_back(entry);

                    }
                    qm->Sort();

                    double countSum = totalCount();


                    startIteration();
                    while (hasMore()) {
                        QueryTerm *qt = nextTerm();
                        setCount(qt->id(), qt->weight()*origModCoeff/countSum);
                        delete qt;
                    }

                    cout << "-------- FB terms --------" << endl;
                    double prSum = 0;
                    int wdCount = 0;
                    IndexedRealVector::iterator it;
                    it = qm->begin();
                    while (it != qm->end() && prSum < prSumThresh &&
                                wdCount < howManyWord && (*it).val >=prThresh) {
                        incCount((*it).ind, (*it).val*(1-origModCoeff));
                        cout << ind.term(it->ind) << endl;
                        prSum += (*it).val;
                        it++;
                        wdCount++;
                    }
                    cout << "--------------------------" << endl;


                    colQLikelihood = 0;
                    colQueryLikelihood();
                    colKLComputed = false;
                }
Esempio n. 22
0
void Engine::Inject(istream& A)
{
    if ((phase != fresh) && (phase != crypted) && (phase != endOfCrypt))
        throw Exception("The phase must be fresh, crypted or endOfCrypt to call Engine::Inject().");
    bool cryptingFlag = (phase == crypted) || (phase == endOfCrypt);
    for(unsigned int i=0; i<Pi; i++)
        Pistons[i].Inject(A, cryptingFlag);
    if ((phase == crypted) || hasMore(A)) {
        Spark(false, vector<unsigned int>(Pi, 0));
        phase = fresh;
    }
    else
        phase = endOfMessage;
}
Esempio n. 23
0
void Piston::Inject(istream& X, bool cryptingFlag)
{
    unsigned int omega;
    if (cryptingFlag)
        omega = Rs;
    else
        omega = 0;
    state.get()[InjectStart] ^= enc8(omega);
    while(hasMore(X) && (omega < Ra)) {
        state.get()[omega] ^= X.get();
        omega++;
    }
    state.get()[InjectEnd] ^= enc8(omega);
}
Esempio n. 24
0
void Preprocessor::parseSingleLineComment()
{
  advance(2);
  setFirstOnLine(false);

  while (hasMore())
  {
    if (isNewLine())
      break;
    else
      advance(1);
  }

  appendToOutput();
}
Esempio n. 25
0
int main(int argc, char *argv[]) {
  list *l = mkList();
  append(l, mkIntCell(1));
  append(l, mkIntCell(4));
  append(l, mkIntCell(91));
  iterator *i = mkIterator(l);
  int sum = 0;
  while (hasMore(i)) {
    sum += *(int*) next(i);
  }
  printf("Summa: %d\n", sum);
  rmIterator(i);
  rmList(l);
  return 0;
}
Esempio n. 26
0
void AnyTableReader::verifyDone() const {
    if (hasMore()) {
        // Some entries were unread.  Find them.
        const Table<String, Any>& table = m_any.table();

        for (Table<String, Any>::Iterator it = table.begin();
            it.hasMore();
            ++it) {
            
            if (containsUnread(it->key)) {
                it->value.verify(false, String("Unread Any table key \"") + it->key + "\"");
            }
        }
    }
}
Esempio n. 27
0
void Preprocessor::parse(const char* name, const char* text)
{
  if (std::find(names.begin(), names.end(), name) != names.end())
    return;

  files.push_back(File(name, text));
  names.push_back(name);

  list += format("( file %u: %s )\n", (uint) names.size(), name);

  output.reserve(output.size() + std::strlen(text));
  appendToOutput(format("#line 0 %u /* entering %s */\n",
                        (uint) files.size(),
                        files.back().name).c_str());

  while (hasMore())
  {
    if (isMultiLineComment())
      parseMultiLineComment();
    else if (isSingleLineComment())
      parseSingleLineComment();
    else if (isNewLine())
      parseNewLine();
    else if (isWhitespace())
      parseWhitespace();
    else if (isCommand())
      parseCommand();
    else
    {
      advance(1);
      appendToOutput();
      setFirstOnLine(false);
    }
  }

  files.pop_back();

  if (!files.empty())
  {
    appendToOutput(format("\n#line %u %u /* returning to %s */",
                          files.back().line,
                          (uint) files.size(),
                          files.back().name).c_str());
  }
}
Esempio n. 28
0
void Preprocessor::parseCommand()
{
  advance(1);
  setFirstOnLine(false);
  passWhitespace();

  const String command = passIdentifier();
  if (command == "include")
  {
    passWhitespace();
    const String name = passShaderName();
    discard();
    parse(name.c_str());
  }
  else if (command == "version")
  {
    if (!version.empty())
    {
      logError("%s:%u: Duplicate #version directive",
               files.back().name,
               files.back().line);

      throw Exception("Duplicate #version directive");
    }

    passWhitespace();
    version = passNumber();
    discard();
  }

  while (hasMore())
  {
    if (isNewLine() || isSingleLineComment() || isMultiLineComment())
      break;

    advance(1);
  }

  appendToOutput();
}
TBool CCalInstanceIteratorAll::HasMoreL() const
	{
	TBool hasMore(ETrue);
	
	if (iCurrentIndex >= iInstanceIdCache->Count() - 1)
		{
		// There are no more instances in the cache
		// so find out if there are more in the store
		
		CArrayFixSeg<TAgnInstance>* instances = new(ELeave) CArrayFixSeg<TAgnInstance>(1);
		CleanupStack::PushL(instances);
		
		if (iInstanceIdCache->Count() != 0)
			{
			// we have already got some instances so fetch from there
			iFindInstanceParams.iInstance = (*iInstanceIdCache)[iCurrentIndex];
			}
		else
			{
			// we have no instances so search from the start time
			iFindInstanceParams.iInstance.iId.SetDate(iFindInstanceParams.iRangeStart);
			iFindInstanceParams.iInstance.iCollectionId = 0;
			}
	
		iFindInstanceParams.iNumInstances = 256;
		RArray<TInt64> fileIds;
		iInstanceViewImpl.GetFileIdLC(fileIds);

		iInstanceViewImpl.GetServ().NextInstancesL(fileIds, *instances, iFindInstanceParams);
		CleanupStack::PopAndDestroy(&fileIds);
		hasMore = (instances->Count() != 0);
				
		CleanupStack::PopAndDestroy(instances);
		}
	
	return hasMore;
	}
Esempio n. 30
0
void Variable::handleProperty(const QDomElement &xml)
{
    Q_ASSERT(!xml.isNull());
    Q_ASSERT(xml.nodeName() == "property");

    setInScope(true);

    m_fullName = xml.attribute("fullname");
    //kDebug() << m_fullName;
    if (xml.firstChild().isText()) {
        QString v  = xml.firstChild().toText().data();
        if (xml.attribute("encoding") == "base64") {
            //TODO: use Connection::m_codec->toUnicode
            v = QString::fromUtf8(QByteArray::fromBase64(xml.text().toAscii()));
        }
        //kDebug() << "value" << v;
        setValue(v);
    }

    QMap<QString, Variable*> existing;
    for (int i = 0; i < childCount() - (hasMore() ? 1 : 0) ; i++) {
        Q_ASSERT(dynamic_cast<Variable*>(child(i)));
        Variable* v = static_cast<Variable*>(child(i));
        existing[v->expression()] = v;
    }

    QSet<QString> current;
    QDomElement el = xml.firstChildElement("property");
    while (!el.isNull()) {
        QString name = el.attribute("name");
        //kDebug() << name;
        current << name;
        Variable* v = 0;
        if( !existing.contains(name) ) {
            v = new Variable(model(), this, name);
            appendChild( v, false );
        } else {
            v = existing[name];
        }

        v->handleProperty(el);

        el = el.nextSiblingElement("property");
    }

    for (int i = 0; i < childCount() - (hasMore() ? 1 : 0); ++i) {
        Q_ASSERT(dynamic_cast<KDevelop::Variable*>(child(i)));
        KDevelop::Variable* v = static_cast<KDevelop::Variable*>(child(i));
        if (!current.contains(v->expression())) {
            removeChild(i);
            --i;
            delete v;
        }
    }
    if (!childCount() && xml.attribute("children") == "1") {
        kDebug() << "has more" << this;
        setHasMore(true);
        if (isExpanded()) {
            fetchMoreChildren();
        }
    }
}