Esempio n. 1
0
double KoUnitDoubleSpinBox::valueFromText( const QString& str ) const
{
    QString str2( str );
    /* KLocale::readNumber wants the thousand separator exactly at 1000.
       But when editing, it might be anywhere. So we need to remove it. */
    const QString sep( KGlobal::locale()->thousandsSeparator() );
    if ( !sep.isEmpty() )
        str2.remove( sep );
    str2.remove( KoUnit::unitName( d->unit ) );
    bool ok;
    const double dbl = KGlobal::locale()->readNumber( str2, &ok );
    if ( ok )
      kDebug(30004) <<"valueFromText:" << str <<": => :" << str2 <<": =>" << QString::number( dbl, 'f', 12 );
    else
        kWarning(30004) << "valueFromText error:" << str << ": => :" << str2 << ":";
    return dbl;
}
Esempio n. 2
0
int main(int argc, char **argv) {
    if (argc != 4) {
        std::cout << "Usage: " << argv[0] << " <databasefilename> <queryfilename> <tree-type>" << std::endl;
        return 0;
    }
    std::string db_filename(argv[1]);
    std::string str1(argv[2]);
    std::string str2(argv[3]);
    std::cout << "Input file is " << db_filename << " ";
    std::cout << "String 1 is " << str1 << "   and string 2 is " << str2 << std::endl;
    CheckFile(db_filename);
    
    AvlTree<SequenceMap> a_tree;
    FillTree(db_filename, a_tree);
    a_tree.print_Between(str1, str2);
    return 0;
}
Esempio n. 3
0
int
main(int argc, char **argv)
{
  std::ifstream f("tests/data/default-style.iss");
  TestParser parser(f);

  try
  {
    parser.parse();
  }
  catch (IgStyleParser::StyleParserError &e)
  {
    std::cerr << e.explain() << std::endl;
    exit(1);
    assert(false);
  }

  std::stringstream str("* {color: rgb(.7,.7,.7) ;} Background {diffuse-color: rgb(1., 0, 0);}");
  std::cerr << str.str() << std::endl;
  TestParser styleParser(str);
  try
  {
    styleParser.parse();
  }
  catch (IgStyleParser::StyleParserError &e)
  {
    std::cerr << e.explain() << std::endl;
    exit(1);
    assert(false);
  }

  bool hasThrown = false;
  try
  {
    throw IgStyleParser::StyleParserError("Dummy", "Error");
  }
  catch(IgStyleParser::StyleParserError &e)
  {
    hasThrown = true;
  }
  assert(hasThrown);

  std::stringstream str2("// A comment\n* {name: \"pippo\" ; version: 'pluto'}");
  TestParser styleParser2(str);
}
Esempio n. 4
0
	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()));
	}
Esempio n. 5
0
// CDialogNew 消息处理程序
void CDialogNew::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	m_EditText.GetWindowTextW(m_Text);
	if(m_Text == "0" || m_Text == ""|| m_Text.SpanIncluding( _T(".0123456789"))!= m_Text)
	{
		CString str1("输入格式不正确,请重新输入!");
		CString str2("提示");
		MessageBox(str1,str2);
		m_Text = "";
	}
	else
	{
		int nIndex = m_Combobox.GetCurSel();
		m_Combobox.GetLBText(nIndex,m_Unit);
		CDialogEx::OnOK();
	}
}
Esempio n. 6
0
void CDialogNew::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	m_EditRow.GetWindowTextW(m_Row);
	m_EditCol.GetWindowTextW(m_Col);
	if(m_Row == "" || m_Col == "" || m_Row.SpanIncluding( _T("0123456789"))!= m_Row || m_Col.SpanIncluding( _T("0123456789"))!= m_Col)
	{
		CString str1("输入格式不正确,请重新输入!");
		CString str2("提示");
		MessageBox(str1,str2);
		m_Row = "";
		m_Col = "";
	}
	else
	{
		CDialogEx::OnOK();
	}
}
Esempio n. 7
0
void YZParserConfigWidget::execute()
{
    this->clear();
    QScriptValue result = m_engine.evaluate(configUi.plainTextEdit->toPlainText());
    m_functionValue = m_engine.globalObject().property("parseArticle");
    QScriptValueList args;
    QString str(targetUi.plainTextEdit->toPlainText());
    QString str2(targetUi.lineEdit->text());
    args << QScriptValue(str)<<QScriptValue(str2);
    QScriptValue article = m_functionValue.call(QScriptValue(),args);
    QVariant articleItem = article.toVariant();

    resultUi.plainTextEdit->appendPlainText(QString("version:")  + QString::fromUtf8(articleItem.toMap()["version"].toByteArray().data())+"\n");
    resultUi.plainTextEdit->appendPlainText(QString("lastModified:")  + QString::fromUtf8(articleItem.toMap()["lastModified"].toByteArray().data())+"\n");
    resultUi.plainTextEdit->appendPlainText(QString("refreshTag:")  + QString::fromUtf8(articleItem.toMap()["refreshTag"].toByteArray().data())+"\n");
    resultUi.plainTextEdit->appendPlainText(QString("author:")  + QString::fromUtf8(articleItem.toMap()["author"].toByteArray().data())+"\n");
    resultUi.plainTextEdit->appendPlainText(QString("body:")  + QString::fromUtf8(articleItem.toMap()["body"].toByteArray().data())+"\n");
}
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);
}
Esempio n. 9
0
//---------------------------------------------------------------------------------------------------------------------------------------------------
void ProgressBar::DrawProgress()
{
    sprite->Clear(Color::GRAY);
    sprite->FillRectangle(0, 0, (int)(width * progress), (int)height, Color::BLUE);

    char buffer[100];
    sprintf_s(buffer, 99, "%5.1f%%", progress * 100.0f);

    textPercents->SetText(String(buffer));

    sprintf_s(buffer, 99, "Size: all %5.1fMB, recieved %5.1fMB\n", bytesAll / 1024.0f / 1024.0f, bytesRecieved / 1024.0f / 1024.0f);
    String str1(buffer);

    sprintf_s(buffer, 99, "Speed %5.1fkB/s, time: passed %5.1fs, elapsed %5.1fs", speed / 1024.0f, timePassed, timeElapsed);
    String str2(buffer);

    text->SetText(currentFile + String("\n") + str1 + str2);
}
//---------------------------------------------------------
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;
}
Esempio n. 11
0
static
void test_static_string_equal()
{
    my_static_string_t str0("hello");
    my_static_string_t str0b("hello");
    my_static_string_t str1("hello!");
    my_static_string_t str2("hell");

    my_static_string_t a("a");
    my_static_string_t b("b");

    UF_TEST(str0 == str0b);
    UF_TEST(!(str0 == str1));
    UF_TEST(str0 != str1);
    UF_TEST(str0 != str2);
    UF_TEST(  a < b);
    UF_TEST(!(a < a));
    UF_TEST(!(b < a));
}
Esempio n. 12
0
// some sort of error in the music data...
//
static void Music_Parse_Error(LPCSTR psError)
{
    string	str(S_COLOR_RED);	// that way I don't have to use either nested va (since quake only has 2), or know what that colour macro actually does
    string	str2(psError);		// ... so I can re-use va(), which is only 2-deep in Q3
    str += va("Error parsing music data ( in \"%s\" ):\n%s\n",sFILENAME_DMS,str2.c_str());

#ifdef FINAL_BUILD
    extern cvar_t *s_debugdynamic;
    if (s_debugdynamic && s_debugdynamic->integer)
    {
#endif
        Com_Printf(str.c_str());

#ifdef FINAL_BUILD
    }
#endif

    MusicData.clear();
}
Esempio n. 13
0
// similar to matlab's fileparts
// if in=parent/child/file.txt
// then path=parent/child
// name=file, ext=txt
inline void fileparts(const std::string& str, std::string* pPath=0,
	std::string* pName=0, std::string* pExt=0)
{
	std::string str2(str);
	std::replace(str2.begin(), str2.end(), another_filesep, filesep); //make sure no mixed filesep
	std::string::size_type last_sep = str2.find_last_of(filesep);
	std::string::size_type last_dot = str2.find_last_of('.');
	if (last_sep != std::string::npos && last_dot<last_sep) // "D:\parent\child.folderA\file", "D:\parent\child.folderA\"
		last_dot = std::string::npos;

	std::string path, name, ext;

	if (last_sep == std::string::npos) {
		path = "";
		if (last_dot == std::string::npos) { // "test"
			name = str2;
			ext = "";
		} else { // "test.txt"
			name = str2.substr(0, last_dot);
			ext = str2.substr(last_dot + 1);
		}
	}
	else {
		path = str2.substr(0, last_sep);
		if (last_dot == std::string::npos) { // "d:/parent/test", "d:/parent/child/"
			name = str2.substr(last_sep + 1);
			ext = "";
		} else { // "d:/parent/test.txt"
			name = str2.substr(last_sep + 1, last_dot - last_sep - 1);
			ext = str2.substr(last_dot + 1);
		}
	}

	if (pPath != 0) {
		*pPath = path;
	}
	if (pName != 0) {
		*pName = name;
	}
	if (pExt != 0) {
		*pExt = ext;
	}
}
Esempio n. 14
0
	void OilWellSensor::setupSensor(char *id, char *type, char *className, char *displayName, double min, bool minUdf, double max, bool maxUdf, double step, char *units, char *unitAbbrev, char *dataGenAlg, char **linkSenType) {

		wellID = (string)id;

		string str(type);
		int lengthTest = str.length();
		sensorType = new char[lengthTest];
		strcpy(sensorType, type);

		sensorClassName = (string)className;

		sensorDisplayName = new char[100];
		strcpy(sensorDisplayName, displayName);

		m_dMinValue = min;
		minCounter = (int)m_dMinValue;
		this->minUdf = minUdf;

		m_dMaxValue = max;
		maxCounter = (int)m_dMaxValue;
		this->maxUdf = maxUdf;

		this->step = step;

		sensorUnits = new char[100];
		strcpy(sensorUnits, units);

		sensorUnitAbbreviation = new char[100];
		strcpy(sensorUnitAbbreviation, unitAbbrev);


		string str2(dataGenAlg);
		int lengthTest2 = str2.length();
		this->dataGenAlg = new char[lengthTest2];
		strcpy(this->dataGenAlg, dataGenAlg);

		if (linkSenType != NULL) {
			linkedSensor = new char[100];
			strcpy(linkedSensor, *linkSenType);
		}

	}
Esempio n. 15
0
TEST(String, Compare) {
  EXPECT_TRUE(String("abc").compare("abc") == 0);
  EXPECT_TRUE(String("abc").compare("bbc") < 0);
  EXPECT_TRUE(String("bbc").compare("abc") > 0);
  EXPECT_TRUE(String("abc").compare(String("abc")) == 0);
  EXPECT_TRUE(String("abc").compare(String("bbc")) < 0);
  EXPECT_TRUE(String("bbc").compare(String("abc")) > 0);

  EXPECT_TRUE(String("abc").compare("abcd") < 0);
  EXPECT_TRUE(String("abcd").compare("abc") > 0);
  EXPECT_TRUE(String("abc").compare(String("abcd")) < 0);
  EXPECT_TRUE(String("abcd").compare(String("abc")) > 0);

  // check Strings with embedded nulls
  std::string str1("a\0bc", 4);
  std::string str2("a\0bb", 4);
  EXPECT_TRUE(String(str1).compare(String(str1)) == 0);
  EXPECT_TRUE(String(str1).compare(String(str2)) > 0);
  EXPECT_TRUE(String(str2).compare(String(str1)) < 0);
}
static string_t replace_all(string_t const& str, PAN_CHAR_T const* srch, PAN_CHAR_T const* repl)
{
    string_t    str2(str);
    size_t      srchLen = stlsoft::c_str_len(srch);

    for(;;)
    {
        size_t  lpos = str2.find(srch);
        size_t  rpos = lpos + srchLen;

        if(string_t::npos == lpos)
        {
            break;
        }

        str2 = stlsoft::left(str2, lpos) + repl + stlsoft::right(str2, str2.length() - rpos);
    }

    return str2;
}
Esempio n. 17
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;
}
Esempio n. 18
0
void HttpResponse::GetResponse(char* pszResponse, vector<byte> *pvb, DWORD dwSize)
{
	DWORD dwThreadId = GetCurrentThreadId();
	ZeroMemory(pszResponse, dwSize);
	sprintf_s(pszResponse, dwSize, "%s%s", resp_ok, "\n");
	sprintf_s(pszResponse, dwSize, "%s%s%s%s", pszResponse, "Date: " , "HTTP/1.x 200 OK" , "\n");
	std::string ctstr;
	ctstr.assign(contenType.begin(), contenType.end());
	sprintf_s(pszResponse, dwSize, "%s%s%s%s", pszResponse, "Content-Type: ", ctstr.c_str(), "\n");

	size_t siz = m_sbResponsePackage.size();
	sprintf_s(pszResponse, dwSize, "%s%s%d%s", pszResponse, "Content-Length: ", siz, "\n\n");
	std::string str;
	str.assign(pszResponse);

	std::string str2(m_sbResponsePackage.begin(), m_sbResponsePackage.end());
	str.insert(str.end(), str2.begin(), str2.end());
	sprintf_s(pszResponse, dwSize, "%s", str.c_str());
	m_sbResponsePackage.assign(str.begin(), str.end());
	pvb->assign(m_sbResponsePackage.begin(), m_sbResponsePackage.end());
}
Esempio n. 19
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;
}
Esempio n. 20
0
//Test indole with 4000 molecules and a  primary index of 1 on GPU
TEST (Indole4000Test, OnePrimaryIndex_GPU)
{

        string directory = get_current_dir_name();
        std::string mc ("MCGPU");
        std::size_t found = directory.find(mc);

        if(found != std::string::npos) {
                directory = directory.substr(0,found+6);

        }

        std::string MCGPU = directory;

        std::stringstream ss;
                ss << MCGPU << "/bin/metrosim "
                << " "
                << MCGPU << "/test/unittests/MultipleSolvents/indole4000Tests/indole4000-1MPI.config -p --threads 12 --name indole4000-1MPI-GPU -i 10000";

        //launch MCGPU in parallel
         system(ss.str().c_str());
        double expected = 588107;
        double energyResult = -1;

        std::ifstream infile(std::string(MCGPU + "bin/indole4000-1MPI-GPU.results").c_str());

        for(std::string line; getline(infile, line);) {
                std::string str2 ("Final-Energy");
                std::string result;
                found = line.find(str2);

                if (found != std::string::npos) {
                        result = line.substr(15);
                        energyResult = strtod(result.c_str(), NULL);
                        break;
                }
        }

        EXPECT_NEAR(expected, energyResult, 100);
}
Esempio n. 21
0
void str(int lvl, int &x, int &y, int a, int b, int l, int n, int k, int& superbase)
         {
                int canv=30*5;
                int pos=0;
                x=10+100*(lvl-1);
                y = y - canv;
                pos=5*((lvl-1)*ty+(y-110+canv)/canv);
                out(pos+0,x,y,"equ",a,b+l,l);
                out(pos+1,x,y,"sub",a,b,l);
                out(pos+2,x,y,"equ",a+l,b+l+l,l);
                out(pos+3,x,y,"sub",a+l,b+3*l,l);
                out(pos+4,x,y,"xchg",b+l,b+l+l,l);
                if(l!=1)//lvl==k-1//p3=3^k-1
                {
                int yy=y;
                str(lvl+1,x,y,a-n/2,b,l/2,n,k,superbase);
                y = y + 30*5;
                str(lvl+1,x,y,a-n/2+l,b+l+l,l/2,n,k,superbase);
                y = y + 30*5;
                str2(lvl+1,x,y,a+n/2,a,l/2,n,k,superbase);
                //superbase+=l;
                //y=yy;
                }
                else
                {
                        x=10+100*k;
                        int yy=y-canv;
                        pos=(5*(k-1)*ty+3*(y-110)/canv);
                        out(pos+0,x,yy,"mul",b,b+1,1);
                        out(pos+1,x,yy,"mul",b+2,b+3,1);
                        out(pos+2,x,yy,"mul",a,a+1,1);
                }
                y = y - canv;
                x=10+100*(k+k-lvl+1);
                pos=(5*(k-1)*ty+3*ty*(1+k-lvl)+3*(y-110)/canv);
                out(pos+0,x,y,"add",a,b,2*l);
                out(pos+1,x,y,"add",a,b+l+l,2*l);
                out(pos+2,x,y,"add",b+l,a,2*l);
                y = y + 30*2;
         }
Esempio n. 22
0
//Test indole with 4000 molecules and multiple solvent primary indexes of [1,2],1 on GPU
TEST (Indole4000Test, SingleMultipleIndexes2_GPU)
{

        string directory = get_current_dir_name();
        std::string mc ("MCGPU");
        std::size_t found = directory.find(mc);

        if(found != std::string::npos) {
                directory = directory.substr(0,found+6);

        }

        std::string MCGPU = directory;

        //Since this case results in an error it does not print to a '.results' file.
        //So the commandline error output is pipelined to a text file
        //The textfile is used to compare the expected and actual output
        std::stringstream ss;
                ss << MCGPU << "/bin/metrosim "
                << " "
                << MCGPU << "/test/unittests/MultipleSolvents/indole4000Tests/indole4000SingleMultipleIndexes2.config -p -i 10000 >"
                << " "
                << MCGPU << "/bin/indole4000SingleMultipleIndexes2-GPU.txt 2>&1";

        //launch MCGPU in parallel
        system(ss.str().c_str());
        std::string errorResult;
        std::ifstream infile(std::string(MCGPU + "bin/indole4000SingleMultipleIndexes2-GPU.txt").c_str());

        for(std::string line; getline(infile, line);) {
                std::string str2 ("Error");
                found = line.find(str2);
                if (found != std::string::npos) {
                       errorResult = line.substr(7,13);
                        break;
                }
        }

        EXPECT_STREQ("loadBoxData()", errorResult.c_str());
}
Esempio n. 23
0
// Unlike other contracts, which calculate their ID from a hash of the file itself, a mint has
// the same ID as its Asset Contract.  When we open the Mint file, we read the Asset Type ID
// from it and then verify that it matches what we were expecting from the asset type.
bool OTMint::VerifyContractID()
{
	// I use the == operator here because there is no != operator at this time.
	// That's why you see the ! outside the parenthesis.
	if (!(m_ID == m_AssetID))
	{
		OTString str1(m_ID), str2(m_AssetID);
		
		OTLog::vError("\nMint ID does NOT match Asset Type ID in OTMint::VerifyContractID.\n%s\n%s\n"
				//				"\nRAW FILE:\n--->%s<---"
				"\n",
				str1.Get(), str2.Get()
				//				m_strRawFile.Get()
				);
		return false;
	}
	else {
		OTString str1(m_ID);
		OTLog::vOutput(2, "\nMint ID *SUCCESSFUL* match to Asset Contract ID:\n%s\n\n", str1.Get());
		return true;
	}
}
Esempio n. 24
0
// write string to output:
inline static void OutputString(wxOutputStream& stream, const wxString& str,
#if wxUSE_UNICODE
    wxMBConv * WXUNUSED(convMem),
#else
    wxMBConv *convMem,
#endif
    wxMBConv *convFile)
{
    if (str.empty()) return;
#if wxUSE_UNICODE
    const wxWX2MBbuf buf(str.mb_str(*(convFile ? convFile : &wxConvUTF8)));
    stream.Write((const char*)buf, strlen((const char*)buf));
#else
    if ( convFile == NULL )
        stream.Write(str.mb_str(), str.Len());
    else
    {
        wxString str2(str.wc_str(*convMem), *convFile);
        stream.Write(str2.mb_str(), str2.Len());
    }
#endif
}
Esempio n. 25
0
double getEnergyResult(std::string MCGPU, std::string resultsFile) {
	std::string dir;
	if(inDebugMode())
		dir = "bin/debug/";
	else
		dir = "bin/";

	std::ifstream infile(std::string(MCGPU + dir + resultsFile).c_str());
	std::size_t found;

	for(std::string line; getline(infile, line);) {
		std::string str2 ("Final-Energy");
		std::string result;
		found = line.find(str2);
		if(found != std::string::npos) {
			result = line.substr(15);
			return strtod(result.c_str(), NULL);
		}
	}

	return -1;
}
Esempio n. 26
0
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");
}
Esempio n. 27
0
int init() {
    QTextStream out(stdout);
    
    QString str1 = "The night train";
    out << str1 << endl;
    
    QString str2("A yellow rose");
    out << str2 << endl;
    
    std::string s1 = "A blue sky";
    QString str3 = s1.c_str();
    out << str3 << endl;
    
    std::string s2 = "A think fog";
    QString str4 = QString::fromAscii(s2.data(), s2.size());
    out << str4 << endl;
    
    char s3[] = "A deep forest";
    QString str5(s3);
    out << str5 << endl;
    
    return 0;
}
Esempio n. 28
0
std::vector<std::pair<std::string, std::string>> getKeywords(std::string filePath)
{
    //The vector to return
    std::vector<std::pair<std::string, std::string>> toRet;
    
    //The two strings to make a pair with
    std::string str1(""), str2("");
    
    //Opens the file
    std::ifstream in(filePath);
    if(!in.is_open()) throw 0;
    
    //Continues to add pairs while the file is still open
    while(!in.eof())
    {
        in >> str1 >> str2;
        toRet.push_back(std::pair<std::string, std::string>(str1, str2));
    }
    
    in.close();
    
    return toRet;
}
bool OTTransactionType::VerifyContractID() const
{
    // 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 NotaryID as well.  They go hand in hand.

    if ((m_ID != m_AcctID) || (m_NotaryID != m_AcctNotaryID)) {
        String str1(m_ID), str2(m_AcctID), str3(m_NotaryID),
            str4(m_AcctNotaryID);
        otErr << "Identifiers do NOT match in "
                 "OTTransactionType::VerifyContractID.\n"
                 "m_ID: " << str1 << "\n m_AcctID: " << str2
              << "\n m_NotaryID: " << str3 << "\n m_AcctNotaryID: " << str4
              << "\n";

        //        OT_FAIL;  // I was debugging.

        return false;
    }
    else {
        //        OTString str1(m_AcctID), str2(m_AcctNotaryID);
        //        otErr << "Expected Account ID and Notary ID both *SUCCESSFUL*
        // match to "
        //                "IDs in the xml:\n Account ID:\n%s\n NotaryID:\n%s\n"
        //                "-----------------------------------------------------------------------------\n",
        //                str1.Get(), str2.Get());
        return true;
    }
}
Esempio n. 30
0
// The copy constructor used to be broken for headers with multiple values.
// http://code.google.com/p/android/issues/detail?id=6722
int CTest::test_copyConstructor(int argc, char* argv[])
{
   AutoPtr<IRawHeaders> h1;
   CRawHeaders::New((IRawHeaders**)&h1);
   String str0("key");
   String str1("value1");
   String str2("value2");
   h1->Add(str0, str1);
   h1->Add(str0, str2);
   AutoPtr<IMap> objMap;
   h1->ToMultimap((IMap**)&objMap);
   AutoPtr<IRawHeaders> h2;
   AutoPtr<IRawHeadersHelper> rawHeadersHelper;
   CRawHeadersHelper::AcquireSingleton((IRawHeadersHelper**)&rawHeadersHelper);

   rawHeadersHelper->FromMultimap(objMap, (IRawHeaders**)&h2);
   Int32 length;
   h2->Length(&length);
   assert(2 == length);

   String strOut;
   h2->GetFieldName(0, &strOut);
   Boolean flag = strOut.Equals(str0);
   assert(flag == TRUE);

   h2->GetValue(0, &strOut);
   flag = strOut.Equals(str1);
   assert(flag == TRUE);

   h2->GetFieldName(1, &strOut);
   flag = strOut.Equals(str0);
   assert(flag == TRUE);

   h2->GetValue(1, &strOut);
   flag = strOut.Equals(str2);
   assert(flag == TRUE);
}