本文整理汇总了C++中write_record函数的典型用法代码示例。如果您正苦于以下问题:C++ write_record函数的具体用法?C++ write_record怎么用?C++ write_record使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_record函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_hit_record
/**
* Write the hit record.
*
* \param ctx GL context.
*
* Write the hit record, i.e., the number of names in the stack, the minimum and
* maximum depth values and the number of names in the name stack at the time
* of the event. Resets the hit flag.
*
* \sa gl_selection.
*/
static void
write_hit_record(struct gl_context *ctx)
{
GLuint i;
GLuint zmin, zmax, zscale = (~0u);
/* HitMinZ and HitMaxZ are in [0,1]. Multiply these values by */
/* 2^32-1 and round to nearest unsigned integer. */
assert( ctx != NULL ); /* this line magically fixes a SunOS 5.x/gcc bug */
zmin = (GLuint) ((GLfloat) zscale * ctx->Select.HitMinZ);
zmax = (GLuint) ((GLfloat) zscale * ctx->Select.HitMaxZ);
write_record( ctx, ctx->Select.NameStackDepth );
write_record( ctx, zmin );
write_record( ctx, zmax );
for (i = 0; i < ctx->Select.NameStackDepth; i++) {
write_record( ctx, ctx->Select.NameStack[i] );
}
ctx->Select.Hits++;
ctx->Select.HitFlag = GL_FALSE;
ctx->Select.HitMinZ = 1.0;
ctx->Select.HitMaxZ = -1.0;
}
示例2: bwrite
static int bwrite (int chan, void *buffer, int nelem, char *dtype)
/* To fill the write buffer of initialized channel "chan". When
the write buffer "chn[chan].buffer" is full, it will write the contents
out to the data file related to the channel */
{
int nb, i, j, msg;
msg = send_command_to_server(chn[chan].gchannel, "WRITE");
#ifdef DEBUG
printf("mgilib2::bwrite(), ==\n");
#endif
if(*dtype == 'I' || *dtype == 'R')
{
nb = write_record(chn[chan].gchannel, (unsigned char *)buffer, nelem, sizeof(int));
get_ack_nack(chn[chan].gchannel);
}
else if(*dtype == 'D')
{
nb = write_record(chn[chan].gchannel, (char *)buffer, nelem, sizeof(double));
get_ack_nack(chn[chan].gchannel);
}
else if(*dtype == 'C')
{
nb = write_record(chn[chan].gchannel, buffer, nelem, 1);
get_ack_nack(chn[chan].gchannel);
}
return nb;
}
示例3: encode
static int encode(FILE *in, FILE *out) {
unsigned bank = 0, address = 0;
unsigned char buffer[0x10];
size_t nbytes;
/* write data records, 16 bytes each */
while ((nbytes = fread(buffer, 1, sizeof(buffer), in)) > 0) {
write_record(out, (size_t)nbytes, address,
0, buffer);
address += (size_t)nbytes;
if (address >= BANK_SIZE) {
/* switch to next bank */
bank++;
address %= BANK_SIZE;
write_record(out, 0, 0, 0x10 + bank, NULL);
}
}
/* write end-of-file record */
write_record(out, 0, 0, 1, NULL);
return 0;
}
示例4: save_serial
static int save_serial(ulong address, ulong count)
{
int i, c, reclen, checksum, length;
char *hex = "0123456789ABCDEF";
char record[2*SREC_BYTES_PER_RECORD+16]; /* buffer for one S-Record */
char data[2*SREC_BYTES_PER_RECORD+1]; /* buffer for hex data */
reclen = 0;
checksum = 0;
if (write_record(SREC3_START)) /* write the header */
return -1;
do {
if (count) { /* collect hex data in the buffer */
c = *(volatile uchar*)(address + reclen); /* get one byte */
checksum += c; /* accumulate checksum */
data[2*reclen] = hex[(c>>4)&0x0f];
data[2*reclen+1] = hex[c & 0x0f];
data[2*reclen+2] = '\0';
++reclen;
--count;
}
if (reclen == SREC_BYTES_PER_RECORD || count == 0) {
/* enough data collected for one record: dump it */
if (reclen) { /* build & write a data record: */
/* address + data + checksum */
length = 4 + reclen + 1;
/* accumulate length bytes into checksum */
for (i = 0; i < 2; i++)
checksum += (length >> (8*i)) & 0xff;
/* accumulate address bytes into checksum: */
for (i = 0; i < 4; i++)
checksum += (address >> (8*i)) & 0xff;
/* make proper checksum byte: */
checksum = ~checksum & 0xff;
/* output one record: */
sprintf(record, SREC3_FORMAT, length, address, data, checksum);
if (write_record(record))
return -1;
}
address += reclen; /* increment address */
checksum = 0;
reclen = 0;
}
} while (count);
if (write_record(SREC3_END)) /* write the final record */
return -1;
return 0;
}
示例5: main
int main (int argc, char *argv[]) {
// Déclare un timer, ainsi que deux recorder qui vont contenir les résultats de l'exécution du programme
timer *t = timer_alloc();
recorder *bash_rec = recorder_alloc("shell-bash.csv");
recorder *prog_rec = recorder_alloc("shell-prog.csv");
// Nom du programme C et du script à comparer
char * progr = "./shell-program ";
char * bash = "./shell-bash.sh ";
// Cette variable contient la transformation du nombre d'instruction (i).
// Puisque cette variable est un int, 7 caractères suffisent à sa représentation.
char nbr[7];
int i;
// Allocation des emplacements contenant la commande à exécuter
char*argProgr = (char *) malloc(24*sizeof(char));
char*argBash = (char *) malloc(24*sizeof(char));
if(argProgr == NULL || argBash == NULL)
exit(EXIT_FAILURE);
for(i=1; i<MAX_SIZE; i+=1) {
// Convertit "i" en char* et le place dans nbr
snprintf(nbr, 7, "%d", i);
// Concatene les deux parties de la commande
strncpy(argProgr, progr, 24);
strncpy(argBash, bash, 24);
strncat(argProgr, nbr, 7);
strncat(argBash, nbr, 7);
// Commence le timer et lance la commande, puis écrit le résultat dans le record approprié
start_timer(t);
system(argProgr);
write_record(prog_rec, i, stop_timer(t));
start_timer(t);
system(argBash);
write_record(bash_rec, i, stop_timer(t));
}
// Libère la mémoire
recorder_free(bash_rec);
recorder_free(prog_rec);
timer_free(t);
return EXIT_SUCCESS;
}
示例6: generate_process64ex_record
static void
generate_process64ex_record(const char *directory, const char *record_filename,
u_int32_t type)
{
token_t *process64ex_token;
char *buf;
buf = (char *)malloc(strlen(record_filename) + 6);
if (type == AU_IPv6) {
inet_pton(AF_INET6, "fe80::1", process64_tid_addr.at_addr);
process64_tid_addr.at_type = AU_IPv6;
sprintf(buf, "%s%s", record_filename, "-IPv6");
} else {
process64_tid_addr.at_addr[0] = inet_addr("127.0.0.1");
process64_tid_addr.at_type = AU_IPv4;
sprintf(buf, "%s%s", record_filename, "-IPv4");
}
process64ex_token = au_to_process64_ex(process64_auid, process64_euid,
process64_egid, process64_ruid, process64_rgid, process64_pid,
process64_sid, &process64_tid_addr);
if (process64ex_token == NULL)
err(EX_UNAVAILABLE, "au_to_process64_ex");
write_record(directory, buf, process64ex_token, AUE_NULL);
free(buf);
}
示例7: save_area
void save_area(struct element *xy, int num_points, int category)
{
int incr;
float first_cell, last_cell;
for (incr = 0; incr < num_points;) {
if (START_ROW != STOP_ROW) {
fprintf(stderr, "ERROR: start and end row not same\n");
for (incr = 0; incr < num_points; incr += 2) {
fprintf(stderr, "%d: %d %f %d %f\n",
incr, xy[incr].row, xy[incr].col,
xy[incr + 1].row, xy[incr + 1].col);
}
incr++;
continue;
}
first_cell = START_COL + 1.;
last_cell = STOP_COL;
if (last_cell >= first_cell)
write_record(START_ROW, first_cell, last_cell, category);
incr += 2;
}
}
示例8: write_records_to_log
/* Tries to write the specified number of records. Stops when the log gets
full. Returns the number of records written. Spins for random
number of times, up to 'max_spin_count', between writes. */
static size_t write_records_to_log(int writer_id, int32_t record_size,
int32_t num_records,
int32_t max_spin_count) {
int32_t ix;
int counter = 0;
for (ix = 0; ix < num_records; ++ix) {
int32_t jx;
int32_t spin_count = max_spin_count ? rand() % max_spin_count : 0;
char *record;
if (counter++ == num_records / 10) {
printf(" Writer %d: %d out of %d written\n", writer_id, ix,
num_records);
counter = 0;
}
record = (char *)(census_log_start_write(record_size));
if (record == NULL) {
return ix;
}
write_record(record, record_size);
census_log_end_write(record, record_size);
for (jx = 0; jx < spin_count; ++jx) {
GPR_ASSERT(jx >= 0);
}
}
return num_records;
}
示例9: amar_file_close
gboolean
amar_file_close(
amar_file_t *file,
GError **error)
{
gboolean success = TRUE;
amar_t *archive = file->archive;
/* close all attributes that haven't already written EOA */
g_hash_table_foreach(file->attributes, foreach_attr_close, error);
if (*error)
success = FALSE;
/* write an EOF record */
if (success) {
if (!write_record(archive, file->filenum, AMAR_ATTR_EOF, 1,
NULL, 0, error))
success = FALSE;
}
/* remove from archive->file list */
g_hash_table_remove(archive->files, &file->filenum);
/* clean up */
g_hash_table_destroy(file->attributes);
amfree(file);
return success;
}
示例10: entry_menu
void entry_menu()
{
int ch,num;
clrscr();
cout<<"\n\n\n\t\tENTRY MENU";
cout<<"\n\n\t1.CREATE STUDENT RECORD";
cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORD";
cout<<"\n\n\t3.SEARCH STUDENT RECORD";
cout<<"\n\n\t4.MODIFY STUDENT RECORD ";
cout<<"\n\n\t5.DELETE STUDENT RECORD ";
cout<<"\n\n\t6.RETURN TO MAIN MENU";
cout<<"\n\nPlease Enter Your Choice(1-6).......";
cin>>ch;
clrscr();
switch(ch)
{
case 1:write_record();break;
case 2:read_record();break;
case 3:cout<<"\n\n\tPlease enter the roll no. of student ";
cin>>num;
display(num);
break;
case 4:cout<<"\n\n\tPlease enter the roll no. of student ";
cin>>num;
modify_record(num);
break;
case 5:cout<<"\n\n\tPlease enter the roll no. of student ";
cin>>num;
delete_record(num);
break;
case 6:break;
default : cout<<"\a";entry_menu();
}
}
示例11: time
void DbDumperWriter::run(tbsys::CThread *thr_, void *arg)
{
last_rotate_time_ = time(NULL);
UNUSED(thr_);
UNUSED(arg);
int ret = OB_SUCCESS;
while(running_ || !records_.empty()) {
ret = OB_SUCCESS;
bool flush = !running_;
if (need_rotate_output_file()) {
ret = rotate_output_file();
if (ret != OB_SUCCESS) {
TBSYS_LOG(ERROR, "can't rotate file");
break;
}
}
if (ret == OB_SUCCESS) {
ret = write_record(flush);
if (ret != OB_SUCCESS) {
TBSYS_LOG(ERROR, "write record failed, %d", ret);
sleep(1);
}
}
}
//mv last_file.TMP to last_file
if (ret == OB_SUCCESS)
mv_output_file();
}
示例12: t
void TeamEdit::save() {
dbo::Transaction t(tApp->session());
write_record(team_.modify(), /* init */ false);
team_chat(team_, "change name/description of the team", tApp->user());
t.commit();
t_emit(TEAM_OBJECT, team_.id());
}
示例13: main
int main (int argc, char *argv[]) {
timer *t = timer_alloc();
recorder *parent_rec = recorder_alloc("parent.csv");
recorder *child_rec = recorder_alloc("child.csv");
pid_t pid;
int status, i;
for (i = 0; i < N; i++) {
start_timer(t);
pid = fork();
if (pid == -1) {
// erreur à l'exécution de fork
perror("fork");
return EXIT_FAILURE;
}
// pas d'erreur
// BEGIN
if (pid == 0) {
// processus fils
write_record(child_rec, i, stop_timer(t));
recorder_free(child_rec);
recorder_free(parent_rec);
timer_free(t);
return EXIT_SUCCESS;
}
else {
// processus père
write_record(parent_rec, i, stop_timer(t));
pid = waitpid(pid, &status, 0);
if (pid == -1) {
perror("wait");
return EXIT_FAILURE;
}
}
// END
}
recorder_free(child_rec);
recorder_free(parent_rec);
timer_free(t);
return EXIT_SUCCESS;
}
示例14: fopen
int mcs_file::save(const char* file, void* data, int len)
{
FILE* f;
int rc = -1;
int addr, addr_offs, count;
const int buff_len = 16;
union {
u8 buff[buff_len];
u16 word;
} u;
f = fopen(file, "wt");
if (f == NULL)
{
msgf(STR_UNABLE_TO_OPEN_FILE);
return -1;
}
addr = 0;
addr_offs = 0;
u.word = 0x0000;
if (write_record(f, 2, 0, RECORD_ADDRESS, u.buff))
goto cleanup;
while (addr_offs + addr < len)
{
if (addr_offs + addr + buff_len < len)
count = buff_len;
else
count = len - addr_offs - addr;
if (write_record(f, count, addr, RECORD_DATA, (u8*)data + addr_offs + addr))
goto cleanup;
addr += count;
if (addr >= 0x10000 && addr_offs + addr < len)
{
addr_offs += 0x10000;
addr &= 0xFFFF;
u.word = HTON16(addr_offs >> 16);
if (write_record(f, 2, 0, RECORD_ADDRESS, u.buff))
goto cleanup;
}
}
示例15: io_exception
void file_bstore::write_root(const std::vector<char>& record)
{
if (m_cur_slab == NULL)
throw io_exception("file_store is not open");
lock_t lock(m_mutex);
m_root = write_record('R', record);
//printf("Writing root record: %d\n", (int) m_root);
}