本文整理汇总了C++中read_item函数的典型用法代码示例。如果您正苦于以下问题:C++ read_item函数的具体用法?C++ read_item怎么用?C++ read_item使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_item函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: objectstore_read
PUBLIC gboolean objectstore_read(FILE *f, ObjectStore *db) {
ObjectStoreItem *item;
ObjectStoreDatum *datum;
char magic[5];
setlocale( LC_NUMERIC, "C" );
fread(magic, sizeof(char), 4, f);
magic[4] = '\0';
if (strcmp(magic, "Mjik")) {
setlocale( LC_NUMERIC, "" );
return FALSE;
}
item = read_item(f);
if (strcmp(item->tag, "ObjectStore") ||
item->key != 0) {
objectstore_kill_objectstoreitem(NULL, item, NULL);
setlocale( LC_NUMERIC, "" );
return FALSE;
}
datum = objectstore_item_get(item, "version");
if (datum == NULL ||
datum->kind != OSI_KIND_INT ||
datum->d.integer != OBJECTSTORE_CURRENT_VERSION) {
objectstore_kill_objectstoreitem(NULL, item, NULL);
setlocale( LC_NUMERIC, "" );
return FALSE;
}
datum = objectstore_item_get(item, "rootkey");
if (datum == NULL ||
datum->kind != OSI_KIND_INT) {
setlocale( LC_NUMERIC, "");
return FALSE;
}
db->rootkey = datum->d.integer;
objectstore_kill_objectstoreitem(NULL, item, NULL);
while (!feof(f)) {
item = read_item(f);
if (item != NULL) {
g_hash_table_insert(db->object_table, (gpointer) item->key, item);
item->db = db;
db->nextkey = MAX(db->nextkey, item->key + 1);
}
}
setlocale( LC_NUMERIC, "" );
return TRUE;
}
示例2: read_item
// add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_add_item(lua_State *L)
{
GET_ENV_PTR;
// pos
//v3f pos = checkFloatPos(L, 1);
// item
ItemStack item = read_item(L, 2,getServer(L));
if(item.empty() || !item.isKnown(getServer(L)->idef()))
return 0;
lua_pushcfunction(L, script_error_handler);
int errorhandler = lua_gettop(L);
// Use spawn_item to spawn a __builtin:item
lua_getglobal(L, "core");
lua_getfield(L, -1, "spawn_item");
lua_remove(L, -2); // Remove core
if(lua_isnil(L, -1))
return 0;
lua_pushvalue(L, 1);
lua_pushstring(L, item.getItemString().c_str());
PCALL_RESL(L, lua_pcall(L, 2, 1, errorhandler));
lua_remove(L, errorhandler); // Remove error handler
return 1;
}
示例3: PUSH_ERROR_HANDLER
bool ScriptApiItem::item_OnUse(ItemStack &item,
ServerActiveObject *user, const PointedThing &pointed)
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
// Push callback function on stack
if (!getItemCallback(item.name.c_str(), "on_use"))
return false;
// Call function
LuaItemStack::create(L, item);
objectrefGetOrCreate(L, user);
pushPointedThing(pointed);
PCALL_RES(lua_pcall(L, 3, 1, error_handler));
if(!lua_isnil(L, -1)) {
try {
item = read_item(L,-1, getServer());
} catch (LuaError &e) {
throw LuaError(std::string(e.what()) + ". item=" + item.name);
}
}
lua_pop(L, 2); // Pop item and error handler
return true;
}
示例4: load
int load() {
getc();
while (!_files.empty()) {
ll_failed_return(read_item());
}
return ok;
}
示例5: lua_pushcfunction
bool ScriptApiItem::item_OnDrop(ItemStack &item,
ServerActiveObject *dropper, v3f pos)
{
SCRIPTAPI_PRECHECKHEADER
lua_pushcfunction(L, script_error_handler);
int errorhandler = lua_gettop(L);
// Push callback function on stack
if(!getItemCallback(item.name.c_str(), "on_drop"))
return false;
// Call function
LuaItemStack::create(L, item);
objectrefGetOrCreate(dropper);
pushFloatPos(L, pos);
if(lua_pcall(L, 3, 1, errorhandler))
scriptError();
if(!lua_isnil(L, -1)) {
try {
item = read_item(L,-1, getServer());
} catch (LuaError &e) {
throw LuaError(std::string(e.what()) + ". item=" + item.name);
}
}
lua_pop(L, 2); // Pop item and error handler
return true;
}
示例6: scriptapi_item_on_place
bool scriptapi_item_on_place(lua_State *L, ItemStack &item,
ServerActiveObject *placer, const PointedThing &pointed)
{
actionstream<<"DebugTracePlaceEnteredLua scriptapi_item Line 250 "<<std::endl;
realitycheck(L);
assert(lua_checkstack(L, 20));
StackUnroller stack_unroller(L);
actionstream<<"DebugTracePlacePassedStackCheck scriptapi_item Line 254 "<<std::endl;
// Push callback function on stack
if(!get_item_callback(L, item.name.c_str(), "on_place"))
actionstream<<"DebugTracePlaceLuaReturningFalse scriptapi_item Line 257 "<<std::endl;
return false;
// Call function
LuaItemStack::create(L, item);
objectref_get_or_create(L, placer);
push_pointed_thing(L, pointed);
actionstream<<"DebugTracePlaceClearToRunLua scriptapi_item Line 263 "<<std::endl;
if(lua_pcall(L, 3, 1, 0))
script_error(L, "error: %s", lua_tostring(L, -1));
if(!lua_isnil(L, -1))
actionstream<<"DebugTracePlaceItemReturned scriptapi_item Line 267 "<<std::endl;
item = read_item(L, -1);
actionstream<<"DebugTracePlaceLuaReturningTrue scriptapi_item Line 270 "<<std::endl;
return true;
}
示例7: nagp_iio_provider_read_items
/*
* nagp_iio_provider_read_items:
*
* Note that whatever be the version of the read action, it will be
* stored as a #NAObjectAction and its set of #NAObjectProfile of the same,
* latest, version of these classes.
*/
GList *
nagp_iio_provider_read_items( const NAIIOProvider *provider, GSList **messages )
{
static const gchar *thisfn = "nagp_reader_nagp_iio_provider_read_items";
NagpGConfProvider *self;
GList *items_list = NULL;
GSList *listpath, *ip;
NAObjectItem *item;
g_debug( "%s: provider=%p, messages=%p", thisfn, ( void * ) provider, ( void * ) messages );
g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), NULL );
g_return_val_if_fail( NAGP_IS_GCONF_PROVIDER( provider ), NULL );
self = NAGP_GCONF_PROVIDER( provider );
if( !self->private->dispose_has_run ){
listpath = na_gconf_utils_get_subdirs( self->private->gconf, NAGP_CONFIGURATIONS_PATH );
for( ip = listpath ; ip ; ip = ip->next ){
item = read_item( self, ( const gchar * ) ip->data, messages );
if( item ){
items_list = g_list_prepend( items_list, item );
na_object_dump( item );
}
}
na_gconf_utils_free_subdirs( listpath );
}
g_debug( "%s: count=%d", thisfn, g_list_length( items_list ));
return( items_list );
}
示例8: read_element
static inline void read_element(PRSS *res, xmlNodePtr n)
{
xmlNodePtr child;
if (n->type != XML_ELEMENT_NODE) {
return;
}
child = n->children;
if (!child) {
return;
}
#define ASSIGN(a) if (strcasecmp((const char*)n->name, #a) == EQUAL) { \
if (res->a) free(res->a); \
res->a = strdup((const char*)child->content); \
return; \
}
ASSIGN(title);
ASSIGN(link);
ASSIGN(description);
ASSIGN(language);
ASSIGN(pubDate);
ASSIGN(lastBuildDate);
ASSIGN(generator);
ASSIGN(docs);
ASSIGN(managingEditor);
ASSIGN(webMaster);
ASSIGN(copyright);
ASSIGN(ttl);
#undef ASSIGN
if (!strcasecmp((const char*)n->name, "item")) {
read_item(&res->items[res->item_count++], n->children);
}
}
示例9: checkobject
// replace(self, itemstack or itemstring or table or nil) -> true
int LuaItemStack::l_replace(lua_State *L)
{
LuaItemStack *o = checkobject(L, 1);
o->m_stack = read_item(L, 2);
lua_pushboolean(L, true);
return 1;
}
示例10: read_item
QString read_item( IDispatchPtr dispatch, const QByteArray &record )
{
Q_ASSERT( dispatch );
Outlook::_AppointmentItemPtr item( dispatch );
QXmlStreamReader reader(record);
return read_item( item, reader, false );
}
示例11: read_item
// minetest.add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_add_item(lua_State *L)
{
GET_ENV_PTR;
// pos
//v3f pos = checkFloatPos(L, 1);
// item
ItemStack item = read_item(L, 2,getServer(L));
if(item.empty() || !item.isKnown(getServer(L)->idef()))
return 0;
// Use minetest.spawn_item to spawn a __builtin:item
lua_getglobal(L, "minetest");
lua_getfield(L, -1, "spawn_item");
if(lua_isnil(L, -1))
return 0;
lua_pushvalue(L, 1);
lua_pushstring(L, item.getItemString().c_str());
if(lua_pcall(L, 2, 1, 0))
script_error(L, "error: %s", lua_tostring(L, -1));
return 1;
/*lua_pushvalue(L, 1);
lua_pushstring(L, "__builtin:item");
lua_pushstring(L, item.getItemString().c_str());
return l_add_entity(L);*/
/*// Do it
ServerActiveObject *obj = createItemSAO(env, pos, item.getItemString());
int objectid = env->addActiveObject(obj);
// If failed to add, return nothing (reads as nil)
if(objectid == 0)
return 0;
// Return ObjectRef
objectrefGetOrCreate(L, obj);
return 1;*/
}
示例12: checkobject
// replace(self, itemstack or itemstring or table or nil) -> true
int LuaItemStack::l_replace(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaItemStack *o = checkobject(L, 1);
o->m_stack = read_item(L,2,getServer(L));
lua_pushboolean(L, true);
return 1;
}
示例13: process_binfile
void
process_binfile(FILE *in, FILE *out)
{
struct item_bin *ib;
while ((ib=read_item(in))) {
fwrite(ib, (ib->len+1)*4, 1, out);
}
}
示例14: dump
void
dump(FILE *in)
{
struct item_bin *ib;
while ((ib=read_item(in))) {
dump_itembin(ib);
}
}
示例15: ch_generate_ddsg
static void
ch_generate_ddsg(FILE *in, FILE *ref, FILE *idx, FILE *ddsg)
{
GHashTable *hash=coord_hash_new();
struct item_bin *ib;
int nodes=0,edges=0;
while ((ib=read_item(in))) {
int ccount=ib->clen/2;
struct coord *c=(struct coord *)(ib+1);
if (road_speed(ib->type)) {
add_node_to_hash(idx, hash, &c[0], &nodes);
add_node_to_hash(idx, hash, &c[ccount-1], &nodes);
edges++;
}
}
edge_hash=g_hash_table_new_full(edge_hash_hash, edge_hash_equal, edge_hash_slice_free, item_id_slice_free);
fseek(in, 0, SEEK_SET);
fprintf(ddsg,"d\n");
fprintf(ddsg,"%d %d\n", nodes, edges);
while ((ib=read_item(in))) {
int i,ccount=ib->clen/2;
struct coord *c=(struct coord *)(ib+1);
int n1,n2,speed=road_speed(ib->type);
struct item_id road_id;
double l;
fread(&road_id, sizeof(road_id), 1, ref);
if (speed) {
struct edge_hash_item *hi=g_slice_new(struct edge_hash_item);
struct item_id *id=g_slice_new(struct item_id);
*id=road_id;
dbg_assert((n1=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[0]))) != 0);
dbg_assert((n2=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[ccount-1]))) != 0);
l=0;
for (i = 0 ; i < ccount-1 ; i++) {
l+=sqrt(sq(c[i+1].x-c[i].x)+sq(c[i+1].y-c[i].y));
}
fprintf(ddsg,"%d %d %d 0\n", n1-1, n2-1, (int)(l*36/speed));
hi->first=n1-1;
hi->last=n2-1;
g_hash_table_insert(edge_hash, hi, id);
}
}
g_hash_table_destroy(hash);
}