本文整理汇总了C++中Datum::getNElements方法的典型用法代码示例。如果您正苦于以下问题:C++ Datum::getNElements方法的具体用法?C++ Datum::getNElements怎么用?C++ Datum::getNElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datum
的用法示例。
在下文中一共展示了Datum::getNElements方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: applyTheFunction
// compute the function value(s) with the current parameters
//bool LinearFitableFunction::applyTheFunction(Datum *pInputData, Datum *outputData){ // DDC fix
bool LinearFitableFunction::applyTheFunction(const Datum& pInputData, Datum *outputData){
lock();
if (Parameters == NULL) {
mwarning(M_SYSTEM_MESSAGE_DOMAIN,
"WARNING: Prompted for calibrated value but parameters not yet set.");
unlock(); return false;
}
//if (pInputData->getNElements() != numInputs) { // DDC fix
if (pInputData.getNElements() != numInputs) {
// //int xxx0 = pInputData->getNElements(); // DDC fix
// int xxx0 = pInputData.getNElements();
// //double xxx1 = (double)(pInputData->getElement(0)); // DDC fix
// //double xxx2 = (double)(pInputData->getElement(1));
// double xxx1 = (double)(pInputData.getElement(0)); // DDC fix
// double xxx2 = (double)(pInputData.getElement(1));
mwarning(M_SYSTEM_MESSAGE_DOMAIN,
"WARNING: Prompted for calibrated value but not all input data exists.");
unlock(); return false;
}
double *inputDataDouble = new double [numInputs];
for (int i=0;i<numInputs;i++) {
//inputDataDouble[i] = (double)(pInputData->getElement(i)); // copy data here // DDC fix
inputDataDouble[i] = (double)(pInputData.getElement(i)); // copy data here // DDC fix
//xxx = inputDataDouble[i]; //TODO -- remove
}
double temp = 0;
for (int p=0; p< (basisSet->getNElements()); p++) {
temp = temp + ((Parameters[p])*((basisSet->getElement(p))->applyBasis(inputDataDouble)));
//ppp = Parameters[p]; //TODO -- remove
}
*outputData = Datum(temp);//DDC edit
//*outputData = (Datum)temp;
delete [] inputDataDouble; // DDC added
unlock();
return true;
}
示例2: tryToUseDataToSetParameters
// this routine handles both "requests" and loading of private data (stored params)
// if a request, then priuvate values are probably in need of update
// if a load of private, then private values are OK, but I can check this.
void EyeCalibrator::tryToUseDataToSetParameters(Datum dictionaryData) {
// check if this is a dictionary
if (!(dictionaryData.getDataType() == M_DICTIONARY)) {
mwarning(M_SYSTEM_MESSAGE_DOMAIN,
"Data processed by calibrator %s that was not expected dictionary type was ignored.", uniqueCalibratorName.c_str());
return;
}
// try to perform the requested action
bool paramsChanged = false;
Datum paramData;
// if appropriate param fields are present and have expected length, then use the data
// to try to update the parameters
// H params ================================================
if (!(dictionaryData.hasKey(R_CALIBRATOR_PARAMS_H))) {
mwarning(M_SYSTEM_MESSAGE_DOMAIN,
"Data processed to update params of calibrator %s without proper params filed was ignored.", uniqueCalibratorName.c_str());
return;
}
paramData = dictionaryData.getElement(R_CALIBRATOR_PARAMS_H);
// check if vector and correct length
if (paramData.getDataType() != M_LIST) {
mwarning(M_SYSTEM_MESSAGE_DOMAIN,
"Data processed to update params of calibrator %s that did not contain vector in params field was ignored.", uniqueCalibratorName.c_str());
return;
}
Datum paramsH = paramData;
if (paramsH.getNElements() != (fitableFunctions->getElement(HfunctionIndex))->getNumParameters() ) {
mwarning(M_SYSTEM_MESSAGE_DOMAIN,
"Data processed to update params of calibrator %s that did not contain expected number of params was ignored.", uniqueCalibratorName.c_str());
return;
}
bool noErr = (fitableFunctions->getElement(HfunctionIndex))->setParameters(paramsH);
if (noErr) paramsChanged = true; // params have been updated
// V params ================================================
if (!(dictionaryData.hasKey(R_CALIBRATOR_PARAMS_V))) {
mwarning(M_SYSTEM_MESSAGE_DOMAIN,
"Data processed to update params of calibrator %s without proper params filed was ignored.", uniqueCalibratorName.c_str());
return;
}
paramData = dictionaryData.getElement(R_CALIBRATOR_PARAMS_V);
// check if vector and correct length
if (paramData.getDataType() != M_LIST) {
mwarning(M_SYSTEM_MESSAGE_DOMAIN,
"Data processed to update params of calibrator %s that did not contain vector in params field was ignored.", uniqueCalibratorName.c_str());
return;
}
Datum paramsV = paramData;
if (paramsV.getNElements() != (fitableFunctions->getElement(VfunctionIndex))->getNumParameters() ) {
mwarning(M_SYSTEM_MESSAGE_DOMAIN,
"Data processed to update params of calibrator %s that did not contain expected number of params was ignored.", uniqueCalibratorName.c_str());
return;
}
noErr = (fitableFunctions->getElement(VfunctionIndex))->setParameters(paramsV);
if (noErr) paramsChanged = true; // params have been updated
// if any params were updated, announce the full set of current parameters
// if this change was triggered by an external change to the private variable, then we do not need to update that private variable (and we cannot anyway -- it is locked)
if (paramsChanged) reportParameterUpdate();
}
示例3: unpackageExperiment
bool ExperimentUnpackager::unpackageExperiment(Datum payload) {
namespace bf = boost::filesystem;
if(payload.getDataType() != M_DICTIONARY) {
merror(M_NETWORK_MESSAGE_DOMAIN,
"Invalid payload type for experiment package");
return false;
}
Datum experimentFilePackage =
payload.getElement(M_PACKAGER_EXPERIMENT_STRING);
if(experimentFilePackage.getNElements() !=
M_EXPERIMENT_PACKAGE_NUMBER_ELEMENTS_PER_UNIT ||
experimentFilePackage.getDataType() != M_DICTIONARY)
return false;
Datum experimentFileName =
experimentFilePackage.getElement(M_PACKAGER_FILENAME_STRING);
if(experimentFileName.getDataType() != M_STRING ||
experimentFileName.getString().empty())
return false;
bf::path experimentName(experimentFileName.getString());
loadedExperimentFilename = prependExperimentInstallPath(removeFileExtension(experimentName.string()),
experimentName.string());
bf::path experimentPath = loadedExperimentFilename.branch_path();
createExperimentInstallDirectoryStructure(experimentName.string());
// create the XML file
Datum experimentFileBuffer =
experimentFilePackage.getElement(M_PACKAGER_CONTENTS_STRING);
if(experimentFileBuffer.getDataType() != M_STRING ||
experimentFileBuffer.getString().empty())
return false;
if(!(createFile(Datum(loadedExperimentFilename.string().c_str()),
experimentFileBuffer))) {
// failed to create experiment file
merror(M_FILE_MESSAGE_DOMAIN,
"Failed to create server side experiment file %s",
loadedExperimentFilename.string().c_str());
return false;
}
// create all of the other media files
Datum mediaFileList = payload.getElement(M_PACKAGER_MEDIA_BUFFERS_STRING);
if(mediaFileList.isList()) {
for(int i=0; i<mediaFileList.getNElements(); ++i) {
Datum mediaFilePackage = mediaFileList.getElement(i);
if(mediaFilePackage.getDataType() != M_DICTIONARY |
mediaFilePackage.getNElements() != 2) {
merror(M_FILE_MESSAGE_DOMAIN,
"incorrectly packaged media files");
return false;
}
Datum mediaFileName =
mediaFilePackage.getElement(M_PACKAGER_FILENAME_STRING);
Datum mediaFileBuffer =
mediaFilePackage.getElement(M_PACKAGER_CONTENTS_STRING);
if(mediaFileName.getDataType() != M_STRING ||
mediaFileName.getString().empty() ||
mediaFileBuffer.getDataType() != M_STRING) return false;
std::string filename(mediaFileName.getString());
std::string filenameWPath = experimentPath.string() + "/" + filename;
if(!(createFile(Datum(filenameWPath.c_str()),
mediaFileBuffer))) {
// failed to create experiment file
merror(M_FILE_MESSAGE_DOMAIN,
"Failed to create server side experiment file %s",
filenameWPath.c_str());
return false;
}
}
}
expandRangeReplicatorItems(loadedExperimentFilename);
modifyExperimentMediaPaths(loadedExperimentFilename);
return true;
}