array<String^>^ Manager::runSort(int setSizeModifier) { array<int>^ originalSet = af->MakeArray(setSizeModifier); String^ orginalSetStr = arrayToString(originalSet); array<int>^ sortedSet = sortMethod(originalSet); String^ sortedSetStr = arrayToString(sortedSet); array<String^>^ result = { orginalSetStr, sortedSetStr }; return result; }
std::string Util::arrayToString(std::vector<Element> ary) { std::ostringstream os; for (int i = 0; i < ary.size(); i++) { switch (ary[i].type) { case Global::_number: os << *(double *)(ary[i].data); if (i != ary.size() - 1) os << ", "; break; case Global::_boolean: os << *(bool *)(ary[i].data); if (i != ary.size() - 1) os << ", "; break; case Global::_string: os << *(string *)(ary[i].data); if (i != ary.size() - 1) os << ", "; break; case Global::_array: os << "["; os << arrayToString(*(vector<Element> *)ary[i].data); os << "]"; if (i != ary.size() - 1) os << ", "; break; } } return os.str(); }
FB::variant hapticAPI::getPosition() { if (initialized){ hdPhantomGetPosition(deviceID, &position[0],&position[1],&position[2]); double buf[3]; if (strcmp(context.c_str(),"2d")==0){ buf[0] = position[1]+0.1+offsetX; buf[1] = -(position[2]-0.1)+offsetY; buf[2] = position[0]; double x = (buf[0]/pixelWidth); double y = (buf[1]/pixelWidth); mouseRenderPosition(x,y); if (leftButton()) mouseRenderLeftButton(); } else{ buf[0] = position[1]; buf[1] = -position[2]; buf[2] = -position[0]; } std::string pos = arrayToString(buf); return pos; } return NotInitializedString; }
/* * Cast operands as required for invokeArrayOperator */ static EjsVar *coerceArrayOperands(Ejs *ejs, EjsVar *lhs, int opcode, EjsVar *rhs) { switch (opcode) { /* * Binary operators */ case EJS_OP_ADD: return ejsInvokeOperator(ejs, arrayToString(ejs, (EjsArray*) lhs, 0, 0), opcode, rhs); case EJS_OP_AND: case EJS_OP_DIV: case EJS_OP_MUL: case EJS_OP_OR: case EJS_OP_REM: case EJS_OP_SHL: case EJS_OP_SHR: case EJS_OP_SUB: case EJS_OP_USHR: case EJS_OP_XOR: return ejsInvokeOperator(ejs, (EjsVar*) ejs->zeroValue, opcode, rhs); case EJS_OP_COMPARE_EQ: case EJS_OP_COMPARE_NE: if (ejsIsNull(rhs) || ejsIsUndefined(rhs)) { return (EjsVar*) ((opcode == EJS_OP_COMPARE_EQ) ? ejs->falseValue: ejs->trueValue); } else if (ejsIsNumber(rhs)) { return ejsInvokeOperator(ejs, (EjsVar*) ejsToNumber(ejs, lhs), opcode, rhs); } return ejsInvokeOperator(ejs, (EjsVar*) ejsToString(ejs, lhs), opcode, rhs); case EJS_OP_COMPARE_LE: case EJS_OP_COMPARE_LT: case EJS_OP_COMPARE_GE: case EJS_OP_COMPARE_GT: if (ejsIsNumber(rhs)) { return ejsInvokeOperator(ejs, (EjsVar*) ejsToNumber(ejs, lhs), opcode, rhs); } return ejsInvokeOperator(ejs, (EjsVar*) ejsToString(ejs, lhs), opcode, rhs); case EJS_OP_COMPARE_STRICTLY_NE: case EJS_OP_COMPARE_UNDEFINED: case EJS_OP_COMPARE_NOT_ZERO: case EJS_OP_COMPARE_NULL: return (EjsVar*) ejs->trueValue; case EJS_OP_COMPARE_STRICTLY_EQ: case EJS_OP_COMPARE_FALSE: case EJS_OP_COMPARE_TRUE: case EJS_OP_COMPARE_ZERO: return (EjsVar*) ejs->falseValue; /* * Unary operators */ case EJS_OP_LOGICAL_NOT: case EJS_OP_NOT: case EJS_OP_NEG: return 0; default: ejsThrowTypeError(ejs, "Opcode %d not valid for type %s", opcode, lhs->type->qname.name); return ejs->undefinedValue; } return 0; }
/* Cast operands as required for invokeArrayOperator */ static EjsObj *coerceArrayOperands(Ejs *ejs, EjsObj *lhs, int opcode, EjsObj *rhs) { switch (opcode) { /* Binary operators */ case EJS_OP_ADD: return ejsInvokeOperator(ejs, arrayToString(ejs, (EjsArray*) lhs, 0, 0), opcode, rhs); case EJS_OP_AND: case EJS_OP_DIV: case EJS_OP_MUL: case EJS_OP_OR: case EJS_OP_REM: case EJS_OP_SHL: case EJS_OP_SHR: case EJS_OP_SUB: case EJS_OP_USHR: case EJS_OP_XOR: return ejsInvokeOperator(ejs, ESV(zero), opcode, rhs); case EJS_OP_COMPARE_EQ: case EJS_OP_COMPARE_NE: if (!ejsIsDefined(ejs, rhs)) { return ((opcode == EJS_OP_COMPARE_EQ) ? ESV(false): ESV(true)); } else if (ejsIs(ejs, rhs, Number)) { return ejsInvokeOperator(ejs, ejsToNumber(ejs, lhs), opcode, rhs); } return ejsInvokeOperator(ejs, ejsToString(ejs, lhs), opcode, rhs); case EJS_OP_COMPARE_LE: case EJS_OP_COMPARE_LT: case EJS_OP_COMPARE_GE: case EJS_OP_COMPARE_GT: if (ejsIs(ejs, rhs, Number)) { return ejsInvokeOperator(ejs, ejsToNumber(ejs, lhs), opcode, rhs); } return ejsInvokeOperator(ejs, ejsToString(ejs, lhs), opcode, rhs); case EJS_OP_COMPARE_STRICTLY_NE: case EJS_OP_COMPARE_UNDEFINED: case EJS_OP_COMPARE_NOT_ZERO: case EJS_OP_COMPARE_NULL: return ESV(true); case EJS_OP_COMPARE_STRICTLY_EQ: case EJS_OP_COMPARE_FALSE: case EJS_OP_COMPARE_TRUE: case EJS_OP_COMPARE_ZERO: return ESV(false); /* Unary operators */ case EJS_OP_LOGICAL_NOT: case EJS_OP_NOT: case EJS_OP_NEG: return 0; default: ejsThrowTypeError(ejs, "Opcode %d not valid for type %@", opcode, TYPE(lhs)->qname.name); return ESV(undefined); } }
static EjsVar *castArray(Ejs *ejs, EjsArray *vp, EjsType *type) { switch (type->id) { case ES_Boolean: return (EjsVar*) ejs->trueValue; case ES_Number: return (EjsVar*) ejs->zeroValue; case ES_String: return arrayToString(ejs, vp, 0, 0); default: ejsThrowTypeError(ejs, "Can't cast to this type"); return 0; } }
/* Cast the object operand to a primitive type */ static EjsAny *castArray(Ejs *ejs, EjsArray *vp, EjsType *type) { switch (type->sid) { case ES_Boolean: return ESV(true); case ES_Number: return ESV(zero); case ES_String: return arrayToString(ejs, vp, 0, 0); default: ejsThrowTypeError(ejs, "Cannot cast to this type"); return 0; } }
void FinanceMgr::testClick(){ #if 0 DepMgrUi ui(this); ui.show(); Database* mysql = new QMySql; bool ok = mysql->connect("127.0.0.1", 3306, "gdf", "root", ""); if (ok) { QMessageBox::about(this, tr("FinaceMgr"), tr("connect ok")); } Array x; x["money_direction"] = "D"; x["title_code"] = "fadf3344"; x["title_description"] = "中文测试"; //mysql->insert("subtitle", x); //return; Database_Result& dr = mysql->query("SELECT * FROM subtitle WHERE id > 3"); //Database_Result& dr = mysql->from("subtitle")->where("id > 3")->limit("1")->get(); Array values; values["money_direction"] = "F"; values["title_code"] = "vu"; Array wheres; wheres["id"] = "3"; bool bok = mysql->update("subtitle", values, wheres); mysql->del("subtitle", wheres); if ( (!dr.isValid()) || !dr.hasRecord()) { QMessageBox::about(this, tr("FinaceMgr"), tr("query error:%1").arg(dr.errorMsg().c_str())); return; } ResultArray& rAry = dr.resultArray(); foreach(Array ary, rAry) { QMessageBox::about(NULL, "test click", arrayToString(ary).c_str()); }
FB::variant hapticAPI::getWorkspaceSize() { std::string pos=arrayToString(workspaceSize); return pos; }
/* Convert the array to a single localized string each member of the array has toString called on it and the resulting strings are concatenated. Currently just calls toString. function toLocaleString(): String */ static EjsString *toLocaleString(Ejs *ejs, EjsArray *ap, int argc, EjsObj **argv) { return arrayToString(ejs, ap, argc, argv); }