var_p_t hashmap_put(var_p_t map, const char *key, int length) { Node *node = hashmap_search(map, key, length); if (node->key == NULL) { node->key = v_new(); node->value = v_new(); v_setstrn(node->key, key, length); map->v.m.count++; } return node->value; }
/* * create RxC array */ var_t *v_new_matrix(int r, int c) { var_t *v; v = v_new(); v_tomatrix(v, r, c); return v; }
/** * v_video_frame_new: * * Creates a new #VFrameVideo with default values. * * Returns: a #VFrameVideo structure. */ VFrameSubtitle * v_frame_subtitle_new (void) { VFrameSubtitle *ret = v_new (VFrameSubtitle); ret->parent.type = V_FRAME_TYPE_SUBTITLE; //ret->data = NULL; return ret; }
/** * v_raw_frame_new: * * Creates a new #VFrameRaw with default values. * * Returns: a #VFrameRaw structure. */ VFrameRaw * v_frame_raw_new (int size) { VFrameRaw *ret = v_new (VFrameRaw); ret->parent.type = V_FRAME_TYPE_RAW; ret->length = size; ret->data = v_mallocz (size); return ret; }
/** * v_video_frame_new: * * Creates a new #VFrameVideo with default values. * * Returns: a #VFrameVideo structure. */ VFrameVideo * v_frame_video_new (void) { VFrameVideo *ret = v_new (VFrameVideo); ret->parent.type = V_FRAME_TYPE_VIDEO; ret->length = 0; //ret->data = NULL; return ret; }
/** * v_audio_frame_new: * * Creates a new #VFrameAudio with default values. * * Returns: a #VFrameAudio structure. */ VFrameAudio * v_frame_audio_new (int size) { VFrameAudio *ret = v_new (VFrameAudio); ret->parent.type = V_FRAME_TYPE_AUDIO; ret->length = size; ret->samples = v_mallocz (size); return ret; }
Vertex * g_vertex (Graph *gg, const char *name) { Vertex *vv = g_find (gg, name); if (NULL != vv) return vv; gg->vertex = realloc (gg->vertex, (gg->size + 1) * sizeof *(gg->vertex)); if (NULL == gg) err (EXIT_FAILURE, __FILE__": %s: realloc", __func__); vv = v_new (name); gg->vertex[gg->size++] = vv; return vv; }
v_queryStatistics v_queryStatisticsNew(v_kernel k) { v_queryStatistics qs; c_type queryStatisticsType; assert(k != NULL); assert(C_TYPECHECK(k, v_kernel)); queryStatisticsType = v_kernelType(k,K_QUERYSTATISTICS); qs = v_queryStatistics(v_new(k, queryStatisticsType)); v_queryStatisticsInit(qs); return qs; }
v_readerStatistics v_readerStatisticsNew(v_kernel k) { v_readerStatistics rs; c_type readerStatisticsType; assert(k != NULL); assert(C_TYPECHECK(k, v_kernel)); readerStatisticsType = v_kernelType(k,K_READERSTATISTICS); rs = v_readerStatistics(v_new(k, readerStatisticsType)); v_readerStatisticsInit(rs); return rs; }
v_durabilityStatistics v_durabilityStatisticsNew(v_kernel k) { v_durabilityStatistics ds; c_type durabilityStatisticsType; assert(k != NULL); assert(C_TYPECHECK(k, v_kernel)); /* not necessary to cache this type since it is looked up only once per process */ durabilityStatisticsType = c_resolve(c_getBase(k), "kernelModuleI::v_durabilityStatistics"); ds = v_durabilityStatistics(v_new(k, durabilityStatisticsType)); v_durabilityStatisticsInit(ds); return ds; }
v_writerStatistics v_writerStatisticsNew( v_kernel k) { v_writerStatistics ws; c_type writerStatisticsType; assert(k != NULL); assert(C_TYPECHECK(k, v_kernel)); writerStatisticsType = v_kernelType(k,K_WRITERSTATISTICS); ws = v_writerStatistics(v_new(k, writerStatisticsType)); v_writerStatisticsInit(ws); return ws; }
v_networkQueueStatistics v_networkQueueStatisticsNew(v_kernel k, const c_char *name) { v_networkQueueStatistics nqs; c_string channelName; assert(k != NULL); assert(C_TYPECHECK(k, v_kernel)); if (networkQueueStatisticsType == NULL) { networkQueueStatisticsType = c_resolve(c_getBase(k), "kernelModule::v_networkQueueStatistics"); } nqs = v_networkQueueStatistics(v_new(k, networkQueueStatisticsType)); channelName = c_stringNew(c_getBase(c_object(k)),name); v_networkQueueStatisticsInit(nqs,channelName); return nqs; }
v_networkingStatistics v_networkingStatisticsNew( v_kernel k) { v_networkingStatistics _this; c_type networkingStatisticsType; assert(k != NULL); assert(C_TYPECHECK(k, v_kernel)); /* not necessary to cache this type since it is looked up only once per process */ networkingStatisticsType = c_resolve(c_getBase(k), "kernelModule::v_networkingStatistics"); _this = v_networkingStatistics(v_new(k, networkingStatisticsType)); v_networkingStatisticsInit(_this,k); return _this; }
char *System::loadResource(const char *fileName) { char *buffer = NULL; if (strstr(fileName, "://") != NULL) { String *cached = _cache.get(fileName); if (cached != NULL) { int len = cached->length(); buffer = (char *)malloc(len + 1); memcpy(buffer, cached->c_str(), len); buffer[len] = '\0'; } else { int handle = 1; var_t *var_p = v_new(); dev_file_t *f = dev_getfileptr(handle); _output->setStatus("Loading..."); _output->redraw(); if (dev_fopen(handle, fileName, 0)) { if (http_read(f, var_p) == 0) { systemPrint("\nfailed to read %s\n", fileName); } else { int len = var_p->v.p.length; buffer = (char *)malloc(len + 1); memcpy(buffer, var_p->v.p.ptr, len); buffer[len] = '\0'; _cache.add(fileName, buffer); } } else { systemPrint("\nfailed to open %s\n", fileName); } _output->setStatus(NULL); dev_fclose(handle); v_free(var_p); v_detach(var_p); opt_file_permitted = 0; } } if (buffer == NULL) { // remove failed item from history strlib::String *old = _history.peek(); if (old && old->equals(fileName)) { delete _history.pop(); } } return buffer; }
CGAL::OGL::OGL_base_object::Affine_3 Qt_widget_OpenGL::virtual_sphere_transformation( double old_x, double old_y, double new_x, double new_y) { if ( old_x == new_x && old_y == new_y)// zero rotation. return Affine_3( CGAL::IDENTITY); // Determine the projected vectors on the `sphere'. double dd = old_x * old_x + old_y * old_y; Double_vector v_old( old_x, old_y, ((dd < 0.5) ? std::sqrt(1-dd) : 0.5 / std::sqrt(dd))); dd = new_x * new_x + new_y * new_y; Double_vector v_new( new_x, new_y, ((dd < 0.5) ? std::sqrt(1-dd) : 0.5 / std::sqrt(dd))); Double_vector axis = cross_product( v_old, v_new); double angle = 0.0; double norm = std::sqrt( (v_old*v_old)*(v_new*v_new)); if ( norm != 0) { double x = v_old*v_new/ norm; if ( x <= -1) angle = CGAL_PI; if ( x < 1) angle = std::acos(x); } double len = std::sqrt( double(axis * axis)); double s = std::sin( angle / 2.0) / len; double q1 = axis.x() * s; // quaternion double q2 = axis.y() * s; double q3 = axis.z() * s; double q0 = std::cos( angle / 2.0); double a = q1 * q2; double b = q0 * q3; double c = q1 * q3; double d = q0 * q2; double e = q2 * q3; double f = q0 * q1; double qq0 = q0 * q0; double qq1 = q1 * q1; double qq2 = q2 * q2; double qq3 = q3 * q3; return Affine_3( qq0 + qq1 - qq2 - qq3, 2 * (a-b), 2 * (c+d), 2 * (a+b), qq0 - qq1 + qq2 - qq3, 2 * (e-f), 2 * (c-d), 2 * (e+f), qq0 - qq1 - qq2 + qq3); }
var_p_t hashmap_putv(var_p_t map, const var_p_t key) { // hashmap takes ownership of key if (key->type != V_STR) { // keys are always strings v_tostr(key); } Node *node = hashmap_search(map, key->v.p.ptr, key->v.p.length); if (node->key == NULL) { node->key = key; node->value = v_new(); map->v.m.count++; } else { // discard unused key v_free(key); v_detach(key); } return node->value; }
v_networkChannelStatistics v_networkChannelStatisticsNew( v_kernel k, const c_char *name) { v_networkChannelStatistics ncs; c_string channelName; c_type type; assert(k != NULL); assert(C_TYPECHECK(k, v_kernel)); type = c_resolve(c_getBase(k), "kernelModuleI::v_networkChannelStatistics"); assert(type); ncs = v_networkChannelStatistics(v_new(k, type)); c_free(type); channelName = c_stringNew(c_getBase(c_object(k)),name); v_networkChannelStatisticsInit(ncs,channelName); return ncs; }
/** * v_stream_new: * @id: a unique stream ID. * @codec_id: a #VCodecID value indicating the codec type of the stream. * @error: a #VError, or %NULL. * * Creates a new #VStream. * * Returns: a #VStream structure if successful, %NULL otherwise. */ VStream * v_stream_new (int id, VCodecID codec_id, VError *error) { VStream *ret = v_new (VStream); /* default values */ ret->id = id; /* create codec */ ret->codec = v_codec_new (codec_id, error); /* no codec */ if (ret->codec == NULL) { v_free (ret); return NULL; } return ret; }
v_listening_t * v_create_listening(const char *hostname, int port, int backlog) { struct sockaddr_in *host_addr; v_listening_t *ls; v_io_event_t *ev; char *buf; v_connection_t **head; ls = v_new(v_listening_t); if (ls == NULL) { v_log_error(V_LOG_ALERT, v_errno, "v_malloc failed: "); return NULL; } buf = v_malloc(2 * sizeof(struct sockaddr) + 16); if (buf == NULL) { v_log_error(V_LOG_ALERT, v_errno, "v_malloc failed: "); v_free(ls); return NULL; } ev = v_new(v_io_event_t); if (ev == NULL) { v_log_error(V_LOG_ALERT, v_errno, "v_malloc failed: "); v_free(ls); v_free(buf); return NULL; } host_addr = v_new(struct sockaddr_in); if (host_addr == NULL) { v_log_error(V_LOG_ALERT, v_errno, "v_malloc failed: "); v_free(ls); v_free(buf); v_free(ev); return NULL; } head = v_new(void *); if (head == NULL) { v_log_error(V_LOG_ALERT, v_errno, "v_malloc failed: "); v_free(host_addr); v_free(ls); v_free(buf); v_free(ev); return NULL; } *head = NULL; v_memzero(ls, sizeof(v_listening_t)); v_memzero(ev, sizeof(v_io_event_t)); if (v_io_prepare(ev) == V_ERR) { v_free(ls); v_free(buf); v_free(ev); v_free(host_addr); return NULL; } ls->event = ev; ls->buffer = buf; ev->data = ls; ls->head = head; host_addr->sin_family = AF_INET; host_addr->sin_port = htons(port); if (hostname == NULL) { host_addr->sin_addr.s_addr = htonl(INADDR_ANY); } else { if ((host_addr->sin_addr.s_addr = inet_addr(hostname)) == INADDR_NONE) { v_log(V_LOG_ALERT, "Host address invalid %s", hostname); v_close_listening(ls); return NULL; } } if (bind(ev->fd, (SOCKADDR *)host_addr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) { v_log_error(V_LOG_ALERT, v_socket_errno, "bind() failed: "); v_close_listening(ls); return NULL; } backlog = (backlog == 0) ? SOMAXCONN : backlog; if (listen(ev->fd, backlog) == SOCKET_ERROR) { v_log_error(V_LOG_ALERT, v_socket_errno, "listen() failed: "); v_close_listening(ls); return NULL; } ls->sockaddr = host_addr; ev->type = V_IO_NONE; ev->status = V_IO_STATUS_LISTENING; return ls; }
/** * build parameter table */ int slib_build_ptable(slib_par_t *ptable) { #if defined(LNX_EXTLIB) || defined(WIN_EXTLIB) int pcount = 0; var_t *arg = NULL; byte ready, code; bcip_t ofs; if (code_peek() == kwTYPE_LEVEL_BEGIN) { code_skipnext(); ready = 0; do { code = code_peek(); switch (code) { case kwTYPE_EOC: code_skipnext(); break; case kwTYPE_SEP: code_skipsep(); break; case kwTYPE_LEVEL_END: ready = 1; break; case kwTYPE_VAR: // variable ofs = prog_ip; if (code_isvar()) { // push parameter ptable[pcount].var_p = code_getvarptr(); ptable[pcount].byref = 1; pcount++; break; } // restore IP prog_ip = ofs; // no 'break' here default: // default --- expression (BYVAL ONLY) arg = v_new(); eval(arg); if (!prog_error) { // push parameter ptable[pcount].var_p = arg; ptable[pcount].byref = 0; pcount++; } else { v_free(arg); v_detach(arg); return pcount; } } } while (!ready); // kwTYPE_LEVEL_END code_skipnext(); } return pcount; #else return 0; #endif }
/** * v_error_new: * * Creates a new #VError with default values. * * Returns: a #VError structure. */ VError * v_error_new (void) { return v_new (VError); }
// Version to cope with z <= 0. This is wrong but it in the places where // it is used below the result is acceptable because it generates a // conservative result (i.e. a box or outline that is bigger then reality). static void PerspectiveWrong (const csVector3& v, csVector2& p, const CS::Math::Matrix4& proj, int screenWidth, int screenHeight) { csVector3 v_new (v.x, v.y, 0.1f); Perspective (v_new, p, proj, screenWidth, screenHeight); }
/* * return a full copy of the 'source' */ var_t *v_clone(const var_t *source) { var_t *vnew = v_new(); v_set(vnew, source); return vnew; }