int main(){

  std::cout << std::endl;

  {
    std::shared_ptr<int> sharedPtr1( new int,IntDeleter() );
    std::shared_ptr<int> sharedPtr2( new int,IntDeleter() );
    auto intDeleter= std::get_deleter<IntDeleter>(sharedPtr1);
    intDeleter->getInfo();
    sharedPtr2.reset();
    intDeleter->getInfo();

  }
  createRandomNumbers();
  IntDeleter().getInfo();

  {
    // create three Smart pointer for doubles
    std::unique_ptr<double,DoubleDeleter > uniquePtr( new double, DoubleDeleter() );
    std::unique_ptr<double,DoubleDeleter > uniquePtr1( new double, DoubleDeleter() );
    std::shared_ptr<double> sharedPtr( new double, DoubleDeleter() );

    std::shared_ptr<double> sharedPtr4(std::move(uniquePtr));
    std::shared_ptr<double> sharedPtr5= std::move(uniquePtr1);
    DoubleDeleter().getInfo();
  }

  DoubleDeleter().getInfo();

}
Exemple #2
0
void TestCppTools::BasicSharedPointer_test()
{
    int spyHint = 0;
    {
        DeleteHook* delHook = new DeleteHook(-1, &spyHint);
        cpp::BasicSharedPointer<DeleteHook> sharedPtr(delHook);
    }
    QCOMPARE(spyHint, -1);

    spyHint = 0;
    {
        DeleteHook* delHook = new DeleteHook(-1, &spyHint);
        cpp::BasicSharedPointer<DeleteHook> sharedPtr(delHook);
        QCOMPARE(sharedPtr.data(), delHook);

        cpp::BasicSharedPointer<DeleteHook> sharedPtr1;
        QVERIFY(sharedPtr1.isNull());
        sharedPtr1 = sharedPtr;
        QCOMPARE(sharedPtr1.data(), delHook);
    }
    QCOMPARE(spyHint, -1);
}
std::tr1::shared_ptr<ParameterObject> Sphere::createDialog()
{
    return std::tr1::shared_ptr<ParameterObject>(new ParameterSphere(sharedPtr()));
}
bool MainFile::LoadMainFile(bool bReadOnly)
{
    if (!OTDB::Exists(".", server_->m_strWalletFilename.Get())) {
        Log::vError("%s: Error finding file: %s\n", __FUNCTION__,
                    server_->m_strWalletFilename.Get());
        return false;
    }
    String strFileContents(OTDB::QueryPlainString(
        ".",
        server_->m_strWalletFilename.Get())); // <=== LOADING FROM DATA STORE.

    if (!strFileContents.Exists()) {
        Log::vError("%s: Unable to read main file: %s\n", __FUNCTION__,
                    server_->m_strWalletFilename.Get());
        return false;
    }

    bool bNeedToSaveAgain = false;

    bool bFailure = false;

    {
        OTStringXML xmlFileContents(strFileContents);

        if (false ==
            xmlFileContents.DecodeIfArmored()) // bEscapedIsAllowed=true by
                                               // default.
        {
            Log::vError("%s: Notary server file apparently was encoded and "
                        "then failed decoding. Filename: %s \n"
                        "Contents: \n%s\n",
                        __FUNCTION__, server_->m_strWalletFilename.Get(),
                        strFileContents.Get());
            return false;
        }
        irr::io::IrrXMLReader* xml =
            irr::io::createIrrXMLReader(xmlFileContents);
        std::unique_ptr<irr::io::IrrXMLReader> theXMLGuardian(xml);
        while (xml && xml->read()) {
            // strings for storing the data that we want to read out of the file

            String AssetName;
            String InstrumentDefinitionID;

            const String strNodeName(xml->getNodeName());

            switch (xml->getNodeType()) {
            case irr::io::EXN_TEXT:
                // in this xml file, the only text which occurs is the
                // messageText
                // messageText = xml->getNodeData();
                break;
            case irr::io::EXN_ELEMENT: {
                if (strNodeName.Compare("notaryServer")) {
                    version_ = xml->getAttributeValue("version");
                    server_->m_strNotaryID = xml->getAttributeValue("notaryID");
                    server_->m_strServerNymID =
                        xml->getAttributeValue("serverNymID");

                    String strTransactionNumber; // The server issues
                                                 // transaction numbers and
                                                 // stores the counter here
                                                 // for the latest one.
                    strTransactionNumber =
                        xml->getAttributeValue("transactionNum");
                    server_->transactor_.transactionNumber(
                        strTransactionNumber.ToLong());

                    Log::vOutput(
                        0,
                        "\nLoading Open Transactions server. File version: %s\n"
                        " Last Issued Transaction Number: %" PRId64
                        "\n Notary ID:     "
                        " %s\n Server Nym ID: %s\n",
                        version_.c_str(),
                        server_->transactor_.transactionNumber(),
                        server_->m_strNotaryID.Get(),
                        server_->m_strServerNymID.Get());

                }
                // todo in the future just remove masterkey. I'm leaving it for
                // now so people's
                // data files can get converted over. After a while just remove
                // it.
                //
                else if (strNodeName.Compare("masterKey") ||
                         strNodeName.Compare("cachedKey")) {
                    OTASCIIArmor ascCachedKey;

                    if (Contract::LoadEncodedTextField(xml, ascCachedKey)) {
                        // We successfully loaded the masterKey from file, so
                        // let's SET it
                        // as the master key globally...
                        //
                        OTCachedKey::It()->SetCachedKey(ascCachedKey);

                        if (!OTCachedKey::It()->HasHashCheck()) {
                            OTPassword tempPassword;
                            tempPassword.zeroMemory();
                            std::shared_ptr<OTCachedKey> sharedPtr(
                                OTCachedKey::It());
                            bNeedToSaveAgain = sharedPtr->GetMasterPassword(
                                sharedPtr, tempPassword,
                                "We do not have a check hash yet for this "
                                "password, "
                                "please enter your password",
                                true);
                        }
                    }

                    Log::vOutput(0, "\nLoading cachedKey:\n%s\n",
                                 ascCachedKey.Get());
                    //
                    // It's only here, AFTER the master key has been loaded,
                    // that we can
                    // go ahead and load the server user, the server contract,
                    // cron, etc.
                    // (It wasn't that way in version 1, before we had master
                    // keys.)
                    //
                    // This is, for example, 2.0
                    if (version_ != "1.0") {
                        if (!LoadServerUserAndContract()) {
                            Log::vError("%s: Failed calling "
                                        "LoadServerUserAndContract.\n",
                                        __FUNCTION__);
                            bFailure = true;
                        }
                    }
                }
                else if (strNodeName.Compare("accountList")) // the voucher
                                                               // reserve
                                                               // account IDs.
                {
                    const String strAcctType = xml->getAttributeValue("type");
                    const String strAcctCount = xml->getAttributeValue("count");

                    if ((-1) ==
                        server_->transactor_.voucherAccounts_.ReadFromXMLNode(
                            xml, strAcctType, strAcctCount))
                        Log::vError("%s: Error loading voucher accountList.\n",
                                    __FUNCTION__);
                }
                else if (strNodeName.Compare("basketInfo")) {
                    String strBasketID = xml->getAttributeValue("basketID");
                    String strBasketAcctID =
                        xml->getAttributeValue("basketAcctID");
                    String strBasketContractID =
                        xml->getAttributeValue("basketContractID");

                    const Identifier BASKET_ID(strBasketID),
                        BASKET_ACCT_ID(strBasketAcctID),
                        BASKET_CONTRACT_ID(strBasketContractID);

                    if (server_->transactor_.addBasketAccountID(
                            BASKET_ID, BASKET_ACCT_ID, BASKET_CONTRACT_ID))
                        Log::vOutput(0, "Loading basket currency info...\n "
                                        "Basket ID: %s\n Basket Acct ID: "
                                        "%s\n Basket Contract ID: %s\n",
                                     strBasketID.Get(), strBasketAcctID.Get(),
                                     strBasketContractID.Get());
                    else
                        Log::vError("Error adding basket currency info...\n "
                                    "Basket ID: %s\n Basket Acct ID: %s\n",
                                    strBasketID.Get(), strBasketAcctID.Get());
                }

                // Create an OTAssetContract and load them from file, (for each
                // instrument definition),
                // and add them to the internal map.
                else if (strNodeName.Compare("assetType")) {
                    OTASCIIArmor ascAssetName = xml->getAttributeValue("name");

                    if (ascAssetName.Exists())
                        ascAssetName.GetString(AssetName,
                                               false); // linebreaks == false

                    InstrumentDefinitionID = xml->getAttributeValue(
                        "instrumentDefinitionID"); // hash of contract itself

                    Log::vOutput(0, "\n\n****Asset Contract**** (server "
                                    "listing)\n Name: %s\n Contract ID: %s\n",
                                 AssetName.Get(), InstrumentDefinitionID.Get());

                    String strContractPath;
                    strContractPath = OTFolders::Contract().Get();

                    AssetContract* pContract = new AssetContract(
                        AssetName, strContractPath, InstrumentDefinitionID,
                        InstrumentDefinitionID);

                    OT_ASSERT_MSG(nullptr != pContract,
                                  "ASSERT: allocating memory for Asset "
                                  "Contract in MainFile::LoadMainFile\n");

                    if (pContract->LoadContract()) {
                        if (pContract->VerifyContract()) {
                            Log::Output(0, "** Asset Contract Verified **\n");

                            pContract->SetName(AssetName);

                            server_->transactor_
                                .contractsMap_[InstrumentDefinitionID.Get()] =
                                pContract;
                            App::Me().DHT().Insert(
                                InstrumentDefinitionID.Get(),
                                *pContract);
                        }
                        else {
                            delete pContract;
                            pContract = nullptr;
                            Log::Output(0,
                                        "Asset Contract FAILED to verify.\n");
                        }
                    }
                    else {
                        delete pContract;
                        pContract = nullptr;
                        Log::vOutput(
                            0, "%s: Failed reading file for Asset Contract.\n",
                            __FUNCTION__);
                    }
                }
                else {
                    // unknown element type
                    Log::vError("%s: Unknown element type: %s\n", __FUNCTION__,
                                xml->getNodeName());
                }
            } break;
            default:
                break;
            }
        }
    }
    if (!bReadOnly) {
        {
            if (bNeedToSaveAgain)
                SaveMainFile();
        }
    }
    return !bFailure;
}
bool MainFile::CreateMainFile(const std::string& strContract,
                              const std::string& strNotaryID,
                              const std::string& strCert,
                              const std::string& strNymID,
                              const std::string& strCachedKey)
{
    if (!OTDB::StorePlainString(strContract, "contracts", strNotaryID)) {
        Log::Error("Failed trying to store the server contract.\n");
        return false;
    }

    if (!strCert.empty() &&
        !OTDB::StorePlainString(strCert, "certs", strNymID)) {
        Log::Error(
            "Failed trying to store the server Nym's public/private cert.\n");
        return false;
    }

    const char* szBlankFile = // todo hardcoding.
        "<notaryServer version=\"2.0\"\n"
        " notaryID=\"%s\"\n"
        " serverNymID=\"%s\"\n"
        " transactionNum=\"%ld\" >\n"
        "\n"
        "<cachedKey>\n"
        "%s</cachedKey>\n"
        "\n"
        "<accountList type=\"voucher\" count=\"0\" >\n"
        "\n"
        "</accountList>\n"
        "\n"
        "</notaryServer>\n\n";

    int64_t lTransNum = 5; // a starting point, for the new server.

    String strNotaryFile;
    strNotaryFile.Format(szBlankFile, strNotaryID.c_str(), strNymID.c_str(),
                         lTransNum, strCachedKey.c_str());

    std::string str_Notary(strNotaryFile.Get());

    if (!OTDB::StorePlainString(str_Notary, ".",
                                "notaryServer.xml")) // todo hardcoding.
    {
        Log::Error("Failed trying to store the new notaryServer.xml file.\n");
        return false;
    }
    OTASCIIArmor ascCachedKey;
    ascCachedKey.Set(strCachedKey.c_str());
    OTCachedKey::It()->SetCachedKey(ascCachedKey);

    if (!OTCachedKey::It()->HasHashCheck()) {
        OTPassword tempPassword;
        tempPassword.zeroMemory();
        std::shared_ptr<OTCachedKey> sharedPtr(OTCachedKey::It());
        sharedPtr->GetMasterPassword(
            sharedPtr, tempPassword,
            "We do not have a check hash yet for this password, "
            "please enter your password",
            true);
        if (!SaveMainFile()) {
            OT_FAIL;
        }
    }
    // At this point, the contract is saved, the cert is saved, and the
    // notaryServer.xml file
    // is saved. All we have left is the Nymfile, which we'll create.

    const String strServerNymID(strNymID.c_str());

    server_->m_nymServer.SetIdentifier(strServerNymID);

    if (!server_->m_nymServer.LoadCredentials(true)) {
        Log::vOutput(0, "%s: Error loading server credentials, or "
                        "certificate and private key.\n",
                     __FUNCTION__);
    }
    else if (!server_->m_nymServer.VerifyPseudonym()) {
        Log::vOutput(0, "%s: Error verifying server nym. Are you sure you "
                        "have the right ID?\n",
                     __FUNCTION__);
    }
    else if (!server_->m_nymServer.SaveSignedNymfile(server_->m_nymServer)) {
        Log::vOutput(0, "%s: Error saving new nymfile for server nym.\n",
                     __FUNCTION__);
    }
    else {
        Log::vOutput(0, "%s: OKAY, we have apparently created the new "
                        "server.\n"
                        "Let's try to load up your new server contract...\n",
                     __FUNCTION__);
        return true;
    }

    return false;
}
Exemple #6
0
 template <class U> static std::tr1::shared_ptr<U> internalConstruct(U * u){
     std::tr1::shared_ptr<U> retval(u);
     std::tr1::shared_ptr<T> sharedPtr(retval);
     sharedPtr->mWeakPtr=sharedPtr;
     return retval;
 }
Exemple #7
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
VolumeMesh::Pointer VolumeMesh::New( QObject* parent)
{
  Pointer sharedPtr(new VolumeMesh(parent));
  return sharedPtr;
}
std::tr1::shared_ptr<Parameterdialog> RandomdotStereogram::createDialog()
{
	return std::tr1::shared_ptr<Parameterdialog>(new ParameterRandomDot(sharedPtr()));
}
std::tr1::shared_ptr<Scene const> Scene::scene() const
{
	return std::tr1::dynamic_pointer_cast<Scene const>(sharedPtr());
}
std::tr1::shared_ptr<Scene> Scene::getScene()
{
	return std::tr1::dynamic_pointer_cast<Scene,Object>(sharedPtr());
}
std::tr1::shared_ptr<Container> Scene::getParent()
{
	return std::tr1::dynamic_pointer_cast<Container,Object>(sharedPtr());
}
std::tr1::shared_ptr<ParameterObject> Scene::createDialog()
{
	std::tr1::shared_ptr<Scene> thisPtr = std::tr1::dynamic_pointer_cast<Scene>(sharedPtr());
	return std::tr1::shared_ptr<ParameterObject>(new ParameterScene(thisPtr));
}
const AnimSet* AnimationAllocator::requestPtr(const std::string& rFileName)
{
    const AnimSet* constAnimSetPtr = NULL;
    auto it_find = m_animationSets.find(rFileName);
    bool parsedSuccess;

    if(it_find != m_animationSets.end())//if it exists
    {
        constAnimSetPtr = &*(it_find->second);
    }
    else//if it doesn't exist
    {

        std::tr1::shared_ptr<AnimSet> sharedPtr(new AnimSet);
        Json::Value root;//Let's parse it
        Json::Reader reader;
        std::ifstream test(rFileName, std::ifstream::binary);
        parsedSuccess = reader.parse(test, root, false);

        if(parsedSuccess)
        {
            std::vector<int> copyPositions;//positions of settings that need a copy of another setting
            const Json::Value stateList = root["stateList"];

            int counter = 0;
            for(auto it = stateList.begin(); it != stateList.end(); ++it)//get all the state settings
            {
                if(not (*it)["copyFrom"].isNull())//check if we have some value to copy from
                {
                    copyPositions.push_back(counter);//store us for later
                }
                else//copy that data to one of our animation states
                {
                    AnimationSetting setting;
                    setting.delay = (*it)["delay"].asFloat();
                    setting.nextState = (*it)["nextState"].asString();
                    setting.texTileSize = sf::Vector2f(root["texTileSize"][0].asInt(), root["texTileSize"][1].asInt());

                    const Json::Value tileList = (*it)["tileList"];
                    for(unsigned int i = 0; i<tileList.size(); i+=2)
                    {
                        setting.sequence.push_back(sf::Vector2f(tileList[i].asInt(), tileList[i+1].asInt()));
                    }

                    (*sharedPtr)[(*it)["state"].asString()] = setting;
                }
                ++counter;
            }


            for(auto it = copyPositions.begin(); it != copyPositions.end(); ++it)
            {
                (*sharedPtr)[stateList[*it]["animState"].asString()] = (*sharedPtr)[stateList[*it]["copyFrom"].asString()];
            }

            m_animationSets[rFileName] = sharedPtr;//if everything went right, we can add it to our list
            constAnimSetPtr = &*(m_animationSets[rFileName]);
        }
        else//we failed to parse successfully
        {
            std::cout << "\nFailed to parse JSON file [" << rFileName << "]." << std::endl << FILELINE;
            ///ERROR LOG

            constAnimSetPtr = this->requestPtr("textures/default.acfg");///why doesn't this work, this causes crash?
        }
    }

    return constAnimSetPtr;
}