/*** MyOpen will open a file like fopen(...,"r") with regard to the ude *** *** configuration search paths. the file will be passed through the c *** *** preprocessor if available. *** *** TO CHECK FOR A PREPROCESSOR CheckCPP MUST BE RUN BEFORE THE FIRST *** *** CALL OF MyOpen!!! ***/ FILE *MyOpen(char *name, char *ppopts) { int files[2]; pid_t pid; FILE *r; char *temp = NULL; struct stat stats; #define str3(T, A, B, C) if(T) free(T); T = MyCalloc(1 + strlen(A) + strlen(B) + strlen(C), sizeof(char)); sprintf(T, "%s%s%s", A, B, C) str3(temp, TheScreen.Home, "/.ude/config/", name); if(stat(temp,&stats)){ str3(temp, TheScreen.udedir, "config/", name); if(stat(temp,&stats)) { str3(temp, name, "", ""); if(stat(temp,&stats)){ fprintf(TheScreen.errout, "UWM: file not found: %s.\n", name); return(NULL); } } } #undef str3 if(!TheScreen.cppcall) return(fopen(temp, "r")); pipe(files); if(!(pid = fork())) { /* Child Process */ char *temp2; close(files[0]); fclose(stdout); if(STDOUT_FILENO != fcntl(files[1], F_DUPFD, STDOUT_FILENO)) exit(-1); close(files[1]); if(-1==fcntl(STDOUT_FILENO,F_SETFD,0)) exit(-1); if(!(temp2 = malloc(sizeof(char) * (strlen(TheScreen.cppcall) + strlen(ppopts) + strlen(temp) + 10)))) exit(-1); sprintf(temp2,"%s %s - < %s", TheScreen.cppcall, ppopts, temp); execl("/bin/sh","/bin/sh","-c",temp2,NULL); fprintf(TheScreen.errout,"UWM: couldn't start /bin/sh\n"); exit(-1); } free(temp); close(files[1]); if(!(r=fdopen(files[0], "r"))) { close(files[0]); return(NULL); } if(pid < 0) { fclose(r); return(NULL); } return(r); }
pilo::i32_t functional_test_constructor_3_char(void* param) { M_UNUSED(param); const char* str = "1234567890"; size_t len = pilo::core::string::string_util::length(str); pilo::core::string::fixed_astring<32> str0(str, len); pilo::core::string::fixed_astring<64> str1(str0); if (str0.size() != str1.length()) { return -1; } if (::memcmp(str0.c_str(), str1.c_str(), (len + 1)*sizeof(char)) != 0) { return -2; } const char* cstr2 = "012345678901234567890123456789"; len = pilo::core::string::string_util::length(cstr2); pilo::core::string::fixed_astring<112> str2(cstr2); pilo::core::string::fixed_astring<32> str3(str2); if (str3.size() != len) { return -3; } if (::memcmp(str3.c_str(), str2.c_str(), (len + 1) * sizeof(char)) != 0) { return -4; } return 0; }
void Interpolate_inside(std::stringstream& ss, std::string ln){ std::string str2 ("%"); std::size_t found=-1; std::string res(""); do{ found = ln.find(str2, found+1); if(found==std::string::npos){ break; } if(found == 0){ throwException(); } if(ln.at(found-1)!='\\'){ throwException(); } }while(true); res += ln; std::string str3 ("\\%"); std::size_t found2 = -1; do{ found2 = res.find(str3, found2+1); if(found2==std::string::npos){ break; } res.replace(found2, 2, std::string("%")); found2 --; }while(true); ss << res; }
int main() { std::cout<< "hello, this is mystring plugin" << std::endl; MyString str0("AAA"); std::cout << "str0="<< str0 << std::endl; MyString str1(NULL); std::cout << "str1="<< str1 << std::endl; //MyString str2; // compile error, cause lacking of default constructor //std::cout << "str2="<< str2 << std::endl; str0 += "BBB"; std::cout << "str0="<< str0 << std::endl; MyString str3("CCC"); str0 += str3; std::cout << "str0="<< str0 << std::endl; MyString str4("DDD"); MyString str5("DDD"); std::cout << "str4==str5:"<< ((str4==str5)? "true":"false") << std::endl; std::vector<MyString> vec; vec.push_back(MyString("aaa")); vec.push_back(MyString("bbb")); std::cout << "vec:"<< vec[0] << ", " << vec[1] << std::endl; return 0; }
void DebugStrUnitTest() { struct strTests { wchar_t szTest[100], szCmp[100]; } Tests[] = { {L"Line1\n#Comment1\nLine2\r\n#Comment2\r\nEnd of file", L"Line1\nLine2\r\nEnd of file"}, {L"Line1\n#Comment1\r\n", L"Line1\n"} }; int iCmp; for (INT_PTR i = 0; i < countof(Tests); i++) { StripLines(Tests[i].szTest, L"#"); iCmp = wcscmp(Tests[i].szTest, Tests[i].szCmp); _ASSERTE(iCmp == 0); StripLines(Tests[i].szTest, L"#"); iCmp = wcscmp(Tests[i].szTest, Tests[i].szCmp); _ASSERTE(iCmp == 0); } // Some compilation and operators check CEStr str1; LPCWSTR pszTest = Tests[0].szTest; { str1 = lstrdup(pszTest); } iCmp = lstrcmp(str1, pszTest); _ASSERTE(iCmp == 0); { CEStr str2(lstrdup(pszTest)); wchar_t* pszDup = lstrdup(pszTest); iCmp = lstrcmp(str2, pszTest); _ASSERTE(iCmp == 0 && str2.ms_Arg && str2.ms_Arg != pszTest); } // The following block must to be able to compile #if 0 { CEStr str3(pszDup); str3 = pszTest; } { CEStr str4; str4 = pszTest; iCmp = lstrcmp(str4, pszTest); _ASSERTE(iCmp == 0 && str4.ms_Arg && str4.ms_Arg != pszTest); } { CEStr str5; str5 = str1; iCmp = lstrcmp(str5, pszTest); _ASSERTE(iCmp == 0 && str5.ms_Arg && str3.ms_Arg != str1.ms_Arg); } #endif iCmp = lstrcmp(str1, pszTest); _ASSERTE(iCmp == 0); }
bool OTTransactionType::VerifyContractID() { //m_AcctID contains the number we read from the xml file //we can compare it to the existing and actual identifier. // m_AcctID contains the "IDENTIFIER" of the object, according to the xml file. // // Meanwhile m_ID contains the same identifier, except it was generated. // // Now let's compare the two and make sure they match... // Also, for this class, we compare ServerID as well. They go hand in hand. if ((m_ID != m_AcctID) || (m_ServerID != m_AcctServerID)) { OTString str1(m_ID), str2(m_AcctID), str3(m_ServerID), str4(m_AcctServerID); OTLog::vError("Identifiers do NOT match in OTTransactionType::VerifyContractID.\n" "m_ID: %s\n m_AcctID: %s\n m_ServerID: %s\n m_AcctServerID: %s\n", str1.Get(), str2.Get(), str3.Get(), str4.Get()); // OT_FAIL; // I was debugging. return false; } else { // OTString str1(m_AcctID), str2(m_AcctServerID); // OTLog::vError("Expected Account ID and Server ID both *SUCCESSFUL* match to " // "IDs in the xml:\n Account ID:\n%s\n ServerID:\n%s\n" // "-----------------------------------------------------------------------------\n", // str1.Get(), str2.Get()); return true; } }
void TestW() { std::wstring str1 = L"abc\0def"; // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal std::wstring str2 = L"\0"; // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal std::wstring str3(L"\0"); // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal std::wstring str4{L"\x00\x01\x02\x03"}; // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal }
void Interpolate_inside(std::stringstream& ss, const std::string ln, First& arg, Strings&... rest){ if(isffr(arg)){ ss << arg; Interpolate_inside(ss, ln, rest...); return; } std::string str2 ("%"); std::size_t found=-1; std::string res(""); do{ found = ln.find(str2, found+1); if(found==std::string::npos){ if(isManipulators(arg)){ ss << ln; ss << arg; Interpolate_inside(ss, ln, rest...); return; } else { throwException(); } } if(found == 0){ break; } if(ln.at(found-1)!='\\'){ break; } }while(true); res += ln.substr(0, found); std::string str3 ("\\%"); std::size_t found2 = -1; do{ found2 = res.find(str3, found2+1); if(found2==std::string::npos){ break; } res.replace(found2, 2, std::string("%")); found2 --; }while(true); ss << res; if(isManipulators(arg)){ ss << arg; std::string restStr = ln.substr(found); Interpolate_inside(ss, restStr, rest...); } else{ ss << arg; std::string restStr = ln.substr(found+1); res += ss.str(); Interpolate_inside(ss, restStr, rest...); } }
char *MyOpen(char *name) { char *temp = NULL; struct stat stats; #define str3(T, A, B, C) if(T) free(T); T = MyCalloc(1 + strlen(A) + strlen(B) + strlen(C), sizeof(char)); sprintf(T, "%s%s%s", A, B, C) str3(temp, home, "/.ude/config/", name); if(stat(temp,&stats)){ str3(temp, udedir, "config/", name); if(stat(temp,&stats)) { str3(temp, name, "", ""); if(stat(temp,&stats)){ return(NULL); } } } #undef str3 return temp; }
void exercise2(){ bool failed = false; Xstr str1("1c0111001f010100061a024b53535009181c", Xstr::HEX_ENCODED); Xstr str2("686974207468652062756c6c277320657965", Xstr::HEX_ENCODED); Xstr str3("746865206b696420646f6e277420706c6179", Xstr::HEX_ENCODED); if((str1 ^ str2) != str3) failed = true; eval2: crypto_exercise_test(2, !failed); }
TEST( String, normal, off ) { const char* str = "THIS::IS::A::TEST"; { ex::string_t str1; ex::string_t str2(""); ex::string_t str3(""); CHECK( str1 == ex::string_t::null ); CHECK( str2 == str3 ); CHECK( str1 == str2 ); } { ex::string_t str1(str); ex::string_t str2 = str1.left( str1.findFirstOf("::") ); ex::string_t str3 = str1.right( str1.findFirstOf("::")+strlen("::") ); printf ("str1: %s\n", str1.c_str()); printf ("str2: %s\n", str2.c_str()); printf ("str3: %s\n", str3.c_str()); } { ex::string_t str1(str); ex::string_t str2(str, 3); const char* str_1 = str1.c_str(); const char* str_2 = str2.c_str(); printf ("str_1: %d", ex::str::len(str_1)); printf ("str_2: %d", ex::str::len(str_2)); char str_3[1024]; ex::mem::set( str_3, 1, sizeof(char)*1024 ); ex::str::ncpy( str_3, 1024, str, ex::str::len(str)+1 ); printf ("str_1: %s", str_1); printf ("str_2: %s", str_2); printf ("str_3: %s", str_3); } { char test[5] = { 'h', 'e', 'l', 'l', 'o' }; const char* test2 = "hello"; printf ( "len:%d, str:%s\n", ex::str::len(test2), test2 ); ex::string_t strTest ( test, 5 ); printf ( "len:%d, str:%s\n", strTest.size(), strTest.c_str() ); } }
int CTest::test_caseInsensitiveButCasePreserving(int argc, char* argv[]) { AutoPtr<IRawHeaders> h; CRawHeaders::New((IRawHeaders**)&h); String str0("Content-Type"); String str1("text/plain"); h->Add(str0, str1); // Case-insensitive: String strOut; h->Get(str0, &strOut); Boolean flag = strOut.Equals(str1); assert(flag == TRUE); String str2("Content-type"); h->Get(str2, &strOut); flag = strOut.Equals(str1); assert(flag == TRUE); String str3("content-type"); h->Get(str3, &strOut); flag = strOut.Equals(str1); assert(flag == TRUE); String str4("CONTENT-TYPE"); h->Get(str4, &strOut); flag = strOut.Equals(str1); assert(flag == TRUE); // ...but case-preserving: AutoPtr<IMap> innerMap; h->ToMultimap((IMap**)&innerMap); AutoPtr<ISet> keyset; innerMap->KeySet((ISet**)&keyset); AutoPtr<ArrayOf<IInterface*> > array; keyset->ToArray((ArrayOf<IInterface*>**)&array); AutoPtr<ICharSequence> cs = (ICharSequence*)ICharSequence::Probe((*array)[0]); String str5(String("Content-Type")); cs->ToString(&strOut); flag = strOut.Equals(str5); assert(flag == TRUE); // We differ from the RI in that the Map we return is also case-insensitive. // Our behavior seems more consistent. (And code that works on the RI will work on Android.) // AutoPtr<ICharSequence> cs1; // CString::New(String("Content-Type"), (ICharSequence**)&cs1); // AutoPtr<IInterface> value; // innerMap->Get(cs1, (IInterface**)&value); // assertEquals(Arrays.asList("text/plain"), h.toMultimap().get("Content-Type")); // assertEquals(Arrays.asList("text/plain"), h.toMultimap().get("Content-type")); // RI fails this. }
TEST(SimpleString, endsWith) { SimpleString str("Hello World"); CHECK(str.endsWith("World")); CHECK(!str.endsWith("Worl")); CHECK(!str.endsWith("Hello")); SimpleString str2("ah"); CHECK(str2.endsWith("ah")); CHECK(!str2.endsWith("baah")); SimpleString str3(""); CHECK(!str3.endsWith("baah")); SimpleString str4("ha ha ha ha"); CHECK(str4.endsWith("ha")); }
TEST(SecureAllocator, SecureString) { SecureAllocatorDefaultDomain::SecureString str; str->resize(2000, 'x'); ASSERT_EQUALS(0, str->compare(*SecureAllocatorDefaultDomain::SecureString(2000, 'x'))); SecureAllocatorDefaultDomain::SecureString str2(str); ASSERT_NOT_EQUALS(&*str, &*str2); str2 = str; ASSERT_NOT_EQUALS(&*str, &*str2); auto strPtr = &*str; auto str2Ptr = &*str2; SecureAllocatorDefaultDomain::SecureString str3(std::move(str)); ASSERT_EQUALS(strPtr, &*str3); str3 = std::move(str2); ASSERT_EQUALS(str2Ptr, &*str3); }
void testCountASCIIChars() { vmime::string str1("foo"); VASSERT_EQ("1", static_cast <vmime::string::size_type>(3), stringUtils::countASCIIchars(str1.begin(), str1.end())); vmime::string str2("f=?oo"); VASSERT_EQ("2", static_cast <vmime::string::size_type>(3 + 1), stringUtils::countASCIIchars(str2.begin(), str2.end())); vmime::string str3("foo\x7f"); VASSERT_EQ("3", static_cast <vmime::string::size_type>(4), stringUtils::countASCIIchars(str3.begin(), str3.end())); vmime::string str4("foo\x80"); VASSERT_EQ("4", static_cast <vmime::string::size_type>(3), stringUtils::countASCIIchars(str4.begin(), str4.end())); }
//--------------------------------------------------------- int main(int argc, char* argv[]) { { std::string str("abc 123 abc 123"); boost::replace_all(str, "123", "abc"); assert(str=="abc abc abc abc"); } { std::string str1, str2; std::vector<std::string> token; str1="one.two"; boost::split(token, str1, boost::is_any_of(".")); str2=boost::algorithm::join(token, "_"); boost::algorithm::replace_all(str2, "_", "."); assert(str1==str2); token.erase(token.begin()); assert(boost::algorithm::join(token, ".")=="two"); } //trim { std::string str1(" 1x x x x1 "); std::string str2("<>trim<>"); std::string str3("123abs343"); assert(boost::trim_left_copy(str1)=="1x x x x1 "); boost::trim_right(str1); assert(boost::trim_left_copy(str1)=="1x x x x1"); assert(boost::trim_copy_if(str2, boost::is_any_of("<>"))=="trim"); assert(boost::trim_copy_if(str3, boost::is_digit())=="abs"); boost::trim_if(str2, boost::is_any_of("<>")); assert(str2=="trim"); } { std::string str("aBc"); boost::to_upper(str); assert(str=="ABC"); boost::to_lower(str); assert(str=="abc"); } return 0; }
int main(int argc, char *argv[]) { // BinaryCode *bc = new BinaryCode(); auto_ptr<BinaryCode> bc (new BinaryCode()); string str1 ("123210122"); vector<string> str1Response = bc->decode(str1); cout << "Dla stringa: " << str1 << endl; cout << "Pierwsza wartość: " << str1Response[0] << endl; cout << "Druga wartość: " << str1Response[1] << endl << endl; string str2 ("11"); vector<string> str2Response = bc->decode(str2); cout << "Dla stringa: " << str2 << endl; cout << "Pierwsza wartość: " << str2Response[0] << endl; cout << "Druga wartość: " << str2Response[1] << endl << endl;; string str3 ("22111"); vector<string> str3Response = bc->decode(str3); cout << "Dla stringa: " << str3 << endl; cout << "Pierwsza wartość: " << str3Response[0] << endl; cout << "Druga wartość: " << str3Response[1] << endl << endl;; string str4 ("123210120"); vector<string> str4Response = bc->decode(str4); cout << "Dla stringa: " << str4 << endl; cout << "Pierwsza wartość: " << str4Response[0] << endl; cout << "Druga wartość: " << str4Response[1] << endl << endl;; string str5 ("3"); vector<string> str5Response = bc->decode(str5); cout << "Dla stringa: " << str5 << endl; cout << "Pierwsza wartość: " << str5Response[0] << endl; cout << "Druga wartość: " << str5Response[1] << endl << endl;; string str6 ("12221112222221112221111111112221111"); vector<string> str6Response = bc->decode(str6); cout << "Dla stringa: " << str6 << endl; cout << "Pierwsza wartość: " << str6Response[0] << endl; cout << "Druga wartość: " << str6Response[1] << endl << endl;; return 0; }
int main () { std::string str1 ("/usr/bin/man"); std::string str2 ("c:\\windows\\winhelp.exe"); std::string str3 ("woman"); std::string str4 ("/hello"); SplitFilename (str1); std::cout << " newfile " << str1 << '\n'; SplitFilename (str2); std::cout << " newfile " << str2 << '\n'; SplitFilename (str3); std::cout << " newfile " << str3 << '\n'; SplitFilename (str4); std::cout << " newfile " << str4 << '\n'; return 0; }
void TestA() { std::string str1 = "abc\0def"; // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal std::string str2 = "\0"; // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal std::string str3("\0"); // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal std::string str4{"\x00\x01\x02\x03"}; // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal std::string str; str += "abc\0def"; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: truncated string literal str = "abc\0def"; // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: truncated string literal if (str == "abc\0def") return; // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: truncated string literal if ("abc\0def" == str) return; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: truncated string literal }
void TEST_MostCommon() { std::unordered_map<std::string, size_t> hash_map; std::string common; std::stringstream str1(std::stringstream::in | std::stringstream::out); hash_map.clear(); common = find_most_common_element(str1, &hash_map); ASSERT_EQ(common, ""); std::stringstream str2(std::stringstream::in | std::stringstream::out); str2 << "hi" << std::endl << "bye" << std::endl << "hi" << std::endl; hash_map.clear(); common = find_most_common_element(str2, &hash_map); ASSERT_EQ(common, "hi"); std::stringstream str3(std::stringstream::in | std::stringstream::out); str3 << "hi" << std::endl << "bye" << std::endl << "bye" << std::endl << "bye" << std::endl; hash_map.clear(); common = find_most_common_element(str3, &hash_map); ASSERT_EQ(common, "bye"); }
void post::pushB1_clicked() { client.dataMine(); list<MLogRec> logList_temp= logreader.getLogList(); list<MLogRec>::iterator it=logList_temp.begin(); while(it!=logList_temp.end()){ QString str1(it->logname); QString str2(it->logip); int pid=it->pid; QString str3(QString::number(pid)); long logintime=it->logintime; QString str4(QString::number(logintime)); long logouttime=it->logouttime; QString str5(QString::number(logouttime)); long logtime=it->logtime; QString str6(QString::number(logtime)); QString str=str1+" "+str2+" "+str3+" "+str4+" "+str5+" "+str6+'\n'; ui->textEdit->append(str); it++; } ui->textEdit->append("***************************Send data over!***********************"); ui->textEdit->append("total:"+QString::number(logList_temp.size())); }
int main(){ String str; String str2("Salut"); String str4("Beaucoup"); String str3(str2); printf("Length : %zu \n",str2.length()); printf("Max_Size : %zu \n",str2.max_size()); str2.resize((size_t)7); printf("Size: %zu \n",str2.size()); str2.clear(); printf("Size: %zu \n",str2.size()); const char* essai=str3.c_str(); printf(essai); String str6=str4 +" trop" ; str2='c'; str2.resize((size_t)3,'c'); //~ String str6(str); str2.resize((size_t)102,'c'); str2='c'; String operatoregal; operatoregal=str4; printf("Size: %zu \n",operatoregal.size()); printf("%zu \n",str2.capacity()) ; printf("%d \n",str2.empty()) ; printf("%d \n",str.empty()) ; String str5("Hello !") ; printf("Size : %zu\n",str5.length()) ; printf("Capacity : %zu\n",str5.capacity()) ; str5.reserve((size_t)10) ; printf("Size : %zu\n",str5.length()) ; printf("Capacity : %zu\n",str5.capacity()) ; str5.reserve((size_t)9) ; printf("Size : %zu\n",str5.length()) ; printf("Capacity : %zu\n",str5.capacity()) ; str5.reserve((size_t)5) ; printf("Size : %zu\n",str5.length()) ; printf("Capacity : %zu\n",str5.capacity()) ; //~ str5.reserve((size_t)200) ; //~ printf("Size : %zu\n",str5.length()) ; //~ printf("Capacity : %zu\n",str5.capacity()) ; //~ String str360; str360=str2+'d'; printf("Size : %zu\n",str360.length()) ; String elea1("Bla"); printf("Size : %zu\n",elea1.length()) ; printf("Capacity : %zu\n",elea1.capacity()) ; String elea2(" bla"); String elea3 = elea1 + elea2 ; printf("Size : %zu\n",elea3.length()) ; printf("Capacity : %zu\n",elea3.capacity()) ; return 0 ; }
int main (int argc, char const* argv[]) { fcl::Environment env; fcl::KernelFunc kernel(env, "test_kernel"); kernel << "__kernel void test_kernel(" << "\n" << " void" << "\n" << ")" << "\n" << "{" << "\n" << " int tid = get_global_id(0);" << "\n" << "}" << "\n"; kernel.build(); std::cout << "kernel: " << std::endl << kernel << std::endl; { fcl::ExpKernel kernel2(env, "exp_kernel"); kernel2 [ "__kernel void exp_kernel(" ] [ ")" ] [ "{" ] [ " int bla = 5;"] [ "}" ]; std::cout << "kernel2: " << std::endl << kernel2 << std::endl; } std::complex<double> c; std::vector<double> v; unsigned result; fcl::mini_xml blaxml; fcl::roman<std::string::const_iterator> roman_parser; std::string str("1, 2, 3, 4, 5"); std::string str2("(1.5, 6.4)"); std::string str3("MCMLXXXVIII"); std::string str4("<mini_xml><head>bla</head></mini_xml>"); if(fcl::parse_numbers(str.begin(), str.end()) && fcl::parse_complex(str2.begin(), str2.end(), c) && fcl::parse_list(str.begin(), str.end(), v) && fcl::parse_roman(str3.begin(), str3.end(), result) && fcl::parse_mini_xml(str4.begin(), str4.end(), blaxml)) { std::cout << "Parsing succeeded" << std::endl; std::cout << str << " Parses OK" << std::endl; std::cout << str2 << " Parses OK --> c = " << c << std::endl; std::cout << "List parser OK" << std::endl; std::cout << str3 << " Parses OK --> result = " << result << std::endl; std::cout << str4 << " Parses OK" << std::endl; } else { std::cout << "Parsing failed" << std::endl; } return 0; }
void Sauron::atualizar_cpu_sched(){ int total_tempo[4]; int work_tempo[4]; int a, b, c, d, e, f, g, h, i, j; QString cpuname; QFile file("/proc/stat"); if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream in(&file); QString line =in.readLine(); QTextStream str(&line); //cpu1 line = in.readLine(); //str >> cpuname >> a >> b >> c >> d >> e >> f >> g >> h >> i >>j; str >> cpuname >> a >> b >> c >> d >> e >> f >> g >> h >> i >>j; total_tempo[0] = a + b + c + d + e + f + g + i + j; work_tempo[0] = a + b + c; ui->pbar1->setValue(((float)(work_tempo[0] - work_passado[0])/(total_tempo[0] - total_passado[0]))*100); work_passado[0] = work_tempo[0]; total_passado[0] = total_tempo[0]; //cpu2 line = in.readLine(); QTextStream str1(&line); str1 >> cpuname >> a >> b >> c >> d >> e >> f >> g >> h >> i >> j; total_tempo[1] = a + b + c + d + e + f + g + i + j; work_tempo[1] = a + b + c; ui->pbar2->setValue((float)(work_tempo[1] - work_passado[1])/(total_tempo[1] - total_passado[1])*100); work_passado[1] = work_tempo[1]; total_passado[1] = total_tempo[1]; //cpu3 line = in.readLine(); QTextStream str2(&line); str2 >> cpuname >> a >> b >> c >> d >> e >> f >> g >> h >> i >>j; total_tempo[2] = a + b + c + d + e + f + g + i + j; work_tempo[2] = a + b + c; ui->pbar3->setValue((float)(work_tempo[2] - work_passado[2])/(total_tempo[2] - total_passado[2])*100); work_passado[2] = work_tempo[2]; total_passado[2] = total_tempo[2]; //cpu4 line = in.readLine(); QTextStream str3(&line); str3 >> cpuname >> a >> b >> c >> d >> e >> f >> g >> h >> i >>j; total_tempo[3] = a + b + c + d + e + f + g + i + j; work_tempo[3] = a + b + c; ui->pbar4->setValue((float)(work_tempo[3] - work_passado[3])/(total_tempo[3] - total_passado[3])*100); work_passado[3] = work_tempo[3]; total_passado[3] = total_tempo[3]; }
void Debuger::DrawEntitiesStats(int eco){ sf::View currentView = _window->getView(); sf::Vector2f centerView = currentView.getCenter(); sf::Vector2f sizeView = currentView.getSize(); _text.setPosition(centerView.x-sizeView.x/2, centerView.y-sizeView.y/2+_displace); std::stringstream buffer; Scene* s = Scene::getScene(); Ecosystem *e1 = s->getEcosystem(eco); buffer << "Ecosystem " << eco << " (" << e1->getInterval().x << " - " << e1->getInterval().y <<") Num Mobs: " << e1->getMobPopulationAndTreshold().x << "/" << e1->getMobPopulationAndTreshold().y << "/" << e1->getMobPopulationAndTreshold().z << "Num Trees: " << e1->getTreePopulationAndTreshold().x << "/" << e1->getTreePopulationAndTreshold().y << "/" << e1->getTreePopulationAndTreshold().z; std::string string(buffer.str()); sf::String str(string); _text.setString(str); _window->draw(_text); _displace = _displace + DISPLACEMENT; sf::Vector2f position = _window->mapPixelToCoords(sf::Mouse::getPosition(*_window)); float zoom = s->getZoom(); sf::Vector2f position_center = sf::Vector2f(s->getPlayer()->GetPosition().x+Player::PLAYER_WIDTH/2,s->getPlayer()->GetPosition().y+Player::PLAYER_WIDTH/2); sf::Vector2f position_zoomed = (position-position_center)/zoom +position_center; position = position_zoomed; std::vector<Mob*> mobs; s->getMobsOnArea(mobs,sf::Vector2i(position),100,eco); for(int i =0; i<mobs.size();i++){ mobs[i]->_focusDebug = true; } if(mobs.size()>0) { std::stringstream buffer2; buffer2 << "Mob Position colision: " << mobs[0]->_positionCol.x << " " << mobs[0]->_positionCol.y << " Size colision: " << mobs[0]->_sizeCol.x << " " << mobs[0]->_sizeCol.y << " Radius: " << mobs[0]->getGenetics()->_distanceMaxReproduce << "/" << mobs[0]->getGenetics()->_distanceMaxMove; std::string string(buffer2.str()); sf::String str(string); _text.setString(str); _text.setPosition(centerView.x-sizeView.x/2, centerView.y-sizeView.y/2+_displace); _window->draw(_text); _displace = _displace + DISPLACEMENT; std::stringstream buffer3; buffer3 << "Race: " << mobs[0]->getGenetics()->_race << " Life: " << mobs[0]->_life << "/" << mobs[0]->getGenetics()->_health << " Hunger: " << mobs[0]->_hunger << "/" << mobs[0]->getGenetics()->_foodNeeds << " Age: " << mobs[0]->_age << "/" << mobs[0]->getGenetics()->_age << " Target: " << (mobs[0]->_target !=nullptr); std::string string3(buffer3.str()); sf::String str3(string3); _text.setString(str3); _text.setPosition(centerView.x-sizeView.x/2, centerView.y-sizeView.y/2+_displace); _window->draw(_text); _displace = _displace + DISPLACEMENT; std::stringstream buffer4; buffer4 << "Food: "; for(int i =0; i< mobs[0]->getGenetics()->_food.size();i++){ buffer4 << mobs[0]->getGenetics()->_food[i] << " "; } buffer4 << "\n Enemys: "; for(int i =0; i< mobs[0]->getGenetics()->_enemys.size();i++){ buffer4 << mobs[0]->getGenetics()->_enemys[i] << " "; } buffer4 << "\n Friends: "; for(int i =0; i< mobs[0]->getGenetics()->_friends.size();i++){ buffer4 << mobs[0]->getGenetics()->_friends[i] << " "; } buffer4 << "\n Neutral: "; for(int i =0; i< mobs[0]->getGenetics()->_neutral.size();i++){ buffer4 << mobs[0]->getGenetics()->_neutral[i] << " "; } std::string string4(buffer4.str()); sf::String str4(string4); _text.setString(str4); _text.setPosition(centerView.x-sizeView.x/2, centerView.y-sizeView.y/2+_displace); _window->draw(_text); _displace = _displace + DISPLACEMENT*4; } else { std::vector<Tree*> trees; s->getTreesOnArea(trees,sf::Vector2i(position),100,eco); if(trees.size() >0){ int pos_l = 0; int pos_r = 0; if(trees[0]->_left_n != nullptr) pos_l = trees[0]->_left_n->_position.x; if(trees[0]->_right_n != nullptr) pos_r = trees[0]->_right_n->_position.x; std::stringstream buffer2; buffer2 << "Tree Position: " << trees[0]->_position.x << " " << trees[0]->_position.y << " padding: " << trees[0]->_min_x << ", " << trees[0]->_max_x <<" Health: " << trees[0]->_life <<" Reproduce countdown: " << trees[0]->_timeToReproduce << "\n"; buffer2 << "Damage time: " << trees[0]->_debug_last_damage_time << " Damage distance: " << trees[0]->_debug_last_damage_distance << " Damage temp: " << trees[0]->_debug_last_damage_temp << " Damage humid " << trees[0]->_debug_last_damage_hum << "\n"; buffer2 << "Tree Fathers: " << pos_l << " " << pos_r << "\n"; TreeGenetics *gens = trees[0]->getGenetics(); buffer2 << "Tree corb: " << gens->_corb << " Tree amplitude: " << gens->_amplitude << " Tree height: " << gens->_height << "\n"; buffer2 << "Branch amount: " << gens->_branchAmount << " Curve branch: " << gens->_curveBranch << " Branch size: " << gens->_sizeBranch << "\n"; buffer2 << "Type leave: " << gens->_typeLeave << " Amount leave: " << gens->_amountLeave << " Density leave: " << gens->_densityLeave << "\n"; buffer2 << "Life: " << gens->_health << " Cold res " << gens->_cold << " Hot res " << gens->_hot << " Humidity res " << gens->_humidity << " Gen strenght " << gens->_strenghtGen << " Reproduce freq " << gens->_reproduceFactor; std::string string(buffer2.str()); sf::String str(string); _text.setString(str); _text.setPosition(centerView.x-sizeView.x/2, centerView.y-sizeView.y/2+_displace); _window->draw(_text); _displace = _displace + DISPLACEMENT*7; } } }
int main() { { string str1("AAAA"), str2("BBBB"); string result; //setup fixture result=str1 + str2; assert(str1=="AAAA"); assert(str2== "BBBB"); assert(result=="AAAABBBB"); } { string str1("AAAA"), result; result=str1+"BBBB"; assert(str1=="AAAA"); assert(result=="AAAABBBB"); } { string str1("AAAA"), result; result="BBBB"+str1; assert(str1=="AAAA"); assert(result=="BBBBAAAA"); } { string str1("AAAA"), result; char ch='B'; result=str1+ch; assert(str1=="AAAA"); assert(ch=='B'); assert(result=="AAAAB"); } { string str1("AAAA"),result; result='B'+str1; assert(str1=="AAAA"); assert(result=="BAAAA"); } { string str1("AAAA"), str3("CCCC"), result; char ch='B'; result = str1 + ch + 'B' + 'B'+ 'B' + str3; assert(str1=="AAAA"); assert(ch== 'B'); assert(str3=="CCCC"); assert(result=="AAAABBBBCCCC"); } { string str1("ABC"), result; result=" " + str1; assert(str1=="ABC"); assert(result==" ABC"); } { string str1("ABC"), result; result = str1 + " "; assert(str1 == "ABC"); assert(result == "ABC "); } { string str1(" "), str2(" "), result; result = str1 + str2; assert(str1 == " "); assert(str2 == " "); assert(result == " "); } { string rhs("ABC"), result; result = 'A' + rhs; assert(rhs=="ABC"); assert(result== "AABC"); } { string lhs("ABC"), result; result = lhs + 'A'; assert(lhs == "ABC"); assert(result == "ABCA"); } { string str1("Hello"), str2("Wiggins"), result; char ch1='C', ch2='t'; result = str1 + ',' + " My name is " + ch1 + 'u' + 'r' + ch2 + "iss " + str2 + '.'; assert(str1=="Hello"); assert(str2=="Wiggins"); assert(ch1=='C'); assert(ch2=='t'); assert(result=="Hello, My name is Curtiss Wiggins."); } }
void drive_operation() { // Uint64 tests CQLValue a1(Uint64(10)); CQLValue a2(Uint64(15)); CQLValue a3(Uint64(25)); CQLValue a4(Uint64(30)); CQLValue a5(Uint64(150)); PEGASUS_TEST_ASSERT(a1 != a2); PEGASUS_TEST_ASSERT(a5 == a5); PEGASUS_TEST_ASSERT(a1 < a2); PEGASUS_TEST_ASSERT(a2 >= a1); PEGASUS_TEST_ASSERT(a1 <= a2); PEGASUS_TEST_ASSERT(a2 > a1); // Sint64 tests CQLValue b1(Sint64(10)); CQLValue b2(Sint64(15)); CQLValue b3(Sint64(25)); CQLValue b4(Sint64(30)); CQLValue b5(Sint64(150)); PEGASUS_TEST_ASSERT(b1 != b2); PEGASUS_TEST_ASSERT(b5 == b5); PEGASUS_TEST_ASSERT(b1 < b2); PEGASUS_TEST_ASSERT(b2 >= b1); PEGASUS_TEST_ASSERT(b1 <= b2); PEGASUS_TEST_ASSERT(b2 > b1); // Real64 tests CQLValue c1(Real64(10.00)); CQLValue c2(Real64(15.00)); CQLValue c3(Real64(25.00)); CQLValue c4(Real64(30.00)); CQLValue c5(Real64(150.00)); PEGASUS_TEST_ASSERT(c1 != c2); PEGASUS_TEST_ASSERT(c5 == c5); PEGASUS_TEST_ASSERT(c1 < c2); PEGASUS_TEST_ASSERT(c2 >= c1); PEGASUS_TEST_ASSERT(c1 <= c2); PEGASUS_TEST_ASSERT(c2 > c1); // Misc PEGASUS_TEST_ASSERT(a1 == b1); PEGASUS_TEST_ASSERT(a1 == c1); PEGASUS_TEST_ASSERT(b1 == a1); PEGASUS_TEST_ASSERT(b1 == c1); PEGASUS_TEST_ASSERT(c1 == a1); PEGASUS_TEST_ASSERT(c1 == b1); PEGASUS_TEST_ASSERT(a2 != b1); PEGASUS_TEST_ASSERT(a2 != c1); PEGASUS_TEST_ASSERT(b2 != a1); PEGASUS_TEST_ASSERT(b2 != c1); PEGASUS_TEST_ASSERT(c2 != a1); PEGASUS_TEST_ASSERT(c2 != b1); PEGASUS_TEST_ASSERT(a2 >= b1); PEGASUS_TEST_ASSERT(a2 >= c1); PEGASUS_TEST_ASSERT(b2 >= a1); PEGASUS_TEST_ASSERT(b2 >= c1); PEGASUS_TEST_ASSERT(c2 >= a1); PEGASUS_TEST_ASSERT(c2 >= b1); PEGASUS_TEST_ASSERT(a2 <= b3); PEGASUS_TEST_ASSERT(a2 <= c3); PEGASUS_TEST_ASSERT(b2 <= a3); PEGASUS_TEST_ASSERT(b2 <= c3); PEGASUS_TEST_ASSERT(c2 <= a3); PEGASUS_TEST_ASSERT(c2 <= b3); PEGASUS_TEST_ASSERT(a2 > b1); PEGASUS_TEST_ASSERT(a2 > c1); PEGASUS_TEST_ASSERT(b2 > a1); PEGASUS_TEST_ASSERT(b2 > c1); PEGASUS_TEST_ASSERT(c2 > a1); PEGASUS_TEST_ASSERT(c2 > b1); PEGASUS_TEST_ASSERT(a2 < b3); PEGASUS_TEST_ASSERT(a2 < c3); PEGASUS_TEST_ASSERT(b2 < a3); PEGASUS_TEST_ASSERT(b2 < c3); PEGASUS_TEST_ASSERT(c2 < a3); PEGASUS_TEST_ASSERT(c2 < b3); //Overflow testing CQLValue real1(Real64(0.00000001)); CQLValue sint1(Sint64(-1)); CQLValue uint1(Sint64(1)); CQLValue uint2(Uint64(0)); PEGASUS_TEST_ASSERT(uint1 > sint1); PEGASUS_TEST_ASSERT(real1 > sint1); PEGASUS_TEST_ASSERT(uint2 > sint1); PEGASUS_TEST_ASSERT(real1 > uint2); CQLValue real2(Real64(25.00000000000001)); CQLValue real3(Real64(24.99999999999999)); CQLValue sint2(Sint64(25)); CQLValue uint3(Uint64(25)); PEGASUS_TEST_ASSERT(real2 > real3); PEGASUS_TEST_ASSERT(real2 > sint2); PEGASUS_TEST_ASSERT(real2 > uint3); PEGASUS_TEST_ASSERT(real3 < sint2); PEGASUS_TEST_ASSERT(real3 < uint3); // String tests CQLValue d1(String("HELLO")); CQLValue d2(String("HEL")); CQLValue d3(String("LO")); CQLValue d4(String("AHELLO")); CQLValue d5(String("ZHELLO")); PEGASUS_TEST_ASSERT(d1 == d2 + d3); PEGASUS_TEST_ASSERT(d1 != d2 + d4); PEGASUS_TEST_ASSERT(d1 <= d5); PEGASUS_TEST_ASSERT(d1 < d5); PEGASUS_TEST_ASSERT(d1 >= d4); PEGASUS_TEST_ASSERT(d1 > d4); String str1("0x10"); String str2("10"); String str3("10B"); String str4("10.10"); CQLValue e1( str1, CQLValue::Hex); CQLValue e2( str2, CQLValue::Decimal); CQLValue e3( str3, CQLValue::Binary); CQLValue e4( str4, CQLValue::Real); CQLValue e5(Uint64(16)); CQLValue e6(Uint64(10)); CQLValue e7(Uint64(2)); CQLValue e8(Real64(10.10)); PEGASUS_TEST_ASSERT(e1 == e5); PEGASUS_TEST_ASSERT(e2 == e6); PEGASUS_TEST_ASSERT(e3 == e7); PEGASUS_TEST_ASSERT(e4 == e8); Array<Uint64> array1; array1.append(1); array1.append(2); array1.append(3); array1.append(4); array1.append(5); array1.append(6); array1.append(7); array1.append(8); array1.append(9); array1.append(10); Array<Sint64> array2; array2.append(1); array2.append(2); array2.append(3); array2.append(4); array2.append(5); array2.append(6); array2.append(7); array2.append(8); array2.append(9); array2.append(10); array2.append(3); Array<Real64> array3; array3.append(1.00); array3.append(2.00); array3.append(3.00); array3.append(9.00); array3.append(10.00); array3.append(3.00); array3.append(4.00); array3.append(5.00); array3.append(6.00); array3.append(7.00); array3.append(8.00); Array<Uint64> array4; array4.append(1); array4.append(23); array4.append(3); array4.append(4); array4.append(5); array4.append(6); array4.append(7); array4.append(88); array4.append(9); array4.append(10); Array<Sint64> array5; array5.append(-1); array5.append(2); array5.append(3); array5.append(4); array5.append(5); array5.append(-6); array5.append(7); array5.append(8); array5.append(9); array5.append(10); array5.append(-3); Array<Real64> array6; array6.append(1.23); array6.append(2.00); array6.append(3.00); array6.append(9.00); array6.append(10.00); array6.append(3.00); array6.append(4.14); array6.append(5.00); array6.append(6.00); array6.append(7.00); array6.append(8.00); CIMValue cv1(array1); CIMValue cv2(array2); CIMValue cv3(array3); CIMValue cv4(array4); CIMValue cv5(array5); CIMValue cv6(array6); CQLValue vr1(cv1); CQLValue vr2(cv1); CQLValue vr3(cv2); CQLValue vr4(cv3); CQLValue vr5(cv4); CQLValue vr6(cv5); CQLValue vr7(cv6); PEGASUS_TEST_ASSERT(vr1 == vr2); PEGASUS_TEST_ASSERT(vr1 == vr3); PEGASUS_TEST_ASSERT(vr1 == vr4); PEGASUS_TEST_ASSERT(vr4 == vr3); PEGASUS_TEST_ASSERT(vr1 != vr5); PEGASUS_TEST_ASSERT(vr3 != vr6); PEGASUS_TEST_ASSERT(vr4 != vr7); const CIMName _cimName(String("CIM_OperatingSystem")); CIMInstance _i1(_cimName); CIMProperty _p1(CIMName("Description"),CIMValue(String("Dave Rules"))); CIMProperty _p2(CIMName("EnabledState"),CIMValue(Uint16(2))); CIMProperty _p3(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600))); CIMProperty _p4(CIMName("TimeOfLastStateChange"), CIMValue(CIMDateTime(String("20040811105625.000000-360")))); _i1.addProperty(_p1); _i1.addProperty(_p2); _i1.addProperty(_p3); _i1.addProperty(_p4); CIMInstance _i2(_cimName); CIMProperty _p5(CIMName("Description"), CIMValue(String("Dave Rules Everything"))); CIMProperty _p6(CIMName("EnabledState"),CIMValue(Uint16(2))); CIMProperty _p7(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600))); CIMProperty _p8(CIMName("TimeOfLastStateChange"), CIMValue(CIMDateTime(String("20040811105625.000000-360")))); _i2.addProperty(_p5); _i2.addProperty(_p6); _i2.addProperty(_p7); _i2.addProperty(_p8); CQLValue cql1(_i1); CQLValue cql2(_i1); CQLValue cql3(_i2); CQLValue cql4(_i2); //PEGASUS_TEST_ASSERT(cql1 == cql1); return; }
void CHttpHdrTest::TestHeaderCollIterL() { RStringF field1Str = iStrP.OpenFStringL(_L8("hcfield1")); CleanupClosePushL(field1Str); RStringF value1Str = iStrP.OpenFStringL(_L8("hcvalue1")); CleanupClosePushL(value1Str); RStringF field2Str = iStrP.OpenFStringL(_L8("hcfield2")); CleanupClosePushL(field2Str); RStringF value2Str = iStrP.OpenFStringL(_L8("hcvalue2")); CleanupClosePushL(value2Str); RStringF field3Str = iStrP.OpenFStringL(_L8("hcfield3")); CleanupClosePushL(field3Str); RStringF value3Str = iStrP.OpenFStringL(_L8("hcvalue3")); CleanupClosePushL(value3Str); RStringF field4Str = iStrP.OpenFStringL(_L8("hcfield4")); CleanupClosePushL(field4Str); RStringF value4Str = iStrP.OpenFStringL(_L8("hcvalue4")); CleanupClosePushL(value4Str); // CTextModeHeaderCodec* headerCodec = CTextModeHeaderCodec::NewL(iStrP); CleanupStack::PushL(headerCodec); CHeaders* headers = CHeaders::NewL(*headerCodec); CleanupStack::PushL(headers); RHTTPHeaders hdr = headers->Handle(); THTTPHdrVal str1(value1Str); hdr.SetFieldL(field1Str, str1); THTTPHdrVal str2(value2Str); hdr.SetFieldL(field2Str, str2); THTTPHdrVal str3(value3Str); hdr.SetFieldL(field3Str, str3); THTTPHdrVal str4(value4Str); hdr.SetFieldL(field4Str, str4); THTTPHdrFieldIter it = hdr.Fields(); TInt count = 0; while (it.AtEnd() == EFalse) { RStringTokenF nextTk = it(); RStringF nextStr = iStrP.StringF(nextTk); THTTPHdrVal hVal; TestL(hdr.GetField(nextStr,0,hVal)==KErrNone); switch (count) { case 0: TestL(nextStr.Index(RHTTPSession::GetTable()) == field1Str.Index(RHTTPSession::GetTable())); break; case 1: TestL(nextStr.Index(RHTTPSession::GetTable()) == field2Str.Index(RHTTPSession::GetTable())); break; case 2: TestL(nextStr.Index(RHTTPSession::GetTable()) == field3Str.Index(RHTTPSession::GetTable())); break; case 3: TestL(nextStr.Index(RHTTPSession::GetTable()) == field4Str.Index(RHTTPSession::GetTable())); break; } ++it; ++count; } // Close strings used in this test CleanupStack::PopAndDestroy(10); }
void CPkt30viewDoc::LoadOpcodes(void) { TCHAR str[1024], filename[MAX_PATH], opcode_str[200], opcode_val[200], lua_str[200]; m_LuaFuncNames.clear(); m_Opcodes.clear(); sprintf_s(filename, "%s\\%d\\opcodes.txt", gWorkDir, m_Header.build); std::ifstream file(filename); if (file) { while (file.getline(str, 1024)) { memset(opcode_str, 0, 200); memset(opcode_val, 0, 200); memset(lua_str, 0, 200); int step = 0, index = 0; for (int i = 0; (i < 1024) && str[i]; i++) { if ((str[i] != 0x20) && (str[i] != 0x09)) { switch(step) { case 0: if (str[i] == ',') { step++; index = 0; } else opcode_val[index++] = str[i]; break; case 1: if (str[i] == ',') { step++; index = 0; } else opcode_str[index++] = str[i]; break; case 2: lua_str[index++] = str[i]; break; } } } int opcode = 0; if (opcode_val[0]) { char *end, *start; int base; if ((opcode_val[0] == '0') && ((opcode_val[1] == 'x') || (opcode_val[1] == 'X'))) { base = 16; start = &opcode_val[2]; } else { base = 10; start = &opcode_val[0]; } opcode = strtol(start, &end, base); if (opcode_str[0]) { std::string str2(opcode_str); m_Opcodes.insert(std::make_pair(opcode, str2)); } if (lua_str[0]) { std::string str3(lua_str); m_LuaFuncNames.insert(std::make_pair(opcode, str3)); } } } } }
/* the gateway routine. */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { /* create a pointer to the real data in the input matrix */ int nfields = mxGetNumberOfFields(prhs[0]); // number of fields in each constraint mwSize NStructElems = mxGetNumberOfElements(prhs[0]); // number of constraints const char **fnames = (const char **)mxCalloc(nfields, sizeof(*fnames)); /* pointers to field names */ double *sw = mxGetPr(prhs[1]); /* switch vector */ double *xs = mxGetPr(prhs[2]); /* linearisation point */ long unsigned int nrow = mxGetM(prhs[2]); double *ptr = mxGetPr(prhs[3]); /* number of cameras */ int ncams = ptr[0]; /* initialise a PwgOptimiser object */ PwgOptimiser *Object; // pointer initialisation Object = new PwgOptimiser (ncams, nrow-6*ncams) ; // pointer initialisation /* get constraints from Matlab to C++ and initialise a constraint */ double *pr; mxArray *tmp; int cam, kpt; std::vector<double> p1(2), z(2), R(4,0.0);//, Y(49,0.0), y(7,0.0); std::string str1 ("cam"); std::string str2 ("kpt"); std::string str3 ("p1"); std::string str4 ("z"); std::string str5 ("R"); std::string str6 ("y"); std::string str7 ("Y"); Eigen::MatrixXd yz = Eigen::MatrixXd::Zero(7,1); Eigen::VectorXd Yz = Eigen::MatrixXd::Zero(7,7); for (mwIndex jstruct = 0; jstruct < NStructElems; jstruct++) { /* loop the constraints */ for (int ifield = 0; ifield < nfields; ifield++) { /* loop the fields */ fnames[ifield] = mxGetFieldNameByNumber(prhs[0],ifield); // get field name tmp = mxGetFieldByNumber(prhs[0], jstruct, ifield); // get field pr = (double *)mxGetData(tmp); // get the field data pointer if (str1.compare(fnames[ifield]) == 0) // cam cam = pr[0]; if (str2.compare(fnames[ifield]) == 0) // kpt kpt = pr[0]; if (str3.compare(fnames[ifield]) == 0){ // p1 p1[0] = pr[0]; p1[1] = pr[1];} if (str4.compare(fnames[ifield]) == 0){ // z z[0] = pr[0]; z[1] = pr[1];} if (str5.compare(fnames[ifield]) == 0){ // R R[0] = pr[0]; R[3] = pr[3];} } // end of nfields loop Object->initialise_a_constraint(cam, kpt, p1, z, R, Yz, yz, (int)sw[jstruct]) ; // using pointer to object } // end of NStructElems loop // optimise constraints information Object->optimise_constraints_image_inverse_depth_Mviews( xs ) ; /* get output state vector */ int ncol = (Object->xhat).size(); plhs[0] = mxCreateDoubleMatrix(ncol, 1, mxREAL); double *vec_out = mxGetPr(plhs[0]); for (int i=0; i<ncol; i++) vec_out[i] = (Object->xhat).coeffRef(i); /* get output sparse covariance matrix */ ncol = (Object->Phat).outerSize(); long unsigned int nzmax = (Object->Phat).nonZeros(); plhs[1] = mxCreateSparse(ncol, ncol, nzmax, mxREAL); double *mat_out = mxGetPr(plhs[1]); long unsigned int *ir2 = mxGetIr(plhs[1]); long unsigned int *jc2 = mxGetJc(plhs[1]); int index=0; for (int k=0; k < (Object->Phat).outerSize(); ++k) { jc2[k] = index; for (Eigen::SparseMatrix<double>::InnerIterator it(Object->Phat,k); it; ++it) { ir2[index] = it.row(); mat_out[index] = it.value(); index++; } } jc2[(Object->Phat).outerSize()] = index; /* Free memory */ mxFree((void *)fnames); delete Object; // delete class pointer //mxFree(tmp); }