當前位置: 首頁>>代碼示例>>C++>>正文


C++ FileWriter函數代碼示例

本文整理匯總了C++中FileWriter函數的典型用法代碼示例。如果您正苦於以下問題:C++ FileWriter函數的具體用法?C++ FileWriter怎麽用?C++ FileWriter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了FileWriter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: CallFunction

static FnCallResult CallFunction(EvalContext *ctx, const Policy *policy, const FnCall *fp, const Rlist *expargs)
{
    const Rlist *rp = fp->args;
    const FnCallType *fncall_type = FnCallTypeGet(fp->name);

    int argnum = 0;
    for (argnum = 0; rp != NULL && fncall_type->args[argnum].pattern != NULL; argnum++)
    {
        if (rp->val.type != RVAL_TYPE_FNCALL)
        {
            /* Nested functions will not match to lval so don't bother checking */
            SyntaxTypeMatch err = CheckConstraintTypeMatch(fp->name, rp->val,
                                                           fncall_type->args[argnum].dtype,
                                                           fncall_type->args[argnum].pattern, 1);
            if (err != SYNTAX_TYPE_MATCH_OK && err != SYNTAX_TYPE_MATCH_ERROR_UNEXPANDED)
            {
                FatalError(ctx, "In function '%s', error in variable '%s', '%s'", fp->name, (const char *)rp->val.item, SyntaxTypeMatchToString(err));
            }
        }

        rp = rp->next;
    }

    char output[CF_BUFSIZE];
    if (argnum != RlistLen(expargs) && !(fncall_type->options & FNCALL_OPTION_VARARG))
    {
        snprintf(output, CF_BUFSIZE, "Argument template mismatch handling function %s(", fp->name);
        {
            Writer *w = FileWriter(stderr);
            RlistWrite(w, expargs);
            FileWriterDetach(w);
        }

        fprintf(stderr, ")\n");

        rp = expargs;
        for (int i = 0; i < argnum; i++)
        {
            printf("  arg[%d] range %s\t", i, fncall_type->args[i].pattern);
            if (rp != NULL)
            {
                Writer *w = FileWriter(stdout);
                RvalWrite(w, rp->val);
                FileWriterDetach(w);
                rp = rp->next;
            }
            else
            {
                printf(" ? ");
            }
            printf("\n");
        }

        FatalError(ctx, "Bad arguments");
    }


    return (*fncall_type->impl) (ctx, policy, fp, expargs);
}
開發者ID:bahamat,項目名稱:cfengine-core,代碼行數:59,代碼來源:fncall.c

示例2: main

int main(int argc, char *argv[])
{
    EvalContext *ctx = EvalContextNew();
    GenericAgentConfig *config = CheckOpts(ctx, argc, argv);
    GenericAgentConfigApply(ctx, config);

    GenericAgentDiscoverContext(ctx, config);
    Policy *policy = GenericAgentLoadPolicy(ctx, config);
    if (!policy)
    {
        Log(LOG_LEVEL_ERR, "Input files contain errors.");
        exit(EXIT_FAILURE);
    }

    if (SHOWREPORTS)
    {
        ShowPromises(policy->bundles, policy->bodies);
    }

    switch (config->agent_specific.common.policy_output_format)
    {
    case GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_CF:
        {
            Policy *output_policy = ParserParseFile(config->input_file, config->agent_specific.common.parser_warnings,
                                                    config->agent_specific.common.parser_warnings_error);
            Writer *writer = FileWriter(stdout);
            PolicyToString(policy, writer);
            WriterClose(writer);
            PolicyDestroy(output_policy);
        }
        break;

    case GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_JSON:
        {
            Policy *output_policy = ParserParseFile(config->input_file, config->agent_specific.common.parser_warnings,
                                                    config->agent_specific.common.parser_warnings_error);
            JsonElement *json_policy = PolicyToJson(output_policy);
            Writer *writer = FileWriter(stdout);
            JsonWrite(writer, json_policy, 2);
            WriterClose(writer);
            JsonDestroy(json_policy);
            PolicyDestroy(output_policy);
        }
        break;

    case GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_NONE:
        break;
    }

    GenericAgentConfigDestroy(config);
    EvalContextDestroy(ctx);
}
開發者ID:nperron,項目名稱:core,代碼行數:52,代碼來源:cf-promises.c

示例3: QString

bool ValidatorGenerator::generate() const
{
    // Writes each files
    QString output = QString(VALIDATOR_HEADER_TEMPLATE).arg(name.toUpper()).arg(name);
    FileWriter(dstDir.filePath(name.toLower() + "validator.h")).write(output, false);

    output = QString(VALIDATOR_IMPL_TEMPLATE).arg(name.toLower()).arg(name);
    FileWriter(dstDir.filePath(name.toLower() + "validator.cpp")).write(output, false);

    // Updates the project file
    ProjectFileGenerator progen(dstDir.filePath("helpers.pro"));
    QStringList files;
    files << name.toLower() + "validator.h" << name.toLower() + "validator.cpp";
    return progen.add(files);
}
開發者ID:CasyWang,項目名稱:treefrog-framework,代碼行數:15,代碼來源:validatorgenerator.cpp

示例4: WriteReleaseIdFile

/**
 * @brief Writes a file with a contained release ID based on git SHA,
 *        or file checksum if git SHA is not available.
 * @param filename the release_id file
 * @param dirname the directory to checksum or get the Git hash
 * @return True if successful
 */
static bool WriteReleaseIdFile(const char *filename, const char *dirname)
{
    char release_id[GENERIC_AGENT_CHECKSUM_SIZE];

    bool have_release_id =
        GeneratePolicyReleaseID(release_id, sizeof(release_id), dirname);

    if (!have_release_id)
    {
        return false;
    }

    int fd = creat(filename, 0600);
    if (fd == -1)
    {
        Log(LOG_LEVEL_ERR, "While writing policy release ID file '%s', could not create file (creat: %s)", filename, GetErrorStr());
        return false;
    }

    JsonElement *info = JsonObjectCreate(3);
    JsonObjectAppendString(info, "releaseId", release_id);

    Writer *w = FileWriter(fdopen(fd, "w"));
    JsonWrite(w, info, 0);

    WriterClose(w);
    JsonDestroy(info);

    Log(LOG_LEVEL_VERBOSE, "Saved policy release ID file '%s'", filename);
    return true;
}
開發者ID:nishesj,項目名稱:core,代碼行數:38,代碼來源:generic_agent.c

示例5: WritePolicyValidatedFile

/**
 * @brief Writes a file with a contained timestamp to mark a policy file as validated
 * @param filename the filename
 * @return True if successful.
 */
static bool WritePolicyValidatedFile(ARG_UNUSED const GenericAgentConfig *config, const char *filename)
{
    if (!MakeParentDirectory(filename, true))
    {
        Log(LOG_LEVEL_ERR, "While writing policy validated marker file '%s', could not create directory (MakeParentDirectory: %s)", filename, GetErrorStr());
        return false;
    }

    int fd = creat(filename, 0600);
    if (fd == -1)
    {
        Log(LOG_LEVEL_ERR, "While writing policy validated marker file '%s', could not create file (creat: %s)", filename, GetErrorStr());
        return false;
    }

    JsonElement *info = JsonObjectCreate(3);
    JsonObjectAppendInteger(info, "timestamp", time(NULL));

    Writer *w = FileWriter(fdopen(fd, "w"));
    JsonWrite(w, info, 0);

    WriterClose(w);
    JsonDestroy(info);

    Log(LOG_LEVEL_VERBOSE, "Saved policy validated marker file '%s'", filename);
    return true;
}
開發者ID:nishesj,項目名稱:core,代碼行數:32,代碼來源:generic_agent.c

示例6: GenerateAvahiConfig

static int GenerateAvahiConfig(const char *path)
{
    FILE *fout;
    Writer *writer = NULL;
    fout = safe_fopen(path, "w+");
    if (fout == NULL)
    {
        Log(LOG_LEVEL_ERR, "Unable to open '%s'", path);
        return -1;
    }
    writer = FileWriter(fout);
    fprintf(fout, "<?xml version=\"1.0\" standalone='no'?>\n");
    fprintf(fout, "<!DOCTYPE service-group SYSTEM \"avahi-service.dtd\">\n");
    XmlComment(writer, "This file has been automatically generated by cf-serverd.");
    XmlStartTag(writer, "service-group", 0);
    FprintAvahiCfengineTag(fout);
    XmlStartTag(writer, "service", 0);
    XmlTag(writer, "type", "_cfenginehub._tcp",0);
    DetermineCfenginePort();
    XmlStartTag(writer, "port", 0);
    WriterWriteF(writer, "%d", CFENGINE_PORT);
    XmlEndTag(writer, "port");
    XmlEndTag(writer, "service");
    XmlEndTag(writer, "service-group");
    fclose(fout);

    return 0;
}
開發者ID:maciejmrowiec,項目名稱:core,代碼行數:28,代碼來源:cf-serverd-functions.c

示例7: GenerateAvahiConfig

static int GenerateAvahiConfig(const char *path)
{
    FILE *fout;
    Writer *writer = NULL;
    fout = fopen(path, "w+");
    if (fout == NULL)
    {
        CfOut(cf_error, "", "Unable to open %s", path);
        return -1;
    }
    writer = FileWriter(fout);
    fprintf(fout, "<?xml version=\"1.0\" standalone='no'?>\n");
    fprintf(fout, "<!DOCTYPE service-group SYSTEM \"avahi-service.dtd\">\n");
    XmlComment(writer, "This file has been automatically generated by cf-serverd.");
    XmlStartTag(writer, "service-group", 0);
#ifdef HAVE_NOVA
    fprintf(fout,"<name replace-wildcards=\"yes\" >CFEngine Enterprise %s Policy Hub on %s </name>\n", Version(), "%h");
#else
    fprintf(fout,"<name replace-wildcards=\"yes\" >CFEngine Community %s Policy Server on %s </name>\n", Version(), "%h");
#endif
    XmlStartTag(writer, "service", 0);
    XmlTag(writer, "type", "_cfenginehub._tcp",0);
    DetermineCfenginePort();
    XmlTag(writer, "port", STR_CFENGINEPORT, 0);
    XmlEndTag(writer, "service");
    XmlEndTag(writer, "service-group");
    fclose(fout);

    return 0;
}
開發者ID:cf-gary,項目名稱:core,代碼行數:30,代碼來源:cf-serverd-functions.c

示例8: XmlManual

void XmlManual(const char *mandir, FILE *fout)
{
    Writer *writer = NULL;
    int i;
    SubTypeSyntax *st = NULL;

    MANUAL_DIRECTORY = (char *) mandir;
    AddSlash(MANUAL_DIRECTORY);

    writer = FileWriter(fout);

/* XML HEADER */
    XmlComment(writer, "AUTOGENERATED SYNTAX DOCUMENTATION BY CF-KNOW");
    WriterWrite(writer, "\n");

/* START XML ELEMENT -- SYNTAX-DOCUMENTATION */
    XmlStartTag(writer, XMLTAG_DOC_ROOT, 0);

/* SPECIAL VARIABLES */
    XmlStartTag(writer, XMLTAG_VARSCOPES_ROOT, 0);
    XmlExportVariables(writer, "const");
    XmlExportVariables(writer, "edit");
    XmlExportVariables(writer, "match");
    XmlExportVariables(writer, "mon");
    XmlExportVariables(writer, "sys");
    XmlExportVariables(writer, "this");
    XmlEndTag(writer, XMLTAG_VARSCOPES_ROOT);

/* SPECIAL FUNCTIONS */
    XmlStartTag(writer, XMLTAG_FUNCTIONS_ROOT, 0);
    for (i = 0; CF_FNCALL_TYPES[i].name != NULL; i++)
    {
        XmlExportFunction(writer, CF_FNCALL_TYPES[i]);
    }
    XmlEndTag(writer, XMLTAG_FUNCTIONS_ROOT);

/* CONTROL */
    XmlStartTag(writer, XMLTAG_CONTROLS_ROOT, 0);
    for (i = 0; CF_ALL_BODIES[i].btype != NULL; i++)
    {
        XmlExportControl(writer, CF_ALL_BODIES[i]);
    }
    XmlEndTag(writer, XMLTAG_CONTROLS_ROOT);

/* PROMISE TYPES */
    XmlStartTag(writer, XMLTAG_PROMISETYPES_ROOT, 0);
    for (i = 0; i < CF3_MODULES; i++)
    {
        st = CF_ALL_SUBTYPES[i];
        XmlExportPromiseType(writer, st);
    }
    XmlEndTag(writer, XMLTAG_PROMISETYPES_ROOT);

/* END XML ELEMENT -- SYNTAX-DOCUMENTATION */
    XmlEndTag(writer, XMLTAG_DOC_ROOT);

    WriterClose(writer);
}
開發者ID:joegen,項目名稱:sipx-externals,代碼行數:58,代碼來源:export_xml.c

示例9: time

Policy *GenericAgentLoadPolicy(EvalContext *ctx, GenericAgentConfig *config)
{
    config->policy_last_read_attempt = time(NULL);

    StringSet *parsed_files = StringSetNew();
    StringSet *failed_files = StringSetNew();

    Policy *policy = LoadPolicyFile(ctx, config, config->input_file, parsed_files, failed_files);

    if (StringSetSize(failed_files) > 0)
    {
        Log(LOG_LEVEL_ERR, "There are syntax errors in policy files");
        exit(EXIT_FAILURE);
    }

    StringSetDestroy(parsed_files);
    StringSetDestroy(failed_files);

    {
        Seq *errors = SeqNew(100, PolicyErrorDestroy);

        if (PolicyCheckPartial(policy, errors))
        {
            if (!config->bundlesequence && (PolicyIsRunnable(policy) || config->check_runnable))
            {
                Log(LOG_LEVEL_VERBOSE, "Running full policy integrity checks");
                PolicyCheckRunnable(ctx, policy, errors, config->ignore_missing_bundles);
            }
        }

        if (SeqLength(errors) > 0)
        {
            Writer *writer = FileWriter(stderr);
            for (size_t i = 0; i < errors->length; i++)
            {
                PolicyErrorWrite(writer, errors->data[i]);
            }
            WriterClose(writer);
            exit(EXIT_FAILURE); // TODO: do not exit
        }

        SeqDestroy(errors);
    }

    if (LogGetGlobalLevel() >= LOG_LEVEL_VERBOSE)
    {
        ShowContext(ctx);
    }

    if (policy)
    {
        VerifyPromises(ctx, policy, config);
    }

    return policy;
}
開發者ID:nperron,項目名稱:core,代碼行數:56,代碼來源:generic_agent.c

示例10: WaitForSingleObject

void ArrayStringCount::writeToDisk(std::string& file_name)
{
    WaitForSingleObject(gHashWriteSemaphone, INFINITE);
    {
        FileWriter FW = FileWriter(file_name);
        FW.write(this->start, this->start_offset - this->start);
        this->total_write += (this->start_offset - this->start);
        this->start_offset = this->start;
    }
    ReleaseSemaphore(gHashWriteSemaphone, 1, NULL);
}
開發者ID:arunxls,項目名稱:InvertedLinks,代碼行數:11,代碼來源:ArrayStringCount.cpp

示例11: DumpErrors

static void DumpErrors(Seq *errs)
{
    if (SeqLength(errs) > 0)
    {
        Writer *writer = FileWriter(stdout);
        for (size_t i = 0; i < errs->length; i++)
        {
            PolicyErrorWrite(writer, errs->data[i]);
        }
        FileWriterDetach(writer);
    }
}
開發者ID:modulistic,項目名稱:cfengine__core,代碼行數:12,代碼來源:policy_test.c

示例12: test_empty_file_buffer

void test_empty_file_buffer(void **p)
{
    global_w = StringWriter();
    global_w_closed = false;
    Writer *w = FileWriter(NULL);

    assert_int_equal(StringWriterLength(global_w), 0);
    assert_string_equal(StringWriterData(global_w), "");

    WriterClose(w);
    WriterClose(global_w);
    assert_int_equal(global_w_closed, true);
}
開發者ID:FancsalMelinda,項目名稱:core,代碼行數:13,代碼來源:file_writer_test.c

示例13: test_write_file_buffer

void test_write_file_buffer(void **p)
{
    global_w = StringWriter();
    Writer *w = FileWriter(NULL);

    WriterWrite(w, "123");

    assert_int_equal(StringWriterLength(global_w), 3);
    assert_string_equal(StringWriterData(global_w), "123");

    WriterClose(w);
    WriterClose(global_w);
    assert_int_equal(global_w_closed, true);
}
開發者ID:FancsalMelinda,項目名稱:core,代碼行數:14,代碼來源:file_writer_test.c

示例14: FileWriter

void Simulation::writeFile(std::string path, int channels, double duration, bool mayApplyMixingMatrix) {
	int blocks = (duration*getSr()/block_size)+1;
	auto file = FileWriter();
	file.open(path.c_str(), sr, channels);
	//vectors are guaranteed to be contiguous. Using a vector here guarantees proper cleanup.
	std::vector<float> block;
	block.resize(channels*getBlockSize());
	for(int i = 0; i < blocks; i++) {
		getBlock(&block[0], channels, mayApplyMixingMatrix);
		unsigned int written= 0;
		while(written < getBlockSize()) written += file.write(getBlockSize(), &block[0]);
	}
	file.close();
}
開發者ID:moshverhavikk,項目名稱:libaudioverse,代碼行數:14,代碼來源:simulation.cpp

示例15: pro

bool ProjectFileGenerator::remove(const QStringList &files)
{
    QString output;

    QFile pro(filePath);
    if (pro.exists()) {
        if (pro.open(QIODevice::ReadOnly | QIODevice::Text)) {
            output = pro.readAll();
        } else {
            qCritical("failed to open file: %s", qPrintable(pro.fileName()));
            return false;
        }
    } else {
        qCritical("Project file not found: %s", qPrintable(pro.fileName()));
        return false;
    }
    pro.close();

    if (files.isEmpty())
        return true;

    for (QStringListIterator i(files); i.hasNext(); ) {
        QString f = QFileInfo(i.next()).fileName();
        QString str;
        QRegExp rx("*.h");
        rx.setPatternSyntax(QRegExp::Wildcard);
        if (rx.exactMatch(f)) {
            str  = "HEADERS += ";
            str += f;
            str += '\n';
        } else {
            rx.setPattern("*.cpp");
            if (rx.exactMatch(f)) {
                str  = "SOURCES += ";
                str += f;
                str += '\n';
            }
        }
        
        int idx = 0;
        if (!str.isEmpty() && (idx = output.indexOf(str)) >= 0 ) {
            output.remove(idx, str.length());
        }
    }

    return FileWriter(filePath).write(output, true);
}
開發者ID:Keloran,項目名稱:treefrog-framework,代碼行數:47,代碼來源:projectfilegenerator.cpp


注:本文中的FileWriter函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。