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


C++ SharedKObject类代码示例

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


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

示例1: PropertiesBinding

	void AppBinding::CreateProperties(const ValueList& args, SharedValue result)
	{
		AutoPtr<PropertiesBinding> properties = new PropertiesBinding();
		result->SetObject(properties);
		
		if (args.size() > 0 && args.at(0)->IsObject())
		{
			SharedKObject p = args.at(0)->ToObject();
			SharedStringList names = p->GetPropertyNames();
			for (size_t i = 0; i < names->size(); i++)
			{
				SharedValue value = p->Get(names->at(i));
				ValueList setterArgs;
				setterArgs.push_back(Value::NewString(names->at(i)));
				setterArgs.push_back(value);
				PropertiesBinding::Type type;
				
				if (value->IsList()) type = PropertiesBinding::List;
				else if (value->IsInt()) type = PropertiesBinding::Int;
				else if (value->IsDouble()) type = PropertiesBinding::Double;
				else if (value->IsBool()) type = PropertiesBinding::Bool;
				else type = PropertiesBinding::String;
				
				properties->Setter(setterArgs, type);
			}
		}
	}
开发者ID:jonnymind,项目名称:titanium_desktop,代码行数:27,代码来源:app_binding.cpp

示例2: StaticBoundObject

void UserWindow::PageLoaded(SharedKObject global_bound_object, std::string &url)
{
	SharedKObject event = new StaticBoundObject();
	event->Set("scope", Value::NewObject(global_bound_object));
	event->Set("url", Value::NewString(url.c_str()));
	this->FireEvent(LOAD, event);
}
开发者ID:pctj101,项目名称:titanium,代码行数:7,代码来源:user_window.cpp

示例3: BSTRToString

HRESULT STDMETHODCALLTYPE
ScriptEvaluator::evaluate(BSTR mimeType, BSTR sourceCode, int *context)
{
	std::string type = BSTRToString(mimeType);
	std::string moduleName = GetModuleName(type);
	JSContextRef contextRef = reinterpret_cast<JSContextRef>(context);

	SharedKObject global = host->GetGlobalObject();

	SharedValue moduleValue = global->Get(moduleName.c_str());
	if (!moduleValue->IsNull()) {
		SharedValue evalValue = moduleValue->ToObject()->Get("evaluate");
		if (!evalValue->IsNull() && evalValue->IsMethod()) {
			ValueList args;
			SharedValue typeValue = Value::NewString(type);
			SharedValue sourceCodeValue = Value::NewString(BSTRToString(sourceCode));
			JSObjectRef globalObjectRef = JSContextGetGlobalObject(contextRef);
			SharedKObject contextObject = new KKJSObject(contextRef, globalObjectRef);
			SharedValue contextValue = Value::NewObject(contextObject);
			args.push_back(typeValue);
			args.push_back(sourceCodeValue);
			args.push_back(contextValue);

			evalValue->ToMethod()->Call(args);
		}
	}

	return S_OK;
}
开发者ID:CJ580K,项目名称:titanium,代码行数:29,代码来源:script_evaluator.cpp

示例4: _SetContextMenu

	void UIBinding::_SetContextMenu(const ValueList& args, SharedValue result)
	{
		args.VerifyException("setContextMenu", "o|0");
		SharedKObject argObj = args.GetObject(0, NULL);
		AutoMenu menu = NULL;

		if (!argObj.isNull())
		{
			menu = argObj.cast<Menu>();
		}
		this->SetContextMenu(menu);
	}
开发者ID:leongersing,项目名称:titanium_desktop,代码行数:12,代码来源:ui_binding.cpp

示例5: RubyKObjectRespondTo

	// A :responds_to? method for finding KObject properties in Ruby
	static VALUE RubyKObjectRespondTo(int argc, VALUE *argv, VALUE self)
	{
		SharedValue* dval = NULL;
		Data_Get_Struct(self, SharedValue, dval);
		SharedKObject object = (*dval)->ToObject();
		VALUE mid, priv; // We ignore the priv argument

		rb_scan_args(argc, argv, "11", &mid, &priv);
		const char* name = rb_id2name(rb_to_id(mid));
		SharedValue value = object->Get(name);
		return value->IsUndefined() ? Qfalse : Qtrue;
	}
开发者ID:maccman,项目名称:kroll,代码行数:13,代码来源:ruby_utils.cpp

示例6: while

	void NetworkBinding::RemoveBinding(void* binding)
	{
		std::vector<SharedKObject>::iterator i = bindings.begin();
		while(i!=bindings.end())
		{
			SharedKObject b = (*i);
			if (binding == b.get())
			{
				bindings.erase(i);
				break;
			}
			i++;
		}
	}
开发者ID:CJ580K,项目名称:titanium,代码行数:14,代码来源:network_binding.cpp

示例7: Callback

	void MonkeyBinding::Callback(const ValueList &args, SharedValue result)
	{
		SharedKObject event = args.at(1)->ToObject();
		std::string url_value = event->Get("url")->ToString();
		
		std::vector< std::pair< std::pair< VectorOfPatterns,VectorOfPatterns >,std::string> >::iterator iter = scripts.begin();
		while(iter!=scripts.end())
		{
			std::pair< std::pair< VectorOfPatterns,VectorOfPatterns >, std::string> e = (*iter++);
			VectorOfPatterns include = e.first.first;
			VectorOfPatterns exclude = e.first.second;

			if (Matches(exclude,url_value))
			{
				continue;
			}
			if (Matches(include,url_value))
			{
				// I got a castle in brooklyn, that's where i dwell 
				try
				{
					SharedKMethod eval = event->Get("scope")->ToObject()->Get("window")->ToObject()->Get("eval")->ToMethod();
#ifdef DEBUG
					std::cout << ">>> loading user script for " << url_value << std::endl;
#endif
					eval->Call(Value::NewString(e.second));
				}
				catch (ValueException &ex)
				{
					Logger* logger = Logger::Get("Monkey");
					SharedString ss = ex.DisplayString();
					int line = -1;

					if (ex.GetValue()->IsObject() &&
						ex.GetValue()->ToObject()->Get("line")->IsNumber())
					{
						line = ex.GetValue()->ToObject()->Get("line")->ToInt();
					}
					logger->Error(
						"Exception generated evaluating user script for %s "
						"(line %i): %s", url_value.c_str(), line, ss->c_str());
				}
				catch (std::exception &ex)
				{
					Logger* logger = Logger::Get("Monkey");
					logger->Error("Exception generated evaluating user script for %s, Exception: %s",url_value.c_str(),ex.what());
				}
			}
		}
	}
开发者ID:CJ580K,项目名称:titanium,代码行数:50,代码来源:monkey_binding.cpp

示例8: RubyKObjectMethodMissing

	// A :method_missing method for finding KObject properties in Ruby
	static VALUE RubyKObjectMethodMissing(int argc, VALUE *argv, VALUE self)
	{
		SharedValue* dval = NULL;
		Data_Get_Struct(self, SharedValue, dval);
		SharedKObject object = (*dval)->ToObject();

		// TODO: We should raise an exception instead
		if (object.isNull())
			return Qnil;

		// This is the same error that ruby throws
		if (argc == 0 || !SYMBOL_P(argv[0]))
		{
			rb_raise(rb_eArgError, "no id given");
		}

		// We need to determine the method that was invoked:
		// store the method name and arguments in separate variables
		VALUE r_name, args;
		rb_scan_args(argc, argv, "1*", &r_name, &args);
		const char* name = rb_id2name(SYM2ID(r_name));

		// Check if this is an assignment
		SharedValue value = object->Get(name);
		if (name[strlen(name) - 1] == '=' && argc > 1)
		{
			char* mod_name = strdup(name);
			mod_name[strlen(mod_name) - 1] = '\0';
			value = RubyUtils::ToKrollValue(argv[1]);
			object->Set(mod_name, value);
			free(mod_name);
			return argv[1];
		}
		else if (value->IsUndefined()) // raise a method missing error
		{
			VALUE selfString = rb_obj_as_string(self);
			rb_raise(rb_eNoMethodError, "undefined method `%s' for %s",
				name, RubyUtils::ToString(selfString));
		}
		else if (value->IsMethod()) // actually call a method
		{
			return RubyUtils::GenericKMethodCall(value->ToMethod(), args);
		}
		else // Plain old access
		{
			return RubyUtils::ToRubyValue(value);
		}
	}
开发者ID:maccman,项目名称:kroll,代码行数:49,代码来源:ruby_utils.cpp

示例9: RubyKObjectMethods

	static VALUE RubyKObjectMethods(VALUE self)
	{
		SharedValue* value = NULL;
		Data_Get_Struct(self, SharedValue, value);
		SharedKObject object = (*value)->ToObject();

		VALUE* args = NULL;
		VALUE methods = rb_call_super(0, args);

		SharedStringList props = object->GetPropertyNames();
		for (unsigned int i = 0; i < props->size(); i++)
		{
			SharedString prop_name = props->at(i);
			rb_ary_push(methods, rb_str_new2(prop_name->c_str()));
		}
		return methods;
	}
开发者ID:maccman,项目名称:kroll,代码行数:17,代码来源:ruby_utils.cpp

示例10: GetModuleName

HRESULT STDMETHODCALLTYPE
ScriptEvaluator::matchesMimeType(BSTR mimeType, BOOL *result)
{
	std::string moduleName = GetModuleName(BSTRToString(mimeType));
	SharedKObject global = host->GetGlobalObject();

	SharedValue moduleValue = global->Get(moduleName.c_str());
	*result = FALSE;
	if (!moduleValue->IsNull() && moduleValue->IsObject()) {
		if (!moduleValue->ToObject()->Get("evaluate")->IsNull()
				&& !moduleValue->ToObject()->Get("evaluate")->IsUndefined()
				&& moduleValue->ToObject()->Get("evaluate")->IsMethod()) {
			*result = TRUE;
		}
	}

	return S_OK;
}
开发者ID:CJ580K,项目名称:titanium,代码行数:18,代码来源:script_evaluator.cpp

示例11: _SetMenu

	void UIBinding::_SetMenu(const ValueList& args, SharedValue result)
	{
		args.VerifyException("setMenu", "o|0");
		SharedKObject argObj = args.GetObject(0, NULL);
		AutoMenu menu = NULL;

		if (!argObj.isNull())
		{
			menu = argObj.cast<Menu>();
		}

		this->SetMenu(menu); // platform-specific impl

		// Notify all windows that the app menu has changed.
		std::vector<AutoUserWindow>::iterator i = openWindows.begin();
		while (i != openWindows.end()) {
			(*i++)->AppMenuChanged();
		}
	}
开发者ID:leongersing,项目名称:titanium_desktop,代码行数:19,代码来源:ui_binding.cpp

示例12: Send

	void HTTPClientBinding::Send(const ValueList& args, SharedValue result)
	{
		if (this->Get("connected")->ToBool())
		{
			throw ValueException::FromString("already connected");
		}
		if (args.size()==1)
		{
			// can be a string of data or a file
			SharedValue v = args.at(0);
			if (v->IsObject())
			{
				// probably a file
				SharedKObject obj = v->ToObject();
				this->datastream = obj->Get("toString")->ToMethod()->Call()->ToString();
			}
			else if (v->IsString())
			{
				this->datastream = v->ToString();
			}
			else if (v->IsNull() || v->IsUndefined())
			{
				this->datastream = "";
			}
			else
			{
				throw ValueException::FromString("unknown data type");
			}
		}
		this->thread = new Poco::Thread();
		this->thread->start(&HTTPClientBinding::Run,(void*)this);
		if (!this->async)
		{
			PRINTD("Waiting on HTTP Client thread to finish (sync)");
			Poco::Stopwatch sw;
			sw.start();
			while (!this->shutdown && sw.elapsedSeconds() * 1000 < this->timeout)
			{
				this->thread->tryJoin(100);
			}
			PRINTD("HTTP Client thread finished (sync)");
		}
	}
开发者ID:CJ580K,项目名称:titanium,代码行数:43,代码来源:http_client_binding.cpp

示例13: StaticBoundList

	void IRCClientBinding::GetUsers(const ValueList& args, SharedValue result)
	{
		const char *channel = args.at(0)->ToString();
		SharedKList list = new StaticBoundList();
		channel_user* cu = irc.get_users();
		while(cu)
		{
			if (!strcmp(cu->channel,(char*)channel) && cu->nick && strlen(cu->nick)>0)
			{
				SharedKObject entry = new StaticBoundObject();
				entry->Set("name",Value::NewString(cu->nick));
				entry->Set("operator",Value::NewBool(cu->flags & IRC_USER_OP));
				entry->Set("voice",Value::NewBool(cu->flags & IRC_USER_VOICE));
				list->Append(Value::NewObject(entry));
			}
			cu = cu->next;
		}
		result->SetList(list);
	}
开发者ID:jonnymind,项目名称:titanium_desktop,代码行数:19,代码来源:irc_client_binding.cpp

示例14: SendFile

	void HTTPClientBinding::SendFile(const ValueList& args, SharedValue result)
	{
		if (this->Get("connected")->ToBool())
		{
			throw ValueException::FromString("already connected");
		}
		if (args.size()==1)
		{
			// can be a string of data or a file
			SharedValue v = args.at(0);
			if (v->IsObject())
			{
				// probably a file
				SharedKObject obj = v->ToObject();
				if (obj->Get("isFile")->IsMethod())
				{
					std::string file = obj->Get("toString")->ToMethod()->Call()->ToString();
					this->filestream = new Poco::FileInputStream(file);
					Poco::Path p(file);
					this->filename = p.getFileName();
				}
				else
				{
					this->datastream = obj->Get("toString")->ToMethod()->Call()->ToString();
				}
			}
			else if (v->IsString())
			{
				this->filestream = new Poco::FileInputStream(v->ToString());
			}
			else
			{
				throw ValueException::FromString("unknown data type");
			}
		}
		this->thread = new Poco::Thread();
		this->thread->start(&HTTPClientBinding::Run,(void*)this);
		if (!this->async)
		{
			PRINTD("Waiting on HTTP Client thread to finish");
			this->thread->join();
		}
	}
开发者ID:CJ580K,项目名称:titanium,代码行数:43,代码来源:http_client_binding.cpp

示例15: GetHostByAddress

	void NetworkBinding::GetHostByAddress(const ValueList& args, SharedValue result)
	{
		if (args.at(0)->IsObject())
		{
			SharedKObject obj = args.at(0)->ToObject();
			SharedPtr<IPAddressBinding> b = obj.cast<IPAddressBinding>();
			if (!b.isNull())
			{
				// in this case, they've passed us an IPAddressBinding
				// object, which we can just retrieve the ipaddress
				// instance and resolving using it
				IPAddress addr(b->GetAddress()->toString());
				SharedPtr<HostBinding> binding = new HostBinding(addr);
				if (binding->IsInvalid())
				{
					throw ValueException::FromString("Could not resolve address");
				}
				result->SetObject(binding);
				return;
			}
			else
			{
				SharedValue bo = obj->Get("toString");
				if (bo->IsMethod())
				{
					SharedKMethod m = bo->ToMethod();
					ValueList args;
					SharedValue tostr = m->Call(args);
					this->_GetByHost(tostr->ToString(),result);
					return;
				}
				throw ValueException::FromString("Unknown object passed");
			}
		}
		else if (args.at(0)->IsString())
		{
			// in this case, they just passed in a string so resolve as
			// normal
			this->_GetByHost(args.at(0)->ToString(),result);
		}
	}
开发者ID:CJ580K,项目名称:titanium,代码行数:41,代码来源:network_binding.cpp


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