本文整理汇总了C++中cache_get函数的典型用法代码示例。如果您正苦于以下问题:C++ cache_get函数的具体用法?C++ cache_get怎么用?C++ cache_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cache_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderer_render
void renderer_render(renderer *renderer, world *world, cache *cache) {
// Clear surface
SDL_RenderClear(renderer->sdl_renderer);
// RenderCopy legit surfaces
for(int i = 0; i < MAX_ENTITY; i++) {
int mask = world->mask[i];
if ((mask & GRAPHIC) == GRAPHIC) {
(void)printf("Rendering entity %d with image %s\n", i, world->graphics[i].image_file);
// Get image size and position info, if present. Else,
// image fills up entire screen.
if(((mask & POSITION) == POSITION) && ((mask & SIZE) == SIZE)) {
SDL_Rect rect;
rect.x = world->positions[i].x;
rect.y = world->positions[i].y;
rect.w = world->sizes[i].x;
rect.h = world->sizes[i].y;
SDL_RenderCopy(renderer->sdl_renderer, cache_get(&cache, renderer->sdl_renderer, world->graphics[i].image_file), NULL, &rect);
} else {
SDL_RenderCopy(renderer->sdl_renderer, cache_get(&cache, renderer->sdl_renderer, world->graphics[i].image_file), NULL, NULL);
}
}
}
// Update screen surface
SDL_RenderPresent(renderer->sdl_renderer);
}
示例2: test_basics
void test_basics()
{
cache_t cache = create_cache(65536, NULL);
uint32_t val_size = 0;
const uint8_t
*key1 = (uint8_t*)"One key",
*key2 = (uint8_t*)"Two key",
*key3 = (uint8_t*)"Red key";
uint8_t *value1 = (uint8_t*) "First value";
uint64_t value2 = 20039;
int32_t value3 = -12;
cache_set(cache, key1, value1, strlen((char *)value1) + 1);
cache_set(cache, key2, &value2, sizeof(value2));
cache_set(cache, key3, &value3, sizeof(value3));
uint8_t *result1 = (uint8_t *)cache_get(cache, key1, &val_size);
uint64_t *result2 = (uint64_t *)cache_get(cache, key2, &val_size);
int32_t *result3 = (int32_t *)cache_get(cache, key3, &val_size);
bool results_not_null = result1 != NULL && result2 != NULL && result3 != NULL;
bool string_result_correct = strcmp((const char*)value1, (const char*)result1) == 0;
bool uint64_result_correct = *result2 == value2;
bool int32_result_correct = *result3 == value3;
test(results_not_null, "Get returns non null pointers when retrieving valid entries.");
test(string_result_correct, "Cache can store and retrieve strings");
test(uint64_result_correct, "Cache can store and retrieve uint64_t integers correctly.");
test(int32_result_correct, "Cache can store and retrieve int32_t integers correctly.");
test(val_size == sizeof(value3), "cache_get sets val_size pointer to value size.");
destroy_cache(cache);
}
示例3: max_predicate_value
void ExistsFeatures::get(const IntermediateExample& e, FeatureIDs& l, item_predicate_ty predicate, item_group_ty group) const {
ItemTokens items;
unsigned values_size = max_predicate_value(predicate)+1;
vector<bool> exists_features(values_size, false);
deque<unsigned> value_list;
unsigned v;
GroupIterator item(group, e);
int size = item.size();
for (; !item.end(); item++) {
v = get_predicate_value(predicate, *item);
if (is_binary_predicate(predicate) && v == (unsigned)false && !parameter::binary_predicates_can_have_false_value()) continue;
exists_features.at(v) = true;
if (size*2 < (int)values_size)
value_list.push_back(v);
}
if (size*2 < (int)values_size) {
deque<unsigned>::const_iterator i;
for (i = value_list.begin(); i != value_list.end(); i++)
if (exists_features.at(*i)) {
l.push_back(cache_get(group, predicate, *i)->id());
exists_features.at(*i) = false;
}
} else {
unsigned i;
for (i = 0; i < exists_features.size(); i++)
if (exists_features.at(i))
l.push_back(cache_get(group, predicate, i)->id());
}
}
示例4: cache_get
char *mime_types_get(char *ext, int len, cache *c) {
if (len > 1) {
if (cache_exists(c, ext, len) == 0) {
return cache_get(c, ext, len);
} else {
return cache_get(c, ".default", 8);
}
} else {
return cache_get(c, ".default", 8);
}
}
示例5: bg_db_get_thumbnail
void * bg_db_get_thumbnail(bg_db_t * db, int64_t id,
int max_width, int max_height,
const char * mimetype)
{
browse_t b;
int64_t thumb_id;
if((thumb_id = cache_get(&db->th_cache,
id, max_width, max_height,
mimetype)) > 0)
return bg_db_object_query(db, thumb_id);
memset(&b, 0, sizeof(b));
b.max_width = max_width;
b.max_height = max_height;
b.mimetype = mimetype;
bg_db_browse_thumbnails(db, id, browse_callback, &b);
if(!b.ret)
{
bg_db_object_t * img = bg_db_object_query(db, id);
b.ret = make_thumbnail(db,
img, max_width, max_height, mimetype);
bg_db_object_unref(img);
}
cache_put(&db->th_cache,
id,
max_width, max_height,
mimetype, bg_db_object_get_id(b.ret));
return b.ret;
}
示例6: idx_get_page
static int idx_get_page(IDX *idx, const long number)
{
idx -> page_dirty = 0;
idx -> page_number = number;
return cache_get(idx -> cache, idx -> page_number, &idx -> page);
}
示例7: test_LRU
void test_LRU(){
cache_t cache = create_cache_fake(16*DATASIZE);
data_t data1 = create_data(1,(DATATYPE)"123456789012345678901234567890123",8*DATASIZE);
data_t data2 = create_data(2,(DATATYPE)"223456789012345678901234567890123",8*DATASIZE);
data_t data3 = create_data(3,(DATATYPE)"111",DATASIZE);
cache_set(cache,data1->key,data1->value,data1->value_size);
cache_set(cache,data2->key,data2->value,data2->value_size);
//Get key1 to put it to the front of the linked_list
cache_get(cache,data1->key,data1->value_size_ptr);
//Set key3 to evict key2
cache_set(cache,data3->key,data3->value,data3->value_size);
data_existence_test(cache,data3);
//key1 is supposed to be kept
data_existence_test(cache,data1);
//key2 is supposed to be evicted already
data_nonexistence_test(cache, data2);
test_destroy_cache(cache);
destroy_data(data1);
destroy_data(data2);
destroy_data(data3);
}
示例8: svcudp_recv
static bool_t
svcudp_recv(
register SVCXPRT *xprt,
struct rpc_msg *msg)
{
register struct svcudp_data *su = su_data(xprt);
register XDR *xdrs = &(su->su_xdrs);
register ssize_t rlen;
char *reply;
unsigned long replylen;
socklen_t len;
again:
len = xprt->xp_addrlen = sizeof(struct sockaddr_in);
rlen = recvfrom(xprt->xp_sock, rpc_buffer(xprt), (int) su->su_iosz,
0, (struct sockaddr *)&(xprt->xp_raddr), &len);
if (rlen == -1 && errno == EINTR)
goto again;
if (rlen < 4*sizeof(uint32_t))
return (FALSE);
xprt->xp_addrlen = len;
xdrs->x_op = XDR_DECODE;
XDR_SETPOS(xdrs, 0);
if (! xdr_callmsg(xdrs, msg))
return (FALSE);
su->su_xid = msg->rm_xid;
if (su->su_cache != NULL) {
if (cache_get(xprt, msg, &reply, &replylen)) {
(void) sendto(xprt->xp_sock, reply, replylen, 0,
(struct sockaddr *) &xprt->xp_raddr, xprt->xp_addrlen);
return (TRUE);
}
}
return (TRUE);
}
示例9: _dict_read_dzip
static int
_dict_read_dzip(struct _dict_stream *str, char *buf, size_t size, size_t *pret)
{
int chunk_num = str->offset / str->chunk_size;
size_t chunk_off = str->offset - chunk_num * str->chunk_size;
size_t rdbytes = 0;
int rc;
while (size) {
struct _dict_chunk_cache *cp;
size_t n;
rc = cache_get(str, chunk_num, &cp);
if (rc)
break;
n = cp->size - chunk_off; /* FIXME = str->chunk[chunk_num].length;? */
if (n > size)
n = size;
memcpy(buf, cp->buffer + chunk_off, n);
size -= n;
buf += n;
rdbytes += n;
str->offset += n;
chunk_num++;
chunk_off = 0;
}
*pret = rdbytes;
return rc;
}
示例10: fprintf
// gadget cache copy (both cache must have the same size)
struct cache_t *cache_copy (struct cache_t *dest, struct cache_t *src)
{
int idx_cache;
int dest_capacity, src_capacity;
void *copied, *cached;
// check parameters
if ((!dest || !src) || (src == dest)) {
fprintf(stderr, "error: cache_copy(): Bad parameters\n");
return NULL;
}
// cache must be of same sizes
dest_capacity = cache_get_capacity(dest);
src_capacity = cache_get_capacity(src);
if (dest_capacity != src_capacity) {
fprintf(stderr, "error: cache_copy(): dest and src are not of the same size\n");
return NULL;
}
// copy cache
for (idx_cache = 0; idx_cache < cache_get_size(src); idx_cache++) {
// copying
cached = cache_get (src, idx_cache);
cache_set (dest, idx_cache, copied);
}
dest->used = src->used;
return dest;
}
示例11: main
int main(int argc,char **argv)
{
int i;
char *x;
char *y;
unsigned int u;
uint32 ttl;
if (!cache_init(200)) _exit(111);
if (*argv) ++argv;
while (x = *argv++) {
i = str_chr(x,':');
if (x[i])
cache_set(x,i,x + i + 1,str_len(x) - i - 1,86400,0);
else {
y = cache_get(x,i,&u,&ttl,0);
if (y)
buffer_put(buffer_1,y,u);
buffer_puts(buffer_1,"\n");
}
}
buffer_flush(buffer_1);
_exit(0);
}
示例12: op_indfun
void op_indfun(mval *v, mint code, mval *dst)
{
bool rval;
mstr *obj, object;
oprtype x;
unsigned char argcode;
error_def(ERR_INDMAXNEST);
argcode = (unsigned char)code;
assert(UCHAR_MAX >= code); /* if not, the assignment to argcode is lossy */
assert(indir_opcode[argcode]);
MV_FORCE_STR(v);
if (!(obj = cache_get(argcode, &v->str)))
{
comp_init(&v->str);
rval = (*indir_fcn[argcode])(&x, indir_opcode[argcode]);
if (!comp_fini(rval, &object, OC_IRETMVAL, &x, v->str.len))
return;
cache_put(argcode, &v->str, &object);
*ind_result_sp++ = dst;
if (ind_result_sp >= ind_result_top)
rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
comp_indr(&object);
return;
}
*ind_result_sp++ = dst;
if (ind_result_sp >= ind_result_top)
rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
comp_indr(obj);
return;
}
示例13: resolve_tex
url
resolve_tex (url name) {
string s= as_string (name);
if (is_cached ("font_cache.scm", s)) {
url u= url_system (cache_get ("font_cache.scm", s) -> label);
if (exists (u)) return u;
cache_reset ("font_cache.scm", s);
}
bench_start ("resolve tex");
url u= url_none ();
if (ends (s, "mf" )) {
u= resolve_tfm (name);
#ifdef OS_WIN32
if (is_none (u))
u= resolve_tfm (replace (s, ".mf", ".tfm"));
#endif
}
if (ends (s, "tfm")) u= resolve_tfm (name);
if (ends (s, "pk" )) u= resolve_pk (name);
if (ends (s, "pfb")) u= resolve_pfb (name);
bench_cumul ("resolve tex");
if (!is_none (u)) cache_set ("font_cache.scm", s, as_string (u));
//cout << "Resolve " << name << " -> " << u << "\n";
return u;
}
示例14: find_replicated
/*
* Asks the paxos master for the metric value
* name: find_replicated
* @param name metric name
* @param hostname
* @param timestamp
* @return value
*/
char * find_replicated(char *hostname, char *name, time_t *timestamp) {
FILE *stream;
char *value, * tstp, *resp, * cookie;
char *host, *ret;
if (_PAXOS_DEBUG) pax_log(LOG_DEBUG, "Find replicated\n");
net_proto(NPROTO_AUTO);
host = get_host(&node); /*Find the master*/
if (host == NULL) return NULL;
stream = cache_connect_net(host, PBS_CACHE_PORT);
free(host);
if (stream != NULL) {
resp = cache_get(stream, hostname, name);
if ((tstp = strtok_r(resp, "\t", &cookie)) == NULL) {
pax_log(LOG_ERR, "Incomplete metric message\n");
cache_close(stream);
return NULL;
}
if ((value = strtok_r(cookie, "\n", &cookie)) == NULL) {
pax_log(LOG_ERR, "Incomplete metric message\n");
cache_close(stream);
return NULL;
}
*timestamp = atol(tstp);
cache_close(stream);
} else {
pax_log(LOG_ERR, "cache_connect failed\n");
return NULL;
}
ret = strdup(value);
free(resp);
return ret;
}
示例15: op_indpat
void op_indpat(mval *v, mval *dst)
{
bool rval;
mstr *obj, object;
oprtype x;
error_def(ERR_INDMAXNEST);
MV_FORCE_STR(v);
if (!(obj = cache_get(indir_pattern, &v->str)))
{
comp_init(&v->str);
source_column = 1; /* to coordinate with scanner redirection*/
rval = compile_pattern(&x,window_token == TK_ATSIGN);
if (comp_fini(rval, &object, OC_IRETMVAL, &x, v->str.len))
{
cache_put(indir_pattern, &v->str, &object);
*ind_result_sp++ = dst;
if (ind_result_sp >= ind_result_top)
rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
comp_indr(&object);
}
}
else
{
*ind_result_sp++ = dst;
if (ind_result_sp >= ind_result_top)
rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
comp_indr(obj);
}
}