Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ParameterList.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 
43 #ifndef TEUCHOS_PARAMETER_LIST_H
44 #define TEUCHOS_PARAMETER_LIST_H
45 
50 #include "Teuchos_ParameterListExceptions.hpp"
52 #include "Teuchos_StringIndexedOrderedValueObjectContainer.hpp"
53 #include "Teuchos_Assert.hpp"
54 #include "Teuchos_RCP.hpp"
55 #include "Teuchos_Array.hpp"
56 #include "Teuchos_map.hpp"
57 
58 
63 namespace Teuchos {
64 
75 };
76 
87 };
88 
132 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT ParameterList {
133 
136 
139 
140 public:
141 
143 
144 
147 
149  class PrintOptions {
150  public:
151  PrintOptions() : indent_(0), showTypes_(false), showFlags_(false), showDoc_(false) {}
152  PrintOptions& indent(int _indent) { indent_ = _indent; return *this; }
153  PrintOptions& showTypes(bool _showTypes) { showTypes_ = _showTypes; return *this; }
154  PrintOptions& showFlags(bool _showFlags) { showFlags_ = _showFlags; return *this; }
155  PrintOptions& showDoc(bool _showDoc) { showDoc_ = _showDoc; return *this; }
156  PrintOptions& incrIndent(int indents) { indent_ += indents; return *this; }
157  int indent() const { return indent_; }
158  bool showTypes() const { return showTypes_; }
159  bool showFlags() const { return showFlags_; }
160  bool showDoc() const { return showDoc_; }
161  PrintOptions copy() const { return PrintOptions(*this); }
162  private:
163  int indent_;
164  bool showTypes_;
165  bool showFlags_;
166  bool showDoc_;
167  };
168 
170 
172 
173 
175  ParameterList();
176 
178  ParameterList(const std::string &name);
179 
181  ParameterList(const ParameterList& source);
182 
184  virtual ~ParameterList();
185 
187  Ordinal numParams () const;
188 
190 
192 
194  ParameterList& setName( const std::string &name );
195 
199  ParameterList& operator= (const ParameterList& source);
200 
209  ParameterList& setParameters(const ParameterList& source);
210 
220  ParameterList& setParametersNotAlreadySet(const ParameterList& source);
221 
229  ParameterList& disableRecursiveValidation();
230 
249  template<typename T>
250  ParameterList& set (std::string const& name,
251  T const& value,
252  std::string const& docString = "",
253  RCP<const ParameterEntryValidator> const& validator = null);
254 
259  ParameterList& set(
260  std::string const& name, char value[], std::string const& docString = "",
261  RCP<const ParameterEntryValidator> const& validator = null
262  );
263 
268  ParameterList& set(
269  std::string const& name, const char value[], std::string const& docString = "",
270  RCP<const ParameterEntryValidator> const& validator = null
271  );
272 
276  ParameterList& set(
277  std::string const& name, ParameterList const& value, std::string const& docString = ""
278  );
279 
284  ParameterList& setEntry(const std::string& name, const ParameterEntry& entry);
285 
287 
289 
306  template<typename T>
307  T& get(const std::string& name, T def_value);
308 
312  std::string& get(const std::string& name, char def_value[]);
313 
317  std::string& get(const std::string& name, const char def_value[]);
318 
349  template<typename T>
350  T& get (const std::string& name);
351 
379  template<typename T>
380  const T& get (const std::string& name) const;
381 
387  template<typename T>
388  inline
389  T* getPtr(const std::string& name);
390 
396  template<typename T>
397  inline
398  const T* getPtr(const std::string& name) const;
399 
400  // ToDo: Add getSafePtr() functions to return Ptr<T> instead of raw T*
401 
407  ParameterEntry& getEntry(const std::string& name);
408 
414  inline
415  const ParameterEntry& getEntry(const std::string& name) const;
416 
419  inline
420  ParameterEntry* getEntryPtr(const std::string& name);
421 
422  // ToDo: Add function called getEntrySafePtr() to return Ptr<> as the main
423  // implementation and deprecate getEntryPtr()
424 
427  inline
428  const ParameterEntry* getEntryPtr(const std::string& name) const;
429 
432  inline RCP<ParameterEntry> getEntryRCP(const std::string& name);
433 
436  inline RCP<const ParameterEntry> getEntryRCP(const std::string& name) const;
437 
439 
441 
442 
456  bool remove(
457  std::string const& name, bool throwIfNotExists = true
458  );
459 
461 
463 
464 
470  ParameterList& sublist(
471  const std::string& name, bool mustAlreadyExist = false
472  ,const std::string& docString = ""
473  );
474 
479  const ParameterList& sublist(const std::string& name) const;
480 
482 
484 
485 
487  const std::string& name() const;
488 
493  bool isParameter (const std::string& name) const;
494 
499  bool isSublist (const std::string& name) const;
500 
506  template<typename T>
507  bool isType (const std::string& name) const;
508 
509 #ifndef DOXYGEN_SHOULD_SKIP_THIS
510 
520  template<typename T>
521  bool isType(const std::string& name, T* ptr) const;
522 #endif
523 
525 
527 
528 
534  void print() const;
535 
538  std::ostream& print(std::ostream& os, const PrintOptions &printOptions) const;
539 
542  std::ostream& print(std::ostream& os, int indent = 0, bool showTypes = false, bool showFlags = true ) const;
543 
545  void unused(std::ostream& os) const;
546 
548  std::string currentParametersString() const;
549 
551 
553 
554 
556  inline ConstIterator begin() const;
557 
559  inline ConstIterator end() const;
560 
562  inline const std::string& name(ConstIterator i) const;
563 
565  inline const ParameterEntry& entry(ConstIterator i) const;
566 
568 
570 
571 
616  void validateParameters(
617  ParameterList const& validParamList,
618  int const depth = 1000,
619  EValidateUsed const validateUsed = VALIDATE_USED_ENABLED,
620  EValidateDefaults const validateDefaults = VALIDATE_DEFAULTS_ENABLED
621  ) const;
622 
660  void validateParametersAndSetDefaults(
661  ParameterList const& validParamList,
662  int const depth = 1000
663  );
664 
666 
667 private: // Functions
668 
670  inline Iterator nonconstBegin();
672  inline Iterator nonconstEnd();
674  inline ParameterEntry& nonconstEntry(Iterator i);
676  void validateEntryExists(const std::string &funcName, const std::string &name,
677  const ParameterEntry *entry) const;
678  // ToDo: Change above function to take Ptr<> instead of raw pointer.
680  template<typename T>
681  void validateEntryType(const std::string &funcName, const std::string &name,
682  const ParameterEntry &entry ) const;
684  void validateEntryIsList(const std::string &name, const ParameterEntry &entry) const;
686  void validateMissingSublistMustExist(const std::string &baselist_name,
687  const std::string &sublist_name, const bool mustAlreadyExist) const;
689  void updateSubListNames(int depth = 0);
690 
691 private: // Data members
692 
694  std::string name_;
695 
697 //use pragmas to disable some false-positive warnings for windows sharedlibs export
698 //#ifdef _MSC_VER
699 //#pragma warning(push)
700 //#pragma warning(disable:4251)
701 //#endif
702  params_t params_;
703 //#ifdef _MSC_VER
704 //#pragma warning(pop)
705 //#endif
706 
708  bool disableRecursiveValidation_;
709 
710 };
711 
712 
717 inline
719 {
720  return rcp(new ParameterList);
721 }
722 
723 
728 inline
729 RCP<ParameterList> parameterList(const std::string &name)
730 {
731  return rcp(new ParameterList(name));
732 }
733 
734 
739 inline
741 {
742  return rcp(new ParameterList(source));
743 }
744 
745 
750 inline
752 {
753  return rcp(new ParameterList);
754 }
755 
756 
761 inline
762 RCP<ParameterList> createParameterList(const std::string &name)
763 {
764  return rcp(new ParameterList(name));
765 }
766 
767 
772 template<>
773 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT TypeNameTraits<ParameterList> {
774 public:
775  static std::string name() { return "ParameterList"; }
776  static std::string concreteName( const ParameterList& /*t2*/ )
777  { return name(); }
778 };
779 
780 
785 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool operator==( const ParameterList& list1, const ParameterList& list2 );
786 
787 
792 inline
793 bool operator!=( const ParameterList& list1, const ParameterList& list2 )
794 {
795  return !( list1 == list2 );
796 }
797 
798 
810 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameValues( const ParameterList& list1, const ParameterList& list2,
811  bool verbose = false);
812 
813 
825 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT bool haveSameValuesSorted( const ParameterList& list1,
826  const ParameterList& list2, bool verbose = false);
827 
828 
829 // /////////////////////////////////////////////////////
830 // Inline and Template Function Definitions
831 
832 
833 inline
834 ParameterList& ParameterList::setName( const std::string &name_in )
835 {
836  name_ = name_in;
837  return *this;
838 }
839 
840 
841 // Set functions
842 
843 
844 template<typename T>
845 inline
847  std::string const& name_in, T const& value_in, std::string const& docString_in,
848  RCP<const ParameterEntryValidator> const& validator_in
849  )
850 {
852  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
853  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
854  Ptr<ParameterEntry> param = params_.getNonconstObjPtr(param_idx);
855  const std::string docString =
856  (docString_in.length() ? docString_in : param->docString());
857  const RCP<const ParameterEntryValidator> validator =
858  (nonnull(validator_in) ? validator_in : param->validator());
859  // Create temp param to validate before setting
860  ParameterEntry param_new(value_in, false, false, docString, validator );
861  if (nonnull(validator)) {
862  validator->validate(param_new, name_in, this->name());
863  }
864  // Strong guarantee: (if exception is thrown, the value is not changed)
865  *param = param_new;
866  }
867  else {
868  ParameterEntry param_new(value_in, false, false, docString_in, validator_in);
869  if (nonnull(param_new.validator())) {
870  param_new.validator()->validate(param_new, name_in, this->name());
871  }
872  params_.setObj(name_in, param_new);
873  }
874  return *this;
875 }
876 
877 
878 inline
880  std::string const& name_in, char value[], std::string const& docString
881  ,RCP<const ParameterEntryValidator> const& validator
882  )
883 { return set(name_in, std::string(value), docString, validator); }
884 
885 
886 inline
888  const std::string& name_in, const char value[], const std::string &docString
889  ,RCP<const ParameterEntryValidator> const& validator
890  )
891 { return set( name_in, std::string(value), docString, validator ); }
892 
893 
894 inline
896  std::string const& name_in, ParameterList const& value, std::string const& /*docString*/
897  )
898 {
899  sublist(name_in) = value;
900  return *this;
901 }
902 
903 
904 inline
905 ParameterList& ParameterList::setEntry(std::string const& name_in, ParameterEntry const& entry_in)
906 {
907  params_.setObj(name_in, entry_in);
908  return *this;
909 }
910 
911 
912 // Get functions
913 
914 
915 template<typename T>
916 T& ParameterList::get(const std::string& name_in, T def_value)
917 {
919  Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
920  if (param_idx == SIOVOCB::getInvalidOrdinal()) {
921  // Param does not exist
922  param_idx = params_.setObj(name_in, ParameterEntry(def_value, true));
923  }
924  Ptr<ParameterEntry> param = params_.getNonconstObjPtr(param_idx);
925  this->template validateEntryType<T>("get", name_in, *param);
926  return getValue<T>(*param);
927 }
928 
929 
930 inline
931 std::string& ParameterList::get(const std::string& name_in, char def_value[])
932 { return get(name_in, std::string(def_value)); }
933 
934 
935 inline
936 std::string& ParameterList::get(const std::string& name_in, const char def_value[])
937 { return get(name_in, std::string(def_value)); }
938 
939 
940 template<typename T>
941 T& ParameterList::get(const std::string& name_in)
942 {
943  ParameterEntry *foundEntry = this->getEntryPtr(name_in);
944  validateEntryExists("get",name_in,foundEntry);
945  this->template validateEntryType<T>("get",name_in,*foundEntry);
946  return getValue<T>(*foundEntry);
947 }
948 
949 
950 template<typename T>
951 const T& ParameterList::get(const std::string& name_in) const
952 {
953  const ParameterEntry *foundEntry = this->getEntryPtr(name_in);
954  validateEntryExists("get",name_in,foundEntry);
955  this->template validateEntryType<T>("get",name_in,*foundEntry);
956  return getValue<T>(*foundEntry);
957 }
958 
959 
960 template<typename T>
961 inline
962 T* ParameterList::getPtr(const std::string& name_in)
963 {
965  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
966  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
967  const Ptr<ParameterEntry> param_ptr = params_.getNonconstObjPtr(param_idx);
968  if (param_ptr->isType<T>()) {
969  return &param_ptr->getValue<T>(0);
970  }
971  // Note: The above is inefficinet. You have to do the dynamic_cast twice
972  // (once to see if it is the type and once to do the cast). This could be
973  // made more efficinet by upgrading Teuchos::any to add a any_cast_ptr()
974  // function but I don't think anyone actually uses this function.
975  return 0;
976  }
977  return 0;
978 }
979 
980 
981 template<typename T>
982 inline
983 const T* ParameterList::getPtr(const std::string& name_in) const
984 {
986  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
987  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
988  const Ptr<const ParameterEntry> param_ptr = params_.getObjPtr(param_idx);
989  if (param_ptr->isType<T>()) {
990  return &param_ptr->getValue<T>(0);
991  }
992  // Note: The above is inefficinet, see above non-const getPtr() function.
993  return 0;
994  }
995  return 0;
996 }
997 
998 
999 inline
1000 ParameterEntry& ParameterList::getEntry(const std::string& name_in)
1001 {
1002  ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1003  validateEntryExists("get", name_in, foundEntry);
1004  return *foundEntry;
1005 }
1006 
1007 
1008 inline
1009 const ParameterEntry& ParameterList::getEntry(const std::string& name_in) const
1010 {
1011  const ParameterEntry *foundEntry = this->getEntryPtr(name_in);
1012  validateEntryExists("get", name_in, foundEntry);
1013  return *foundEntry;
1014 }
1015 
1016 
1017 inline
1019 ParameterList::getEntryPtr(const std::string& name_in)
1020 {
1022  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1023  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1024  return &*params_.getNonconstObjPtr(param_idx);
1025  }
1026  return 0;
1027 }
1028 
1029 
1030 inline
1031 const ParameterEntry*
1032 ParameterList::getEntryPtr(const std::string& name_in) const
1033 {
1035  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1036  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1037  return &*params_.getObjPtr(param_idx);
1038  }
1039  return 0;
1040 }
1041 
1042 
1043 inline RCP<ParameterEntry>
1044 ParameterList::getEntryRCP(const std::string& name_in)
1045 {
1047  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1048  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1049  return rcpFromPtr(params_.getNonconstObjPtr(param_idx));
1050  }
1051  return null;
1052 }
1053 
1054 
1056 ParameterList::getEntryRCP(const std::string& name_in) const
1057 {
1059  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1060  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1061  return rcpFromPtr(params_.getObjPtr(param_idx));
1062  }
1063  return null;
1064 }
1065 
1066 
1067 // Attribute Functions
1068 
1069 
1070 inline
1071 const std::string& ParameterList::name() const
1072 {
1073  return name_;
1074 }
1075 
1076 
1077 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1078 template<typename T>
1079 bool ParameterList::isType(const std::string& name_in, T* /*ptr*/) const
1080 {
1082  const Ordinal param_idx = params_.getObjOrdinalIndex(name_in);
1083  if (param_idx != SIOVOCB::getInvalidOrdinal()) {
1084  return params_.getObjPtr(param_idx)->isType<T>();
1085  }
1086  return false;
1087 }
1088 #endif
1089 
1090 
1091 template<typename T>
1092 bool ParameterList::isType(const std::string& name_in) const
1093 {
1094  return this->isType(name_in, static_cast<T*>(0));
1095 }
1096 
1097 
1098 // Read-only access to the iterator
1099 
1100 
1102 {
1103  return params_.begin();
1104 }
1105 
1106 
1108 {
1109  return params_.end();
1110 }
1111 
1112 
1113 inline const std::string& ParameterList::name(ConstIterator i) const
1114 {
1115  return (i->first);
1116 }
1117 
1118 
1120 {
1121  return (i->second);
1122 }
1123 
1124 
1125 // private
1126 
1127 
1128 inline ParameterList::Iterator ParameterList::nonconstBegin()
1129 {
1130  return params_.nonconstBegin();
1131 }
1132 
1133 
1134 inline ParameterList::Iterator ParameterList::nonconstEnd()
1135 {
1136  return params_.nonconstEnd();
1137 }
1138 
1139 
1140 inline ParameterEntry& ParameterList::nonconstEntry(Iterator i)
1141 {
1142  return (i->second);
1143 }
1144 
1145 
1146 template<typename T>
1147 inline
1148 void ParameterList::validateEntryType(
1149  const std::string &/*funcName*/, const std::string &name_in,
1150  const ParameterEntry &entry_in
1151  ) const
1152 {
1154  entry_in.getAny().type() != typeid(T), Exceptions::InvalidParameterType
1155  ,"Error! An attempt was made to access parameter \""<<name_in<<"\""
1156  " of type \""<<entry_in.getAny().typeName()<<"\""
1157  "\nin the parameter (sub)list \""<<this->name()<<"\""
1158  "\nusing the incorrect type \""<<TypeNameTraits<T>::name()<<"\"!"
1159  );
1160 }
1161 
1162 
1163 // //////////////////////////////////////
1164 // Helper functions
1165 
1166 
1173 template<typename T>
1174 T& getParameter( ParameterList& l, const std::string& name )
1175 {
1176  return l.template get<T>(name);
1177 }
1178 
1179 
1185 template<typename T>
1186 inline
1187 T& get( ParameterList& l, const std::string& name )
1188 {
1189  return getParameter<T>(l,name);
1190 }
1191 
1192 
1199 template<typename T>
1200 const T& getParameter( const ParameterList& l, const std::string& name )
1201 {
1202  return l.template get<T>(name);
1203 }
1204 
1205 
1213 template<typename T>
1214 inline
1215 T* getParameterPtr( ParameterList& l, const std::string& name )
1216 {
1217  return l.template getPtr<T>(name);
1218 }
1219 
1220 
1228 template<typename T>
1229 inline
1230 const T* getParameterPtr( const ParameterList& l, const std::string& name )
1231 {
1232  return l.template getPtr<T>(name);
1233 }
1234 
1235 
1242 template<typename T>
1243 inline
1244 bool isParameterType( ParameterList& l, const std::string& name )
1245 {
1246  return l.isType( name, (T*)NULL );
1247 }
1248 
1249 
1256 template<typename T>
1257 inline
1258 bool isParameterType( const ParameterList& l, const std::string& name )
1259 {
1260  return l.isType( name, (T*)NULL );
1261 }
1262 
1263 
1275 template<typename T>
1277  const std::string &paramName
1278  ,const Array<T> &array
1279  ,ParameterList *paramList
1280  )
1281 {
1282  TEUCHOS_TEST_FOR_EXCEPT(!paramList);
1283  paramList->set(paramName,toString(array));
1284 }
1285 
1286 
1351 template<typename T>
1353  const ParameterList &paramList
1354  ,const std::string &paramName
1355  ,const int arrayDim = -1
1356  ,const bool mustExist = true
1357  )
1358 {
1359  std::string arrayStr;
1360  if(mustExist) {
1361  arrayStr = getParameter<std::string>(paramList,paramName);
1362  }
1363  else {
1364  const std::string
1365  *arrayStrPtr = getParameterPtr<std::string>(paramList,paramName);
1366  if(arrayStrPtr) {
1367  arrayStr = *arrayStrPtr;
1368  }
1369  else {
1370  return Array<T>(); // Return an empty array
1371  }
1372  }
1373  Array<T> a;
1374  try {
1375  a = fromStringToArray<T>(arrayStr);
1376  }
1377  catch( const InvalidArrayStringRepresentation&) {
1380  ,"Error! The parameter \""<<paramName<<"\"\n"
1381  "in the sublist \""<<paramList.name()<<"\"\n"
1382  "exists, but the std::string value:\n"
1383  "----------\n"
1384  <<arrayStr<<
1385  "\n----------\n"
1386  "is not a valid array represntation!"
1387  );
1388  }
1390  ( ( a.size()>0 && arrayDim>=0 ) && static_cast<int>(a.size())!=arrayDim )
1392  ,"Error! The parameter \""<<paramName<<"\"\n"
1393  "in the sublist \""<<paramList.name()<<"\"\n"
1394  "exists and is a valid array, but the dimension of\n"
1395  "the read in array a.size() = " << a.size() << "\n"
1396  "was not equal to the expected size arrayDim = " << arrayDim << "!"
1397  );
1398  return a;
1399 }
1400 
1401 
1405 inline
1407  const RCP<ParameterList> &paramList, const std::string& name,
1408  bool mustAlreadyExist = false, const std::string& docString = ""
1409  )
1410 {
1411  return rcpWithEmbeddedObjPostDestroy(
1412  &paramList->sublist(name, mustAlreadyExist, docString), paramList, false );
1413 }
1414 
1415 
1419 inline
1421  const RCP<const ParameterList> &paramList, const std::string& name
1422  )
1423 {
1424  return rcpWithEmbeddedObjPostDestroy(
1425  &paramList->sublist(name), paramList, false );
1426 }
1427 
1428 
1432 inline std::ostream& operator<<(std::ostream& os, const ParameterList& l)
1433 {
1434  return l.print(os);
1435 }
1436 
1437 
1438 } // end of Teuchos namespace
1439 
1440 
1441 #endif
void print() const
Print function to use in debugging in a debugger.
Object held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
const std::string & name() const
The name of this ParameterList.
C++ Standard Library compatable filtered iterator.
Ordinal getObjOrdinalIndex(const std::string &key) const
Get the ordinal index given the string key.
ConstIterator end() const
An iterator pointing beyond the last entry.
Array< T > getArrayFromStringParameter(const ParameterList &paramList, const std::string &paramName, const int arrayDim=-1, const bool mustExist=true)
Get an Array object (with entries of type T) from a parameter holding a std::string representation of...
RCP< ParameterEntry > getEntryRCP(const std::string &name)
Retrieves the RCP for an entry with the name name if it exists.
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
RCP< ParameterList > createParameterList()
Nonmember constructor.
RCP< ParameterList > createParameterList(const std::string &name)
Nonmember constructor.
T & get(const std::string &name, T def_value)
Return the parameter&#39;s value, or the default value if it is not there.
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.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
bool isParameterType(ParameterList &l, const std::string &name)
A templated helper function for determining the type of a parameter entry for a non-const list...
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Return a RCP to a sublist in another RCP-ed parameter list.
const T * getParameterPtr(const ParameterList &l, const std::string &name)
A templated helper function for getting a pointer to a parameter from a non-const list...
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
RCP< ParameterList > parameterList()
Nonmember constructor.
ParameterList & setEntry(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
std::ostream & operator<<(std::ostream &os, const ParameterList &l)
Output stream operator for handling the printing of the parameter list.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
bool isParameterType(const ParameterList &l, const std::string &name)
A templated helper function for determining the type of a parameter entry for a const list...
bool operator!=(const ParameterList &list1, const ParameterList &list2)
Returns true if two parameter lists are not the same.
RCP< ParameterList > parameterList(const ParameterList &source)
Nonmember constructor.
params_t::ConstIterator ConstIterator
Parameter container const iterator typedef.
const T & getParameter(const ParameterList &l, const std::string &name)
A templated helper function for getting a parameter from a const list. This helper function prevents ...
Utility class for setting and passing in print options.
T & getParameter(ParameterList &l, const std::string &name)
A templated helper function for getting a parameter from a non-const list. This helper function preve...
ConstIterator begin() const
An iterator pointing to the first entry.
RCP< const ParameterList > sublist(const RCP< const ParameterList > &paramList, const std::string &name)
Return a RCP to a sublist in another RCP-ed parameter list.
T * getParameterPtr(ParameterList &l, const std::string &name)
A templated helper function for getting a pointer to a parameter from a non-const list...
Ptr< const ObjType > getObjPtr(const Ordinal &idx) const
Get a const semi-persisting association with the stored object indexed by ordinal.
T * getPtr(const std::string &name)
Retrieves the pointer for parameter name of type T from a list. A null pointer is returned if this pa...
A list of parameters of arbitrary type.
Provides std::map class for deficient platforms.
const ParameterEntry & entry(ConstIterator i) const
Access to ParameterEntry (i.e., returns i-&gt;second)
Templated array class derived from the STL std::vector.
Ordinal setObj(const std::string &key, const ObjType &obj)
Set (or reset) object by value and return its ordinal index.
Default traits class that just returns typeid(T).name().
void setStringParameterFromArray(const std::string &paramName, const Array< T > &array, ParameterList *paramList)
Set a std::string parameter representation of an array.
size_type size() const
bool isType(const std::string &name) const
Whether the given parameter exists in this list and has type T.
EValidateDefaults
Validation defaults enum.
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...
ParameterList & setName(const std::string &name)
Set the name of *this list.
Smart reference counting pointer class for automatic garbage collection.
ParameterEntry & getEntry(const std::string &name)
Retrieves an entry with the name name.
Ptr< ObjType > getNonconstObjPtr(const Ordinal &idx)
Get a nonconst semi-persisting association with the stored object indexed by ordinal.
EValidateUsed
Validation used enum.
RCP< ParameterList > parameterList(const std::string &name)
Nonmember constructor.
Reference-counted pointer class and non-member templated function implementations.
#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...
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...