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


C++ context::get_value方法代码示例

本文整理汇总了C++中context::get_value方法的典型用法代码示例。如果您正苦于以下问题:C++ context::get_value方法的具体用法?C++ context::get_value怎么用?C++ context::get_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在context的用法示例。


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

示例1: execute

void tag_query::execute(context &ctx, std::ostream &out,
  const tag *caller) const {
	// obtain the current database of current context
	string db_ptr = ctx.get_value(string("@ODBC:[email protected]") +
	  get_parameter(ctx, "database"));
	if (db_ptr.empty()) {
		string id = get_parameter(ctx, "database");
		if (id.empty()) {
			id = _("(default)");
		}
		throw tag_query_exception(
		  (format(_("database (id='{0}') is not defined in the current "
		    "context")) % id).str());
	}
	connection *db = (connection*)from_string<void*>(db_ptr);
	// intitialize the query
	query q(*db);
	query::parameters &p = q.prepare(get_parameter(ctx, "statement"));
	// process parameters
	vector<string> params = tokenize()(get_parameter(ctx, "parameters"));
	vector<string>::const_iterator j = params.begin();
	for (query::parameters::iterator i = p.begin(); i != p.end(); ++i) {
		if (i->name.empty()) {
			// initialize unnamed parameter
			if (j != params.end()) {
				i->value = *j;
				++j;
			}
		} else {
			// initialize named parameter
			i->value = ctx.get_value(i->name);
		}
	}
	// execute the query
	const query::fields &f = q.execute();
	// for each row execute the subnodes
	while (q.next()) {
		ctx.enter();
		try {
			for (query::fields::const_iterator i = f.begin(); i != f.end(); ++i) {
				ctx.add_value(i->name, i->get_value());
			}
			// call inherited method
			tag_impl::execute(ctx, out, caller);
		}
		catch (...) {
			ctx.leave();
			throw;
		}
		ctx.leave();
	}
}
开发者ID:wolfsoft,项目名称:dbpager,代码行数:52,代码来源:tag_query.cpp

示例2: execute

void tag_delete::execute(context &ctx, std::ostream &out,
  const tag *caller) const {

	const string &collection = get_parameter(ctx, "collection");
	if (collection.empty())
		throw tag_delete_exception(
		  _("query collection (collection) is not defined"));

	string db_ptr = ctx.get_value("@MONGODB:[email protected]");
	if (db_ptr.empty()) {
		throw tag_delete_exception(
		  _("MongoDB database is not defined in the current context"));
	}
	database *db = (database*)from_string<void*>(db_ptr);

	ctx.enter();
	try {
		BSONObjBuilder b;
		ctx.add_value("@MONGODB:[email protected]", to_string<BSONObjBuilder*>(&b));

		// call inherited method
		tag_impl::execute(ctx, out, caller);

		db->remove(collection, b.obj());

	}
	catch (...) {
		ctx.leave();
		throw;
	}
	ctx.leave();
}
开发者ID:wolfsoft,项目名称:dbpager,代码行数:32,代码来源:tag_delete.cpp

示例3: execute

void tag_set::execute(context &ctx, std::ostream &out,
  const tag *caller) const {
	string name = get_parameter(ctx, "name");
	if (name.empty())
		throw tag_storage_exception(
		  _("key name (name) is not defined"));
	// obtain the current storage of current context by ugly hack
	string db_ptr = ctx.get_value(string("@BDB:[email protected]") +
	  get_parameter(ctx, "storage"));
	if (db_ptr.empty()) {
		string id = get_parameter(ctx, "storage");
		if (id.empty()) {
			id = _("(default)");
		}
		throw tag_set_exception(
		  (format(_("storage (id='{0}') is not defined in the current context")) %
		    id).str());
	}
	bdb_database *db = (bdb_database*)from_string<void*>(db_ptr);
	// cache protected output
	ostringstream s(ostringstream::out | ostringstream::binary);
	// call inherited method
	tag_impl::execute(ctx, s, caller);
	// set the data
	db->set(name, s.str());
}
开发者ID:wolfsoft,项目名称:dbpager,代码行数:26,代码来源:tag_set.cpp

示例4: execute

void tag_database::execute(context &ctx, std::ostream &out,
  const tag *caller) const {
	const string &dsn = get_parameter(ctx, "dsn");
	const string &database = get_parameter(ctx, "id");
	if (dsn.empty()) {
		throw tag_database_exception(
		  _("data source name (dsn) is not defined"));
	}

	string db_ptr = ctx.get_value(string("@SQLITE:[email protected]") + database);
	if (!db_ptr.empty()) {
		tag_impl::execute(ctx, out, caller);
		return;
	}

	ctx.enter();
	try {
		pool_ptr<sqlite_connection> c = database_pool::instance().acquire(dsn);
		if (!c->is_open())
			c->open(dsn);
		// save the pointer to database for nested tags
		ctx.add_value(string("@SQLITE:[email protected]") + get_parameter(ctx, "id"),
		  to_string<sqlite3*>(c->get_ptr()));
		tag_impl::execute(ctx, out, caller);
		ctx.leave();
	}
	catch (...) {
		ctx.leave();
		throw;
	}

}
开发者ID:wolfsoft,项目名称:dbpager,代码行数:32,代码来源:tag_database.cpp

示例5: execute

void tag_task::execute(context &ctx, std::ostream &out,
                       const tag *caller) const {
    const string &function = get_parameter(ctx, "function");
    string server_ptr = ctx.get_value("@GEARMAN:[email protected]");
    if (server_ptr.empty())
        throw tag_task_exception(
            _("gearman server is not defined in the current "
              "context"));
    server *gm = (server*)from_string<void*>(server_ptr);
    ctx.enter();
    try {
        // cache protected output
        ostringstream s(ostringstream::out | ostringstream::binary);
        // call inherited method
        tag_impl::execute(ctx, s, caller);
        gm->add_task(function, s.str());
        ctx.leave();
    }
    catch (...) {
        ctx.leave();
        throw;
    }
}
开发者ID:wolfsoft,项目名称:dbpager,代码行数:23,代码来源:tag_task.cpp


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