Ejemplo n.º 1
0
Stream::ptr
Connection::getStream(const GeneralHeaders &general,
    const EntityHeaders &entity, const std::string &method, Status status,
    boost::function<void()> notifyOnEof,
    boost::function<void()> notifyOnException, bool forRead)
{
    MORDOR_ASSERT(hasMessageBody(general, entity, method, status));
    Stream::ptr stream;
    if (forRead) {
        stream.reset(new SingleplexStream(m_stream, SingleplexStream::READ, false));
    } else {
        stream.reset(new SingleplexStream(m_stream, SingleplexStream::WRITE, false));
    }
    Stream::ptr baseStream(stream);
    for (ParameterizedList::const_reverse_iterator it(general.transferEncoding.rbegin());
        it != general.transferEncoding.rend();
        ++it) {
        if (stricmp(it->value.c_str(), "chunked") == 0) {
            stream.reset(new ChunkedStream(stream));
        } else if (stricmp(it->value.c_str(), "deflate") == 0) {
            stream.reset(new ZlibStream(stream));
        } else if (stricmp(it->value.c_str(), "gzip") == 0 ||
            stricmp(it->value.c_str(), "x-gzip") == 0) {
            stream.reset(new GzipStream(stream));
        } else if (stricmp(it->value.c_str(), "compress") == 0 ||
            stricmp(it->value.c_str(), "x-compress") == 0) {
            MORDOR_ASSERT(false);
        } else if (stricmp(it->value.c_str(), "identity") == 0) {
            MORDOR_ASSERT(false);
        } else {
            MORDOR_ASSERT(false);
        }
    }
    if (stream != baseStream) {
    } else if (entity.contentLength != ~0ull) {
        LimitedStream::ptr limited(new LimitedStream(stream, entity.contentLength));
        limited->strict(true);
        stream = limited;
    } else if (entity.contentType.type == "multipart") {
        // Getting stream to pass to multipart; self-delimiting
    } else {
        // Delimited by closing the connection
    }
    NotifyStream::ptr notify(new NotifyStream(stream));
    stream = notify;
    notify->notifyOnClose = notifyOnEof;
    notify->notifyOnEof = notifyOnEof;
    notify->notifyOnException = notifyOnException;
    return stream;
}
Ejemplo n.º 2
0
int main()
{
    int base, exp, logNum, lineNum, max, maxLine;
    lineNum = 0;
    max = 0;
    maxLine = 0;
    
    ifstream baseExpPairs ("base_exp.txt");
    string line;
    
    while (getline(baseExpPairs, line)){
        istringstream tokenizer(line);
        string token;
        lineNum++;

        getline(tokenizer, token, ',');
        istringstream baseStream(token);
        baseStream >> base;
        
        getline(tokenizer, token, ',');
        istringstream expStream(token);
        expStream >> exp;
        
        logNum = exp * log(base);
        
        if (logNum > max){
            max = logNum;
            maxLine = lineNum;
        }
    }
    
    baseExpPairs.close();
    cout << maxLine << endl;
    
    return 0;
}
Ejemplo n.º 3
0
    FileList enroll(File input, File gallery = File())
    {
        FileList files;

        qDebug("Enrolling %s%s", qPrintable(input.flat()),
               gallery.isNull() ? "" : qPrintable(" to " + gallery.flat()));

        if (gallery.name.isEmpty()) {
            if (input.name.isEmpty()) return FileList();
            else                      gallery = getMemoryGallery(input);
        }

        bool multiProcess = Globals->file.getBool("multiProcess", false);
        bool fileExclusion = false;

        // In append mode, we will exclude any templates with filenames already present in the output gallery
        if (gallery.contains("append") && gallery.exists() ) {
            FileList::fromGallery(gallery,true);
            fileExclusion = true;
        }

        Gallery * temp = Gallery::make(input);
        qint64 total = temp->totalSize();

        Globals->currentStep = 0;
        Globals->totalSteps = total;

        QScopedPointer<Transform> basePipe;

        QString pipeDesc = "GalleryOutput("+gallery.flat()+")+ProgressCounter("+QString::number(total)+")+Discard";

        if (!multiProcess) {
            basePipe.reset(Transform::make(pipeDesc,NULL));
            CompositeTransform * downcast = dynamic_cast<CompositeTransform *>(basePipe.data());

            if (downcast == NULL) qFatal("downcast failed?");

            downcast->transforms.prepend(this->transform.data());
            if (fileExclusion) {
                Transform * temp = Transform::make("FileExclusion(" + gallery.flat() + ")", downcast);
                downcast->transforms.prepend(temp);
            }

            // call init on the pipe to collapse the algorithm (if its top level is a pipe)
            downcast->init();
        }
        else {
            pipeDesc = "ProcessWrapper("+transformString+")"+pipeDesc;
            if (fileExclusion)
                pipeDesc = "FileExclusion(" + gallery.flat() +")" + pipeDesc;

            basePipe.reset(Transform::make(pipeDesc,NULL));
        }

        // Next, we make a Stream (with placeholder transform)
        QString streamDesc = "Stream(readMode=StreamGallery)";
        QScopedPointer<Transform> baseStream(Transform::make(streamDesc, NULL));
        WrapperTransform * wrapper = dynamic_cast<WrapperTransform *> (baseStream.data());

        // replace that placeholder with the pipe we built
        wrapper->transform = basePipe.data();

        // and get the final stream's stages by reinterpreting the pipe. Perfectly straightforward.
        wrapper->init();

        Globals->startTime.start();

        TemplateList data, output;
        data.append(input);
        wrapper->projectUpdate(data, output);

        files.append(output.files());

        return files;
    }