本文整理汇总了C++中Variant类的典型用法代码示例。如果您正苦于以下问题:C++ Variant类的具体用法?C++ Variant怎么用?C++ Variant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Variant类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: _variant_to_jvalue
jvalue _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant* p_arg, bool force_jobject = false) {
jvalue v;
switch(p_type) {
case Variant::BOOL: {
if (force_jobject) {
jclass bclass = env->FindClass("java/lang/Boolean");
jmethodID ctor = env->GetMethodID(bclass, "<init>", "(Z)V");
jvalue val;
val.z = (bool)(*p_arg);
jobject obj = env->NewObjectA(bclass, ctor, &val);
v.l = obj;
} else {
v.z=*p_arg;
};
} break;
case Variant::INT: {
if (force_jobject) {
jclass bclass = env->FindClass("java/lang/Integer");
jmethodID ctor = env->GetMethodID(bclass, "<init>", "(I)V");
jvalue val;
val.i = (int)(*p_arg);
jobject obj = env->NewObjectA(bclass, ctor, &val);
v.l = obj;
} else {
v.i=*p_arg;
};
} break;
case Variant::REAL: {
if (force_jobject) {
jclass bclass = env->FindClass("java/lang/Double");
jmethodID ctor = env->GetMethodID(bclass, "<init>", "(D)V");
jvalue val;
val.d = (double)(*p_arg);
jobject obj = env->NewObjectA(bclass, ctor, &val);
v.l = obj;
} else {
v.f=*p_arg;
};
} break;
case Variant::STRING: {
String s = *p_arg;
jstring jStr = env->NewStringUTF(s.utf8().get_data());
v.l=jStr;
} break;
case Variant::STRING_ARRAY: {
DVector<String> sarray = *p_arg;
jobjectArray arr = env->NewObjectArray(sarray.size(),env->FindClass("java/lang/String"),env->NewStringUTF(""));
for(int j=0;j<sarray.size();j++) {
env->SetObjectArrayElement(arr,j,env->NewStringUTF( sarray[j].utf8().get_data() ));
}
v.l=arr;
} break;
case Variant::DICTIONARY: {
Dictionary dict = *p_arg;
jclass dclass = env->FindClass("com/android/godot/Dictionary");
jmethodID ctor = env->GetMethodID(dclass, "<init>", "()V");
jobject jdict = env->NewObject(dclass, ctor);
Array keys = dict.keys();
jobjectArray jkeys = env->NewObjectArray(keys.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
for (int j=0; j<keys.size(); j++) {
env->SetObjectArrayElement(jkeys, j, env->NewStringUTF(String(keys[j]).utf8().get_data()));
};
jmethodID set_keys = env->GetMethodID(dclass, "set_keys", "([Ljava/lang/String;)V");
jvalue val;
val.l = jkeys;
env->CallVoidMethodA(jdict, set_keys, &val);
jobjectArray jvalues = env->NewObjectArray(keys.size(), env->FindClass("java/lang/Object"), NULL);
for (int j=0; j<keys.size(); j++) {
Variant var = dict[keys[j]];
val = _variant_to_jvalue(env, var.get_type(), &var, true);
env->SetObjectArrayElement(jvalues, j, val.l);
};
jmethodID set_values = env->GetMethodID(dclass, "set_values", "([Ljava/lang/Object;)V");
val.l = jvalues;
env->CallVoidMethodA(jdict, set_values, &val);
v.l = jdict;
//.........这里部分代码省略.........
开发者ID:9cat,项目名称:godot,代码行数:101,代码来源:java_glue.cpp
示例2: WideString
void TForm1::WriteClassifications(Variant &vSheet, std::vector<exlClass> &classes)
{
lblStatus->Caption = "Приступаю к сортировке классификаций...";
Log->Lines->Add("Приступаю к сортировке классификаций...");
int nReplaced = 1;
while(nReplaced > 0) {
nReplaced = 0;
for (unsigned int i = 0; i < classes.size()-1; i++) {
if (classes[i].Name.UpperCase() > classes[i+1].Name.UpperCase()) {
exlClass cl = classes[i];
classes[i] = classes[i+1];
classes[i+1] = cl;
nReplaced++;
}
}
}
Log->Lines->Add("Отсортировано!");
int nRowsCount = vSheet.OlePropertyGet("Cells").OlePropertyGet("Rows").OlePropertyGet("Count");
int nLastRow1 = vSheet.OlePropertyGet("Cells", nRowsCount, 1).OlePropertyGet("End", xlUp).OlePropertyGet("Row");
int nLastRow2 = vSheet.OlePropertyGet("Cells", nRowsCount, 2).OlePropertyGet("End", xlUp).OlePropertyGet("Row");
int nLastRow3 = vSheet.OlePropertyGet("Cells", nRowsCount, 3).OlePropertyGet("End", xlUp).OlePropertyGet("Row");
int nLastRow4 = vSheet.OlePropertyGet("Cells", nRowsCount, 4).OlePropertyGet("End", xlUp).OlePropertyGet("Row");
int nLastRow = 0;
nLastRow = std::max(nLastRow, nLastRow1);
nLastRow = std::max(nLastRow, nLastRow2);
nLastRow = std::max(nLastRow, nLastRow3);
nLastRow = std::max(nLastRow, nLastRow4);
lblStatus->Caption = "Произвожу очистку классификаций в файле...";
Log->Lines->Add("Произвожу очистку классификаций в файле");
ProgressBar1->Max = nLastRow;
ProgressBar1->Min = 0;
for (int i = 1; i < nLastRow; i++) {
ProgressBar1->Position = i;
Application->ProcessMessages();
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,1).OlePropertySet("Value", WideString(""));
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,2).OlePropertySet("Value", WideString(""));
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,3).OlePropertySet("Value", WideString(""));
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,4).OlePropertySet("Value", WideString(""));
}
lblStatus->Caption = "Приступаю к записи классификаций в файл...";
Log->Lines->Add("Приступаю к записи в файл " + IntToStr((int)classes.size()));
ProgressBar1->Max = classes.size();
ProgressBar1->Min = 0;
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertySet("Value", WideString("Наименование"));
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",1,2).OlePropertySet("Value", WideString("Класс"));
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",1,3).OlePropertySet("Value", WideString("Комментарий"));
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",1,4).OlePropertySet("Value", WideString("Месяца"));
for (unsigned int i = 0; i < classes.size(); i++) {
exlClass cl = classes[i];
ProgressBar1->Position = i;
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+2,1).OlePropertySet("Value", WideString(cl.Name));
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+2,2).OlePropertySet("Value", WideString(cl.Class));
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+2,3).OlePropertySet("Value", WideString(cl.Comment));
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+2,4).OlePropertySet("Value", WideString(cl.Monthes));
}
lblStatus->Caption = "";
}
开发者ID:sea-kg,项目名称:homemoney,代码行数:61,代码来源:main.cpp
示例3:
void TForm1::setBorders(Variant &vSheet, int nRow, int nCol) {
vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,nCol).OlePropertyGet("Borders").OlePropertySet("LineStyle", xlContinuous);
}
开发者ID:sea-kg,项目名称:homemoney,代码行数:3,代码来源:main.cpp
示例4: f_file_get_contents
bool TestExtOpenssl::test_openssl_x509_read() {
Variant fcert = f_file_get_contents("test/ext/test_x509.crt");
Variant cert = f_openssl_x509_read(fcert);
VERIFY(!cert.toObject().isNull());
return Count(true);
}
开发者ID:MarkTseng,项目名称:hiphop-php,代码行数:6,代码来源:test_ext_openssl.cpp
示例5: http
bool UrlFile::open(const String& input_url, const String& mode) {
String url = input_url;
const char* modestr = mode.c_str();
if (strchr(modestr, '+') || strchr(modestr, 'a') || strchr(modestr, 'w')) {
std::string msg = "cannot open a url stream for write/append operation: ";
msg += url.c_str();
m_error = msg;
return false;
}
HttpClient http(m_timeout, m_maxRedirect);
auto ctx = this->getStreamContext();
if (ctx) {
http.setStreamContextOptions(ctx->getOptions());
}
m_response.clear();
if (!m_proxyHost.empty()) {
http.proxy(m_proxyHost, m_proxyPort, m_proxyUsername, m_proxyPassword);
}
HeaderMap *pHeaders = nullptr;
HeaderMap requestHeaders;
if (!m_headers.empty()) {
pHeaders = &requestHeaders;
for (ArrayIter iter(m_headers); iter; ++iter) {
requestHeaders[std::string(iter.first().toString().data())].
push_back(iter.second().toString().data());
}
}
Variant user = f_parse_url(url, k_PHP_URL_USER);
if (user.isString()) {
Variant pass = f_parse_url(url, k_PHP_URL_PASS);
http.auth(user.toString().c_str(), pass.toString().c_str());
url = HHVM_FN(preg_replace)(
s_remove_user_pass_pattern,
s_remove_user_pass_replace,
url,
1
).toString();
}
int code;
req::vector<String> responseHeaders;
if (m_get) {
code = http.get(url.c_str(), m_response, pHeaders, &responseHeaders);
} else {
code = http.request(m_method,
url.c_str(), m_postData.data(), m_postData.size(),
m_response, pHeaders, &responseHeaders);
}
m_responseHeaders.reset();
for (unsigned int i = 0; i < responseHeaders.size(); i++) {
m_responseHeaders.append(responseHeaders[i]);
}
VMRegAnchor vra;
ActRec* fp = vmfp();
if (fp->skipFrame()) fp = g_context->getPrevVMStateSkipFrame(fp);
auto id = fp->func()->lookupVarId(s_http_response_header.get());
if (id != kInvalidId) {
auto tvTo = frame_local(fp, id);
Variant varFrom(m_responseHeaders);
const auto tvFrom(varFrom.asTypedValue());
if (tvTo->m_type == KindOfRef) {
tvTo = tvTo->m_data.pref->tv();
}
tvDup(*tvFrom, *tvTo);
} else if ((fp->func()->attrs() & AttrMayUseVV) && fp->hasVarEnv()) {
fp->getVarEnv()->set(s_http_response_header.get(),
Variant(m_responseHeaders).asTypedValue());
}
/*
* If code == 0, Curl failed to connect; per PHP5, ignore_errors just means
* to not worry if we get an http resonse code that isn't between 200 and 400,
* but we shouldn't ignore other errors.
* all status codes in the 2xx range are defined by the specification as
* successful;
* all status codes in the 3xx range are for redirection, and so also should
* never fail.
*/
if ((code >= 200 && code < 400) || (m_ignoreErrors && code != 0)) {
setName(url.toCppString());
m_data = const_cast<char*>(m_response.data());
m_len = m_response.size();
return true;
} else {
m_error = http.getLastError().c_str();
return false;
}
}
开发者ID:DerPapst,项目名称:hhvm,代码行数:92,代码来源:url-file.cpp
示例6: apc_rfc1867_progress
int apc_rfc1867_progress(apc_rfc1867_data *rfc1867ApcData,
unsigned int event, void *event_data,
void **extra) {
switch (event) {
case MULTIPART_EVENT_START: {
multipart_event_start *data = (multipart_event_start *) event_data;
rfc1867ApcData->content_length = data->content_length;
rfc1867ApcData->tracking_key.clear();
rfc1867ApcData->name.clear();
rfc1867ApcData->cancel_upload = 0;
rfc1867ApcData->temp_filename = NULL;
rfc1867ApcData->start_time = my_time();
rfc1867ApcData->bytes_processed = 0;
rfc1867ApcData->prev_bytes_processed = 0;
rfc1867ApcData->rate = 0;
rfc1867ApcData->update_freq = RuntimeOption::Rfc1867Freq;
if (rfc1867ApcData->update_freq < 0) {
assert(false); // TODO: support percentage
// frequency is a percentage, not bytes
rfc1867ApcData->update_freq =
rfc1867ApcData->content_length * RuntimeOption::Rfc1867Freq / 100;
}
break;
}
case MULTIPART_EVENT_FORMDATA: {
multipart_event_formdata *data = (multipart_event_formdata *)event_data;
if (data->name &&
!strncasecmp(data->name, RuntimeOption::Rfc1867Name.c_str(),
RuntimeOption::Rfc1867Name.size()) &&
data->value && data->length &&
data->length < RFC1867_TRACKING_KEY_MAXLEN -
RuntimeOption::Rfc1867Prefix.size()) {
int len = RuntimeOption::Rfc1867Prefix.size();
if (len > RFC1867_TRACKING_KEY_MAXLEN) {
len = RFC1867_TRACKING_KEY_MAXLEN;
}
rfc1867ApcData->tracking_key =
string(RuntimeOption::Rfc1867Prefix.c_str(), len);
len = strlen(*data->value);
int rem = RFC1867_TRACKING_KEY_MAXLEN -
rfc1867ApcData->tracking_key.size();
if (len > rem) len = rem;
rfc1867ApcData->tracking_key +=
string(*data->value, len);
rfc1867ApcData->bytes_processed = data->post_bytes_processed;
}
/* Facebook: Temporary fix for a bug in PHP's rfc1867 code,
fixed here for convenience:
http://cvs.php.net/viewvc.cgi/php-src/main/
rfc1867.c?r1=1.173.2.1.2.11&r2=1.173.2.1.2.12 */
(*data->newlength) = data->length;
break;
}
case MULTIPART_EVENT_FILE_START:
if (!rfc1867ApcData->tracking_key.empty()) {
multipart_event_file_start *data =
(multipart_event_file_start *)event_data;
rfc1867ApcData->bytes_processed = data->post_bytes_processed;
int len = strlen(*data->filename);
if (len > RFC1867_FILENAME_MAXLEN) len = RFC1867_FILENAME_MAXLEN;
rfc1867ApcData->filename = string(*data->filename, len);
rfc1867ApcData->temp_filename = NULL;
len = strlen(data->name);
if (len > RFC1867_NAME_MAXLEN) len = RFC1867_NAME_MAXLEN;
rfc1867ApcData->name = string(data->name, len);
ArrayInit track(6);
track.set(s_total, rfc1867ApcData->content_length);
track.set(s_current, rfc1867ApcData->bytes_processed);
track.set(s_filename, rfc1867ApcData->filename);
track.set(s_name, rfc1867ApcData->name);
track.set(s_done, 0);
track.set(s_start_time, rfc1867ApcData->start_time);
f_apc_store(rfc1867ApcData->tracking_key, track.create(), 3600);
}
break;
case MULTIPART_EVENT_FILE_DATA:
if (!rfc1867ApcData->tracking_key.empty()) {
multipart_event_file_data *data =
(multipart_event_file_data *) event_data;
rfc1867ApcData->bytes_processed = data->post_bytes_processed;
if (rfc1867ApcData->bytes_processed -
rfc1867ApcData->prev_bytes_processed >
rfc1867ApcData->update_freq) {
Variant v;
if (s_apc_store[0].get(rfc1867ApcData->tracking_key, v)) {
if (v.is(KindOfArray)) {
ArrayInit track(6);
track.set(s_total, rfc1867ApcData->content_length);
track.set(s_current, rfc1867ApcData->bytes_processed);
track.set(s_filename, rfc1867ApcData->filename);
track.set(s_name, rfc1867ApcData->name);
track.set(s_done, 0);
track.set(s_start_time, rfc1867ApcData->start_time);
f_apc_store(rfc1867ApcData->tracking_key, track.create(), 3600);
}
//.........这里部分代码省略.........
开发者ID:TSMG1972,项目名称:hhvm,代码行数:101,代码来源:ext_apc.cpp
示例7: strdup
//.........这里部分代码省略.........
if (ch == '.') {
ch = format[++inpos];
if (isdigit((int)ch)) {
if ((precision = getnumber(format, &inpos)) < 0) {
free(result);
throw_invalid_argument("precision: must be greater than zero "
"and less than %d", INT_MAX);
return NULL;
}
ch = format[inpos];
adjusting |= ADJ_PRECISION;
expprec = 1;
} else {
precision = 0;
}
} else {
precision = 0;
}
} else {
width = precision = 0;
argnum = currarg++;
}
if (argnum > vargs.size()) {
free(result);
throw_invalid_argument("arguments: (too few)");
return NULL;
}
if (ch == 'l') {
ch = format[++inpos];
}
/* now we expect to find a type specifier */
Variant tmp = vargs[argnum-1];
switch (ch) {
case 's': {
String s = tmp.toString();
appendstring(&result, &outpos, &size, s,
width, precision, padding, alignment, s.size(),
0, expprec, 0);
break;
}
case 'd':
appendint(&result, &outpos, &size, tmp.toInt64(),
width, padding, alignment, always_sign);
break;
case 'u':
appenduint(&result, &outpos, &size, tmp.toInt64(),
width, padding, alignment);
break;
case 'g':
case 'G':
case 'e':
case 'E':
case 'f':
case 'F':
appenddouble(&result, &outpos, &size, tmp.toDouble(),
width, padding, alignment, precision, adjusting,
ch, always_sign);
break;
case 'c':
appendchar(&result, &outpos, &size, tmp.toByte());
break;
开发者ID:Jostein,项目名称:hiphop-php,代码行数:67,代码来源:zend_printf.cpp
示例8: IsValidKey
bool ArrayData::IsValidKey(const Variant& k) {
return k.isInteger() ||
(k.isString() && IsValidKey(k.getStringData()));
}
开发者ID:GokuMizuno,项目名称:hhvm,代码行数:4,代码来源:array-data.cpp
示例9: HHVM_METHOD
static Variant HHVM_METHOD(Memcache, get, const Variant& key,
VRefParam flags /*= null*/) {
auto data = Native::data<MemcacheData>(this_);
if (key.is(KindOfArray)) {
std::vector<const char *> real_keys;
std::vector<size_t> key_len;
Array keyArr = key.toArray();
real_keys.reserve(keyArr.size());
key_len.reserve(keyArr.size());
for (ArrayIter iter(keyArr); iter; ++iter) {
auto key = iter.second().toString();
String serializedKey = memcache_prepare_key(key);
real_keys.push_back(const_cast<char *>(serializedKey.c_str()));
key_len.push_back(iter.second().toString().length());
}
if (!real_keys.empty()) {
const char *payload = NULL;
size_t payload_len = 0;
uint32_t flags = 0;
const char *res_key = NULL;
size_t res_key_len = 0;
memcached_result_st result;
memcached_return_t ret = memcached_mget(&data->m_memcache, &real_keys[0],
&key_len[0], real_keys.size());
memcached_result_create(&data->m_memcache, &result);
Array return_val;
while ((memcached_fetch_result(&data->m_memcache, &result, &ret))
!= nullptr) {
if (ret != MEMCACHED_SUCCESS) {
// should probably notify about errors
continue;
}
payload = memcached_result_value(&result);
payload_len = memcached_result_length(&result);
flags = memcached_result_flags(&result);
res_key = memcached_result_key_value(&result);
res_key_len = memcached_result_key_length(&result);
return_val.set(String(res_key, res_key_len, CopyString),
memcache_fetch_from_storage(payload,
payload_len, flags));
}
memcached_result_free(&result);
return return_val;
}
} else {
char *payload = NULL;
size_t payload_len = 0;
uint32_t flags = 0;
memcached_return_t ret;
String serializedKey = memcache_prepare_key(key.toString());
if (serializedKey.length() == 0) {
return false;
}
payload = memcached_get(&data->m_memcache, serializedKey.c_str(),
serializedKey.length(), &payload_len, &flags, &ret);
/* This is for historical reasons from libmemcached*/
if (ret == MEMCACHED_END) {
ret = MEMCACHED_NOTFOUND;
}
if (ret == MEMCACHED_NOTFOUND) {
return false;
}
Variant retval = memcache_fetch_from_storage(payload, payload_len, flags);
free(payload);
return retval;
}
return false;
}
开发者ID:galtline,项目名称:hhvm,代码行数:84,代码来源:ext_memcache.cpp
示例10: lua_gettop
void LuaScriptInstance::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
{
if (attr.ptr_ != (void*)0xffffffff)
{
Serializable::OnSetAttribute(attr, src);
return;
}
if (scriptObjectRef_ == LUA_REFNIL)
return;
String name = attr.name_;
unsigned length = name.Length();
if (name.Back() == '_')
length -= 1;
int top = lua_gettop(luaState_);
String functionName = String("Set") + name.Substring(0, 1).ToUpper() + name.Substring(1, length - 1);
WeakPtr<LuaFunction> function = GetScriptObjectFunction(functionName);
// If set function exist
if (function)
{
if (function->BeginCall(this))
{
function->PushVariant(src);
function->EndCall();
}
}
else
{
lua_rawgeti(luaState_, LUA_REGISTRYINDEX, scriptObjectRef_);
lua_pushstring(luaState_, name.CString());
switch (attr.type_)
{
case VAR_BOOL:
lua_pushboolean(luaState_, src.GetBool());
break;
case VAR_FLOAT:
lua_pushnumber(luaState_, src.GetFloat());
break;
case VAR_STRING:
tolua_pushurho3dstring(luaState_, src.GetString());
break;
case VAR_VECTOR2:
tolua_pushusertype(luaState_, (void*)&(src.GetVector2()), "Vector2");
break;
case VAR_VECTOR3:
tolua_pushusertype(luaState_, (void*)&(src.GetVector3()), "Vector3");
break;
case VAR_VECTOR4:
tolua_pushusertype(luaState_, (void*)&(src.GetVector4()), "Vector4");
break;
case VAR_QUATERNION:
tolua_pushusertype(luaState_, (void*)&(src.GetQuaternion()), "Quaternion");
break;
case VAR_COLOR:
tolua_pushusertype(luaState_, (void*)&(src.GetColor()), "Color");
break;
case VAR_INTRECT:
tolua_pushusertype(luaState_, (void*)&(src.GetIntRect()), "IntRect");
break;
case VAR_INTVECTOR2:
tolua_pushusertype(luaState_, (void*)&(src.GetIntVector2()), "IntVector2");
break;
default:
LOGERROR("Unsupported data type");
lua_settop(luaState_, top);
return;
}
lua_settable(luaState_, -3);
}
lua_settop(luaState_, top);
}
开发者ID:1vanK,项目名称:Urho3DQuake2,代码行数:76,代码来源:LuaScriptInstance.cpp
示例11: HHVM_FUNCTION
Variant HHVM_FUNCTION(json_decode, const String& json, bool assoc /* = false */,
int64_t depth /* = 512 */, int64_t options /* = 0 */) {
json_set_last_error_code(json_error_codes::JSON_ERROR_NONE);
if (json.empty()) {
return init_null();
}
const int64_t supported_options =
k_JSON_FB_LOOSE |
k_JSON_FB_COLLECTIONS |
k_JSON_FB_STABLE_MAPS |
k_JSON_BIGINT_AS_STRING;
int64_t parser_options = options & supported_options;
Variant z;
if (JSON_parser(z, json.data(), json.size(), assoc, depth, parser_options)) {
return z;
}
String trimmed = HHVM_FN(trim)(json, "\t\n\r ");
if (trimmed.size() == 4) {
if (!strcasecmp(trimmed.data(), "null")) {
json_set_last_error_code(json_error_codes::JSON_ERROR_NONE);
return init_null();
}
if (!strcasecmp(trimmed.data(), "true")) {
json_set_last_error_code(json_error_codes::JSON_ERROR_NONE);
return true;
}
} else if (trimmed.size() == 5 && !strcasecmp(trimmed.data(), "false")) {
json_set_last_error_code(json_error_codes::JSON_ERROR_NONE);
return false;
}
int64_t p;
double d;
DataType type = json.get()->isNumericWithVal(p, d, 0);
if (type == KindOfInt64) {
json_set_last_error_code(json_error_codes::JSON_ERROR_NONE);
return p;
} else if (type == KindOfDouble) {
json_set_last_error_code(json_error_codes::JSON_ERROR_NONE);
if ((options & k_JSON_BIGINT_AS_STRING) &&
(json.toInt64() == LLONG_MAX || json.toInt64() == LLONG_MIN)
&& errno == ERANGE) { // Overflow
bool is_float = false;
for (int i = (trimmed[0] == '-' ? 1 : 0); i < trimmed.size(); ++i) {
if (trimmed[i] < '0' || trimmed[i] > '9') {
is_float = true;
break;
}
}
if (!is_float) {
return trimmed;
}
}
return d;
}
char ch0 = json.charAt(0);
if (json.size() > 1 && ch0 == '"' && json.charAt(json.size() - 1) == '"') {
json_set_last_error_code(json_error_codes::JSON_ERROR_NONE);
// Wrap the string in an array to allow the JSON_parser to handle
// things like unicode escape sequences, then unwrap to get result
String wrapped("[");
wrapped += json + "]";
// Stick to a normal hhvm array for the wrapper
const int64_t mask = ~(k_JSON_FB_COLLECTIONS | k_JSON_FB_STABLE_MAPS);
if (JSON_parser(z, wrapped.data(), wrapped.size(), false, depth,
parser_options & mask) && z.isArray()) {
Array arr = z.toArray();
if ((arr.size() == 1) && arr.exists(0)) {
return arr[0];
}
// The input string could be something like: "foo","bar"
// Which will parse inside the [] wrapper, but be invalid
json_set_last_error_code(json_error_codes::JSON_ERROR_SYNTAX);
}
}
if ((options & k_JSON_FB_LOOSE) && json.size() > 1 &&
ch0 == '\'' && json.charAt(json.size() - 1) == '\'') {
json_set_last_error_code(json_error_codes::JSON_ERROR_NONE);
return json.substr(1, json.size() - 2);
}
assert(json_get_last_error_code() != json_error_codes::JSON_ERROR_NONE);
return init_null();
}
开发者ID:anthonyattard,项目名称:hhvm,代码行数:92,代码来源:ext_json.cpp
示例12: url
bool_t BtcChinaBtcCny::process(Callback& callback)
{
if(!callback.receivedTime(Time::time()))
return false;
HttpRequest httpRequest;
Buffer data;
String dataStr;
for(;; Thread::sleep(14000))
{
String url("https://data.btcchina.com/data/historydata");
if(lastTradeId != 0)
url.printf("https://data.btcchina.com/data/historydata?since=%llu", lastTradeId);
if(!httpRequest.get(url, data))
{
error = httpRequest.getErrorString();
open = false;
return false;
}
timestamp_t localTime = Time::time();
dataStr.attach((const char_t*)(byte_t*)data, data.size());
Variant dataVar;
if(!Json::parse(dataStr, dataVar))
{
error = "Could not parse trade data.";
open = false;
return false;
}
const List<Variant>& tradesList = dataVar.toList();
if(!tradesList.isEmpty())
{
const HashMap<String, Variant>& tradeData = tradesList.back().toMap();
timestamp_t serverTime = tradeData.find("date")->toInt64() * 1000LL;
timestamp_t offset = serverTime - localTime;
if(offset < timeOffset || !timeOffsetSet)
{
timeOffset = offset;
timeOffsetSet = true;
if(!callback.receivedTime(serverTime))
return false;
}
}
Trade trade;
for(List<Variant>::Iterator i = tradesList.begin(), end = tradesList.end(); i != end; ++i)
{
const HashMap<String, Variant>& tradeData = i->toMap();
trade.id = tradeData.find("tid")->toInt64();
trade.time = tradeData.find("date")->toInt64() * 1000LL;
trade.price = tradeData.find("price")->toDouble();
trade.amount = tradeData.find("amount")->toDouble();
trade.flags = 0;
if(trade.id > lastTradeId)
{
if(!callback.receivedTrade(trade))
return false;
lastTradeId = trade.id;
}
}
}
return false; // unreachable
}
开发者ID:donpillou,项目名称:MegucoData,代码行数:65,代码来源:BtcChinaBtcCny.cpp
示例13: _property_changed
void ScriptEditorDebugger::_property_changed(Object*p_base,const StringName& p_property,const Variant& p_value){
if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
return;
Node *node = p_base->cast_to<Node>();
if (node) {
NodePath path = editor->get_edited_scene()->get_path_to(node);
int pathid = _get_node_path_cache(path);
if (p_value.is_ref()) {
Ref<Resource> res = p_value;
if (res.is_valid() && res->get_path()!=String()) {
Array msg;
msg.push_back("live_node_prop_res");
msg.push_back(pathid);
msg.push_back(p_property);
msg.push_back(res->get_path());
ppeer->put_var(msg);
}
} else {
Array msg;
msg.push_back("live_node_prop");
msg.push_back(pathid);
msg.push_back(p_property);
msg.push_back(p_value);
ppeer->put_var(msg);
}
return;
}
Resource *res = p_base->cast_to<Resource>();
if (res && res->get_path()!=String()) {
String respath = res->get_path();
int pathid = _get_res_path_cache(respath);
if (p_value.is_ref()) {
Ref<Resource> res = p_value;
if (res.is_valid() && res->get_path()!=String()) {
Array msg;
msg.push_back("live_res_prop_res");
msg.push_back(pathid);
msg.push_back(p_property);
msg.push_back(res->get_path());
ppeer->put_var(msg);
}
} else {
Array msg;
msg.push_back("live_res_prop");
msg.push_back(pathid);
msg.push_back(p_property);
msg.push_back(p_value);
ppeer->put_var(msg);
}
return;
}
//print_line("prop");
}
开发者ID:Ragar0ck,项目名称:godot,代码行数:75,代码来源:script_editor_debugger.cpp
示例14: switch
void ScriptEditorDebugger::_notification(int p_what) {
switch(p_what) {
case NOTIFICATION_ENTER_TREE: {
step->set_icon( get_icon("DebugStep","EditorIcons"));
next->set_icon( get_icon("DebugNext","EditorIcons"));
back->set_icon( get_icon("Back","EditorIcons"));
forward->set_icon( get_icon("Forward","EditorIcons"));
dobreak->set_icon( get_icon("Pause","EditorIcons"));
docontinue->set_icon( get_icon("DebugContinue","EditorIcons"));
tb->set_normal_texture( get_icon("Close","EditorIcons"));
tb->set_hover_texture( get_icon("CloseHover","EditorIcons"));
tb->set_pressed_texture( get_icon("Close","EditorIcons"));
scene_tree_refresh->set_icon( get_icon("Reload","EditorIcons"));
le_set->connect("pressed",this,"_live_edit_set");
le_clear->connect("pressed",this,"_live_edit_clear");
error_list->connect("item_selected",this,"_error_selected");
error_stack->connect("item_selected",this,"_error_stack_selected");
vmem_refresh->set_icon( get_icon("Reload","EditorIcons"));
} break;
case NOTIFICATION_PROCESS: {
if (error_count!=last_error_count) {
if (error_count==0) {
error_split->set_name("Errors");
} else {
error_split->set_name("Errors ("+itos(error_count)+")");
}
last_error_count=error_count;
}
if (connection.is_null()) {
if (server->is_connection_available()) {
connection = server->take_connection();
if (connection.is_null())
break;
EditorNode::get_log()->add_message("** Debug Process Started **");
log_forced_visible=false;
ppeer->set_stream_peer(connection);
show();
dobreak->set_disabled(false);
tabs->set_current_tab(0);
emit_signal("show_debugger",true);
reason->set_text("Child Process Connected");
reason->set_tooltip("Child Process Connected");
scene_tree->clear();
le_set->set_disabled(true);
le_clear->set_disabled(false);
error_list->clear();
error_stack->clear();
error_count=0;
//live_edit_root->set_text("/root");
update_live_edit_root();
} else {
break;
}
};
if (!connection->is_connected()) {
stop();
editor->notify_child_process_exited(); //somehow, exited
break;
};
if (ppeer->get_available_packet_count() <= 0) {
break;
};
while(ppeer->get_available_packet_count() > 0) {
if (pending_in_queue) {
int todo = MIN( ppeer->get_available_packet_count(), pending_in_queue );
for(int i=0;i<todo;i++) {
Variant cmd;
Error ret = ppeer->get_var(cmd);
if (ret!=OK) {
stop();
ERR_FAIL_COND(ret!=OK);
}
message.push_back(cmd);
pending_in_queue--;
}
//.........这里部分代码省略.........
开发者ID:Ragar0ck,项目名称:godot,代码行数:101,代码来源:script_editor_debugger.cpp
示例15: ASSERT
bool TestServer::VerifyServerResponse(const char *input, const char *output,
const char *url, const char *method,
const char *header, const char *postdata,
bool responseHeader,
const char *file /* = "" */,
int line /* = 0 */) {
ASSERT(input);
if (!CleanUp()) return false;
if (Option::EnableEval < Option::FullEval) {
if (!GenerateFiles(input, "TestServer") || !CompileFiles()) {
return false;
}
} else {
string fullPath = "/unittest/rootdoc/string";
ofstream f(fullPath.c_str());
if (!f) {
printf("Unable to open %s for write. Run this test from src/.\n",
fullPath.c_str());
return false;
}
f << input;
f.close();
}
AsyncFunc<TestServer> func(this, &TestServer::RunServer);
func.start();
String server = "http://";
server += f_php_uname("n");
server += ":8080/";
server += url;
string actual, err;
for (int i = 0; i < 10; i++) {
Variant c = f_curl_init();
f_curl_setopt(c, k_CURLOPT_URL, server);
f_curl_setopt(c, k_CURLOPT_RETURNTRANSFER, true);
if (postdata) {
f_curl_setopt(c, k_CURLOPT_POSTFIELDS, postdata);
f_curl_setopt(c, k_CURLOPT_POST, true);
}
if (header) {
f_curl_setopt(c, k_CURLOPT_HTTPHEADER, CREATE_VECTOR1(header));
}
if (responseHeader) {
f_curl_setopt(c, k_CURLOPT_HEADER, 1);
}
Variant res = f_curl_exec(c);
if (!same(res, false)) {
actual = res.toString();
break;
}
sleep(1); // wait until HTTP server is up and running
}
AsyncFunc<TestServer>(this, &TestServer::StopServer).run();
func.waitForEnd();
bool passed = (actual == output);
if (responseHeader) {
passed = (actual.find(output) != string::npos);
}
if (!passed) {
printf("%s:%d\nParsing: [%s]\nBet %d:\n"
"--------------------------------------\n"
"%s"
"--------------------------------------\n"
"Got %d:\n"
"--------------------------------------\n"
"%s"
"--------------------------------------\n",
file, line, input, (int)strlen(output), output,
(int)actual.length(), actual.c_str());
return false;
}
return true;
}
开发者ID:scottmac,项目名称:hiphop-dev,代码行数:80,代码来源:test_server.cpp
示例16: CreateOleObject
//---------------------------------------------------------------------------
void __fastcall TXFTJALLExportThread::Execute()
{
//---- Place thread code here ----
ValidEXBTN->Enabled = false;
ValidPreBTN->Enabled = false;
ValidEBTN->Enabled = false;
ValidQBTN->Enabled = false;
Variant ExcelApp;
try
{
ExcelApp = CreateOleObject("Excel.Application");
}
catch(...)
{
MessageBox(XFTJQFrm->Handle, "错误:您的系统中可能没有安装Excel!", "Error in launch Excel!", MB_OK|MB_ICONERROR);
ValidEXBTN->Enabled = true;
ValidPreBTN->Enabled = true;
ValidEBTN->Enabled = true;
return;
}
ValidQuery->Open();
String DTX = "";
String path = GlobalPath;
String Templatepath;
ValidQuery->First();
int allrecord = ValidQuery->RecordCount;
for(int i = 0; i <65531; i++)
{
DTX += ValidQuery->FieldByName("qdate")->AsAnsiString.Trim();
DTX += "\t";
DTX += ValidQuery->FieldByName("ZSFZE")->AsAnsiString.Trim();
DTX += "\t";
DTX += ValidQuery->FieldByName("ZSFCS")->AsAnsiString.Trim();
DTX += "\t";
DTX += ValidQuery->FieldByName("BFSFZE")->AsAnsiString.Trim();
DTX += "\t";
DTX += ValidQuery->FieldByName("BFCS")->AsAnsiString.Trim();
DTX += "\t";
DTX += ValidQuery->FieldByName("LHSFZE")->AsAnsiString.Trim();
DTX += "\t";
DTX += ValidQuery->FieldByName("LHCS")->AsAnsiString.Trim();
DTX += "\t";
DTX += ValidQuery->FieldByName("SUSFZE")->AsAnsiString.Trim();
DTX += "\t";
DTX += ValidQuery->FieldByName("SUCS")->AsAnsiString.Trim();
DTX += "\t";
DTX += ValidQuery->FieldByName("NTSFZE")->AsAnsiString.Trim();
DTX += "\t";
DTX += ValidQuery->FieldByName("NTCS")->AsAnsiString.Trim();
DTX += "\n";
Validprogress->Position = i*100/allrecord;
ValidQuery->Next();
if(ValidQuery->Eof)
break;
}
Templatepath = path + "\\ExportXLSTemplate\\XFTJALLMXTemplate.xlt";
ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
Variant WB = ExcelApp.OlePropertyGet("ActiveWorkBook");
Variant ST = WB.OlePropertyGet("Sheets", 1);
ST.OlePropertyGet("Cells",2,2).OlePropertySet("Value", ValidBHStr.t_str());
ST.OlePropertyGet("Cells",2,5).OlePropertySet("Value", ValidBMStr.t_str());
ST.OlePropertyGet("Cells",2,9).OlePropertySet("Value", ValidBeginDatestr.t_str());
ST.OlePropertyGet("Cells",3,2).OlePropertySet("Value", ValidCZYStr.t_str());
ST.OlePropertyGet("Cells",3,5).OlePropertySet("Value", DateTimeToStr(Now()).t_str());
ST.OlePropertyGet("Cells",3,9).OlePropertySet("Value", ValidEndDatestr.t_str());
ST.OlePropertyGet("Cells",5,2).OlePropertySet("Value", ValidZZE.t_str());
ST.OlePropertyGet("Cells",6,2).OlePropertySet("Value", ValidZZCS.t_str());
ST.OlePropertyGet("Cells",5,4).OlePropertySet("Value", ValidBZE.t_str());
ST.OlePropertyGet("Cells",6,4).OlePropertySet("Value", ValidBZCS.t_str());
ST.OlePropertyGet("Cells",5,6).OlePropertySet("Value", ValidLZE.t_str());
ST.OlePropertyGet("Cells",6,6).OlePropertySet("Value", ValidLZCS.t_str());
ST.OlePropertyGet("Cells",5,8).OlePropertySet("Value", ValidSZE.t_str());
ST.OlePropertyGet("Cells",6,8).OlePropertySet("Value", ValidSZCS.t_str());
ST.OlePropertyGet("Cells",5,10).OlePropertySet("Value", ValidNZE.t_str());
ST.OlePropertyGet("Cells",6,10).OlePropertySet("Value", ValidNZCS.t_str());
Variant RE = ST.OlePropertyGet("Range", "A9").OleFunction("Select");
Clipboard()->Clear();
Clipboard()->SetTextBuf(DTX.c_str());
ST.OleFunction("Paste");
Clipboard()->Clear();
ExcelApp.OlePropertyGet("Columns").OleFunction("AutoFit");
WB.OleFunction("SaveAs", Validsavepath.t_str());
ExcelApp.OleFunction("Quit");
ExcelApp = Unassigned;
Validprogress->Position = 100;
MessageBox(XFTJQFrm->Handle, "数据已完成导出!", "Successfully!", MB_OK|MB_ICONINFORMATION);
ValidEXBTN->Enabled = true;
//.........这里部分代码省略.........
开发者ID:jackyrouse,项目名称:IC2Water,代码行数:101,代码来源:XFTJALLExportThread.cpp
|
请发表评论