Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_YamlParser_decl.hpp
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 
10 #ifndef TEUCHOS_YAMLPARSER_DECL_H_
11 #define TEUCHOS_YAMLPARSER_DECL_H_
12 
102 #include "Teuchos_ParameterList.hpp"
104 #include "Teuchos_RCP.hpp"
105 #include "Teuchos_PtrDecl.hpp"
107 #ifdef HAVE_TEUCHOSPARAMETERLIST_YAMLCPP
108 #include "yaml-cpp/yaml.h"
109 #endif // HAVE_TEUCHOSPARAMETERLIST_YAMLCPP
110 
111 #include <iostream>
112 #include <string>
113 
114 namespace Teuchos
115 {
116 
117 #ifdef HAVE_TEUCHOSPARAMETERLIST_YAMLCPP
118 #define MAKE_EXCEPTION_TYPE(Name) \
119 class Name : public Teuchos::ExceptionBase \
120 { \
121  public: \
122  Name(const std::string& arg) : ExceptionBase(arg) {} \
123 };
124 
125 MAKE_EXCEPTION_TYPE(YamlKeyError)
126 MAKE_EXCEPTION_TYPE(YamlSequenceError)
127 MAKE_EXCEPTION_TYPE(YamlStructureError)
128 MAKE_EXCEPTION_TYPE(YamlUndefinedNodeError)
129 
130 #undef MAKE_EXCEPTION_TYPE
131 #endif // HAVE_TEUCHOSPARAMETERLIST_YAMLCPP
132 
133 std::string convertXmlToYaml(const std::string& xmlFileName); //returns filename of produced YAML file
134 void convertXmlToYaml(const std::string& xmlFileName, const std::string& yamlFileName); //writes to given filename
135 void convertXmlToYaml(std::istream& xmlStream, std::ostream& yamlStream);
136 
137 //Functions modeled after Teuchos::XMLParameterListReader
138 namespace YAMLParameterList
139 {
140  Teuchos::RCP<Teuchos::ParameterList> parseYamlText(const std::string& text,
141  const std::string& name);
142  Teuchos::RCP<Teuchos::ParameterList> parseYamlFile(const std::string& yamlFile);
144  void writeYamlStream(std::ostream& yamlFile, const Teuchos::ParameterList& pl);
145  void writeYamlFile(const std::string& yamlFile, const Teuchos::ParameterList& pl);
146 
147  #ifdef HAVE_TEUCHOSPARAMETERLIST_YAMLCPP
148  Teuchos::RCP<Teuchos::ParameterList> readParams(std::vector<::YAML::Node>& lists);
149  void processMapNode(const ::YAML::Node& node, Teuchos::ParameterList& parent, bool topLevel = false);
150  void processKeyValueNode(const std::string& key, const ::YAML::Node& node, Teuchos::ParameterList& parent, bool topLevel = false);
151  #endif // HAVE_TEUCHOSPARAMETERLIST_YAMLCPP
152 
153  void writeParameterList(const Teuchos::ParameterList& pl, std::ostream& yaml, int indentLevel);
154  void writeParameter(const std::string& paramName, const Teuchos::ParameterEntry& entry, std::ostream& yaml, int indentLevel); //throws if the entry's type is not supported
155  void generalWriteString(const std::string& str, std::ostream& yaml);
156  void generalWriteDouble(double d, std::ostream& yaml);
157  bool stringNeedsQuotes(const std::string& str);
159 }
160 
161 } //namespace
162 
163 #endif
Teuchos::RCP< Teuchos::ParameterList > parseYamlStream(std::istream &yaml)
Object held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
C++ Standard Library compatable filtered iterator.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
void generalWriteString(const std::string &str, std::ostream &yaml)
void generalWriteDouble(double d, std::ostream &yaml)
void writeYamlFile(const std::string &yamlFile, const Teuchos::ParameterList &pl)
Templated Parameter List class.
Teuchos::RCP< Teuchos::ParameterList > parseYamlText(const std::string &text, const std::string &name)
void writeParameter(const std::string &paramName, const Teuchos::ParameterEntry &entry, std::ostream &yaml, int indentLevel)
void writeParameterList(const Teuchos::ParameterList &pl, std::ostream &yaml, int indentLevel)
A list of parameters of arbitrary type.
Teuchos::RCP< Teuchos::ParameterList > parseYamlFile(const std::string &yamlFile)
bool stringNeedsQuotes(const std::string &s)
Definition of XMLInputSource derived class for reading XML from a file.
std::string convertXmlToYaml(const std::string &xmlFileName)
void writeYamlStream(std::ostream &yaml, const Teuchos::ParameterList &pl)
Reference-counted pointer class and non-member templated function implementations.
Teuchos::ParameterList::ConstIterator PLIter