42 #ifndef Teuchos_OBJECT_BUILDER_H
43 #define Teuchos_OBJECT_BUILDER_H
88 template<
class ObjectType>
101 const std::string &objectName
106 const std::string &objectTypeName
112 const std::string &objectFactoryName
128 const std::string &objectName =
""
183 template<
class ObjectType>
191 template<
class ObjectType>
192 RCP<ObjectBuilder<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 paramList_->validateParameters(*this->getValidParameters());
226 template<
class ObjectType>
229 const std::string &objectName
233 validObjectNames_.push_back(objectName);
234 objectArray_.push_back(objectFactory);
235 defaultObject_name_ = objectName;
236 validParamList_ =
null;
238 this->getValidParameters();
239 #endif // TEUCHOS_DEBUG
243 template<
class ObjectType>
248 this->getValidParameters();
255 pl = parameterList();
258 return objectValidator_->
getStringValue(*pl, objectType_name_, defaultObject_name_);
262 template<
class ObjectType>
269 paramList_ = paramList;
274 template<
class ObjectType>
282 template<
class ObjectType>
289 paramList_->validateParameters(*this->getValidParameters());
297 template<
class ObjectType>
305 template<
class ObjectType>
309 if(!validParamList_.get()) {
312 objectValidator_ =
rcp(
314 validObjectNames_, objectType_name_
317 objectValidator_->validateString(defaultObject_name_,objectType_name_);
319 objectType_name_, defaultObject_name_,
320 (std::string(
"Determines the type of " + object_name_ +
" object that will be built.\n")
321 +
"The parameters for each " + objectType_name_ +
" are specified in this sublist"
325 for(
int i = 0; i < static_cast<int>(objectArray_.size()); ++i ) {
327 &sname = validObjectNames_[i+1];
329 object = objectArray_[i]->create();
331 *object->getValidParameters()).disableRecursiveValidation();
333 validParamList_ = validParamList;
335 return validParamList_;
338 template<
class ObjectType>
340 const std::string &defaultObject_name
344 if (
is_null(validParamList_)) {
345 this->getValidParameters();
347 objectValidator_->validateString(defaultObject_name,objectType_name_);
348 #endif // TEUCHOS_DEBUG
349 defaultObject_name_ = defaultObject_name;
351 validParamList_ =
null;
354 template<
class ObjectType>
357 const std::string &objectName
360 if (
is_null(validParamList_)) {
361 this->getValidParameters();
364 sname = ( objectName.length()
366 : this->getObjectName() );
370 s_idx = objectValidator_->getIntegralValue(sname, objectType_name_);
373 object = objectArray_[s_idx-1]->create();
375 (std::string(
"Error! ObjectBuilder attempted to create an object of type ")
376 + validObjectNames_[s_idx] +
" and it came back as a null RCP!").c_str()
382 pl = parameterList();
383 pl->
setParameters(this->getValidParameters()->sublist(sname));
389 #endif // TEUCHOS_DEBUG
390 pl = sublist(paramList_,sname);
393 object->setParameterList(pl);
399 template<
class ObjectType>
401 const std::string &objectName
405 object_name_ = objectName;
406 validParamList_ =
null;
410 template<
class ObjectType>
412 const std::string &objectTypeName
416 objectType_name_ = objectTypeName;
417 validParamList_ =
null;
421 template<
class ObjectType>
425 object_name_ =
"Object";
426 objectType_name_ =
"Object Type";
428 defaultObject_name_ =
"None";
429 validObjectNames_.resize(0);
430 validObjectNames_.push_back(defaultObject_name_);
438 #endif //Teuchos_OBJECT_BUILDER_H
RCP< const ParameterList > validParamList_
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...
bool is_null(const boost::shared_ptr< T > &p)
Returns true if p.get()==NULL.
RCP< ParameterList > getNonconstParameterList()
Array< object_fcty_t > objectArray_
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Set a parameter whose value has type T.
Generic parameterlist driven bulider class.
RCP< const ParameterList > getValidParameters() const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
std::string defaultObject_name_
RCP< ParameterList > unsetParameterList()
void setObjectName(const std::string &objectName)
Set the name of the object this will be a builder for, e.g. "Object".
RCP< ObjectType > create(const std::string &objectName="") const
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.
std::string getStringValue(ParameterList const ¶mList, std::string const ¶mName)
Get a std::string value for a parameter that is assumed to already be set.
void setParameterList(const RCP< ParameterList > ¶mList)
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
Validate the parameters in this list given valid selections in the input list.
ParameterList & setParameters(const ParameterList &source)
std::string getObjectName() const
Get the name of the Object that will be created on the next call to this->create().
Base class objects that can accept a parameter list.
RCP< const StringToIntegralParameterEntryValidator< int > > objectValidator_
Array< std::string > validObjectNames_
void initializeDefaults_()
std::string objectType_name_
RCP< ParameterList > paramList_
RCP< ObjectBuilder< ObjectType > > objectBuilder()
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Creates an empty sublist and returns a reference to the sublist name. If the list already exists...
Smart reference counting pointer class for automatic garbage collection.
Simple, universal "Abstract Factory" interface for the dynamic creation of objects.
RCP< const AbstractFactory< ObjectType > > object_fcty_t
RCP< const ParameterList > getParameterList() const
#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...