本文整理汇总了C++中KValueRef::ToObject方法的典型用法代码示例。如果您正苦于以下问题:C++ KValueRef::ToObject方法的具体用法?C++ KValueRef::ToObject怎么用?C++ KValueRef::ToObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KValueRef
的用法示例。
在下文中一共展示了KValueRef::ToObject方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetNS
KValueRef KObject::GetNS(const char *name)
{
std::string s(name);
std::string::size_type last = 0;
std::string::size_type pos = s.find_first_of(".");
KValueRef 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;
}
示例2: Wrap
KValueRef ProfiledBoundObject::Wrap(KValueRef value, std::string type)
{
if (AlreadyWrapped(value))
{
return value;
}
else if (value->IsMethod())
{
KMethodRef toWrap = value->ToMethod();
KMethodRef wrapped = new ProfiledBoundMethod(toWrap, type);
return Value::NewMethod(wrapped);
}
else if (value->IsList())
{
KListRef wrapped = new ProfiledBoundList(value->ToList());
return Value::NewList(wrapped);
}
else if (value->IsObject())
{
KObjectRef wrapped = new ProfiledBoundObject(value->ToObject());
return Value::NewObject(wrapped);
}
else
{
return value;
}
}
示例3: GetPathFromValue
static std::string GetPathFromValue(KValueRef value)
{
if (value->IsObject())
{
return value->ToObject()->DisplayString()->c_str();
}
else
{
return value->ToString();
}
}
示例4: GetObject
KObjectRef KObject::GetObject(const char* name, KObjectRef defaultValue)
{
KValueRef prop = this->Get(name);
if (prop->IsObject())
{
return prop->ToObject();
}
else
{
return defaultValue;
}
}
示例5: ValueToBytes
static BytesRef ValueToBytes(KValueRef value)
{
if (value->IsObject())
{
BytesRef bytes = value->ToObject().cast<Bytes>();
if (bytes.isNull())
bytes = new Bytes("", 0);
return bytes;
}
else if (value->IsString())
{
const char* data = value->ToString();
return new Bytes(data, strlen(data));
}
else
{
throw ValueException::FromString("Need a Bytes or a String");
}
}
示例6: AlreadyWrapped
bool ProfiledBoundObject::AlreadyWrapped(KValueRef value)
{
if (value->IsMethod()) {
KMethodRef source = value->ToMethod();
AutoPtr<ProfiledBoundMethod> po = source.cast<ProfiledBoundMethod>();
return !po.isNull();
} else if (value->IsList()) {
KListRef source = value->ToList();
AutoPtr<ProfiledBoundList> po = source.cast<ProfiledBoundList>();
return !po.isNull();
} else if (value->IsObject()) {
KObjectRef source = value->ToObject();
AutoPtr<ProfiledBoundObject> po = source.cast<ProfiledBoundObject>();
return !po.isNull();
} else {
return true;
}
}
示例7: ValueToLevel
Logger::Level APIBinding::ValueToLevel(KValueRef v)
{
if (v->IsString())
{
string levelString = v->ToString();
return Logger::GetLevel(levelString);
}
else if (v->IsObject())
{
SharedString ss = v->ToObject()->DisplayString();
return Logger::GetLevel(*ss);
}
else if (v->IsNumber())
{
return (Logger::Level) v->ToInt();
}
else // return the appropriate default
{
string levelString = "";
return Logger::GetLevel(levelString);
}
}
示例8: GetBytes
static void GetBytes(KValueRef value, std::vector<BytesRef>& blobs)
{
if (value->IsObject())
{
blobs.push_back(value->ToObject().cast<Bytes>());
}
else if (value->IsString())
{
blobs.push_back(new Bytes(value->ToString()));
}
else if (value->IsList())
{
KListRef list = value->ToList();
for (size_t j = 0; j < list->Size(); j++)
{
GetBytes(list->At((int)j), blobs);
}
}
else if (value->IsNumber())
{
blobs.push_back(new Bytes(value->ToInt()));
}
}
示例9: if
AutoPtr<PreprocessData> Script::Preprocess(const char *url, KObjectRef scope)
{
KObjectRef evaluator = this->FindEvaluatorWithMethod("canPreprocess", url);
if (!evaluator.isNull())
{
KMethodRef preprocess = evaluator->GetMethod("preprocess");
if (!preprocess.isNull())
{
ValueList args;
args.push_back(Value::NewString(url));
args.push_back(Value::NewObject(scope));
KValueRef result = preprocess->Call(args);
if (result->IsObject())
{
KObjectRef object = result->ToObject();
AutoPtr<PreprocessData> data = new PreprocessData();
if (object->HasProperty("data"))
{
KValueRef objectData = object->Get("data");
if (objectData->IsObject())
{
BlobRef blobData = objectData->ToObject().cast<Blob>();
if (!blobData.isNull())
{
data->data = blobData;
}
}
else if (objectData->IsString())
{
data->data = new Blob(objectData->ToString(), strlen(objectData->ToString()));
}
}
else
{
throw ValueException::FromString("Preprocessor didn't return any data");
}
if (object->HasProperty("mimeType"))
{
data->mimeType = object->Get("mimeType")->ToString();
}
else
{
throw ValueException::FromString("Preprocessor didn't return a mimeType");
}
return data;
}
}
else
{
throw ValueException::FromFormat(
"Error preprocessing: No \"preprocess\" method found on evaluator for url: \"%s\"", url);
}
}
else
{
throw ValueException::FromFormat("Error preprocessing: No evaluator found for url: \"%s\"", url);
}
return 0;
}
示例10: BeginRequest
bool HTTPClientBinding::BeginRequest(KValueRef sendData)
{
if (this->Get("connected")->ToBool())
{
return false;
}
// Reset internal variables for new request
if (this->dirty)
{
this->Reset();
}
// Determine what data type we have to send
if (sendData->IsObject())
{
KObjectRef dataObject = sendData->ToObject();
KMethodRef nativePathMethod(dataObject->GetMethod("nativePath"));
KMethodRef sizeMethod(dataObject->GetMethod("size"));
if (nativePathMethod.isNull() || sizeMethod.isNull())
{
std::string err("Unsupported File-like object: did not have"
"nativePath and size methods");
logger->Error(err);
throw ValueException::FromString(err);
}
const char* filename = nativePathMethod->Call()->ToString();
if (!filename)
{
std::string err("Unsupported File-like object: nativePath method"
"did not return a String");
logger->Error(err);
throw ValueException::FromString(err);
}
this->datastream = new std::ifstream(filename,
std::ios::in | std::ios::binary);
if (this->datastream->fail())
{
std::string err("Failed to open file: ");
err.append(filename);
logger->Error(err);
throw ValueException::FromString(err);
}
this->contentLength = sizeMethod->Call()->ToInt();
}
else if (sendData->IsString())
{
std::string dataString(sendData->ToString());
if (!dataString.empty())
{
this->datastream = new std::istringstream(dataString,
std::ios::in | std::ios::binary);
this->contentLength = dataString.length();
}
}
else
{
// Sending no data
this->datastream = 0;
}
this->dirty = true;
this->Set("connected", Value::NewBool(true));
if (this->async)
{
this->thread = new Poco::Thread();
this->thread->start(*this);
}
else
{
this->ExecuteRequest();
}
return true;
}