本文整理汇总了C++中SharedValue类的典型用法代码示例。如果您正苦于以下问题:C++ SharedValue类的具体用法?C++ SharedValue怎么用?C++ SharedValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SharedValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DisplayString
SharedString KObject::DisplayString(int levels)
{
std::stringstream ss;
if (levels == 0)
{
ss << "<KObject at " << this << ">";
}
else
{
SharedStringList props = this->GetPropertyNames();
ss << "{";
for (size_t i = 0; i < props->size(); i++)
{
SharedValue prop = this->Get(props->at(i));
SharedString disp_string = prop->DisplayString(levels);
ss << " " << *(props->at(i))
<< " : " << *disp_string << ",";
}
if (props->size() > 0) // Erase last comma
ss.seekp((int)ss.tellp() - 1);
ss << "}";
}
return new std::string(ss.str());
}
示例2: LastIndexOf
void Blob::LastIndexOf(const ValueList& args, SharedValue result)
{
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/lastIndexOf
args.VerifyException("Blob.lastIndexOf", "s,?i");
if (this->length <= 0)
{
result->SetInt(-1);
}
else
{
std::string target = this->buffer;
std::string needle = args.at(0)->ToString();
int start = target.size() + 1;
if (args.size() > 1)
{
start = args.GetNumber(1);
if (start < 0)
{
start = 0;
}
}
result->SetInt(target.rfind(needle, start));
}
}
示例3: if
void AppBinding::GetStreamURL(const ValueList& args, SharedValue result)
{
const SharedApplication app = this->host->GetApplication();
std::string stream = app->stream;
// TODO: switch to HTTPS once the ti.Network XHR supports it
std::string url = "http://api.appcelerator.net/";
if (stream == "production")
{
url+="p/v1";
}
else if (stream == "dev")
{
url+="d/v1";
}
else if (stream == "test")
{
url+="t/v1";
}
else
{
url+=stream;
url+="/v1";
}
for (size_t c = 0; c < args.size(); c++)
{
SharedValue arg = args.at(c);
if (arg->IsString())
{
url+="/";
url+=arg->ToString();
}
}
result->SetString(url);
}
示例4: EncodeURIComponent
void NetworkBinding::EncodeURIComponent(const ValueList &args, SharedValue result)
{
if (args.at(0)->IsNull() || args.at(0)->IsUndefined())
{
result->SetString("");
}
else if (args.at(0)->IsString())
{
std::string src = args.at(0)->ToString();
std::string sResult = DataUtils::EncodeURIComponent(src);
result->SetString(sResult);
}
else if (args.at(0)->IsDouble())
{
std::stringstream str;
str << args.at(0)->ToDouble();
result->SetString(str.str().c_str());
}
else if (args.at(0)->IsBool())
{
std::stringstream str;
str << args.at(0)->ToBool();
result->SetString(str.str().c_str());
}
else if (args.at(0)->IsInt())
{
std::stringstream str;
str << args.at(0)->ToInt();
result->SetString(str.str().c_str());
}
else
{
throw ValueException::FromString("Could not encodeURIComponent with type passed");
}
}
示例5: lock
void WorkerContext::SendQueuedMessages()
{
Logger *logger = Logger::Get("WorkerContext");
logger->Debug("SendQueuedMessages called");
SharedValue onmessage = worker->Get("onmessage");
Poco::ScopedLock<Poco::Mutex> lock(mutex);
if (onmessage->IsMethod())
{
if (messages.size()>0)
{
std::list<SharedValue>::iterator i = messages.begin();
while(i!=messages.end())
{
SharedValue v = (*i++);
ValueList _args;
string name = "worker.message";
AutoPtr<KEventObject> target = this;
this->duplicate();
AutoPtr<Event> event = new Event(target, name);
event->Set("message", v);
_args.push_back(Value::NewObject(event));
host->InvokeMethodOnMainThread(onmessage->ToMethod(),_args,false);
}
messages.clear();
}
}
}
示例6: s
SharedValue KObject::GetNS(const char *name)
{
std::string s(name);
std::string::size_type last = 0;
std::string::size_type pos = s.find_first_of(".");
SharedValue current;
KObject* scope = this;
while (pos != std::string::npos)
{
std::string token = s.substr(last,pos-last);
current = scope->Get(token.c_str());
if (current->IsObject())
{
scope = current->ToObject().get();
}
else
{
return Value::Undefined;
}
last = pos + 1;
pos = s.find_first_of(".", last);
}
if (pos!=s.length())
{
std::string token = s.substr(last);
current = scope->Get(token.c_str());
}
return current;
}
示例7: SetProxy
void NetworkBinding::SetProxy(const ValueList& args, SharedValue result)
{
std::string hostname = args.at(0)->ToString();
std::string port = args.at(1)->ToString();
std::string username = args.at(2)->ToString();
std::string password = args.at(3)->ToString();
if(proxy)
{
delete proxy;
proxy = NULL;
}
#if defined(OS_WIN32)
std::string http_proxy = "http://";
http_proxy += username + ":" + password + "@";
http_proxy += hostname + ":" + port;
int i = ::_putenv_s("HTTP_PROXY", http_proxy.c_str());
if(i != 0)
{
result->SetBool(false);
}
#endif
proxy = new ti::Proxy(hostname, port, username,password);
result->SetBool(true);
}
示例8: Read
void HttpServerRequest::Read(const ValueList& args, SharedValue result)
{
std::istream &in = request.stream();
if (in.eof() || in.fail())
{
result->SetNull();
return;
}
int max_size = 8096;
if (args.size()==1)
{
max_size = args.at(0)->ToInt();
}
char *buf = new char[max_size];
in.read(buf,max_size);
std::streamsize count = in.gcount();
if (count == 0)
{
result->SetNull();
}
else
{
result->SetObject(new Blob(buf,count));
}
delete [] buf;
}
示例9: CreateWorker
void WorkerBinding::CreateWorker(const ValueList& args, SharedValue result)
{
if (args.size()!=2)
{
throw ValueException::FromString("invalid argument specified");
}
bool is_function = args.at(1)->ToBool();
std::string code;
Logger *logger = Logger::Get("Worker");
if (is_function)
{
// convert the function to a string block
code = "(";
code += args.at(0)->ToString();
code += ")()";
}
else
{
// this is a path -- probably should verify that this is relative and not an absolute URL to remote
SharedKMethod appURLToPath = global->GetNS("App.appURLToPath")->ToMethod();
ValueList a;
a.push_back(args.at(0));
SharedValue result = appURLToPath->Call(a);
const char *path = result->ToString();
logger->Debug("worker file path = %s",path);
std::ios::openmode flags = std::ios::in;
Poco::FileInputStream *fis = new Poco::FileInputStream(path,flags);
std::stringstream ostr;
char buf[8096];
int count = 0;
while(!fis->eof())
{
fis->read((char*)&buf,8095);
std::streamsize len = fis->gcount();
if (len>0)
{
buf[len]='\0';
count+=len;
ostr << buf;
}
else break;
}
fis->close();
code = std::string(ostr.str());
}
logger->Debug("Worker script code = %s", code.c_str());
SharedKObject worker = new Worker(host,global,code);
result->SetObject(worker);
}
示例10: StdErr
void AppBinding::StdErr(const ValueList& args, SharedValue result)
{
for (size_t c=0;c<args.size();c++)
{
SharedValue arg = args.at(c);
const char *s = arg->ToString();
std::cerr << s;
}
std::cerr << std::endl;
}
示例11: GetIcon
void AppBinding::GetIcon(const ValueList& args, SharedValue result)
{
SharedApplication app = this->host->GetApplication();
result->SetNull();
if (app && !app->image.empty())
{
result->SetString(app->image);
}
}
示例12: ToString
void Blob::ToString(const ValueList& args, SharedValue result)
{
if (this->length == 0)
{
result->SetString("");
}
else
{
result->SetString(buffer);
}
}
示例13: FieldCount
void ResultSetBinding::FieldCount(const ValueList& args, SharedValue result)
{
if (rs.isNull())
{
result->SetInt(0);
}
else
{
result->SetInt(rs->columnCount());
}
}
示例14: _GetSubmenu
void MenuItem::_GetSubmenu(const ValueList& args, SharedValue result)
{
if (this->submenu.isNull())
{
result->SetNull();
}
else
{
result->SetObject(this->submenu);
}
}
示例15: IsValidRow
void ResultSetBinding::IsValidRow(const ValueList& args, SharedValue result)
{
if (rs.isNull())
{
result->SetBool(false);
}
else
{
result->SetBool(!eof);
}
}