void ReadModelList(void) { if (templateModelList.lLength > 0) return; _String modelListFile (_HYStandardDirectory (HY_HBL_DIRECTORY_TEMPLATE_MODELS) & "models.lst"); FILE* modelList = doFileOpen (modelListFile.getStr(),"rb"); if (!modelList) { return; } _String theData (modelList); fclose (modelList); if (theData.sLength) { _ElementaryCommand::ExtractConditions(theData,0,templateModelList); for (unsigned long i = 0; i<templateModelList.countitems(); i++) { _String* thisString = (_String*)templateModelList(i); _List thisModel; _ElementaryCommand::ExtractConditions(*thisString,thisString->FirstNonSpaceIndex(),thisModel,','); if (thisModel.lLength!=5) { templateModelList.Delete(i); i--; continue; } for (long j = 0; j<5; j++) { ((_String*)thisModel(j))->StripQuotes(); } ((_String*)thisModel(0))->UpCase(); templateModelList.Replace(i,&thisModel,true); } } }
FBL_Begin_Namespace /**********************************************************************************************/ void Clone_Current_Value( VALUE_TYPE inFldType, I_Field_Ptr inSourceFld, I_Field_Ptr inTargetFld ) { switch( inFldType ) { case kTypeSound: case kTypeMovie: case kTypeBLOB: // Commented because this way we must read/write TEXT as STRING to avoid // double read/write (we use FirstRecord()/NextRecord() for source table and therefore // src TEXT field already has its value). // case kTypeText: case kTypePicture: { try { if( inSourceFld->get_IsNull() == false ) { I_FldBlob_Ptr sourceBlobFld = QI( inSourceFld, I_FldBlob ); FBL_CHECK( sourceBlobFld ); vuint32 datasize = sourceBlobFld->get_DataSize(); if( datasize ) { MemPtr<char> theData( datasize ); sourceBlobFld->ReadData( theData, datasize ); I_FldBlob_Ptr targetBlobFld = QI( inTargetFld, I_FldBlob ); targetBlobFld->WriteData( theData, datasize ); } else { // Zero data but not sql-NULL. I_FldBlob_Ptr targetBlobFld = QI( inTargetFld, I_FldBlob ); targetBlobFld->WriteData( nullptr, 0 ); } } } catch(...) { } } break; default: { // Common case: inTargetFld->put_Value( inSourceFld->get_Value() ); } break; } }
int main(int argc, char** argv) { typedef BW::CompressedArray<3, float> CA; typedef CA::V V; vigra::MultiArray<3,float> theData(V(100,200,300)); FillRandom<float, typename vigra::MultiArray<3,float>::iterator>::fillRandom(theData.begin(), theData.end()); CALLGRIND_START_INSTRUMENTATION; CA ca(theData); CALLGRIND_STOP_INSTRUMENTATION; }
// static bool OTKeyring::Gnome_StoreSecret(const OTString& strUser, const OTPassword& thePassword, const std::string& str_display) { OT_ASSERT(strUser.Exists()); OT_ASSERT(thePassword.getMemorySize() > 0); OTData theData(thePassword.getMemory(), thePassword.getMemorySize()); OTASCIIArmor ascData(theData); theData.zeroMemory(); // security reasons. OTString strOutput; const bool bSuccess = ascData.Exists() && ascData.WriteArmoredString(strOutput, "DERIVED KEY"); // There's no // default, to // force you to // enter the right // string. ascData.zeroMemory(); GnomeKeyringResult theResult = GNOME_KEYRING_RESULT_IO_ERROR; if (bSuccess && strOutput.Exists()) { theResult = gnome_keyring_store_password_sync( GNOME_KEYRING_NETWORK_PASSWORD, GNOME_KEYRING_DEFAULT, // GNOME_KEYRING_SESSION, str_display.c_str(), strOutput.Get(), "user", strUser.Get(), "protocol", "opentxs", // todo: hardcoding. nullptr); strOutput.zeroMemory(); bool bResult = false; if (theResult == GNOME_KEYRING_RESULT_OK) bResult = true; else otErr << "OTKeyring::Gnome_StoreSecret: " << "Failure in gnome_keyring_store_password_sync: " << gnome_keyring_result_to_message(theResult) << '\n'; return bResult; } otOut << "OTKeyring::Gnome_StoreSecret: No secret to store.\n"; return false; }
void DataSetIO::SaveDataSet(const DataSet& dataSet_, const std::string& filename_){ // Get the relevant params hsize_t nEntries = dataSet_.GetNEntries(); hsize_t nObs = dataSet_.GetNObservables(); hsize_t nData = nObs * nEntries; // create colon separated string from list of observables std::vector<std::string> observableNames = dataSet_.GetObservableNames(); if (observableNames.size() != nObs) throw HdfIOError("SaveDataSet::Require one name and one name only for each observable"); // Set up files H5::H5File file(filename_, H5F_ACC_TRUNC); // Flatten data into 1D array // HDF5 likes c arrays. Here use a vector and pass pointer to first element // memory guaranteed to be contiguous std::vector<double> flattenedData; std::vector<double> eventData; flattenedData.reserve(nData); for(size_t i = 0; i < nEntries; i++){ eventData = dataSet_.GetEntry(i).GetData(); flattenedData.insert(flattenedData.end(), eventData.begin(), eventData.end()); } // Set up the data set // 1D, ndata long, called "observations". Saved as native doubles on this computer H5::DataSpace dataSpace(1, &nData); H5::DataSet theData(file.createDataSet("observations", H5::PredType::NATIVE_DOUBLE, dataSpace)); // Set up the attributes - the number of obs per event and the names of the observables // 64 chars max in str to save space H5::StrType strType(H5::PredType::C_S1, 64); H5::DataSpace attSpace(H5S_SCALAR); H5::Attribute obsListAtt = theData.createAttribute("observed_quantities", strType, attSpace); obsListAtt.write(strType, FlattenStringVector(observableNames, fDelimiter)); H5::Attribute countAtt = theData.createAttribute("n_observables", H5::PredType::NATIVE_INT, attSpace); countAtt.write(H5::PredType::NATIVE_INT, &nObs); // Write the data theData.write(&flattenedData.at(0), H5::PredType::NATIVE_DOUBLE); }
// static bool OTKeyring::KWallet_StoreSecret(const OTString& strUser, const OTPassword& thePassword, const std::string& str_display) { OT_ASSERT(strUser.Exists()); OT_ASSERT(thePassword.getMemorySize() > 0); KWallet::Wallet* pWallet = OTKeyring::OpenKWallet(); if (nullptr != pWallet) { const QString qstrKey(strUser.Get()); OTData theData(thePassword.getMemory(), thePassword.getMemorySize()); OTASCIIArmor ascData(theData); theData.zeroMemory(); // security reasons. OTString strOutput; const bool bSuccess = ascData.Exists() && ascData.WriteArmoredString( strOutput, "DERIVED KEY"); // There's no default, to force you // to enter the right string. ascData.zeroMemory(); // Set the password // bool bReturnVal = false; if (bSuccess && strOutput.Exists() && pWallet->writePassword(qstrKey, QString::fromUtf8(strOutput.Get())) == 0) bReturnVal = true; else otErr << "OTKeyring::KWallet_StoreSecret: Failed trying to store " "secret into KWallet.\n"; strOutput.zeroMemory(); return bReturnVal; } otErr << "OTKeyring::KWallet_StoreSecret: Unable to open kwallet.\n"; return false; }
//__________________________________________________________________________________ void ReadInTemplateFiles(void) { _String fileIndex; fileIndex = *((_String*)pathNames(0)) &"TemplateBatchFiles/files.lst"; FILE* modelList = fopen (fileIndex.getStr(),"r"); if (!modelList) { fileIndex = baseArgDir&"TemplateBatchFiles/files.lst"; modelList = fopen (fileIndex.getStr(),"r"); if (!modelList) return; } else baseArgDir = *((_String*)pathNames(0)); fseek (modelList,0,SEEK_END); unsigned long fLength = ftell(modelList); if (fLength) { rewind (modelList); _String theData (fLength); fread (theData.getStr(),sizeof (char), fLength, modelList); _ElementaryCommand::ExtractConditions(theData,0,availableTemplateFiles); for (long i = 0; i<availableTemplateFiles.countitems(); i++) { _String* thisString = (_String*)availableTemplateFiles(i); _List thisFile; _ElementaryCommand::ExtractConditions(*thisString,thisString->FirstNonSpaceIndex(),thisFile,','); if (thisFile.lLength!=3) { availableTemplateFiles.Delete(i); i--; continue; } for (long j = 0; j<3; j++) ((_String*)thisFile(j))->StripQuotes(); availableTemplateFiles.Replace(i,&thisFile,true); } } }
XObjectPtr FunctionString::execute( XPathExecutionContext& executionContext, XalanNode* context, const LocatorType* locator) const { if (context == 0) { XPathExecutionContext::GetAndReleaseCachedString theGuard(executionContext); XalanDOMString& theResult = theGuard.get(); executionContext.error( XalanMessageLoader::getMessage( theResult, XalanMessages::FunctionRequiresNonNullContextNode_1Param, "string"), context, locator); // Dummy return value... return XObjectPtr(); } else { // The XPath standard says that if there are no arguments, // the argument defaults to a node set with the context node // as the only member. The string value of a node set is the // string value of the first node in the node set. // DOMServices::getNodeData() will give us the data. // Get a cached string... XPathExecutionContext::GetAndReleaseCachedString theData(executionContext); XalanDOMString& theString = theData.get(); DOMServices::getNodeData(*context, theString); return executionContext.getXObjectFactory().createString(theData); } }
// static bool OTKeyring::FlatFile_StoreSecret(const String& strUser, const OTPassword& thePassword, const std::string& str_display) { OT_ASSERT(strUser.Exists()); OT_ASSERT(thePassword.getMemorySize() > 0); const std::string str_pw_folder(OTKeyring::FlatFile_GetPasswordFolder()); if (!str_pw_folder.empty()) { String strExactPath; strExactPath.Format("%s%s%s", str_pw_folder.c_str(), Log::PathSeparator(), strUser.Get()); const std::string str_ExactPath(strExactPath.Get()); OTData theData(thePassword.getMemory(), thePassword.getMemorySize()); OTASCIIArmor ascData(theData); theData.zeroMemory(); // security reasons. // Save the password // const bool bSaved = ascData.Exists() && ascData.SaveToExactPath(str_ExactPath); ascData.zeroMemory(); if (!bSaved) otErr << "OTKeyring::FlatFile_StoreSecret: Failed trying to store " "secret.\n"; return bSaved; } otErr << "OTKeyring::FlatFile_StoreSecret: Unable to cache derived key, " "since password_folder not provided in config file.\n"; return false; }
//constructors static server::bhnode::constFuture construct_node( const id_type gid, const double dat[7], const bool root){ std::vector<double> theData(dat,dat+7); return lcos::eager_future<server::bhnode::constNodeAction, int>(gid,gid,theData,root); }
//__________________________________________________________________________________ void ReadInPostFiles(void) { //if (!likeFuncList.lLength) // return; _String fileIndex; FILE* modelList = fopen (fileIndex.getStr(),"r"); fileIndex = baseArgDir &"TemplateBatchFiles/postprocessors.lst"; modelList = fopen (fileIndex.getStr(),"r"); fseek (modelList,0,SEEK_END); unsigned long fLength = ftell(modelList); fseek (modelList,0,SEEK_END); fLength = ftell(modelList); if (fLength) { rewind (modelList); _String theData (fLength); fread (theData.getStr(),sizeof (char), fLength, modelList); _ElementaryCommand::ExtractConditions(theData,0,availablePostProcessors); for (long i = 0; i<availablePostProcessors.countitems(); i++) { _String* thisString = (_String*)availablePostProcessors(i); _List thisFile; _ElementaryCommand::ExtractConditions(*thisString,thisString->FirstNonSpaceIndex(),thisFile,','); if (thisFile.lLength!=3) { availablePostProcessors.Delete(i); i--; continue; } for (long j = 0; j<3; j++) ((_String*)thisFile(j))->StripQuotes(); if (*(_String*)thisFile(0)!=_String("SEPARATOR")) { fileIndex = *((_String*)pathNames(0)) &"TemplateBatchFiles/" & *(_String*)thisFile(1); FILE* dummyFile = fopen (fileIndex,"r"); if (!dummyFile) { fileIndex =baseArgDir&"TemplateBatchFiles/"& *(_String*)thisFile(1); dummyFile = fopen (fileIndex,"r"); } if (dummyFile) { fclose (dummyFile); _String* condition = (_String*)thisFile(2); if (condition->sLength) { _Formula condCheck (*condition,nil); _PMathObj condCheckRes = condCheck.Compute(); if ((!condCheckRes)||(condCheckRes->Value()<.5)) { availablePostProcessors.Delete(i); i--; continue; } } *(_String*)thisFile(1) = fileIndex; availablePostProcessors.Replace(i,&thisFile,true); continue; } } availablePostProcessors.Delete(i); i--; } } }