Commit 0d5c5715 authored by Ted Lyngmo's avatar Ted Lyngmo Committed by Jesse Beder
Browse files

Apply formatting/style tweaks to comply with compile time diagnostics for g++ and clang++ (#686)

* Add compilation flags: -Wshadow -Weffc++ -pedantic -pedantic-errors
* Delete implicit copy & move constructors & assignment operators
  in classes with pointer data members.
* An exception to the above: Add default copy & move constructors &
  assignment operators for the Binary class.
* Convert boolean RegEx operators to binary operators.
* Initialize all members in all classes in ctors.
* Let default ctor delegate to the converting ctor in
  Binary and RegEx
* Don't change any tests except regex_test (as a result of the change
  to binary operators).

Note: https://bugzilla.redhat.com/show_bug.cgi?id=1544675 makes
-Weffc++ report a false positive in "include/yaml-cpp/node/impl.h".
parent eca9cfd6
...@@ -165,7 +165,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR ...@@ -165,7 +165,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} -fPIC") set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} -fPIC")
endif() endif()
# #
set(FLAG_TESTED "-Wextra") set(FLAG_TESTED "-Wextra -Wshadow -Weffc++ -pedantic -pedantic-errors")
check_cxx_compiler_flag(${FLAG_TESTED} FLAG_WEXTRA) check_cxx_compiler_flag(${FLAG_TESTED} FLAG_WEXTRA)
if(FLAG_WEXTRA) if(FLAG_WEXTRA)
set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}") set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}")
......
...@@ -19,9 +19,13 @@ YAML_CPP_API std::vector<unsigned char> DecodeBase64(const std::string &input); ...@@ -19,9 +19,13 @@ YAML_CPP_API std::vector<unsigned char> DecodeBase64(const std::string &input);
class YAML_CPP_API Binary { class YAML_CPP_API Binary {
public: public:
Binary() : m_unownedData(0), m_unownedSize(0) {}
Binary(const unsigned char *data_, std::size_t size_) Binary(const unsigned char *data_, std::size_t size_)
: m_unownedData(data_), m_unownedSize(size_) {} : m_data{}, m_unownedData(data_), m_unownedSize(size_) {}
Binary() : Binary(nullptr, 0) {}
Binary(const Binary &) = default;
Binary(Binary &&) = default;
Binary &operator=(const Binary &) = default;
Binary &operator=(Binary &&) = default;
bool owned() const { return !m_unownedData; } bool owned() const { return !m_unownedData; }
std::size_t size() const { return owned() ? m_data.size() : m_unownedSize; } std::size_t size() const { return owned() ? m_data.size() : m_unownedSize; }
...@@ -62,6 +66,6 @@ class YAML_CPP_API Binary { ...@@ -62,6 +66,6 @@ class YAML_CPP_API Binary {
const unsigned char *m_unownedData; const unsigned char *m_unownedData;
std::size_t m_unownedSize; std::size_t m_unownedSize;
}; };
} } // namespace YAML
#endif // BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -22,6 +22,7 @@ namespace YAML { ...@@ -22,6 +22,7 @@ namespace YAML {
template <class T> template <class T>
class AnchorDict { class AnchorDict {
public: public:
AnchorDict() : m_data{} {}
void Register(anchor_t anchor, T value) { void Register(anchor_t anchor, T value) {
if (anchor > m_data.size()) { if (anchor > m_data.size()) {
m_data.resize(anchor); m_data.resize(anchor);
...@@ -34,6 +35,6 @@ class AnchorDict { ...@@ -34,6 +35,6 @@ class AnchorDict {
private: private:
std::vector<T> m_data; std::vector<T> m_data;
}; };
} } // namespace YAML
#endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
#include "yaml-cpp/emitterdef.h" #include "yaml-cpp/emitterdef.h"
#include "yaml-cpp/emittermanip.h" #include "yaml-cpp/emittermanip.h"
#include "yaml-cpp/noncopyable.h"
#include "yaml-cpp/null.h" #include "yaml-cpp/null.h"
#include "yaml-cpp/ostream_wrapper.h" #include "yaml-cpp/ostream_wrapper.h"
...@@ -28,10 +27,12 @@ struct _Null; ...@@ -28,10 +27,12 @@ struct _Null;
namespace YAML { namespace YAML {
class EmitterState; class EmitterState;
class YAML_CPP_API Emitter : private noncopyable { class YAML_CPP_API Emitter {
public: public:
Emitter(); Emitter();
explicit Emitter(std::ostream& stream); explicit Emitter(std::ostream& stream);
Emitter(const Emitter&) = delete;
Emitter& operator=(const Emitter&) = delete;
~Emitter(); ~Emitter();
// output // output
...@@ -249,6 +250,6 @@ inline Emitter& operator<<(Emitter& emitter, _Indent indent) { ...@@ -249,6 +250,6 @@ inline Emitter& operator<<(Emitter& emitter, _Indent indent) {
inline Emitter& operator<<(Emitter& emitter, _Precision precision) { inline Emitter& operator<<(Emitter& emitter, _Precision precision) {
return emitter.SetLocalPrecision(precision); return emitter.SetLocalPrecision(precision);
} }
} } // namespace YAML
#endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -22,6 +22,7 @@ namespace YAML { ...@@ -22,6 +22,7 @@ namespace YAML {
namespace detail { namespace detail {
class YAML_CPP_API memory { class YAML_CPP_API memory {
public: public:
memory() : m_nodes{} {}
node& create_node(); node& create_node();
void merge(const memory& rhs); void merge(const memory& rhs);
...@@ -40,7 +41,7 @@ class YAML_CPP_API memory_holder { ...@@ -40,7 +41,7 @@ class YAML_CPP_API memory_holder {
private: private:
shared_memory m_pMemory; shared_memory m_pMemory;
}; };
} } // namespace detail
} } // namespace YAML
#endif // VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -7,18 +7,18 @@ ...@@ -7,18 +7,18 @@
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/emitterstyle.h"
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
#include "yaml-cpp/node/type.h" #include "yaml-cpp/emitterstyle.h"
#include "yaml-cpp/node/ptr.h"
#include "yaml-cpp/node/detail/node_ref.h" #include "yaml-cpp/node/detail/node_ref.h"
#include "yaml-cpp/node/ptr.h"
#include "yaml-cpp/node/type.h"
#include <set> #include <set>
namespace YAML { namespace YAML {
namespace detail { namespace detail {
class node { class node {
public: public:
node() : m_pRef(new node_ref) {} node() : m_pRef(new node_ref), m_dependencies{} {}
node(const node&) = delete; node(const node&) = delete;
node& operator=(const node&) = delete; node& operator=(const node&) = delete;
...@@ -163,7 +163,7 @@ class node { ...@@ -163,7 +163,7 @@ class node {
typedef std::set<node*> nodes; typedef std::set<node*> nodes;
nodes m_dependencies; nodes m_dependencies;
}; };
} } // namespace detail
} } // namespace YAML
#endif // NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -7,15 +7,15 @@ ...@@ -7,15 +7,15 @@
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/node/node.h" #include "yaml-cpp/exceptions.h"
#include "yaml-cpp/node/iterator.h"
#include "yaml-cpp/node/detail/memory.h" #include "yaml-cpp/node/detail/memory.h"
#include "yaml-cpp/node/detail/node.h" #include "yaml-cpp/node/detail/node.h"
#include "yaml-cpp/exceptions.h" #include "yaml-cpp/node/iterator.h"
#include "yaml-cpp/node/node.h"
#include <string> #include <string>
namespace YAML { namespace YAML {
inline Node::Node() : m_isValid(true), m_pNode(NULL) {} inline Node::Node() : m_isValid(true), m_pMemory(nullptr), m_pNode(nullptr) {}
inline Node::Node(NodeType::value type) inline Node::Node(NodeType::value type)
: m_isValid(true), : m_isValid(true),
...@@ -42,7 +42,7 @@ inline Node::Node(const Node& rhs) ...@@ -42,7 +42,7 @@ inline Node::Node(const Node& rhs)
m_pMemory(rhs.m_pMemory), m_pMemory(rhs.m_pMemory),
m_pNode(rhs.m_pNode) {} m_pNode(rhs.m_pNode) {}
inline Node::Node(Zombie) : m_isValid(false), m_pNode(NULL) {} inline Node::Node(Zombie) : m_isValid(false), m_pMemory{}, m_pNode(nullptr) {}
inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory) inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory)
: m_isValid(true), m_pMemory(pMemory), m_pNode(&node) {} : m_isValid(true), m_pMemory(pMemory), m_pNode(&node) {}
...@@ -202,6 +202,15 @@ inline Node& Node::operator=(const T& rhs) { ...@@ -202,6 +202,15 @@ inline Node& Node::operator=(const T& rhs) {
return *this; return *this;
} }
inline Node& Node::operator=(const Node& rhs) {
if (!m_isValid || !rhs.m_isValid)
throw InvalidNode();
if (is(rhs))
return *this;
AssignNode(rhs);
return *this;
}
inline void Node::reset(const YAML::Node& rhs) { inline void Node::reset(const YAML::Node& rhs) {
if (!m_isValid || !rhs.m_isValid) if (!m_isValid || !rhs.m_isValid)
throw InvalidNode(); throw InvalidNode();
...@@ -238,15 +247,6 @@ inline void Node::Assign(char* rhs) { ...@@ -238,15 +247,6 @@ inline void Node::Assign(char* rhs) {
m_pNode->set_scalar(rhs); m_pNode->set_scalar(rhs);
} }
inline Node& Node::operator=(const Node& rhs) {
if (!m_isValid || !rhs.m_isValid)
throw InvalidNode();
if (is(rhs))
return *this;
AssignNode(rhs);
return *this;
}
inline void Node::AssignData(const Node& rhs) { inline void Node::AssignData(const Node& rhs) {
if (!m_isValid || !rhs.m_isValid) if (!m_isValid || !rhs.m_isValid)
throw InvalidNode(); throw InvalidNode();
...@@ -366,7 +366,7 @@ template <typename T> ...@@ -366,7 +366,7 @@ template <typename T>
inline typename to_value_t<T>::return_type to_value(const T& t) { inline typename to_value_t<T>::return_type to_value(const T& t) {
return to_value_t<T>(t)(); return to_value_t<T>(t)();
} }
} } // namespace detail
// indexing // indexing
template <typename Key> template <typename Key>
...@@ -374,8 +374,8 @@ inline const Node Node::operator[](const Key& key) const { ...@@ -374,8 +374,8 @@ inline const Node Node::operator[](const Key& key) const {
if (!m_isValid) if (!m_isValid)
throw InvalidNode(); throw InvalidNode();
EnsureNodeExists(); EnsureNodeExists();
detail::node* value = static_cast<const detail::node&>(*m_pNode) detail::node* value = static_cast<const detail::node&>(*m_pNode).get(
.get(detail::to_value(key), m_pMemory); detail::to_value(key), m_pMemory);
if (!value) { if (!value) {
return Node(ZombieNode); return Node(ZombieNode);
} }
...@@ -443,6 +443,6 @@ inline void Node::force_insert(const Key& key, const Value& value) { ...@@ -443,6 +443,6 @@ inline void Node::force_insert(const Key& key, const Value& value) {
// free functions // free functions
inline bool operator==(const Node& lhs, const Node& rhs) { return lhs.is(rhs); } inline bool operator==(const Node& lhs, const Node& rhs) { return lhs.is(rhs); }
} } // namespace YAML
#endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#ifndef NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || \
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include "yaml-cpp/dll.h"
namespace YAML {
// this is basically boost::noncopyable
class YAML_CPP_API noncopyable {
protected:
noncopyable() {}
~noncopyable() {}
private:
noncopyable(const noncopyable&);
const noncopyable& operator=(const noncopyable&);
};
}
#endif // NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -17,6 +17,10 @@ class YAML_CPP_API ostream_wrapper { ...@@ -17,6 +17,10 @@ class YAML_CPP_API ostream_wrapper {
public: public:
ostream_wrapper(); ostream_wrapper();
explicit ostream_wrapper(std::ostream& stream); explicit ostream_wrapper(std::ostream& stream);
ostream_wrapper(const ostream_wrapper&) = delete;
ostream_wrapper(ostream_wrapper&&) = delete;
ostream_wrapper& operator=(const ostream_wrapper&) = delete;
ostream_wrapper& operator=(ostream_wrapper&&) = delete;
~ostream_wrapper(); ~ostream_wrapper();
void write(const std::string& str); void write(const std::string& str);
...@@ -52,7 +56,7 @@ class YAML_CPP_API ostream_wrapper { ...@@ -52,7 +56,7 @@ class YAML_CPP_API ostream_wrapper {
template <std::size_t N> template <std::size_t N>
inline ostream_wrapper& operator<<(ostream_wrapper& stream, inline ostream_wrapper& operator<<(ostream_wrapper& stream,
const char(&str)[N]) { const char (&str)[N]) {
stream.write(str, N - 1); stream.write(str, N - 1);
return stream; return stream;
} }
...@@ -67,6 +71,6 @@ inline ostream_wrapper& operator<<(ostream_wrapper& stream, char ch) { ...@@ -67,6 +71,6 @@ inline ostream_wrapper& operator<<(ostream_wrapper& stream, char ch) {
stream.write(&ch, 1); stream.write(&ch, 1);
return stream; return stream;
} }
} } // namespace YAML
#endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <memory> #include <memory>
#include "yaml-cpp/dll.h" #include "yaml-cpp/dll.h"
#include "yaml-cpp/noncopyable.h"
namespace YAML { namespace YAML {
class EventHandler; class EventHandler;
...@@ -24,11 +23,17 @@ struct Token; ...@@ -24,11 +23,17 @@ struct Token;
* A parser turns a stream of bytes into one stream of "events" per YAML * A parser turns a stream of bytes into one stream of "events" per YAML
* document in the input stream. * document in the input stream.
*/ */
class YAML_CPP_API Parser : private noncopyable { class YAML_CPP_API Parser {
public: public:
/** Constructs an empty parser (with no input. */ /** Constructs an empty parser (with no input. */
Parser(); Parser();
/** non copyable but movable */
Parser(const Parser&) = delete;
Parser(Parser&&) = default;
Parser& operator=(const Parser&) = delete;
Parser& operator=(Parser&&) = default;
/** /**
* Constructs a parser from the given input stream. The input stream must * Constructs a parser from the given input stream. The input stream must
* live as long as the parser. * live as long as the parser.
...@@ -81,6 +86,6 @@ class YAML_CPP_API Parser : private noncopyable { ...@@ -81,6 +86,6 @@ class YAML_CPP_API Parser : private noncopyable {
std::unique_ptr<Scanner> m_pScanner; std::unique_ptr<Scanner> m_pScanner;
std::unique_ptr<Directives> m_pDirectives; std::unique_ptr<Directives> m_pDirectives;
}; };
} } // namespace YAML
#endif // PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#pragma once #pragma once
#endif #endif
#include <stack>
#include <cassert> #include <cassert>
#include <stack>
namespace YAML { namespace YAML {
struct CollectionType { struct CollectionType {
...@@ -17,6 +17,7 @@ struct CollectionType { ...@@ -17,6 +17,7 @@ struct CollectionType {
class CollectionStack { class CollectionStack {
public: public:
CollectionStack() : collectionStack{} {}
CollectionType::value GetCurCollectionType() const { CollectionType::value GetCurCollectionType() const {
if (collectionStack.empty()) if (collectionStack.empty())
return CollectionType::NoCollection; return CollectionType::NoCollection;
...@@ -35,6 +36,6 @@ class CollectionStack { ...@@ -35,6 +36,6 @@ class CollectionStack {
private: private:
std::stack<CollectionType::value> collectionStack; std::stack<CollectionType::value> collectionStack;
}; };
} } // namespace YAML
#endif // COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -26,7 +26,15 @@ namespace YAML { ...@@ -26,7 +26,15 @@ namespace YAML {
class GraphBuilderAdapter : public EventHandler { class GraphBuilderAdapter : public EventHandler {
public: public:
GraphBuilderAdapter(GraphBuilderInterface& builder) GraphBuilderAdapter(GraphBuilderInterface& builder)
: m_builder(builder), m_pRootNode(nullptr), m_pKeyNode(nullptr) {} : m_builder(builder),
m_containers{},
m_anchors{},
m_pRootNode(nullptr),
m_pKeyNode(nullptr) {}
GraphBuilderAdapter(const GraphBuilderAdapter&) = delete;
GraphBuilderAdapter(GraphBuilderAdapter&&) = delete;
GraphBuilderAdapter& operator=(const GraphBuilderAdapter&) = delete;
GraphBuilderAdapter& operator=(GraphBuilderAdapter&&) = delete;
virtual void OnDocumentStart(const Mark& mark) { (void)mark; } virtual void OnDocumentStart(const Mark& mark) { (void)mark; }
virtual void OnDocumentEnd() {} virtual void OnDocumentEnd() {}
...@@ -50,8 +58,8 @@ class GraphBuilderAdapter : public EventHandler { ...@@ -50,8 +58,8 @@ class GraphBuilderAdapter : public EventHandler {
struct ContainerFrame { struct ContainerFrame {
ContainerFrame(void* pSequence) ContainerFrame(void* pSequence)
: pContainer(pSequence), pPrevKeyNode(&sequenceMarker) {} : pContainer(pSequence), pPrevKeyNode(&sequenceMarker) {}
ContainerFrame(void* pMap, void* pPrevKeyNode) ContainerFrame(void* pMap, void* pPreviousKeyNode)
: pContainer(pMap), pPrevKeyNode(pPrevKeyNode) {} : pContainer(pMap), pPrevKeyNode(pPreviousKeyNode) {}
void* pContainer; void* pContainer;
void* pPrevKeyNode; void* pPrevKeyNode;
...@@ -74,6 +82,6 @@ class GraphBuilderAdapter : public EventHandler { ...@@ -74,6 +82,6 @@ class GraphBuilderAdapter : public EventHandler {
void RegisterAnchor(anchor_t anchor, void* pNode); void RegisterAnchor(anchor_t anchor, void* pNode);
void DispositionNode(void* pNode); void DispositionNode(void* pNode);
}; };
} } // namespace YAML
#endif // GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#include "directives.h" #include "directives.h"
namespace YAML { namespace YAML {
Directives::Directives() { Directives::Directives() : version{true, 1, 2}, tags{} {}
// version
version.isDefault = true;
version.major = 1;
version.minor = 2;
}
const std::string Directives::TranslateTagHandle( const std::string Directives::TranslateTagHandle(
const std::string& handle) const { const std::string& handle) const {
...@@ -19,4 +14,4 @@ const std::string Directives::TranslateTagHandle( ...@@ -19,4 +14,4 @@ const std::string Directives::TranslateTagHandle(
return it->second; return it->second;
} }
} } // namespace YAML
...@@ -16,10 +16,11 @@ std::string ToString(YAML::anchor_t anchor) { ...@@ -16,10 +16,11 @@ std::string ToString(YAML::anchor_t anchor) {
stream << anchor; stream << anchor;
return stream.str(); return stream.str();
} }
} } // namespace
namespace YAML { namespace YAML {
EmitFromEvents::EmitFromEvents(Emitter& emitter) : m_emitter(emitter) {} EmitFromEvents::EmitFromEvents(Emitter& emitter)
: m_emitter(emitter), m_stateStack{} {}
void EmitFromEvents::OnDocumentStart(const Mark&) {} void EmitFromEvents::OnDocumentStart(const Mark&) {}
...@@ -116,4 +117,4 @@ void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) { ...@@ -116,4 +117,4 @@ void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) {
if (anchor) if (anchor)
m_emitter << Anchor(ToString(anchor)); m_emitter << Anchor(ToString(anchor));
} }
} } // namespace YAML
...@@ -11,7 +11,7 @@ namespace YAML { ...@@ -11,7 +11,7 @@ namespace YAML {
class Binary; class Binary;
struct _Null; struct _Null;
Emitter::Emitter() : m_pState(new EmitterState) {} Emitter::Emitter() : m_pState(new EmitterState), m_stream{} {}
Emitter::Emitter(std::ostream& stream) Emitter::Emitter(std::ostream& stream)
: m_pState(new EmitterState), m_stream(stream) {} : m_pState(new EmitterState), m_stream(stream) {}
...@@ -906,4 +906,4 @@ Emitter& Emitter::Write(const Binary& binary) { ...@@ -906,4 +906,4 @@ Emitter& Emitter::Write(const Binary& binary) {
return *this; return *this;
} }
} } // namespace YAML
...@@ -6,27 +6,31 @@ ...@@ -6,27 +6,31 @@
namespace YAML { namespace YAML {
EmitterState::EmitterState() EmitterState::EmitterState()
: m_isGood(true), : m_isGood(true),
m_lastError{},
// default global manipulators
m_charset(EmitNonAscii),
m_strFmt(Auto),
m_boolFmt(TrueFalseBool),
m_boolLengthFmt(LongBool),
m_boolCaseFmt(LowerCase),
m_intFmt(Dec),
m_indent(2),
m_preCommentIndent(2),
m_postCommentIndent(1),
m_seqFmt(Block),
m_mapFmt(Block),
m_mapKeyFmt(Auto),
m_floatPrecision(std::numeric_limits<float>::max_digits10),
m_doublePrecision(std::numeric_limits<double>::max_digits10),
//
m_modifiedSettings{},
m_globalModifiedSettings{},
m_groups{},
m_curIndent(0), m_curIndent(0),
m_hasAnchor(false), m_hasAnchor(false),
m_hasTag(false), m_hasTag(false),
m_hasNonContent(false), m_hasNonContent(false),
m_docCount(0) { m_docCount(0) {}
// set default global manipulators
m_charset.set(EmitNonAscii);
m_strFmt.set(Auto);
m_boolFmt.set(TrueFalseBool);
m_boolLengthFmt.set(LongBool);
m_boolCaseFmt.set(LowerCase);
m_intFmt.set(Dec);
m_indent.set(2);
m_preCommentIndent.set(2);
m_postCommentIndent.set(1);
m_seqFmt.set(Block);
m_mapFmt.set(Block);
m_mapKeyFmt.set(Auto);
m_floatPrecision.set(std::numeric_limits<float>::max_digits10);
m_doublePrecision.set(std::numeric_limits<double>::max_digits10);
}
EmitterState::~EmitterState() {} EmitterState::~EmitterState() {}
...@@ -362,4 +366,4 @@ bool EmitterState::SetDoublePrecision(std::size_t value, ...@@ -362,4 +366,4 @@ bool EmitterState::SetDoublePrecision(std::size_t value,
_Set(m_doublePrecision, value, scope); _Set(m_doublePrecision, value, scope);
return true; return true;
} }
} } // namespace YAML
...@@ -145,7 +145,12 @@ class EmitterState { ...@@ -145,7 +145,12 @@ class EmitterState {
struct Group { struct Group {
explicit Group(GroupType::value type_) explicit Group(GroupType::value type_)
: type(type_), indent(0), childCount(0), longKey(false) {} : type(type_),
flowType{},
indent(0),
childCount(0),
longKey(false),
modifiedSettings{} {}
GroupType::value type; GroupType::value type;
FlowType::value flowType; FlowType::value flowType;
...@@ -198,6 +203,6 @@ void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) { ...@@ -198,6 +203,6 @@ void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) {
assert(false); assert(false);
} }
} }
} } // namespace YAML
#endif // EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include "regeximpl.h" #include "regeximpl.h"
#include "stringsource.h" #include "stringsource.h"
#include "yaml-cpp/binary.h" // IWYU pragma: keep #include "yaml-cpp/binary.h" // IWYU pragma: keep
#include "yaml-cpp/ostream_wrapper.h"
#include "yaml-cpp/null.h" #include "yaml-cpp/null.h"
#include "yaml-cpp/ostream_wrapper.h"
namespace YAML { namespace YAML {
namespace Utils { namespace Utils {
...@@ -173,12 +173,12 @@ bool IsValidPlainScalar(const std::string& str, FlowType::value flowType, ...@@ -173,12 +173,12 @@ bool IsValidPlainScalar(const std::string& str, FlowType::value flowType,
// then check until something is disallowed // then check until something is disallowed
static const RegEx& disallowed_flow = static const RegEx& disallowed_flow =
Exp::EndScalarInFlow() || (Exp::BlankOrBreak() + Exp::Comment()) || Exp::EndScalarInFlow() | (Exp::BlankOrBreak() + Exp::Comment()) |
Exp::NotPrintable() || Exp::Utf8_ByteOrderMark() || Exp::Break() || Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() |
Exp::Tab(); Exp::Tab();
static const RegEx& disallowed_block = static const RegEx& disallowed_block =
Exp::EndScalar() || (Exp::BlankOrBreak() + Exp::Comment()) || Exp::EndScalar() | (Exp::BlankOrBreak() + Exp::Comment()) |
Exp::NotPrintable() || Exp::Utf8_ByteOrderMark() || Exp::Break() || Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() |
Exp::Tab(); Exp::Tab();
const RegEx& disallowed = const RegEx& disallowed =
flowType == FlowType::Flow ? disallowed_flow : disallowed_block; flowType == FlowType::Flow ? disallowed_flow : disallowed_block;
...@@ -258,7 +258,7 @@ bool WriteAliasName(ostream_wrapper& out, const std::string& str) { ...@@ -258,7 +258,7 @@ bool WriteAliasName(ostream_wrapper& out, const std::string& str) {
} }
return true; return true;
} }
} } // namespace
StringFormat::value ComputeStringFormat(const std::string& str, StringFormat::value ComputeStringFormat(const std::string& str,
EMITTER_MANIP strFormat, EMITTER_MANIP strFormat,
...@@ -401,8 +401,8 @@ bool WriteComment(ostream_wrapper& out, const std::string& str, ...@@ -401,8 +401,8 @@ bool WriteComment(ostream_wrapper& out, const std::string& str,
for (std::string::const_iterator i = str.begin(); for (std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());) { GetNextCodePointAndAdvance(codePoint, i, str.end());) {
if (codePoint == '\n') { if (codePoint == '\n') {
out << "\n" << IndentTo(curIndent) << "#" out << "\n"
<< Indentation(postCommentIndent); << IndentTo(curIndent) << "#" << Indentation(postCommentIndent);
out.set_comment(); out.set_comment();
} else { } else {
WriteCodePoint(out, codePoint); WriteCodePoint(out, codePoint);
...@@ -479,5 +479,5 @@ bool WriteBinary(ostream_wrapper& out, const Binary& binary) { ...@@ -479,5 +479,5 @@ bool WriteBinary(ostream_wrapper& out, const Binary& binary) {
false); false);
return true; return true;
} }
} } // namespace Utils
} } // namespace YAML
...@@ -33,15 +33,15 @@ inline const RegEx& Tab() { ...@@ -33,15 +33,15 @@ inline const RegEx& Tab() {
return e; return e;
} }
inline const RegEx& Blank() { inline const RegEx& Blank() {
static const RegEx e = Space() || Tab(); static const RegEx e = Space() | Tab();
return e; return e;
} }
inline const RegEx& Break() { inline const RegEx& Break() {
static const RegEx e = RegEx('\n') || RegEx("\r\n"); static const RegEx e = RegEx('\n') | RegEx("\r\n");
return e; return e;
} }
inline const RegEx& BlankOrBreak() { inline const RegEx& BlankOrBreak() {
static const RegEx e = Blank() || Break(); static const RegEx e = Blank() | Break();
return e; return e;
} }
inline const RegEx& Digit() { inline const RegEx& Digit() {
...@@ -49,29 +49,29 @@ inline const RegEx& Digit() { ...@@ -49,29 +49,29 @@ inline const RegEx& Digit() {
return e; return e;
} }
inline const RegEx& Alpha() { inline const RegEx& Alpha() {
static const RegEx e = RegEx('a', 'z') || RegEx('A', 'Z'); static const RegEx e = RegEx('a', 'z') | RegEx('A', 'Z');
return e; return e;
} }
inline const RegEx& AlphaNumeric() { inline const RegEx& AlphaNumeric() {
static const RegEx e = Alpha() || Digit(); static const RegEx e = Alpha() | Digit();
return e; return e;
} }
inline const RegEx& Word() { inline const RegEx& Word() {
static const RegEx e = AlphaNumeric() || RegEx('-'); static const RegEx e = AlphaNumeric() | RegEx('-');
return e; return e;
} }
inline const RegEx& Hex() { inline const RegEx& Hex() {
static const RegEx e = Digit() || RegEx('A', 'F') || RegEx('a', 'f'); static const RegEx e = Digit() | RegEx('A', 'F') | RegEx('a', 'f');
return e; return e;
} }
// Valid Unicode code points that are not part of c-printable (YAML 1.2, sec. // Valid Unicode code points that are not part of c-printable (YAML 1.2, sec.
// 5.1) // 5.1)
inline const RegEx& NotPrintable() { inline const RegEx& NotPrintable() {
static const RegEx e = static const RegEx e =
RegEx(0) || RegEx(0) |
RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) || RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) |
RegEx(0x0E, 0x1F) || RegEx(0x0E, 0x1F) |
(RegEx('\xC2') + (RegEx('\x80', '\x84') || RegEx('\x86', '\x9F'))); (RegEx('\xC2') + (RegEx('\x80', '\x84') | RegEx('\x86', '\x9F')));
return e; return e;
} }
inline const RegEx& Utf8_ByteOrderMark() { inline const RegEx& Utf8_ByteOrderMark() {
...@@ -82,19 +82,19 @@ inline const RegEx& Utf8_ByteOrderMark() { ...@@ -82,19 +82,19 @@ inline const RegEx& Utf8_ByteOrderMark() {
// actual tags // actual tags
inline const RegEx& DocStart() { inline const RegEx& DocStart() {
static const RegEx e = RegEx("---") + (BlankOrBreak() || RegEx()); static const RegEx e = RegEx("---") + (BlankOrBreak() | RegEx());
return e; return e;
} }
inline const RegEx& DocEnd() { inline const RegEx& DocEnd() {
static const RegEx e = RegEx("...") + (BlankOrBreak() || RegEx()); static const RegEx e = RegEx("...") + (BlankOrBreak() | RegEx());
return e; return e;
} }
inline const RegEx& DocIndicator() { inline const RegEx& DocIndicator() {
static const RegEx e = DocStart() || DocEnd(); static const RegEx e = DocStart() | DocEnd();
return e; return e;
} }
inline const RegEx& BlockEntry() { inline const RegEx& BlockEntry() {
static const RegEx e = RegEx('-') + (BlankOrBreak() || RegEx()); static const RegEx e = RegEx('-') + (BlankOrBreak() | RegEx());
return e; return e;
} }
inline const RegEx& Key() { inline const RegEx& Key() {
...@@ -106,11 +106,11 @@ inline const RegEx& KeyInFlow() { ...@@ -106,11 +106,11 @@ inline const RegEx& KeyInFlow() {
return e; return e;
} }
inline const RegEx& Value() { inline const RegEx& Value() {
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx()); static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx());
return e; return e;
} }
inline const RegEx& ValueInFlow() { inline const RegEx& ValueInFlow() {
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx(",}", REGEX_OR)); static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx(",}", REGEX_OR));
return e; return e;
} }
inline const RegEx& ValueInJSONFlow() { inline const RegEx& ValueInJSONFlow() {
...@@ -122,20 +122,20 @@ inline const RegEx Comment() { ...@@ -122,20 +122,20 @@ inline const RegEx Comment() {
return e; return e;
} }
inline const RegEx& Anchor() { inline const RegEx& Anchor() {
static const RegEx e = !(RegEx("[]{},", REGEX_OR) || BlankOrBreak()); static const RegEx e = !(RegEx("[]{},", REGEX_OR) | BlankOrBreak());
return e; return e;
} }
inline const RegEx& AnchorEnd() { inline const RegEx& AnchorEnd() {
static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak(); static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) | BlankOrBreak();
return e; return e;
} }
inline const RegEx& URI() { inline const RegEx& URI() {
static const RegEx e = Word() || RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) || static const RegEx e = Word() | RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) |
(RegEx('%') + Hex() + Hex()); (RegEx('%') + Hex() + Hex());
return e; return e;
} }
inline const RegEx& Tag() { inline const RegEx& Tag() {
static const RegEx e = Word() || RegEx("#;/?:@&=+$_.~*'()", REGEX_OR) || static const RegEx e = Word() | RegEx("#;/?:@&=+$_.~*'()", REGEX_OR) |
(RegEx('%') + Hex() + Hex()); (RegEx('%') + Hex() + Hex());
return e; return e;
} }
...@@ -148,34 +148,34 @@ inline const RegEx& Tag() { ...@@ -148,34 +148,34 @@ inline const RegEx& Tag() {
// space. // space.
inline const RegEx& PlainScalar() { inline const RegEx& PlainScalar() {
static const RegEx e = static const RegEx e =
!(BlankOrBreak() || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || !(BlankOrBreak() | RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) |
(RegEx("-?:", REGEX_OR) + (BlankOrBreak() || RegEx()))); (RegEx("-?:", REGEX_OR) + (BlankOrBreak() | RegEx())));
return e; return e;
} }
inline const RegEx& PlainScalarInFlow() { inline const RegEx& PlainScalarInFlow() {
static const RegEx e = static const RegEx e =
!(BlankOrBreak() || RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) || !(BlankOrBreak() | RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) |
(RegEx("-:", REGEX_OR) + Blank())); (RegEx("-:", REGEX_OR) + Blank()));
return e; return e;
} }
inline const RegEx& EndScalar() { inline const RegEx& EndScalar() {
static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx()); static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx());
return e; return e;
} }
inline const RegEx& EndScalarInFlow() { inline const RegEx& EndScalarInFlow() {
static const RegEx e = static const RegEx e =
(RegEx(':') + (BlankOrBreak() || RegEx() || RegEx(",]}", REGEX_OR))) || (RegEx(':') + (BlankOrBreak() | RegEx() | RegEx(",]}", REGEX_OR))) |
RegEx(",?[]{}", REGEX_OR); RegEx(",?[]{}", REGEX_OR);
return e; return e;
} }
inline const RegEx& ScanScalarEndInFlow() { inline const RegEx& ScanScalarEndInFlow() {
static const RegEx e = (EndScalarInFlow() || (BlankOrBreak() + Comment())); static const RegEx e = (EndScalarInFlow() | (BlankOrBreak() + Comment()));
return e; return e;
} }
inline const RegEx& ScanScalarEnd() { inline const RegEx& ScanScalarEnd() {
static const RegEx e = EndScalar() || (BlankOrBreak() + Comment()); static const RegEx e = EndScalar() | (BlankOrBreak() + Comment());
return e; return e;
} }
inline const RegEx& EscSingleQuote() { inline const RegEx& EscSingleQuote() {
...@@ -192,8 +192,8 @@ inline const RegEx& ChompIndicator() { ...@@ -192,8 +192,8 @@ inline const RegEx& ChompIndicator() {
return e; return e;
} }
inline const RegEx& Chomp() { inline const RegEx& Chomp() {
static const RegEx e = (ChompIndicator() + Digit()) || static const RegEx e = (ChompIndicator() + Digit()) |
(Digit() + ChompIndicator()) || ChompIndicator() || (Digit() + ChompIndicator()) | ChompIndicator() |
Digit(); Digit();
return e; return e;
} }
......
...@@ -22,8 +22,13 @@ node_data::node_data() ...@@ -22,8 +22,13 @@ node_data::node_data()
: m_isDefined(false), : m_isDefined(false),
m_mark(Mark::null_mark()), m_mark(Mark::null_mark()),
m_type(NodeType::Null), m_type(NodeType::Null),
m_tag{},
m_style(EmitterStyle::Default), m_style(EmitterStyle::Default),
m_seqSize(0) {} m_scalar{},
m_sequence{},
m_seqSize(0),
m_map{},
m_undefinedPairs{} {}
void node_data::mark_defined() { void node_data::mark_defined() {
if (m_type == NodeType::Undefined) if (m_type == NodeType::Undefined)
...@@ -238,8 +243,8 @@ bool node_data::remove(node& key, shared_memory_holder /* pMemory */) { ...@@ -238,8 +243,8 @@ bool node_data::remove(node& key, shared_memory_holder /* pMemory */) {
if (m_type != NodeType::Map) if (m_type != NodeType::Map)
return false; return false;
kv_pairs::iterator it = m_undefinedPairs.begin(); for (kv_pairs::iterator it = m_undefinedPairs.begin();
while (it != m_undefinedPairs.end()) { it != m_undefinedPairs.end();) {
kv_pairs::iterator jt = std::next(it); kv_pairs::iterator jt = std::next(it);
if (it->first->is(key)) if (it->first->is(key))
m_undefinedPairs.erase(it); m_undefinedPairs.erase(it);
...@@ -307,5 +312,5 @@ void node_data::convert_sequence_to_map(shared_memory_holder pMemory) { ...@@ -307,5 +312,5 @@ void node_data::convert_sequence_to_map(shared_memory_holder pMemory) {
reset_sequence(); reset_sequence();
m_type = NodeType::Map; m_type = NodeType::Map;
} }
} } // namespace detail
} } // namespace YAML
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment