本网站可以出售:只需60000元直接拥有。QQ:939804642
您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ rb_hash_aset函数代码示例

51自学网 2021-06-02 11:21:29
  C++
这篇教程C++ rb_hash_aset函数代码示例写得很实用,希望能帮到您。

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

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

示例1: define_ruby_class

voiddefine_ruby_class(){  if (rb_klass)    return;  /*    * opencv = rb_define_module("OpenCV");   *    * note: this comment is used by rdoc.   */  VALUE opencv = rb_module_opencv();    rb_klass = rb_define_class_under(opencv, "CvCapture", rb_cData);    VALUE video_interface = rb_hash_new();  /* {:any, :mil, :vfw, :v4l, :v4l2, :fireware, :ieee1394, :dc1394, :cmu1394, :stereo,     :tyzx, :tyzx_left, :tyzx_right, :tyzx_color, :tyzx_z, :qt, :qtuicktime}: video source */  rb_define_const(rb_klass, "INTERFACE", video_interface);  rb_hash_aset(video_interface, ID2SYM(rb_intern("any")), INT2FIX(CV_CAP_ANY));  rb_hash_aset(video_interface, ID2SYM(rb_intern("mil")), INT2FIX(CV_CAP_MIL));  rb_hash_aset(video_interface, ID2SYM(rb_intern("vfw")), INT2FIX(CV_CAP_VFW));  rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l")), INT2FIX(CV_CAP_V4L));  rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l2")), INT2FIX(CV_CAP_V4L2));  rb_hash_aset(video_interface, ID2SYM(rb_intern("fireware")), INT2FIX(CV_CAP_FIREWARE));  rb_hash_aset(video_interface, ID2SYM(rb_intern("ieee1394")), INT2FIX(CV_CAP_IEEE1394));  rb_hash_aset(video_interface, ID2SYM(rb_intern("dc1394")), INT2FIX(CV_CAP_DC1394));  rb_hash_aset(video_interface, ID2SYM(rb_intern("cmu1394")), INT2FIX(CV_CAP_CMU1394));  rb_hash_aset(video_interface, ID2SYM(rb_intern("stereo")), INT2FIX(CV_CAP_STEREO));  rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx")), INT2FIX(CV_CAP_TYZX));  rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_left")), INT2FIX(CV_TYZX_LEFT));  rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_right")), INT2FIX(CV_TYZX_RIGHT));  rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_color")), INT2FIX(CV_TYZX_COLOR));  rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_z")), INT2FIX(CV_TYZX_Z));  rb_hash_aset(video_interface, ID2SYM(rb_intern("qt")), INT2FIX(CV_CAP_QT));  rb_hash_aset(video_interface, ID2SYM(rb_intern("quicktime")), INT2FIX(CV_CAP_QT));    rb_define_singleton_method(rb_klass, "open", RUBY_METHOD_FUNC(rb_open), -1);    rb_define_method(rb_klass, "grab", RUBY_METHOD_FUNC(rb_grab), 0);  rb_define_method(rb_klass, "retrieve", RUBY_METHOD_FUNC(rb_retrieve), 0);  rb_define_method(rb_klass, "query", RUBY_METHOD_FUNC(rb_query), 0);  rb_define_method(rb_klass, "millisecond", RUBY_METHOD_FUNC(rb_get_millisecond), 0);  rb_define_method(rb_klass, "millisecond=", RUBY_METHOD_FUNC(rb_set_millisecond), 1);  rb_define_method(rb_klass, "frames", RUBY_METHOD_FUNC(rb_get_frames), 0);  rb_define_method(rb_klass, "frames=", RUBY_METHOD_FUNC(rb_set_frames), 1);  rb_define_method(rb_klass, "avi_ratio", RUBY_METHOD_FUNC(rb_get_avi_ratio), 0);  rb_define_method(rb_klass, "avi_ratio=", RUBY_METHOD_FUNC(rb_set_avi_ratio), 1);  rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_get_size), 0);  rb_define_method(rb_klass, "size=", RUBY_METHOD_FUNC(rb_set_size), 1);  rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_get_width), 0);  rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);  rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_get_height), 0);  rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);  rb_define_method(rb_klass, "fps", RUBY_METHOD_FUNC(rb_get_fps), 0);  rb_define_method(rb_klass, "fps=", RUBY_METHOD_FUNC(rb_set_fps), 1);  rb_define_method(rb_klass, "fourcc", RUBY_METHOD_FUNC(rb_get_fourcc), 0);  rb_define_method(rb_klass, "frame_count", RUBY_METHOD_FUNC(rb_get_frame_count), 0);  rb_define_method(rb_klass, "format", RUBY_METHOD_FUNC(rb_get_format), 0);  rb_define_method(rb_klass, "mode", RUBY_METHOD_FUNC(rb_get_mode), 0);  rb_define_method(rb_klass, "brightness", RUBY_METHOD_FUNC(rb_get_brightness), 0);  rb_define_method(rb_klass, "contrast", RUBY_METHOD_FUNC(rb_get_contrast), 0);  rb_define_method(rb_klass, "saturation", RUBY_METHOD_FUNC(rb_get_saturation), 0);  rb_define_method(rb_klass, "hue", RUBY_METHOD_FUNC(rb_get_hue), 0);  rb_define_method(rb_klass, "gain", RUBY_METHOD_FUNC(rb_get_gain), 0);  rb_define_method(rb_klass, "exposure", RUBY_METHOD_FUNC(rb_get_exposure), 0);  rb_define_method(rb_klass, "convert_rgb", RUBY_METHOD_FUNC(rb_get_convert_rgb), 0);  rb_define_method(rb_klass, "rectification", RUBY_METHOD_FUNC(rb_get_rectification), 0);}
开发者ID:iceydee,项目名称:ruby-opencv,代码行数:68,


示例2: cState_to_h

/* * call-seq: to_h * * Returns the configuration instance variables as a hash, that can be * passed to the configure method. */static VALUE cState_to_h(VALUE self){    VALUE result = rb_hash_new();    GET_STATE(self);    rb_hash_aset(result, ID2SYM(i_indent), rb_str_new(state->indent, state->indent_len));    rb_hash_aset(result, ID2SYM(i_space), rb_str_new(state->space, state->space_len));    rb_hash_aset(result, ID2SYM(i_space_before), rb_str_new(state->space_before, state->space_before_len));    rb_hash_aset(result, ID2SYM(i_object_nl), rb_str_new(state->object_nl, state->object_nl_len));    rb_hash_aset(result, ID2SYM(i_array_nl), rb_str_new(state->array_nl, state->array_nl_len));    rb_hash_aset(result, ID2SYM(i_allow_nan), state->allow_nan ? Qtrue : Qfalse);    rb_hash_aset(result, ID2SYM(i_ascii_only), state->ascii_only ? Qtrue : Qfalse);    rb_hash_aset(result, ID2SYM(i_quirks_mode), state->quirks_mode ? Qtrue : Qfalse);    rb_hash_aset(result, ID2SYM(i_max_nesting), LONG2FIX(state->max_nesting));    rb_hash_aset(result, ID2SYM(i_depth), LONG2FIX(state->depth));    rb_hash_aset(result, ID2SYM(i_buffer_initial_length), LONG2FIX(state->buffer_initial_length));    return result;}
开发者ID:1nueve,项目名称:MacRuby,代码行数:23,


示例3: etc_uname

/* * Returns the system information obtained by uname system call. * * The return value is a hash which has 5 keys at least: *   :sysname, :nodename, :release, :version, :machine * * Example: * *   require 'etc' *   require 'pp' * *   pp Etc.uname *   #=> {:sysname=>"Linux", *   #    :nodename=>"boron", *   #    :release=>"2.6.18-6-xen-686", *   #    :version=>"#1 SMP Thu Nov 5 19:54:42 UTC 2009", *   #    :machine=>"i686"} * */static VALUEetc_uname(VALUE obj){#ifdef _WIN32    OSVERSIONINFOW v;    SYSTEM_INFO s;    const char *sysname, *mach;    VALUE result, release, version;    VALUE vbuf, nodename = Qnil;    DWORD len = 0;    WCHAR *buf;    v.dwOSVersionInfoSize = sizeof(v);    if (!GetVersionExW(&v))        rb_sys_fail("GetVersionEx");    result = rb_hash_new();    switch (v.dwPlatformId) {      case VER_PLATFORM_WIN32s:	sysname = "Win32s";	break;      case VER_PLATFORM_WIN32_NT:	sysname = "Windows_NT";	break;      case VER_PLATFORM_WIN32_WINDOWS:      default:	sysname = "Windows";	break;    }    rb_hash_aset(result, ID2SYM(rb_intern("sysname")), rb_str_new_cstr(sysname));    release = rb_sprintf("%lu.%lu.%lu", v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);    rb_hash_aset(result, ID2SYM(rb_intern("release")), release);    version = rb_sprintf("%s Version %"PRIsVALUE": %"PRIsVALUE, sysname, release,			 rb_w32_conv_from_wchar(v.szCSDVersion, rb_utf8_encoding()));    rb_hash_aset(result, ID2SYM(rb_intern("version")), version);# if defined _MSC_VER && _MSC_VER < 1300#   define GET_COMPUTER_NAME(ptr, plen) GetComputerNameW(ptr, plen)# else#   define GET_COMPUTER_NAME(ptr, plen) GetComputerNameExW(ComputerNameDnsFullyQualified, ptr, plen)# endif    GET_COMPUTER_NAME(NULL, &len);    buf = ALLOCV_N(WCHAR, vbuf, len);    if (GET_COMPUTER_NAME(buf, &len)) {	nodename = rb_w32_conv_from_wchar(buf, rb_utf8_encoding());    }    ALLOCV_END(vbuf);    if (NIL_P(nodename)) nodename = rb_str_new(0, 0);    rb_hash_aset(result, ID2SYM(rb_intern("nodename")), nodename);# ifndef PROCESSOR_ARCHITECTURE_AMD64#   define PROCESSOR_ARCHITECTURE_AMD64 9# endif# ifndef PROCESSOR_ARCHITECTURE_IA64#   define PROCESSOR_ARCHITECTURE_IA64 6# endif# ifndef PROCESSOR_ARCHITECTURE_INTEL#   define PROCESSOR_ARCHITECTURE_INTEL 0# endif    GetSystemInfo(&s);    switch (s.wProcessorArchitecture) {      case PROCESSOR_ARCHITECTURE_AMD64:	mach = "x64";	break;      case PROCESSOR_ARCHITECTURE_ARM:	mach = "ARM";	break;      case PROCESSOR_ARCHITECTURE_IA64:	mach = "IA64";	break;      case PROCESSOR_ARCHITECTURE_INTEL:	mach = "x86";	break;      default:	mach = "unknown";	break;    }    rb_hash_aset(result, ID2SYM(rb_intern("machine")), rb_str_new_cstr(mach));#else    struct utsname u;//.........这里部分代码省略.........
开发者ID:brightbox,项目名称:deb-ruby2.3,代码行数:101,


示例4: headers_complete_cb

intheaders_complete_cb(http_parser *p){  VALUE obj, key;  client_t *client = get_client(p);  request *req = client->req;  VALUE env = client->environ;  uint32_t i = 0;  header *h;    if(max_content_length < p->content_length){    client->bad_request_code = 413;    return -1;  }  if (p->http_minor == 1) {    obj = rb_str_new2("HTTP/1.1");  } else {    obj = rb_str_new2("HTTP/1.0");  }      rb_hash_aset(env, server_protocol, obj);      if(req->path){    obj = getRbString(req->path);    rb_hash_aset(env, path_info, obj);    req->path = NULL;  }  if(req->uri){    obj = getRbString(req->uri);    rb_hash_aset(env, request_uri, obj);    req->uri = NULL;  }  if(req->query_string){    obj = getRbString(req->query_string);    rb_hash_aset(env, query_string, obj);    req->query_string = NULL;  }  if(req->fragment){    obj = getRbString(req->fragment);    rb_hash_aset(env, http_fragment, obj);    req->fragment = NULL;  }  for(i = 0; i < req->num_headers+1; i++){    h = req->headers[i];    if(h){      key = getRbString(h->field);      obj = getRbString(h->value);      rb_hash_aset(env, key, obj);      free_header(h);      req->headers[i] = NULL;    }  }       switch(p->method){  case HTTP_DELETE:    obj = rb_str_new("DELETE", 6);    break;  case HTTP_GET:    obj = rb_str_new("GET", 3);    break;  case HTTP_HEAD:    obj = rb_str_new("HEAD", 4);    break;  case HTTP_POST:    obj = rb_str_new("POST", 4);    break;  case HTTP_PUT:    obj = rb_str_new("PUT", 3);    break;  case HTTP_CONNECT:    obj = rb_str_new("CONNECT", 7);    break;  case HTTP_OPTIONS:    obj = rb_str_new("OPTIONS", 7);    break;  case  HTTP_TRACE:    obj = rb_str_new("TRACE", 5);    break;  case HTTP_COPY:    obj = rb_str_new("COPY", 4);    break;  case HTTP_LOCK:    obj = rb_str_new("LOCK", 4);    break;  case HTTP_MKCOL:    obj = rb_str_new("MKCOL", 5);    break;  case HTTP_MOVE:    obj = rb_str_new("MOVE", 4);    break;  case HTTP_PROPFIND:    obj = rb_str_new("PROPFIND", 8);    break;  case HTTP_PROPPATCH:    obj = rb_str_new("PROPPATCH", 9);    break;  case HTTP_UNLOCK:    obj = rb_str_new("UNLOCK", 6);    break;  case HTTP_REPORT://.........这里部分代码省略.........
开发者ID:henteko,项目名称:bossan,代码行数:101,


示例5: native_slot_set_value_and_case

void native_slot_set_value_and_case(const char* name,                                    upb_fieldtype_t type, VALUE type_class,                                    void* memory, VALUE value,                                    uint32_t* case_memory,                                    uint32_t case_number) {  // Note that in order to atomically change the value in memory and the case  // value (w.r.t. Ruby VM calls), we must set the value at |memory| only after  // all Ruby VM calls are complete. The case is then set at the bottom of this  // function.  switch (type) {    case UPB_TYPE_FLOAT:      if (!is_ruby_num(value)) {        rb_raise(cTypeError, "Expected number type for float field '%s' (given %s).",                 name, rb_class2name(CLASS_OF(value)));      }      DEREF(memory, float) = NUM2DBL(value);      break;    case UPB_TYPE_DOUBLE:      if (!is_ruby_num(value)) {        rb_raise(cTypeError, "Expected number type for double field '%s' (given %s).",                 name, rb_class2name(CLASS_OF(value)));      }      DEREF(memory, double) = NUM2DBL(value);      break;    case UPB_TYPE_BOOL: {      int8_t val = -1;      if (value == Qtrue) {        val = 1;      } else if (value == Qfalse) {        val = 0;      } else {        rb_raise(cTypeError, "Invalid argument for boolean field '%s' (given %s).",                 name, rb_class2name(CLASS_OF(value)));      }      DEREF(memory, int8_t) = val;      break;    }    case UPB_TYPE_STRING:      if (CLASS_OF(value) == rb_cSymbol) {        value = rb_funcall(value, rb_intern("to_s"), 0);      } else if (CLASS_OF(value) != rb_cString) {        rb_raise(cTypeError, "Invalid argument for string field '%s' (given %s).",                 name, rb_class2name(CLASS_OF(value)));      }      DEREF(memory, VALUE) = native_slot_encode_and_freeze_string(type, value);      break;    case UPB_TYPE_BYTES: {      if (CLASS_OF(value) != rb_cString) {        rb_raise(cTypeError, "Invalid argument for bytes field '%s' (given %s).",                 name, rb_class2name(CLASS_OF(value)));      }      DEREF(memory, VALUE) = native_slot_encode_and_freeze_string(type, value);      break;    }    case UPB_TYPE_MESSAGE: {      if (CLASS_OF(value) == CLASS_OF(Qnil)) {        value = Qnil;      } else if (CLASS_OF(value) != type_class) {        // check for possible implicit conversions        VALUE converted_value = NULL;        char* field_type_name = rb_class2name(type_class);        if (strcmp(field_type_name, "Google::Protobuf::Timestamp") == 0 &&            rb_obj_is_kind_of(value, rb_cTime)) {          // Time -> Google::Protobuf::Timestamp          VALUE hash = rb_hash_new();          rb_hash_aset(hash, rb_str_new2("seconds"), rb_funcall(value, rb_intern("to_i"), 0));          rb_hash_aset(hash, rb_str_new2("nanos"), rb_funcall(value, rb_intern("nsec"), 0));          VALUE args[1] = { hash };          converted_value = rb_class_new_instance(1, args, type_class);        } else if (strcmp(field_type_name, "Google::Protobuf::Duration") == 0 &&                   rb_obj_is_kind_of(value, rb_cNumeric)) {          // Numeric -> Google::Protobuf::Duration          VALUE hash = rb_hash_new();          rb_hash_aset(hash, rb_str_new2("seconds"), rb_funcall(value, rb_intern("to_i"), 0));          VALUE n_value = rb_funcall(value, rb_intern("remainder"), 1, INT2NUM(1));          n_value = rb_funcall(n_value, rb_intern("*"), 1, INT2NUM(1000000000));          n_value = rb_funcall(n_value, rb_intern("round"), 0);          rb_hash_aset(hash, rb_str_new2("nanos"), n_value);          VALUE args[1] = { hash };          converted_value = rb_class_new_instance(1, args, type_class);        }        // raise if no suitable conversaion could be found        if (converted_value == NULL) {          rb_raise(cTypeError,                   "Invalid type %s to assign to submessage field '%s'.",                  rb_class2name(CLASS_OF(value)), name);        } else {          value = converted_value;        }      }      DEREF(memory, VALUE) = value;      break;    }    case UPB_TYPE_ENUM: {      int32_t int_val = 0;//.........这里部分代码省略.........
开发者ID:acozzette,项目名称:protobuf,代码行数:101,


示例6: Init_ray_gl

/* * Document-Class: Ray::GL * * The GL module is used to give access to low-level OpenGL features in Ray. */void Init_ray_gl() {  ray_mGL = rb_define_module_under(ray_mRay, "GL");  ray_gl_primitives = rb_hash_new();  rb_hash_aset(ray_gl_primitives, RAY_SYM("points"), INT2FIX(GL_POINTS));  rb_hash_aset(ray_gl_primitives, RAY_SYM("line_strip"),               INT2FIX(GL_LINE_STRIP));  rb_hash_aset(ray_gl_primitives, RAY_SYM("line_loop"), INT2FIX(GL_LINE_LOOP));  rb_hash_aset(ray_gl_primitives, RAY_SYM("lines"), INT2FIX(GL_LINES));  rb_hash_aset(ray_gl_primitives, RAY_SYM("triangle_strip"),               INT2FIX(GL_TRIANGLE_STRIP));  rb_hash_aset(ray_gl_primitives, RAY_SYM("triangle_fan"),               INT2FIX(GL_TRIANGLE_FAN));  rb_hash_aset(ray_gl_primitives, RAY_SYM("triangles"), INT2FIX(GL_TRIANGLES));  /* @return [Hash] Available primitives. */  rb_define_const(ray_mGL, "Primitives", ray_gl_primitives);  /* @group Context configuration */  rb_define_module_function(ray_mGL, "depth_size", ray_gl_depth_size, 0);  rb_define_module_function(ray_mGL, "depth_size=", ray_gl_set_depth_size, 1);  rb_define_module_function(ray_mGL, "stencil_size", ray_gl_stencil_size, 0);  rb_define_module_function(ray_mGL, "stencil_size=", ray_gl_set_stencil_size,                            1);  rb_define_module_function(ray_mGL, "major_version", ray_gl_major_version, 0);  rb_define_module_function(ray_mGL, "major_version=", ray_gl_set_major_version,                            1);  rb_define_module_function(ray_mGL, "minor_version", ray_gl_minor_version, 0);  rb_define_module_function(ray_mGL, "minor_version=", ray_gl_set_minor_version,                            1);  rb_define_module_function(ray_mGL, "core_profile?", ray_gl_core_profile, 0);  rb_define_module_function(ray_mGL, "core_profile=", ray_gl_set_core_profile,                            1);  rb_define_module_function(ray_mGL, "debug?", ray_gl_debug, 0);  rb_define_module_function(ray_mGL, "debug=", ray_gl_set_debug, 1);  /* @endgroup */  /* @group Low-level rendering */  rb_define_module_function(ray_mGL, "draw_arrays", ray_gl_draw_arrays, 3);  rb_define_module_function(ray_mGL, "draw_elements", ray_gl_draw_elements, 3);  rb_define_module_function(ray_mGL, "draw_arrays_instanced",                            ray_gl_draw_arrays_instanced, 4);  rb_define_module_function(ray_mGL, "draw_elements_instanced",                            ray_gl_draw_elements_instanced, 4);  rb_define_module_function(ray_mGL, "multi_draw_arrays",                            ray_gl_multi_draw_arrays, 3);  rb_define_module_function(ray_mGL, "multi_draw_elements",                            ray_gl_multi_draw_elements, 3);  /* @endgroup */  rb_define_module_function(ray_mGL, "has_callback?", ray_gl_has_callback, 0);  rb_define_module_function(ray_mGL, "callback=", ray_gl_set_callback, 1);  rb_define_module_function(ray_mGL, "ensure_context", ray_gl_ensure_context,                            0);}
开发者ID:Mon-Ouie,项目名称:ray,代码行数:69,


示例7: rb_thread_aset

static VALUErb_thread_aset(VALUE self, SEL sel, ID key, VALUE val){    key = ID2SYM(rb_to_id(key));    return rb_hash_aset(rb_vm_thread_locals(self, true), key, val);}
开发者ID:alloy,项目名称:mr-experimental,代码行数:6,


示例8: rho_ruby_add_to_hash

void rho_ruby_add_to_hash(VALUE hash, VALUE key, VALUE item) {    rb_hash_aset(hash, key, item);}
开发者ID:redbeardenterprises,项目名称:rhodes,代码行数:3,


示例9: addTimeToHash

VALUE addTimeToHash(VALUE hash, const char* key, time_t val) {    return rb_hash_aset(hash, rb_str_new2(key), rb_time_new(val,0));}
开发者ID:redbeardenterprises,项目名称:rhodes,代码行数:3,


示例10: rb_mysql_result_fetch_row

//.........这里部分代码省略.........            if (app_timezone == intern_local) {              val = rb_funcall(val, intern_localtime, 0);            } else { // utc              val = rb_funcall(val, intern_utc, 0);            }          }          break;        }        case MYSQL_TYPE_TIMESTAMP:  // TIMESTAMP field        case MYSQL_TYPE_DATETIME: { // DATETIME field          unsigned int year, month, day, hour, min, sec, tokens;          uint64_t seconds;          tokens = sscanf(row[i], "%4d-%2d-%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec);          seconds = (year*31557600ULL) + (month*2592000ULL) + (day*86400ULL) + (hour*3600ULL) + (min*60ULL) + sec;          if (seconds == 0) {            val = Qnil;          } else {            if (month < 1 || day < 1) {              rb_raise(cMysql2Error, "Invalid date: %s", row[i]);              val = Qnil;            } else {              if (seconds < MYSQL2_MIN_TIME || seconds >= MYSQL2_MAX_TIME) { // use DateTime instead                VALUE offset = INT2NUM(0);                if (db_timezone == intern_local) {                  offset = rb_funcall(cMysql2Client, intern_local_offset, 0);                }                val = rb_funcall(cDateTime, intern_civil, 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec), offset);                if (!NIL_P(app_timezone)) {                  if (app_timezone == intern_local) {                    offset = rb_funcall(cMysql2Client, intern_local_offset, 0);                    val = rb_funcall(val, intern_new_offset, 1, offset);                  } else { // utc                    val = rb_funcall(val, intern_new_offset, 1, opt_utc_offset);                  }                }              } else {                val = rb_funcall(rb_cTime, db_timezone, 6, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec));                if (!NIL_P(app_timezone)) {                  if (app_timezone == intern_local) {                    val = rb_funcall(val, intern_localtime, 0);                  } else { // utc                    val = rb_funcall(val, intern_utc, 0);                  }                }              }            }          }          break;        }        case MYSQL_TYPE_DATE:       // DATE field        case MYSQL_TYPE_NEWDATE: {  // Newer const used > 5.0          int year, month, day, tokens;          tokens = sscanf(row[i], "%4d-%2d-%2d", &year, &month, &day);          if (year+month+day == 0) {            val = Qnil;          } else {            if (month < 1 || day < 1) {              rb_raise(cMysql2Error, "Invalid date: %s", row[i]);              val = Qnil;            } else {              val = rb_funcall(cDate, intern_new, 3, INT2NUM(year), INT2NUM(month), INT2NUM(day));            }          }          break;        }        case MYSQL_TYPE_TINY_BLOB:        case MYSQL_TYPE_MEDIUM_BLOB:        case MYSQL_TYPE_LONG_BLOB:        case MYSQL_TYPE_BLOB:        case MYSQL_TYPE_VAR_STRING:        case MYSQL_TYPE_VARCHAR:        case MYSQL_TYPE_STRING:     // CHAR or BINARY field        case MYSQL_TYPE_SET:        // SET field        case MYSQL_TYPE_ENUM:       // ENUM field        case MYSQL_TYPE_GEOMETRY:   // Spatial fielda        default:          val = rb_str_new(row[i], fieldLengths[i]);#ifdef HAVE_RUBY_ENCODING_H          val = mysql2_set_field_string_encoding(val, fields[i], default_internal_enc, conn_enc);#endif          break;        }      }      if (asArray) {        rb_ary_push(rowVal, val);      } else {        rb_hash_aset(rowVal, field, val);      }    } else {      if (asArray) {        rb_ary_push(rowVal, Qnil);      } else {        rb_hash_aset(rowVal, field, Qnil);      }    }  }  return rowVal;}
开发者ID:theokorigroup,项目名称:mysql2,代码行数:101,


示例11: rb_mysql_result_fetch_row

//.........这里部分代码省略.........            val = Qnil;          } else {            if (month < 1 || day < 1) {              rb_raise(cMysql2Error, "Invalid date: %s", row[i]);              val = Qnil;            } else {              if (seconds < MYSQL2_MIN_TIME || seconds > MYSQL2_MAX_TIME) { /* use DateTime for larger date range, does not support microseconds */                VALUE offset = INT2NUM(0);                if (db_timezone == intern_local) {                  offset = rb_funcall(cMysql2Client, intern_local_offset, 0);                }                val = rb_funcall(cDateTime, intern_civil, 7, UINT2NUM(year), UINT2NUM(month), UINT2NUM(day), UINT2NUM(hour), UINT2NUM(min), UINT2NUM(sec), offset);                if (!NIL_P(app_timezone)) {                  if (app_timezone == intern_local) {                    offset = rb_funcall(cMysql2Client, intern_local_offset, 0);                    val = rb_funcall(val, intern_new_offset, 1, offset);                  } else { /* utc */                    val = rb_funcall(val, intern_new_offset, 1, opt_utc_offset);                  }                }              } else {                 /* microseconds can be up to 6 digits. Fewer digits must be interpreted from                 * the left because the microseconds are to the right of the decimal point.                 */                if (tokens == 7) {                  int i;                  for (i = 0; i < 6; ++i) {                    if (msec_char[i] == '/0') {                      msec_char[i] = '0';                    }                  }                  msec = (unsigned int)strtoul(msec_char, NULL, 10);                }                val = rb_funcall(rb_cTime, db_timezone, 7, UINT2NUM(year), UINT2NUM(month), UINT2NUM(day), UINT2NUM(hour), UINT2NUM(min), UINT2NUM(sec), UINT2NUM(msec));                if (!NIL_P(app_timezone)) {                  if (app_timezone == intern_local) {                    val = rb_funcall(val, intern_localtime, 0);                  } else { /* utc */                    val = rb_funcall(val, intern_utc, 0);                  }                }              }            }          }          break;        }        case MYSQL_TYPE_DATE:       /* DATE field */        case MYSQL_TYPE_NEWDATE: {  /* Newer const used > 5.0 */          int tokens;          unsigned int year=0, month=0, day=0;          tokens = sscanf(row[i], "%4u-%2u-%2u", &year, &month, &day);          if (tokens < 3) {            val = Qnil;            break;          }          if (year+month+day == 0) {            val = Qnil;          } else {            if (month < 1 || day < 1) {              rb_raise(cMysql2Error, "Invalid date: %s", row[i]);              val = Qnil;            } else {              val = rb_funcall(cDate, intern_new, 3, UINT2NUM(year), UINT2NUM(month), UINT2NUM(day));            }          }          break;        }        case MYSQL_TYPE_TINY_BLOB:        case MYSQL_TYPE_MEDIUM_BLOB:        case MYSQL_TYPE_LONG_BLOB:        case MYSQL_TYPE_BLOB:        case MYSQL_TYPE_VAR_STRING:        case MYSQL_TYPE_VARCHAR:        case MYSQL_TYPE_STRING:     /* CHAR or BINARY field */        case MYSQL_TYPE_SET:        /* SET field */        case MYSQL_TYPE_ENUM:       /* ENUM field */        case MYSQL_TYPE_GEOMETRY:   /* Spatial fielda */        default:          val = rb_str_new(row[i], fieldLengths[i]);#ifdef HAVE_RUBY_ENCODING_H          val = mysql2_set_field_string_encoding(val, fields[i], default_internal_enc, conn_enc);#endif          break;        }      }      if (asArray) {        rb_ary_push(rowVal, val);      } else {        rb_hash_aset(rowVal, field, val);      }    } else {      if (asArray) {        rb_ary_push(rowVal, Qnil);      } else {        rb_hash_aset(rowVal, field, Qnil);      }    }  }  return rowVal;}
开发者ID:zhaoyk,项目名称:mysql2,代码行数:101,


示例12: rhe_accept

staticVALUE rhe_accept(VALUE self, VALUE fileno, VALUE timeoutv, VALUE tcp, VALUE env) {  struct sockaddr_in cliaddr;  unsigned int len;  char read_buf[MAX_HEADER_SIZE];  VALUE req;  int flag = 1;  ssize_t rv = 0;  ssize_t buf_len;  ssize_t reqlen;  int fd;  double timeout = NUM2DBL(timeoutv);  len = sizeof(cliaddr);  fd = _accept(NUM2INT(fileno), (struct sockaddr *)&cliaddr, len);  /* endif */  if (fd < 0) {    goto badexit;  }  rv = _read_timeout(fd, timeout, &read_buf[0], MAX_HEADER_SIZE);  if ( rv <= 0 ) {    close(fd);    goto badexit;  }  if ( IMMEDIATE_P(tcp) ) {    setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(int));    rb_hash_aset(env, remote_addr_key, rb_str_new2(inet_ntoa(cliaddr.sin_addr)));    rb_hash_aset(env, remote_port_key, rb_String(rb_int_new(ntohs(cliaddr.sin_port))));  }  else {    rb_hash_aset(env, remote_addr_key, rb_str_new("",0));    rb_hash_aset(env, remote_port_key, rb_String(rb_int_new(0)));  }  buf_len = rv;  while (1) {    reqlen = _parse_http_request(&read_buf[0],buf_len,env);    if ( reqlen >= 0 ) {      break;    }    else if ( reqlen == -1 ) {      /* error */      close(fd);      goto badexit;    }    if ( MAX_HEADER_SIZE - buf_len == 0 ) {      /* too large header  */     char* badreq;     badreq = BAD_REQUEST;     rv = _write_timeout(fd, timeout, badreq, sizeof(BAD_REQUEST) - 1);     close(fd);     goto badexit;    }    /* request is incomplete */    rv = _read_timeout(fd, timeout, &read_buf[buf_len], MAX_HEADER_SIZE - buf_len);    if ( rv <= 0 ) {      close(fd);      goto badexit;    }    buf_len += rv;  }  req = rb_ary_new2(3);  rb_ary_push(req, rb_int_new(fd));  rb_ary_push(req, rb_str_new(&read_buf[reqlen],buf_len - reqlen));  return req; badexit:  return Qnil;}
开发者ID:tricknotes,项目名称:rhebok,代码行数:72,


示例13: _parse_http_request

staticint _parse_http_request(char *buf, ssize_t buf_len, VALUE env) {  const char* method;  size_t method_len;  const char* path;  size_t path_len;  int minor_version;  struct phr_header headers[MAX_HEADERS];  size_t num_headers, question_at;  size_t i;  int ret;  char tmp[MAX_HEADER_NAME_LEN + sizeof("HTTP_") - 1];  VALUE last_value;  num_headers = MAX_HEADERS;  ret = phr_parse_request(buf, buf_len, &method, &method_len, &path,                          &path_len, &minor_version, headers, &num_headers, 0);  if (ret < 0)    goto done;  rb_hash_aset(env, request_method_key, rb_str_new(method,method_len));  rb_hash_aset(env, request_uri_key, rb_str_new(path, path_len));  rb_hash_aset(env, script_name_key, rb_str_new2(""));  strcpy(tmp, "HTTP/1.");  tmp[7] = 48 + ((minor_version > 1 || minor_version < 0 ) ? 0 : minor_version);  rb_hash_aset(env, server_protocol_key, rb_str_new(tmp, sizeof("HTTP/1.0") - 1));  /* PATH_INFO QUERY_STRING */  path_len = find_ch(path, path_len, '#'); /* strip off all text after # after storing request_uri */  question_at = find_ch(path, path_len, '?');  if ( store_path_info(env, path, question_at) < 0 ) {    rb_hash_clear(env);    ret = -1;    goto done;  }  if (question_at != path_len) ++question_at;  rb_hash_aset(env, query_string_key, rb_str_new(path + question_at, path_len - question_at));  last_value = Qnil;  for (i = 0; i < num_headers; ++i) {    if (headers[i].name != NULL) {      const char* name;      size_t name_len;      VALUE slot;      VALUE env_key;      env_key = find_common_header(headers + i);      if ( env_key == Qnil ) {        const char* s;        char* d;        size_t n;        if (sizeof(tmp) - 5 < headers[i].name_len) {          rb_hash_clear(env);          ret = -1;          goto done;        }        strcpy(tmp, "HTTP_");        for (s = headers[i].name, n = headers[i].name_len, d = tmp + 5;          n != 0;          s++, --n, d++) {            *d = *s == '-' ? '_' : TOU(*s);            name = tmp;            name_len = headers[i].name_len + 5;            env_key = rb_str_new(name, name_len);        }      }      slot = rb_hash_aref(env, env_key);      if ( slot != Qnil ) {        rb_str_cat2(slot, ", ");        rb_str_cat(slot, headers[i].value, headers[i].value_len);      } else {        slot = rb_str_new(headers[i].value, headers[i].value_len);        rb_hash_aset(env, env_key, slot);        last_value = slot;      }    } else {      /* continuing lines of a mulitiline header */      if ( last_value != Qnil )        rb_str_cat(last_value, headers[i].value, headers[i].value_len);    }  } done:  return ret;}
开发者ID:tricknotes,项目名称:rhebok,代码行数:83,


示例14: cb_storage_callback

    voidcb_storage_callback(lcb_t handle, const void *cookie, lcb_storage_t operation,        lcb_error_t error, const lcb_store_resp_t *resp){    struct cb_context_st *ctx = (struct cb_context_st *)cookie;    struct cb_bucket_st *bucket = ctx->bucket;    VALUE key, cas, exc, res;    key = STR_NEW((const char*)resp->v.v0.key, resp->v.v0.nkey);    cb_strip_key_prefix(bucket, key);    cas = resp->v.v0.cas > 0 ? ULL2NUM(resp->v.v0.cas) : Qnil;    switch(operation) {        case LCB_ADD:            ctx->operation = cb_sym_add;            break;        case LCB_REPLACE:            ctx->operation = cb_sym_replace;            break;        case LCB_SET:            ctx->operation = cb_sym_set;            break;        case LCB_APPEND:            ctx->operation = cb_sym_append;            break;        case LCB_PREPEND:            ctx->operation = cb_sym_prepend;            break;        default:            ctx->operation = Qnil;    }    exc = cb_check_error(error, "failed to store value", key);    if (exc != Qnil) {        rb_ivar_set(exc, cb_id_iv_cas, cas);        rb_ivar_set(exc, cb_id_iv_operation, ctx->operation);        ctx->exception = exc;    }    if (bucket->async) { /* asynchronous */        if (RTEST(ctx->observe_options)) {            VALUE args[2]; /* it's ok to pass pointer to stack struct here */            args[0] = rb_hash_new();            rb_hash_aset(args[0], key, cas);            args[1] = ctx->observe_options;            rb_block_call(bucket->self, cb_id_observe_and_wait, 2, args,                    storage_observe_callback, (VALUE)ctx);            ctx->observe_options = Qnil;        } else if (ctx->proc != Qnil) {            res = rb_class_new_instance(0, NULL, cb_cResult);            rb_ivar_set(res, cb_id_iv_error, exc);            rb_ivar_set(res, cb_id_iv_key, key);            rb_ivar_set(res, cb_id_iv_operation, ctx->operation);            rb_ivar_set(res, cb_id_iv_cas, cas);            cb_proc_call(bucket, ctx->proc, 1, res);        }    } else {             /* synchronous */        rb_hash_aset(ctx->rv, key, cas);    }    if (!RTEST(ctx->observe_options)) {        ctx->nqueries--;        if (ctx->nqueries == 0) {            ctx->proc = Qnil;            if (bucket->async) {                cb_context_free(ctx);            }        }    }    (void)handle;}
开发者ID:dr-strangecode,项目名称:couchbase-ruby-client,代码行数:70,


示例15: rb_do_kcluster

/* @api private */VALUE rb_do_kcluster(int argc, VALUE *argv, VALUE self) {    VALUE size, data, mask, weights, options;    rb_scan_args(argc, argv, "21", &size, &data, &options);    if (TYPE(data) != T_ARRAY)        rb_raise(rb_eArgError, "data should be an array of arrays");    if (NIL_P(size) || NUM2INT(rb_Integer(size)) > RARRAY_LEN(data))        rb_raise(rb_eArgError, "size should be > 0 and <= data size");    mask = get_value_option(options, "mask", Qnil);    if (!NIL_P(mask) && TYPE(mask) != T_ARRAY)        rb_raise(rb_eArgError, "mask should be an array of arrays");    int transpose = get_bool_option(options, "transpose", 0);    int npass     = get_int_option(options, "iterations", DEFAULT_ITERATIONS);    // a = average, m = means    int method    = get_int_option(options, "method", 'a');    // e = euclidian,    // b = city-block distance    // c = correlation    // a = absolute value of the correlation    // u = uncentered correlation    // x = absolute uncentered correlation    // s = spearman's rank correlation    // k = kendall's tau    int dist      = get_int_option(options, "metric", 'e');    // initial assignment    int assign    = get_int_option(options, "seed",    0);    int i,j;    int nrows = RARRAY_LEN(data);    int ncols = RARRAY_LEN(rb_ary_entry(data, 0));    int nsets = NUM2INT(rb_Integer(size));    double **cdata          = (double**)malloc(sizeof(double*)*nrows);    int    **cmask          = (int   **)malloc(sizeof(int   *)*nrows);    double *cweights        = (double *)malloc(sizeof(double )*ncols);    double **ccentroid;    int *ccluster, **ccentroid_mask, dimx = nrows, dimy = ncols, cdimx = nsets, cdimy = ncols;    for (i = 0; i < nrows; i++) {        cdata[i]          = (double*)malloc(sizeof(double)*ncols);        cmask[i]          = (int   *)malloc(sizeof(int   )*ncols);        for (j = 0; j < ncols; j++) {            cdata[i][j] = NUM2DBL(rb_Float(rb_ary_entry(rb_ary_entry(data, i), j)));            cmask[i][j] = NIL_P(mask) ? 1 : NUM2INT(rb_Integer(rb_ary_entry(rb_ary_entry(mask, i), j)));        }    }    weights = NIL_P(options) ? Qnil : rb_hash_aref(options, ID2SYM(rb_intern("weights")));    for (i = 0; i < ncols; i++) {        cweights[i] = NIL_P(weights) ? 1.0 : NUM2DBL(rb_Float(rb_ary_entry(weights, i)));    }    if (transpose) {        dimx  = ncols;        dimy  = nrows;        cdimx = nrows;        cdimy = nsets;    }    ccluster       = (int    *)malloc(sizeof(int    )*dimx);    ccentroid      = (double**)malloc(sizeof(double*)*cdimx);    ccentroid_mask = (int   **)malloc(sizeof(int   *)*cdimx);    for (i = 0; i < cdimx; i++) {      ccentroid[i]      = (double*)malloc(sizeof(double)*cdimy);      ccentroid_mask[i] = (int   *)malloc(sizeof(int   )*cdimy);    }    int    ifound;    double error;    kcluster(nsets,        nrows, ncols, cdata, cmask, cweights, transpose, npass, method, dist, ccluster, &error, &ifound, assign);    getclustercentroids(nsets,        nrows, ncols, cdata, cmask, ccluster, ccentroid, ccentroid_mask, transpose, method);    VALUE result   = rb_hash_new();    VALUE cluster  = rb_ary_new();    VALUE centroid = rb_ary_new();    for (i = 0; i < dimx; i++)        rb_ary_push(cluster, INT2NUM(ccluster[i]));    for (i = 0; i < cdimx; i++) {        VALUE point = rb_ary_new();        for (j = 0; j < cdimy; j++)            rb_ary_push(point, DBL2NUM(ccentroid[i][j]));        rb_ary_push(centroid, point);    }    rb_hash_aset(result, ID2SYM(rb_intern("cluster")),   cluster);//.........这里部分代码省略.........
开发者ID:deepfryed,项目名称:flock,代码行数:101,


示例16: addIntToHash

VALUE addIntToHash(VALUE hash, const char* key, int val) {    return rb_hash_aset(hash, rb_str_new2(key), INT2FIX(val));}
开发者ID:redbeardenterprises,项目名称:rhodes,代码行数:3,


示例17: rb_git_indexentry_fromC

static VALUE rb_git_indexentry_fromC(const git_index_entry *entry){	VALUE rb_entry, rb_mtime, rb_ctime;	unsigned int valid, stage;	if (!entry)		return Qnil;	rb_entry = rb_hash_new();	rb_hash_aset(rb_entry, CSTR2SYM("path"), rb_str_new_utf8(entry->path));	rb_hash_aset(rb_entry, CSTR2SYM("oid"), rugged_create_oid(&entry->id));	rb_hash_aset(rb_entry, CSTR2SYM("dev"), INT2FIX(entry->dev));	rb_hash_aset(rb_entry, CSTR2SYM("ino"), INT2FIX(entry->ino));	rb_hash_aset(rb_entry, CSTR2SYM("mode"), INT2FIX(entry->mode));	rb_hash_aset(rb_entry, CSTR2SYM("gid"), INT2FIX(entry->gid));	rb_hash_aset(rb_entry, CSTR2SYM("uid"), INT2FIX(entry->uid));	rb_hash_aset(rb_entry, CSTR2SYM("file_size"), INT2FIX(entry->file_size));	valid = (entry->flags & GIT_IDXENTRY_VALID);	rb_hash_aset(rb_entry, CSTR2SYM("valid"), valid ? Qtrue : Qfalse);	stage = (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT;	rb_hash_aset(rb_entry, CSTR2SYM("stage"), INT2FIX(stage));	rb_mtime = rb_time_new(entry->mtime.seconds, entry->mtime.nanoseconds / 1000);	rb_ctime = rb_time_new(entry->ctime.seconds, entry->ctime.nanoseconds / 1000);	rb_hash_aset(rb_entry, CSTR2SYM("ctime"), rb_ctime);	rb_hash_aset(rb_entry, CSTR2SYM("mtime"), rb_mtime);	return rb_entry;}
开发者ID:mkanoor,项目名称:rugged,代码行数:34,


示例18: addBoolToHash

VALUE addBoolToHash(VALUE hash, const char* key, int val){    return rb_hash_aset(hash, rb_str_new2(key), (val ? Qtrue : Qfalse) );}
开发者ID:redbeardenterprises,项目名称:rhodes,代码行数:4,


示例19: Draw_marshal_dump

/** * Custom marshal for Draw objects. * * Ruby usage: *   - @verbatim Draw#marshal_dump @endverbatim * * Notes: *   - Instead of trying to replicate Ruby's support for cross-system *     marshalling, exploit it. Convert the Draw fields to Ruby objects and *     store them in a hash. Let Ruby marshal the hash. *   - Commented out code that dumps/loads fields that are used internally by *     ImageMagick and shouldn't be marshaled. I left the code as placeholders *     so I'll know which fields have been deliberately omitted. * * @param self this object * @return the marshalled object (as a Ruby hash) * @todo Handle gradients when christy gets the new gradient support added (23Dec08) */VALUEDraw_marshal_dump(VALUE self){    Draw *draw;    VALUE ddraw;    Data_Get_Struct(self, Draw, draw);    // Raise an exception if the Draw has a non-NULL gradient or element_reference field    if (draw->info->element_reference.type != UndefinedReference        || draw->info->gradient.type != UndefinedGradient)    {        rb_raise(rb_eTypeError, "can't dump gradient definition");    }    ddraw = rb_hash_new();    // rb_hash_aset(ddraw, CSTR2SYM("primitive"), MAGICK_STRING_TO_OBJ(draw->info->primitive)); internal    // rb_hash_aset(ddraw, CSTR2SYM("geometry"), MAGICK_STRING_TO_OBJ(draw->info->geometry)); set by "text" primitive    // rb_hash_aset(ddraw, CSTR2SYM("viewbox"), Import_RectangleInfo(&draw->info->viewbox)); internal    rb_hash_aset(ddraw, CSTR2SYM("affine"), Import_AffineMatrix(&draw->info->affine));    rb_hash_aset(ddraw, CSTR2SYM("gravity"), INT2FIX(draw->info->gravity));    rb_hash_aset(ddraw, CSTR2SYM("fill"), Pixel_from_PixelColor(&draw->info->fill));    rb_hash_aset(ddraw, CSTR2SYM("stroke"), Pixel_from_PixelColor(&draw->info->stroke));    rb_hash_aset(ddraw, CSTR2SYM("stroke_width"), rb_float_new(draw->info->stroke_width));    // rb_hash_aset(ddraw, CSTR2SYM("gradient"), Qnil);  // not used yet    rb_hash_aset(ddraw, CSTR2SYM("fill_pattern"), image_to_str(draw->info->fill_pattern));    rb_hash_aset(ddraw, CSTR2SYM("tile"), Qnil); // deprecated    rb_hash_aset(ddraw, CSTR2SYM("stroke_pattern"), image_to_str(draw->info->stroke_pattern));    rb_hash_aset(ddraw, CSTR2SYM("stroke_antialias"), draw->info->stroke_antialias ? Qtrue : Qfalse);    rb_hash_aset(ddraw, CSTR2SYM("text_antialias"), draw->info->text_antialias ? Qtrue : Qfalse);    // rb_hash_aset(ddraw, CSTR2SYM("fill_rule"), INT2FIX(draw->info->fill_rule)); internal    // rb_hash_aset(ddraw, CSTR2SYM("linecap"), INT2FIX(draw->info->linecap));    // rb_hash_aset(ddraw, CSTR2SYM("linejoin"), INT2FIX(draw->info->linejoin));    // rb_hash_aset(ddraw, CSTR2SYM("miterlimit"), ULONG2NUM(draw->info->miterlimit));    // rb_hash_aset(ddraw, CSTR2SYM("dash_offset"), rb_float_new(draw->info->dash_offset));    rb_hash_aset(ddraw, CSTR2SYM("decorate"), INT2FIX(draw->info->decorate));    // rb_hash_aset(ddraw, CSTR2SYM("compose"), INT2FIX(draw->info->compose)); set via "image" primitive    // rb_hash_aset(ddraw, CSTR2SYM("text"), MAGICK_STRING_TO_OBJ(draw->info->text)); set via "text" primitive    // rb_hash_aset(ddraw, CSTR2SYM("face"), Qnil);  internal    rb_hash_aset(ddraw, CSTR2SYM("font"), MAGICK_STRING_TO_OBJ(draw->info->font));    // rb_hash_aset(ddraw, CSTR2SYM("metrics"), Qnil);   internal    rb_hash_aset(ddraw, CSTR2SYM("family"), MAGICK_STRING_TO_OBJ(draw->info->family));    rb_hash_aset(ddraw, CSTR2SYM("style"), INT2FIX(draw->info->style));    rb_hash_aset(ddraw, CSTR2SYM("stretch"), INT2FIX(draw->info->stretch));    rb_hash_aset(ddraw, CSTR2SYM("weight"), ULONG2NUM(draw->info->weight));    rb_hash_aset(ddraw, CSTR2SYM("encoding"), MAGICK_STRING_TO_OBJ(draw->info->encoding));    rb_hash_aset(ddraw, CSTR2SYM("pointsize"), rb_float_new(draw->info->pointsize));    rb_hash_aset(ddraw, CSTR2SYM("density"), MAGICK_STRING_TO_OBJ(draw->info->density));    rb_hash_aset(ddraw, CSTR2SYM("align"), INT2FIX(draw->info->align));    rb_hash_aset(ddraw, CSTR2SYM("undercolor"), Pixel_from_PixelColor(&draw->info->undercolor));    // rb_hash_aset(ddraw, CSTR2SYM("border_color"), Pixel_from_PixelColor(&draw->info->border_color)); Montage and Polaroid    // rb_hash_aset(ddraw, CSTR2SYM("server_name"), MAGICK_STRING_TO_OBJ(draw->info->server_name));    // rb_hash_aset(ddraw, CSTR2SYM("dash_pattern"), dash_pattern_to_array(draw->info->dash_pattern)); internal    // rb_hash_aset(ddraw, CSTR2SYM("clip_mask"), MAGICK_STRING_TO_OBJ(draw->info->clip_mask)); internal    // rb_hash_aset(ddraw, CSTR2SYM("bounds"), Import_SegmentInfo(&draw->info->bounds)); internal    rb_hash_aset(ddraw, CSTR2SYM("clip_units"), INT2FIX(draw->info->clip_units));    rb_hash_aset(ddraw, CSTR2SYM("opacity"), QUANTUM2NUM(draw->info->opacity));    // rb_hash_aset(ddraw, CSTR2SYM("render"), draw->info->render ? Qtrue : Qfalse); internal    // rb_hash_aset(ddraw, CSTR2SYM("element_reference"), Qnil);     // not used yet    // rb_hash_aset(ddraw, CSTR2SYM("debug"), draw->info->debug ? Qtrue : Qfalse);    rb_hash_aset(ddraw, CSTR2SYM("kerning"), rb_float_new(draw->info->kerning));    rb_hash_aset(ddraw, CSTR2SYM("interword_spacing"), rb_float_new(draw->info->interword_spacing));    // Non-DrawInfo fields    rb_hash_aset(ddraw, CSTR2SYM("primitives"), draw->primitives);    // rb_hash_aset(ddraw, CSTR2SYM("shadow_color"), Pixel_from_PixelColor(&draw->shadow_color)); Polaroid-only    return ddraw;}
开发者ID:Watson1978,项目名称:rmagick,代码行数:88,


示例20: addStrToHash

VALUE addStrToHash(VALUE hash, const char* key, const char* val) {    return rb_hash_aset(hash, rb_str_new2(key), rb_str_new2(val));}
开发者ID:redbeardenterprises,项目名称:rhodes,代码行数:3,


示例21: read_anything

static VALUE read_anything(VALUE protocol, int ttype, VALUE field_info) {  VALUE result = Qnil;  if (ttype == TTYPE_BOOL) {    result = mt->read_bool(protocol);  } else if (ttype == TTYPE_BYTE) {    result = mt->read_byte(protocol);  } else if (ttype == TTYPE_I16) {    result = mt->read_i16(protocol);  } else if (ttype == TTYPE_I32) {    result = mt->read_i32(protocol);  } else if (ttype == TTYPE_I64) {    result = mt->read_i64(protocol);  } else if (ttype == TTYPE_STRING) {    result = mt->read_string(protocol);  } else if (ttype == TTYPE_DOUBLE) {    result = mt->read_double(protocol);  } else if (ttype == TTYPE_STRUCT) {    VALUE klass = rb_hash_aref(field_info, class_sym);    result = rb_class_new_instance(0, NULL, klass);    rb_thrift_struct_read(result, protocol);  } else if (ttype == TTYPE_MAP) {    int i;    VALUE map_header = mt->read_map_begin(protocol);    int key_ttype = FIX2INT(rb_ary_entry(map_header, 0));    int value_ttype = FIX2INT(rb_ary_entry(map_header, 1));    int num_entries = FIX2INT(rb_ary_entry(map_header, 2));    VALUE key_info = rb_hash_aref(field_info, key_sym);    VALUE value_info = rb_hash_aref(field_info, value_sym);    result = rb_hash_new();    for (i = 0; i < num_entries; ++i) {      VALUE key, val;      key = read_anything(protocol, key_ttype, key_info);      val = read_anything(protocol, value_ttype, value_info);      rb_hash_aset(result, key, val);    }    mt->read_map_end(protocol);  } else if (ttype == TTYPE_LIST) {    int i;    VALUE list_header = mt->read_list_begin(protocol);    int element_ttype = FIX2INT(rb_ary_entry(list_header, 0));    int num_elements = FIX2INT(rb_ary_entry(list_header, 1));    result = rb_ary_new2(num_elements);    for (i = 0; i < num_elements; ++i) {      rb_ary_push(result, read_anything(protocol, element_ttype, rb_hash_aref(field_info, element_sym)));    }    mt->read_list_end(protocol);  } else if (ttype == TTYPE_SET) {    VALUE items;    int i;    VALUE set_header = mt->read_set_begin(protocol);    int element_ttype = FIX2INT(rb_ary_entry(set_header, 0));    int num_elements = FIX2INT(rb_ary_entry(set_header, 1));    items = rb_ary_new2(num_elements);    for (i = 0; i < num_elements; ++i) {      rb_ary_push(items, read_anything(protocol, element_ttype, rb_hash_aref(field_info, element_sym)));    }    mt->read_set_end(protocol);    result = rb_class_new_instance(1, &items, rb_cSet);  } else {    rb_raise(rb_eNotImpError, "read_anything not implemented for type %d!", ttype);  }  return result;}
开发者ID:crnt,项目名称:thrift-1,代码行数:81,


示例22: addStrToHashLen

VALUE addStrToHashLen(VALUE hash, const char* key, const char* val, int len) {    return rb_hash_aset(hash, rb_str_new2(key), rb_str_new(val, len));}
开发者ID:redbeardenterprises,项目名称:rhodes,代码行数:3,


示例23: init_parser

intinit_parser(client_t *cli, const char *name, const short port){  VALUE object;  char r_port[7];  cli->http = (http_parser*)ruby_xmalloc(sizeof(http_parser));  memset(cli->http, 0, sizeof(http_parser));      cli->environ = rb_hash_new();  rb_hash_aset(cli->environ, version_key, version_val);  rb_hash_aset(cli->environ, scheme_key, scheme_val);  rb_hash_aset(cli->environ, errors_key, errors_val);  rb_hash_aset(cli->environ, multithread_key, multithread_val);  rb_hash_aset(cli->environ, multiprocess_key, multiprocess_val);  rb_hash_aset(cli->environ, run_once_key, run_once_val);  rb_hash_aset(cli->environ, script_key, script_val);  rb_hash_aset(cli->environ, server_name_key, server_name_val);  rb_hash_aset(cli->environ, server_port_key, server_port_val);  // query_string  rb_hash_aset(cli->environ, query_string, empty_string);  object = rb_str_new2(cli->remote_addr);  rb_hash_aset(cli->environ, rb_remote_addr, object);  sprintf(r_port, "%d", cli->remote_port);  object = rb_str_new2(r_port);  rb_hash_aset(cli->environ, rb_remote_port, object);  http_parser_init(cli->http, HTTP_REQUEST);  cli->http->data = cli;  return 0;}
开发者ID:henteko,项目名称:bossan,代码行数:36,


示例24: addHashToHash

VALUE addHashToHash(VALUE hash, const char* key, VALUE val) {    return rb_hash_aset(hash, rb_str_new2(key), val);}
开发者ID:redbeardenterprises,项目名称:rhodes,代码行数:3,


示例25: track_get_audio_channel_map

/*  call-seq: track_get_audio_channel_map() -> array        Returns an array n-channels in length    Array contains Hashes in the form: {:assignment => :description} where :description is a symbol representing an audio channel description.  eg. :Left, :Right, :Mono  */static VALUE track_get_audio_channel_map(VALUE obj){  AudioChannelLayout *layout = track_get_audio_channel_layout(obj);  if (layout == NULL) return Qnil;    VALUE channels = Qnil;  UInt32 numChannels, x, highLayoutTag;  VALUE channel;  char message[256];  AudioChannelLayoutTag layoutTag = layout->mChannelLayoutTag;    if (layoutTag == kAudioChannelLayoutTag_UseChannelDescriptions) {    // using the descriptions    // not implemented    numChannels = layout->mNumberChannelDescriptions;    channels = rb_ary_new2(numChannels);        // loop through all channels, adding assignment descriptions    AudioChannelDescription desc;    char *trackStr;    for (x=0; x < numChannels; x++) {      desc = layout->mChannelDescriptions[x];      trackStr = track_str_for_AudioChannelLabel(desc.mChannelLabel);      if (trackStr != NULL) {        ADD_CHANNEL(channels, channel, trackStr);      } else {         // unsupported audio channel labels         ADD_CHANNEL(channels, channel, "UnsupportedByRMov");         sprintf(message, "ChannelLabel unsupported by rmov: %d", (int)desc.mChannelLabel);         rb_hash_aset(channel, ID2SYM(rb_intern("message")), rb_str_new2(message));      }    }      } else {    numChannels = AudioChannelLayoutTag_GetNumberOfChannels(layoutTag);    channels = rb_ary_new2(numChannels);    if (layoutTag == kAudioChannelLayoutTag_UseChannelBitmap) {      // use the bitmap approach      // not implemented      //rb_raise(eQuickTime, "Not Implemented: kAudioChannelLayoutTag_UseChannelBitmap in track_get_audio_channel_map");      for (x=0; x < numChannels; x++) {        ADD_CHANNEL(channels, channel, "UnsupportedByRMov");        rb_hash_aset(channel, ID2SYM(rb_intern("message")), rb_str_new2("UseChannelBitmap unsupported by rmov"));      }    } else {      // using a standard LayoutTag      switch (layoutTag) {        case kAudioChannelLayoutTag_Mono:          ADD_CHANNEL(channels, channel, "Mono");          break;                case kAudioChannelLayoutTag_Stereo:          ADD_CHANNEL(channels, channel, "Left");          ADD_CHANNEL(channels, channel, "Right");          break;                  case kAudioChannelLayoutTag_MatrixStereo:          ADD_CHANNEL(channels, channel, "LeftTotal");          ADD_CHANNEL(channels, channel, "RightTotal");          break;                  case kAudioChannelLayoutTag_SMPTE_DTV:          ADD_CHANNEL(channels, channel, "Left");          ADD_CHANNEL(channels, channel, "Right");          ADD_CHANNEL(channels, channel, "Center");          ADD_CHANNEL(channels, channel, "LFEScreen");          ADD_CHANNEL(channels, channel, "LeftSurround");          ADD_CHANNEL(channels, channel, "RightSurround");          ADD_CHANNEL(channels, channel, "LeftTotal");          ADD_CHANNEL(channels, channel, "RightTotal");          break;        default:          // unsupported channels          highLayoutTag = (layoutTag & 0xff0000) >> 16;          sprintf(message, "layoutTag unsupported by rmov: (%dL << 16) | %d", (int)highLayoutTag, (int)numChannels);          for (x=0; x < numChannels; x++) {            ADD_CHANNEL(channels, channel, "UnsupportedByRMov");            rb_hash_aset(channel, ID2SYM(rb_intern("message")), rb_str_new2(message));          }          //rb_raise(eQuickTime, "Unsupported ChannelLayoutTag in track_get_audio_channel_map: %d", layoutTag);          break;      }    }//.........这里部分代码省略.........
开发者ID:one-k,项目名称:rmov,代码行数:101,


示例26: rb_do_self_organizing_map

/* @api private */VALUE rb_do_self_organizing_map(int argc, VALUE *argv, VALUE self) {    VALUE nx, ny, data, mask, weights, options;    rb_scan_args(argc, argv, "31", &nx, &ny, &data, &options);    if (TYPE(data) != T_ARRAY)        rb_raise(rb_eArgError, "data should be an array of arrays");    mask = get_value_option(options, "mask", Qnil);    if (!NIL_P(mask) && TYPE(mask) != T_ARRAY)        rb_raise(rb_eArgError, "mask should be an array of arrays");    if (NIL_P(nx) || NUM2INT(rb_Integer(nx)) <= 0)        rb_raise(rb_eArgError, "nx should be > 0");    if (NIL_P(ny) || NUM2INT(rb_Integer(ny)) <= 0)        rb_raise(rb_eArgError, "ny should be > 0");    int nxgrid    = NUM2INT(rb_Integer(nx));    int nygrid    = NUM2INT(rb_Integer(ny));    int transpose = get_int_option(options, "transpose", 0);    int npass     = get_int_option(options, "iterations", DEFAULT_ITERATIONS);    // e = euclidian,    // b = city-block distance    // c = correlation    // a = absolute value of the correlation    // u = uncentered correlation    // x = absolute uncentered correlation    // s = spearman's rank correlation    // k = kendall's tau    int dist      = get_int_option(options, "metric", 'e');    double tau    = get_dbl_option(options, "tau", 1.0);    int i, j, k;    int nrows = RARRAY_LEN(data);    int ncols = RARRAY_LEN(rb_ary_entry(data, 0));    double **cdata          = (double**)malloc(sizeof(double*)*nrows);    int    **cmask          = (int   **)malloc(sizeof(int   *)*nrows);    double *cweights        = (double *)malloc(sizeof(double )*ncols);    int **ccluster;    double ***ccelldata;    int dimx = nrows, dimy = ncols;    if (transpose) {        dimx = ncols;        dimy = nrows;    }    ccluster = (int **)malloc(sizeof(int*)*dimx);    for (i = 0; i < dimx; i++)        ccluster[i] = (int*)malloc(sizeof(int)*2);    for (i = 0; i < nrows; i++) {        cdata[i]          = (double*)malloc(sizeof(double)*ncols);        cmask[i]          = (int   *)malloc(sizeof(int   )*ncols);        for (j = 0; j < ncols; j++) {            cdata[i][j] = NUM2DBL(rb_Float(rb_ary_entry(rb_ary_entry(data, i), j)));            cmask[i][j] = NIL_P(mask) ? 1 : NUM2INT(rb_Integer(rb_ary_entry(rb_ary_entry(mask, i), j)));        }    }    weights = NIL_P(options) ? Qnil : rb_hash_aref(options, ID2SYM(rb_intern("weights")));    for (i = 0; i < ncols; i++) {        cweights[i] = NIL_P(weights) ? 1.0 : NUM2DBL(rb_Float(rb_ary_entry(weights, i)));    }    ccelldata = (double***)malloc(sizeof(double**)*nxgrid);    for (i = 0; i < nxgrid; i++) {        ccelldata[i] = (double **)malloc(sizeof(double*)*nygrid);        for (j = 0; j < nygrid; j++)            ccelldata[i][j] = (double *)malloc(sizeof(double)*dimy);    }    somcluster(nrows, ncols, cdata, cmask, cweights, transpose, nxgrid, nygrid, tau, npass, dist, ccelldata, ccluster);    VALUE result   = rb_hash_new();    VALUE cluster  = rb_ary_new();    VALUE centroid = rb_ary_new();    for (i = 0; i < dimx; i++) {        VALUE gridpoint = rb_ary_new();        rb_ary_push(gridpoint, INT2NUM(ccluster[i][0]));        rb_ary_push(gridpoint, INT2NUM(ccluster[i][1]));        rb_ary_push(cluster, gridpoint);    }    for (i = 0; i < nxgrid; i++) {        for (j = 0; j < nygrid; j++) {            VALUE point = rb_ary_new();            for (k = 0; k < dimy; k++)                rb_ary_push(point, DBL2NUM(ccelldata[i][j][k]));            rb_ary_push(centroid, point);        }    }    rb_hash_aset(result, ID2SYM(rb_intern("cluster")),   cluster);//.........这里部分代码省略.........
开发者ID:deepfryed,项目名称:flock,代码行数:101,


示例27: read_anything

static VALUE read_anything(VALUE protocol, field_metadata* fmd, protocol_method_table *pmt) {  VALUE result = Qnil;  if (fmd->type == TTYPE_BOOL) {    result = fastcall_call(pmt->read_bool, protocol, Qnil);  } else if (fmd->type == TTYPE_BYTE) {    result = fastcall_call(pmt->read_byte, protocol, Qnil);  } else if (fmd->type == TTYPE_I16) {    result = fastcall_call(pmt->read_i16, protocol, Qnil);  } else if (fmd->type == TTYPE_I32) {    result = fastcall_call(pmt->read_i32, protocol, Qnil);  } else if (fmd->type == TTYPE_I64) {    result = fastcall_call(pmt->read_i64, protocol, Qnil);  } else if (fmd->type == TTYPE_STRING) {    result = fastcall_call(pmt->read_string, protocol, Qnil);  } else if (fmd->type == TTYPE_DOUBLE) {    result = fastcall_call(pmt->read_double, protocol, Qnil);  } else if (fmd->type == TTYPE_STRUCT) {    result = rb_class_new_instance(0, NULL, fmd->klass_v);    if (rb_obj_is_kind_of(result, thrift_union_class)) {      union_read(result, protocol, pmt);    } else {      struct_read(result, protocol, pmt);    }  } else if (fmd->type == TTYPE_MAP) {    int i;    VALUE map_header = fastcall_call(pmt->read_map_begin, protocol, Qnil);    int key_ttype = FIX2INT(rb_ary_entry(map_header, 0));    int value_ttype = FIX2INT(rb_ary_entry(map_header, 1));    int num_entries = FIX2INT(rb_ary_entry(map_header, 2));    // Check the declared key and value types against the expected ones and skip the map contents    // if the types don't match.    field_metadata* key_md = fmd->key;    field_metadata* value_md = fmd->value;    if (key_md && value_md) {      int specified_key_type = key_md->type;      int specified_value_type = value_md->type;      if (num_entries == 0 || (specified_key_type == key_ttype && specified_value_type == value_ttype)) {        result = rb_hash_new();        for (i = 0; i < num_entries; ++i) {          VALUE key, val;          key = read_anything(protocol, key_md, pmt);          val = read_anything(protocol, value_md, pmt);          rb_hash_aset(result, key, val);        }      } else {        skip_map_contents(protocol, INT2FIX(key_ttype), INT2FIX(value_ttype), num_entries);      }    } else {      skip_map_contents(protocol, INT2FIX(key_ttype), INT2FIX(value_ttype), num_entries);    }    fastcall_call(pmt->read_map_end, protocol, Qnil);  } else if (fmd->type == TTYPE_LIST) {    int i;    VALUE list_header = fastcall_call(pmt->read_list_begin, protocol, Qnil);    int element_ttype = FIX2INT(rb_ary_entry(list_header, 0));    int num_elements = FIX2INT(rb_ary_entry(list_header, 1));    // Check the declared element type against the expected one and skip the list contents    // if the types don't match.    field_metadata* element_md = fmd->element;    if (element_md) {      int specified_element_type = element_md->type;      if (specified_element_type == element_ttype) {        result = rb_ary_new2(num_elements);        for (i = 0; i < num_elements; ++i) {          rb_ary_push(result, read_anything(protocol, element_md, pmt));        }      } else {        skip_list_or_set_contents(protocol, INT2FIX(element_ttype), num_elements);      }    } else {      skip_list_or_set_contents(protocol, INT2FIX(element_ttype), num_elements);    }    fastcall_call(pmt->read_list_end, protocol, Qnil);  } else if (fmd->type == TTYPE_SET) {    VALUE items;    int i;    VALUE set_header = fastcall_call(pmt->read_set_begin, protocol, Qnil);    int element_ttype = FIX2INT(rb_ary_entry(set_header, 0));    int num_elements = FIX2INT(rb_ary_entry(set_header, 1));    // Check the declared element type against the expected one and skip the set contents    // if the types don't match.    field_metadata* element_md = fmd->element;    if (element_md) {//.........这里部分代码省略.........
开发者ID:ggPeti,项目名称:thrift,代码行数:101,


示例28: rb_do_treecluster

/* @api private */VALUE rb_do_treecluster(int argc, VALUE *argv, VALUE self) {    VALUE size, data, mask, weights, options;    rb_scan_args(argc, argv, "21", &size, &data, &options);    if (TYPE(data) != T_ARRAY)        rb_raise(rb_eArgError, "data should be an array of arrays");    mask = get_value_option(options, "mask", Qnil);    if (!NIL_P(mask) && TYPE(mask) != T_ARRAY)        rb_raise(rb_eArgError, "mask should be an array of arrays");    if (NIL_P(size) || NUM2INT(rb_Integer(size)) > RARRAY_LEN(data))        rb_raise(rb_eArgError, "size should be > 0 and <= data size");    int transpose = get_int_option(options, "transpose", 0);    // s: pairwise single-linkage clustering    // m: pairwise maximum- (or complete-) linkage clustering    // a: pairwise average-linkage clustering    // c: pairwise centroid-linkage clustering    int method    = get_int_option(options, "method", 'a');    // e = euclidian,    // b = city-block distance    // c = correlation    // a = absolute value of the correlation    // u = uncentered correlation    // x = absolute uncentered correlation    // s = spearman's rank correlation    // k = kendall's tau    int dist      = get_int_option(options, "metric", 'e');    int i,j;    int nrows = RARRAY_LEN(data);    int ncols = RARRAY_LEN(rb_ary_entry(data, 0));    int nsets = NUM2INT(rb_Integer(size));    double **cdata    = (double**)malloc(sizeof(double*)*nrows);    int    **cmask    = (int   **)malloc(sizeof(int   *)*nrows);    double *cweights  = (double *)malloc(sizeof(double )*ncols);    int *ccluster, dimx = nrows, dimy = ncols;    for (i = 0; i < nrows; i++) {        cdata[i]          = (double*)malloc(sizeof(double)*ncols);        cmask[i]          = (int   *)malloc(sizeof(int   )*ncols);        for (j = 0; j < ncols; j++) {            cdata[i][j] = NUM2DBL(rb_Float(rb_ary_entry(rb_ary_entry(data, i), j)));            cmask[i][j] = NIL_P(mask) ? 1 : NUM2INT(rb_Integer(rb_ary_entry(rb_ary_entry(mask, i), j)));        }    }    weights = NIL_P(options) ? Qnil : rb_hash_aref(options, ID2SYM(rb_intern("weights")));    for (i = 0; i < ncols; i++) {        cweights[i] = NIL_P(weights) ? 1.0 : NUM2DBL(rb_Float(rb_ary_entry(weights, i)));    }    if (transpose) {        dimx  = ncols;        dimy  = nrows;    }    ccluster = (int *)malloc(sizeof(int)*dimx);    Node *tree   = treecluster(nrows, ncols, cdata, cmask, cweights, transpose, dist, method, 0);    VALUE result = Qnil, cluster;    if (tree) {        cuttree(dimx, tree, nsets, ccluster);        result  = rb_hash_new();        cluster = rb_ary_new();        for (i = 0; i < dimx; i++)            rb_ary_push(cluster, INT2NUM(ccluster[i]));        rb_hash_aset(result, ID2SYM(rb_intern("cluster")),   cluster);    }    for (i = 0; i < nrows; i++) {        free(cdata[i]);        free(cmask[i]);    }    free(cdata);    free(cmask);    free(cweights);    free(ccluster);    if (tree)        free(tree);    else        rb_raise(rb_eNoMemError, "treecluster ran out of memory");    return result;}
开发者ID:deepfryed,项目名称:flock,代码行数:98,


示例29: init_ruby_class

voidinit_ruby_class(){#if 0  // For documentation using YARD  VALUE opencv = rb_define_module("OpenCV");#endif  if (rb_klass)    return;  VALUE opencv = rb_module_opencv();  rb_klass = rb_define_class_under(opencv, "CvFont", rb_cObject);  rb_define_alloc_func(rb_klass, rb_allocate);  VALUE face = rb_hash_new();  rb_define_const(rb_klass, "FACE", face);  rb_hash_aset(face, ID2SYM(rb_intern("simplex")), INT2FIX(CV_FONT_HERSHEY_SIMPLEX));  rb_hash_aset(face, ID2SYM(rb_intern("plain")), INT2FIX(CV_FONT_HERSHEY_PLAIN));  rb_hash_aset(face, ID2SYM(rb_intern("duplex")), INT2FIX(CV_FONT_HERSHEY_DUPLEX));  rb_hash_aset(face, ID2SYM(rb_intern("triplex")), INT2FIX(CV_FONT_HERSHEY_TRIPLEX));  rb_hash_aset(face, ID2SYM(rb_intern("complex_small")), INT2FIX(CV_FONT_HERSHEY_COMPLEX_SMALL));  rb_hash_aset(face, ID2SYM(rb_intern("script_simplex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_SIMPLEX));  rb_hash_aset(face, ID2SYM(rb_intern("script_complex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_COMPLEX));  VALUE default_option = rb_hash_new();  rb_define_const(rb_klass, "FONT_OPTION", default_option);  rb_hash_aset(default_option, ID2SYM(rb_intern("hscale")), rb_float_new(1.0));  rb_hash_aset(default_option, ID2SYM(rb_intern("vscale")), rb_float_new(1.0));  rb_hash_aset(default_option, ID2SYM(rb_intern("shear")), INT2FIX(0));  rb_hash_aset(default_option, ID2SYM(rb_intern("thickness")), INT2FIX(1));  rb_hash_aset(default_option, ID2SYM(rb_intern("line_type")), INT2FIX(8));    rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);  rb_define_method(rb_klass, "face", RUBY_METHOD_FUNC(rb_face), 0);  rb_define_method(rb_klass, "hscale", RUBY_METHOD_FUNC(rb_hscale), 0);  rb_define_method(rb_klass, "vscale", RUBY_METHOD_FUNC(rb_vscale), 0);  rb_define_method(rb_klass, "shear", RUBY_METHOD_FUNC(rb_shear), 0);  rb_define_method(rb_klass, "thickness", RUBY_METHOD_FUNC(rb_thickness), 0);  rb_define_method(rb_klass, "line_type", RUBY_METHOD_FUNC(rb_line_type), 0);  rb_define_method(rb_klass, "italic", RUBY_METHOD_FUNC(rb_italic), 0);}
开发者ID:HaiTo,项目名称:ruby-opencv,代码行数:41,


示例30: get_def_opts

/* call-seq: ox_default_options() => Hash * * Returns the default load and dump options as a Hash. The options are * - indent: [Fixnum] number of spaces to indent each element in an XML document * - trace: [Fixnum] trace level where 0 is silent * - encoding: [String] character encoding for the XML file * - with_dtd: [true|false|nil] include DTD in the dump * - with_instruct: [true|false|nil] include instructions in the dump * - with_xml: [true|false|nil] include XML prolog in the dump * - circular: [true|false|nil] support circular references while dumping * - xsd_date: [true|false|nil] use XSD date format instead of decimal format * - mode: [:object|:generic|:limited|nil] load method to use for XML * - effort: [:strict|:tolerant|:auto_define] set the tolerance level for loading * - symbolize_keys: [true|false|nil] symbolize element attribute keys or leave as Strings * @return [Hash] all current option settings. */static VALUEget_def_opts(VALUE self) {    VALUE	opts = rb_hash_new();    int		elen = (int)strlen(ox_default_options.encoding);    rb_hash_aset(opts, ox_encoding_sym, (0 == elen) ? Qnil : rb_str_new(ox_default_options.encoding, elen));    rb_hash_aset(opts, indent_sym, INT2FIX(ox_default_options.indent));    rb_hash_aset(opts, trace_sym, INT2FIX(ox_default_options.trace));    rb_hash_aset(opts, with_dtd_sym, (Yes == ox_default_options.with_dtd) ? Qtrue : ((No == ox_default_options.with_dtd) ? Qfalse : Qnil));    rb_hash_aset(opts, with_xml_sym, (Yes == ox_default_options.with_xml) ? Qtrue : ((No == ox_default_options.with_xml) ? Qfalse : Qnil));    rb_hash_aset(opts, with_instruct_sym, (Yes == ox_default_options.with_instruct) ? Qtrue : ((No == ox_default_options.with_instruct) ? Qfalse : Qnil));    rb_hash_aset(opts, circular_sym, (Yes == ox_default_options.circular) ? Qtrue : ((No == ox_default_options.circular) ? Qfalse : Qnil));    rb_hash_aset(opts, xsd_date_sym, (Yes == ox_default_options.xsd_date) ? Qtrue : ((No == ox_default_options.xsd_date) ? Qfalse : Qnil));    rb_hash_aset(opts, symbolize_keys_sym, (Yes == ox_default_options.sym_keys) ? Qtrue : ((No == ox_default_options.sym_keys) ? Qfalse : Qnil));    switch (ox_default_options.mode) {    case ObjMode:	rb_hash_aset(opts, mode_sym, object_sym);	break;    case GenMode:	rb_hash_aset(opts, mode_sym, generic_sym);	break;    case LimMode:	rb_hash_aset(opts, mode_sym, limited_sym);	break;    case NoMode:    default:		rb_hash_aset(opts, mode_sym, Qnil);		break;    }    switch (ox_default_options.effort) {    case StrictEffort:		rb_hash_aset(opts, effort_sym, strict_sym);		break;    case TolerantEffort:	rb_hash_aset(opts, effort_sym, tolerant_sym);		break;    case AutoEffort:		rb_hash_aset(opts, effort_sym, auto_define_sym);	break;    case NoEffort:    default:			rb_hash_aset(opts, effort_sym, Qnil);			break;    }    return opts;}
开发者ID:edanaher,项目名称:ox,代码行数:46,



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


C++ rb_id2name函数代码示例
C++ rb_hash_aref函数代码示例
51自学网自学EXCEL、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。
京ICP备13026421号-1