43 #include <boost/filesystem.hpp>
44 #include <boost/lexical_cast.hpp>
49 #include <rose_strtoull.h>
52 #include <type_traits>
68 template<
typename T,
class Enable =
void>
70 static T Get(
const std::string &data) {
71 return boost::lexical_cast<T>(data);
74 static T Get(
const std::string &data,
const T &defaultValue) {
76 return boost::conversion::try_lexical_convert(data, result) ? result : defaultValue;
83 static T Get(
const std::string &data) {
84 const char *s = data.c_str();
86 static_assert(
sizeof(T) <=
sizeof(uint64_t),
"sizeof(T) is too big for implementation");
87 if (strlen(s) != data.size() || data.empty() || isspace(data[0]))
88 throw std::runtime_error(
"string is not a recognized integral literal");
90 uint64_t big = rose_strtoull(s, &rest, 0);
92 throw std::runtime_error(
"string is not a recognized integral literal");
93 }
else if (ULLONG_MAX == big && ERANGE == errno) {
94 throw std::runtime_error(
"integral literal out of range");
96 return boost::numeric_cast<T>(big);
100 static T Get(
const std::string &data,
const T &defaultValue) {
111 static std::string Get(
const std::string &data) {
115 static std::string Get(
const std::string &data,
const std::string &defaultValue) {
116 if (data.size() == 0) {
125 static bool Get(
const std::string &data) {
126 std::string tmpData = data;
127 std::transform(tmpData.begin(), tmpData.end(), tmpData.begin(), ::tolower);
128 if (tmpData ==
"true" || tmpData ==
"yes" || tmpData ==
"1") {
135 static bool Get(
const std::string &data,
const bool &defaultValue) {
136 if (data.size() == 0) {
233 std::pair<const std::string&, Node&>
operator*();
236 std::unique_ptr<std::pair<const std::string&, Node&>>
operator->();
290 std::pair<const std::string&, const Node&>
operator*();
293 std::unique_ptr<std::pair<const std::string&, const Node&>>
operator->();
351 explicit Node(
const std::string &value);
352 explicit Node(
const char* value);
364 bool isMap()
const {
return IsMap(); }
371 explicit operator bool()
const {
394 T
as(
const T &defaultValue)
const {
402 size_t size()
const {
return Size(); }
440 void erase(
const size_t index) { Erase(index); }
441 void erase(
const std::string& key) { Erase(key); }
469 bool IsSequence()
const;
471 bool IsScalar()
const;
474 Node& Insert(
const size_t index);
477 void Erase(
const size_t index);
478 void Erase(
const std::string &key);
490 T As(
const T &defaultValue)
const {
491 return impl::StringConverter<T>::Get(AsString(), defaultValue);
497 const std::string& AsString()
const;
505 void Parse(Node &root,
const boost::filesystem::path&);
506 void Parse(Node &root, std::iostream&);
507 void Parse(Node &root,
const std::string &data);
508 void Parse(Node &root,
const char *data,
const size_t size);
511 Yaml::Node
parse(
const boost::filesystem::path&);
514 Yaml::Node
parse(std::istream&);
518 Yaml::Node
parse(
const std::string&);
519 Yaml::Node
parse(
const char*);
532 const size_t scalarMaxLength = 64,
533 const bool sequenceMapNewline =
false,
534 const bool mapScalarNewline =
false);
557 void Serialize(
const Node &root, std::ostream &stream,
const SerializeConfig &config = {2, 64,
false,
false});
558 void Serialize(
const Node &root, std::string &
string,
const SerializeConfig &config = {2, 64,
false,
false});
OperationException(const std::string &message)
Constructor.
ConstIterator & operator++()
Increment operator.
size_t SpaceIndentation
Number of spaces per indentation.
bool isScalar() const
Functions for checking type of node.
InternalException(const std::string &message)
Constructor.
bool operator!=(const Iterator &)
Check if this iterator is not equal to another iterator.
eType type() const
Functions for checking type of node.
bool operator==(const ConstIterator &)
Check if this iterator is equal to another iterator.
void erase(const std::string &key)
Erase item.
bool operator!=(const ConstIterator &)
Check if this iterator is not equal to another iterator.
Iterator begin()
Get start iterator.
bool isMap() const
Functions for checking type of node.
ConstIterator begin() const
Get start iterator.
Serialization configuration structure, describing output behavior.
void Serialize(const Node &root, const char *filename, const SerializeConfig &config={2, 64, false, false})
Serialize YAML.
ConstIterator & operator=(const ConstIterator &)
Assignment operator.
T as(const T &defaultValue) const
Get node as given template type.
bool isSequence() const
Functions for checking type of node.
Iterator over constant YAML nodes.
Node & operator[](const size_t index)
Get sequence/map item.
Main namespace for the ROSE library.
std::unique_ptr< std::pair< const std::string &, Node & > > operator->()
Dereference.
bool SequenceMapNewline
Put maps on a new line if parent node is a sequence.
Iterator over YAML nodes.
eType Type() const
Get type of exception.
Iterator & operator=(const Iterator &)
Assignment operator.
Iterator & operator--()
Decrement operator.
Base class for YAML exceptions.
bool operator==(const Iterator &)
Check if this iterator is equal to another iterator.
Node & operator=(const Node &node)
Assignment operators.
void clear()
Completely clear node.
bool operator!() const
Predicate to test whether node exists.
T as() const
Get node as given template type.
bool MapScalarNewline
Put scalars on a new line if parent node is a map.
Iterator & operator++()
Increment operator.
bool isNone() const
Functions for checking type of node.
Yaml::Node parse(const boost::filesystem::path &)
Parse YAML from file.
std::pair< const std::string &, Node & > operator*()
Get node of iterator.
Node & insert(const size_t index)
Insert sequence item at given index.
void erase(const size_t index)
Erase item.
Exception(const std::string &message, const eType type)
Constructor.
ConstIterator & operator--()
Decrement operator.
Node & pushBack()
Add new sequence index to back.
ConstIterator()
Default constructor.
size_t size() const
Get size of node.
SerializeConfig(const size_t spaceIndentation=2, const size_t scalarMaxLength=64, const bool sequenceMapNewline=false, const bool mapScalarNewline=false)
Constructor.
Iterator()
Default constructor.
Node & pushFront()
Add new sequence index to front.
std::pair< const std::string &, const Node & > operator*()
Get node of iterator.
std::unique_ptr< std::pair< const std::string &, const Node & > > operator->()
Dereference.
const char * Message() const
Get message of exception.
ConstIterator end() const
Get end iterator.
Node()
Default constructor.
Iterator end()
Get end iterator.
~ConstIterator()
Destructor.
size_t ScalarMaxLength
Maximum length of scalars.
ParsingException(const std::string &message)
Constructor.
eType
Enumeration of node types.