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


C++ Local::GetPropertyNames方法代码示例

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


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

示例1: WrappedContext

Handle<Value> WrappedScript::CreateContext(const Arguments& args)
{
	HandleScope scope;

	Persistent<Context> context = Context::New(NULL, WrappedContext::global_template);
	WrappedContext *wrappedContext = new WrappedContext(context);
	Local<Object> global = context->Global();

	// Allow current context access to newly created context's objects.
	context->SetSecurityToken(Context::GetCurrent()->GetSecurityToken());

	// If a sandbox is provided initial the new context's global with it.
	if (args.Length() > 0) {
		Local<Object> sandbox = args[0]->ToObject();
		Local<Array> keys = sandbox->GetPropertyNames();

		for (uint32_t i = 0; i < keys->Length(); i++) {
			Handle<String> key = keys->Get(Integer::New(i))->ToString();
			Handle<Value> value = sandbox->Get(key);
			if (value == sandbox) {
				value = global;
			}
			global->Set(key, value);
		}
	}

	return scope.Close(global);
}
开发者ID:0anasm,项目名称:titanium_mobile,代码行数:28,代码来源:ScriptsModule.cpp

示例2:

Handle<Value> WrappedScript::CreateContext(const Arguments& args)
{
	HandleScope scope;
	Local<Object> context = WrappedContext::NewInstance();
	WrappedContext *wrappedContext = NativeObject::Unwrap<WrappedContext>(context);

	if (args.Length() > 0) {
		Local<Object> sandbox = args[0]->ToObject();
		Local<Array> keys = sandbox->GetPropertyNames();

		for (uint32_t i = 0; i < keys->Length(); i++) {
			Handle<String> key = keys->Get(Integer::New(i))->ToString();
			Handle<Value> value = sandbox->Get(key);
			if (value == sandbox) {
				value = context;
			}
			context->Set(key, value);
		}

		if (args.Length() > 1 && args[1]->IsFunction()) {
			wrappedContext->SetInitCallback(Persistent<Function>::New(Handle<Function>::Cast(args[1])));
		}
	}

	wrappedContext->GetV8Context()->SetSecurityToken(
		Context::GetCurrent()->GetSecurityToken());

	return scope.Close(context);
}
开发者ID:QGao,项目名称:titanium_mobile,代码行数:29,代码来源:ScriptsModule.cpp

示例3: Undefined

/**
 * @details This is the asynchronous method used to generate a mapserv
 * response. The response is a javascript object literal with the following
 * properties:
 *
 * - `data`: a `Buffer` object representing the response body
 * - `headers`: the HTTP headers as an object literal
 *
 * `args` should contain the following parameters:
 *
 * @param env A javascript object literal containing the CGI environment
 * variables which will direct the mapserv response.
 *
 * @param body The optional string or buffer object representing the body of an
 * HTTP request.
 *
 * @param callback A function that is called on error or when the
 * resource has been created. It should have the signature
 * `callback(err, resource)`.
 */
Handle<Value> Map::MapservAsync(const Arguments& args) {
  HandleScope scope;
  string body;
  Local<Object> env;
  Local<Function> callback;

  switch (args.Length()) {
  case 2:
    ASSIGN_OBJ_ARG(0, env);
    ASSIGN_FUN_ARG(1, callback);
    break;
  case 3:
    ASSIGN_OBJ_ARG(0, env);

    if (args[1]->IsString()) {
      body = *String::Utf8Value(args[1]->ToString());
    } else if (Buffer::HasInstance(args[1])) {
      Local<Object> buffer = args[1]->ToObject();
      body = string(Buffer::Data(buffer), Buffer::Length(buffer));
    } else if (!args[1]->IsNull() && !args[1]->IsUndefined()) {
      THROW_CSTR_ERROR(TypeError, "Argument 1 must be one of a string; buffer; null; undefined");
    }

    ASSIGN_FUN_ARG(2, callback);
    break;
  default:
    THROW_CSTR_ERROR(Error, "usage: Map.mapserv(env, [body], callback)");
  }

  Map* self = ObjectWrap::Unwrap<Map>(args.This());
  MapBaton *baton = new MapBaton();

  baton->request.data = baton;
  baton->self = self;
  baton->callback = Persistent<Function>::New(callback);
  baton->map = self->map;
  baton->error = NULL;
  baton->body = body;

  // Convert the environment object to a `std::map`
  const Local<Array> properties = env->GetPropertyNames();
  const uint32_t length = properties->Length();
  for (uint32_t i = 0; i < length; ++i) {
    const Local<Value> key = properties->Get(i);
    const Local<Value> value = env->Get(key);
    baton->env.insert(pair<string, string>(string(*String::Utf8Value(key->ToString())),
                                           string(*String::Utf8Value(value->ToString())))
                      );
  }

  self->Ref(); // increment reference count so map is not garbage collected

  uv_queue_work(uv_default_loop(),
                &baton->request,
                MapservWork,
                (uv_after_work_cb) MapservAfter);

  return Undefined();
}
开发者ID:escribano,项目名称:node-mapserv,代码行数:79,代码来源:map.cpp

示例4: ToCString

Handle<Value> xhr_send(const Arguments &args) {
	LOGFN("calling xhr send");
	String::Utf8Value arg0(args[0]);
	String::Utf8Value arg1(args[1]);

	const char *method = ToCString(arg0);
	const char *url = ToCString(arg1);

	bool async = args[2]->BooleanValue();
	const char *data = NULL;
	String::Utf8Value arg3(args[3]);
	data = ToCString(arg3);

	int state = args[4]->Int32Value();

	int id = args[5]->Int32Value();

	request_header *headers = NULL;
	if(!args[6].IsEmpty() && !args[6]->IsUndefined() && !args[6]->IsNull()) {
		Local<Object> requestHeadersObj = args[6]->ToObject();
		Local<Array> requestHeaderNames = requestHeadersObj->GetPropertyNames();
		int length = requestHeaderNames->Get(STRING_CACHE_length)->Int32Value();

		for (int i = 0; i < length; i++) {
			request_header * rh = (request_header*) malloc(sizeof(request_header));
			Local<Value> prop = requestHeaderNames->Get(i);
			String::Utf8Value header(prop);
			String::Utf8Value value(requestHeadersObj->Get(prop));
			int hLen = strlen(ToCString(header)) + 1;
			rh->header = (char *) malloc(hLen);
			strlcpy(rh->header, ToCString(header), hLen);
			int vLen = strlen(ToCString(value)) + 1;
			rh->value = (char *) malloc(vLen);
			strlcpy(rh->value, ToCString(value), vLen);
			HASH_ADD(hh, headers, header, strlen(rh->header)+1, rh);
		}
	}

	xhr req;
	req.id = id;
	req.method = method;
	req.url = url;
	req.data = data;
	req.async = async;
	req.state = state;
	req.request_headers = headers;
	xhr_send(&req);

	if(headers != NULL) {
		request_header *currentHeader, *tmp;

		HASH_ITER(hh, headers, currentHeader, tmp) {
			HASH_DEL(headers, currentHeader);
			free(currentHeader->header);
			free(currentHeader->value);
			free(currentHeader);
		}
开发者ID:ChrisCinelli,项目名称:native-android,代码行数:57,代码来源:js_xhr.cpp

示例5: ThrowException

Handle<Value> Feature::addAttributes(const Arguments& args)
{
    HandleScope scope;

    Feature* fp = ObjectWrap::Unwrap<Feature>(args.This());

    if (args.Length() > 0 ) {
        Local<Value> value = args[0];
        if (value->IsNull() || value->IsUndefined()) {
            return ThrowException(Exception::TypeError(String::New("object expected")));
        } else {
            Local<Object> attr = value->ToObject();
            try
            {
                Local<Array> names = attr->GetPropertyNames();
                uint32_t i = 0;
                uint32_t a_length = names->Length();
                boost::scoped_ptr<mapnik::transcoder> tr(new mapnik::transcoder("utf8"));
                while (i < a_length) {
                    Local<Value> name = names->Get(i)->ToString();
                    Local<Value> value = attr->Get(name);
                    if (value->IsString()) {
                        UnicodeString ustr = tr->transcode(TOSTR(value));
                        boost::put(*fp->get(),TOSTR(name),ustr);
                    } else if (value->IsNumber()) {
                        double num = value->NumberValue();
                        // todo - round
                        if (num == value->IntegerValue()) {
                            int integer = value->IntegerValue();
                            boost::put(*fp->get(),TOSTR(name),integer);
                        } else {
                            double dub_val = value->NumberValue();
                            boost::put(*fp->get(),TOSTR(name),dub_val);
                        }
                    } else {
                        std::clog << "unhandled type for property: " << TOSTR(name) << "\n";
                    }
                    i++;
                }
            }
            catch (const std::exception & ex )
            {
                return ThrowException(Exception::Error(
                  String::New(ex.what())));
            }
            catch (...) {
                return ThrowException(Exception::Error(
                  String::New("Unknown exception happended - please report bug")));
            }
        }
    }

    return Undefined();
}
开发者ID:booo,项目名称:node-mapnik,代码行数:54,代码来源:mapnik_feature.cpp

示例6: toString

	v8::Handle<v8::Value> _BeaScript::enumProperties(const v8::Arguments& args){

		HandleScope scope; 
		
		Local<Object> obj = args[0]->ToObject();
		v8::Local<v8::Array> keys = obj->GetPropertyNames();

		for (uint32_t i = 0; i < keys->Length(); i++) {
			v8::Handle<v8::String> key = keys->Get(i)->ToString();
			v8::Handle<v8::Value> value = obj->Get(key);
			std::cout << toString(key) << " : " << toString(value) << std::endl;
		}
		return args.This(); 
	}
开发者ID:bagobor,项目名称:bea,代码行数:14,代码来源:beascript.cpp

示例7: encodeObject

bson encodeObject(const Local<Value> element) {
    HandleScope scope;
    bson_buffer bb;
    bson_buffer_init(&bb);

    Local<Object> object = element->ToObject();
    Local<Array> properties = object->GetPropertyNames();

    for (int i = 0; i < properties->Length(); i++) {
        // get the property name and value
        Local<Value> prop_name = properties->Get(Integer::New(i));
        Local<Value> prop_val = object->Get(prop_name->ToString());

        // convert the property name to a c string
        String::Utf8Value n(prop_name);
        const char *pname = ToCString(n);

        // append property using appropriate appender
        if (prop_val->IsString()) {
            encodeString(&bb, pname, prop_val);
        }
        else if (prop_val->IsInt32()) {
            encodeInteger(&bb, pname, prop_val);
        }
        else if (prop_val->IsNumber()) {
            encodeNumber(&bb, pname, prop_val);
        }
        else if (prop_val->IsBoolean()) {
            encodeBoolean(&bb, pname, prop_val);
        }
        else if (prop_val->IsArray()) {
            encodeArray(&bb, pname, prop_val);
        }
        else if (prop_val->IsObject()
                 && ObjectID::constructor_template->HasInstance(prop_val)) {
            encodeObjectID(&bb, pname, prop_val);
	    }
        else if (prop_val->IsObject()) {
            bson bson(encodeObject(prop_val));
            bson_append_bson(&bb, pname, &bson);
            bson_destroy(&bson);
        }
    }

    bson bson;
    bson_from_buffer(&bson, &bb);

    return bson;
}
开发者ID:w1nk,项目名称:node-mongodb,代码行数:49,代码来源:bson.cpp

示例8: assert

void
Session::formOptions(std::string* str, Handle<Value> value)
{
    // Use the HandleScope of the calling function for speed.

    if (value->IsUndefined() || value->IsNull())
        return;

    assert(value->IsObject());

    std::stringstream ss;

    if (value->IsArray()) {
        // Format each array value into the options string "V[&V]"
        Local<Object> object = value->ToObject();
        for (std::size_t i = 0; i < Array::Cast(*object)->Length(); ++i) {
            Local<String> key = object->Get(i)->ToString();
            String::Utf8Value valv(key);
            if (valv.length()) {
                if (i > 0)
                    ss << "&";
                ss << *valv;
            }
        }
    } else {
        // Format each KV pair into the options string "K=V[&K=V]"
        Local<Object> object = value->ToObject();
        Local<Array> keys = object->GetPropertyNames();
        for (std::size_t i = 0; i < keys->Length(); ++i) {
            Local<String> key = keys->Get(i)->ToString();
            String::Utf8Value keyv(key);
            if (keyv.length()) {
                if (i > 0)
                    ss << "&";
                ss << *keyv << "=";
            }

            Local<String> val = object->Get(key)->ToString();
            String::Utf8Value valv(val);
            if (valv.length())
                ss << *valv;
        }
    }

    *str = ss.str();
}
开发者ID:ZJONSSON,项目名称:node-blpapi,代码行数:46,代码来源:blpapijs.cpp

示例9: snprintf

SV*
V8Context::object2blessed(Handle<Object> obj) {
    char package[128];

    snprintf(
        package,
        128,
        "%s%s::N%d",
        bless_prefix.c_str(),
        *String::AsciiValue(obj->Get(String::New("__perlPackage"))->ToString()),
        number
    );

    HV *stash = gv_stashpv(package, 0);

    if (!stash) {
        Local<Object> prototype = obj->GetPrototype()->ToObject();

        stash = gv_stashpv(package, GV_ADD);

        Local<Array> properties = prototype->GetPropertyNames();
        for (int i = 0; i < properties->Length(); i++) {
            Local<String> name = properties->Get(i)->ToString();
            Local<Value> property = prototype->Get(name);

            if (!property->IsFunction())
                continue;

            Local<Function> fn = Local<Function>::Cast(property);

            CV *code = newXS(NULL, v8method, __FILE__);
            V8ObjectData *data = new V8FunctionData(this, fn, (SV*)code);

            GV* gv = (GV*)*hv_fetch(stash, *String::AsciiValue(name), name->Length(), TRUE);
            gv_init(gv, stash, *String::AsciiValue(name), name->Length(), GV_ADDMULTI); /* vivify */
            my_gv_setsv(aTHX_ gv, (SV*)code);
        }
    }

    SV* rv = newSV(0);
    SV* sv = newSVrv(rv, package);
    V8ObjectData *data = new V8ObjectData(this, obj, sv);
    sv_setiv(sv, PTR2IV(data));

    return rv;
}
开发者ID:nordicdyno,项目名称:javascript-v8,代码行数:46,代码来源:V8Context.cpp

示例10: ThrowException

Handle<Value> MemoryDatasource::New(const Arguments& args)
{
    HandleScope scope;

    if (!args.IsConstructCall())
        return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

    if (args[0]->IsExternal())
    {
        //std::clog << "external!\n";
        Local<External> ext = Local<External>::Cast(args[0]);
        void* ptr = ext->Value();
        MemoryDatasource* d =  static_cast<MemoryDatasource*>(ptr);
        d->Wrap(args.This());
        return args.This();
    }
    if (args.Length() != 1){
        return ThrowException(Exception::TypeError(
                                  String::New("accepts only one argument, an object of key:value datasource options")));
    }

    if (!args[0]->IsObject())
        return ThrowException(Exception::TypeError(
                                  String::New("Must provide an object, eg {type: 'shape', file : 'world.shp'}")));

    Local<Object> options = args[0]->ToObject();

    mapnik::parameters params;
    Local<Array> names = options->GetPropertyNames();
    unsigned int i = 0;
    unsigned int a_length = names->Length();
    while (i < a_length) {
        Local<Value> name = names->Get(i)->ToString();
        Local<Value> value = options->Get(name);
        params[TOSTR(name)] = TOSTR(value);
        i++;
    }

    //memory_datasource cache;
    MemoryDatasource* d = new MemoryDatasource();
    d->Wrap(args.This());
    d->datasource_ = MAPNIK_MAKE_SHARED<mapnik::memory_datasource>();
    return args.This();
}
开发者ID:kkoopa,项目名称:node-mapnik,代码行数:44,代码来源:mapnik_memory_datasource.cpp

示例11: setParametersFromObject

void TiProxy::setParametersFromObject(void* userContext, Local<Object> obj)
{
    HandleScope handleScope;
    Handle<Value> value;
    Handle<Value> controlValue = getValue();
    if (!controlValue->IsObject())
    {
        return;
    }
    Handle<Array> propNames = obj->GetPropertyNames();
    uint32_t props = propNames->Length();
    Local<Value> propValue;
    for (uint32_t i = 0; i < props; i++)
    {
        Handle<String> propString = Handle<String>::Cast(propNames->Get(Integer::New(i)));
        String::Utf8Value propNameUTF(propString);
        Local<Value> propValue = obj->Get(propString);
        TiObject* foundProp = onLookupMember(*propNameUTF);
        if (foundProp != NULL)
        {
            TiObject* addObj = getTiObjectFromJsObject(propValue);
            if (addObj)
            {
                TiProxy* obj = (TiProxy*) userContext;
                TiProxy* uiObj = (TiProxy*) addObj;
                NativeObject* childNO = uiObj->getNativeObject();
                NativeObject* parentNO = obj->getNativeObject();
                parentNO->addChildNativeObject(childNO);
                parentNO->release();
            }
            else
            {
                foundProp->setValue(propValue);
            }
        }
        else
        {
            // Set any custom properties onto the JS object.
            getValue()->ToObject()->ForceSet(propString, propValue);
        }
    }
}
开发者ID:richardmadison,项目名称:titanium_mobile_blackberry,代码行数:42,代码来源:TiProxy.cpp

示例12: keyString

bool
createTXTRecord(scopedTXTRecord& txtRecord, Local<Object>& object) {
    HandleScope scope;
    Local<Array> names = object->GetPropertyNames();
    uint32_t length = names->Length();

    for (uint32_t index = 0; index<length; ++index) {
        Local<Value> key = names->Get(index);

        if (key->IsString()) {
            // Local<Value> buffer = object->Get(key);
            Handle<Value> buffer = object->Get(key);
            String::Utf8Value string_value( buffer->ToString());

            // A DNS-SD key is 7-bit ascii
            String::AsciiValue keyString(key);
            std::string buf(*keyString, keyString.length());

 /*           Local<Object> obj;
            uint8_t valLen = 0;
            const void *value = NULL;

            if (Buffer::HasInstance(buffer)) {
                obj = buffer->ToObject();
                valLen = Buffer::Length(obj);
                value = Buffer::Data(obj);
            }

            if (txtRecord.setValue(buf.c_str(), valLen, value) != kDNSServiceErr_NoError) {
                return false;
            }
*/        
            if (txtRecord.setValue(buf.c_str(), buffer->ToString()->Utf8Length(), *string_value) != kDNSServiceErr_NoError) {
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}
开发者ID:baiyunping333,项目名称:node_mdns,代码行数:41,代码来源:dns_service_register.cpp

示例13: ThrowException

Handle<Value> JSDatasource::New(const Arguments& args)
{
    if (!args.IsConstructCall())
        return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

    if (args[0]->IsExternal())
    {
        //std::clog << "external!\n";
        Local<External> ext = Local<External>::Cast(args[0]);
        void* ptr = ext->Value();
        JSDatasource* d =  static_cast<JSDatasource*>(ptr);
        d->Wrap(args.This());
        return args.This();
    }
    
    if (!args.Length() == 2){
        return ThrowException(Exception::TypeError(
          String::New("two argument required: an object of key:value datasource options and a callback function for features")));
    }

    if (!args[0]->IsObject())
        return ThrowException(Exception::TypeError(
          String::New("Must provide an object, eg {extent: '-180,-90,180,90'}")));

    Local<Object> options = args[0]->ToObject();

    // function callback
    if (!args[args.Length()-1]->IsFunction())
        return ThrowException(Exception::TypeError(
                  String::New("last argument must be a callback function")));

    // TODO - maybe validate in js?

    bool bind=true;
    if (options->Has(String::New("bind")))
    {
        Local<Value> bind_opt = options->Get(String::New("bind"));
        if (!bind_opt->IsBoolean())
          return ThrowException(Exception::TypeError(
            String::New("'bind' must be a Boolean")));

        bind = bind_opt->BooleanValue();
    }

    mapnik::parameters params;
    params["type"] = "js";
    Local<Array> names = options->GetPropertyNames();
    uint32_t i = 0;
    uint32_t a_length = names->Length();
    while (i < a_length) {
        Local<Value> name = names->Get(i)->ToString();
        Local<Value> value = options->Get(name);
        params[TOSTR(name)] = TOSTR(value);
        i++;
    }

    mapnik::datasource_ptr ds;
    try
    {

        ds = mapnik::datasource_ptr(new js_datasource(params,bind,args[args.Length()-1]));
        
    }
    catch (const std::exception & ex)
    {
        return ThrowException(Exception::Error(
          String::New(ex.what())));
    }
    catch (...)
    {
        return ThrowException(Exception::Error(
          String::New("unknown exception happened, please file bug")));
    }
    if (ds)
    {
        JSDatasource* d = new JSDatasource();
        d->Wrap(args.This());
        d->ds_ptr_ = ds;
        return args.This();
    }

    return Undefined();
}
开发者ID:booo,项目名称:node-mapnik,代码行数:83,代码来源:mapnik_js_datasource.cpp

示例14: ConnectParseOptions

/*-----------------------------------------------------------------------------
 * Parse options
 */
bool ConnectParseOptions(Local<Object> options, ConnectRequest* request)
{
  // Get options data
  std::vector<std::string> optionNames = cvv8::CastFromJS<std::vector<std::string> >(options->GetPropertyNames());
  for (size_t i = 0; i < optionNames.size(); i++)
  {
    char* optionName = (char*)(optionNames[i].c_str());
    Local<Value> optionValue = options->Get(String::NewSymbol(optionName));

    if (optionValue->IsUndefined())
    {
      continue;
    }

    if (tva_str_casecmp(optionName, "username") == 0)
    {
      String::AsciiValue val(optionValue->ToString());
      request->username = strdup(*val);
    }
    else if (tva_str_casecmp(optionName, "password") == 0)
    {
      String::AsciiValue val(optionValue->ToString());
      request->password = strdup(*val);
    }
    else if (tva_str_casecmp(optionName, "tmx") == 0)
    {
      if (optionValue->IsString())
      {
        String::AsciiValue val(optionValue->ToString());
        request->primaryTmx = strdup(*val);
      }
      else if (optionValue->IsArray())
      {
        Handle<Array> tmxs = Handle<Array>::Cast(optionValue);
        char** p_tmx = &request->primaryTmx;
        Local<Value> element;
        
        element = tmxs->Get(0);
        if (!element->IsUndefined())
        {
          String::AsciiValue tmx(element->ToString());
          *p_tmx = strdup(*tmx);
          p_tmx = &request->secondaryTmx;
        }

        if (tmxs->Length() > 1)
        {
          element = tmxs->Get(1);
          if (!element->IsUndefined())
          {
            String::AsciiValue tmx(element->ToString());
            *p_tmx = strdup(*tmx);
          }
        }
      }
    }
    else if (tva_str_casecmp(optionName, "name") == 0)
    {
      String::AsciiValue val(optionValue->ToString());
      request->gdClientName = strdup(*val);
    }
    else if (tva_str_casecmp(optionName, "timeout") == 0)
    {
      request->timeout = optionValue->Int32Value() * 1000;
    }
    else if (tva_str_casecmp(optionName, "gdMaxOut") == 0)
    {
      request->gdMaxOut = optionValue->Int32Value();
    }
    else if (tva_str_casecmp(optionName, "config") == 0)
    {
      if (optionValue->IsObject())
      {
        Local<Object> config = Local<Object>::Cast(optionValue);
        std::vector<std::string> configNames = cvv8::CastFromJS<std::vector<std::string> >(config->GetPropertyNames());
        for (size_t j = 0; j < configNames.size(); j++)
        {
          char* configName = (char*)(configNames[j].c_str());
          Local<Value> configValue = config->Get(String::NewSymbol(configName));

          if (configValue->IsUndefined())
          {
            continue;
          }

          for (size_t c = 0; c < NUM_PARAMS; c++)
          {
            ConnectConfigParam* cp = &g_connectConfig[c];
            if (tva_str_casecmp(configName, cp->jsName) == 0)
            {
              switch (cp->configType)
              {
              case ConfigTypeBool:
                {
                  bool bVal;
                  if (configValue->IsBoolean())
                  {
//.........这里部分代码省略.........
开发者ID:hgokhale,项目名称:tvanode,代码行数:101,代码来源:Tervela.cpp

示例15: ThrowException

Handle<Value> Feature::addAttributes(const Arguments& args)
{
    HandleScope scope;

    Feature* fp = node::ObjectWrap::Unwrap<Feature>(args.This());

    if (args.Length() > 0 ) {
        Local<Value> val = args[0];
        if (val->IsNull() || val->IsUndefined()) {
            return ThrowException(Exception::TypeError(String::New("object expected")));
        } else {
            Local<Object> attr = val->ToObject();
            try
            {
                Local<Array> names = attr->GetPropertyNames();
                unsigned int i = 0;
                unsigned int a_length = names->Length();
                boost::scoped_ptr<mapnik::transcoder> tr(new mapnik::transcoder("utf8"));
                while (i < a_length) {
                    Local<Value> name = names->Get(i)->ToString();
                    Local<Value> value = attr->Get(name);
                    if (value->IsString()) {
                        mapnik::value_unicode_string ustr = tr->transcode(TOSTR(value));
#if MAPNIK_VERSION >= 200100
                        fp->get()->put_new(TOSTR(name),ustr);
#else
                        boost::put(*fp->get(),TOSTR(name),ustr);
#endif
                    } else if (value->IsNumber()) {
                        double num = value->NumberValue();
                        // todo - round
                        if (num == value->IntegerValue()) {
#if MAPNIK_VERSION >= 200100
                            fp->get()->put_new(TOSTR(name),static_cast<node_mapnik::value_integer>(value->IntegerValue()));
#else
                            boost::put(*fp->get(),TOSTR(name),static_cast<int>(value->IntegerValue()));
#endif

                        } else {
                            double dub_val = value->NumberValue();
#if MAPNIK_VERSION >= 200100
                            fp->get()->put_new(TOSTR(name),dub_val);
#else
                            boost::put(*fp->get(),TOSTR(name),dub_val);
#endif
                        }
                    } else if (value->IsNull()) {
#if MAPNIK_VERSION >= 200100
                        fp->get()->put_new(TOSTR(name),mapnik::value_null());
#else
                        boost::put(*fp->get(),TOSTR(name),mapnik::value_null());
#endif
                    } else {
                        std::clog << "unhandled type for property: " << TOSTR(name) << "\n";
                    }
                    i++;
                }
            }
            catch (std::exception const& ex )
            {
                return ThrowException(Exception::Error(
                                          String::New(ex.what())));
            }
        }
    }

    return Undefined();
}
开发者ID:calvinmetcalf,项目名称:node-mapnik,代码行数:68,代码来源:mapnik_feature.cpp


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