本文整理汇总了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);
}
}
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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++;
}
}
示例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());
}
}
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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)");
}
}
示例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);
}
示例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();
}
}
示例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);
}
}