本文整理汇总了C++中KValueRef::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ KValueRef::ToString方法的具体用法?C++ KValueRef::ToString怎么用?C++ KValueRef::ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KValueRef
的用法示例。
在下文中一共展示了KValueRef::ToString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddKrollValueToPHPArray
void KPHPArrayObject::AddKrollValueToPHPArray(KValueRef value, zval *phpArray, unsigned int index)
{
if (value->IsNull() || value->IsUndefined())
{
add_index_null(phpArray, (unsigned long) index);
}
else if (value->IsBool())
{
if (value->ToBool())
add_index_bool(phpArray, (unsigned long) index, 1);
else
add_index_bool(phpArray, (unsigned long) index, 0);
}
else if (value->IsNumber())
{
/* No way to check whether the number is an
integer or a double here. All Kroll numbers
are doubles, so return a double. This could
cause some PHP to function incorrectly if it's
doing strict type checking. */
add_index_double(phpArray, (unsigned long) index, value->ToNumber());
}
else if (value->IsString())
{
add_index_stringl(phpArray, (unsigned long) index, (char *) value->ToString(), strlen(value->ToString()), 1);
}
else if (value->IsObject())
{
/*TODO: Implement*/
}
else if (value->IsMethod())
{
/*TODO: Implement*/
}
else if (value->IsList())
{
zval *phpValue;
AutoPtr<KPHPArrayObject> pl = value->ToList().cast<KPHPArrayObject>();
if (!pl.isNull())
phpValue = pl->ToPHP();
else
phpValue = PHPUtils::ToPHPValue(value);
add_index_zval(phpArray, (unsigned long) index, phpValue);
}
}
示例2: _Print
void APIBinding::_Print(const ValueList& args, KValueRef result)
{
for (size_t c=0; c < args.size(); c++)
{
KValueRef arg = args.at(c);
if (arg->IsString())
{
const char *s = arg->ToString();
std::cout << s;
}
else
{
SharedString ss = arg->DisplayString();
std::cout << *ss;
}
}
std::cout.flush();
}
示例3: StdErr
void AppBinding::StdErr(const ValueList& args, KValueRef result)
{
for (size_t c = 0; c < args.size(); c++)
{
KValueRef arg = args.at(c);
if (arg->IsString())
{
const char *s = arg->ToString();
std::cerr << s;
}
else
{
SharedString ss = arg->DisplayString();
std::cerr << *ss;
}
}
std::cerr << std::endl;
}
示例4: 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");
}
}
示例5: Log
//---------------- IMPLEMENTATION METHODS
void APIBinding::Log(int severity, KValueRef value)
{
// optimize these calls since they're called a lot
if (false == logger->IsEnabled((Logger::Level)severity))
{
return;
}
if (value->IsString())
{
string message = value->ToString();
logger->Log((Logger::Level) severity, message);
}
else
{
SharedString message = value->DisplayString();
logger->Log((Logger::Level) severity, *message);
}
}
示例6: GetStringList
void KObject::GetStringList(const char *name, std::vector<std::string> &list)
{
KValueRef prop = this->Get(name);
if(!prop->IsUndefined() && prop->IsList())
{
KListRef values = prop->ToList();
if (values->Size() > 0)
{
for (unsigned int c = 0; c < values->Size(); c++)
{
KValueRef v = values->At(c);
if (v->IsString())
{
const char *s = v->ToString();
list.push_back(s);
}
}
}
}
}
示例7: GetList
void PropertiesBinding::GetList(const ValueList& args, KValueRef result)
{
KValueRef stringValue = Value::Null;
GetString(args, stringValue);
if (!stringValue->IsNull())
{
KListRef list = new StaticBoundList();
std::string string = stringValue->ToString();
Poco::StringTokenizer t(string, ",", Poco::StringTokenizer::TOK_TRIM);
for (size_t i = 0; i < t.count(); i++)
{
KValueRef token = Value::NewString(t[i].c_str());
list->Append(token);
}
KListRef list2 = list;
result->SetList(list2);
}
}
示例8: convert
void convert (Statement &select, KValueRef arg)
{
if (arg->IsString())
{
std::string *s = new std::string(arg->ToString());
select , use(*s);
strings.push_back(s);
}
else if (arg->IsInt())
{
int *i = new int(arg->ToInt());
select , use(*i);
ints.push_back(i);
}
else if (arg->IsDouble())
{
double *d = new double(arg->ToDouble());
select , use(*d);
doubles.push_back(d);
}
else if (arg->IsBool())
{
bool *b = new bool(arg->ToBool());
select , use(*b);
bools.push_back(b);
}
else if (arg->IsNull() || arg->IsUndefined())
{
// in this case, we bind a null string (dequoted)
std::string *s = new std::string("null");
select , use(s);
strings.push_back(s);
}
else
{
throw ValueException::FromFormat("Unsupport type for argument: %s",
arg->GetType().c_str());
}
}
示例9: 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);
}
}
示例10: 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()));
}
}
示例11: 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;
}
示例12: 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;
}