本文整理汇总了C++中sentinel函数的典型用法代码示例。如果您正苦于以下问题:C++ sentinel函数的具体用法?C++ sentinel怎么用?C++ sentinel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sentinel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: project_bounding_on_axis
void project_bounding_on_axis(const Bounding *b, const Vector *axis, double *projection_start, double *projection_end)
{
assert(b && "Bad bounding pointer.");
assert(axis && "Bad axis pointer.");
assert(projection_start && projection_end && "Bad projection pointers.");
switch (b->bounding_type)
{
case bounding_box:
project_box_on_axis(b, axis, projection_start, projection_end);
return;
case bounding_sphere:
project_sphere_on_axis(b, axis, projection_start, projection_end);
return;
case bounding_composite:
sentinel("Cannot project composite bounding.", "");
default:
sentinel("Unknown bounding type.", "");
}
error:
assert(false);
}
示例2: sky_property_get_standard_data_type_name
// Retrieves a reference to a standardized bstring that represents the name
// of the data type.
//
// type_name - The name of the type.
// ret - A pointer to where the standardized type name should be returned.
//
// Returns 0 if successful, otherwise returns -1.
int sky_property_get_standard_data_type_name(bstring type_name, bstring *ret)
{
check(type_name != NULL, "Type name required");
check(ret != NULL, "Return pointer required");
// Check against standard types.
if(biseq(&SKY_DATA_TYPE_INT, type_name)) {
*ret = &SKY_DATA_TYPE_INT;
}
else if(biseq(&SKY_DATA_TYPE_FLOAT, type_name)) {
*ret = &SKY_DATA_TYPE_FLOAT;
}
else if(biseq(&SKY_DATA_TYPE_BOOLEAN, type_name)) {
*ret = &SKY_DATA_TYPE_BOOLEAN;
}
else if(biseq(&SKY_DATA_TYPE_STRING, type_name)) {
*ret = &SKY_DATA_TYPE_STRING;
}
// If this is not a standard type then return the name that came in.
else {
sentinel("Type is not a standard type: %s", bdata(type_name));
}
return 0;
error:
return -1;
}
示例3: Command_install
int Command_install(
apr_pool_t *p, const char *url, const char *configure_opts,
const char *make_opts, const char *install_opts
) {
int rc = 0;
// first clean up
check(Shell_exec(CLEANUP_SH, NULL) == 0,
"Faild to clean up before building.");
// next, make sure it isn't already installed
rc = DB_find(url);
check(rc != -1, "Error checking the installed database");
if (rc == 1) {
log_info("Package already installed.");
return 0;
}
// it isn't installed. So, fetch.
rc = Command_fetch(p, url, 0);
// if fetch worked, build.
if (rc == 1) {
rc = Command_build(p, url, configure_opts, make_opts, install_opts);
} else if (rc == 0) {
// no install needed... I haven't read fetch yet so I'm not sure how
// this would happen.
log_info("Depends successfully installed: %s", url);
} else {
sentinel("Install failed: %s", url);
}
// cleanup again. It doesn't matter whether we check errors this time.
Shell_exec(CLEANUP_SH, NULL);
return 0;
error:
return -1;
}
示例4: qip_ast_node_get_type
// Recursively determines the type of a node.
//
// node - The node to determine the type for.
// module - The compilation unit this node is a part of.
// type - A pointer to where the type should be returned.
//
// Returns 0 if successful, otherwise returns -1.
int qip_ast_node_get_type(qip_ast_node *node, qip_module *module,
qip_ast_node **type)
{
int rc;
check(node != NULL, "Node required");
// Delegate to each type.
switch(node->type) {
case QIP_AST_TYPE_INT_LITERAL: rc = qip_ast_int_literal_get_type(node, type); break;
case QIP_AST_TYPE_FLOAT_LITERAL: rc = qip_ast_float_literal_get_type(node, type); break;
case QIP_AST_TYPE_BOOLEAN_LITERAL: rc = qip_ast_boolean_literal_get_type(node, type); break;
case QIP_AST_TYPE_STRING_LITERAL: rc = qip_ast_string_literal_get_type(node, type); break;
case QIP_AST_TYPE_NULL_LITERAL: rc = qip_ast_null_literal_get_type(node, type); break;
case QIP_AST_TYPE_ARRAY_LITERAL: rc = qip_ast_array_literal_get_type(node, type); break;
case QIP_AST_TYPE_BINARY_EXPR: rc = qip_ast_binary_expr_get_type(node, module, type); break;
case QIP_AST_TYPE_VAR_REF: rc = qip_ast_var_ref_get_type(node, module, type); break;
case QIP_AST_TYPE_SIZEOF: rc = qip_ast_sizeof_get_type(node, type); break;
case QIP_AST_TYPE_OFFSETOF: rc = qip_ast_offsetof_get_type(node, type); break;
case QIP_AST_TYPE_ALLOCA: rc = qip_ast_alloca_get_type(node, type); break;
default: {
sentinel("AST node does not have a type");
break;
}
}
check(rc == 0, "Unable to retrieve type name");
return 0;
error:
*type = NULL;
return -1;
}
示例5: qip_ast_node_get_var_pointer
// Retrieves a variable pointer to a given node. This only works with variable
// references and struct member accesses.
//
// node - The variable node to retrieve the pointer for.
// module - The compilation unit this node is a part of.
// value - A pointer to where the LLVM value should be returned.
//
// Returns 0 if successful, otherwise returns -1.
int qip_ast_node_get_var_pointer(qip_ast_node *node, qip_module *module,
LLVMValueRef *value)
{
int rc;
check(node != NULL, "Node is required");
check(module != NULL, "Module is required");
check(module->llvm_module != NULL, "LLVM Module is required");
check(module->compiler != NULL, "Module compiler is required");
check(module->compiler->llvm_builder != NULL, "LLVM Builder is required");
// Delegate codegen to AST nodes.
switch(node->type) {
case QIP_AST_TYPE_VAR_REF: {
rc = qip_ast_var_ref_get_pointer(node, module, NULL, value);
check(rc == 0, "Unable to retrieve pointer to variable reference");
break;
}
default:
{
sentinel("Unable to retrieve pointer for AST node");
break;
}
}
return 0;
error:
*value = NULL;
return -1;
}
示例6: sky_event_data_sizeof
// Calculates the total number of bytes needed to store an event data.
//
// data - The event data item.
size_t sky_event_data_sizeof(sky_event_data *data)
{
size_t sz = 0;
sz += sizeof(data->key);
switch(data->data_type) {
case SKY_DATA_TYPE_INT:
sz += minipack_sizeof_int(data->int_value);
break;
case SKY_DATA_TYPE_DOUBLE:
sz += minipack_sizeof_double(data->double_value);
break;
case SKY_DATA_TYPE_BOOLEAN:
sz += minipack_sizeof_bool(data->boolean_value);
break;
case SKY_DATA_TYPE_STRING:
sz += minipack_sizeof_raw(blength(data->string_value));
sz += blength(data->string_value);
break;
default:
sentinel("Invalid data type (%d) for event data", data->data_type);
}
return sz;
error:
return 0;
}
示例7: sky_event_data_copy
// Creates a copy of an event data item.
//
// source - The event data to copy.
// target - A reference to the new event data item.
//
// Returns 0 if successful, otherwise returns -1.
int sky_event_data_copy(sky_event_data *source, sky_event_data **target)
{
check(source != NULL, "Event data source required for copy");
switch(source->data_type) {
case SKY_DATA_TYPE_STRING:
*target = sky_event_data_create_string(source->key, source->string_value);
break;
case SKY_DATA_TYPE_INT:
*target = sky_event_data_create_int(source->key, source->int_value);
break;
case SKY_DATA_TYPE_DOUBLE:
*target = sky_event_data_create_double(source->key, source->double_value);
break;
case SKY_DATA_TYPE_BOOLEAN:
*target = sky_event_data_create_boolean(source->key, source->boolean_value);
break;
default:
sentinel("Invalid data type (%d) for event data", source->data_type);
}
return 0;
error:
if(*target) sky_event_data_free(*target);
*target = NULL;
return -1;
}
示例8: Map_del
void* Map_del(Map *map, char* key) {
sentinel("not yet implemented");
// if (map->length == 0) {
// return NULL;
// }
void *data = map->last->data;
// if (map->length == 1) {
// free(map->last);
// map->last = NULL;
// map->first = NULL;
// }
// if (map->length > 1) {
// struct MapNode *removee = map->last;
// map->last = removee->prev;
// free(removee);
// map->last->next = NULL;
// }
// map->length--;
return data;
error:
return NULL;
}
示例9: malloc
Value *Value_create(ValueType type, void *data) {
Value *val = malloc(sizeof(Value));
val->type = type;
switch(val->type) {
case VAL_QSTRING: val->as.string = data;
break;
case VAL_NUMBER: val->as.number = data;
break;
case VAL_CLASS: val->as.cls = data;
break;
case VAL_LIST: val->as.list = data;
break;
case VAL_HASH: val->as.hash = data;
break;
case VAL_IDENT: val->as.ident = data;
break;
case VAL_REF: val->as.ref = data;
break;
default:
sentinel("Unknown value type: %d", val->type);
}
return val;
error:
return val;
}
示例10: GTBoard_Parse
int GTBoard_Parse(GTBoard* b, char* s)
{
b->err = GTBoardError_None;
int parsedUnits = 0;
char* tok;
GTLexer l;
GTLexer_Init(&l, s);
GTLexer_Skip(&l, whitespace);
while ((tok = GTLexer_GetToken(&l, whitespace)) != NULL) {
GTLexer_GetToken(&l, "{");
char* s = GTLexer_GetToken(&l, "}");
if (strcmp(tok, fileTokens[GTBoardFileToken_Units]) == 0) {
check(GTBoard_ParseUnits(b, s) == 0, "parsing units failed");
parsedUnits = 1;
} else if (strcmp(tok, fileTokens[GTBoardFileToken_Tiles]) == 0) {
check(!parsedUnits, "tiles must be read before units");
check(GTBoard_ParseTiles(b, s) == 0, "parsing tiles failed");
} else if (strcmp(tok, fileTokens[GTBoardFileToken_Options]) == 0) {
// do nothing
} else {
sentinel("unidentified token %.*s", 80, tok);
}
GTLexer_Skip(&l, whitespace);
}
return 0;
error:
b->err = GTBoardError_BadParse;
return -1;
}
示例11: GTBoard_ParseUnit
int GTBoard_ParseUnit(GTBoard* b, char* tok, int pos)
{
char u = tok[0];
char l = tok[1];
GTPlayer p = GTPlayer_None;
if ('a' <= u && u <= 'z') {
p = GTPlayer_Black;
} else if ('A' <= u && u <= 'Z') {
p = GTPlayer_White;
} else {
sentinel("invalid unit token %c", u);
}
GTUnitType t = GTUnitType_None;
int i;
for (i = 0; i < GTUnitType_Size; i++) {
if (u != unitChar[p][i]) { continue; }
t = i;
}
check(t != GTUnitType_None, "unrecognized unit %c", u);
int life = l - '0';
check(life > 0, "life = %d too low", life);
check(GTBoard_CreateUnit(b, p, t, pos) == 0, "create unit failed");
b->units[b->board[pos]].life = life;
return 0;
error:
return -1;
}
示例12: sky_path_add_event
// Adds an event to a path. An event can only be added if the event's object id
// matches the path's object id.
//
// path - The path to add the event to.
// event - The event to add to the path.
//
// Returns 0 if successful, otherwise returns -1.
int sky_path_add_event(sky_path *path, sky_event *event)
{
// Validation.
check(path != NULL, "Path required");
check(path->object_id != 0, "Path object id cannot be null");
check(event != NULL, "Event required");
check(path->object_id == event->object_id, "Event object id (%d) does not match path object id (%d)", event->object_id, path->object_id);
// Raise error if event has already been added.
unsigned int i;
for(i=0; i<path->event_count; i++) {
if(path->events[i] == event) {
sentinel("Event has already been added to path");
}
}
// Allocate space for event.
path->event_count++;
path->events = realloc(path->events, sizeof(sky_event*) * path->event_count);
check_mem(path->events);
// Append event to the end.
path->events[path->event_count-1] = event;
// Sort events.
sort_events(path);
return 0;
error:
return -1;
}
示例13: sentinel
void
ComputeIndicatorThread::onElement(const Elem * elem)
{
for (const auto & it : _aux_sys._elem_vars[_tid])
{
MooseVariable * var = it.second;
var->prepareAux();
}
_fe_problem.prepare(elem, _tid);
_fe_problem.reinitElem(elem, _tid);
// Set up Sentinel class so that, even if reinitMaterials() throws, we
// still remember to swap back during stack unwinding.
SwapBackSentinel sentinel(_fe_problem, &FEProblemBase::swapBackMaterials, _tid);
_fe_problem.reinitMaterials(_subdomain, _tid);
// Compute
if (!_finalize)
{
if (_indicator_whs.hasActiveBlockObjects(_subdomain, _tid))
{
const std::vector<std::shared_ptr<Indicator>> & indicators =
_indicator_whs.getActiveBlockObjects(_subdomain, _tid);
for (const auto & indicator : indicators)
indicator->computeIndicator();
}
}
// Finalize
else
{
if (_indicator_whs.hasActiveBlockObjects(_subdomain, _tid))
{
const std::vector<std::shared_ptr<Indicator>> & indicators =
_indicator_whs.getActiveBlockObjects(_subdomain, _tid);
for (const auto & indicator : indicators)
indicator->finalize();
}
if (_internal_side_indicators.hasActiveBlockObjects(_subdomain, _tid))
{
const std::vector<std::shared_ptr<InternalSideIndicator>> & internal_indicators =
_internal_side_indicators.getActiveBlockObjects(_subdomain, _tid);
for (const auto & internal_indicator : internal_indicators)
internal_indicator->finalize();
}
}
if (!_finalize) // During finalize the Indicators should be setting values in the vectors manually
{
Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
for (const auto & it : _aux_sys._elem_vars[_tid])
{
MooseVariable * var = it.second;
var->add(_aux_sys.solution());
}
}
}
示例14: bind_this_thread
bool bind_this_thread( const std::pair<unsigned,unsigned> coord )
{
if ( ! sentinel() ) return false ;
#if DEBUG_PRINT
std::cout << "Kokkos::bind_this_thread() at " ;
hwloc_get_last_cpu_location( s_hwloc_topology ,
s_hwloc_location , HWLOC_CPUBIND_THREAD );
print_bitmap( std::cout , s_hwloc_location );
std::cout << " to " ;
print_bitmap( std::cout , s_core[ coord.second + coord.first * s_core_topology.second ] );
std::cout << std::endl ;
#endif
// As safe and fast as possible.
// Fast-lookup by caching the coordinate -> hwloc cpuset mapping in 's_core'.
return coord.first < s_core_topology.first &&
coord.second < s_core_topology.second &&
0 == hwloc_set_cpubind( s_hwloc_topology ,
s_core[ coord.second + coord.first * s_core_topology.second ] ,
HWLOC_CPUBIND_THREAD | HWLOC_CPUBIND_STRICT );
}
示例15: free_sexp
/* free_sexp: free all the memory allocated by reading an s-expression
*/
void free_sexp( struct node *sexp )
{
if( sexp != NULL )
{
switch( sexp->tag )
{
case NAME:
free( sexp->str );
sexp->str = NULL;
break;
case NUM:
break;
case LST:
free_sexp( sexp->sublst );
sexp->sublst = NULL;
break;
default:
sentinel("Non-existent tag: %d", sexp->tag);
break;
}
free_sexp( sexp->rest );
sexp->rest = NULL;
free( sexp );
sexp = NULL;
}
error:
return;
}