本文整理汇总了C++中ASSERT_LOG函数的典型用法代码示例。如果您正苦于以下问题:C++ ASSERT_LOG函数的具体用法?C++ ASSERT_LOG怎么用?C++ ASSERT_LOG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ASSERT_LOG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT_LOG
DisplayDevicePtr DisplayDevice::factory(const std::string& type)
{
ASSERT_LOG(!get_display_registry().empty(), "No display device drivers registered.");
auto it = get_display_registry().find(type);
if(it == get_display_registry().end()) {
LOG_WARN("Requested display driver '" << type << "' not found, using default: " << get_display_registry().begin()->first);
current_display_device() = get_display_registry().begin()->second();
return get_display_registry().begin()->second();
}
current_display_device() = it->second();
return it->second();
}
示例2: convert_numeric
float convert_numeric(const variant& node)
{
if(node.is_int()) {
return clamp<int>(node.as_int32(), 0, 255) / 255.0f;
} else if(node.is_float()) {
return clamp<float>(node.as_float(), 0.0f, 1.0f);
} else if(node.is_string()) {
return convert_string_to_number(node.as_string());
}
ASSERT_LOG(false, "attribute of Color value was expected to be numeric type.");
return 1.0f;
}
示例3: switch
double as3_value::to_number()
{
switch(type_) {
case UNDEFINED: return std::numeric_limits<double>::infinity();
case BOOLEAN: return b_ ? 1 : 0;
case NUMERIC: return d_;
case OBJECT: return o_ == NULL ? 0 : o_->to_number();
case PROPERTY: {
ASSERT_LOG(false, "XXX todo PROPERTY::to_number");
}
}
ASSERT_LOG(type_ != STRING, "FATAL: unknown type_ value: " << type_);
// String case -- we do thing the lazy way, not the compliant way.
double num = std::numeric_limits<double>::infinity();
try {
num = boost::lexical_cast<double>(s_);
} catch(boost::bad_lexical_cast&) {
std::cerr << "Caught a bad floating point cast from " << s_ << " assuming infinity" << std::endl;
}
return num;
}
示例4: get_color_from_name
const SDL_Color& get_color_from_name(std::string name)
{
if(get_color_cache().empty()) {
color_cache_init();
}
std::map<std::string,boost::function<const SDL_Color&()> >::iterator it = get_color_cache().find(name);
if(it != get_color_cache().end()) {
return it->second();
}
ASSERT_LOG(false, "Color \"" << name << "\" not known!");
return color_black();
}
示例5: quick_draw
rect quick_draw(int x,
int y,
const std::string& str,
const std::string& font,
int size,
const color& c)
{
SDL_Color bg = {0, 0, 0, 255};
surface_ptr surf = surface_ptr(new surface(TTF_RenderUTF8_Shaded(font::get_font(font, size).get(), str.c_str(), c.as_sdl_color(), bg)));
ASSERT_LOG(surf != NULL, "Couldn't render text into texture");
blit_2d_texture(texture::get(surf), static_cast<float>(x), static_cast<float>(y), static_cast<float>(surf->width()), static_cast<float>(surf->height()));
return rect(x, y, surf->width(), surf->height());
}
示例6: write_file
void write_file(const std::string& fname, const std::string& data)
{
bool absolute_path = fname[0] == '/' ? true : false;
//Try to ensure that the dir the file is in exists.
std::vector<std::string> components;
boost::split(components, fname, std::bind2nd(std::equal_to<char>(), '/'));
boost::filesystem::path p(fname);
ASSERT_LOG(get_dir(p.parent_path().string()) != "", "Couldn't create directory: " << p.parent_path().string());
//Write the file.
std::ofstream file(fname.c_str(),std::ios_base::binary);
file << data;
}
示例7: ASSERT_LOG
bool File::readBuffer(uint8_t* _pBuffer, int iBufferSize)
{
ASSERT_LOG(m_pHandle != NULL, "File handle is invalid");
ASSERT_LOG(_pBuffer != NULL, "Buffer is invalid");
if (-1 == iBufferSize)
{
iBufferSize = getLength();
}
if (0 == iBufferSize)
{
return false;
}
if (static_cast<int>(fread(_pBuffer, 1, iBufferSize, (FILE*)m_pHandle)) != iBufferSize)
{
return false;
}
return true;
}
示例8: surface_ptr
void text::quick_draw(render& render_obj,
GLfloat x,
GLfloat y,
const std::string& str,
const std::string& font,
int size,
const color& c)
{
SDL_Color bg = {0, 0, 0, 255};
surface_ptr surf = surface_ptr(TTF_RenderUTF8_Shaded(font::get_font(font, size).get(), str.c_str(), c.as_sdl_color(), bg), SDL_FreeSurface);
ASSERT_LOG(surf != NULL, "Couldn't render text into texture");
render_obj.blit_2d_texture(texture::get(surf), x, y);
}
示例9: ASSERT_LOG
SurfacePtr Surface::create(int width,
int height,
int bpp,
uint32_t rmask,
uint32_t gmask,
uint32_t bmask,
uint32_t amask)
{
// XXX no caching as default?
ASSERT_LOG(get_surface_creator().empty() == false, "No resources registered to create surfaces from masks.");
auto create_fn_tuple = get_surface_creator().begin()->second;
return std::get<2>(create_fn_tuple)(width, height, bpp, rmask, gmask, bmask, amask);
}
示例10: SDL_GetSurfaceBlendMode
Surface::BlendMode SurfaceSDL::getBlendMode() const
{
SDL_BlendMode sdl_bm;
SDL_GetSurfaceBlendMode(surface_, &sdl_bm);
switch(sdl_bm) {
case SDL_BLENDMODE_NONE: return BLEND_MODE_NONE;
case SDL_BLENDMODE_BLEND: return BLEND_MODE_BLEND;
case SDL_BLENDMODE_ADD: return BLEND_MODE_ADD;
case SDL_BLENDMODE_MOD: return BLEND_MODE_MODULATE;
}
ASSERT_LOG(false, "Unrecognised SDL blend mode: " << sdl_bm);
return BLEND_MODE_NONE;
}
示例11: if
void Material::init(const variant& node)
{
blend_.set(BlendModeConstants::BM_SRC_ALPHA, BlendModeConstants::BM_ONE_MINUS_SRC_ALPHA);
if(node.is_string()) {
name_ = node.as_string();
tex_.emplace_back(DisplayDevice::createTexture(name_));
} else if(node.is_map()) {
name_ = node["name"].as_string();
// XXX: technically a material could have multiple technique's and passes -- ignoring for now.
ASSERT_LOG(node.has_key("technique"), "PSYSTEM2: 'material' must have 'technique' attribute.");
ASSERT_LOG(node["technique"].has_key("pass"), "PSYSTEM2: 'material' must have 'pass' attribute.");
const variant& pass = node["technique"]["pass"];
use_lighting_ = pass["lighting"].as_bool(false);
use_fog_ = pass["fog_override"].as_bool(false);
do_depth_write_ = pass["depth_write"].as_bool(true);
do_depth_check_ = pass["depth_check"].as_bool(true);
if(pass.has_key("scene_blend")) {
blend_.set(pass["scene_blend"]);
}
if(pass.has_key("texture_unit")) {
if(pass["texture_unit"].is_map()) {
tex_.emplace_back(createTexture(pass["texture_unit"]));
} else if(pass["texture_unit"].is_list()) {
for(size_t n = 0; n != pass["texture_unit"].num_elements(); ++n) {
tex_.emplace_back(createTexture(pass["texture_unit"][n]));
}
} else {
ASSERT_LOG(false, "'texture_unit' attribute must be map or list ");
}
}
if(pass.has_key("rect")) {
draw_rect_ = rectf(pass["rect"]);
}
} else {
ASSERT_LOG(false, "Materials(Textures) must be either a single string filename or a map.");
}
}
示例12: client_handle_response
/* Handle a response to a given request. if this is a quorum setting, choose the
* right response. Then make sure all the requests are satisfied in a fragmented
* request scenario and then use the post coalesce logic to cook up a combined
* response
*/
static rstatus_t
client_handle_response(struct conn *conn, msgid_t reqid, struct msg *rsp)
{
ASSERT_LOG(!rsp->peer, "response %lu:%lu has peer set",
rsp->id, rsp->parent_id);
// now the handler owns the response.
ASSERT(conn->type == CONN_CLIENT);
// Fetch the original request
struct msg *req = dictFetchValue(conn->outstanding_msgs_dict, &reqid);
if (!req) {
log_notice("looks like we already cleanedup the request for %d", reqid);
rsp_put(rsp);
return DN_OK;
}
// we have to submit the response irrespective of the unref status.
rstatus_t status = msg_handle_response(req, rsp);
if (conn->waiting_to_unref) {
// dont care about the status.
if (req->awaiting_rsps)
return DN_OK;
// all responses received
dictDelete(conn->outstanding_msgs_dict, &reqid);
log_info("Putting req %d", req->id);
req_put(req);
client_unref_internal_try_put(conn);
return DN_OK;
}
if (status == DN_NOOPS) {
// by now the response is dropped
if (!req->awaiting_rsps) {
// if we have sent the response for this request or the connection
// is closed and we are just waiting to drain off the messages.
if (req->rsp_sent) {
dictDelete(conn->outstanding_msgs_dict, &reqid);
log_info("Putting req %d", req->id);
req_put(req);
}
}
} else if (status == DN_OK) {
g_pre_coalesce(req->selected_rsp);
if (req_done(conn, req)) {
struct context *ctx = conn_to_ctx(conn);
status = event_add_out(ctx->evb, conn);
if (status != DN_OK) {
conn->err = errno;
}
}
}
return status;
}
示例13: compress
std::vector<char> compress(const std::vector<char>& data, int compression_level) {
z_stream strm;
int ret;
int pos_in = 0;
int pos_out = 0;
int flush;
std::vector<char> in(data); // <-- annoying work around for old versions of zlib that don't define z_stream.in as const, by defining ZLIB_CONST
std::vector<char> out;
ASSERT_LOG(compression_level >= -1 && compression_level <= 9, "Compression level must be between -1(default) and 9.");
memset(&strm, 0, sizeof(z_stream));
if(deflateInit(&strm, compression_level) != Z_OK) {
CompressionException e = {"Unable to initialise deflation routines."};
throw CompressionException(e);
}
do {
strm.avail_in = (in.size() - pos_in) > CHUNK ? CHUNK : in.size() - pos_in;
flush = (strm.avail_in + pos_in) == in.size() ? Z_FINISH : Z_NO_FLUSH;
if(in.size()) {
strm.next_in = reinterpret_cast<Bytef*>(&in[pos_in]);
} else {
strm.next_in = 0;
}
do {
out.resize(pos_out - out.size() + CHUNK);
strm.avail_out = CHUNK;
strm.next_out = reinterpret_cast<Bytef*>(&out[pos_out]);
ret = deflate(&strm, flush); // no bad return value
ASSERT_LOG(ret != Z_STREAM_ERROR, "Error in the compression stream");
pos_out += CHUNK - strm.avail_out;
} while (strm.avail_out == 0);
ASSERT_LOG(strm.avail_in == 0, "zip::compress(): All input used"); // all input will be used
} while(flush != Z_FINISH);
ASSERT_LOG(ret == Z_STREAM_END, "zip::compress(): stream will be complete");
deflateEnd(&strm);
out.resize(pos_out);
return out;
}
示例14: switch
float node::as_float() const
{
switch(type()) {
case NODE_TYPE_INTEGER:
return float(i_);
case NODE_TYPE_FLOAT:
return f_;
case NODE_TYPE_BOOL:
return b_ ? 1.0f : 0.0f;
default: break;
}
ASSERT_LOG(false, "as_float() type conversion error from " << type_as_string() << " to float");
return 0;
}
示例15: loc_
tile::tile(int x, int y, const std::string& data)
: loc_(x, y)
{
std::vector<std::string> v = util::split(data, ' ');
ASSERT_GE(v.size(), 1);
terrain_ = terrain::get(v.front());
ASSERT_LOG(terrain_, "Could not find terrain " << v.front());
if(v.size() > 1) {
productivity_ = atoi(v[1].c_str());
} else {
productivity_ = terrain_->calculate_production_value();
}
}