Example #1
0
/***	ACCESSOR FUNCTION ONLY		***/
String& String::operator=(char *str) const{
/*	this->ch=new char[strlen(str)];
	this->len=strlen(str);
	strcpy(ch,str);*/
	String myString(str);
	return myString;
}
Example #2
0
int xmm::to_int(const std::string& s)
{
    std::istringstream myString(s);
    int value;
    myString >> value;
    return value;
}
Example #3
0
int main(int argc, const char * argv[]) {
    
    Value value;
    int64_t var = 98765431234;
    
    std::string myString("This is my string");
    std::list<std::string> myList;
    std::list<Value> valueList;

    // illegal because var & 0xFFFF is a rvalue;
    //value.SetValue(var & 0xFFFF);
    
    // there is no restriction when using universal refs
    value.SetValueUnivRef(var & 0xFFFF);
    
    std::cout << "Before: " << myString << std::endl;
    myList.push_back(std::move(myString));
    std::cout << "After: " << myString << std::endl;
    std::cout << "From list: "<< myList.front() << std::endl;

    std::cout << "Moving value object to the list" << std::endl;
    valueList.push_back(std::move(value));
   
    std::cout << "Moving new value object to the list" << std::endl;
    valueList.push_back(std::move(Value()));
    
    std::cout << "Adding new value object to the list without move" << std::endl;
    valueList.push_back(Value());
    
    
    return 0;
}
int main(int argc, const char * argv[])
{
    String myString("Hello");
    myString.Concatenate(" World. ");
    myString.Concatenate(myString);
    printf("%s\n", myString.c_str());
    
    return EXIT_SUCCESS;
}
Example #5
0
myString operator+ (const myString &s, const char* t) {
	char* str = new char[strlen(s.p) + strlen(t) + 1];
//	for(int i=0; i<strlen(s.p); i++) str[i]=s.p[i];
//	for(int i=0; i<strlen(t); i++) str[i+strlen(s.p)]=t[i];
//	str[strlen(s.p)+strlen(t)]='\0';
	strcpy(str, s.p);
	strcpy(str+strlen(s.p), t);
	return myString(str);
}
int main(int argc, const char * argv[])
{
    String myString("Hello");
    myString.Concatenate("World");
    myString.Concatenate(myString);
    String otherString(myString);
    String yetAnotherString("AnotherWorld");
    otherString = yetAnotherString;
    
    std::cout << otherString.c_str() << std::endl;
    
    return EXIT_SUCCESS;
}
Example #7
0
QString TodoDelegate::cutString( const QString &string, const QRect &size, const QFont &font) const
{
  QString myString(string);
  QFontMetrics metrics(font);
  if( metrics.boundingRect(myString).width()+5 < size.width() ){ // I had to add 5, else it didn't work
    return myString;
  }
  myString.append("...");
  while( metrics.boundingRect(myString).width()+5 >= size.width() ){
    myString.remove(myString.count()-4,1);
  }
  return myString;
}
Example #8
0
// -----------------------------------------------------------------
// wifi
// -----------------------------------------------------------------
bool Qaul::QaulWifiGetInterface(void)
{
    // get all wifi interfaces
    // iwconfig
    QProcess *myProcess = new QProcess(this);
    myProcess->start("iwconfig");
    // wait until process has finished
    if(!myProcess->waitForFinished(10000))
    {
        qDebug() << "iwconfig process crashed";
        return false;
    }
    //QByteArray myOutput = myProcess->readAllStandardOutput();
    QString myString(myProcess->readAllStandardOutput());
    QRegExp myRx("^([\\S]+)");
    int myPos = 0;
    if((myPos = myRx.indexIn(myString, myPos)) == -1)
    {
        qDebug() << "iwconfig returned no interface";
        return false;
    }
    // take the first interface
    // TODO: make interface list
    qaulWifiInterface = myRx.cap(1);
    qDebug() << "interface found: " << qaulWifiInterface;

    // check if interface is active
    if(!QaulWifiInterfaceActive(qaulWifiInterface))
    {
        qDebug() << "interface not active";

        // deblock wifi
        myProcess->start("rfkill unblock all");
        if(!myProcess->waitForFinished(2000))
            qDebug() << "rfkill unblock process crashed";

        // try to activate interface if not available
        myProcess->start("nmcli nm wifi on");
        if(!myProcess->waitForFinished(10000))
            qDebug() << "nmcli process crashed";

        if(!QaulWifiInterfaceActive(qaulWifiInterface)) return false;
    }

    return true;
}
vector<string> FaceFinder::Find(Mat* img,string fileName)
{
    WindowsIterator * windowsIterator;
    if (maxInitialSize==-1)
    {
        windowsIterator=new WindowsIterator(img);
    }
    else
    {
        windowsIterator=new WindowsIterator(img,maxInitialSize);
    }
    windowsIterator->SetWindowSize(classifier->GetInputGeometry());
    vector<WindowInformation> faceWindows;
    Window *window;
    vector<float> scores;
    while ((window=windowsIterator->GetNextWindow())!=NULL){
        scores=classifier->Classify(window->GetWindowImage());
        if (GetWindowLabel(scores)==1)
        {
            window->GetWindowInformation()->SetScore(scores[1]);
            faceWindows.push_back(*(window->GetWindowInformation()));
        }
    }
    CleanFaceWindows(&faceWindows);
    Drawer *drawer=new Drawer();
    drawer->DrawFaceWindows(img,&faceWindows);
    vector<string> resultTexts;
    for (unsigned int i=0;i<faceWindows.size();i++)
    {
        std::ostringstream myStringStream;
        myStringStream<<fileName<<" ";
        myStringStream<<faceWindows[i].GetScore()<<" ";
        myStringStream<<faceWindows[i].GetOriginalStartingPixel().col<<" ";
        myStringStream<<faceWindows[i].GetOriginalStartingPixel().row<<" ";
        myStringStream<<faceWindows[i].GetOriginalStartingPixel().col+faceWindows[i].GetOriginalSize().width<<" ";
        myStringStream<<faceWindows[i].GetOriginalStartingPixel().row+faceWindows[i].GetOriginalSize().height;
        string myString(myStringStream.str());
        resultTexts.push_back(myString);
    }
    return resultTexts;
}
void ResourceItemDelegate::paint(QPainter *painter,
                                 const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if (option.state & QStyle::State_Selected)
        drawSelectionBackground(painter, option);

    painter->save();

    QIcon icon(m_model->fileIcon(index));
    QPixmap pixmap(icon.pixmap(icon.availableSizes().front()));
    painter->drawPixmap(option.rect.x(),option.rect.y()+2,pixmap);
    QString myString(m_model->fileName(index));

    // Check text length does not exceed available space
    int extraSpace=12+pixmap.width();
    QFontMetrics fm(option.font);
    myString = fm.elidedText(myString,Qt::ElideMiddle,option.rect.width()-extraSpace);

    painter->drawText(option.rect.bottomLeft()+QPoint(3+pixmap.width(),-8),myString);

    painter->restore();
}
Example #11
0
bool Qaul::QaulWifiInterfaceActive(QString interface)
{
    // get all active interfaces
    // ifconfig
    QProcess *myProcess = new QProcess(this);
    myProcess->start("ifconfig");
    // wait until process has finished
    if(!myProcess->waitForFinished(10000))
    {
        qDebug() << "ifconfig process crashed";
        return false;
    }
    //QByteArray myOutput = myProcess->readAllStandardOutput();
    QString myString(myProcess->readAllStandardOutput());
    QString myLine;
    QRegExp myRxLine("([^\\n]*)\\n");
    QRegExp myRx("^([\\S]+)");
    int myPos = 0;
    // loop through output line by line
    while((myPos = myRxLine.indexIn(myString, myPos)) != -1)
    {
        qDebug() << "[detect wifi] " << myRxLine.matchedLength() << " chars: " << myRxLine.cap(1);

        myLine = myRxLine.cap(1);
        // search for interface in this line
        if(myRx.indexIn(myLine, 0) != -1)
        {
            qDebug() << "interface compare: " << myRx.cap(1);
            if(QString::compare(myRx.cap(1), interface) == 0)
            {
                qDebug() << "comparison successful";
                return true;
            }
        }
        myPos += myRxLine.matchedLength();
    }
    qDebug() << "interface not active";
    return false;
}
Example #12
0
// read configuring root process output line by line
// and search for sucess tokens
void Qaul::QaulConfigureProcessRead(void)
{
    QString myString(qaulConfigProcess->readAllStandardOutput());
    QString myLine;
    QRegExp myRxLine("([^\\n]*)\\n");
    QRegExp myRxWifi("^(qaulTokenWifi)");
    QRegExp myRxOlsr("^(qaulTokenOlsr)");
    int myPos = 0;
    // loop through output line by line
    while((myPos = myRxLine.indexIn(myString, myPos)) != -1)
    {
        qDebug() << "[config process] " << myRxLine.matchedLength() << " chars: " << myRxLine.cap(1);

        // search for tokens in this line
        if(qaulConfigureCounter == 22)
        {
            myLine = myRxLine.cap(1);
            if(myRxWifi.indexIn(myLine, 0) != -1)
            {
                qDebug() << "[SUCCESS] " << myRxWifi.cap(1);
                qaulConfigureCounter = 29;
                QaulConfigure();
            }
        }
        else if(qaulConfigureCounter == 41)
        {
            myLine = myRxLine.cap(1);
            if(myRxOlsr.indexIn(myLine, 0) != -1)
            {
                qDebug() << "[SUCCESS] " << myRxOlsr.cap(1);
                qaulConfigureCounter = 44;
                QaulConfigure();
            }
        }
        myPos += myRxLine.matchedLength();
    }
}
Example #13
0
TEST(pxScene2dTests, rtNodeTests)
{
    // Create rtNode
    extern rtScript script;

    //v8::Isolate *isolate = script.getIsolate();

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test as have isolate + init
    //EXPECT_TRUE ( isolate      != NULL);
    EXPECT_TRUE ( rtNodeInit() == true);

    double s1 = pxMilliseconds();

    // Create rtNodeContextRef
    rtScriptContextRef ctx;
    script.createContext("javascript", ctx);

    double e1 = pxMilliseconds();

    EXPECT_TRUE( ctx.getPtr()      != NULL ); // Should exist
    //EXPECT_TRUE( ctx->getIsolate() != NULL ); // Should exist

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Create test rtString and add() to JS ctx
    
    rtString myString("Foo String");
    rtError addErr = ctx->add("Foo", myString);

    EXPECT_TRUE( addErr == RT_OK);  // Should fail !

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that add() fails when expected
    {
        rtError err1 = ctx->add(NULL, rtValue());
        EXPECT_TRUE( err1 == RT_FAIL);  // Should fail !

        rtError err2 = ctx->add("EmptyFoo", rtValue());
        EXPECT_TRUE( err2 == RT_FAIL);  // Should fail !
    }
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that has() works
    
    EXPECT_TRUE( ctx->has(NULL)  == false);              // Should not exist
    EXPECT_TRUE( ctx->has("Bar") == false);              // Should not exist
    EXPECT_TRUE( ctx->has("Foo") == true);               // Should exist !
    //EXPECT_TRUE( ctx->has(std::string("Foo")) == true);  // Should exist !

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that get() works and behaves with bad params
    {
        rtValue noFoo = ctx->get("NoFoo");
        EXPECT_TRUE( noFoo.isEmpty() == true);
    }
    #if 0
    {
        rtValue noFoo = ctx->get( std::string("NoFoo") );
        EXPECT_TRUE( noFoo.isEmpty() == true);
    }
    #endif
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that get() works and behaves with bad params
    {
        rtValue foo = ctx->get("Foo");

        EXPECT_TRUE( foo.isEmpty() == false);
        EXPECT_TRUE( strcmp(foo.toString().cString(), "Foo String") == 0);
    }    
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that get() works  and behaves with bad params
    {
        rtValue foo = ctx->get(NULL);

        EXPECT_TRUE( foo.isEmpty() == true);
    }
    #if 0
    {
        rtValue foo = ctx->get( std::string("") );

        EXPECT_TRUE( foo.isEmpty() == true);
    }    
    #endif
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that get() works and can get obj from JS
    #if 0
    {
        rtValue foo = ctx->get( std::string("Foo") );

        EXPECT_TRUE( foo.isEmpty() == false);
        EXPECT_TRUE( strcmp(foo.toString().cString(), "Foo String") == 0);
    }
    #endif
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that runScript() works and can get result JS
    {
        rtValue val;
        rtError err = ctx->runScript("3 + 1", &val);

//    printf("\n val \"3 + 1\" = [%s]  \n\n", val.toString().cString());

        EXPECT_TRUE( err == RT_OK );
        EXPECT_TRUE( strcmp(val.toString().cString(), "4") == 0);
    }

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that runScript() works and detects param errors
    {
        rtValue val;
        rtError err = ctx->runScript(NULL, &val);

        EXPECT_TRUE( err == RT_FAIL );
    }
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that runScript() works and detects param errors
    #if 0
    {
        rtValue val;
        rtError err = ctx->runScript(std::string(""), &val);

        EXPECT_TRUE( err == RT_FAIL );
    }
    #endif
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that runFile() works and detects i/o errors
    {
        rtValue val;
        rtError err = ctx->runFile("supportfiles/nothere.js", &val);

        EXPECT_TRUE( err == RT_FAIL );
    }
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that runFile() works and detects NULL errors
    {
        rtValue val;
        rtError err = ctx->runFile(NULL, &val);

        EXPECT_TRUE( err == RT_FAIL );
    }
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test that runFile() works and can get result JS
    {
        rtValue val;
        rtError err = ctx->runFile("supportfiles/simple.js", &val);

        EXPECT_TRUE( err == RT_OK );
        EXPECT_TRUE( strcmp(val.toString().cString(), "Hello World") == 0);
    }
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    #if 0
    {
        EXPECT_TRUE( ctx->getIsolate()   != NULL); // Should be Non-NULL
        EXPECT_TRUE( ctx->getContextId() != 0);    // Should be Non-Zero
    }
    #endif
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Test Clone create performance.
    double total = 0.0;
    double count = 1000;

    for(int i = 0; i< count; i++)
    {
        double s = pxMilliseconds();

        // Create rtNodeContextRef - CLONE
        rtScriptContextRef ctx1;
        script.createContext("javascript", ctx1);
        EXPECT_TRUE(ctx1 != NULL);
  
        double e = pxMilliseconds();

        total += (e - s);
    }

    double t1 = (e1 - s1);      // REFERENCE  CONTEXT - create time
    double t2 = total / count;  // CONTEXTIFY CONTEXT - create time (avg)

    // printf("\n createContext() -  Non-Clone = %f ms", t1 );
    // printf("\n createContext() - With-Clone = %f ms\n\n", t2 );

    // Clone create (t2) should be significantly (4 x)  faster than Reference create.
    EXPECT_TRUE((t2 < (t1 / 4)) == true);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
}
Example #14
0
/* Astring getCellText (in long row, in nsITreeColumn col); */
NS_IMETHODIMP 
nsCertTree::GetCellText(PRInt32 row, nsITreeColumn* col, 
                        nsAString& _retval)
{
  if (!mTreeArray)
    return NS_ERROR_NOT_INITIALIZED;

  nsresult rv;
  _retval.Truncate();

  const PRUnichar* colID;
  col->GetIdConst(&colID);

  treeArrayEl *el = GetThreadDescAtIndex(row);
  if (el != nsnull) {
    if (NS_LITERAL_STRING("certcol").Equals(colID))
      _retval.Assign(el->orgName);
    else
      _retval.Truncate();
    return NS_OK;
  }

  PRInt32 absoluteCertOffset;
  nsRefPtr<nsCertTreeDispInfo> certdi = 
    GetDispInfoAtIndex(row, &absoluteCertOffset);
  if (!certdi)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIX509Cert> cert = certdi->mCert;
  if (!cert && certdi->mAddonInfo) {
    cert = certdi->mAddonInfo->mCert;
  }

  PRInt32 colIndex;
  col->GetIndex(&colIndex);
  PRUint32 arrayIndex=absoluteCertOffset+colIndex*(mNumRows-mNumOrgs);
  PRUint32 arrayLength=0;
  if (mCellText) {
    mCellText->GetLength(&arrayLength);
  }
  if (arrayIndex < arrayLength) {
    nsCOMPtr<nsISupportsString> myString(do_QueryElementAt(mCellText, arrayIndex));
    if (myString) {
      myString->GetData(_retval);
      return NS_OK;
    }
  }

  if (NS_LITERAL_STRING("certcol").Equals(colID)) {
    if (!cert) {
      mNSSComponent->GetPIPNSSBundleString("CertNotStored", _retval);
    }
    else {
      rv = cert->GetCommonName(_retval);
      if (NS_FAILED(rv) || _retval.IsEmpty()) {
        // kaie: I didn't invent the idea to cut off anything before 
        //       the first colon. :-)
        nsAutoString nick;
        rv = cert->GetNickname(nick);
        
        nsAString::const_iterator start, end, end2;
        nick.BeginReading(start);
        nick.EndReading(end);
        end2 = end;
  
        if (FindInReadable(NS_LITERAL_STRING(":"), start, end)) {
          // found. end points to the first char after the colon,
          // that's what we want.
          _retval = Substring(end, end2);
        }
        else {
          _retval = nick;
        }
      }
    }
  } else if (NS_LITERAL_STRING("tokencol").Equals(colID) && cert) {
    rv = cert->GetTokenName(_retval);
  } else if (NS_LITERAL_STRING("emailcol").Equals(colID) && cert) {
    rv = cert->GetEmailAddress(_retval);
  } else if (NS_LITERAL_STRING("purposecol").Equals(colID) && mNSSComponent && cert) {
    PRUint32 verified;

    nsAutoString theUsages;
    rv = cert->GetUsagesString(false, &verified, theUsages); // allow OCSP
    if (NS_FAILED(rv)) {
      verified = nsIX509Cert::NOT_VERIFIED_UNKNOWN;
    }

    switch (verified) {
      case nsIX509Cert::VERIFIED_OK:
        _retval = theUsages;
        break;

      case nsIX509Cert::CERT_REVOKED:
        rv = mNSSComponent->GetPIPNSSBundleString("VerifyRevoked", _retval);
        break;
      case nsIX509Cert::CERT_EXPIRED:
        rv = mNSSComponent->GetPIPNSSBundleString("VerifyExpired", _retval);
        break;
      case nsIX509Cert::CERT_NOT_TRUSTED:
        rv = mNSSComponent->GetPIPNSSBundleString("VerifyNotTrusted", _retval);
        break;
      case nsIX509Cert::ISSUER_NOT_TRUSTED:
        rv = mNSSComponent->GetPIPNSSBundleString("VerifyIssuerNotTrusted", _retval);
        break;
      case nsIX509Cert::ISSUER_UNKNOWN:
        rv = mNSSComponent->GetPIPNSSBundleString("VerifyIssuerUnknown", _retval);
        break;
      case nsIX509Cert::INVALID_CA:
        rv = mNSSComponent->GetPIPNSSBundleString("VerifyInvalidCA", _retval);
        break;
      case nsIX509Cert::NOT_VERIFIED_UNKNOWN:
      case nsIX509Cert::USAGE_NOT_ALLOWED:
      default:
        rv = mNSSComponent->GetPIPNSSBundleString("VerifyUnknown", _retval);
        break;
    }
  } else if (NS_LITERAL_STRING("issuedcol").Equals(colID) && cert) {
    nsCOMPtr<nsIX509CertValidity> validity;

    rv = cert->GetValidity(getter_AddRefs(validity));
    if (NS_SUCCEEDED(rv)) {
      validity->GetNotBeforeLocalDay(_retval);
    }
  } else if (NS_LITERAL_STRING("expiredcol").Equals(colID) && cert) {
    nsCOMPtr<nsIX509CertValidity> validity;

    rv = cert->GetValidity(getter_AddRefs(validity));
    if (NS_SUCCEEDED(rv)) {
      validity->GetNotAfterLocalDay(_retval);
    }
  } else if (NS_LITERAL_STRING("serialnumcol").Equals(colID) && cert) {
    rv = cert->GetSerialNumber(_retval);


  } else if (NS_LITERAL_STRING("overridetypecol").Equals(colID)) {
    // default to classic permanent-trust
    nsCertOverride::OverrideBits ob = nsCertOverride::ob_Untrusted;
    if (certdi->mTypeOfEntry == nsCertTreeDispInfo::host_port_override) {
      ob = certdi->mOverrideBits;
    }
    nsCAutoString temp;
    nsCertOverride::convertBitsToString(ob, temp);
    _retval = NS_ConvertUTF8toUTF16(temp);
  } else if (NS_LITERAL_STRING("sitecol").Equals(colID)) {
    if (certdi->mTypeOfEntry == nsCertTreeDispInfo::host_port_override) {
      nsCAutoString hostPort;
      nsCertOverrideService::GetHostWithPort(certdi->mAsciiHost, certdi->mPort, hostPort);
      _retval = NS_ConvertUTF8toUTF16(hostPort);
    }
    else {
      _retval = NS_LITERAL_STRING("*");
    }
  } else if (NS_LITERAL_STRING("lifetimecol").Equals(colID)) {
    const char *stringID = 
      (certdi->mIsTemporary) ? "CertExceptionTemporary" : "CertExceptionPermanent";
    rv = mNSSComponent->GetPIPNSSBundleString(stringID, _retval);
  } else if (NS_LITERAL_STRING("typecol").Equals(colID) && cert) {
    nsCOMPtr<nsIX509Cert2> pipCert = do_QueryInterface(cert);
    PRUint32 type = nsIX509Cert::UNKNOWN_CERT;

    if (pipCert) {
	rv = pipCert->GetCertType(&type);
    }

    switch (type) {
    case nsIX509Cert::USER_CERT:
        rv = mNSSComponent->GetPIPNSSBundleString("CertUser", _retval);
	break;
    case nsIX509Cert::CA_CERT:
        rv = mNSSComponent->GetPIPNSSBundleString("CertCA", _retval);
	break;
    case nsIX509Cert::SERVER_CERT:
        rv = mNSSComponent->GetPIPNSSBundleString("CertSSL", _retval);
	break;
    case nsIX509Cert::EMAIL_CERT:
        rv = mNSSComponent->GetPIPNSSBundleString("CertEmail", _retval);
	break;
    default:
        rv = mNSSComponent->GetPIPNSSBundleString("CertUnknown", _retval);
	break;
    }

  } else {
    return NS_ERROR_FAILURE;
  }
  if (mCellText) {
    nsCOMPtr<nsISupportsString> text(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);
    text->SetData(_retval);
    mCellText->ReplaceElementAt(text, arrayIndex, false);
  }
  return rv;
}