本文整理汇总了C++中TokenPtr::Alloc方法的典型用法代码示例。如果您正苦于以下问题:C++ TokenPtr::Alloc方法的具体用法?C++ TokenPtr::Alloc怎么用?C++ TokenPtr::Alloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TokenPtr
的用法示例。
在下文中一共展示了TokenPtr::Alloc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddSet
/** Add a DataSet of specified type, set it up and return pointer to it.
* \param inType type of DataSet to add.
* \param metaIn DataSet MetaData.
* \return pointer to successfully set-up DataSet or 0 if error.
*/
DataSet* DataSetList::AddSet(DataSet::DataType inType, MetaData const& metaIn)
{ // TODO Always generate default name if empty?
// Do not add to a list with copies
if (hasCopies_) {
mprinterr("Internal Error: Attempting to add DataSet (%s) to DataSetList with copies.\n",
metaIn.PrintName().c_str());
return 0;
}
MetaData meta( metaIn );
meta.SetEnsembleNum( ensembleNum_ );
// Check if DataSet with same attributes already present.
DataSet* DS = CheckForSet(meta);
if (DS != 0) {
mprintf("Warning: DataSet '%s' already present.\n", DS->Meta().PrintName().c_str());
// NOTE: Should return found dataset?
return 0;
}
TokenPtr token = &(DataArray[inType]);
if ( token->Alloc == 0) {
mprinterr("Internal Error: No allocator for DataSet type [%s]\n", token->Description);
return 0;
}
DS = (DataSet*)token->Alloc();
if (DS==0) {
mprinterr("Internal Error: DataSet %s memory allocation failed.\n", meta.PrintName().c_str());
return 0;
}
// If 1 dim set and time series status not set, set to true.
if (meta.TimeSeries() == MetaData::UNKNOWN_TS && DS->Ndim() == 1) {
meta.SetTimeSeries( MetaData::IS_TS );
// Also set dimension default
DS->SetDim(Dimension::X, Dimension(1.0, 1.0, "Frame") );
}
// Set up dataset
if ( DS->SetMeta( meta ) ) {
mprinterr("Error setting up data set %s.\n", meta.PrintName().c_str());
delete DS;
return 0;
}
Push_Back(DS);
//fprintf(stderr,"ADDED dataset %s\n",dsetName);
return DS;
}
示例2: AddSet_NoCheck
/** Special version of AddSet that does NOT check if set already exists.
* Intended for use in Action Setup/DoAction where it is assumed that
* the Action is setting up DataSets in such a way that there will not
* be name conflicts, i.e. the DataSet name at least is unique.
* \param inType type of DataSet to add.
* \param metaIn DataSet MetaData.
* \return pointer to successfully set-up DataSet or 0 if error.
*/
DataSet* DataSetList::AddSet_NoCheck(DataSet::DataType inType, MetaData const& metaIn)
{ // TODO Pass in Nframes?
// Assume list does NOT have copies.
MetaData meta( metaIn );
meta.SetEnsembleNum( ensembleNum_ );
// Allocate DataSet
TokenPtr token = &(DataArray[inType]);
if ( token->Alloc == 0) {
mprinterr("Internal Error: No allocator for DataSet type [%s]\n", token->Description);
return 0;
}
DataSet* DS = (DataSet*)token->Alloc();
if (DS==0) {
mprinterr("Internal Error: DataSet %s memory allocation failed.\n", meta.PrintName().c_str());
return 0;
}
// If 1 dim set and time series status not set, set to true, allocate for frames.
if (meta.TimeSeries() == MetaData::UNKNOWN_TS && DS->Ndim() == 1) {
meta.SetTimeSeries( MetaData::IS_TS );
// Also set dimension default
DS->SetDim(Dimension::X, Dimension(1.0, 1.0, "Frame") );
//DS->Allocate( DataSet::SizeArray(1, Nframes) );
}
// Set up DataSet MetaData
if ( DS->SetMeta( meta ) ) {
mprinterr("Error setting up data set %s.\n", meta.PrintName().c_str());
delete DS;
return 0;
}
# ifdef MPI
if (newSetsNeedSync_) DS->SetNeedsSync( true );
# endif
// Add to list
Push_Back(DS);
return DS;
}