当前位置: 首页>>代码示例>>C++>>正文


C++ GridFS类代码示例

本文整理汇总了C++中GridFS的典型用法代码示例。如果您正苦于以下问题:C++ GridFS类的具体用法?C++ GridFS怎么用?C++ GridFS使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GridFS类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: gridfs_list

/*
 * cursor,err = gridfs:list([lua_table or json_str])
 */
static int gridfs_list(lua_State *L) {
    GridFS *gridfs = userdata_to_gridfs(L, 1);

    BSONObj query;
    int type = lua_type(L, 2);
    if (type == LUA_TSTRING) {
        const char *jsonstr = luaL_checkstring(L, 2);
        query = fromjson(jsonstr);
    } else if (type == LUA_TTABLE) {
        lua_to_bson(L, 2, query);
    }
    std::auto_ptr<DBClientCursor> autocursor = gridfs->list(query);

    if (!autocursor.get()){
        lua_pushnil(L);
        lua_pushstring(L, LUAMONGO_ERR_CONNECTION_LOST);
        return 2;
    }

    DBClientCursor **cursor = (DBClientCursor **)lua_newuserdata(L, sizeof(DBClientCursor *));
    *cursor = autocursor.get();
    autocursor.release();

    luaL_getmetatable(L, LUAMONGO_CURSOR);
    lua_setmetatable(L, -2);

    return 1;
}
开发者ID:fushanlang,项目名称:luamongo,代码行数:31,代码来源:mongo_gridfs.cpp

示例2: gridfs_find_file

/*
 * gridfile, err = gridfs:find_file(query)
 */
static int gridfs_find_file(lua_State *L) {
    GridFS *gridfs = userdata_to_gridfs(L, 1);
    int resultcount = 1;

    if (!lua_isnoneornil(L, 2)) {
        try {
            int type = lua_type(L, 2);
            if (type == LUA_TTABLE) {
                BSONObj obj;
                lua_to_bson(L, 2, obj);
                GridFile gridfile = gridfs->findFile(obj);
                resultcount = gridfile_create(L, gridfile);
            } else {
                GridFile gridfile = gridfs->findFile(luaL_checkstring(L, 2));
                resultcount = gridfile_create(L, gridfile);
            }

        } catch (std::exception &e) {
            lua_pushnil(L);
            lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_GRIDFS, "find_file", e.what());
            resultcount = 2;
        }
    }

    return resultcount;

}
开发者ID:fushanlang,项目名称:luamongo,代码行数:30,代码来源:mongo_gridfs.cpp

示例3: gridfs_remove_file

/*
 * ok, err = gridfs:remove_file(filename)
 */
static int gridfs_remove_file(lua_State *L) {
    int resultcount = 1;

    GridFS *gridfs = userdata_to_gridfs(L, 1);

    const char *filename = luaL_checkstring(L, 2);

    try {
        gridfs->removeFile(filename);
        lua_pushboolean(L, 1);
    } catch (std::exception &e) {
        lua_pushboolean(L, 0);
        lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_GRIDFS, "remove_file", e.what());
        resultcount = 2;
    }

    return resultcount;
}
开发者ID:fushanlang,项目名称:luamongo,代码行数:21,代码来源:mongo_gridfs.cpp

示例4: gridfs_find_file_by_name

/*
 * gridfile, err = gridfs:find_file_by_name(filename)
 */
static int gridfs_find_file_by_name(lua_State *L) {
    GridFS *gridfs = userdata_to_gridfs(L, 1);
    int resultcount = 1;

    if (!lua_isnoneornil(L, 2)) {
	try {
	    GridFile gridfile = gridfs->findFileByName(luaL_checkstring(L, 2));
	    resultcount = gridfile_create(L, gridfile);
	    
        } catch (std::exception &e) {
            lua_pushnil(L);
            lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_GRIDFS, "find_file_by_name", e.what());
            resultcount = 2;
        }
    }

    return resultcount;

}
开发者ID:fushanlang,项目名称:luamongo,代码行数:22,代码来源:mongo_gridfs.cpp

示例5: gridfs_store_file

/*
 * bson, err = gridfs:store_file(filename[, remote_file[, content_type]])
 */
static int gridfs_store_file(lua_State *L) {
    int resultcount = 1;

    GridFS *gridfs = userdata_to_gridfs(L, 1);

    const char *filename = luaL_checkstring(L, 2);
    const char *remote = luaL_optstring(L, 3, "");
    const char *content_type = luaL_optstring(L, 4, "");

    try {
        BSONObj res = gridfs->storeFile(filename, remote, content_type);
        bson_to_lua(L, res);
    } catch (std::exception &e) {
        lua_pushnil(L);
        lua_pushfstring(L, LUAMONGO_ERR_CALLING, LUAMONGO_GRIDFS, "store_file", e.what());
        resultcount = 2;
    }

    return resultcount;
}
开发者ID:fushanlang,项目名称:luamongo,代码行数:23,代码来源:mongo_gridfs.cpp

示例6: gridfs_list

/*
 * cursor,err = gridfs:list()
 */
static int gridfs_list(lua_State *L) {
    GridFS *gridfs = userdata_to_gridfs(L, 1);

    std::auto_ptr<DBClientCursor> autocursor = gridfs->list();

    if (!autocursor.get()) {
        lua_pushnil(L);
        lua_pushstring(L, LUAMONGO_ERR_CONNECTION_LOST);
        return 2;
    }

    DBClientCursor **cursor = (DBClientCursor **)lua_newuserdata(L, sizeof(DBClientCursor *));
    *cursor = autocursor.get();
    autocursor.release();

    luaL_getmetatable(L, LUAMONGO_CURSOR);
    lua_setmetatable(L, -2);

    return 1;
}
开发者ID:lywaterman,项目名称:luamongo,代码行数:23,代码来源:mongo_gridfs.cpp

示例7: main

int main() {
    try {
        DBClientBase *conn = NULL;
        string err_msg;
        ConnectionString cs = ConnectionString::parse("localhost", err_msg);
        
        if (!cs.isValid()) {
            throw "bad: " + err_msg;
        }
        
        try {
            conn = cs.connect(err_msg);
        } catch (DBException &e) {
            cout << "caught " << err_msg << endl;
            return 1;
        }
        
        if (!conn){
            cout<<"Unable to connect to DB"<<endl;
            return 1;
        }
        
//        BSONObjBuilder b;
//        b.append("name", "Joe");
//        b.append("age", 33);
//        BSONObj p = b.obj();
//        
//        conn->insert("db.coll",p,0);
        
        
        GridFS * fs;
       
        fs = new GridFS(*conn,"test");
        BSONObj p = fs->storeFile("pic.JPG");
        conn->insert("db.coll",p,0);
    }
    catch( DBException &e ) {
        cout << "caught " << e.what() << endl;
    }
    return 0;
}
开发者ID:dourabbit,项目名称:ProjMeToo,代码行数:41,代码来源:gridfsTest.cpp

示例8: main

int
main(int argc, char **argv)
{
  ArgumentParser argp(argc, argv, "ho:fd:c:");
  if (argp.has_arg("h")) {
    print_usage(argv[0]);
    exit(0);
  }

  const std::vector<const char *> &items = argp.items();

  std::string output_dir = "tmp/";
  std::string database = "fflog";
  std::string collection;
  std::string query_coll;
  bool filename_indexed = ! argp.has_arg("f");

  std::vector<std::pair<long long, long long> > times;

  if (argp.has_arg("o")) {
    output_dir = argp.arg("o");
    if (output_dir[output_dir.length() - 1] != '/') {
      output_dir += "/";
    }
  }
  if (argp.has_arg("d")) {
    database = argp.arg("d");
  }
  if (argp.has_arg("c")) {
    collection = argp.arg("c");
  } else {
    print_usage(argv[0]);
    printf("No collection given\n");
    exit(-1);
  }

  query_coll = database + "." + collection;

  if (items.empty()) {
    times.push_back(std::make_pair(0L, std::numeric_limits<long long>::max()));
  } else {
    for (unsigned int i = 0; i < items.size(); ++i) {
      std::string item = items[i];
      std::string::size_type dotpos = item.find("..");
      if (dotpos == std::string::npos) {
	// singular timestamp
	long int ts = argp.parse_item_int(i);
	times.push_back(std::make_pair(ts, ts));	
      } else {
	// range
	std::string first_ts, second_ts;
	first_ts = item.substr(0, dotpos);
	second_ts = item.substr(dotpos + 2);
	times.push_back(std::make_pair(StringConversions::to_long(first_ts),
				       StringConversions::to_long(second_ts)));
      }
    }
  }

  unsigned int image_n = 0;

  DBClientConnection *mongodb_client =
    new DBClientConnection(/* auto reconnect */ true);
  std::string errmsg;
  mongodb_client->connect("localhost", errmsg);

  GridFS *gridfs = new GridFS(*mongodb_client, "fflog");


  for (unsigned int i = 0; i < times.size(); ++i) {
    Query q;

    if (times[i].first == times[i].second) {
      printf("Querying for timestamp %lli\n", times[i].first);
      q = QUERY("timestamp" << times[i].first).sort("timestamp", 1);
    } else {
      printf("Querying for range %lli..%lli\n", times[i].first, times[i].second);
      q = QUERY("timestamp"
		<< mongo::GTE << times[i].first
		<< mongo::LTE << times[i].second)
	.sort("timestamp", 1);
    }

#if __cplusplus >= 201103L
    std::unique_ptr<mongo::DBClientCursor> cursor =
      mongodb_client->query(query_coll, q);
#else
    std::auto_ptr<mongo::DBClientCursor> cursor =
      mongodb_client->query(query_coll, q);
#endif

    while (cursor->more()) {
      BSONObj doc = cursor->next();
      
      BSONObj imgdoc = doc.getObjectField("image");
      if (imgdoc["colorspace"].String() == "RGB") {
	std::string filename = imgdoc.getFieldDotted("data.filename").String();
	long filesize = imgdoc.getFieldDotted("data.length").numberLong();
	std::string image_id = imgdoc["image_id"].String();

//.........这里部分代码省略.........
开发者ID:timn,项目名称:fawkes,代码行数:101,代码来源:ffmongodb_save_imgs.cpp


注:本文中的GridFS类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。