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
...@@ -11,7 +11,12 @@ namespace YAML { ...@@ -11,7 +11,12 @@ namespace YAML {
struct Mark; struct Mark;
NodeBuilder::NodeBuilder() NodeBuilder::NodeBuilder()
: m_pMemory(new detail::memory_holder), m_pRoot(nullptr), m_mapDepth(0) { : m_pMemory(new detail::memory_holder),
m_pRoot(nullptr),
m_stack{},
m_anchors{},
m_keys{},
m_mapDepth(0) {
m_anchors.push_back(nullptr); // since the anchors start at 1 m_anchors.push_back(nullptr); // since the anchors start at 1
} }
...@@ -127,4 +132,4 @@ void NodeBuilder::RegisterAnchor(anchor_t anchor, detail::node& node) { ...@@ -127,4 +132,4 @@ void NodeBuilder::RegisterAnchor(anchor_t anchor, detail::node& node) {
m_anchors.push_back(&node); m_anchors.push_back(&node);
} }
} }
} } // namespace YAML
...@@ -27,6 +27,10 @@ class Node; ...@@ -27,6 +27,10 @@ class Node;
class NodeBuilder : public EventHandler { class NodeBuilder : public EventHandler {
public: public:
NodeBuilder(); NodeBuilder();
NodeBuilder(const NodeBuilder&) = delete;
NodeBuilder(NodeBuilder&&) = delete;
NodeBuilder& operator=(const NodeBuilder&) = delete;
NodeBuilder& operator=(NodeBuilder&&) = delete;
virtual ~NodeBuilder(); virtual ~NodeBuilder();
Node Root(); Node Root();
...@@ -65,6 +69,6 @@ class NodeBuilder : public EventHandler { ...@@ -65,6 +69,6 @@ class NodeBuilder : public EventHandler {
std::vector<PushedKey> m_keys; std::vector<PushedKey> m_keys;
std::size_t m_mapDepth; std::size_t m_mapDepth;
}; };
} } // namespace YAML
#endif // NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_NODEBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -20,7 +20,7 @@ anchor_t NodeEvents::AliasManager::LookupAnchor( ...@@ -20,7 +20,7 @@ anchor_t NodeEvents::AliasManager::LookupAnchor(
} }
NodeEvents::NodeEvents(const Node& node) NodeEvents::NodeEvents(const Node& node)
: m_pMemory(node.m_pMemory), m_root(node.m_pNode) { : m_pMemory(node.m_pMemory), m_root(node.m_pNode), m_refCount{} {
if (m_root) if (m_root)
Setup(*m_root); Setup(*m_root);
} }
...@@ -98,4 +98,4 @@ bool NodeEvents::IsAliased(const detail::node& node) const { ...@@ -98,4 +98,4 @@ bool NodeEvents::IsAliased(const detail::node& node) const {
RefCount::const_iterator it = m_refCount.find(node.ref()); RefCount::const_iterator it = m_refCount.find(node.ref());
return it != m_refCount.end() && it->second > 1; return it != m_refCount.end() && it->second > 1;
} }
} } // namespace YAML
...@@ -26,13 +26,17 @@ class Node; ...@@ -26,13 +26,17 @@ class Node;
class NodeEvents { class NodeEvents {
public: public:
explicit NodeEvents(const Node& node); explicit NodeEvents(const Node& node);
NodeEvents(const NodeEvents&) = delete;
NodeEvents(NodeEvents&&) = delete;
NodeEvents& operator=(const NodeEvents&) = delete;
NodeEvents& operator=(NodeEvents&&) = delete;
void Emit(EventHandler& handler); void Emit(EventHandler& handler);
private: private:
class AliasManager { class AliasManager {
public: public:
AliasManager() : m_curAnchor(0) {} AliasManager() : m_anchorByIdentity{}, m_curAnchor(0) {}
void RegisterReference(const detail::node& node); void RegisterReference(const detail::node& node);
anchor_t LookupAnchor(const detail::node& node) const; anchor_t LookupAnchor(const detail::node& node) const;
...@@ -59,6 +63,6 @@ class NodeEvents { ...@@ -59,6 +63,6 @@ class NodeEvents {
typedef std::map<const detail::node_ref*, int> RefCount; typedef std::map<const detail::node_ref*, int> RefCount;
RefCount m_refCount; RefCount m_refCount;
}; };
} } // namespace YAML
#endif // NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // NODE_NODEEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -14,7 +14,12 @@ ostream_wrapper::ostream_wrapper() ...@@ -14,7 +14,12 @@ ostream_wrapper::ostream_wrapper()
m_comment(false) {} m_comment(false) {}
ostream_wrapper::ostream_wrapper(std::ostream& stream) ostream_wrapper::ostream_wrapper(std::ostream& stream)
: m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false) {} : m_buffer{},
m_pStream(&stream),
m_pos(0),
m_row(0),
m_col(0),
m_comment(false) {}
ostream_wrapper::~ostream_wrapper() {} ostream_wrapper::~ostream_wrapper() {}
...@@ -54,4 +59,4 @@ void ostream_wrapper::update_pos(char ch) { ...@@ -54,4 +59,4 @@ void ostream_wrapper::update_pos(char ch) {
m_comment = false; m_comment = false;
} }
} }
} } // namespace YAML
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
namespace YAML { namespace YAML {
class EventHandler; class EventHandler;
Parser::Parser() {} Parser::Parser() : m_pScanner{}, m_pDirectives{} {}
Parser::Parser(std::istream& in) { Load(in); } Parser::Parser(std::istream& in) : Parser() { Load(in); }
Parser::~Parser() {} Parser::~Parser() {}
...@@ -126,4 +126,4 @@ void Parser::PrintTokens(std::ostream& out) { ...@@ -126,4 +126,4 @@ void Parser::PrintTokens(std::ostream& out) {
m_pScanner->pop(); m_pScanner->pop();
} }
} }
} } // namespace YAML
...@@ -12,15 +12,17 @@ ...@@ -12,15 +12,17 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "yaml-cpp/noncopyable.h"
namespace YAML { namespace YAML {
// TODO: This class is no longer needed // TODO: This class is no longer needed
template <typename T> template <typename T>
class ptr_vector : private YAML::noncopyable { class ptr_vector {
public: public:
ptr_vector() {} ptr_vector() : m_data{} {}
ptr_vector(const ptr_vector&) = delete;
ptr_vector(ptr_vector&&) = default;
ptr_vector& operator=(const ptr_vector&) = delete;
ptr_vector& operator=(ptr_vector&&) = default;
void clear() { m_data.clear(); } void clear() { m_data.clear(); }
...@@ -38,6 +40,6 @@ class ptr_vector : private YAML::noncopyable { ...@@ -38,6 +40,6 @@ class ptr_vector : private YAML::noncopyable {
private: private:
std::vector<std::unique_ptr<T>> m_data; std::vector<std::unique_ptr<T>> m_data;
}; };
} } // namespace YAML
#endif // PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // PTR_VECTOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -2,18 +2,16 @@ ...@@ -2,18 +2,16 @@
namespace YAML { namespace YAML {
// constructors // constructors
RegEx::RegEx() : m_op(REGEX_EMPTY) {}
RegEx::RegEx(REGEX_OP op) : m_op(op) {} RegEx::RegEx(REGEX_OP op) : m_op(op), m_a(0), m_z(0), m_params{} {}
RegEx::RegEx() : RegEx(REGEX_EMPTY) {}
RegEx::RegEx(char ch) : m_op(REGEX_MATCH), m_a(ch) {} RegEx::RegEx(char ch) : m_op(REGEX_MATCH), m_a(ch), m_z(0), m_params{} {}
RegEx::RegEx(char a, char z) : m_op(REGEX_RANGE), m_a(a), m_z(z) {} RegEx::RegEx(char a, char z) : m_op(REGEX_RANGE), m_a(a), m_z(z), m_params{} {}
RegEx::RegEx(const std::string& str, REGEX_OP op) : m_op(op) { RegEx::RegEx(const std::string& str, REGEX_OP op)
for (std::size_t i = 0; i < str.size(); i++) : m_op(op), m_a(0), m_z(0), m_params(str.begin(), str.end()) {}
m_params.push_back(RegEx(str[i]));
}
// combination constructors // combination constructors
RegEx operator!(const RegEx& ex) { RegEx operator!(const RegEx& ex) {
...@@ -22,14 +20,14 @@ RegEx operator!(const RegEx& ex) { ...@@ -22,14 +20,14 @@ RegEx operator!(const RegEx& ex) {
return ret; return ret;
} }
RegEx operator||(const RegEx& ex1, const RegEx& ex2) { RegEx operator|(const RegEx& ex1, const RegEx& ex2) {
RegEx ret(REGEX_OR); RegEx ret(REGEX_OR);
ret.m_params.push_back(ex1); ret.m_params.push_back(ex1);
ret.m_params.push_back(ex2); ret.m_params.push_back(ex2);
return ret; return ret;
} }
RegEx operator&&(const RegEx& ex1, const RegEx& ex2) { RegEx operator&(const RegEx& ex1, const RegEx& ex2) {
RegEx ret(REGEX_AND); RegEx ret(REGEX_AND);
ret.m_params.push_back(ex1); ret.m_params.push_back(ex1);
ret.m_params.push_back(ex2); ret.m_params.push_back(ex2);
...@@ -42,4 +40,4 @@ RegEx operator+(const RegEx& ex1, const RegEx& ex2) { ...@@ -42,4 +40,4 @@ RegEx operator+(const RegEx& ex1, const RegEx& ex2) {
ret.m_params.push_back(ex2); ret.m_params.push_back(ex2);
return ret; return ret;
} }
} } // namespace YAML
...@@ -31,14 +31,14 @@ enum REGEX_OP { ...@@ -31,14 +31,14 @@ enum REGEX_OP {
class YAML_CPP_API RegEx { class YAML_CPP_API RegEx {
public: public:
RegEx(); RegEx();
RegEx(char ch); explicit RegEx(char ch);
RegEx(char a, char z); RegEx(char a, char z);
RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ); RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
~RegEx() {} ~RegEx() {}
friend YAML_CPP_API RegEx operator!(const RegEx& ex); friend YAML_CPP_API RegEx operator!(const RegEx& ex);
friend YAML_CPP_API RegEx operator||(const RegEx& ex1, const RegEx& ex2); friend YAML_CPP_API RegEx operator|(const RegEx& ex1, const RegEx& ex2);
friend YAML_CPP_API RegEx operator&&(const RegEx& ex1, const RegEx& ex2); friend YAML_CPP_API RegEx operator&(const RegEx& ex1, const RegEx& ex2);
friend YAML_CPP_API RegEx operator+(const RegEx& ex1, const RegEx& ex2); friend YAML_CPP_API RegEx operator+(const RegEx& ex1, const RegEx& ex2);
bool Matches(char ch) const; bool Matches(char ch) const;
...@@ -53,7 +53,7 @@ class YAML_CPP_API RegEx { ...@@ -53,7 +53,7 @@ class YAML_CPP_API RegEx {
int Match(const Source& source) const; int Match(const Source& source) const;
private: private:
RegEx(REGEX_OP op); explicit RegEx(REGEX_OP op);
template <typename Source> template <typename Source>
bool IsValidSource(const Source& source) const; bool IsValidSource(const Source& source) const;
......
...@@ -9,10 +9,15 @@ ...@@ -9,10 +9,15 @@
namespace YAML { namespace YAML {
Scanner::Scanner(std::istream& in) Scanner::Scanner(std::istream& in)
: INPUT(in), : INPUT(in),
m_tokens{},
m_startedStream(false), m_startedStream(false),
m_endedStream(false), m_endedStream(false),
m_simpleKeyAllowed(false), m_simpleKeyAllowed(false),
m_canBeJSONFlow(false) {} m_canBeJSONFlow(false),
m_simpleKeys{},
m_indents{},
m_indentRefs{},
m_flows{} {}
Scanner::~Scanner() {} Scanner::~Scanner() {}
......
...@@ -338,7 +338,7 @@ void Scanner::ScanQuotedScalar() { ...@@ -338,7 +338,7 @@ void Scanner::ScanQuotedScalar() {
// setup the scanning parameters // setup the scanning parameters
ScanScalarParams params; ScanScalarParams params;
RegEx end = (single ? RegEx(quote) && !Exp::EscSingleQuote() : RegEx(quote)); RegEx end = (single ? RegEx(quote) & !Exp::EscSingleQuote() : RegEx(quote));
params.end = &end; params.end = &end;
params.eatEnd = true; params.eatEnd = true;
params.escape = (single ? '\'' : '\\'); params.escape = (single ? '\'' : '\\');
...@@ -434,4 +434,4 @@ void Scanner::ScanBlockScalar() { ...@@ -434,4 +434,4 @@ void Scanner::ScanBlockScalar() {
token.value = scalar; token.value = scalar;
m_tokens.push(token); m_tokens.push(token);
} }
} } // namespace YAML
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#endif #endif
#include <memory> #include <memory>
#include <utility>
#include <vector> #include <vector>
#include "yaml-cpp/noncopyable.h"
namespace YAML { namespace YAML {
class SettingChangeBase; class SettingChangeBase;
...@@ -18,6 +18,7 @@ template <typename T> ...@@ -18,6 +18,7 @@ template <typename T>
class Setting { class Setting {
public: public:
Setting() : m_value() {} Setting() : m_value() {}
Setting(const T& value) : m_value() { set(value); }
const T get() const { return m_value; } const T get() const { return m_value; }
std::unique_ptr<SettingChangeBase> set(const T& value); std::unique_ptr<SettingChangeBase> set(const T& value);
...@@ -36,10 +37,14 @@ class SettingChangeBase { ...@@ -36,10 +37,14 @@ class SettingChangeBase {
template <typename T> template <typename T>
class SettingChange : public SettingChangeBase { class SettingChange : public SettingChangeBase {
public: public:
SettingChange(Setting<T>* pSetting) : m_pCurSetting(pSetting) { SettingChange(Setting<T>* pSetting)
// copy old setting to save its state : m_pCurSetting(pSetting),
m_oldSetting = *pSetting; m_oldSetting(*pSetting) // copy old setting to save its state
} {}
SettingChange(const SettingChange&) = delete;
SettingChange(SettingChange&&) = delete;
SettingChange& operator=(const SettingChange&) = delete;
SettingChange& operator=(SettingChange&&) = delete;
virtual void pop() { m_pCurSetting->restore(m_oldSetting); } virtual void pop() { m_pCurSetting->restore(m_oldSetting); }
...@@ -55,9 +60,12 @@ inline std::unique_ptr<SettingChangeBase> Setting<T>::set(const T& value) { ...@@ -55,9 +60,12 @@ inline std::unique_ptr<SettingChangeBase> Setting<T>::set(const T& value) {
return pChange; return pChange;
} }
class SettingChanges : private noncopyable { class SettingChanges {
public: public:
SettingChanges() {} SettingChanges() : m_settingChanges{} {}
SettingChanges(const SettingChanges&) = delete;
SettingChanges(SettingChanges&&) = default;
SettingChanges& operator=(const SettingChanges&) = delete;
~SettingChanges() { clear(); } ~SettingChanges() { clear(); }
void clear() { void clear() {
...@@ -90,6 +98,6 @@ class SettingChanges : private noncopyable { ...@@ -90,6 +98,6 @@ class SettingChanges : private noncopyable {
typedef std::vector<std::unique_ptr<SettingChangeBase>> setting_changes; typedef std::vector<std::unique_ptr<SettingChangeBase>> setting_changes;
setting_changes m_settingChanges; setting_changes m_settingChanges;
}; };
} } // namespace YAML
#endif // SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -18,6 +18,7 @@ SingleDocParser::SingleDocParser(Scanner& scanner, const Directives& directives) ...@@ -18,6 +18,7 @@ SingleDocParser::SingleDocParser(Scanner& scanner, const Directives& directives)
: m_scanner(scanner), : m_scanner(scanner),
m_directives(directives), m_directives(directives),
m_pCollectionStack(new CollectionStack), m_pCollectionStack(new CollectionStack),
m_anchors{},
m_curAnchor(0) {} m_curAnchor(0) {}
SingleDocParser::~SingleDocParser() {} SingleDocParser::~SingleDocParser() {}
...@@ -170,10 +171,10 @@ void SingleDocParser::HandleBlockSequence(EventHandler& eventHandler) { ...@@ -170,10 +171,10 @@ void SingleDocParser::HandleBlockSequence(EventHandler& eventHandler) {
// check for null // check for null
if (!m_scanner.empty()) { if (!m_scanner.empty()) {
const Token& token = m_scanner.peek(); const Token& nextToken = m_scanner.peek();
if (token.type == Token::BLOCK_ENTRY || if (nextToken.type == Token::BLOCK_ENTRY ||
token.type == Token::BLOCK_SEQ_END) { nextToken.type == Token::BLOCK_SEQ_END) {
eventHandler.OnNull(token.mark, NullAnchor); eventHandler.OnNull(nextToken.mark, NullAnchor);
continue; continue;
} }
} }
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <string> #include <string>
#include "yaml-cpp/anchor.h" #include "yaml-cpp/anchor.h"
#include "yaml-cpp/noncopyable.h"
namespace YAML { namespace YAML {
class CollectionStack; class CollectionStack;
...@@ -23,9 +22,13 @@ struct Directives; ...@@ -23,9 +22,13 @@ struct Directives;
struct Mark; struct Mark;
struct Token; struct Token;
class SingleDocParser : private noncopyable { class SingleDocParser {
public: public:
SingleDocParser(Scanner& scanner, const Directives& directives); SingleDocParser(Scanner& scanner, const Directives& directives);
SingleDocParser(const SingleDocParser&) = delete;
SingleDocParser(SingleDocParser&&) = delete;
SingleDocParser& operator=(const SingleDocParser&) = delete;
SingleDocParser& operator=(SingleDocParser&&) = delete;
~SingleDocParser(); ~SingleDocParser();
void HandleDocument(EventHandler& eventHandler); void HandleDocument(EventHandler& eventHandler);
......
...@@ -111,24 +111,15 @@ static UtfIntroState s_introTransitions[][uictMax] = { ...@@ -111,24 +111,15 @@ static UtfIntroState s_introTransitions[][uictMax] = {
static char s_introUngetCount[][uictMax] = { static char s_introUngetCount[][uictMax] = {
// uict00, uictBB, uictBF, uictEF, uictFE, uictFF, uictAscii, uictOther // uict00, uictBB, uictBF, uictEF, uictFE, uictFF, uictAscii, uictOther
{0, 1, 1, 0, 0, 0, 0, 1}, {0, 1, 1, 0, 0, 0, 0, 1}, {0, 2, 2, 2, 2, 2, 2, 2},
{0, 2, 2, 2, 2, 2, 2, 2}, {3, 3, 3, 3, 0, 3, 3, 3}, {4, 4, 4, 4, 4, 0, 4, 4},
{3, 3, 3, 3, 0, 3, 3, 3}, {1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1},
{4, 4, 4, 4, 4, 0, 4, 4}, {2, 2, 2, 2, 2, 0, 2, 2}, {2, 2, 2, 2, 0, 2, 2, 2},
{1, 1, 1, 1, 1, 1, 1, 1}, {0, 1, 1, 1, 1, 1, 1, 1}, {0, 2, 2, 2, 2, 2, 2, 2},
{1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1},
{2, 2, 2, 2, 2, 0, 2, 2}, {0, 2, 2, 2, 2, 2, 2, 2}, {0, 3, 3, 3, 3, 3, 3, 3},
{2, 2, 2, 2, 0, 2, 2, 2}, {4, 4, 4, 4, 4, 4, 4, 4}, {2, 0, 2, 2, 2, 2, 2, 2},
{0, 1, 1, 1, 1, 1, 1, 1}, {3, 3, 0, 3, 3, 3, 3, 3}, {1, 1, 1, 1, 1, 1, 1, 1},
{0, 2, 2, 2, 2, 2, 2, 2},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1},
{0, 2, 2, 2, 2, 2, 2, 2},
{0, 3, 3, 3, 3, 3, 3, 3},
{4, 4, 4, 4, 4, 4, 4, 4},
{2, 0, 2, 2, 2, 2, 2, 2},
{3, 3, 0, 3, 3, 3, 3, 3},
{1, 1, 1, 1, 1, 1, 1, 1},
}; };
inline UtfIntroCharType IntroCharTypeOf(std::istream::int_type ch) { inline UtfIntroCharType IntroCharTypeOf(std::istream::int_type ch) {
...@@ -192,6 +183,9 @@ inline void QueueUnicodeCodepoint(std::deque<char>& q, unsigned long ch) { ...@@ -192,6 +183,9 @@ inline void QueueUnicodeCodepoint(std::deque<char>& q, unsigned long ch) {
Stream::Stream(std::istream& input) Stream::Stream(std::istream& input)
: m_input(input), : m_input(input),
m_mark{},
m_charSet{},
m_readahead{},
m_pPrefetched(new unsigned char[YAML_PREFETCH_SIZE]), m_pPrefetched(new unsigned char[YAML_PREFETCH_SIZE]),
m_nPrefetchedAvailable(0), m_nPrefetchedAvailable(0),
m_nPrefetchedUsed(0) { m_nPrefetchedUsed(0) {
...@@ -445,4 +439,4 @@ void Stream::StreamInUtf32() const { ...@@ -445,4 +439,4 @@ void Stream::StreamInUtf32() const {
QueueUnicodeCodepoint(m_readahead, ch); QueueUnicodeCodepoint(m_readahead, ch);
} }
} } // namespace YAML
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/noncopyable.h"
#include "yaml-cpp/mark.h" #include "yaml-cpp/mark.h"
#include <cstddef> #include <cstddef>
#include <deque> #include <deque>
...@@ -17,11 +16,15 @@ ...@@ -17,11 +16,15 @@
#include <string> #include <string>
namespace YAML { namespace YAML {
class Stream : private noncopyable { class Stream {
public: public:
friend class StreamCharSource; friend class StreamCharSource;
Stream(std::istream& input); Stream(std::istream& input);
Stream(const Stream&) = delete;
Stream(Stream&&) = delete;
Stream& operator=(const Stream&) = delete;
Stream& operator=(Stream&&) = delete;
~Stream(); ~Stream();
operator bool() const; operator bool() const;
...@@ -71,6 +74,6 @@ inline bool Stream::ReadAheadTo(size_t i) const { ...@@ -71,6 +74,6 @@ inline bool Stream::ReadAheadTo(size_t i) const {
return true; return true;
return _ReadAheadTo(i); return _ReadAheadTo(i);
} }
} } // namespace YAML
#endif // STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/noncopyable.h"
#include <cstddef> #include <cstddef>
namespace YAML { namespace YAML {
...@@ -16,6 +15,9 @@ class StreamCharSource { ...@@ -16,6 +15,9 @@ class StreamCharSource {
StreamCharSource(const Stream& stream) : m_offset(0), m_stream(stream) {} StreamCharSource(const Stream& stream) : m_offset(0), m_stream(stream) {}
StreamCharSource(const StreamCharSource& source) StreamCharSource(const StreamCharSource& source)
: m_offset(source.m_offset), m_stream(source.m_stream) {} : m_offset(source.m_offset), m_stream(source.m_stream) {}
StreamCharSource(StreamCharSource&&) = default;
StreamCharSource& operator=(const StreamCharSource&) = delete;
StreamCharSource& operator=(StreamCharSource&&) = delete;
~StreamCharSource() {} ~StreamCharSource() {}
operator bool() const; operator bool() const;
...@@ -27,8 +29,6 @@ class StreamCharSource { ...@@ -27,8 +29,6 @@ class StreamCharSource {
private: private:
std::size_t m_offset; std::size_t m_offset;
const Stream& m_stream; const Stream& m_stream;
StreamCharSource& operator=(const StreamCharSource&); // non-assignable
}; };
inline StreamCharSource::operator bool() const { inline StreamCharSource::operator bool() const {
...@@ -43,6 +43,6 @@ inline const StreamCharSource StreamCharSource::operator+(int i) const { ...@@ -43,6 +43,6 @@ inline const StreamCharSource StreamCharSource::operator+(int i) const {
source.m_offset = 0; source.m_offset = 0;
return source; return source;
} }
} } // namespace YAML
#endif // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
#include "token.h" #include "token.h"
namespace YAML { namespace YAML {
Tag::Tag(const Token& token) : type(static_cast<TYPE>(token.data)) { Tag::Tag(const Token& token)
: type(static_cast<TYPE>(token.data)), handle{}, value{} {
switch (type) { switch (type) {
case VERBATIM: case VERBATIM:
value = token.value; value = token.value;
...@@ -46,4 +47,4 @@ const std::string Tag::Translate(const Directives& directives) { ...@@ -46,4 +47,4 @@ const std::string Tag::Translate(const Directives& directives) {
} }
throw std::runtime_error("yaml-cpp: internal error, bad tag type"); throw std::runtime_error("yaml-cpp: internal error, bad tag type");
} }
} } // namespace YAML
...@@ -14,10 +14,11 @@ ...@@ -14,10 +14,11 @@
namespace YAML { namespace YAML {
const std::string TokenNames[] = { const std::string TokenNames[] = {
"DIRECTIVE", "DOC_START", "DOC_END", "BLOCK_SEQ_START", "BLOCK_MAP_START", "DIRECTIVE", "DOC_START", "DOC_END", "BLOCK_SEQ_START",
"BLOCK_SEQ_END", "BLOCK_MAP_END", "BLOCK_ENTRY", "FLOW_SEQ_START", "BLOCK_MAP_START", "BLOCK_SEQ_END", "BLOCK_MAP_END", "BLOCK_ENTRY",
"FLOW_MAP_START", "FLOW_SEQ_END", "FLOW_MAP_END", "FLOW_MAP_COMPACT", "FLOW_SEQ_START", "FLOW_MAP_START", "FLOW_SEQ_END", "FLOW_MAP_END",
"FLOW_ENTRY", "KEY", "VALUE", "ANCHOR", "ALIAS", "TAG", "SCALAR"}; "FLOW_MAP_COMPACT", "FLOW_ENTRY", "KEY", "VALUE",
"ANCHOR", "ALIAS", "TAG", "SCALAR"};
struct Token { struct Token {
// enums // enums
...@@ -48,7 +49,7 @@ struct Token { ...@@ -48,7 +49,7 @@ struct Token {
// data // data
Token(TYPE type_, const Mark& mark_) Token(TYPE type_, const Mark& mark_)
: status(VALID), type(type_), mark(mark_), data(0) {} : status(VALID), type(type_), mark(mark_), value{}, params{}, data(0) {}
friend std::ostream& operator<<(std::ostream& out, const Token& token) { friend std::ostream& operator<<(std::ostream& out, const Token& token) {
out << TokenNames[token.type] << std::string(": ") << token.value; out << TokenNames[token.type] << std::string(": ") << token.value;
...@@ -64,6 +65,6 @@ struct Token { ...@@ -64,6 +65,6 @@ struct Token {
std::vector<std::string> params; std::vector<std::string> params;
int data; int data;
}; };
} } // namespace YAML
#endif // TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#include "gtest/gtest.h"
#include "regex_yaml.h" #include "regex_yaml.h"
#include "stream.h" #include "stream.h"
#include "gtest/gtest.h"
using YAML::RegEx; using YAML::RegEx;
using YAML::Stream; using YAML::Stream;
...@@ -106,8 +106,8 @@ TEST(RegExTest, OperatorOr) { ...@@ -106,8 +106,8 @@ TEST(RegExTest, OperatorOr) {
for (int j = i + 1; j < 128; ++j) { for (int j = i + 1; j < 128; ++j) {
auto iStr = std::string(1, char(i)); auto iStr = std::string(1, char(i));
auto jStr = std::string(1, char(j)); auto jStr = std::string(1, char(j));
RegEx ex1 = RegEx(iStr) || RegEx(jStr); RegEx ex1 = RegEx(iStr) | RegEx(jStr);
RegEx ex2 = RegEx(jStr) || RegEx(iStr); RegEx ex2 = RegEx(jStr) | RegEx(iStr);
for (int k = MIN_CHAR; k < 128; ++k) { for (int k = MIN_CHAR; k < 128; ++k) {
auto str = std::string(1, char(k)); auto str = std::string(1, char(k));
...@@ -128,8 +128,8 @@ TEST(RegExTest, OperatorOr) { ...@@ -128,8 +128,8 @@ TEST(RegExTest, OperatorOr) {
} }
TEST(RegExTest, OperatorOrShortCircuits) { TEST(RegExTest, OperatorOrShortCircuits) {
RegEx ex1 = RegEx(std::string("aaaa")) || RegEx(std::string("aa")); RegEx ex1 = RegEx(std::string("aaaa")) | RegEx(std::string("aa"));
RegEx ex2 = RegEx(std::string("aa")) || RegEx(std::string("aaaa")); RegEx ex2 = RegEx(std::string("aa")) | RegEx(std::string("aaaa"));
EXPECT_TRUE(ex1.Matches(std::string("aaaaa"))); EXPECT_TRUE(ex1.Matches(std::string("aaaaa")));
EXPECT_EQ(4, ex1.Match(std::string("aaaaa"))); EXPECT_EQ(4, ex1.Match(std::string("aaaaa")));
...@@ -139,13 +139,13 @@ TEST(RegExTest, OperatorOrShortCircuits) { ...@@ -139,13 +139,13 @@ TEST(RegExTest, OperatorOrShortCircuits) {
} }
TEST(RegExTest, OperatorAnd) { TEST(RegExTest, OperatorAnd) {
RegEx emptySet = RegEx('a') && RegEx(); RegEx emptySet = RegEx('a') & RegEx();
EXPECT_FALSE(emptySet.Matches(std::string("a"))); EXPECT_FALSE(emptySet.Matches(std::string("a")));
} }
TEST(RegExTest, OperatorAndShortCircuits) { TEST(RegExTest, OperatorAndShortCircuits) {
RegEx ex1 = RegEx(std::string("aaaa")) && RegEx(std::string("aa")); RegEx ex1 = RegEx(std::string("aaaa")) & RegEx(std::string("aa"));
RegEx ex2 = RegEx(std::string("aa")) && RegEx(std::string("aaaa")); RegEx ex2 = RegEx(std::string("aa")) & RegEx(std::string("aaaa"));
EXPECT_TRUE(ex1.Matches(std::string("aaaaa"))); EXPECT_TRUE(ex1.Matches(std::string("aaaaa")));
EXPECT_EQ(4, ex1.Match(std::string("aaaaa"))); EXPECT_EQ(4, ex1.Match(std::string("aaaaa")));
...@@ -174,4 +174,4 @@ TEST(RegExTest, StringOr) { ...@@ -174,4 +174,4 @@ TEST(RegExTest, StringOr) {
EXPECT_EQ(1, ex.Match(str)); EXPECT_EQ(1, ex.Match(str));
} }
} } // namespace
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