Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
custom_validator_xml.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
11 #include "Teuchos_Array.hpp"
12 #include "Teuchos_Version.hpp"
18 #include <iostream>
19 
20 
21 
28 int main(int argc, char* argv[])
29 {
30  std::cout << Teuchos::Teuchos_Version() << std::endl << std::endl;
31 
32  Teuchos::ParameterList My_List;
33 
34  //Basic data types
36  solverValidator = Teuchos::rcp(
38  Teuchos::tuple<std::string>( "GMRES", "CG", "TFQMR" )
39  ,"Solver"
40  )
41  );
42  My_List.set(
43  "Solver"
44  ,"GMRES"
45  ,"The type of solver to use."
46  ,solverValidator
47  );
48 
49  //By default, there is no validator converter for a StringToIntegralParameterEntryValidator
50  //templated on type short. So lets add one with the following convience macro found
51  //in ValidatorXMLConverterDB.hpp
53 
54  //Of course if you have a completly custom validator you'll need to do a little more
55  //You'll have to make you're own converter for it by subclassing the ValidatorXMLConverter
56  //class and then use the TEUCHOS_ADD_VALIDATOR_CONVERTER convience macro.
57 
58 
59  //Now we'll write it out to xml.
60  Teuchos::writeParameterListToXmlFile(My_List, "custom_validator_test_list.xml");
61  //Then read it in to a new list.
62 
63  Teuchos::writeParameterListToXmlOStream(My_List, std::cout);
64  Teuchos::RCP<Teuchos::ParameterList> readIn = Teuchos::getParametersFromXmlFile("custom_validator_test_list.xml");
65 
66  std::cout << *readIn;
67 
74  return 0;
75 }
A collection of standard ValidatorXMLConverters.
Standard implementation of a ParameterEntryValidator that maps from a list of strings to an enum or i...
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method.
Simple helper functions that make it easy to read and write XML to and from a parameterlist.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
A database for ValidatorXMLConverters.
std::string Teuchos_Version()
A list of parameters of arbitrary type.
int main(int argc, char *argv[])
Templated array class derived from the STL std::vector.
#define TEUCHOS_ADD_STRINGTOINTEGRALVALIDATOR_CONVERTER(INTEGRALTYPE)
Add StringToIntegralParameterEntryValidator&lt;INTEGRAL_TYPE&gt; to set of supported parameter types...
Smart reference counting pointer class for automatic garbage collection.