42 #ifndef Teuchos_OBJECT_BUILDER_H 43 #define Teuchos_OBJECT_BUILDER_H 46 #include "Teuchos_ParameterListAcceptor.hpp" 47 #include "Teuchos_AbstractFactoryStd.hpp" 48 #include "Teuchos_StandardParameterEntryValidators.hpp" 88 template<
class ObjectType>
101 const std::string &objectName
106 const std::string &objectTypeName
112 const std::string &objectFactoryName
128 const std::string &objectName =
"" 165 std::string object_name_;
166 std::string objectType_name_;
170 std::string defaultObject_name_;
175 void initializeDefaults_();
183 template<
class ObjectType>
191 template<
class ObjectType>
193 objectBuilder(
const std::string& objectName,
const std::string& objectTypeName)
196 ob->setObjectName(objectName);
197 ob->setObjectTypeName(objectTypeName);
207 template<
class ObjectType>
210 this->initializeDefaults_();
214 template<
class ObjectType>
220 template<
class ObjectType>
223 const std::string &objectName
228 objectArray_.push_back(objectFactory);
229 defaultObject_name_ = objectName;
230 validParamList_ = null;
233 #endif // TEUCHOS_DEBUG 237 template<
class ObjectType>
249 pl = parameterList();
252 return objectValidator_->getStringValue(*pl, objectType_name_, defaultObject_name_);
256 template<
class ObjectType>
263 paramList_ = paramList;
268 template<
class ObjectType>
276 template<
class ObjectType>
291 template<
class ObjectType>
299 template<
class ObjectType>
303 if(!validParamList_.get()) {
306 objectValidator_ =
rcp(
308 validObjectNames_, objectType_name_
311 objectValidator_->validateString(defaultObject_name_,objectType_name_);
313 objectType_name_, defaultObject_name_,
314 (std::string(
"Determines the type of " + object_name_ +
" object that will be built.\n")
315 +
"The parameters for each " + objectType_name_ +
" are specified in this sublist" 319 for(
int i = 0; i < static_cast<int>(objectArray_.size()); ++i ) {
321 &sname = validObjectNames_[i+1];
323 object = objectArray_[i]->create();
324 validParamList->sublist(sname).setParameters(
325 *object->getValidParameters()).disableRecursiveValidation();
327 validParamList_ = validParamList;
329 return validParamList_;
332 template<
class ObjectType>
334 const std::string &defaultObject_name
338 if (
is_null(validParamList_)) {
341 objectValidator_->validateString(defaultObject_name,objectType_name_);
342 #endif // TEUCHOS_DEBUG 343 defaultObject_name_ = defaultObject_name;
345 validParamList_ = null;
348 template<
class ObjectType>
351 const std::string &objectName
354 if (
is_null(validParamList_)) {
358 sname = ( objectName.length()
364 s_idx = objectValidator_->getIntegralValue(sname, objectType_name_);
367 object = objectArray_[s_idx-1]->create();
369 (std::string(
"Error! ObjectBuilder attempted to create an object of type ")
370 + validObjectNames_[s_idx] +
" and it came back as a null RCP!").c_str()
376 pl = parameterList();
383 #endif // TEUCHOS_DEBUG 384 pl = sublist(paramList_,sname);
387 object->setParameterList(pl);
393 template<
class ObjectType>
395 const std::string &objectName
399 object_name_ = objectName;
400 validParamList_ = null;
404 template<
class ObjectType>
406 const std::string &objectTypeName
410 objectType_name_ = objectTypeName;
411 validParamList_ = null;
415 template<
class ObjectType>
419 object_name_ =
"Object";
420 objectType_name_ =
"Object Type";
422 defaultObject_name_ =
"None";
423 validObjectNames_.
resize(0);
424 validObjectNames_.
push_back(defaultObject_name_);
432 #endif //Teuchos_OBJECT_BUILDER_H
void setDefaultObject(const std::string &defaultObject_name)
Set the name of the desired object to be created when the parameter list does not specify which objec...
RCP< ParameterList > getNonconstParameterList()
Generic parameterlist driven bulider class.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
RCP< ParameterList > unsetParameterList()
void setObjectName(const std::string &objectName)
Set the name of the object this will be a builder for, e.g. "Object".
void setObjectFactory(const RCP< const AbstractFactory< ObjectType > > &objectFactory, const std::string &objectFactoryName)
Set a new Object factory object.
void setObjectTypeName(const std::string &objectTypeName)
Set the name of the parameterlist selector, e.g. "Object Type".
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
RCP< ObjectType > create(const std::string &objectName="") const
void setParameterList(const RCP< ParameterList > ¶mList)
void resize(size_type new_size, const value_type &x=value_type())
Interface for objects that can accept a ParameterList.
void push_back(const value_type &x)
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
RCP< const ParameterList > getParameterList() const
Smart reference counting pointer class for automatic garbage collection.
RCP< const ParameterList > getValidParameters() const
Simple, universal "Abstract Factory" interface for the dynamic creation of objects.
std::string getObjectName() const
Get the name of the Object that will be created on the next call to this->create().
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...